annotate dvdsub_parser.c @ 8520:a0164882aa38 libavcodec

Generic metadata API. avi is updated as example. No version bump, the API still might change slightly ... No update to ffmpeg.c as requested by aurel.
author michael
date Sun, 04 Jan 2009 18:48:37 +0000
parents 27b3ee661472
children 2acf0ae7b041
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4091
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
1 /*
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
2 * DVD subtitle decoding for ffmpeg
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
3 * Copyright (c) 2005 Fabrice Bellard.
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
4 *
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
5 * This file is part of FFmpeg.
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
6 *
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
11 *
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
15 * Lesser General Public License for more details.
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
16 *
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
20 */
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
21 #include "avcodec.h"
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
22
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
23 /* parser definition */
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
24 typedef struct DVDSubParseContext {
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
25 uint8_t *packet;
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
26 int packet_len;
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
27 int packet_index;
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
28 } DVDSubParseContext;
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
29
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
30 static int dvdsub_parse_init(AVCodecParserContext *s)
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
31 {
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
32 return 0;
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
33 }
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
34
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
35 static int dvdsub_parse(AVCodecParserContext *s,
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
36 AVCodecContext *avctx,
4931
0d1cc37d9430 make some parser parameters const to avoid casting const to non-const
aurel
parents: 4924
diff changeset
37 const uint8_t **poutbuf, int *poutbuf_size,
4091
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
38 const uint8_t *buf, int buf_size)
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
39 {
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
40 DVDSubParseContext *pc = s->priv_data;
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
41
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
42 if (pc->packet_index == 0) {
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
43 if (buf_size < 2)
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
44 return 0;
4438
fe3179006730 Remove the getbe16 functions and use the AV_RB16 macro instead. Patch by Ian
takis
parents: 4437
diff changeset
45 pc->packet_len = AV_RB16(buf);
5399
27b3ee661472 Update the dvdsub parser to be able to parse HD-DVD subtitle packets.
takis
parents: 4931
diff changeset
46 if (pc->packet_len == 0) /* HD-DVD subpicture packet */
27b3ee661472 Update the dvdsub parser to be able to parse HD-DVD subtitle packets.
takis
parents: 4931
diff changeset
47 pc->packet_len = AV_RB32(buf+2);
4091
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
48 av_freep(&pc->packet);
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
49 pc->packet = av_malloc(pc->packet_len);
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
50 }
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
51 if (pc->packet) {
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
52 if (pc->packet_index + buf_size <= pc->packet_len) {
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
53 memcpy(pc->packet + pc->packet_index, buf, buf_size);
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
54 pc->packet_index += buf_size;
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
55 if (pc->packet_index >= pc->packet_len) {
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
56 *poutbuf = pc->packet;
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
57 *poutbuf_size = pc->packet_len;
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
58 pc->packet_index = 0;
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
59 return buf_size;
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
60 }
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
61 } else {
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
62 /* erroneous size */
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
63 pc->packet_index = 0;
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
64 }
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
65 }
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
66 *poutbuf = NULL;
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
67 *poutbuf_size = 0;
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
68 return buf_size;
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
69 }
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
70
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
71 static void dvdsub_parse_close(AVCodecParserContext *s)
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
72 {
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
73 DVDSubParseContext *pc = s->priv_data;
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
74 av_freep(&pc->packet);
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
75 }
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
76
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
77 AVCodecParser dvdsub_parser = {
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
78 { CODEC_ID_DVD_SUBTITLE },
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
79 sizeof(DVDSubParseContext),
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
80 dvdsub_parse_init,
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
81 dvdsub_parse,
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
82 dvdsub_parse_close,
3c00eb82db0d Rename dvdsub.c to dvdsubdec.c.
diego
parents:
diff changeset
83 };