Audio播放逻辑

This commit is contained in:
2024-02-23 16:24:42 +08:00
parent 5e794cf825
commit f005b19ee4
8 changed files with 206 additions and 36 deletions

View File

@@ -1,5 +1,17 @@
#ifndef DECODEPARAM_H
#define DECODEPARAM_H
extern "C" {
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavutil/imgutils.h"
}
#include <queue>
#include <condition_variable>
#include <mutex>
#include <chrono>
using namespace std::literals::chrono_literals;
template<typename T>
requires std::is_same_v<T, AVPacket> || std::is_same_v<T, AVFrame>
struct MediaQueue
@@ -83,7 +95,6 @@ struct VideoParam
{
MediaQueue<AVPacket> packetQueue;
MediaQueue<AVFrame> frameQueue;
AVFormatContext* fmtCtx;
AVCodecContext* codecCtx;
int width;
int height;
@@ -98,13 +109,13 @@ struct VideoParam
struct AudioParam
{
MediaQueue<AVPacket> packetQueue;
MediaQueue<AVFrame> frameQueue;
AVFormatContext* fmtCtx;
AVCodecContext* codecCtx;
int audioStreamIndex;
static constexpr int MAX_BUFFER_SIZE = 192000;
uint8_t* buffer = new uint8_t[MAX_BUFFER_SIZE];
uint32_t bufferSize = 0;
uint32_t bufferIndex = 0;
bool eof = false;
bool pause = false;
bool quit = false;
};
@@ -113,5 +124,6 @@ struct MediaParam
{
VideoParam videoParam;
AudioParam audioParam;
AVFormatContext* fmtCtx;
};
#endif