annotate mpeg4videodec.c @ 12530:63edd10ad4bc libavcodec tip

Try to fix crashes introduced by r25218 r25218 made assumptions about the existence of past reference frames that weren't necessarily true.
author darkshikari
date Tue, 28 Sep 2010 09:06:22 +0000
parents c35d7bc64882
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1 /*
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2 * MPEG4 decoder.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
3 * Copyright (c) 2000,2001 Fabrice Bellard
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
4 * Copyright (c) 2002-2010 Michael Niedermayer <michaelni@gmx.at>
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
5 *
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
6 * This file is part of FFmpeg.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
7 *
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
12 *
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
16 * Lesser General Public License for more details.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
17 *
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
21 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
22
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
23 #include "mpegvideo.h"
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
24 #include "mpeg4video.h"
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
25 #include "h263.h"
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
26
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
27 // The defines below define the number of bits that are read at once for
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
28 // reading vlc values. Changing these may improve speed and data cache needs
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
29 // be aware though that decreasing them may need the number of stages that is
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
30 // passed to get_vlc* to be increased.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
31 #define SPRITE_TRAJ_VLC_BITS 6
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
32 #define DC_VLC_BITS 9
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
33 #define MB_TYPE_B_VLC_BITS 4
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
34
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
35
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
36 static VLC dc_lum, dc_chrom;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
37 static VLC sprite_trajectory;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
38 static VLC mb_type_b_vlc;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
39
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
40 static const int mb_type_b_map[4]= {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
41 MB_TYPE_DIRECT2 | MB_TYPE_L0L1,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
42 MB_TYPE_L0L1 | MB_TYPE_16x16,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
43 MB_TYPE_L1 | MB_TYPE_16x16,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
44 MB_TYPE_L0 | MB_TYPE_16x16,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
45 };
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
46
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
47 /**
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
48 * predicts the ac.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
49 * @param n block index (0-3 are luma, 4-5 are chroma)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
50 * @param dir the ac prediction direction
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
51 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
52 void mpeg4_pred_ac(MpegEncContext * s, DCTELEM *block, int n,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
53 int dir)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
54 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
55 int i;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
56 int16_t *ac_val, *ac_val1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
57 int8_t * const qscale_table= s->current_picture.qscale_table;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
58
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
59 /* find prediction */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
60 ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
61 ac_val1 = ac_val;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
62 if (s->ac_pred) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
63 if (dir == 0) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
64 const int xy= s->mb_x-1 + s->mb_y*s->mb_stride;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
65 /* left prediction */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
66 ac_val -= 16;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
67
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
68 if(s->mb_x==0 || s->qscale == qscale_table[xy] || n==1 || n==3){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
69 /* same qscale */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
70 for(i=1;i<8;i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
71 block[s->dsp.idct_permutation[i<<3]] += ac_val[i];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
72 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
73 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
74 /* different qscale, we must rescale */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
75 for(i=1;i<8;i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
76 block[s->dsp.idct_permutation[i<<3]] += ROUNDED_DIV(ac_val[i]*qscale_table[xy], s->qscale);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
77 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
78 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
79 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
80 const int xy= s->mb_x + s->mb_y*s->mb_stride - s->mb_stride;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
81 /* top prediction */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
82 ac_val -= 16 * s->block_wrap[n];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
83
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
84 if(s->mb_y==0 || s->qscale == qscale_table[xy] || n==2 || n==3){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
85 /* same qscale */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
86 for(i=1;i<8;i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
87 block[s->dsp.idct_permutation[i]] += ac_val[i + 8];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
88 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
89 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
90 /* different qscale, we must rescale */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
91 for(i=1;i<8;i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
92 block[s->dsp.idct_permutation[i]] += ROUNDED_DIV(ac_val[i + 8]*qscale_table[xy], s->qscale);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
93 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
94 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
95 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
96 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
97 /* left copy */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
98 for(i=1;i<8;i++)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
99 ac_val1[i ] = block[s->dsp.idct_permutation[i<<3]];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
100
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
101 /* top copy */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
102 for(i=1;i<8;i++)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
103 ac_val1[8 + i] = block[s->dsp.idct_permutation[i ]];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
104
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
105 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
106
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
107 /**
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
108 * check if the next stuff is a resync marker or the end.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
109 * @return 0 if not
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
110 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
111 static inline int mpeg4_is_resync(MpegEncContext *s){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
112 int bits_count= get_bits_count(&s->gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
113 int v= show_bits(&s->gb, 16);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
114
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
115 if(s->workaround_bugs&FF_BUG_NO_PADDING){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
116 return 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
117 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
118
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
119 while(v<=0xFF){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
120 if(s->pict_type==FF_B_TYPE || (v>>(8-s->pict_type)!=1) || s->partitioned_frame)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
121 break;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
122 skip_bits(&s->gb, 8+s->pict_type);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
123 bits_count+= 8+s->pict_type;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
124 v= show_bits(&s->gb, 16);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
125 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
126
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
127 if(bits_count + 8 >= s->gb.size_in_bits){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
128 v>>=8;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
129 v|= 0x7F >> (7-(bits_count&7));
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
130
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
131 if(v==0x7F)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
132 return 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
133 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
134 if(v == ff_mpeg4_resync_prefix[bits_count&7]){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
135 int len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
136 GetBitContext gb= s->gb;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
137
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
138 skip_bits(&s->gb, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
139 align_get_bits(&s->gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
140
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
141 for(len=0; len<32; len++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
142 if(get_bits1(&s->gb)) break;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
143 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
144
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
145 s->gb= gb;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
146
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
147 if(len>=ff_mpeg4_get_video_packet_prefix_length(s))
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
148 return 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
149 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
150 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
151 return 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
152 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
153
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
154 static void mpeg4_decode_sprite_trajectory(MpegEncContext * s, GetBitContext *gb)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
155 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
156 int i;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
157 int a= 2<<s->sprite_warping_accuracy;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
158 int rho= 3-s->sprite_warping_accuracy;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
159 int r=16/a;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
160 const int vop_ref[4][2]= {{0,0}, {s->width,0}, {0, s->height}, {s->width, s->height}}; // only true for rectangle shapes
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
161 int d[4][2]={{0,0}, {0,0}, {0,0}, {0,0}};
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
162 int sprite_ref[4][2];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
163 int virtual_ref[2][2];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
164 int w2, h2, w3, h3;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
165 int alpha=0, beta=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
166 int w= s->width;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
167 int h= s->height;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
168 int min_ab;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
169
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
170 for(i=0; i<s->num_sprite_warping_points; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
171 int length;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
172 int x=0, y=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
173
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
174 length= get_vlc2(gb, sprite_trajectory.table, SPRITE_TRAJ_VLC_BITS, 3);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
175 if(length){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
176 x= get_xbits(gb, length);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
177 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
178 if(!(s->divx_version==500 && s->divx_build==413)) skip_bits1(gb); /* marker bit */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
179
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
180 length= get_vlc2(gb, sprite_trajectory.table, SPRITE_TRAJ_VLC_BITS, 3);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
181 if(length){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
182 y=get_xbits(gb, length);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
183 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
184 skip_bits1(gb); /* marker bit */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
185 s->sprite_traj[i][0]= d[i][0]= x;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
186 s->sprite_traj[i][1]= d[i][1]= y;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
187 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
188 for(; i<4; i++)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
189 s->sprite_traj[i][0]= s->sprite_traj[i][1]= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
190
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
191 while((1<<alpha)<w) alpha++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
192 while((1<<beta )<h) beta++; // there seems to be a typo in the mpeg4 std for the definition of w' and h'
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
193 w2= 1<<alpha;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
194 h2= 1<<beta;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
195
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
196 // Note, the 4th point isn't used for GMC
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
197 if(s->divx_version==500 && s->divx_build==413){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
198 sprite_ref[0][0]= a*vop_ref[0][0] + d[0][0];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
199 sprite_ref[0][1]= a*vop_ref[0][1] + d[0][1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
200 sprite_ref[1][0]= a*vop_ref[1][0] + d[0][0] + d[1][0];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
201 sprite_ref[1][1]= a*vop_ref[1][1] + d[0][1] + d[1][1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
202 sprite_ref[2][0]= a*vop_ref[2][0] + d[0][0] + d[2][0];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
203 sprite_ref[2][1]= a*vop_ref[2][1] + d[0][1] + d[2][1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
204 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
205 sprite_ref[0][0]= (a>>1)*(2*vop_ref[0][0] + d[0][0]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
206 sprite_ref[0][1]= (a>>1)*(2*vop_ref[0][1] + d[0][1]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
207 sprite_ref[1][0]= (a>>1)*(2*vop_ref[1][0] + d[0][0] + d[1][0]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
208 sprite_ref[1][1]= (a>>1)*(2*vop_ref[1][1] + d[0][1] + d[1][1]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
209 sprite_ref[2][0]= (a>>1)*(2*vop_ref[2][0] + d[0][0] + d[2][0]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
210 sprite_ref[2][1]= (a>>1)*(2*vop_ref[2][1] + d[0][1] + d[2][1]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
211 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
212 /* sprite_ref[3][0]= (a>>1)*(2*vop_ref[3][0] + d[0][0] + d[1][0] + d[2][0] + d[3][0]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
213 sprite_ref[3][1]= (a>>1)*(2*vop_ref[3][1] + d[0][1] + d[1][1] + d[2][1] + d[3][1]); */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
214
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
215 // this is mostly identical to the mpeg4 std (and is totally unreadable because of that ...)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
216 // perhaps it should be reordered to be more readable ...
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
217 // the idea behind this virtual_ref mess is to be able to use shifts later per pixel instead of divides
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
218 // so the distance between points is converted from w&h based to w2&h2 based which are of the 2^x form
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
219 virtual_ref[0][0]= 16*(vop_ref[0][0] + w2)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
220 + ROUNDED_DIV(((w - w2)*(r*sprite_ref[0][0] - 16*vop_ref[0][0]) + w2*(r*sprite_ref[1][0] - 16*vop_ref[1][0])),w);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
221 virtual_ref[0][1]= 16*vop_ref[0][1]
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
222 + ROUNDED_DIV(((w - w2)*(r*sprite_ref[0][1] - 16*vop_ref[0][1]) + w2*(r*sprite_ref[1][1] - 16*vop_ref[1][1])),w);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
223 virtual_ref[1][0]= 16*vop_ref[0][0]
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
224 + ROUNDED_DIV(((h - h2)*(r*sprite_ref[0][0] - 16*vop_ref[0][0]) + h2*(r*sprite_ref[2][0] - 16*vop_ref[2][0])),h);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
225 virtual_ref[1][1]= 16*(vop_ref[0][1] + h2)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
226 + ROUNDED_DIV(((h - h2)*(r*sprite_ref[0][1] - 16*vop_ref[0][1]) + h2*(r*sprite_ref[2][1] - 16*vop_ref[2][1])),h);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
227
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
228 switch(s->num_sprite_warping_points)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
229 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
230 case 0:
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
231 s->sprite_offset[0][0]= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
232 s->sprite_offset[0][1]= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
233 s->sprite_offset[1][0]= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
234 s->sprite_offset[1][1]= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
235 s->sprite_delta[0][0]= a;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
236 s->sprite_delta[0][1]= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
237 s->sprite_delta[1][0]= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
238 s->sprite_delta[1][1]= a;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
239 s->sprite_shift[0]= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
240 s->sprite_shift[1]= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
241 break;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
242 case 1: //GMC only
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
243 s->sprite_offset[0][0]= sprite_ref[0][0] - a*vop_ref[0][0];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
244 s->sprite_offset[0][1]= sprite_ref[0][1] - a*vop_ref[0][1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
245 s->sprite_offset[1][0]= ((sprite_ref[0][0]>>1)|(sprite_ref[0][0]&1)) - a*(vop_ref[0][0]/2);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
246 s->sprite_offset[1][1]= ((sprite_ref[0][1]>>1)|(sprite_ref[0][1]&1)) - a*(vop_ref[0][1]/2);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
247 s->sprite_delta[0][0]= a;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
248 s->sprite_delta[0][1]= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
249 s->sprite_delta[1][0]= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
250 s->sprite_delta[1][1]= a;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
251 s->sprite_shift[0]= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
252 s->sprite_shift[1]= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
253 break;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
254 case 2:
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
255 s->sprite_offset[0][0]= (sprite_ref[0][0]<<(alpha+rho))
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
256 + (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-vop_ref[0][0])
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
257 + ( r*sprite_ref[0][1] - virtual_ref[0][1])*(-vop_ref[0][1])
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
258 + (1<<(alpha+rho-1));
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
259 s->sprite_offset[0][1]= (sprite_ref[0][1]<<(alpha+rho))
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
260 + (-r*sprite_ref[0][1] + virtual_ref[0][1])*(-vop_ref[0][0])
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
261 + (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-vop_ref[0][1])
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
262 + (1<<(alpha+rho-1));
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
263 s->sprite_offset[1][0]= ( (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-2*vop_ref[0][0] + 1)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
264 +( r*sprite_ref[0][1] - virtual_ref[0][1])*(-2*vop_ref[0][1] + 1)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
265 +2*w2*r*sprite_ref[0][0]
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
266 - 16*w2
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
267 + (1<<(alpha+rho+1)));
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
268 s->sprite_offset[1][1]= ( (-r*sprite_ref[0][1] + virtual_ref[0][1])*(-2*vop_ref[0][0] + 1)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
269 +(-r*sprite_ref[0][0] + virtual_ref[0][0])*(-2*vop_ref[0][1] + 1)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
270 +2*w2*r*sprite_ref[0][1]
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
271 - 16*w2
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
272 + (1<<(alpha+rho+1)));
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
273 s->sprite_delta[0][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
274 s->sprite_delta[0][1]= (+r*sprite_ref[0][1] - virtual_ref[0][1]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
275 s->sprite_delta[1][0]= (-r*sprite_ref[0][1] + virtual_ref[0][1]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
276 s->sprite_delta[1][1]= (-r*sprite_ref[0][0] + virtual_ref[0][0]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
277
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
278 s->sprite_shift[0]= alpha+rho;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
279 s->sprite_shift[1]= alpha+rho+2;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
280 break;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
281 case 3:
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
282 min_ab= FFMIN(alpha, beta);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
283 w3= w2>>min_ab;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
284 h3= h2>>min_ab;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
285 s->sprite_offset[0][0]= (sprite_ref[0][0]<<(alpha+beta+rho-min_ab))
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
286 + (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3*(-vop_ref[0][0])
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
287 + (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3*(-vop_ref[0][1])
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
288 + (1<<(alpha+beta+rho-min_ab-1));
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
289 s->sprite_offset[0][1]= (sprite_ref[0][1]<<(alpha+beta+rho-min_ab))
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
290 + (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3*(-vop_ref[0][0])
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
291 + (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3*(-vop_ref[0][1])
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
292 + (1<<(alpha+beta+rho-min_ab-1));
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
293 s->sprite_offset[1][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3*(-2*vop_ref[0][0] + 1)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
294 + (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3*(-2*vop_ref[0][1] + 1)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
295 + 2*w2*h3*r*sprite_ref[0][0]
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
296 - 16*w2*h3
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
297 + (1<<(alpha+beta+rho-min_ab+1));
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
298 s->sprite_offset[1][1]= (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3*(-2*vop_ref[0][0] + 1)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
299 + (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3*(-2*vop_ref[0][1] + 1)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
300 + 2*w2*h3*r*sprite_ref[0][1]
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
301 - 16*w2*h3
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
302 + (1<<(alpha+beta+rho-min_ab+1));
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
303 s->sprite_delta[0][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
304 s->sprite_delta[0][1]= (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
305 s->sprite_delta[1][0]= (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
306 s->sprite_delta[1][1]= (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
307
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
308 s->sprite_shift[0]= alpha + beta + rho - min_ab;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
309 s->sprite_shift[1]= alpha + beta + rho - min_ab + 2;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
310 break;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
311 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
312 /* try to simplify the situation */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
313 if( s->sprite_delta[0][0] == a<<s->sprite_shift[0]
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
314 && s->sprite_delta[0][1] == 0
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
315 && s->sprite_delta[1][0] == 0
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
316 && s->sprite_delta[1][1] == a<<s->sprite_shift[0])
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
317 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
318 s->sprite_offset[0][0]>>=s->sprite_shift[0];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
319 s->sprite_offset[0][1]>>=s->sprite_shift[0];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
320 s->sprite_offset[1][0]>>=s->sprite_shift[1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
321 s->sprite_offset[1][1]>>=s->sprite_shift[1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
322 s->sprite_delta[0][0]= a;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
323 s->sprite_delta[0][1]= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
324 s->sprite_delta[1][0]= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
325 s->sprite_delta[1][1]= a;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
326 s->sprite_shift[0]= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
327 s->sprite_shift[1]= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
328 s->real_sprite_warping_points=1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
329 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
330 else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
331 int shift_y= 16 - s->sprite_shift[0];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
332 int shift_c= 16 - s->sprite_shift[1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
333 for(i=0; i<2; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
334 s->sprite_offset[0][i]<<= shift_y;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
335 s->sprite_offset[1][i]<<= shift_c;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
336 s->sprite_delta[0][i]<<= shift_y;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
337 s->sprite_delta[1][i]<<= shift_y;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
338 s->sprite_shift[i]= 16;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
339 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
340 s->real_sprite_warping_points= s->num_sprite_warping_points;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
341 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
342 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
343
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
344 /**
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
345 * decodes the next video packet.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
346 * @return <0 if something went wrong
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
347 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
348 int mpeg4_decode_video_packet_header(MpegEncContext *s)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
349 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
350 int mb_num_bits= av_log2(s->mb_num - 1) + 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
351 int header_extension=0, mb_num, len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
352
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
353 /* is there enough space left for a video packet + header */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
354 if( get_bits_count(&s->gb) > s->gb.size_in_bits-20) return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
355
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
356 for(len=0; len<32; len++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
357 if(get_bits1(&s->gb)) break;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
358 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
359
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
360 if(len!=ff_mpeg4_get_video_packet_prefix_length(s)){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
361 av_log(s->avctx, AV_LOG_ERROR, "marker does not match f_code\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
362 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
363 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
364
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
365 if(s->shape != RECT_SHAPE){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
366 header_extension= get_bits1(&s->gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
367 //FIXME more stuff here
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
368 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
369
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
370 mb_num= get_bits(&s->gb, mb_num_bits);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
371 if(mb_num>=s->mb_num){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
372 av_log(s->avctx, AV_LOG_ERROR, "illegal mb_num in video packet (%d %d) \n", mb_num, s->mb_num);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
373 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
374 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
375 if(s->pict_type == FF_B_TYPE){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
376 while(s->next_picture.mbskip_table[ s->mb_index2xy[ mb_num ] ]) mb_num++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
377 if(mb_num >= s->mb_num) return -1; // slice contains just skipped MBs which where already decoded
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
378 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
379
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
380 s->mb_x= mb_num % s->mb_width;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
381 s->mb_y= mb_num / s->mb_width;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
382
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
383 if(s->shape != BIN_ONLY_SHAPE){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
384 int qscale= get_bits(&s->gb, s->quant_precision);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
385 if(qscale)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
386 s->chroma_qscale=s->qscale= qscale;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
387 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
388
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
389 if(s->shape == RECT_SHAPE){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
390 header_extension= get_bits1(&s->gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
391 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
392 if(header_extension){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
393 int time_increment;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
394 int time_incr=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
395
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
396 while (get_bits1(&s->gb) != 0)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
397 time_incr++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
398
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
399 check_marker(&s->gb, "before time_increment in video packed header");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
400 time_increment= get_bits(&s->gb, s->time_increment_bits);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
401 check_marker(&s->gb, "before vop_coding_type in video packed header");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
402
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
403 skip_bits(&s->gb, 2); /* vop coding type */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
404 //FIXME not rect stuff here
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
405
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
406 if(s->shape != BIN_ONLY_SHAPE){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
407 skip_bits(&s->gb, 3); /* intra dc vlc threshold */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
408 //FIXME don't just ignore everything
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
409 if(s->pict_type == FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
410 mpeg4_decode_sprite_trajectory(s, &s->gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
411 av_log(s->avctx, AV_LOG_ERROR, "untested\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
412 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
413
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
414 //FIXME reduced res stuff here
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
415
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
416 if (s->pict_type != FF_I_TYPE) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
417 int f_code = get_bits(&s->gb, 3); /* fcode_for */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
418 if(f_code==0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
419 av_log(s->avctx, AV_LOG_ERROR, "Error, video packet header damaged (f_code=0)\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
420 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
421 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
422 if (s->pict_type == FF_B_TYPE) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
423 int b_code = get_bits(&s->gb, 3);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
424 if(b_code==0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
425 av_log(s->avctx, AV_LOG_ERROR, "Error, video packet header damaged (b_code=0)\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
426 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
427 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
428 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
429 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
430 //FIXME new-pred stuff
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
431
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
432 return 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
433 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
434
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
435 /**
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
436 * gets the average motion vector for a GMC MB.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
437 * @param n either 0 for the x component or 1 for y
11556
b94e1810ce4c Replace @returns by @return.
benoit
parents: 11098
diff changeset
438 * @return the average MV for a GMC MB
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
439 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
440 static inline int get_amv(MpegEncContext *s, int n){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
441 int x, y, mb_v, sum, dx, dy, shift;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
442 int len = 1 << (s->f_code + 4);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
443 const int a= s->sprite_warping_accuracy;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
444
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
445 if(s->workaround_bugs & FF_BUG_AMV)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
446 len >>= s->quarter_sample;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
447
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
448 if(s->real_sprite_warping_points==1){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
449 if(s->divx_version==500 && s->divx_build==413)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
450 sum= s->sprite_offset[0][n] / (1<<(a - s->quarter_sample));
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
451 else
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
452 sum= RSHIFT(s->sprite_offset[0][n]<<s->quarter_sample, a);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
453 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
454 dx= s->sprite_delta[n][0];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
455 dy= s->sprite_delta[n][1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
456 shift= s->sprite_shift[0];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
457 if(n) dy -= 1<<(shift + a + 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
458 else dx -= 1<<(shift + a + 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
459 mb_v= s->sprite_offset[0][n] + dx*s->mb_x*16 + dy*s->mb_y*16;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
460
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
461 sum=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
462 for(y=0; y<16; y++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
463 int v;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
464
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
465 v= mb_v + dy*y;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
466 //XXX FIXME optimize
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
467 for(x=0; x<16; x++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
468 sum+= v>>shift;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
469 v+= dx;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
470 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
471 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
472 sum= RSHIFT(sum, a+8-s->quarter_sample);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
473 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
474
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
475 if (sum < -len) sum= -len;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
476 else if (sum >= len) sum= len-1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
477
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
478 return sum;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
479 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
480
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
481 /**
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
482 * decodes the dc value.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
483 * @param n block index (0-3 are luma, 4-5 are chroma)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
484 * @param dir_ptr the prediction direction will be stored here
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
485 * @return the quantized dc
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
486 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
487 static inline int mpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
488 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
489 int level, code;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
490
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
491 if (n < 4)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
492 code = get_vlc2(&s->gb, dc_lum.table, DC_VLC_BITS, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
493 else
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
494 code = get_vlc2(&s->gb, dc_chrom.table, DC_VLC_BITS, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
495 if (code < 0 || code > 9 /* && s->nbit<9 */){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
496 av_log(s->avctx, AV_LOG_ERROR, "illegal dc vlc\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
497 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
498 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
499 if (code == 0) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
500 level = 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
501 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
502 if(IS_3IV1){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
503 if(code==1)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
504 level= 2*get_bits1(&s->gb)-1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
505 else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
506 if(get_bits1(&s->gb))
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
507 level = get_bits(&s->gb, code-1) + (1<<(code-1));
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
508 else
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
509 level = -get_bits(&s->gb, code-1) - (1<<(code-1));
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
510 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
511 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
512 level = get_xbits(&s->gb, code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
513 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
514
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
515 if (code > 8){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
516 if(get_bits1(&s->gb)==0){ /* marker */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
517 if(s->error_recognition>=2){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
518 av_log(s->avctx, AV_LOG_ERROR, "dc marker bit missing\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
519 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
520 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
521 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
522 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
523 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
524
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
525 return ff_mpeg4_pred_dc(s, n, level, dir_ptr, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
526 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
527
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
528 /**
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
529 * decodes first partition.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
530 * @return number of MBs decoded or <0 if an error occurred
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
531 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
532 static int mpeg4_decode_partition_a(MpegEncContext *s){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
533 int mb_num;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
534 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
535
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
536 /* decode first partition */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
537 mb_num=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
538 s->first_slice_line=1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
539 for(; s->mb_y<s->mb_height; s->mb_y++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
540 ff_init_block_index(s);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
541 for(; s->mb_x<s->mb_width; s->mb_x++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
542 const int xy= s->mb_x + s->mb_y*s->mb_stride;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
543 int cbpc;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
544 int dir=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
545
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
546 mb_num++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
547 ff_update_block_index(s);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
548 if(s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y+1)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
549 s->first_slice_line=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
550
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
551 if(s->pict_type==FF_I_TYPE){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
552 int i;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
553
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
554 do{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
555 if(show_bits_long(&s->gb, 19)==DC_MARKER){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
556 return mb_num-1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
557 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
558
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10817
diff changeset
559 cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2);
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
560 if (cbpc < 0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
561 av_log(s->avctx, AV_LOG_ERROR, "cbpc corrupted at %d %d\n", s->mb_x, s->mb_y);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
562 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
563 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
564 }while(cbpc == 8);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
565
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
566 s->cbp_table[xy]= cbpc & 3;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
567 s->current_picture.mb_type[xy]= MB_TYPE_INTRA;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
568 s->mb_intra = 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
569
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
570 if(cbpc & 4) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
571 ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
572 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
573 s->current_picture.qscale_table[xy]= s->qscale;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
574
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
575 s->mbintra_table[xy]= 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
576 for(i=0; i<6; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
577 int dc_pred_dir;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
578 int dc= mpeg4_decode_dc(s, i, &dc_pred_dir);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
579 if(dc < 0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
580 av_log(s->avctx, AV_LOG_ERROR, "DC corrupted at %d %d\n", s->mb_x, s->mb_y);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
581 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
582 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
583 dir<<=1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
584 if(dc_pred_dir) dir|=1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
585 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
586 s->pred_dir_table[xy]= dir;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
587 }else{ /* P/S_TYPE */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
588 int mx, my, pred_x, pred_y, bits;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
589 int16_t * const mot_val= s->current_picture.motion_val[0][s->block_index[0]];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
590 const int stride= s->b8_stride*2;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
591
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
592 try_again:
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
593 bits= show_bits(&s->gb, 17);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
594 if(bits==MOTION_MARKER){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
595 return mb_num-1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
596 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
597 skip_bits1(&s->gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
598 if(bits&0x10000){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
599 /* skip mb */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
600 if(s->pict_type==FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
601 s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_GMC | MB_TYPE_L0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
602 mx= get_amv(s, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
603 my= get_amv(s, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
604 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
605 s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
606 mx=my=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
607 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
608 mot_val[0 ]= mot_val[2 ]=
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
609 mot_val[0+stride]= mot_val[2+stride]= mx;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
610 mot_val[1 ]= mot_val[3 ]=
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
611 mot_val[1+stride]= mot_val[3+stride]= my;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
612
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
613 if(s->mbintra_table[xy])
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
614 ff_clean_intra_table_entries(s);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
615 continue;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
616 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
617
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10817
diff changeset
618 cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
619 if (cbpc < 0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
620 av_log(s->avctx, AV_LOG_ERROR, "cbpc corrupted at %d %d\n", s->mb_x, s->mb_y);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
621 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
622 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
623 if(cbpc == 20)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
624 goto try_again;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
625
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
626 s->cbp_table[xy]= cbpc&(8+3); //8 is dquant
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
627
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
628 s->mb_intra = ((cbpc & 4) != 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
629
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
630 if(s->mb_intra){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
631 s->current_picture.mb_type[xy]= MB_TYPE_INTRA;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
632 s->mbintra_table[xy]= 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
633 mot_val[0 ]= mot_val[2 ]=
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
634 mot_val[0+stride]= mot_val[2+stride]= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
635 mot_val[1 ]= mot_val[3 ]=
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
636 mot_val[1+stride]= mot_val[3+stride]= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
637 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
638 if(s->mbintra_table[xy])
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
639 ff_clean_intra_table_entries(s);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
640
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
641 if(s->pict_type==FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE && (cbpc & 16) == 0)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
642 s->mcsel= get_bits1(&s->gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
643 else s->mcsel= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
644
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
645 if ((cbpc & 16) == 0) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
646 /* 16x16 motion prediction */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
647
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
648 h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
649 if(!s->mcsel){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
650 mx = h263_decode_motion(s, pred_x, s->f_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
651 if (mx >= 0xffff)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
652 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
653
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
654 my = h263_decode_motion(s, pred_y, s->f_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
655 if (my >= 0xffff)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
656 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
657 s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
658 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
659 mx = get_amv(s, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
660 my = get_amv(s, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
661 s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_GMC | MB_TYPE_L0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
662 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
663
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
664 mot_val[0 ]= mot_val[2 ] =
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
665 mot_val[0+stride]= mot_val[2+stride]= mx;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
666 mot_val[1 ]= mot_val[3 ]=
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
667 mot_val[1+stride]= mot_val[3+stride]= my;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
668 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
669 int i;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
670 s->current_picture.mb_type[xy]= MB_TYPE_8x8 | MB_TYPE_L0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
671 for(i=0;i<4;i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
672 int16_t *mot_val= h263_pred_motion(s, i, 0, &pred_x, &pred_y);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
673 mx = h263_decode_motion(s, pred_x, s->f_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
674 if (mx >= 0xffff)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
675 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
676
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
677 my = h263_decode_motion(s, pred_y, s->f_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
678 if (my >= 0xffff)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
679 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
680 mot_val[0] = mx;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
681 mot_val[1] = my;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
682 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
683 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
684 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
685 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
686 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
687 s->mb_x= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
688 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
689
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
690 return mb_num;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
691 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
692
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
693 /**
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
694 * decode second partition.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
695 * @return <0 if an error occurred
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
696 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
697 static int mpeg4_decode_partition_b(MpegEncContext *s, int mb_count){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
698 int mb_num=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
699 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
700
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
701 s->mb_x= s->resync_mb_x;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
702 s->first_slice_line=1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
703 for(s->mb_y= s->resync_mb_y; mb_num < mb_count; s->mb_y++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
704 ff_init_block_index(s);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
705 for(; mb_num < mb_count && s->mb_x<s->mb_width; s->mb_x++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
706 const int xy= s->mb_x + s->mb_y*s->mb_stride;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
707
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
708 mb_num++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
709 ff_update_block_index(s);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
710 if(s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y+1)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
711 s->first_slice_line=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
712
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
713 if(s->pict_type==FF_I_TYPE){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
714 int ac_pred= get_bits1(&s->gb);
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10817
diff changeset
715 int cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
716 if(cbpy<0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
717 av_log(s->avctx, AV_LOG_ERROR, "cbpy corrupted at %d %d\n", s->mb_x, s->mb_y);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
718 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
719 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
720
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
721 s->cbp_table[xy]|= cbpy<<2;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
722 s->current_picture.mb_type[xy] |= ac_pred*MB_TYPE_ACPRED;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
723 }else{ /* P || S_TYPE */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
724 if(IS_INTRA(s->current_picture.mb_type[xy])){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
725 int dir=0,i;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
726 int ac_pred = get_bits1(&s->gb);
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10817
diff changeset
727 int cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
728
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
729 if(cbpy<0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
730 av_log(s->avctx, AV_LOG_ERROR, "I cbpy corrupted at %d %d\n", s->mb_x, s->mb_y);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
731 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
732 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
733
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
734 if(s->cbp_table[xy] & 8) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
735 ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
736 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
737 s->current_picture.qscale_table[xy]= s->qscale;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
738
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
739 for(i=0; i<6; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
740 int dc_pred_dir;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
741 int dc= mpeg4_decode_dc(s, i, &dc_pred_dir);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
742 if(dc < 0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
743 av_log(s->avctx, AV_LOG_ERROR, "DC corrupted at %d %d\n", s->mb_x, s->mb_y);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
744 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
745 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
746 dir<<=1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
747 if(dc_pred_dir) dir|=1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
748 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
749 s->cbp_table[xy]&= 3; //remove dquant
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
750 s->cbp_table[xy]|= cbpy<<2;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
751 s->current_picture.mb_type[xy] |= ac_pred*MB_TYPE_ACPRED;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
752 s->pred_dir_table[xy]= dir;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
753 }else if(IS_SKIP(s->current_picture.mb_type[xy])){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
754 s->current_picture.qscale_table[xy]= s->qscale;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
755 s->cbp_table[xy]= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
756 }else{
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10817
diff changeset
757 int cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
758
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
759 if(cbpy<0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
760 av_log(s->avctx, AV_LOG_ERROR, "P cbpy corrupted at %d %d\n", s->mb_x, s->mb_y);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
761 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
762 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
763
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
764 if(s->cbp_table[xy] & 8) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
765 ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
766 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
767 s->current_picture.qscale_table[xy]= s->qscale;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
768
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
769 s->cbp_table[xy]&= 3; //remove dquant
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
770 s->cbp_table[xy]|= (cbpy^0xf)<<2;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
771 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
772 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
773 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
774 if(mb_num >= mb_count) return 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
775 s->mb_x= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
776 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
777 return 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
778 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
779
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
780 /**
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
781 * decodes the first & second partition
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
782 * @return <0 if error (and sets error type in the error_status_table)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
783 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
784 int ff_mpeg4_decode_partitions(MpegEncContext *s)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
785 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
786 int mb_num;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
787 const int part_a_error= s->pict_type==FF_I_TYPE ? (DC_ERROR|MV_ERROR) : MV_ERROR;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
788 const int part_a_end = s->pict_type==FF_I_TYPE ? (DC_END |MV_END) : MV_END;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
789
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
790 mb_num= mpeg4_decode_partition_a(s);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
791 if(mb_num<0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
792 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, part_a_error);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
793 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
794 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
795
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
796 if(s->resync_mb_x + s->resync_mb_y*s->mb_width + mb_num > s->mb_num){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
797 av_log(s->avctx, AV_LOG_ERROR, "slice below monitor ...\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
798 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, part_a_error);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
799 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
800 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
801
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
802 s->mb_num_left= mb_num;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
804 if(s->pict_type==FF_I_TYPE){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
805 while(show_bits(&s->gb, 9) == 1)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
806 skip_bits(&s->gb, 9);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
807 if(get_bits_long(&s->gb, 19)!=DC_MARKER){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
808 av_log(s->avctx, AV_LOG_ERROR, "marker missing after first I partition at %d %d\n", s->mb_x, s->mb_y);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
809 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
810 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
811 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
812 while(show_bits(&s->gb, 10) == 1)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
813 skip_bits(&s->gb, 10);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
814 if(get_bits(&s->gb, 17)!=MOTION_MARKER){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
815 av_log(s->avctx, AV_LOG_ERROR, "marker missing after first P partition at %d %d\n", s->mb_x, s->mb_y);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
816 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
817 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
818 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
819 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, part_a_end);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
820
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
821 if( mpeg4_decode_partition_b(s, mb_num) < 0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
822 if(s->pict_type==FF_P_TYPE)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
823 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, DC_ERROR);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
824 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
825 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
826 if(s->pict_type==FF_P_TYPE)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
827 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, DC_END);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
828 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
829
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
830 return 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
831 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
832
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
833 /**
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
834 * decodes a block.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
835 * @return <0 if an error occurred
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
836 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
837 static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
838 int n, int coded, int intra, int rvlc)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
839 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
840 int level, i, last, run;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
841 int dc_pred_dir;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
842 RLTable * rl;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
843 RL_VLC_ELEM * rl_vlc;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
844 const uint8_t * scan_table;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
845 int qmul, qadd;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
846
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
847 //Note intra & rvlc should be optimized away if this is inlined
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
848
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
849 if(intra) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
850 if(s->use_intra_dc_vlc){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
851 /* DC coef */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
852 if(s->partitioned_frame){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
853 level = s->dc_val[0][ s->block_index[n] ];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
854 if(n<4) level= FASTDIV((level + (s->y_dc_scale>>1)), s->y_dc_scale);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
855 else level= FASTDIV((level + (s->c_dc_scale>>1)), s->c_dc_scale);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
856 dc_pred_dir= (s->pred_dir_table[s->mb_x + s->mb_y*s->mb_stride]<<n)&32;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
857 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
858 level = mpeg4_decode_dc(s, n, &dc_pred_dir);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
859 if (level < 0)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
860 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
861 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
862 block[0] = level;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
863 i = 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
864 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
865 i = -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
866 ff_mpeg4_pred_dc(s, n, 0, &dc_pred_dir, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
867 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
868 if (!coded)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
869 goto not_coded;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
870
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
871 if(rvlc){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
872 rl = &rvlc_rl_intra;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
873 rl_vlc = rvlc_rl_intra.rl_vlc[0];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
874 }else{
10817
d1fe22d92a65 Rename mpeg4 intra vlc tables so they contain "mpeg4", this improves readability
michael
parents: 10816
diff changeset
875 rl = &ff_mpeg4_rl_intra;
d1fe22d92a65 Rename mpeg4 intra vlc tables so they contain "mpeg4", this improves readability
michael
parents: 10816
diff changeset
876 rl_vlc = ff_mpeg4_rl_intra.rl_vlc[0];
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
877 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
878 if (s->ac_pred) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
879 if (dc_pred_dir == 0)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
880 scan_table = s->intra_v_scantable.permutated; /* left */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
881 else
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
882 scan_table = s->intra_h_scantable.permutated; /* top */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
883 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
884 scan_table = s->intra_scantable.permutated;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
885 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
886 qmul=1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
887 qadd=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
888 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
889 i = -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
890 if (!coded) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
891 s->block_last_index[n] = i;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
892 return 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
893 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
894 if(rvlc) rl = &rvlc_rl_inter;
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10817
diff changeset
895 else rl = &ff_h263_rl_inter;
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
896
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
897 scan_table = s->intra_scantable.permutated;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
898
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
899 if(s->mpeg_quant){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
900 qmul=1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
901 qadd=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
902 if(rvlc){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
903 rl_vlc = rvlc_rl_inter.rl_vlc[0];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
904 }else{
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10817
diff changeset
905 rl_vlc = ff_h263_rl_inter.rl_vlc[0];
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
906 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
907 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
908 qmul = s->qscale << 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
909 qadd = (s->qscale - 1) | 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
910 if(rvlc){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
911 rl_vlc = rvlc_rl_inter.rl_vlc[s->qscale];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
912 }else{
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10817
diff changeset
913 rl_vlc = ff_h263_rl_inter.rl_vlc[s->qscale];
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
914 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
915 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
916 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
917 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
918 OPEN_READER(re, &s->gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
919 for(;;) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
920 UPDATE_CACHE(re, &s->gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
921 GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
922 if (level==0) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
923 /* escape */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
924 if(rvlc){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
925 if(SHOW_UBITS(re, &s->gb, 1)==0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
926 av_log(s->avctx, AV_LOG_ERROR, "1. marker bit missing in rvlc esc\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
927 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
928 }; SKIP_CACHE(re, &s->gb, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
929
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
930 last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
931 run= SHOW_UBITS(re, &s->gb, 6); LAST_SKIP_CACHE(re, &s->gb, 6);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
932 SKIP_COUNTER(re, &s->gb, 1+1+6);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
933 UPDATE_CACHE(re, &s->gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
934
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
935 if(SHOW_UBITS(re, &s->gb, 1)==0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
936 av_log(s->avctx, AV_LOG_ERROR, "2. marker bit missing in rvlc esc\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
937 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
938 }; SKIP_CACHE(re, &s->gb, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
939
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
940 level= SHOW_UBITS(re, &s->gb, 11); SKIP_CACHE(re, &s->gb, 11);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
941
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
942 if(SHOW_UBITS(re, &s->gb, 5)!=0x10){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
943 av_log(s->avctx, AV_LOG_ERROR, "reverse esc missing\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
944 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
945 }; SKIP_CACHE(re, &s->gb, 5);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
946
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
947 level= level * qmul + qadd;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
948 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); LAST_SKIP_CACHE(re, &s->gb, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
949 SKIP_COUNTER(re, &s->gb, 1+11+5+1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
950
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
951 i+= run + 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
952 if(last) i+=192;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
953 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
954 int cache;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
955 cache= GET_CACHE(re, &s->gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
956
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
957 if(IS_3IV1)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
958 cache ^= 0xC0000000;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
959
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
960 if (cache&0x80000000) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
961 if (cache&0x40000000) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
962 /* third escape */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
963 SKIP_CACHE(re, &s->gb, 2);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
964 last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
965 run= SHOW_UBITS(re, &s->gb, 6); LAST_SKIP_CACHE(re, &s->gb, 6);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
966 SKIP_COUNTER(re, &s->gb, 2+1+6);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
967 UPDATE_CACHE(re, &s->gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
968
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
969 if(IS_3IV1){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
970 level= SHOW_SBITS(re, &s->gb, 12); LAST_SKIP_BITS(re, &s->gb, 12);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
971 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
972 if(SHOW_UBITS(re, &s->gb, 1)==0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
973 av_log(s->avctx, AV_LOG_ERROR, "1. marker bit missing in 3. esc\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
974 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
975 }; SKIP_CACHE(re, &s->gb, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
976
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
977 level= SHOW_SBITS(re, &s->gb, 12); SKIP_CACHE(re, &s->gb, 12);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
978
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
979 if(SHOW_UBITS(re, &s->gb, 1)==0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
980 av_log(s->avctx, AV_LOG_ERROR, "2. marker bit missing in 3. esc\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
981 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
982 }; LAST_SKIP_CACHE(re, &s->gb, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
983
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
984 SKIP_COUNTER(re, &s->gb, 1+12+1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
985 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
986
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
987 #if 0
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
988 if(s->error_recognition >= FF_ER_COMPLIANT){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
989 const int abs_level= FFABS(level);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
990 if(abs_level<=MAX_LEVEL && run<=MAX_RUN){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
991 const int run1= run - rl->max_run[last][abs_level] - 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
992 if(abs_level <= rl->max_level[last][run]){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
993 av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, vlc encoding possible\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
994 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
995 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
996 if(s->error_recognition > FF_ER_COMPLIANT){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
997 if(abs_level <= rl->max_level[last][run]*2){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
998 av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 1 encoding possible\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
999 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1000 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1001 if(run1 >= 0 && abs_level <= rl->max_level[last][run1]){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1002 av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 2 encoding possible\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1003 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1004 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1005 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1006 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1007 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1008 #endif
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1009 if (level>0) level= level * qmul + qadd;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1010 else level= level * qmul - qadd;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1011
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1012 if((unsigned)(level + 2048) > 4095){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1013 if(s->error_recognition > FF_ER_COMPLIANT){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1014 if(level > 2560 || level<-2560){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1015 av_log(s->avctx, AV_LOG_ERROR, "|level| overflow in 3. esc, qp=%d\n", s->qscale);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1016 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1017 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1018 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1019 level= level<0 ? -2048 : 2047;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1020 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1021
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1022 i+= run + 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1023 if(last) i+=192;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1024 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1025 /* second escape */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1026 #if MIN_CACHE_BITS < 20
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1027 LAST_SKIP_BITS(re, &s->gb, 2);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1028 UPDATE_CACHE(re, &s->gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1029 #else
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1030 SKIP_BITS(re, &s->gb, 2);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1031 #endif
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1032 GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1033 i+= run + rl->max_run[run>>7][level/qmul] +1; //FIXME opt indexing
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1034 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1035 LAST_SKIP_BITS(re, &s->gb, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1036 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1037 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1038 /* first escape */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1039 #if MIN_CACHE_BITS < 19
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1040 LAST_SKIP_BITS(re, &s->gb, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1041 UPDATE_CACHE(re, &s->gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1042 #else
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1043 SKIP_BITS(re, &s->gb, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1044 #endif
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1045 GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1046 i+= run;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1047 level = level + rl->max_level[run>>7][(run-1)&63] * qmul;//FIXME opt indexing
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1048 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1049 LAST_SKIP_BITS(re, &s->gb, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1050 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1051 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1052 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1053 i+= run;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1054 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1055 LAST_SKIP_BITS(re, &s->gb, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1056 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1057 if (i > 62){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1058 i-= 192;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1059 if(i&(~63)){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1060 av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1061 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1062 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1063
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1064 block[scan_table[i]] = level;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1065 break;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1066 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1067
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1068 block[scan_table[i]] = level;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1069 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1070 CLOSE_READER(re, &s->gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1071 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1072 not_coded:
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1073 if (intra) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1074 if(!s->use_intra_dc_vlc){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1075 block[0] = ff_mpeg4_pred_dc(s, n, block[0], &dc_pred_dir, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1076
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1077 i -= i>>31; //if(i == -1) i=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1078 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1079
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1080 mpeg4_pred_ac(s, block, n, dc_pred_dir);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1081 if (s->ac_pred) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1082 i = 63; /* XXX: not optimal */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1083 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1084 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1085 s->block_last_index[n] = i;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1086 return 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1087 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1088
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1089 /**
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1090 * decode partition C of one MB.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1091 * @return <0 if an error occurred
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1092 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1093 static int mpeg4_decode_partitioned_mb(MpegEncContext *s, DCTELEM block[6][64])
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1094 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1095 int cbp, mb_type;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1096 const int xy= s->mb_x + s->mb_y*s->mb_stride;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1097
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1098 mb_type= s->current_picture.mb_type[xy];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1099 cbp = s->cbp_table[xy];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1100
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1101 s->use_intra_dc_vlc= s->qscale < s->intra_dc_threshold;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1102
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1103 if(s->current_picture.qscale_table[xy] != s->qscale){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1104 ff_set_qscale(s, s->current_picture.qscale_table[xy] );
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1105 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1106
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1107 if (s->pict_type == FF_P_TYPE || s->pict_type==FF_S_TYPE) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1108 int i;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1109 for(i=0; i<4; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1110 s->mv[0][i][0] = s->current_picture.motion_val[0][ s->block_index[i] ][0];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1111 s->mv[0][i][1] = s->current_picture.motion_val[0][ s->block_index[i] ][1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1112 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1113 s->mb_intra = IS_INTRA(mb_type);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1114
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1115 if (IS_SKIP(mb_type)) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1116 /* skip mb */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1117 for(i=0;i<6;i++)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1118 s->block_last_index[i] = -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1119 s->mv_dir = MV_DIR_FORWARD;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1120 s->mv_type = MV_TYPE_16X16;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1121 if(s->pict_type==FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1122 s->mcsel=1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1123 s->mb_skipped = 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1124 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1125 s->mcsel=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1126 s->mb_skipped = 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1127 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1128 }else if(s->mb_intra){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1129 s->ac_pred = IS_ACPRED(s->current_picture.mb_type[xy]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1130 }else if(!s->mb_intra){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1131 // s->mcsel= 0; //FIXME do we need to init that
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1132
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1133 s->mv_dir = MV_DIR_FORWARD;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1134 if (IS_8X8(mb_type)) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1135 s->mv_type = MV_TYPE_8X8;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1136 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1137 s->mv_type = MV_TYPE_16X16;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1138 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1139 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1140 } else { /* I-Frame */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1141 s->mb_intra = 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1142 s->ac_pred = IS_ACPRED(s->current_picture.mb_type[xy]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1143 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1144
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1145 if (!IS_SKIP(mb_type)) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1146 int i;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1147 s->dsp.clear_blocks(s->block[0]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1148 /* decode each block */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1149 for (i = 0; i < 6; i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1150 if(mpeg4_decode_block(s, block[i], i, cbp&32, s->mb_intra, s->rvlc) < 0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1151 av_log(s->avctx, AV_LOG_ERROR, "texture corrupted at %d %d %d\n", s->mb_x, s->mb_y, s->mb_intra);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1152 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1153 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1154 cbp+=cbp;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1155 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1156 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1157
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1158 /* per-MB end of slice check */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1159
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1160 if(--s->mb_num_left <= 0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1161 if(mpeg4_is_resync(s))
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1162 return SLICE_END;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1163 else
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1164 return SLICE_NOEND;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1165 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1166 if(mpeg4_is_resync(s)){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1167 const int delta= s->mb_x + 1 == s->mb_width ? 2 : 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1168 if(s->cbp_table[xy+delta])
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1169 return SLICE_END;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1170 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1171 return SLICE_OK;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1172 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1173 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1174
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1175 static int mpeg4_decode_mb(MpegEncContext *s,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1176 DCTELEM block[6][64])
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1177 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1178 int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1179 int16_t *mot_val;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1180 static int8_t quant_tab[4] = { -1, -2, 1, 2 };
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1181 const int xy= s->mb_x + s->mb_y * s->mb_stride;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1182
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1183 assert(s->h263_pred);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1184
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1185 if (s->pict_type == FF_P_TYPE || s->pict_type==FF_S_TYPE) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1186 do{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1187 if (get_bits1(&s->gb)) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1188 /* skip mb */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1189 s->mb_intra = 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1190 for(i=0;i<6;i++)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1191 s->block_last_index[i] = -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1192 s->mv_dir = MV_DIR_FORWARD;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1193 s->mv_type = MV_TYPE_16X16;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1194 if(s->pict_type==FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1195 s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_GMC | MB_TYPE_16x16 | MB_TYPE_L0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1196 s->mcsel=1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1197 s->mv[0][0][0]= get_amv(s, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1198 s->mv[0][0][1]= get_amv(s, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1199
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1200 s->mb_skipped = 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1201 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1202 s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1203 s->mcsel=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1204 s->mv[0][0][0] = 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1205 s->mv[0][0][1] = 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1206 s->mb_skipped = 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1207 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1208 goto end;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1209 }
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10817
diff changeset
1210 cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1211 if (cbpc < 0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1212 av_log(s->avctx, AV_LOG_ERROR, "cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1213 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1214 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1215 }while(cbpc == 20);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1216
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1217 s->dsp.clear_blocks(s->block[0]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1218 dquant = cbpc & 8;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1219 s->mb_intra = ((cbpc & 4) != 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1220 if (s->mb_intra) goto intra;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1221
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1222 if(s->pict_type==FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE && (cbpc & 16) == 0)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1223 s->mcsel= get_bits1(&s->gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1224 else s->mcsel= 0;
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10817
diff changeset
1225 cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1) ^ 0x0F;
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1226
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1227 cbp = (cbpc & 3) | (cbpy << 2);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1228 if (dquant) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1229 ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1230 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1231 if((!s->progressive_sequence) && (cbp || (s->workaround_bugs&FF_BUG_XVID_ILACE)))
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1232 s->interlaced_dct= get_bits1(&s->gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1233
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1234 s->mv_dir = MV_DIR_FORWARD;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1235 if ((cbpc & 16) == 0) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1236 if(s->mcsel){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1237 s->current_picture.mb_type[xy]= MB_TYPE_GMC | MB_TYPE_16x16 | MB_TYPE_L0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1238 /* 16x16 global motion prediction */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1239 s->mv_type = MV_TYPE_16X16;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1240 mx= get_amv(s, 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1241 my= get_amv(s, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1242 s->mv[0][0][0] = mx;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1243 s->mv[0][0][1] = my;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1244 }else if((!s->progressive_sequence) && get_bits1(&s->gb)){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1245 s->current_picture.mb_type[xy]= MB_TYPE_16x8 | MB_TYPE_L0 | MB_TYPE_INTERLACED;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1246 /* 16x8 field motion prediction */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1247 s->mv_type= MV_TYPE_FIELD;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1248
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1249 s->field_select[0][0]= get_bits1(&s->gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1250 s->field_select[0][1]= get_bits1(&s->gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1251
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1252 h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1253
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1254 for(i=0; i<2; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1255 mx = h263_decode_motion(s, pred_x, s->f_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1256 if (mx >= 0xffff)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1257 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1258
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1259 my = h263_decode_motion(s, pred_y/2, s->f_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1260 if (my >= 0xffff)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1261 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1262
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1263 s->mv[0][i][0] = mx;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1264 s->mv[0][i][1] = my;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1265 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1266 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1267 s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1268 /* 16x16 motion prediction */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1269 s->mv_type = MV_TYPE_16X16;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1270 h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1271 mx = h263_decode_motion(s, pred_x, s->f_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1272
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1273 if (mx >= 0xffff)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1274 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1275
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1276 my = h263_decode_motion(s, pred_y, s->f_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1277
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1278 if (my >= 0xffff)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1279 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1280 s->mv[0][0][0] = mx;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1281 s->mv[0][0][1] = my;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1282 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1283 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1284 s->current_picture.mb_type[xy]= MB_TYPE_8x8 | MB_TYPE_L0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1285 s->mv_type = MV_TYPE_8X8;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1286 for(i=0;i<4;i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1287 mot_val = h263_pred_motion(s, i, 0, &pred_x, &pred_y);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1288 mx = h263_decode_motion(s, pred_x, s->f_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1289 if (mx >= 0xffff)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1290 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1291
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1292 my = h263_decode_motion(s, pred_y, s->f_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1293 if (my >= 0xffff)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1294 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1295 s->mv[0][i][0] = mx;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1296 s->mv[0][i][1] = my;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1297 mot_val[0] = mx;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1298 mot_val[1] = my;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1299 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1300 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1301 } else if(s->pict_type==FF_B_TYPE) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1302 int modb1; // first bit of modb
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1303 int modb2; // second bit of modb
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1304 int mb_type;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1305
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1306 s->mb_intra = 0; //B-frames never contain intra blocks
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1307 s->mcsel=0; // ... true gmc blocks
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1308
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1309 if(s->mb_x==0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1310 for(i=0; i<2; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1311 s->last_mv[i][0][0]=
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1312 s->last_mv[i][0][1]=
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1313 s->last_mv[i][1][0]=
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1314 s->last_mv[i][1][1]= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1315 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1316 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1317
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1318 /* if we skipped it in the future P Frame than skip it now too */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1319 s->mb_skipped= s->next_picture.mbskip_table[s->mb_y * s->mb_stride + s->mb_x]; // Note, skiptab=0 if last was GMC
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1320
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1321 if(s->mb_skipped){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1322 /* skip mb */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1323 for(i=0;i<6;i++)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1324 s->block_last_index[i] = -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1325
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1326 s->mv_dir = MV_DIR_FORWARD;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1327 s->mv_type = MV_TYPE_16X16;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1328 s->mv[0][0][0] = 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1329 s->mv[0][0][1] = 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1330 s->mv[1][0][0] = 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1331 s->mv[1][0][1] = 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1332 s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1333 goto end;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1334 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1335
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1336 modb1= get_bits1(&s->gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1337 if(modb1){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1338 mb_type= MB_TYPE_DIRECT2 | MB_TYPE_SKIP | MB_TYPE_L0L1; //like MB_TYPE_B_DIRECT but no vectors coded
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1339 cbp=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1340 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1341 modb2= get_bits1(&s->gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1342 mb_type= get_vlc2(&s->gb, mb_type_b_vlc.table, MB_TYPE_B_VLC_BITS, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1343 if(mb_type<0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1344 av_log(s->avctx, AV_LOG_ERROR, "illegal MB_type\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1345 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1346 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1347 mb_type= mb_type_b_map[ mb_type ];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1348 if(modb2) cbp= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1349 else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1350 s->dsp.clear_blocks(s->block[0]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1351 cbp= get_bits(&s->gb, 6);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1352 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1353
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1354 if ((!IS_DIRECT(mb_type)) && cbp) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1355 if(get_bits1(&s->gb)){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1356 ff_set_qscale(s, s->qscale + get_bits1(&s->gb)*4 - 2);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1357 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1358 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1359
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1360 if(!s->progressive_sequence){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1361 if(cbp)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1362 s->interlaced_dct= get_bits1(&s->gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1363
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1364 if(!IS_DIRECT(mb_type) && get_bits1(&s->gb)){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1365 mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1366 mb_type &= ~MB_TYPE_16x16;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1367
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1368 if(USES_LIST(mb_type, 0)){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1369 s->field_select[0][0]= get_bits1(&s->gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1370 s->field_select[0][1]= get_bits1(&s->gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1371 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1372 if(USES_LIST(mb_type, 1)){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1373 s->field_select[1][0]= get_bits1(&s->gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1374 s->field_select[1][1]= get_bits1(&s->gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1375 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1376 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1377 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1378
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1379 s->mv_dir = 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1380 if((mb_type & (MB_TYPE_DIRECT2|MB_TYPE_INTERLACED)) == 0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1381 s->mv_type= MV_TYPE_16X16;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1382
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1383 if(USES_LIST(mb_type, 0)){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1384 s->mv_dir = MV_DIR_FORWARD;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1385
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1386 mx = h263_decode_motion(s, s->last_mv[0][0][0], s->f_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1387 my = h263_decode_motion(s, s->last_mv[0][0][1], s->f_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1388 s->last_mv[0][1][0]= s->last_mv[0][0][0]= s->mv[0][0][0] = mx;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1389 s->last_mv[0][1][1]= s->last_mv[0][0][1]= s->mv[0][0][1] = my;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1390 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1391
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1392 if(USES_LIST(mb_type, 1)){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1393 s->mv_dir |= MV_DIR_BACKWARD;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1394
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1395 mx = h263_decode_motion(s, s->last_mv[1][0][0], s->b_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1396 my = h263_decode_motion(s, s->last_mv[1][0][1], s->b_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1397 s->last_mv[1][1][0]= s->last_mv[1][0][0]= s->mv[1][0][0] = mx;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1398 s->last_mv[1][1][1]= s->last_mv[1][0][1]= s->mv[1][0][1] = my;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1399 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1400 }else if(!IS_DIRECT(mb_type)){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1401 s->mv_type= MV_TYPE_FIELD;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1402
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1403 if(USES_LIST(mb_type, 0)){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1404 s->mv_dir = MV_DIR_FORWARD;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1405
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1406 for(i=0; i<2; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1407 mx = h263_decode_motion(s, s->last_mv[0][i][0] , s->f_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1408 my = h263_decode_motion(s, s->last_mv[0][i][1]/2, s->f_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1409 s->last_mv[0][i][0]= s->mv[0][i][0] = mx;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1410 s->last_mv[0][i][1]= (s->mv[0][i][1] = my)*2;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1411 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1412 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1413
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1414 if(USES_LIST(mb_type, 1)){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1415 s->mv_dir |= MV_DIR_BACKWARD;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1416
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1417 for(i=0; i<2; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1418 mx = h263_decode_motion(s, s->last_mv[1][i][0] , s->b_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1419 my = h263_decode_motion(s, s->last_mv[1][i][1]/2, s->b_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1420 s->last_mv[1][i][0]= s->mv[1][i][0] = mx;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1421 s->last_mv[1][i][1]= (s->mv[1][i][1] = my)*2;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1422 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1423 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1424 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1425 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1426
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1427 if(IS_DIRECT(mb_type)){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1428 if(IS_SKIP(mb_type))
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1429 mx=my=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1430 else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1431 mx = h263_decode_motion(s, 0, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1432 my = h263_decode_motion(s, 0, 1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1433 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1434
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1435 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1436 mb_type |= ff_mpeg4_set_direct_mv(s, mx, my);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1437 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1438 s->current_picture.mb_type[xy]= mb_type;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1439 } else { /* I-Frame */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1440 do{
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10817
diff changeset
1441 cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2);
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1442 if (cbpc < 0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1443 av_log(s->avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1444 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1445 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1446 }while(cbpc == 8);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1447
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1448 dquant = cbpc & 4;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1449 s->mb_intra = 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1450 intra:
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1451 s->ac_pred = get_bits1(&s->gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1452 if(s->ac_pred)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1453 s->current_picture.mb_type[xy]= MB_TYPE_INTRA | MB_TYPE_ACPRED;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1454 else
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1455 s->current_picture.mb_type[xy]= MB_TYPE_INTRA;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1456
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10817
diff changeset
1457 cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1458 if(cbpy<0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1459 av_log(s->avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1460 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1461 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1462 cbp = (cbpc & 3) | (cbpy << 2);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1463
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1464 s->use_intra_dc_vlc= s->qscale < s->intra_dc_threshold;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1465
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1466 if (dquant) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1467 ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1468 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1469
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1470 if(!s->progressive_sequence)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1471 s->interlaced_dct= get_bits1(&s->gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1472
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1473 s->dsp.clear_blocks(s->block[0]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1474 /* decode each block */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1475 for (i = 0; i < 6; i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1476 if (mpeg4_decode_block(s, block[i], i, cbp&32, 1, 0) < 0)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1477 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1478 cbp+=cbp;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1479 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1480 goto end;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1481 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1482
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1483 /* decode each block */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1484 for (i = 0; i < 6; i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1485 if (mpeg4_decode_block(s, block[i], i, cbp&32, 0, 0) < 0)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1486 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1487 cbp+=cbp;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1488 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1489 end:
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1490
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1491 /* per-MB end of slice check */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1492 if(s->codec_id==CODEC_ID_MPEG4){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1493 if(mpeg4_is_resync(s)){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1494 const int delta= s->mb_x + 1 == s->mb_width ? 2 : 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1495 if(s->pict_type==FF_B_TYPE && s->next_picture.mbskip_table[xy + delta])
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1496 return SLICE_OK;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1497 return SLICE_END;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1498 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1499 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1500
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1501 return SLICE_OK;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1502 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1503
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1504
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1505 static int mpeg4_decode_gop_header(MpegEncContext * s, GetBitContext *gb){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1506 int hours, minutes, seconds;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1507
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1508 hours= get_bits(gb, 5);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1509 minutes= get_bits(gb, 6);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1510 skip_bits1(gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1511 seconds= get_bits(gb, 6);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1512
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1513 s->time_base= seconds + 60*(minutes + 60*hours);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1514
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1515 skip_bits1(gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1516 skip_bits1(gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1517
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1518 return 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1519 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1520
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1521 static int decode_vol_header(MpegEncContext *s, GetBitContext *gb){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1522 int width, height, vo_ver_id;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1523
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1524 /* vol header */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1525 skip_bits(gb, 1); /* random access */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1526 s->vo_type= get_bits(gb, 8);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1527 if (get_bits1(gb) != 0) { /* is_ol_id */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1528 vo_ver_id = get_bits(gb, 4); /* vo_ver_id */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1529 skip_bits(gb, 3); /* vo_priority */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1530 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1531 vo_ver_id = 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1532 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1533 s->aspect_ratio_info= get_bits(gb, 4);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1534 if(s->aspect_ratio_info == FF_ASPECT_EXTENDED){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1535 s->avctx->sample_aspect_ratio.num= get_bits(gb, 8); // par_width
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1536 s->avctx->sample_aspect_ratio.den= get_bits(gb, 8); // par_height
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1537 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1538 s->avctx->sample_aspect_ratio= ff_h263_pixel_aspect[s->aspect_ratio_info];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1539 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1540
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1541 if ((s->vol_control_parameters=get_bits1(gb))) { /* vol control parameter */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1542 int chroma_format= get_bits(gb, 2);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1543 if(chroma_format!=CHROMA_420){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1544 av_log(s->avctx, AV_LOG_ERROR, "illegal chroma format\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1545 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1546 s->low_delay= get_bits1(gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1547 if(get_bits1(gb)){ /* vbv parameters */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1548 get_bits(gb, 15); /* first_half_bitrate */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1549 skip_bits1(gb); /* marker */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1550 get_bits(gb, 15); /* latter_half_bitrate */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1551 skip_bits1(gb); /* marker */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1552 get_bits(gb, 15); /* first_half_vbv_buffer_size */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1553 skip_bits1(gb); /* marker */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1554 get_bits(gb, 3); /* latter_half_vbv_buffer_size */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1555 get_bits(gb, 11); /* first_half_vbv_occupancy */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1556 skip_bits1(gb); /* marker */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1557 get_bits(gb, 15); /* latter_half_vbv_occupancy */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1558 skip_bits1(gb); /* marker */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1559 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1560 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1561 // set low delay flag only once the smartest? low delay detection won't be overriden
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1562 if(s->picture_number==0)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1563 s->low_delay=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1564 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1565
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1566 s->shape = get_bits(gb, 2); /* vol shape */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1567 if(s->shape != RECT_SHAPE) av_log(s->avctx, AV_LOG_ERROR, "only rectangular vol supported\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1568 if(s->shape == GRAY_SHAPE && vo_ver_id != 1){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1569 av_log(s->avctx, AV_LOG_ERROR, "Gray shape not supported\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1570 skip_bits(gb, 4); //video_object_layer_shape_extension
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1571 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1572
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1573 check_marker(gb, "before time_increment_resolution");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1574
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1575 s->avctx->time_base.den = get_bits(gb, 16);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1576 if(!s->avctx->time_base.den){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1577 av_log(s->avctx, AV_LOG_ERROR, "time_base.den==0\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1578 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1579 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1580
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1581 s->time_increment_bits = av_log2(s->avctx->time_base.den - 1) + 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1582 if (s->time_increment_bits < 1)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1583 s->time_increment_bits = 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1584
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1585 check_marker(gb, "before fixed_vop_rate");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1586
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1587 if (get_bits1(gb) != 0) { /* fixed_vop_rate */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1588 s->avctx->time_base.num = get_bits(gb, s->time_increment_bits);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1589 }else
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1590 s->avctx->time_base.num = 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1591
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1592 s->t_frame=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1593
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1594 if (s->shape != BIN_ONLY_SHAPE) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1595 if (s->shape == RECT_SHAPE) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1596 skip_bits1(gb); /* marker */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1597 width = get_bits(gb, 13);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1598 skip_bits1(gb); /* marker */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1599 height = get_bits(gb, 13);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1600 skip_bits1(gb); /* marker */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1601 if(width && height && !(s->width && s->codec_tag == AV_RL32("MP4S"))){ /* they should be non zero but who knows ... */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1602 s->width = width;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1603 s->height = height;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1604 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1605 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1606
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1607 s->progressive_sequence=
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1608 s->progressive_frame= get_bits1(gb)^1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1609 s->interlaced_dct=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1610 if(!get_bits1(gb) && (s->avctx->debug & FF_DEBUG_PICT_INFO))
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1611 av_log(s->avctx, AV_LOG_INFO, "MPEG4 OBMC not supported (very likely buggy encoder)\n"); /* OBMC Disable */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1612 if (vo_ver_id == 1) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1613 s->vol_sprite_usage = get_bits1(gb); /* vol_sprite_usage */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1614 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1615 s->vol_sprite_usage = get_bits(gb, 2); /* vol_sprite_usage */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1616 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1617 if(s->vol_sprite_usage==STATIC_SPRITE) av_log(s->avctx, AV_LOG_ERROR, "Static Sprites not supported\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1618 if(s->vol_sprite_usage==STATIC_SPRITE || s->vol_sprite_usage==GMC_SPRITE){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1619 if(s->vol_sprite_usage==STATIC_SPRITE){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1620 s->sprite_width = get_bits(gb, 13);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1621 skip_bits1(gb); /* marker */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1622 s->sprite_height= get_bits(gb, 13);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1623 skip_bits1(gb); /* marker */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1624 s->sprite_left = get_bits(gb, 13);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1625 skip_bits1(gb); /* marker */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1626 s->sprite_top = get_bits(gb, 13);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1627 skip_bits1(gb); /* marker */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1628 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1629 s->num_sprite_warping_points= get_bits(gb, 6);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1630 if(s->num_sprite_warping_points > 3){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1631 av_log(s->avctx, AV_LOG_ERROR, "%d sprite_warping_points\n", s->num_sprite_warping_points);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1632 s->num_sprite_warping_points= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1633 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1634 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1635 s->sprite_warping_accuracy = get_bits(gb, 2);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1636 s->sprite_brightness_change= get_bits1(gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1637 if(s->vol_sprite_usage==STATIC_SPRITE)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1638 s->low_latency_sprite= get_bits1(gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1639 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1640 // FIXME sadct disable bit if verid!=1 && shape not rect
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1641
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1642 if (get_bits1(gb) == 1) { /* not_8_bit */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1643 s->quant_precision = get_bits(gb, 4); /* quant_precision */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1644 if(get_bits(gb, 4)!=8) av_log(s->avctx, AV_LOG_ERROR, "N-bit not supported\n"); /* bits_per_pixel */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1645 if(s->quant_precision!=5) av_log(s->avctx, AV_LOG_ERROR, "quant precision %d\n", s->quant_precision);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1646 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1647 s->quant_precision = 5;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1648 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1649
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1650 // FIXME a bunch of grayscale shape things
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1651
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1652 if((s->mpeg_quant=get_bits1(gb))){ /* vol_quant_type */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1653 int i, v;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1654
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1655 /* load default matrixes */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1656 for(i=0; i<64; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1657 int j= s->dsp.idct_permutation[i];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1658 v= ff_mpeg4_default_intra_matrix[i];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1659 s->intra_matrix[j]= v;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1660 s->chroma_intra_matrix[j]= v;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1661
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1662 v= ff_mpeg4_default_non_intra_matrix[i];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1663 s->inter_matrix[j]= v;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1664 s->chroma_inter_matrix[j]= v;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1665 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1666
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1667 /* load custom intra matrix */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1668 if(get_bits1(gb)){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1669 int last=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1670 for(i=0; i<64; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1671 int j;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1672 v= get_bits(gb, 8);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1673 if(v==0) break;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1674
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1675 last= v;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1676 j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1677 s->intra_matrix[j]= v;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1678 s->chroma_intra_matrix[j]= v;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1679 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1680
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1681 /* replicate last value */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1682 for(; i<64; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1683 int j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1684 s->intra_matrix[j]= last;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1685 s->chroma_intra_matrix[j]= last;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1686 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1687 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1688
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1689 /* load custom non intra matrix */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1690 if(get_bits1(gb)){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1691 int last=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1692 for(i=0; i<64; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1693 int j;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1694 v= get_bits(gb, 8);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1695 if(v==0) break;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1696
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1697 last= v;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1698 j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1699 s->inter_matrix[j]= v;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1700 s->chroma_inter_matrix[j]= v;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1701 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1702
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1703 /* replicate last value */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1704 for(; i<64; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1705 int j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1706 s->inter_matrix[j]= last;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1707 s->chroma_inter_matrix[j]= last;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1708 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1709 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1710
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1711 // FIXME a bunch of grayscale shape things
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1712 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1713
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1714 if(vo_ver_id != 1)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1715 s->quarter_sample= get_bits1(gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1716 else s->quarter_sample=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1717
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1718 if(!get_bits1(gb)){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1719 int pos= get_bits_count(gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1720 int estimation_method= get_bits(gb, 2);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1721 if(estimation_method<2){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1722 if(!get_bits1(gb)){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1723 s->cplx_estimation_trash_i += 8*get_bits1(gb); //opaque
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1724 s->cplx_estimation_trash_i += 8*get_bits1(gb); //transparent
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1725 s->cplx_estimation_trash_i += 8*get_bits1(gb); //intra_cae
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1726 s->cplx_estimation_trash_i += 8*get_bits1(gb); //inter_cae
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1727 s->cplx_estimation_trash_i += 8*get_bits1(gb); //no_update
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1728 s->cplx_estimation_trash_i += 8*get_bits1(gb); //upampling
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1729 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1730 if(!get_bits1(gb)){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1731 s->cplx_estimation_trash_i += 8*get_bits1(gb); //intra_blocks
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1732 s->cplx_estimation_trash_p += 8*get_bits1(gb); //inter_blocks
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1733 s->cplx_estimation_trash_p += 8*get_bits1(gb); //inter4v_blocks
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1734 s->cplx_estimation_trash_i += 8*get_bits1(gb); //not coded blocks
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1735 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1736 if(!check_marker(gb, "in complexity estimation part 1")){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1737 skip_bits_long(gb, pos - get_bits_count(gb));
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1738 goto no_cplx_est;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1739 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1740 if(!get_bits1(gb)){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1741 s->cplx_estimation_trash_i += 8*get_bits1(gb); //dct_coeffs
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1742 s->cplx_estimation_trash_i += 8*get_bits1(gb); //dct_lines
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1743 s->cplx_estimation_trash_i += 8*get_bits1(gb); //vlc_syms
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1744 s->cplx_estimation_trash_i += 4*get_bits1(gb); //vlc_bits
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1745 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1746 if(!get_bits1(gb)){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1747 s->cplx_estimation_trash_p += 8*get_bits1(gb); //apm
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1748 s->cplx_estimation_trash_p += 8*get_bits1(gb); //npm
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1749 s->cplx_estimation_trash_b += 8*get_bits1(gb); //interpolate_mc_q
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1750 s->cplx_estimation_trash_p += 8*get_bits1(gb); //forwback_mc_q
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1751 s->cplx_estimation_trash_p += 8*get_bits1(gb); //halfpel2
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1752 s->cplx_estimation_trash_p += 8*get_bits1(gb); //halfpel4
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1753 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1754 if(!check_marker(gb, "in complexity estimation part 2")){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1755 skip_bits_long(gb, pos - get_bits_count(gb));
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1756 goto no_cplx_est;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1757 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1758 if(estimation_method==1){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1759 s->cplx_estimation_trash_i += 8*get_bits1(gb); //sadct
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1760 s->cplx_estimation_trash_p += 8*get_bits1(gb); //qpel
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1761 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1762 }else
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1763 av_log(s->avctx, AV_LOG_ERROR, "Invalid Complexity estimation method %d\n", estimation_method);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1764 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1765 no_cplx_est:
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1766 s->cplx_estimation_trash_i=
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1767 s->cplx_estimation_trash_p=
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1768 s->cplx_estimation_trash_b= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1769 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1770
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1771 s->resync_marker= !get_bits1(gb); /* resync_marker_disabled */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1772
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1773 s->data_partitioning= get_bits1(gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1774 if(s->data_partitioning){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1775 s->rvlc= get_bits1(gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1776 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1777
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1778 if(vo_ver_id != 1) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1779 s->new_pred= get_bits1(gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1780 if(s->new_pred){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1781 av_log(s->avctx, AV_LOG_ERROR, "new pred not supported\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1782 skip_bits(gb, 2); /* requested upstream message type */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1783 skip_bits1(gb); /* newpred segment type */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1784 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1785 s->reduced_res_vop= get_bits1(gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1786 if(s->reduced_res_vop) av_log(s->avctx, AV_LOG_ERROR, "reduced resolution VOP not supported\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1787 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1788 else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1789 s->new_pred=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1790 s->reduced_res_vop= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1791 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1792
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1793 s->scalability= get_bits1(gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1794
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1795 if (s->scalability) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1796 GetBitContext bak= *gb;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1797 int ref_layer_id;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1798 int ref_layer_sampling_dir;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1799 int h_sampling_factor_n;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1800 int h_sampling_factor_m;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1801 int v_sampling_factor_n;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1802 int v_sampling_factor_m;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1804 s->hierachy_type= get_bits1(gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1805 ref_layer_id= get_bits(gb, 4);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1806 ref_layer_sampling_dir= get_bits1(gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1807 h_sampling_factor_n= get_bits(gb, 5);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1808 h_sampling_factor_m= get_bits(gb, 5);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1809 v_sampling_factor_n= get_bits(gb, 5);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1810 v_sampling_factor_m= get_bits(gb, 5);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1811 s->enhancement_type= get_bits1(gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1812
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1813 if( h_sampling_factor_n==0 || h_sampling_factor_m==0
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1814 || v_sampling_factor_n==0 || v_sampling_factor_m==0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1815 /* illegal scalability header (VERY broken encoder),
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1816 * trying to workaround */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1817 s->scalability=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1818 *gb= bak;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1819 }else
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1820 av_log(s->avctx, AV_LOG_ERROR, "scalability not supported\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1821
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1822 // bin shape stuff FIXME
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1823 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1824 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1825 return 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1826 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1827
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1828 /**
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1829 * decodes the user data stuff in the header.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1830 * Also initializes divx/xvid/lavc_version/build.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1831 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1832 static int decode_user_data(MpegEncContext *s, GetBitContext *gb){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1833 char buf[256];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1834 int i;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1835 int e;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1836 int ver = 0, build = 0, ver2 = 0, ver3 = 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1837 char last;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1838
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1839 for(i=0; i<255 && get_bits_count(gb) < gb->size_in_bits; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1840 if(show_bits(gb, 23) == 0) break;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1841 buf[i]= get_bits(gb, 8);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1842 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1843 buf[i]=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1844
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1845 /* divx detection */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1846 e=sscanf(buf, "DivX%dBuild%d%c", &ver, &build, &last);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1847 if(e<2)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1848 e=sscanf(buf, "DivX%db%d%c", &ver, &build, &last);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1849 if(e>=2){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1850 s->divx_version= ver;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1851 s->divx_build= build;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1852 s->divx_packed= e==3 && last=='p';
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1853 if(s->divx_packed && !s->showed_packed_warning) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1854 av_log(s->avctx, AV_LOG_WARNING, "Invalid and inefficient vfw-avi packed B frames detected\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1855 s->showed_packed_warning=1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1856 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1857 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1858
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1859 /* ffmpeg detection */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1860 e=sscanf(buf, "FFmpe%*[^b]b%d", &build)+3;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1861 if(e!=4)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1862 e=sscanf(buf, "FFmpeg v%d.%d.%d / libavcodec build: %d", &ver, &ver2, &ver3, &build);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1863 if(e!=4){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1864 e=sscanf(buf, "Lavc%d.%d.%d", &ver, &ver2, &ver3)+1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1865 if (e>1)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1866 build= (ver<<16) + (ver2<<8) + ver3;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1867 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1868 if(e!=4){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1869 if(strcmp(buf, "ffmpeg")==0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1870 s->lavc_build= 4600;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1871 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1872 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1873 if(e==4){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1874 s->lavc_build= build;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1875 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1876
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1877 /* Xvid detection */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1878 e=sscanf(buf, "XviD%d", &build);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1879 if(e==1){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1880 s->xvid_build= build;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1881 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1882
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1883 return 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1884 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1885
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1886 static int decode_vop_header(MpegEncContext *s, GetBitContext *gb){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1887 int time_incr, time_increment;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1888
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1889 s->pict_type = get_bits(gb, 2) + FF_I_TYPE; /* pict type: I = 0 , P = 1 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1890 if(s->pict_type==FF_B_TYPE && s->low_delay && s->vol_control_parameters==0 && !(s->flags & CODEC_FLAG_LOW_DELAY)){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1891 av_log(s->avctx, AV_LOG_ERROR, "low_delay flag incorrectly, clearing it\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1892 s->low_delay=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1893 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1894
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1895 s->partitioned_frame= s->data_partitioning && s->pict_type!=FF_B_TYPE;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1896 if(s->partitioned_frame)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1897 s->decode_mb= mpeg4_decode_partitioned_mb;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1898 else
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1899 s->decode_mb= mpeg4_decode_mb;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1900
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1901 time_incr=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1902 while (get_bits1(gb) != 0)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1903 time_incr++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1904
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1905 check_marker(gb, "before time_increment");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1906
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1907 if(s->time_increment_bits==0 || !(show_bits(gb, s->time_increment_bits+1)&1)){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1908 av_log(s->avctx, AV_LOG_ERROR, "hmm, seems the headers are not complete, trying to guess time_increment_bits\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1909
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1910 for(s->time_increment_bits=1 ;s->time_increment_bits<16; s->time_increment_bits++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1911 if ( s->pict_type == FF_P_TYPE
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1912 || (s->pict_type == FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE)) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1913 if((show_bits(gb, s->time_increment_bits+6)&0x37) == 0x30) break;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1914 }else
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1915 if((show_bits(gb, s->time_increment_bits+5)&0x1F) == 0x18) break;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1916 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1917
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1918 av_log(s->avctx, AV_LOG_ERROR, "my guess is %d bits ;)\n",s->time_increment_bits);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1919 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1920
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1921 if(IS_3IV1) time_increment= get_bits1(gb); //FIXME investigate further
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1922 else time_increment= get_bits(gb, s->time_increment_bits);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1923
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1924 if(s->pict_type!=FF_B_TYPE){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1925 s->last_time_base= s->time_base;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1926 s->time_base+= time_incr;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1927 s->time= s->time_base*s->avctx->time_base.den + time_increment;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1928 if(s->workaround_bugs&FF_BUG_UMP4){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1929 if(s->time < s->last_non_b_time){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1930 /* header is not mpeg-4-compatible, broken encoder,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1931 * trying to workaround */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1932 s->time_base++;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1933 s->time+= s->avctx->time_base.den;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1934 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1935 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1936 s->pp_time= s->time - s->last_non_b_time;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1937 s->last_non_b_time= s->time;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1938 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1939 s->time= (s->last_time_base + time_incr)*s->avctx->time_base.den + time_increment;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1940 s->pb_time= s->pp_time - (s->last_non_b_time - s->time);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1941 if(s->pp_time <=s->pb_time || s->pp_time <= s->pp_time - s->pb_time || s->pp_time<=0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1942 /* messed up order, maybe after seeking? skipping current b-frame */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1943 return FRAME_SKIPPED;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1944 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1945 ff_mpeg4_init_direct_mv(s);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1946
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1947 if(s->t_frame==0) s->t_frame= s->pb_time;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1948 if(s->t_frame==0) s->t_frame=1; // 1/0 protection
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1949 s->pp_field_time= ( ROUNDED_DIV(s->last_non_b_time, s->t_frame)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1950 - ROUNDED_DIV(s->last_non_b_time - s->pp_time, s->t_frame))*2;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1951 s->pb_field_time= ( ROUNDED_DIV(s->time, s->t_frame)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1952 - ROUNDED_DIV(s->last_non_b_time - s->pp_time, s->t_frame))*2;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1953 if(!s->progressive_sequence){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1954 if(s->pp_field_time <= s->pb_field_time || s->pb_field_time <= 1)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1955 return FRAME_SKIPPED;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1956 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1957 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1958
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1959 if(s->avctx->time_base.num)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1960 s->current_picture_ptr->pts= (s->time + s->avctx->time_base.num/2) / s->avctx->time_base.num;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1961 else
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1962 s->current_picture_ptr->pts= AV_NOPTS_VALUE;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1963 if(s->avctx->debug&FF_DEBUG_PTS)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1964 av_log(s->avctx, AV_LOG_DEBUG, "MPEG4 PTS: %"PRId64"\n", s->current_picture_ptr->pts);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1965
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1966 check_marker(gb, "before vop_coded");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1967
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1968 /* vop coded */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1969 if (get_bits1(gb) != 1){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1970 if(s->avctx->debug&FF_DEBUG_PICT_INFO)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1971 av_log(s->avctx, AV_LOG_ERROR, "vop not coded\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1972 return FRAME_SKIPPED;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1973 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1974 if (s->shape != BIN_ONLY_SHAPE && ( s->pict_type == FF_P_TYPE
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1975 || (s->pict_type == FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE))) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1976 /* rounding type for motion estimation */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1977 s->no_rounding = get_bits1(gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1978 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1979 s->no_rounding = 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1980 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1981 //FIXME reduced res stuff
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1982
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1983 if (s->shape != RECT_SHAPE) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1984 if (s->vol_sprite_usage != 1 || s->pict_type != FF_I_TYPE) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1985 int width, height, hor_spat_ref, ver_spat_ref;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1986
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1987 width = get_bits(gb, 13);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1988 skip_bits1(gb); /* marker */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1989 height = get_bits(gb, 13);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1990 skip_bits1(gb); /* marker */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1991 hor_spat_ref = get_bits(gb, 13); /* hor_spat_ref */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1992 skip_bits1(gb); /* marker */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1993 ver_spat_ref = get_bits(gb, 13); /* ver_spat_ref */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1994 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1995 skip_bits1(gb); /* change_CR_disable */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1996
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1997 if (get_bits1(gb) != 0) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1998 skip_bits(gb, 8); /* constant_alpha_value */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1999 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2000 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2001 //FIXME complexity estimation stuff
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2002
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2003 if (s->shape != BIN_ONLY_SHAPE) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2004 skip_bits_long(gb, s->cplx_estimation_trash_i);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2005 if(s->pict_type != FF_I_TYPE)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2006 skip_bits_long(gb, s->cplx_estimation_trash_p);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2007 if(s->pict_type == FF_B_TYPE)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2008 skip_bits_long(gb, s->cplx_estimation_trash_b);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2009
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2010 s->intra_dc_threshold= mpeg4_dc_threshold[ get_bits(gb, 3) ];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2011 if(!s->progressive_sequence){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2012 s->top_field_first= get_bits1(gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2013 s->alternate_scan= get_bits1(gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2014 }else
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2015 s->alternate_scan= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2016 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2017
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2018 if(s->alternate_scan){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2019 ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_alternate_vertical_scan);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2020 ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_alternate_vertical_scan);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2021 ff_init_scantable(s->dsp.idct_permutation, &s->intra_h_scantable, ff_alternate_vertical_scan);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2022 ff_init_scantable(s->dsp.idct_permutation, &s->intra_v_scantable, ff_alternate_vertical_scan);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2023 } else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2024 ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_zigzag_direct);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2025 ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_zigzag_direct);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2026 ff_init_scantable(s->dsp.idct_permutation, &s->intra_h_scantable, ff_alternate_horizontal_scan);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2027 ff_init_scantable(s->dsp.idct_permutation, &s->intra_v_scantable, ff_alternate_vertical_scan);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2028 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2029
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2030 if(s->pict_type == FF_S_TYPE && (s->vol_sprite_usage==STATIC_SPRITE || s->vol_sprite_usage==GMC_SPRITE)){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2031 mpeg4_decode_sprite_trajectory(s, gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2032 if(s->sprite_brightness_change) av_log(s->avctx, AV_LOG_ERROR, "sprite_brightness_change not supported\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2033 if(s->vol_sprite_usage==STATIC_SPRITE) av_log(s->avctx, AV_LOG_ERROR, "static sprite not supported\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2034 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2035
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2036 if (s->shape != BIN_ONLY_SHAPE) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2037 s->chroma_qscale= s->qscale = get_bits(gb, s->quant_precision);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2038 if(s->qscale==0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2039 av_log(s->avctx, AV_LOG_ERROR, "Error, header damaged or not MPEG4 header (qscale=0)\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2040 return -1; // makes no sense to continue, as there is nothing left from the image then
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2041 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2042
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2043 if (s->pict_type != FF_I_TYPE) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2044 s->f_code = get_bits(gb, 3); /* fcode_for */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2045 if(s->f_code==0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2046 av_log(s->avctx, AV_LOG_ERROR, "Error, header damaged or not MPEG4 header (f_code=0)\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2047 return -1; // makes no sense to continue, as the MV decoding will break very quickly
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2048 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2049 }else
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2050 s->f_code=1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2051
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2052 if (s->pict_type == FF_B_TYPE) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2053 s->b_code = get_bits(gb, 3);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2054 }else
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2055 s->b_code=1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2056
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2057 if(s->avctx->debug&FF_DEBUG_PICT_INFO){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2058 av_log(s->avctx, AV_LOG_DEBUG, "qp:%d fc:%d,%d %s size:%d pro:%d alt:%d top:%d %spel part:%d resync:%d w:%d a:%d rnd:%d vot:%d%s dc:%d ce:%d/%d/%d\n",
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2059 s->qscale, s->f_code, s->b_code,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2060 s->pict_type == FF_I_TYPE ? "I" : (s->pict_type == FF_P_TYPE ? "P" : (s->pict_type == FF_B_TYPE ? "B" : "S")),
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2061 gb->size_in_bits,s->progressive_sequence, s->alternate_scan, s->top_field_first,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2062 s->quarter_sample ? "q" : "h", s->data_partitioning, s->resync_marker, s->num_sprite_warping_points,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2063 s->sprite_warping_accuracy, 1-s->no_rounding, s->vo_type, s->vol_control_parameters ? " VOLC" : " ", s->intra_dc_threshold, s->cplx_estimation_trash_i, s->cplx_estimation_trash_p, s->cplx_estimation_trash_b);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2064 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2065
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2066 if(!s->scalability){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2067 if (s->shape!=RECT_SHAPE && s->pict_type!=FF_I_TYPE) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2068 skip_bits1(gb); // vop shape coding type
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2069 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2070 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2071 if(s->enhancement_type){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2072 int load_backward_shape= get_bits1(gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2073 if(load_backward_shape){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2074 av_log(s->avctx, AV_LOG_ERROR, "load backward shape isn't supported\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2075 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2076 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2077 skip_bits(gb, 2); //ref_select_code
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2078 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2079 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2080 /* detect buggy encoders which don't set the low_delay flag (divx4/xvid/opendivx)*/
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2081 // note we cannot detect divx5 without b-frames easily (although it's buggy too)
11098
77b3f322dba8 Change xvid/divx/lavc build variables to be consistent to x264_build.
michael
parents: 10818
diff changeset
2082 if(s->vo_type==0 && s->vol_control_parameters==0 && s->divx_version==-1 && s->picture_number==0){
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2083 av_log(s->avctx, AV_LOG_ERROR, "looks like this file was encoded with (divx4/(old)xvid/opendivx) -> forcing low_delay flag\n");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2084 s->low_delay=1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2085 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2086
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2087 s->picture_number++; // better than pic number==0 always ;)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2088
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2089 s->y_dc_scale_table= ff_mpeg4_y_dc_scale_table; //FIXME add short header support
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2090 s->c_dc_scale_table= ff_mpeg4_c_dc_scale_table;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2091
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2092 if(s->workaround_bugs&FF_BUG_EDGE){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2093 s->h_edge_pos= s->width;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2094 s->v_edge_pos= s->height;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2095 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2096 return 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2097 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2098
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2099 /**
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2100 * decode mpeg4 headers
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2101 * @return <0 if no VOP found (or a damaged one)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2102 * FRAME_SKIPPED if a not coded VOP is found
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2103 * 0 if a VOP is found
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2104 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2105 int ff_mpeg4_decode_picture_header(MpegEncContext * s, GetBitContext *gb)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2106 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2107 int startcode, v;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2108
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2109 /* search next start code */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2110 align_get_bits(gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2111
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2112 if(s->codec_tag == AV_RL32("WV1F") && show_bits(gb, 24) == 0x575630){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2113 skip_bits(gb, 24);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2114 if(get_bits(gb, 8) == 0xF0)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2115 goto end;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2116 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2117
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2118 startcode = 0xff;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2119 for(;;) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2120 if(get_bits_count(gb) >= gb->size_in_bits){
11098
77b3f322dba8 Change xvid/divx/lavc build variables to be consistent to x264_build.
michael
parents: 10818
diff changeset
2121 if(gb->size_in_bits==8 && (s->divx_version>=0 || s->xvid_build>=0)){
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2122 av_log(s->avctx, AV_LOG_ERROR, "frame skip %d\n", gb->size_in_bits);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2123 return FRAME_SKIPPED; //divx bug
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2124 }else
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2125 return -1; //end of stream
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2126 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2127
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2128 /* use the bits after the test */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2129 v = get_bits(gb, 8);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2130 startcode = ((startcode << 8) | v) & 0xffffffff;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2131
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2132 if((startcode&0xFFFFFF00) != 0x100)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2133 continue; //no startcode
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2134
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2135 if(s->avctx->debug&FF_DEBUG_STARTCODE){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2136 av_log(s->avctx, AV_LOG_DEBUG, "startcode: %3X ", startcode);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2137 if (startcode<=0x11F) av_log(s->avctx, AV_LOG_DEBUG, "Video Object Start");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2138 else if(startcode<=0x12F) av_log(s->avctx, AV_LOG_DEBUG, "Video Object Layer Start");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2139 else if(startcode<=0x13F) av_log(s->avctx, AV_LOG_DEBUG, "Reserved");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2140 else if(startcode<=0x15F) av_log(s->avctx, AV_LOG_DEBUG, "FGS bp start");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2141 else if(startcode<=0x1AF) av_log(s->avctx, AV_LOG_DEBUG, "Reserved");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2142 else if(startcode==0x1B0) av_log(s->avctx, AV_LOG_DEBUG, "Visual Object Seq Start");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2143 else if(startcode==0x1B1) av_log(s->avctx, AV_LOG_DEBUG, "Visual Object Seq End");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2144 else if(startcode==0x1B2) av_log(s->avctx, AV_LOG_DEBUG, "User Data");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2145 else if(startcode==0x1B3) av_log(s->avctx, AV_LOG_DEBUG, "Group of VOP start");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2146 else if(startcode==0x1B4) av_log(s->avctx, AV_LOG_DEBUG, "Video Session Error");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2147 else if(startcode==0x1B5) av_log(s->avctx, AV_LOG_DEBUG, "Visual Object Start");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2148 else if(startcode==0x1B6) av_log(s->avctx, AV_LOG_DEBUG, "Video Object Plane start");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2149 else if(startcode==0x1B7) av_log(s->avctx, AV_LOG_DEBUG, "slice start");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2150 else if(startcode==0x1B8) av_log(s->avctx, AV_LOG_DEBUG, "extension start");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2151 else if(startcode==0x1B9) av_log(s->avctx, AV_LOG_DEBUG, "fgs start");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2152 else if(startcode==0x1BA) av_log(s->avctx, AV_LOG_DEBUG, "FBA Object start");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2153 else if(startcode==0x1BB) av_log(s->avctx, AV_LOG_DEBUG, "FBA Object Plane start");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2154 else if(startcode==0x1BC) av_log(s->avctx, AV_LOG_DEBUG, "Mesh Object start");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2155 else if(startcode==0x1BD) av_log(s->avctx, AV_LOG_DEBUG, "Mesh Object Plane start");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2156 else if(startcode==0x1BE) av_log(s->avctx, AV_LOG_DEBUG, "Still Texture Object start");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2157 else if(startcode==0x1BF) av_log(s->avctx, AV_LOG_DEBUG, "Texture Spatial Layer start");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2158 else if(startcode==0x1C0) av_log(s->avctx, AV_LOG_DEBUG, "Texture SNR Layer start");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2159 else if(startcode==0x1C1) av_log(s->avctx, AV_LOG_DEBUG, "Texture Tile start");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2160 else if(startcode==0x1C2) av_log(s->avctx, AV_LOG_DEBUG, "Texture Shape Layer start");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2161 else if(startcode==0x1C3) av_log(s->avctx, AV_LOG_DEBUG, "stuffing start");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2162 else if(startcode<=0x1C5) av_log(s->avctx, AV_LOG_DEBUG, "reserved");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2163 else if(startcode<=0x1FF) av_log(s->avctx, AV_LOG_DEBUG, "System start");
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2164 av_log(s->avctx, AV_LOG_DEBUG, " at %d\n", get_bits_count(gb));
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2165 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2166
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2167 if(startcode >= 0x120 && startcode <= 0x12F){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2168 if(decode_vol_header(s, gb) < 0)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2169 return -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2170 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2171 else if(startcode == USER_DATA_STARTCODE){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2172 decode_user_data(s, gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2173 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2174 else if(startcode == GOP_STARTCODE){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2175 mpeg4_decode_gop_header(s, gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2176 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2177 else if(startcode == VOP_STARTCODE){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2178 break;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2179 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2180
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2181 align_get_bits(gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2182 startcode = 0xff;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2183 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2184 end:
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2185 if(s->flags& CODEC_FLAG_LOW_DELAY)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2186 s->low_delay=1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2187 s->avctx->has_b_frames= !s->low_delay;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2188 return decode_vop_header(s, gb);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2189 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2190
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2191 static av_cold int decode_init(AVCodecContext *avctx)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2192 {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2193 MpegEncContext *s = avctx->priv_data;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2194 int ret;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2195 static int done = 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2196
11098
77b3f322dba8 Change xvid/divx/lavc build variables to be consistent to x264_build.
michael
parents: 10818
diff changeset
2197 s->divx_version=
77b3f322dba8 Change xvid/divx/lavc build variables to be consistent to x264_build.
michael
parents: 10818
diff changeset
2198 s->divx_build=
77b3f322dba8 Change xvid/divx/lavc build variables to be consistent to x264_build.
michael
parents: 10818
diff changeset
2199 s->xvid_build=
77b3f322dba8 Change xvid/divx/lavc build variables to be consistent to x264_build.
michael
parents: 10818
diff changeset
2200 s->lavc_build= -1;
77b3f322dba8 Change xvid/divx/lavc build variables to be consistent to x264_build.
michael
parents: 10818
diff changeset
2201
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2202 if((ret=ff_h263_decode_init(avctx)) < 0)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2203 return ret;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2204
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2205 if (!done) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2206 done = 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2207
10817
d1fe22d92a65 Rename mpeg4 intra vlc tables so they contain "mpeg4", this improves readability
michael
parents: 10816
diff changeset
2208 init_rl(&ff_mpeg4_rl_intra, ff_mpeg4_static_rl_table_store[0]);
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2209 init_rl(&rvlc_rl_inter, ff_mpeg4_static_rl_table_store[1]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2210 init_rl(&rvlc_rl_intra, ff_mpeg4_static_rl_table_store[2]);
10817
d1fe22d92a65 Rename mpeg4 intra vlc tables so they contain "mpeg4", this improves readability
michael
parents: 10816
diff changeset
2211 INIT_VLC_RL(ff_mpeg4_rl_intra, 554);
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2212 INIT_VLC_RL(rvlc_rl_inter, 1072);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2213 INIT_VLC_RL(rvlc_rl_intra, 1072);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2214 INIT_VLC_STATIC(&dc_lum, DC_VLC_BITS, 10 /* 13 */,
10816
9abebeca7d1b Rename DCtab_*, its a global variable and it helps understanding if mpeg4
michael
parents: 10803
diff changeset
2215 &ff_mpeg4_DCtab_lum[0][1], 2, 1,
9abebeca7d1b Rename DCtab_*, its a global variable and it helps understanding if mpeg4
michael
parents: 10803
diff changeset
2216 &ff_mpeg4_DCtab_lum[0][0], 2, 1, 512);
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2217 INIT_VLC_STATIC(&dc_chrom, DC_VLC_BITS, 10 /* 13 */,
10816
9abebeca7d1b Rename DCtab_*, its a global variable and it helps understanding if mpeg4
michael
parents: 10803
diff changeset
2218 &ff_mpeg4_DCtab_chrom[0][1], 2, 1,
9abebeca7d1b Rename DCtab_*, its a global variable and it helps understanding if mpeg4
michael
parents: 10803
diff changeset
2219 &ff_mpeg4_DCtab_chrom[0][0], 2, 1, 512);
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2220 INIT_VLC_STATIC(&sprite_trajectory, SPRITE_TRAJ_VLC_BITS, 15,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2221 &sprite_trajectory_tab[0][1], 4, 2,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2222 &sprite_trajectory_tab[0][0], 4, 2, 128);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2223 INIT_VLC_STATIC(&mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 4,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2224 &mb_type_b_tab[0][1], 2, 1,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2225 &mb_type_b_tab[0][0], 2, 1, 16);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2226 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2227
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2228 s->h263_pred = 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2229 s->low_delay = 0; //default, might be overriden in the vol header during header parsing
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2230 s->decode_mb= mpeg4_decode_mb;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2231 s->time_increment_bits = 4; /* default value for broken headers */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2232 avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2233
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2234 return 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2235 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2236
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2237 AVCodec mpeg4_decoder = {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2238 "mpeg4",
11560
8a4984c5cacc Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 11556
diff changeset
2239 AVMEDIA_TYPE_VIDEO,
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2240 CODEC_ID_MPEG4,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2241 sizeof(MpegEncContext),
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2242 decode_init,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2243 NULL,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2244 ff_h263_decode_end,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2245 ff_h263_decode_frame,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2246 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2247 .flush= ff_mpeg_flush,
12108
c35d7bc64882 Add new decoder property max_lowres and do not init decoder if requested value is higher.
cehoyos
parents: 11560
diff changeset
2248 .max_lowres= 3,
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2249 .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2"),
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2250 .pix_fmts= ff_hwaccel_pixfmt_list_420,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2251 };
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2252
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2253
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2254 #if CONFIG_MPEG4_VDPAU_DECODER
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2255 AVCodec mpeg4_vdpau_decoder = {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2256 "mpeg4_vdpau",
11560
8a4984c5cacc Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 11556
diff changeset
2257 AVMEDIA_TYPE_VIDEO,
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2258 CODEC_ID_MPEG4,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2259 sizeof(MpegEncContext),
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2260 decode_init,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2261 NULL,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2262 ff_h263_decode_end,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2263 ff_h263_decode_frame,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2264 CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2265 .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 (VDPAU)"),
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2266 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_VDPAU_MPEG4, PIX_FMT_NONE},
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2267 };
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2268 #endif