00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 #include "avcodec.h"
00023 #include "ass.h"
00024 #include "ass_split.h"
00025 
00026 static av_cold int ass_decode_init(AVCodecContext *avctx)
00027 {
00028     avctx->subtitle_header = av_malloc(avctx->extradata_size);
00029     if (!avctx->extradata)
00030         return AVERROR(ENOMEM);
00031     memcpy(avctx->subtitle_header, avctx->extradata, avctx->extradata_size);
00032     avctx->subtitle_header_size = avctx->extradata_size;
00033     avctx->priv_data = ff_ass_split(avctx->extradata);
00034     return 0;
00035 }
00036 
00037 static int ass_decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr,
00038                             AVPacket *avpkt)
00039 {
00040     const char *ptr = avpkt->data;
00041     int len, size = avpkt->size;
00042 
00043     while (size > 0) {
00044         ASSDialog *dialog = ff_ass_split_dialog(avctx->priv_data, ptr, 0, NULL);
00045         int duration = dialog->end - dialog->start;
00046         len = ff_ass_add_rect(data, ptr, 0, duration, 1);
00047         if (len < 0)
00048             return len;
00049         ptr  += len;
00050         size -= len;
00051     }
00052 
00053     *got_sub_ptr = avpkt->size > 0;
00054     return avpkt->size;
00055 }
00056 
00057 static int ass_decode_close(AVCodecContext *avctx)
00058 {
00059     ff_ass_split_free(avctx->priv_data);
00060     avctx->priv_data = NULL;
00061     return 0;
00062 }
00063 
00064 AVCodec ff_ass_decoder = {
00065     .name         = "ass",
00066     .long_name    = NULL_IF_CONFIG_SMALL("Advanced SubStation Alpha subtitle"),
00067     .type         = AVMEDIA_TYPE_SUBTITLE,
00068     .id           = CODEC_ID_SSA,
00069     .init         = ass_decode_init,
00070     .decode       = ass_decode_frame,
00071     .close        = ass_decode_close,
00072 };