Browse code

compute rects duration in ASS decoder

Signed-off-by: Aurelien Jacobs <aurel@gnuage.org>

Aurelien Jacobs authored on 2010/12/16 17:16:33
Showing 1 changed files
... ...
@@ -21,6 +21,7 @@
21 21
 
22 22
 #include "avcodec.h"
23 23
 #include "ass.h"
24
+#include "ass_split.h"
24 25
 
25 26
 static av_cold int ass_decode_init(AVCodecContext *avctx)
26 27
 {
... ...
@@ -29,6 +30,7 @@ static av_cold int ass_decode_init(AVCodecContext *avctx)
29 29
         return AVERROR(ENOMEM);
30 30
     memcpy(avctx->subtitle_header, avctx->extradata, avctx->extradata_size);
31 31
     avctx->subtitle_header_size = avctx->extradata_size;
32
+    avctx->priv_data = ff_ass_split(avctx->extradata);
32 33
     return 0;
33 34
 }
34 35
 
... ...
@@ -39,7 +41,9 @@ static int ass_decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr,
39 39
     int len, size = avpkt->size;
40 40
 
41 41
     while (size > 0) {
42
-        len = ff_ass_add_rect(data, ptr, 0, 0/* FIXME: duration */, 1);
42
+        ASSDialog *dialog = ff_ass_split_dialog(avctx->priv_data, ptr, 0, NULL);
43
+        int duration = dialog->end - dialog->start;
44
+        len = ff_ass_add_rect(data, ptr, 0, duration, 1);
43 45
         if (len < 0)
44 46
             return len;
45 47
         ptr  += len;
... ...
@@ -50,6 +54,13 @@ static int ass_decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr,
50 50
     return avpkt->size;
51 51
 }
52 52
 
53
+static int ass_decode_close(AVCodecContext *avctx)
54
+{
55
+    ff_ass_split_free(avctx->priv_data);
56
+    avctx->priv_data = NULL;
57
+    return 0;
58
+}
59
+
53 60
 AVCodec ff_ass_decoder = {
54 61
     .name         = "ass",
55 62
     .long_name    = NULL_IF_CONFIG_SMALL("Advanced SubStation Alpha subtitle"),
... ...
@@ -57,4 +68,5 @@ AVCodec ff_ass_decoder = {
57 57
     .id           = CODEC_ID_SSA,
58 58
     .init         = ass_decode_init,
59 59
     .decode       = ass_decode_frame,
60
+    .close        = ass_decode_close,
60 61
 };