summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-07-07 19:25:51 +0200
committerwm4 <wm4@nowhere>2019-09-19 20:37:05 +0200
commit226e050b83b1c9946c52ae77b78a63e82a3ae628 (patch)
treee94ad851bae6b60f25aac4ae571a06254f3735b4
parentc43846f2cb51054a5c74f95a1bc167542b8437f6 (diff)
downloadmpv-226e050b83b1c9946c52ae77b78a63e82a3ae628.tar.bz2
mpv-226e050b83b1c9946c52ae77b78a63e82a3ae628.tar.xz
demux: move packet cache reading to a function
Useful for a following commit.
-rw-r--r--demux/demux.c41
1 files changed, 27 insertions, 14 deletions
diff --git a/demux/demux.c b/demux/demux.c
index 8195e5bd17..6c03c71930 100644
--- a/demux/demux.c
+++ b/demux/demux.c
@@ -2487,6 +2487,32 @@ static struct demux_packet *advance_reader_head(struct demux_stream *ds)
return pkt;
}
+// Return a newly allocated new packet. The pkt parameter may be either a
+// in-memory packet (then a new reference is made), or a reference to
+// packet in the disk cache (then the packet is read from disk).
+static struct demux_packet *read_packet_from_cache(struct demux_internal *in,
+ struct demux_packet *pkt)
+{
+ if (!pkt)
+ return NULL;
+
+ if (pkt->is_cached) {
+ assert(in->cache);
+ struct demux_packet *meta = pkt;
+ pkt = demux_cache_read(in->cache, pkt->cached_data.pos);
+ if (pkt) {
+ demux_packet_copy_attribs(pkt, meta);
+ } else {
+ MP_ERR(in, "Failed to retrieve packet from cache.\n");
+ }
+ } else {
+ // The returned packet is mutated etc. and will be owned by the user.
+ pkt = demux_copy_packet(pkt);
+ }
+
+ return pkt;
+}
+
// Returns:
// < 0: EOF was reached, *res is not set
// == 0: no new packet yet, wait, *res is not set
@@ -2562,20 +2588,7 @@ static int dequeue_packet(struct demux_stream *ds, struct demux_packet **res)
struct demux_packet *pkt = advance_reader_head(ds);
assert(pkt);
-
- if (pkt->is_cached) {
- assert(in->cache);
- struct demux_packet *meta = pkt;
- pkt = demux_cache_read(in->cache, pkt->cached_data.pos);
- if (pkt) {
- demux_packet_copy_attribs(pkt, meta);
- } else {
- MP_ERR(in, "Failed to retrieve packet from cache.\n");
- }
- } else {
- // The returned packet is mutated etc. and will be owned by the user.
- pkt = demux_copy_packet(pkt);
- }
+ pkt = read_packet_from_cache(in, pkt);
if (!pkt)
return 0;