X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=shared%2Fmux.cpp;h=a52f21fbdab35b18bae0161cab70b9bd5d6013dd;hb=f9219370ce1f5ba37e716d50d41115bb672c4244;hp=b8feacd6907460cedb017a07626c64dca5ed10a7;hpb=68271fb0bddd8a48aa036428f2928a69a5e4e660;p=nageru diff --git a/shared/mux.cpp b/shared/mux.cpp index b8feacd..a52f21f 100644 --- a/shared/mux.cpp +++ b/shared/mux.cpp @@ -172,7 +172,9 @@ void Mux::add_packet(const AVPacket &pkt, int64_t pts, int64_t dts, AVRational t { lock_guard lock(mu); - if (write_strategy == WriteStrategy::WRITE_BACKGROUND) { + if (drained) { + // Just drop the packet on the floor. + } else if (write_strategy == WriteStrategy::WRITE_BACKGROUND) { packet_queue.push_back(QueuedPacket{ av_packet_clone(&pkt_copy), pts }); if (plug_count == 0) packet_queue_ready.notify_all(); @@ -218,6 +220,7 @@ void Mux::write_packet_or_die(const AVPacket &pkt, int64_t unscaled_pts) void Mux::plug() { lock_guard lock(mu); + assert(!drained); ++plug_count; } @@ -242,6 +245,25 @@ void Mux::unplug() } } +void Mux::drain() +{ + lock_guard lock(mu); + assert(!drained); + assert(plug_count == 0); + for (QueuedPacket &qp : packet_queue) { + av_packet_free(&qp.pkt); + } + packet_queue.clear(); + drained = true; +} + +void Mux::undrain() +{ + lock_guard lock(mu); + assert(drained); + drained = false; +} + void Mux::thread_func() { pthread_setname_np(pthread_self(), "Mux");