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 */
21
22 #include <inttypes.h>
23 #include <string.h>
24
26
29
30 /* Parser (mostly) copied from dvdsub.c */
31
32 #define PARSE_BUF_SIZE (65536)
33
34
35 /* parser definition */
42
45 const uint8_t **poutbuf, int *poutbuf_size,
46 const uint8_t *buf, int buf_size)
47 {
49 uint8_t *p, *p_end;
50 int i,
len, buf_pos = 0;
52
53 ff_dlog(avctx,
"DVB parse packet pts=%"PRIx64
", lpts=%"PRIx64
", cpts=%"PRIx64
":\n",
54 s->pts,
s->last_pts,
s->cur_frame_pts[
s->cur_frame_start_index]);
55
56 for (
i=0;
i < buf_size;
i++)
57 {
61 }
62
65
66 *poutbuf = buf;
67 *poutbuf_size = buf_size;
68
69 s->fetch_timestamp = 1;
70
71 if (
s->last_pts !=
s->pts &&
s->pts !=
AV_NOPTS_VALUE)
/* Start of a new packet */
72 {
74 {
75 ff_dlog(avctx,
"Discarding %d bytes\n",
77 }
78
81
82 if (buf_size < 2 || buf[0] != 0x20 || buf[1] != 0x00) {
83 ff_dlog(avctx,
"Bad packet header\n");
84 return buf_size;
85 }
86
87 buf_pos = 2;
88
90 } else {
92 {
94 {
97
100 } else {
103 }
104 }
105 }
106
108 return buf_size;
109
110 /* if not currently in a packet, pass data */
112 return buf_size;
113
116
119
120 while (p < p_end)
121 {
122 if (*p == 0x0f)
123 {
124 if (6 <= p_end - p)
125 {
127
128 if (
len + 6 <= p_end - p)
129 {
131
133 } else
134 break;
135 } else
136 break;
137 } else if (*p == 0xff) {
138 if (1 < p_end - p)
139 {
140 ff_dlog(avctx,
"Junk at end of packet\n");
141 }
144 break;
145 } else {
147
150 break;
151 }
152 }
153
155 {
159 }
160
162 s->pts =
s->last_pts;
163
164 return buf_size;
165 }
166
171 };