From 9e1fbffc37779c8f491d3aa8e319ab233e5ab0da Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 5 Nov 2017 16:36:18 +0100 Subject: demux_mkv: rewrite packet reading to avoid 1 memcpy() This directly reads individual mkv sub-packets (block laces) into a dedicated AVBufferRefs, which can be directly used for creating packets without a additional copy of the packet data. This also means we switch parsing of block header fields and lacing metadata to read directly from the stream, instead of a memory buffer. This could have been much easier if libavcodec didn't require padding the packet data with zero bytes. We could just have each packet reference a slice of the block data. But as it is, the only way to get padding without a copy is to read the laces into individually allocated (and padded) memory block, which required a larger rewrite. This probably makes recovering from broken mkv files slightly worse if the transport is unseekable. We just read, and then check if we've overread. But I think that shouldn't be a real concern. No actual measureable performance change. Potential for some regressions, as this is quite intrusive, and touches weird obscure shit like mkv lacing. Still keeping it because I like how it removes some redundant EBML parsing functions. --- demux/packet.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'demux/packet.h') diff --git a/demux/packet.h b/demux/packet.h index 93a7f49cc9..f551e0c7f5 100644 --- a/demux/packet.h +++ b/demux/packet.h @@ -46,9 +46,12 @@ typedef struct demux_packet { double kf_seek_pts; // demux.c internal: seek pts for keyframe range } demux_packet_t; +struct AVBufferRef; + struct demux_packet *new_demux_packet(size_t len); struct demux_packet *new_demux_packet_from_avpacket(struct AVPacket *avpkt); struct demux_packet *new_demux_packet_from(void *data, size_t len); +struct demux_packet *new_demux_packet_from_buf(struct AVBufferRef *buf); void demux_packet_shorten(struct demux_packet *dp, size_t len); void free_demux_packet(struct demux_packet *dp); struct demux_packet *demux_copy_packet(struct demux_packet *dp); -- cgit v1.2.3