]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/assdec.c
Use MAP_FAILED to check for mmap failure instead of manually
[ffmpeg] / libavcodec / assdec.c
index c1ad0c4af45c3d9ecbb8a70ca00d62fe1b628361..087a0c839b35e97af9f84bce1e23ecfda40d14d7 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "avcodec.h"
 #include "ass.h"
+#include "ass_split.h"
 
 static av_cold int ass_decode_init(AVCodecContext *avctx)
 {
@@ -29,6 +30,7 @@ static av_cold int ass_decode_init(AVCodecContext *avctx)
         return AVERROR(ENOMEM);
     memcpy(avctx->subtitle_header, avctx->extradata, avctx->extradata_size);
     avctx->subtitle_header_size = avctx->extradata_size;
+    avctx->priv_data = ff_ass_split(avctx->extradata);
     return 0;
 }
 
@@ -38,10 +40,10 @@ static int ass_decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr,
     const char *ptr = avpkt->data;
     int len, size = avpkt->size;
 
-    ff_ass_init(data);
-
     while (size > 0) {
-        len = ff_ass_add_rect(data, ptr, 0, 0/* FIXME: duration */, 1);
+        ASSDialog *dialog = ff_ass_split_dialog(avctx->priv_data, ptr, 0, NULL);
+        int duration = dialog->end - dialog->start;
+        len = ff_ass_add_rect(data, ptr, 0, duration, 1);
         if (len < 0)
             return len;
         ptr  += len;
@@ -52,6 +54,13 @@ static int ass_decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr,
     return avpkt->size;
 }
 
+static int ass_decode_close(AVCodecContext *avctx)
+{
+    ff_ass_split_free(avctx->priv_data);
+    avctx->priv_data = NULL;
+    return 0;
+}
+
 AVCodec ff_ass_decoder = {
     .name         = "ass",
     .long_name    = NULL_IF_CONFIG_SMALL("Advanced SubStation Alpha subtitle"),
@@ -59,4 +68,5 @@ AVCodec ff_ass_decoder = {
     .id           = CODEC_ID_SSA,
     .init         = ass_decode_init,
     .decode       = ass_decode_frame,
+    .close        = ass_decode_close,
 };