-void Mux::add_interleaved_packet(const AVPacket &pkt)
-{
- if (waiting_packets.empty() || waiting_packets.front()->stream_index == pkt.stream_index) {
- // We could still get packets of the other type with earlier pts/dts,
- // so we'll have to queue and wait.
- waiting_packets.push(av_packet_clone(const_cast<AVPacket *>(&pkt)));
- return;
- }
-
- // Flush all the queued packets that are supposed to go before this.
- PacketBefore before(avctx);
- while (!waiting_packets.empty() && !before(&pkt, waiting_packets.front())) {
- AVPacket *queued_pkt = waiting_packets.front();
- waiting_packets.pop();
- write_packet_with_signal(*queued_pkt);
- av_packet_unref(queued_pkt);
- }
-
- if (waiting_packets.empty()) {
- waiting_packets.push(av_packet_clone(const_cast<AVPacket *>(&pkt)));
- } else {
- write_packet_with_signal(pkt);
+ // Note: This will be wrong in the case of plugged packets, but that only happens
+ // for network streams, not for files, and write callbacks are only really relevant
+ // for files. (We don't want to do this from write_packet_or_die, as it only has
+ // the rescaled pts, which is unsuitable for callback.)
+ if (pkt.stream_index == 0 && write_callback != nullptr) {
+ write_callback(pts);