#ifndef DE90A7C0_21FB_4520_99C8_4A6D864A7F12 #define DE90A7C0_21FB_4520_99C8_4A6D864A7F12 /* ******************************************************************************* * INCLUDE ******************************************************************************* */ #include "../core/Muxer.h" #include "../core/VideoEncoder.h" #include "../core/AudioEncoder.h" extern "C" { #include #include } #include #include namespace Video { namespace FFmpeg { /* ******************************************************************************* * CLASS DECLARE ******************************************************************************* */ class Muxer: public Core::Muxer { protected: class Stream { public: using Ptr = Poco::SharedPtr; public: Stream(AVFormatContext& format, Core::VideoEncoder::Ptr pEncoder, AVRational tb, Core::PacketQueue::Ptr pQueue); Stream(AVFormatContext& format, Core::AudioEncoder::Ptr pEncoder, AVRational tb, Core::PacketQueue::Ptr pQueue); ~Stream(); public: int id() const; bool operator<(const Stream& other); Core::PacketQueue::Ptr queue(); AVRational timebase(); uint64_t getTimeline(); void setTimeline(uint64_t t); Core::SerialCodeWatcher& serialCodeWatcher(); protected: void open(AVFormatContext& format, const Core::CodecID codec, std::function init); void close(); private: AVStream* _pStream; Core::PacketQueue::Ptr _pQueue; AVRational _timebase; uint64_t _timeline; AVCodecContext* _pEncoder; Core::SerialCodeWatcher _serialCodeWatcher; }; public: Muxer(const std::string& url); ~Muxer(); protected: void connect() override; void mux() override; void disconnect() override; const std::string getFormatName(); void getSuitableTimebase(AVRational& vtb, AVRational& atb); private: AVFormatContext* _pFormatCtx; std::vector _streams; }; inline bool Muxer::Stream::operator<(const Stream& other) { return _timeline < other._timeline; } inline int Muxer::Stream::id() const { return _pStream->id; } inline Core::PacketQueue::Ptr Muxer::Stream::queue() { return _pQueue; } inline AVRational Muxer::Stream::timebase() { return _timebase; } inline uint64_t Muxer::Stream::getTimeline() { return _timeline; } inline void Muxer::Stream::setTimeline(uint64_t t) { _timeline = t; } inline Core::SerialCodeWatcher& Muxer::Stream::serialCodeWatcher() { return _serialCodeWatcher; } } } #endif