]> git.sesse.net Git - ffmpeg/blob - libavcodec/intelh263dec.c
lavc: add Intel libmfx-based MPEG2 decoder.
[ffmpeg] / libavcodec / intelh263dec.c
1 /*
2  * H.263i decoder
3  *
4  * This file is part of Libav.
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "mpegvideo.h"
22 #include "h263.h"
23 #include "mpegvideodata.h"
24
25 /* don't understand why they choose a different header ! */
26 int ff_intel_h263_decode_picture_header(MpegEncContext *s)
27 {
28     int format;
29
30     if (get_bits_left(&s->gb) == 64) { /* special dummy frames */
31         return FRAME_SKIPPED;
32     }
33
34     /* picture header */
35     if (get_bits_long(&s->gb, 22) != 0x20) {
36         av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
37         return -1;
38     }
39     s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */
40
41     if (get_bits1(&s->gb) != 1) {
42         av_log(s->avctx, AV_LOG_ERROR, "Bad marker\n");
43         return -1;      /* marker */
44     }
45     if (get_bits1(&s->gb) != 0) {
46         av_log(s->avctx, AV_LOG_ERROR, "Bad H263 id\n");
47         return -1;      /* h263 id */
48     }
49     skip_bits1(&s->gb);         /* split screen off */
50     skip_bits1(&s->gb);         /* camera  off */
51     skip_bits1(&s->gb);         /* freeze picture release off */
52
53     format = get_bits(&s->gb, 3);
54     if (format == 0 || format == 6) {
55         av_log(s->avctx, AV_LOG_ERROR, "Intel H263 free format not supported\n");
56         return -1;
57     }
58     s->h263_plus = 0;
59
60     s->pict_type = AV_PICTURE_TYPE_I + get_bits1(&s->gb);
61
62     s->unrestricted_mv = get_bits1(&s->gb);
63     s->h263_long_vectors = s->unrestricted_mv;
64
65     if (get_bits1(&s->gb) != 0) {
66         av_log(s->avctx, AV_LOG_ERROR, "SAC not supported\n");
67         return -1;      /* SAC: off */
68     }
69     s->obmc= get_bits1(&s->gb);
70     s->pb_frame = get_bits1(&s->gb);
71
72     if (format < 6) {
73         s->width = ff_h263_format[format][0];
74         s->height = ff_h263_format[format][1];
75         s->avctx->sample_aspect_ratio.num = 12;
76         s->avctx->sample_aspect_ratio.den = 11;
77     } else {
78         format = get_bits(&s->gb, 3);
79         if(format == 0 || format == 7){
80             av_log(s->avctx, AV_LOG_ERROR, "Wrong Intel H263 format\n");
81             return -1;
82         }
83         if(get_bits(&s->gb, 2))
84             av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
85         s->loop_filter = get_bits1(&s->gb);
86         if(get_bits1(&s->gb))
87             av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
88         if(get_bits1(&s->gb))
89             s->pb_frame = 2;
90         if(get_bits(&s->gb, 5))
91             av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
92         if(get_bits(&s->gb, 5) != 1)
93             av_log(s->avctx, AV_LOG_ERROR, "Invalid marker\n");
94     }
95     if(format == 6){
96         int ar = get_bits(&s->gb, 4);
97         skip_bits(&s->gb, 9); // display width
98         skip_bits1(&s->gb);
99         skip_bits(&s->gb, 9); // display height
100         if(ar == 15){
101             s->avctx->sample_aspect_ratio.num = get_bits(&s->gb, 8); // aspect ratio - width
102             s->avctx->sample_aspect_ratio.den = get_bits(&s->gb, 8); // aspect ratio - height
103         } else {
104             s->avctx->sample_aspect_ratio = ff_h263_pixel_aspect[ar];
105         }
106         if (s->avctx->sample_aspect_ratio.num == 0)
107             av_log(s->avctx, AV_LOG_ERROR, "Invalid aspect ratio.\n");
108     }
109
110     s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
111     skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
112
113     if(s->pb_frame){
114         skip_bits(&s->gb, 3); //temporal reference for B-frame
115         skip_bits(&s->gb, 2); //dbquant
116     }
117
118     /* PEI */
119     while (get_bits1(&s->gb) != 0) {
120         skip_bits(&s->gb, 8);
121     }
122     s->f_code = 1;
123
124     s->y_dc_scale_table=
125     s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
126
127     ff_h263_show_pict_info(s);
128
129     return 0;
130 }
131
132 AVCodec ff_h263i_decoder = {
133     .name           = "h263i",
134     .long_name      = NULL_IF_CONFIG_SMALL("Intel H.263"),
135     .type           = AVMEDIA_TYPE_VIDEO,
136     .id             = AV_CODEC_ID_H263I,
137     .priv_data_size = sizeof(MpegEncContext),
138     .init           = ff_h263_decode_init,
139     .close          = ff_h263_decode_end,
140     .decode         = ff_h263_decode_frame,
141     .capabilities   = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
142     .pix_fmts       = (const enum AVPixelFormat[]) {
143         AV_PIX_FMT_YUV420P,
144         AV_PIX_FMT_NONE
145     },
146 };