dvdsub_parser.c

Go to the documentation of this file.
00001 /*
00002  * DVD subtitle decoding for ffmpeg
00003  * Copyright (c) 2005 Fabrice Bellard.
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 #include "avcodec.h"
00022 
00023 /* parser definition */
00024 typedef struct DVDSubParseContext {
00025     uint8_t *packet;
00026     int packet_len;
00027     int packet_index;
00028 } DVDSubParseContext;
00029 
00030 static int dvdsub_parse_init(AVCodecParserContext *s)
00031 {
00032     return 0;
00033 }
00034 
00035 static int dvdsub_parse(AVCodecParserContext *s,
00036                         AVCodecContext *avctx,
00037                         const uint8_t **poutbuf, int *poutbuf_size,
00038                         const uint8_t *buf, int buf_size)
00039 {
00040     DVDSubParseContext *pc = s->priv_data;
00041 
00042     if (pc->packet_index == 0) {
00043         if (buf_size < 2)
00044             return 0;
00045         pc->packet_len = AV_RB16(buf);
00046         if (pc->packet_len == 0) /* HD-DVD subpicture packet */
00047             pc->packet_len = AV_RB32(buf+2);
00048         av_freep(&pc->packet);
00049         pc->packet = av_malloc(pc->packet_len);
00050     }
00051     if (pc->packet) {
00052         if (pc->packet_index + buf_size <= pc->packet_len) {
00053             memcpy(pc->packet + pc->packet_index, buf, buf_size);
00054             pc->packet_index += buf_size;
00055             if (pc->packet_index >= pc->packet_len) {
00056                 *poutbuf = pc->packet;
00057                 *poutbuf_size = pc->packet_len;
00058                 pc->packet_index = 0;
00059                 return buf_size;
00060             }
00061         } else {
00062             /* erroneous size */
00063             pc->packet_index = 0;
00064         }
00065     }
00066     *poutbuf = NULL;
00067     *poutbuf_size = 0;
00068     return buf_size;
00069 }
00070 
00071 static void dvdsub_parse_close(AVCodecParserContext *s)
00072 {
00073     DVDSubParseContext *pc = s->priv_data;
00074     av_freep(&pc->packet);
00075 }
00076 
00077 AVCodecParser dvdsub_parser = {
00078     { CODEC_ID_DVD_SUBTITLE },
00079     sizeof(DVDSubParseContext),
00080     dvdsub_parse_init,
00081     dvdsub_parse,
00082     dvdsub_parse_close,
00083 };

Generated on Fri Jan 9 13:44:27 2009 for libextractor by  doxygen 1.5.1