1 /*
2 * Apple MJPEG-B decoder
3 * Copyright (c) 2002 Alex Beregszaszi
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 /**
23 * @file
24 * Apple MJPEG-B decoder.
25 */
26
27 #include <inttypes.h>
28
32
35 if(offs >= size){
37 return 0;
38 }
39 return offs;
40 }
41
43 void *
data,
int *got_frame,
45 {
47 int buf_size = avpkt->
size;
49 const uint8_t *buf_end, *buf_ptr;
51 uint32_t dqt_offs, dht_offs, sof_offs, sos_offs, second_field_offs;
52 uint32_t field_size, sod_offs;
54
56 buf_end = buf + buf_size;
58
60 /* reset on every SOI */
64
65 if (buf_end - buf_ptr >= 1 << 28)
67
68 init_get_bits(&hgb, buf_ptr,
/*buf_size*/(buf_end - buf_ptr)*8);
69
71
73 {
76 }
77
80 skip_bits(&hgb, 32);
/* padded field size */
81 second_field_offs =
read_offs(avctx, &hgb, buf_end - buf_ptr,
"second_field_offs is %d and size is %d\n");
83 second_field_offs);
84
85 dqt_offs =
read_offs(avctx, &hgb, buf_end - buf_ptr,
"dqt is %d and size is %d\n");
87 if (dqt_offs)
88 {
89 init_get_bits(&s->
gb, buf_ptr+dqt_offs, (buf_end - (buf_ptr+dqt_offs))*8);
94 }
95
96 dht_offs =
read_offs(avctx, &hgb, buf_end - buf_ptr,
"dht is %d and size is %d\n");
98 if (dht_offs)
99 {
100 init_get_bits(&s->
gb, buf_ptr+dht_offs, (buf_end - (buf_ptr+dht_offs))*8);
103 }
104
105 sof_offs =
read_offs(avctx, &hgb, buf_end - buf_ptr,
"sof is %d and size is %d\n");
107 if (sof_offs)
108 {
109 init_get_bits(&s->
gb, buf_ptr+sof_offs, (buf_end - (buf_ptr+sof_offs))*8);
112 return -1;
113 }
114
115 sos_offs =
read_offs(avctx, &hgb, buf_end - buf_ptr,
"sos is %d and size is %d\n");
117 sod_offs =
read_offs(avctx, &hgb, buf_end - buf_ptr,
"sof is %d and size is %d\n");
119 if (sos_offs)
120 {
122 8 *
FFMIN(field_size, buf_end - buf_ptr - sos_offs));
128 }
129
132 /* if not bottom field, do not output image yet */
134 {
135 buf_ptr = buf + second_field_offs;
137 }
138 }
139
140 //XXX FIXME factorize, this looks very similar to the EOI code
141
144 return buf_size;
145 }
146
149 *got_frame = 1;
150
154 }
155
156 return buf_size;
157 }
158
169 .max_lowres = 3,
170 };