From 781e9fcd6663cac6f36c5f554bd19237a4102d19 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 16 May 2019 16:36:23 +0200 Subject: demux: factor out a some packet queue code Might be helpful for later. The "duplicated" ds->reader_head check above the function call is redundant, but leaving it also for later. --- demux/demux.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'demux') diff --git a/demux/demux.c b/demux/demux.c index 97e5116bab..ff1573dca5 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -1821,6 +1821,27 @@ static void *demux_thread(void *pctx) return NULL; } +// Low-level part of dequeueing a packet. +static struct demux_packet *advance_reader_head(struct demux_stream *ds) +{ + struct demux_packet *pkt = ds->reader_head; + if (!pkt) + return NULL; + + ds->reader_head = pkt->next; + + // Update cached packet queue state. + ds->fw_packs--; + size_t bytes = demux_packet_estimate_total_size(pkt); + ds->fw_bytes -= bytes; + ds->in->fw_bytes -= bytes; + + ds->last_ret_pos = pkt->pos; + ds->last_ret_dts = pkt->dts; + + return pkt; +} + static struct demux_packet *dequeue_packet(struct demux_stream *ds) { if (ds->sh->attached_picture) { @@ -1836,17 +1857,7 @@ static struct demux_packet *dequeue_packet(struct demux_stream *ds) } if (!ds->reader_head || ds->in->blocked) return NULL; - struct demux_packet *pkt = ds->reader_head; - ds->reader_head = pkt->next; - - // Update cached packet queue state. - ds->fw_packs--; - size_t bytes = demux_packet_estimate_total_size(pkt); - ds->fw_bytes -= bytes; - ds->in->fw_bytes -= bytes; - - ds->last_ret_pos = pkt->pos; - ds->last_ret_dts = pkt->dts; + struct demux_packet *pkt = advance_reader_head(ds); // The returned packet is mutated etc. and will be owned by the user. pkt = demux_copy_packet(pkt); -- cgit v1.2.3