1 /*
2 * MxPEG clip file demuxer
3 * Copyright (c) 2010 Anatoly Nenashev
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
31
32 #define DEFAULT_PACKET_SIZE 1024
33 #define OVERREAD_SIZE 3
34
43
45 {
48
49 /* video parameters will be extracted from the compressed bitstream */
56
67
72
73 return 0;
74 }
75
77 {
78 for (;
p < end - 3;
p += 4) {
80
81 if (x & (~(x+0x01010101)) & 0x80808080) {
84 }
else if (
p[1] == 0xff) {
86 }
else if (
p[2] == 0xff) {
88 }
else if (
p[3] == 0xff) {
90 }
91 }
92 }
93
94 for (;
p < end; ++
p) {
95 if (*
p == 0xff)
return p;
96 }
97
98 return end;
99 }
100
102 {
105 unsigned int soi_pos;
108
109 /* reallocate internal buffer */
110 if (current_pos > current_pos + cache_size)
114 current_pos + cache_size +
121
122 /* get data */
127
129
131
133 }
134
136 {
139 uint8_t *startmarker_ptr, *end, *search_end, marker;
141
144 /* update internal buffer */
148 }
150
151 /* find start marker - 0xff */
155 } else {
156 search_end = end;
158 if (startmarker_ptr >= search_end - 1 ||
159 *(startmarker_ptr + 1) !=
EOI)
break;
160 }
161
162 if (startmarker_ptr != search_end) { /* start marker found */
163 marker = *(startmarker_ptr + 1);
166
168 mxg->
soi_ptr = startmarker_ptr;
169 }
else if (marker ==
EOI) {
172 continue;
173 }
174
180
183
187 }
188
190 }
192
194 }
else if ( (
SOF0 <= marker && marker <=
SOF15) ||
195 (
SOS <= marker && marker <=
COM) ) {
196 /* all other markers that start marker segment also contain
197 length value (see specification for JPEG Annex B.1) */
201
208 } else {
210 }
211
213
214 if (marker ==
APP13 &&
size >= 16) {
/* audio data */
218 memcpy(
pkt->
data, startmarker_ptr + 16,
size - 14);
219
220 /* time (GMT) of first sample in usec since 1970, little-endian */
223
227 }
229 }
230
232 }
else if (marker ==
COM &&
size >= 18 &&
233 !strncmp(startmarker_ptr + 4, "MXF", 3)) {
234 /* time (GMT) of video frame in usec since 1970, little-endian */
236 }
237 }
238 } else {
239 /* start marker not found */
242 }
243 }
244
246 }
247
249 {
252 return 0;
253 }
254
258 .p.extensions = "mxg",
263 };