• 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 Libav.
00006  *
00007  * Libav 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  * Libav 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 Libav; 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 
00025 static av_cold int ass_decode_init(AVCodecContext *avctx)
00026 {
00027     avctx->subtitle_header = av_malloc(avctx->extradata_size);
00028     if (!avctx->extradata)
00029         return AVERROR(ENOMEM);
00030     memcpy(avctx->subtitle_header, avctx->extradata, avctx->extradata_size);
00031     avctx->subtitle_header_size = avctx->extradata_size;
00032     return 0;
00033 }
00034 
00035 static int ass_decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr,
00036                             AVPacket *avpkt)
00037 {
00038     const char *ptr = avpkt->data;
00039     int len, size = avpkt->size;
00040 
00041     ff_ass_init(data);
00042 
00043     while (size > 0) {
00044         len = ff_ass_add_rect(data, ptr, 0, 0/* FIXME: duration */, 1);
00045         if (len < 0)
00046             return len;
00047         ptr  += len;
00048         size -= len;
00049     }
00050 
00051     *got_sub_ptr = avpkt->size > 0;
00052     return avpkt->size;
00053 }
00054 
00055 AVCodec ff_ass_decoder = {
00056     .name         = "ass",
00057     .long_name    = NULL_IF_CONFIG_SMALL("Advanced SubStation Alpha subtitle"),
00058     .type         = AVMEDIA_TYPE_SUBTITLE,
00059     .id           = CODEC_ID_SSA,
00060     .init         = ass_decode_init,
00061     .decode       = ass_decode_frame,
00062 };
Generated on Thu Jul 11 2013 15:38:18 for Libav by doxygen 1.7.1