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 "mpegvideo.h"
24 /* don't understand why they choose a different header ! */
25 int ff_intel_h263_decode_picture_header(MpegEncContext *s)
29 if (get_bits_left(&s->gb) == 64) { /* special dummy frames */
34 if (get_bits_long(&s->gb, 22) != 0x20) {
35 av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
38 s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */
40 if (get_bits1(&s->gb) != 1) {
41 av_log(s->avctx, AV_LOG_ERROR, "Bad marker\n");
42 return -1; /* marker */
44 if (get_bits1(&s->gb) != 0) {
45 av_log(s->avctx, AV_LOG_ERROR, "Bad H263 id\n");
46 return -1; /* h263 id */
48 skip_bits1(&s->gb); /* split screen off */
49 skip_bits1(&s->gb); /* camera off */
50 skip_bits1(&s->gb); /* freeze picture release off */
52 format = get_bits(&s->gb, 3);
53 if (format == 0 || format == 6) {
54 av_log(s->avctx, AV_LOG_ERROR, "Intel H263 free format not supported\n");
59 s->pict_type = AV_PICTURE_TYPE_I + get_bits1(&s->gb);
61 s->unrestricted_mv = get_bits1(&s->gb);
62 s->h263_long_vectors = s->unrestricted_mv;
64 if (get_bits1(&s->gb) != 0) {
65 av_log(s->avctx, AV_LOG_ERROR, "SAC not supported\n");
66 return -1; /* SAC: off */
68 s->obmc= get_bits1(&s->gb);
69 s->pb_frame = get_bits1(&s->gb);
72 s->width = ff_h263_format[format][0];
73 s->height = ff_h263_format[format][1];
74 s->avctx->sample_aspect_ratio.num = 12;
75 s->avctx->sample_aspect_ratio.den = 11;
77 format = get_bits(&s->gb, 3);
78 if(format == 0 || format == 7){
79 av_log(s->avctx, AV_LOG_ERROR, "Wrong Intel H263 format\n");
82 if(get_bits(&s->gb, 2))
83 av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
84 s->loop_filter = get_bits1(&s->gb);
86 av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
89 if(get_bits(&s->gb, 5))
90 av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
91 if(get_bits(&s->gb, 5) != 1)
92 av_log(s->avctx, AV_LOG_ERROR, "Invalid marker\n");
95 int ar = get_bits(&s->gb, 4);
96 skip_bits(&s->gb, 9); // display width
98 skip_bits(&s->gb, 9); // display height
100 s->avctx->sample_aspect_ratio.num = get_bits(&s->gb, 8); // aspect ratio - width
101 s->avctx->sample_aspect_ratio.den = get_bits(&s->gb, 8); // aspect ratio - height
103 s->avctx->sample_aspect_ratio = ff_h263_pixel_aspect[ar];
105 if (s->avctx->sample_aspect_ratio.num == 0)
106 av_log(s->avctx, AV_LOG_ERROR, "Invalid aspect ratio.\n");
109 s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
110 skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
113 skip_bits(&s->gb, 3); //temporal reference for B-frame
114 skip_bits(&s->gb, 2); //dbquant
118 while (get_bits1(&s->gb) != 0) {
119 skip_bits(&s->gb, 8);
124 s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
126 ff_h263_show_pict_info(s);
131 AVCodec ff_h263i_decoder = {
133 .long_name = NULL_IF_CONFIG_SMALL("Intel H.263"),
134 .type = AVMEDIA_TYPE_VIDEO,
135 .id = AV_CODEC_ID_H263I,
136 .priv_data_size = sizeof(MpegEncContext),
137 .init = ff_h263_decode_init,
138 .close = ff_h263_decode_end,
139 .decode = ff_h263_decode_frame,
140 .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
141 .pix_fmts = (const enum AVPixelFormat[]) {