• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

libavcodec/assdec.c

Go to the documentation of this file.
00001 /*
00002  * SSA/ASS decoder
00003  * Copyright (c) 2010  Aurelien Jacobs <aurel@gnuage.org>
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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 };

Generated on Wed Apr 11 2012 07:31:32 for FFmpeg by  doxygen 1.7.1