Normalize triplets in gain_val_tab[][] so gain_exp_tab[] can be just an
[ffmpeg-lucabe.git] / libavcodec / dvdsub_parser.c
blob0893daca658714598f2a2d9003a0dbb7ea1109f0
1 /*
2 * DVD subtitle decoding for ffmpeg
3 * Copyright (c) 2005 Fabrice Bellard.
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "avcodec.h"
23 /* parser definition */
24 typedef struct DVDSubParseContext {
25 uint8_t *packet;
26 int packet_len;
27 int packet_index;
28 } DVDSubParseContext;
30 static int dvdsub_parse_init(AVCodecParserContext *s)
32 return 0;
35 static int dvdsub_parse(AVCodecParserContext *s,
36 AVCodecContext *avctx,
37 const uint8_t **poutbuf, int *poutbuf_size,
38 const uint8_t *buf, int buf_size)
40 DVDSubParseContext *pc = s->priv_data;
42 if (pc->packet_index == 0) {
43 if (buf_size < 2)
44 return 0;
45 pc->packet_len = AV_RB16(buf);
46 if (pc->packet_len == 0) /* HD-DVD subpicture packet */
47 pc->packet_len = AV_RB32(buf+2);
48 av_freep(&pc->packet);
49 pc->packet = av_malloc(pc->packet_len);
51 if (pc->packet) {
52 if (pc->packet_index + buf_size <= pc->packet_len) {
53 memcpy(pc->packet + pc->packet_index, buf, buf_size);
54 pc->packet_index += buf_size;
55 if (pc->packet_index >= pc->packet_len) {
56 *poutbuf = pc->packet;
57 *poutbuf_size = pc->packet_len;
58 pc->packet_index = 0;
59 return buf_size;
61 } else {
62 /* erroneous size */
63 pc->packet_index = 0;
66 *poutbuf = NULL;
67 *poutbuf_size = 0;
68 return buf_size;
71 static void dvdsub_parse_close(AVCodecParserContext *s)
73 DVDSubParseContext *pc = s->priv_data;
74 av_freep(&pc->packet);
77 AVCodecParser dvdsub_parser = {
78 { CODEC_ID_DVD_SUBTITLE },
79 sizeof(DVDSubParseContext),
80 dvdsub_parse_init,
81 dvdsub_parse,
82 dvdsub_parse_close,