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.
This commit is contained in:
wm4 2017-01-31 14:48:10 +01:00
parent 55d6408526
commit 9c12d54afa
4 changed files with 54 additions and 1 deletions

View File

@ -69,6 +69,12 @@ elements_matroska = (
'BlockDuration, 9b, uint',
'ReferenceBlock*, fb, sint',
'DiscardPadding, 75A2, sint',
'BlockAdditions, 75A1, sub', (
'BlockMore*, A6, sub', (
'BlockAddID, EE, uint',
'BlockAdditional, A5, binary',
),
),
),
'SimpleBlock*, a3, binary',
),

View File

@ -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;

View File

@ -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;
}

View File

@ -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 */