2828#include "htmlsubtitles.h"
2929
3030#ifdef MXTECHS
31- #include "mxsubdec.c"
32- #else
31+ #include "libavutil/opt.h"
32+ #endif
33+
34+ #ifdef MXTECHS
35+ typedef struct SubRipContext {
36+ AVClass * class ;
37+ FFASSDecoderContext ass_decoder_context ;
38+ int subtitle_type ;
39+ } SubRipContext ;
40+
41+ static int srt_init (AVCodecContext * avctx )
42+ {
43+ SubRipContext * s = avctx -> priv_data ;
44+ int ret = 0 ;
45+ if (s -> subtitle_type == SUBTITLE_ASS ) {
46+ ret = ff_ass_subtitle_header_default (avctx );
47+ }
48+ return ret ;
49+ }
50+ #endif
3351static int srt_to_ass (AVCodecContext * avctx , AVBPrint * dst ,
3452 const char * in , int x1 , int y1 , int x2 , int y2 )
3553{
@@ -55,15 +73,29 @@ static int srt_to_ass(AVCodecContext *avctx, AVBPrint *dst,
5573 return ff_htmlmarkup_to_ass (avctx , dst , in );
5674}
5775
76+ #ifdef MXTECHS
77+ #include "mxsubdec.c"
78+ #endif
79+
5880static int srt_decode_frame (AVCodecContext * avctx ,
5981 void * data , int * got_sub_ptr , AVPacket * avpkt )
6082{
83+ #ifdef MXTECHS
84+ SubRipContext * s2 = avctx -> priv_data ;
85+ if (s2 -> subtitle_type == SUBTITLE_TEXT ) {
86+ return mx_decode_frame (avctx , data , got_sub_ptr , avpkt );
87+ }
88+ #endif
6189 AVSubtitle * sub = data ;
6290 AVBPrint buffer ;
6391 int x1 = -1 , y1 = -1 , x2 = -1 , y2 = -1 ;
6492 int size , ret ;
6593 const uint8_t * p = av_packet_get_side_data (avpkt , AV_PKT_DATA_SUBTITLE_POSITION , & size );
94+ #ifdef MXTECHS
95+ FFASSDecoderContext * s = & s2 -> ass_decoder_context ;
96+ #else
6697 FFASSDecoderContext * s = avctx -> priv_data ;
98+ #endif
6799
68100 if (p && size == 16 ) {
69101 x1 = AV_RL32 (p );
@@ -87,19 +119,18 @@ static int srt_decode_frame(AVCodecContext *avctx,
87119 * got_sub_ptr = sub -> num_rects > 0 ;
88120 return avpkt -> size ;
89121}
90- #endif
91122
123+ #ifdef MXTECHS
124+ static void srt_flush (AVCodecContext * avctx )
125+ {
126+ SubRipContext * s = avctx -> priv_data ;
127+ if (s -> subtitle_type == SUBTITLE_ASS ) {
128+ ff_ass_decoder_flush (avctx );
129+ }
130+ }
131+ #endif
92132#if CONFIG_SRT_DECODER
93133/* deprecated decoder */
94- #ifdef MXTECHS
95- AVCodec ff_srt_decoder = {
96- .name = "srt" ,
97- .long_name = NULL_IF_CONFIG_SMALL ("SubRip subtitle" ),
98- .type = AVMEDIA_TYPE_SUBTITLE ,
99- .id = AV_CODEC_ID_SUBRIP ,
100- .decode = mx_decode_frame ,
101- };
102- #else
103134AVCodec ff_srt_decoder = {
104135 .name = "srt" ,
105136 .long_name = NULL_IF_CONFIG_SMALL ("SubRip subtitle" ),
@@ -111,16 +142,33 @@ AVCodec ff_srt_decoder = {
111142 .priv_data_size = sizeof (FFASSDecoderContext ),
112143};
113144#endif
114- #endif
115145
116146#if CONFIG_SUBRIP_DECODER
117147#ifdef MXTECHS
148+ #define OFFSET (x ) offsetof(SubRipContext, x)
149+ #define FLAGS AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
150+ static const AVOption options [] = {
151+ { "subtitle_type" , "Set the output subtitle type" , OFFSET (subtitle_type ), AV_OPT_TYPE_INT , {.i64 = SUBTITLE_TEXT }, SUBTITLE_TEXT , SUBTITLE_ASS , FLAGS },
152+ { NULL },
153+ };
154+
155+ static const AVClass srt_class = {
156+ .class_name = "Subrip Decoder" ,
157+ .item_name = av_default_item_name ,
158+ .option = options ,
159+ .version = LIBAVUTIL_VERSION_INT ,
160+ };
161+
118162AVCodec ff_subrip_decoder = {
119- .name = "subrip" ,
120- .long_name = NULL_IF_CONFIG_SMALL ("SubRip subtitle" ),
121- .type = AVMEDIA_TYPE_SUBTITLE ,
122- .id = AV_CODEC_ID_SUBRIP ,
123- .decode = mx_decode_frame ,
163+ .name = "subrip" ,
164+ .long_name = NULL_IF_CONFIG_SMALL ("SubRip subtitle" ),
165+ .type = AVMEDIA_TYPE_SUBTITLE ,
166+ .id = AV_CODEC_ID_SUBRIP ,
167+ .init = srt_init ,
168+ .decode = srt_decode_frame ,
169+ .flush = srt_flush ,
170+ .priv_data_size = sizeof (SubRipContext ),
171+ .priv_class = & srt_class ,
124172};
125173#else
126174AVCodec ff_subrip_decoder = {
0 commit comments