]> git.sesse.net Git - nageru/blob - mux.h
Set x264 global headers (Quick Sync global headers are still not there).
[nageru] / mux.h
1 #ifndef _MUX_H
2 #define _MUX_H 1
3
4 // Wrapper around an AVFormat mux.
5
6 extern "C" {
7 #include <libavcodec/avcodec.h>
8 #include <libavformat/avformat.h>
9 #include <libavformat/avio.h>
10 }
11
12 #include <mutex>
13
14 class KeyFrameSignalReceiver {
15 public:
16         // Needs to automatically turn the flag off again after actually receiving data.
17         virtual void signal_keyframe() = 0;
18 };
19
20 class Mux {
21 public:
22         enum Codec {
23                 CODEC_H264,
24                 CODEC_NV12,  // Uncompressed 4:2:0.
25         };
26
27         // Takes ownership of avctx. <keyframe_signal_receiver> can be nullptr.
28         Mux(AVFormatContext *avctx, int width, int height, Codec video_codec, const std::string &video_extradata, const AVCodecContext *audio_ctx, int time_base, KeyFrameSignalReceiver *keyframe_signal_receiver);
29         ~Mux();
30         void add_packet(const AVPacket &pkt, int64_t pts, int64_t dts);
31
32 private:
33         std::mutex ctx_mu;
34         AVFormatContext *avctx;  // Protected by <ctx_mu>.
35         AVStream *avstream_video, *avstream_audio;
36         KeyFrameSignalReceiver *keyframe_signal_receiver;
37 };
38
39 #endif  // !defined(_MUX_H)