1 /*
2 * DVB subtitle parser for FFmpeg
3 * Copyright (c) 2005 Ian Caulfield
4 *
5 * This file is part of FFmpeg.
6 *
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.
11 *
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.
16 *
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
20 */
24
25 /* Parser (mostly) copied from dvdsub.c */
26
27 #define PARSE_BUF_SIZE (65536)
28
29
30 /* parser definition */
37
39 {
42
43 return 0;
44 }
45
48 const uint8_t **poutbuf,
int *poutbuf_size,
50 {
53 int i,
len, buf_pos = 0;
54
55 ff_dlog(avctx,
"DVB parse packet pts=%"PRIx64
", lpts=%"PRIx64
", cpts=%"PRIx64
":\n",
57
58 for (i=0; i < buf_size; i++)
59 {
60 ff_dlog(avctx,
"%02x ", buf[i]);
61 if (i % 16 == 15)
63 }
64
65 if (i % 16 != 0)
67
69 *poutbuf_size = 0;
70
72
74 {
76 {
77 ff_dlog(avctx,
"Discarding %d bytes\n",
79 }
80
83
84 if (buf_size < 2 || buf[0] != 0x20 || buf[1] != 0x00) {
85 ff_dlog(avctx,
"Bad packet header\n");
86 return -1;
87 }
88
89 buf_pos = 2;
90
92 } else {
94 {
96 {
99
102 } else {
105 }
106 }
107 }
108
110 return -1;
111
112 /* if not currently in a packet, discard data */
114 return buf_size;
115
118
121
122 while (p < p_end)
123 {
124 if (*p == 0x0f)
125 {
126 if (6 <= p_end - p)
127 {
129
130 if (len + 6 <= p_end - p)
131 {
132 *poutbuf_size += len + 6;
133
134 p += len + 6;
135 } else
136 break;
137 } else
138 break;
139 } else if (*p == 0xff) {
140 if (1 < p_end - p)
141 {
142 ff_dlog(avctx,
"Junk at end of packet\n");
143 }
146 break;
147 } else {
149
152 break;
153 }
154 }
155
156 if (*poutbuf_size > 0)
157 {
160 }
161
164
165 return buf_size;
166 }
167
169 {
172 }
173
180 };
AVCodecParser ff_dvbsub_parser
static av_cold void dvbsub_parse_close(AVCodecParserContext *s)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
static av_cold int dvbsub_parse_init(AVCodecParserContext *s)
static int dvbsub_parse(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size)
bitstream reader API header.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int64_t cur_frame_pts[AV_PARSER_PTS_NB]
Libavcodec external API header.
main external API structure.
int cur_frame_start_index
common internal api header.
#define AV_NOPTS_VALUE
Undefined timestamp value.