X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Ftextdec.c;h=964da72ad530fff14668bf18bb9ba7571b6b1020;hb=b098e1a4697573d5c501aceb863d89ebf1fcd5fd;hp=a6c8722c1d5f5ef8e4ca3e487bedf5ada5bb58f0;hpb=32766877b4e1a7eeacfbca50c55d55ce8bb7b73d;p=ffmpeg diff --git a/libavcodec/textdec.c b/libavcodec/textdec.c index a6c8722c1d5..964da72ad53 100644 --- a/libavcodec/textdec.c +++ b/libavcodec/textdec.c @@ -32,6 +32,7 @@ typedef struct { AVClass *class; const char *linebreaks; int keep_ass_markup; + int readorder; } TextContext; #define OFFSET(x) offsetof(TextContext, x) @@ -48,15 +49,12 @@ static int text_decode_frame(AVCodecContext *avctx, void *data, AVBPrint buf; AVSubtitle *sub = data; const char *ptr = avpkt->data; - const TextContext *text = avctx->priv_data; - const int ts_start = av_rescale_q(avpkt->pts, avctx->time_base, (AVRational){1,100}); - const int ts_duration = avpkt->duration != -1 ? - av_rescale_q(avpkt->duration, avctx->time_base, (AVRational){1,100}) : -1; + TextContext *text = avctx->priv_data; av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED); if (ptr && avpkt->size > 0 && *ptr) { ff_ass_bprint_text_event(&buf, ptr, avpkt->size, text->linebreaks, text->keep_ass_markup); - ret = ff_ass_add_rect_bprint(sub, &buf, ts_start, ts_duration); + ret = ff_ass_add_rect(sub, buf.str, text->readorder++, 0, NULL, NULL); } av_bprint_finalize(&buf, NULL); if (ret < 0) @@ -65,6 +63,13 @@ static int text_decode_frame(AVCodecContext *avctx, void *data, return avpkt->size; } +static void text_flush(AVCodecContext *avctx) +{ + TextContext *text = avctx->priv_data; + if (!(avctx->flags2 & AV_CODEC_FLAG2_RO_FLUSH_NOOP)) + text->readorder = 0; +} + #define DECLARE_CLASS(decname) static const AVClass decname ## _decoder_class = { \ .class_name = #decname " decoder", \ .item_name = av_default_item_name, \ @@ -85,6 +90,7 @@ AVCodec ff_text_decoder = { .decode = text_decode_frame, .init = ff_ass_subtitle_header_default, .priv_class = &text_decoder_class, + .flush = text_flush, }; #endif @@ -110,6 +116,7 @@ AVCodec ff_vplayer_decoder = { .decode = text_decode_frame, .init = linebreak_init, .priv_class = &vplayer_decoder_class, + .flush = text_flush, }; #endif @@ -126,6 +133,7 @@ AVCodec ff_stl_decoder = { .decode = text_decode_frame, .init = linebreak_init, .priv_class = &stl_decoder_class, + .flush = text_flush, }; #endif @@ -142,6 +150,7 @@ AVCodec ff_pjs_decoder = { .decode = text_decode_frame, .init = linebreak_init, .priv_class = &pjs_decoder_class, + .flush = text_flush, }; #endif @@ -158,6 +167,7 @@ AVCodec ff_subviewer1_decoder = { .decode = text_decode_frame, .init = linebreak_init, .priv_class = &subviewer1_decoder_class, + .flush = text_flush, }; #endif