X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=shared%2Fmux.h;h=5020f37d943c64e98ee73c1d8e7771a2da88659d;hb=refs%2Fheads%2Fcef-kaeru;hp=62cd37cf80791f061182ebf50498756948f24a78;hpb=eeda8995329601f9f4e35047358400833eeae68e;p=nageru diff --git a/shared/mux.h b/shared/mux.h index 62cd37c..5020f37 100644 --- a/shared/mux.h +++ b/shared/mux.h @@ -50,13 +50,9 @@ class Mux { public: enum Codec { CODEC_H264, - CODEC_NV12, // Uncompressed 4:2:0. + CODEC_AV1, CODEC_MJPEG }; - enum WithAudio { - WITH_AUDIO, - WITHOUT_AUDIO - }; enum WriteStrategy { // add_packet() will write the packet immediately, unless plugged. WRITE_FOREGROUND, @@ -68,15 +64,22 @@ public: // higher overhead. WRITE_BACKGROUND, }; + enum WithSubtitles { + WITH_SUBTITLES, + WITHOUT_SUBTITLES + }; // Takes ownership of avctx. will be called every time // a write has been made to the video stream (id 0), with the pts of // the just-written frame. (write_callback can be nullptr.) // Does not take ownership of ; elements in there, if any, // will be added to. - Mux(AVFormatContext *avctx, int width, int height, Codec video_codec, const std::string &video_extradata, const AVCodecParameters *audio_codecpar, AVColorSpace color_space, WithAudio with_audio, int time_base, std::function write_callback, WriteStrategy write_strategy, const std::vector &metrics); + // + // If audio_codecpar is nullptr, there will be no audio stream. + Mux(AVFormatContext *avctx, int width, int height, Codec video_codec, const std::string &video_extradata, const AVCodecParameters *audio_codecpar, AVColorSpace color_space, int time_base, std::function write_callback, WriteStrategy write_strategy, const std::vector &metrics, WithSubtitles with_subtitles = WITHOUT_SUBTITLES); ~Mux(); void add_packet(const AVPacket &pkt, int64_t pts, int64_t dts, AVRational timebase = { 1, TIMEBASE }, int stream_index_override = -1); + int get_subtitle_stream_idx() const { return subtitle_stream_idx; } // As long as the mux is plugged, it will not actually write anything to disk, // just queue the packets. Once it is unplugged, the packets are reordered by pts @@ -89,10 +92,17 @@ public: void plug(); void unplug(); + // Temporary stop the mux; any packets coming in are discarded, and any existing ones + // in the queue will be dropped. Any writes in progress will finish as usual. + // Incompatible with plug(). + void drain(); + void undrain(); + private: // If write_strategy == WRITE_FOREGORUND, Must be called with held. void write_packet_or_die(const AVPacket &pkt, int64_t unscaled_pts); void thread_func(); + void write_header(); WriteStrategy write_strategy; @@ -104,6 +114,7 @@ private: AVFormatContext *avctx; // Protected by , iff write_strategy == WRITE_BACKGROUND. int plug_count = 0; // Protected by . + bool drained = false; // Protected by . // Protected by . If write_strategy == WRITE_FOREGROUND, // this is only in use when plugging. @@ -114,7 +125,8 @@ private: std::vector packet_queue; std::condition_variable packet_queue_ready; - AVStream *avstream_video, *avstream_audio; + std::vector streams; + int subtitle_stream_idx = -1; std::function write_callback; std::vector metrics;