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->subtitle_header)
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 if(!avctx->priv_data)
00035 return -1;
00036 return 0;
00037 }
00038
00039 static int ass_decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr,
00040 AVPacket *avpkt)
00041 {
00042 const char *ptr = avpkt->data;
00043 int len, size = avpkt->size;
00044
00045 while (size > 0) {
00046 int duration;
00047 ASSDialog *dialog = ff_ass_split_dialog(avctx->priv_data, ptr, 0, NULL);
00048 if (!dialog)
00049 return AVERROR_INVALIDDATA;
00050 duration = dialog->end - dialog->start;
00051 len = ff_ass_add_rect(data, ptr, 0, duration, 1);
00052 if (len < 0)
00053 return len;
00054 ptr += len;
00055 size -= len;
00056 }
00057
00058 *got_sub_ptr = avpkt->size > 0;
00059 return avpkt->size;
00060 }
00061
00062 static int ass_decode_close(AVCodecContext *avctx)
00063 {
00064 ff_ass_split_free(avctx->priv_data);
00065 avctx->priv_data = NULL;
00066 return 0;
00067 }
00068
00069 AVCodec ff_ass_decoder = {
00070 .name = "ass",
00071 .long_name = NULL_IF_CONFIG_SMALL("Advanced SubStation Alpha subtitle"),
00072 .type = AVMEDIA_TYPE_SUBTITLE,
00073 .id = CODEC_ID_SSA,
00074 .init = ass_decode_init,
00075 .decode = ass_decode_frame,
00076 .close = ass_decode_close,
00077 };