]> git.sesse.net Git - nageru/blob - mux.h
Separate muxing entirely out of the HTTPD class.
[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 class KeyFrameSignalReceiver {
13 public:
14         // Needs to automatically turn the flag off again after actually receiving data.
15         virtual void signal_keyframe() = 0;
16 };
17
18 class Mux {
19 public:
20         enum Codec {
21                 CODEC_H264,
22                 CODEC_NV12,  // Uncompressed 4:2:0.
23         };
24
25         // Takes ownership of avctx. <keyframe_signal_receiver> can be nullptr.
26         Mux(AVFormatContext *avctx, int width, int height, Codec video_codec, const AVCodec *codec_audio, int time_base, int bit_rate, KeyFrameSignalReceiver *keyframe_signal_receiver);
27         ~Mux();
28         void add_packet(const AVPacket &pkt, int64_t pts, int64_t dts);
29
30 private:
31         AVFormatContext *avctx;
32         AVStream *avstream_video, *avstream_audio;
33         KeyFrameSignalReceiver *keyframe_signal_receiver;
34 };
35
36 #endif  // !defined(_MUX_H)