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) {
82 if (p[0] == 0xff) {
83 return p;
84 } else if (p[1] == 0xff) {
85 return p+1;
86 } else if (p[2] == 0xff) {
87 return p+2;
88 } else if (p[3] == 0xff) {
89 return p+3;
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 }
132
134 {
137 uint8_t *startmarker_ptr, *end, *search_end, marker;
139
142 /* update internal buffer */
146 }
148
149 /* find start marker - 0xff */
153 } else {
154 search_end = end;
156 if (startmarker_ptr >= search_end - 1 ||
157 *(startmarker_ptr + 1) !=
EOI)
break;
158 }
159
160 if (startmarker_ptr != search_end) { /* start marker found */
161 marker = *(startmarker_ptr + 1);
164
166 mxg->
soi_ptr = startmarker_ptr;
167 }
else if (marker ==
EOI) {
170 continue;
171 }
172
178
181
185 }
186
188 }
190
192 }
else if ( (
SOF0 <= marker && marker <=
SOF15) ||
193 (
SOS <= marker && marker <=
COM) ) {
194 /* all other markers that start marker segment also contain
195 length value (see specification for JPEG Annex B.1) */
199
206 } else {
208 }
209
211
212 if (marker ==
APP13 &&
size >= 16) {
/* audio data */
216 memcpy(
pkt->
data, startmarker_ptr + 16,
size - 14);
217
218 /* time (GMT) of first sample in usec since 1970, little-endian */
221
225 }
227 }
228
230 }
else if (marker ==
COM &&
size >= 18 &&
231 !strncmp(startmarker_ptr + 4, "MXF", 3)) {
232 /* time (GMT) of video frame in usec since 1970, little-endian */
234 }
235 }
236 } else {
237 /* start marker not found */
240 }
241 }
242
244 }
245
247 {
250 return 0;
251 }
252
256 .p.extensions = "mxg",
261 };