mirror of
https://github.com/mpv-player/mpv.git
synced 2025-12-28 05:33:14 +00:00
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.
This commit is contained in:
@@ -75,6 +75,17 @@ struct demux_packet *new_demux_packet_from_avpacket(struct AVPacket *avpkt)
|
||||
return dp;
|
||||
}
|
||||
|
||||
// (buf must include proper padding)
|
||||
struct demux_packet *new_demux_packet_from_buf(struct AVBufferRef *buf)
|
||||
{
|
||||
AVPacket pkt = {
|
||||
.size = buf->size,
|
||||
.data = buf->data,
|
||||
.buf = buf,
|
||||
};
|
||||
return new_demux_packet_from_avpacket(&pkt);
|
||||
}
|
||||
|
||||
// Input data doesn't need to be padded.
|
||||
struct demux_packet *new_demux_packet_from(void *data, size_t len)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user