Audio播放逻辑
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
#ifndef AUDIODECODER_H
|
||||
#define AUDIODECODER_H
|
||||
#include <decodeParam.h>
|
||||
|
||||
int RequestAudioFrame(AudioParam& param, uint8_t* audioBuffer, int bufSize);
|
||||
void audioCallback(void* userdata, uint8_t* stream, int len);
|
||||
void RequestAudioPacket(MediaParam& param);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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
|
||||
@@ -1,17 +1,9 @@
|
||||
#ifndef DECODER_H
|
||||
#define DECODER_H
|
||||
extern "C" {
|
||||
#include "libavcodec/avcodec.h"
|
||||
#include "libavformat/avformat.h"
|
||||
#include "libavutil/imgutils.h"
|
||||
}
|
||||
#include <queue>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
|
||||
#include "decodeParam.h"
|
||||
|
||||
void InitDecoder(const char* filepath, VideoParam& param);
|
||||
void RequestPacket(MediaParam& param);
|
||||
void InitDecoder(const char* filepath, MediaParam& param);
|
||||
void RequestVideoPacket(MediaParam& param);
|
||||
void RequestVideoFrame(MediaParam& param);
|
||||
#endif
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <cstring>
|
||||
#include <string_view>
|
||||
enum class FileType {
|
||||
MUSIC,
|
||||
AUDIO,
|
||||
VIDEO,
|
||||
IMG,
|
||||
ERRORTYPE
|
||||
@@ -64,7 +64,7 @@ private:
|
||||
}
|
||||
public:
|
||||
static FileType GetFileType(const path& filepath) {
|
||||
if (IsMusic(filepath)) return FileType::MUSIC;
|
||||
if (IsMusic(filepath)) return FileType::AUDIO;
|
||||
if (IsVideo(filepath)) return FileType::VIDEO;
|
||||
if (IsImg(filepath)) return FileType::IMG;
|
||||
return FileType::ERRORTYPE;
|
||||
|
||||
Reference in New Issue
Block a user