summaryrefslogtreecommitdiffstats
path: root/demux/packet.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2017-04-14 19:19:44 +0200
committerwm4 <wm4@nowhere>2017-04-14 19:19:44 +0200
commit3709ce6718bed8a113d141cdf5e8198f22f3c5f7 (patch)
treeca5e9bd66f9f559365f630d6124592e48e7795e4 /demux/packet.c
parent3e8510d515e9446f7c1f2b4372e501a713bb2502 (diff)
downloadmpv-3709ce6718bed8a113d141cdf5e8198f22f3c5f7.tar.bz2
mpv-3709ce6718bed8a113d141cdf5e8198f22f3c5f7.tar.xz
demux: estimate total packet size, deprecate packet number limits
It's all explained in the DOCS changes. Although this option was always kind of obscure and pointless. Until it is removed, the only reason for setting it would be to raise the static default limit, so change its default to INT_MAX so that it does nothing by default.
Diffstat (limited to 'demux/packet.c')
-rw-r--r--demux/packet.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/demux/packet.c b/demux/packet.c
index 47f0cb87dc..9f9f97ea53 100644
--- a/demux/packet.c
+++ b/demux/packet.c
@@ -130,6 +130,32 @@ struct demux_packet *demux_copy_packet(struct demux_packet *dp)
return new;
}
+#define ROUND_ALLOC(s) MP_ALIGN_UP(s, 64)
+
+// Attempt to estimate the total memory consumption of the given packet.
+// This is important if we store thousands of packets and not to exceed
+// user-provided limits. Of course we can't know how much memory internal
+// fragmentation of the libc memory allocator will waste.
+// Note that this should return a "stable" value - e.g. if a new packet ref
+// is created, this should return the same value with the new ref. (This
+// implies the value is not exact and does not return the actual size of
+// memory wasted due to internal fragmentation.)
+size_t demux_packet_estimate_total_size(struct demux_packet *dp)
+{
+ size_t size = ROUND_ALLOC(sizeof(struct demux_packet));
+ size += ROUND_ALLOC(dp->len);
+ if (dp->avpacket) {
+ size += ROUND_ALLOC(sizeof(AVPacket));
+ size += ROUND_ALLOC(sizeof(AVBufferRef));
+ size += 64; // upper bound estimate on sizeof(AVBuffer)
+ size += ROUND_ALLOC(dp->avpacket->side_data_elems *
+ sizeof(dp->avpacket->side_data[0]));
+ for (int n = 0; n < dp->avpacket->side_data_elems; n++)
+ size += ROUND_ALLOC(dp->avpacket->side_data[n].size);
+ }
+ return size;
+}
+
int demux_packet_set_padding(struct demux_packet *dp, int start, int end)
{
#if LIBAVCODEC_VERSION_MICRO >= 100