From 9c12d54afa70f3535a7114498433cf566a9e9a86 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 31 Jan 2017 14:48:10 +0100 Subject: demux_mkv: passthrough BlockAdditions for libvpx alpha Dumb but simple thing. Requires the FFmpeg libvpx decoder wrapper, as its native decoder doesn't support alpha. --- demux/demux_mkv.c | 27 +++++++++++++++++++++++++++ demux/packet.c | 20 +++++++++++++++++++- demux/packet.h | 2 ++ 3 files changed, 48 insertions(+), 1 deletion(-) (limited to 'demux') diff --git a/demux/demux_mkv.c b/demux/demux_mkv.c index 5db975926e..d564999fc6 100644 --- a/demux/demux_mkv.c +++ b/demux/demux_mkv.c @@ -162,6 +162,7 @@ struct block_info { bstr data; void *alloc; int64_t filepos; + struct ebml_block_additions *additions; }; typedef struct mkv_demuxer { @@ -2392,6 +2393,8 @@ static void free_block(struct block_info *block) free(block->alloc); block->alloc = NULL; block->data = (bstr){0}; + talloc_free(block->additions); + block->additions = NULL; } static void index_block(demuxer_t *demuxer, struct block_info *block) @@ -2552,6 +2555,15 @@ static int handle_block(demuxer_t *demuxer, struct block_info *block_info) block_info->discardpadding / 1e9 * srate); mkv_d->a_skip_preroll = 0; } + if (block_info->additions) { + for (int n = 0; n < block_info->additions->n_block_more; n++) { + struct ebml_block_more *add = + &block_info->additions->block_more[n]; + int64_t id = add->n_block_add_id ? add->block_add_id : 1; + demux_packet_add_blockadditional(dp, id, + add->block_additional.start, add->block_additional.len); + } + } mkv_parse_and_add_packet(demuxer, track, dp); talloc_free_children(track->parser_tmp); @@ -2607,6 +2619,21 @@ static int read_block_group(demuxer_t *demuxer, int64_t end, block->keyframe = false; break; + case MATROSKA_ID_BLOCKADDITIONS:; + struct ebml_block_additions additions = {0}; + struct ebml_parse_ctx parse_ctx = {demuxer->log}; + if (ebml_read_element(s, &parse_ctx, &additions, + &ebml_block_additions_desc) < 0) + return -1; + if (additions.n_block_more > 0) { + block->additions = + talloc_memdup(NULL, &additions, sizeof(additions)); + talloc_steal(block->additions, parse_ctx.talloc_ctx); + parse_ctx.talloc_ctx = NULL; + } + talloc_free(parse_ctx.talloc_ctx); + break; + case MATROSKA_ID_CLUSTER: case EBML_ID_INVALID: goto error; diff --git a/demux/packet.c b/demux/packet.c index b33d5b618e..4ee9253ebf 100644 --- a/demux/packet.c +++ b/demux/packet.c @@ -133,7 +133,7 @@ struct demux_packet *demux_copy_packet(struct demux_packet *dp) int demux_packet_set_padding(struct demux_packet *dp, int start, int end) { #if LIBAVCODEC_VERSION_MICRO >= 100 - if (!start && !end) + if (!start && !end) return 0; if (!dp->avpacket) return -1; @@ -146,3 +146,21 @@ int demux_packet_set_padding(struct demux_packet *dp, int start, int end) #endif return 0; } + +int demux_packet_add_blockadditional(struct demux_packet *dp, uint64_t id, + void *data, size_t size) +{ +#if LIBAVCODEC_VERSION_MICRO >= 100 + if (!dp->avpacket) + return -1; + uint8_t *sd = av_packet_new_side_data(dp->avpacket, + AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL, + 8 + size); + if (!sd) + return -1; + AV_WB64(sd, id); + if (size > 0) + memcpy(sd + 8, data, size); +#endif + return 0; +} diff --git a/demux/packet.h b/demux/packet.h index 723dbc7e54..d669d02376 100644 --- a/demux/packet.h +++ b/demux/packet.h @@ -55,5 +55,7 @@ struct demux_packet *demux_copy_packet(struct demux_packet *dp); void demux_packet_copy_attribs(struct demux_packet *dst, struct demux_packet *src); int demux_packet_set_padding(struct demux_packet *dp, int start, int end); +int demux_packet_add_blockadditional(struct demux_packet *dp, uint64_t id, + void *data, size_t size); #endif /* MPLAYER_DEMUX_PACKET_H */ -- cgit v1.2.3