FFmpegPlayer/Demuxer.h
2024-01-18 22:22:26 +08:00

42 lines
963 B
C++

#ifndef __DEMUXER_H__
#define __DEMUXER_H__
#include <functional>
#include <string>
#include <thread>
struct AVFormatContext;
struct AVCodec;
struct AVCodecParameters;
struct AVPacket;
enum Stream : uint32_t {
Video,
Audio,
Size,
};
class Demuxer {
public:
using CodecInformation = std::pair<const AVCodec *, const AVCodecParameters *>;
using Callback = std::function<void(const std::shared_ptr<AVPacket> &)>;
Demuxer();
~Demuxer();
void open(const std::string &path);
CodecInformation codecInformation(Stream type) const;
void setStreamPacketCallback(Stream type, const Callback &callback);
void start();
protected:
void run();
private:
bool m_exit;
std::thread m_thread;
AVFormatContext *m_context;
int m_streams[Stream::Size];
CodecInformation m_codecInformations[Stream::Size];
Callback m_callback[Stream::Size];
};
#endif // __DEMUXER_H__