From 3f87a17063314dd161d389761f5baa1cda8e61f1 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Mon, 27 Jul 2015 16:31:05 +0200 Subject: avcodec/dvbsubdec: Allow selecting the substream, or all substreams Fixes Ticket 2161 Signed-off-by: Michael Niedermayer --- libavcodec/dvbsubdec.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'libavcodec/dvbsubdec.c') diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c index ce03e12d4a..71dd1fea8b 100644 --- a/libavcodec/dvbsubdec.c +++ b/libavcodec/dvbsubdec.c @@ -238,6 +238,7 @@ typedef struct DVBSubContext { int compute_edt; /**< if 1 end display time calculated using pts if 0 (Default) calculated using time out */ int compute_clut; + int substream; int64_t prev_start; DVBSubRegion *region_list; DVBSubCLUT *clut_list; @@ -368,17 +369,22 @@ static av_cold int dvbsub_init_decoder(AVCodecContext *avctx) int i, r, g, b, a = 0; DVBSubContext *ctx = avctx->priv_data; - if (!avctx->extradata || (avctx->extradata_size < 4) || ((avctx->extradata_size % 5 != 0) && (avctx->extradata_size != 4))) { + if (ctx->substream < 0) { + ctx->composition_id = -1; + ctx->ancillary_id = -1; + } else if (!avctx->extradata || (avctx->extradata_size < 4) || ((avctx->extradata_size % 5 != 0) && (avctx->extradata_size != 4))) { av_log(avctx, AV_LOG_WARNING, "Invalid DVB subtitles stream extradata!\n"); ctx->composition_id = -1; ctx->ancillary_id = -1; } else { - if (avctx->extradata_size > 5) { - av_log(avctx, AV_LOG_WARNING, "Decoding first DVB subtitles sub-stream\n"); + if (avctx->extradata_size > 5*ctx->substream + 2) { + ctx->composition_id = AV_RB16(avctx->extradata + 5*ctx->substream); + ctx->ancillary_id = AV_RB16(avctx->extradata + 5*ctx->substream + 2); + } else { + av_log(avctx, AV_LOG_WARNING, "Selected DVB subtitles sub-stream %d is not available\n", ctx->substream); + ctx->composition_id = AV_RB16(avctx->extradata); + ctx->ancillary_id = AV_RB16(avctx->extradata + 2); } - - ctx->composition_id = AV_RB16(avctx->extradata); - ctx->ancillary_id = AV_RB16(avctx->extradata + 2); } ctx->version = -1; @@ -1715,6 +1721,7 @@ end: static const AVOption options[] = { {"compute_edt", "compute end of time using pts or timeout", offsetof(DVBSubContext, compute_edt), FF_OPT_TYPE_INT, {.i64 = 0}, 0, 1, DS}, {"compute_clut", "compute clut when not available(-1) or always(1) or never(0)", offsetof(DVBSubContext, compute_clut), FF_OPT_TYPE_INT, {.i64 = -1}, -1, 1, DS}, + {"dvb_substream", "", offsetof(DVBSubContext, substream), FF_OPT_TYPE_INT, {.i64 = -1}, -1, 63, DS}, {NULL} }; static const AVClass dvbsubdec_class = { -- cgit v1.2.3