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
30
33 if(offs >= size){
35 return 0;
36 }
37 return offs;
38 }
39
41 void *
data,
int *got_frame,
43 {
45 int buf_size = avpkt->
size;
47 const uint8_t *buf_end, *buf_ptr;
49 uint32_t dqt_offs, dht_offs, sof_offs, sos_offs, second_field_offs;
50 uint32_t field_size, sod_offs;
52
54 buf_end = buf + buf_size;
56
58 /* reset on every SOI */
62
63 if (buf_end - buf_ptr >= 1 << 28)
65
66 init_get_bits(&hgb, buf_ptr,
/*buf_size*/(buf_end - buf_ptr)*8);
67
69
71 {
74 }
75
78 skip_bits(&hgb, 32);
/* padded field size */
79 second_field_offs =
read_offs(avctx, &hgb, buf_end - buf_ptr,
"second_field_offs is %d and size is %d\n");
81
82 dqt_offs =
read_offs(avctx, &hgb, buf_end - buf_ptr,
"dqt is %d and size is %d\n");
84 if (dqt_offs)
85 {
86 init_get_bits(&s->
gb, buf_ptr+dqt_offs, (buf_end - (buf_ptr+dqt_offs))*8);
91 }
92
93 dht_offs =
read_offs(avctx, &hgb, buf_end - buf_ptr,
"dht is %d and size is %d\n");
95 if (dht_offs)
96 {
97 init_get_bits(&s->
gb, buf_ptr+dht_offs, (buf_end - (buf_ptr+dht_offs))*8);
100 }
101
102 sof_offs =
read_offs(avctx, &hgb, buf_end - buf_ptr,
"sof is %d and size is %d\n");
104 if (sof_offs)
105 {
106 init_get_bits(&s->
gb, buf_ptr+sof_offs, (buf_end - (buf_ptr+sof_offs))*8);
109 return -1;
110 }
111
112 sos_offs =
read_offs(avctx, &hgb, buf_end - buf_ptr,
"sos is %d and size is %d\n");
114 sod_offs =
read_offs(avctx, &hgb, buf_end - buf_ptr,
"sof is %d and size is %d\n");
116 if (sos_offs)
117 {
119 8 *
FFMIN(field_size, buf_end - buf_ptr - sos_offs));
125 }
126
129 /* if not bottom field, do not output image yet */
131 {
132 buf_ptr = buf + second_field_offs;
134 }
135 }
136
137 //XXX FIXME factorize, this looks very similar to the EOI code
138
141 return buf_size;
142 }
143
146 *got_frame = 1;
147
151 }
152
153 return buf_size;
154 }
155
166 .max_lowres = 3,
167 };