Browse code

avcodec/dvbsubdec: Allow selecting the substream, or all substreams

Fixes Ticket 2161

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>

Michael Niedermayer authored on 2015/07/27 23:31:05
Showing 2 changed files
... ...
@@ -209,6 +209,8 @@ Never compute CLUT
209 209
 @item 1
210 210
 Always compute CLUT and override the one provided in the stream.
211 211
 @end table
212
+@item dvb_substream
213
+Selects the dvb substream, or all substreams if -1 which is default.
212 214
 
213 215
 @end table
214 216
 
... ...
@@ -238,6 +238,7 @@ typedef struct DVBSubContext {
238 238
     int compute_edt; /**< if 1 end display time calculated using pts
239 239
                           if 0 (Default) calculated using time out */
240 240
     int compute_clut;
241
+    int substream;
241 242
     int64_t prev_start;
242 243
     DVBSubRegion *region_list;
243 244
     DVBSubCLUT   *clut_list;
... ...
@@ -368,17 +369,22 @@ static av_cold int dvbsub_init_decoder(AVCodecContext *avctx)
368 368
     int i, r, g, b, a = 0;
369 369
     DVBSubContext *ctx = avctx->priv_data;
370 370
 
371
-    if (!avctx->extradata || (avctx->extradata_size < 4) || ((avctx->extradata_size % 5 != 0) && (avctx->extradata_size != 4))) {
371
+    if (ctx->substream < 0) {
372
+        ctx->composition_id = -1;
373
+        ctx->ancillary_id   = -1;
374
+    } else if (!avctx->extradata || (avctx->extradata_size < 4) || ((avctx->extradata_size % 5 != 0) && (avctx->extradata_size != 4))) {
372 375
         av_log(avctx, AV_LOG_WARNING, "Invalid DVB subtitles stream extradata!\n");
373 376
         ctx->composition_id = -1;
374 377
         ctx->ancillary_id   = -1;
375 378
     } else {
376
-        if (avctx->extradata_size > 5) {
377
-            av_log(avctx, AV_LOG_WARNING, "Decoding first DVB subtitles sub-stream\n");
379
+        if (avctx->extradata_size > 5*ctx->substream + 2) {
380
+            ctx->composition_id = AV_RB16(avctx->extradata + 5*ctx->substream);
381
+            ctx->ancillary_id   = AV_RB16(avctx->extradata + 5*ctx->substream + 2);
382
+        } else {
383
+            av_log(avctx, AV_LOG_WARNING, "Selected DVB subtitles sub-stream %d is not available\n", ctx->substream);
384
+            ctx->composition_id = AV_RB16(avctx->extradata);
385
+            ctx->ancillary_id   = AV_RB16(avctx->extradata + 2);
378 386
         }
379
-
380
-        ctx->composition_id = AV_RB16(avctx->extradata);
381
-        ctx->ancillary_id   = AV_RB16(avctx->extradata + 2);
382 387
     }
383 388
 
384 389
     ctx->version = -1;
... ...
@@ -1715,6 +1721,7 @@ end:
1715 1715
 static const AVOption options[] = {
1716 1716
     {"compute_edt", "compute end of time using pts or timeout", offsetof(DVBSubContext, compute_edt), FF_OPT_TYPE_INT, {.i64 = 0}, 0, 1, DS},
1717 1717
     {"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},
1718
+    {"dvb_substream", "", offsetof(DVBSubContext, substream), FF_OPT_TYPE_INT, {.i64 = -1}, -1, 63, DS},
1718 1719
     {NULL}
1719 1720
 };
1720 1721
 static const AVClass dvbsubdec_class = {