播放视频时同时播放音频

This commit is contained in:
2024-02-27 14:26:22 +08:00
parent 800364ea78
commit c8578b1e37
5 changed files with 39 additions and 11 deletions

View File

@@ -99,16 +99,19 @@ struct VideoParam
int width;
int height;
int videoStreamIndex;
AVStream* stream;
bool eof = false;
bool pause = false;
bool quit = false;
double totalTime = 0;
double currentTime = 0;
};
struct AudioParam
{
MediaQueue<AVPacket> packetQueue;
AVCodecContext* codecCtx;
AVStream* stream;
int audioStreamIndex;
static constexpr int MAX_BUFFER_SIZE = 192000;
uint8_t* buffer = new uint8_t[MAX_BUFFER_SIZE];
@@ -118,6 +121,16 @@ struct AudioParam
bool pause = false;
bool isVideo = false;
bool quit = false;
double currentTime = 0;
double totalTime = 0;
double lastPts;
double getCurrentTime() const
{
const int diff = bufferSize - bufferIndex;
const int bytePreSec = codecCtx->sample_rate * codecCtx->ch_layout.nb_channels * 2;
return currentTime - static_cast<double>(diff) / bytePreSec;
}
};
struct MediaParam