]> git.sesse.net Git - nageru/blob - mux.h
Remove an obsolete comment.
[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 #include <queue>
14 #include <vector>
15
16 class Mux {
17 public:
18         enum Codec {
19                 CODEC_H264,
20                 CODEC_NV12,  // Uncompressed 4:2:0.
21         };
22
23         // Takes ownership of avctx.
24         Mux(AVFormatContext *avctx, int width, int height, Codec video_codec, const std::string &video_extradata, const AVCodecParameters *audio_codecpar, int time_base);
25         ~Mux();
26         void add_packet(const AVPacket &pkt, int64_t pts, int64_t dts);
27
28         // As long as the mux is plugged, it will not actually write anything to disk,
29         // just queue the packets. Once it is unplugged, the packets are reordered by pts
30         // and written. This is primarily useful if you might have two different encoders
31         // writing to the mux at the same time (because one is shutting down), so that
32         // pts might otherwise come out-of-order.
33         //
34         // You can plug and unplug multiple times; only when the plug count reaches zero,
35         // something will actually happen.
36         void plug();
37         void unplug();
38
39 private:
40         void write_packet_or_die(const AVPacket &pkt);  // Must be called with <mu> held.
41
42         std::mutex mu;
43         AVFormatContext *avctx;  // Protected by <mu>.
44         int plug_count = 0;  // Protected by <mu>.
45         std::vector<AVPacket *> plugged_packets;  // Protected by <mu>.
46
47         AVStream *avstream_video, *avstream_audio;
48 };
49
50 #endif  // !defined(_MUX_H)