4 * This file is part of Libav.
6 * Libav is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * Libav is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Libav; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "mpegutils.h"
22 #include "mpegvideo.h"
24 #include "mpegvideodata.h"
26 /* don't understand why they choose a different header ! */
27 int ff_intel_h263_decode_picture_header(MpegEncContext *s)
31 if (get_bits_left(&s->gb) == 64) { /* special dummy frames */
36 if (get_bits_long(&s->gb, 22) != 0x20) {
37 av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
40 s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */
42 if (get_bits1(&s->gb) != 1) {
43 av_log(s->avctx, AV_LOG_ERROR, "Bad marker\n");
44 return -1; /* marker */
46 if (get_bits1(&s->gb) != 0) {
47 av_log(s->avctx, AV_LOG_ERROR, "Bad H.263 id\n");
48 return -1; /* H.263 id */
50 skip_bits1(&s->gb); /* split screen off */
51 skip_bits1(&s->gb); /* camera off */
52 skip_bits1(&s->gb); /* freeze picture release off */
54 format = get_bits(&s->gb, 3);
55 if (format == 0 || format == 6) {
56 av_log(s->avctx, AV_LOG_ERROR, "Intel H.263 free format not supported\n");
61 s->pict_type = AV_PICTURE_TYPE_I + get_bits1(&s->gb);
63 s->unrestricted_mv = get_bits1(&s->gb);
64 s->h263_long_vectors = s->unrestricted_mv;
66 if (get_bits1(&s->gb) != 0) {
67 av_log(s->avctx, AV_LOG_ERROR, "SAC not supported\n");
68 return -1; /* SAC: off */
70 s->obmc= get_bits1(&s->gb);
71 s->pb_frame = get_bits1(&s->gb);
74 s->width = ff_h263_format[format][0];
75 s->height = ff_h263_format[format][1];
76 s->avctx->sample_aspect_ratio.num = 12;
77 s->avctx->sample_aspect_ratio.den = 11;
79 format = get_bits(&s->gb, 3);
80 if(format == 0 || format == 7){
81 av_log(s->avctx, AV_LOG_ERROR, "Wrong Intel H.263 format\n");
84 if(get_bits(&s->gb, 2))
85 av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
86 s->loop_filter = get_bits1(&s->gb);
88 av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
91 if(get_bits(&s->gb, 5))
92 av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
93 if(get_bits(&s->gb, 5) != 1)
94 av_log(s->avctx, AV_LOG_ERROR, "Invalid marker\n");
97 int ar = get_bits(&s->gb, 4);
98 skip_bits(&s->gb, 9); // display width
100 skip_bits(&s->gb, 9); // display height
102 s->avctx->sample_aspect_ratio.num = get_bits(&s->gb, 8); // aspect ratio - width
103 s->avctx->sample_aspect_ratio.den = get_bits(&s->gb, 8); // aspect ratio - height
105 s->avctx->sample_aspect_ratio = ff_h263_pixel_aspect[ar];
107 if (s->avctx->sample_aspect_ratio.num == 0)
108 av_log(s->avctx, AV_LOG_ERROR, "Invalid aspect ratio.\n");
111 s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
112 skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
115 skip_bits(&s->gb, 3); //temporal reference for B-frame
116 skip_bits(&s->gb, 2); //dbquant
120 while (get_bits1(&s->gb) != 0) {
121 skip_bits(&s->gb, 8);
126 s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
128 ff_h263_show_pict_info(s);
133 AVCodec ff_h263i_decoder = {
135 .long_name = NULL_IF_CONFIG_SMALL("Intel H.263"),
136 .type = AVMEDIA_TYPE_VIDEO,
137 .id = AV_CODEC_ID_H263I,
138 .priv_data_size = sizeof(MpegEncContext),
139 .init = ff_h263_decode_init,
140 .close = ff_h263_decode_end,
141 .decode = ff_h263_decode_frame,
142 .capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1,
143 .pix_fmts = (const enum AVPixelFormat[]) {