]> git.sesse.net Git - ffmpeg/blob - libavcodec/intelh263dec.c
hevc: ppc: Add HEVC 4x4 IDCT for PowerPC
[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 "mpegutils.h"
22 #include "mpegvideo.h"
23 #include "h263.h"
24 #include "mpegvideodata.h"
25
26 /* don't understand why they choose a different header ! */
27 int ff_intel_h263_decode_picture_header(MpegEncContext *s)
28 {
29     int format;
30
31     if (get_bits_left(&s->gb) == 64) { /* special dummy frames */
32         return FRAME_SKIPPED;
33     }
34
35     /* picture header */
36     if (get_bits_long(&s->gb, 22) != 0x20) {
37         av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
38         return -1;
39     }
40     s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */
41
42     if (get_bits1(&s->gb) != 1) {
43         av_log(s->avctx, AV_LOG_ERROR, "Bad marker\n");
44         return -1;      /* marker */
45     }
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 */
49     }
50     skip_bits1(&s->gb);         /* split screen off */
51     skip_bits1(&s->gb);         /* camera  off */
52     skip_bits1(&s->gb);         /* freeze picture release off */
53
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");
57         return -1;
58     }
59     s->h263_plus = 0;
60
61     s->pict_type = AV_PICTURE_TYPE_I + get_bits1(&s->gb);
62
63     s->unrestricted_mv = get_bits1(&s->gb);
64     s->h263_long_vectors = s->unrestricted_mv;
65
66     if (get_bits1(&s->gb) != 0) {
67         av_log(s->avctx, AV_LOG_ERROR, "SAC not supported\n");
68         return -1;      /* SAC: off */
69     }
70     s->obmc= get_bits1(&s->gb);
71     s->pb_frame = get_bits1(&s->gb);
72
73     if (format < 6) {
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;
78     } else {
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");
82             return -1;
83         }
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);
87         if(get_bits1(&s->gb))
88             av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
89         if(get_bits1(&s->gb))
90             s->pb_frame = 2;
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");
95     }
96     if(format == 6){
97         int ar = get_bits(&s->gb, 4);
98         skip_bits(&s->gb, 9); // display width
99         skip_bits1(&s->gb);
100         skip_bits(&s->gb, 9); // display height
101         if(ar == 15){
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
104         } else {
105             s->avctx->sample_aspect_ratio = ff_h263_pixel_aspect[ar];
106         }
107         if (s->avctx->sample_aspect_ratio.num == 0)
108             av_log(s->avctx, AV_LOG_ERROR, "Invalid aspect ratio.\n");
109     }
110
111     s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
112     skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
113
114     if(s->pb_frame){
115         skip_bits(&s->gb, 3); //temporal reference for B-frame
116         skip_bits(&s->gb, 2); //dbquant
117     }
118
119     /* PEI */
120     while (get_bits1(&s->gb) != 0) {
121         skip_bits(&s->gb, 8);
122     }
123     s->f_code = 1;
124
125     s->y_dc_scale_table=
126     s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
127
128     ff_h263_show_pict_info(s);
129
130     return 0;
131 }
132
133 AVCodec ff_h263i_decoder = {
134     .name           = "h263i",
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[]) {
144         AV_PIX_FMT_YUV420P,
145         AV_PIX_FMT_NONE
146     },
147 };