annotate wmv2.c @ 5186:8a6fac216a2f libavcodec

test context before accessing it
author benoit
date Tue, 26 Jun 2007 18:00:50 +0000
parents b215d5a5fa9a
children 19ed7e6ef927
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
1 /*
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
2 * Copyright (c) 2002 The FFmpeg Project.
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
3 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3741
diff changeset
4 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3741
diff changeset
5 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3741
diff changeset
6 * FFmpeg is free software; you can redistribute it and/or
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3741
diff changeset
9 * version 2.1 of the License, or (at your option) any later version.
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
10 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3741
diff changeset
11 * FFmpeg is distributed in the hope that it will be useful,
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
14 * Lesser General Public License for more details.
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
15 *
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3741
diff changeset
17 * License along with FFmpeg; if not, write to the Free Software
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 2979
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
19 *
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
20 */
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
21
1106
1e39f273ecd6 per file doxy
michaelni
parents: 1092
diff changeset
22 /**
1e39f273ecd6 per file doxy
michaelni
parents: 1092
diff changeset
23 * @file wmv2.c
1e39f273ecd6 per file doxy
michaelni
parents: 1092
diff changeset
24 * wmv2 codec.
1e39f273ecd6 per file doxy
michaelni
parents: 1092
diff changeset
25 */
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
26
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
27 #include "simple_idct.h"
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
28
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
29 #define SKIP_TYPE_NONE 0
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
30 #define SKIP_TYPE_MPEG 1
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
31 #define SKIP_TYPE_ROW 2
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
32 #define SKIP_TYPE_COL 3
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
33
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
34
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
35 typedef struct Wmv2Context{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
36 MpegEncContext s;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
37 int j_type_bit;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
38 int j_type;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
39 int flag3;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
40 int flag63;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
41 int abt_flag;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
42 int abt_type;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
43 int abt_type_table[6];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
44 int per_mb_abt;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
45 int per_block_abt;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
46 int mspel_bit;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
47 int cbp_table_index;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
48 int top_left_mv_flag;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
49 int per_mb_rl_bit;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
50 int skip_type;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
51 int hshift;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
52
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
53 ScanTable abt_scantable[2];
3089
072dbc669253 MSVC-compatible __align8/__align16 declaration
diego
parents: 3036
diff changeset
54 DECLARE_ALIGNED_8(DCTELEM, abt_block2[6][64]);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
55 }Wmv2Context;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
56
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
57 static void wmv2_common_init(Wmv2Context * w){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
58 MpegEncContext * const s= &w->s;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
59
1273
a979fab41ed8 ASV1 codec
michaelni
parents: 1185
diff changeset
60 ff_init_scantable(s->dsp.idct_permutation, &w->abt_scantable[0], wmv2_scantableA);
a979fab41ed8 ASV1 codec
michaelni
parents: 1185
diff changeset
61 ff_init_scantable(s->dsp.idct_permutation, &w->abt_scantable[1], wmv2_scantableB);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
62 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
63
4950
665c61d35b52 Replace general CONFIG_ENCODERS by more fine-grained CONFIG_WMV2_ENCODER.
diego
parents: 4947
diff changeset
64 #ifdef CONFIG_WMV2_ENCODER
2024
f65d87bfdd5a some of the warning fixes by (Michael Roitzsch <mroi at users dot sourceforge dot net>)
michael
parents: 1943
diff changeset
65
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
66 static int encode_ext_header(Wmv2Context *w){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
67 MpegEncContext * const s= &w->s;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
68 PutBitContext pb;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
69 int code;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
70
1524
alex
parents: 1418
diff changeset
71 init_put_bits(&pb, s->avctx->extradata, s->avctx->extradata_size);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
72
2637
ef44d24680d1 switch to native time bases
michael
parents: 2632
diff changeset
73 put_bits(&pb, 5, s->avctx->time_base.den / s->avctx->time_base.num); //yes 29.97 -> 29
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
74 put_bits(&pb, 11, FFMIN(s->bit_rate/1024, 2047));
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
75
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
76 put_bits(&pb, 1, w->mspel_bit=1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
77 put_bits(&pb, 1, w->flag3=1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
78 put_bits(&pb, 1, w->abt_flag=1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
79 put_bits(&pb, 1, w->j_type_bit=1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
80 put_bits(&pb, 1, w->top_left_mv_flag=0);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
81 put_bits(&pb, 1, w->per_mb_rl_bit=1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
82 put_bits(&pb, 3, code=1);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
83
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
84 flush_put_bits(&pb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
85
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
86 s->slice_height = s->mb_height / code;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
87
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
88 return 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
89 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
90
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
91 static int wmv2_encode_init(AVCodecContext *avctx){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
92 Wmv2Context * const w= avctx->priv_data;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
93
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
94 if(MPV_encode_init(avctx) < 0)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
95 return -1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
96
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
97 wmv2_common_init(w);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
98
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
99 avctx->extradata_size= 4;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
100 avctx->extradata= av_mallocz(avctx->extradata_size + 10);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
101 encode_ext_header(w);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
102
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
103 return 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
104 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
105
2522
e25782262d7d kill warnings patch by (Mns Rullgrd <mru inprovide com>)
michael
parents: 2474
diff changeset
106 #if 0 /* unused, remove? */
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
107 static int wmv2_encode_end(AVCodecContext *avctx){
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
108
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
109 if(MPV_encode_end(avctx) < 0)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
110 return -1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
111
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
112 avctx->extradata_size= 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
113 av_freep(&avctx->extradata);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
114
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
115 return 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
116 }
2522
e25782262d7d kill warnings patch by (Mns Rullgrd <mru inprovide com>)
michael
parents: 2474
diff changeset
117 #endif
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
118
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
119 int ff_wmv2_encode_picture_header(MpegEncContext * s, int picture_number)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
120 {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
121 Wmv2Context * const w= (Wmv2Context*)s;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
122
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
123 put_bits(&s->pb, 1, s->pict_type - 1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
124 if(s->pict_type == I_TYPE){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
125 put_bits(&s->pb, 7, 0);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
126 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
127 put_bits(&s->pb, 5, s->qscale);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
128
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
129 s->dc_table_index = 1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
130 s->mv_table_index = 1; /* only if P frame */
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
131 // s->use_skip_mb_code = 1; /* only if P frame */
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
132 s->per_mb_rl_table = 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
133 s->mspel= 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
134 w->per_mb_abt=0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
135 w->abt_type=0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
136 w->j_type=0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
137
1163
0951691c4225 fixing msmpeg4v2 encoding
michaelni
parents: 1144
diff changeset
138 assert(s->flipflop_rounding);
0951691c4225 fixing msmpeg4v2 encoding
michaelni
parents: 1144
diff changeset
139
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
140 if (s->pict_type == I_TYPE) {
1163
0951691c4225 fixing msmpeg4v2 encoding
michaelni
parents: 1144
diff changeset
141 assert(s->no_rounding==1);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
142 if(w->j_type_bit) put_bits(&s->pb, 1, w->j_type);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
143
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
144 if(w->per_mb_rl_bit) put_bits(&s->pb, 1, s->per_mb_rl_table);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
145
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
146 if(!s->per_mb_rl_table){
5098
997c368e6433 Rename code012() to ff_code012(), and remove static qualifier: paves the way
gpoirier
parents: 4950
diff changeset
147 ff_code012(&s->pb, s->rl_chroma_table_index);
997c368e6433 Rename code012() to ff_code012(), and remove static qualifier: paves the way
gpoirier
parents: 4950
diff changeset
148 ff_code012(&s->pb, s->rl_table_index);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
149 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
150
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
151 put_bits(&s->pb, 1, s->dc_table_index);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
152
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
153 s->inter_intra_pred= 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
154 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
155 int cbp_index;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
156
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
157 put_bits(&s->pb, 2, SKIP_TYPE_NONE);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
158
5098
997c368e6433 Rename code012() to ff_code012(), and remove static qualifier: paves the way
gpoirier
parents: 4950
diff changeset
159 ff_code012(&s->pb, cbp_index=0);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
160 if(s->qscale <= 10){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
161 int map[3]= {0,2,1};
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
162 w->cbp_table_index= map[cbp_index];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
163 }else if(s->qscale <= 20){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
164 int map[3]= {1,0,2};
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
165 w->cbp_table_index= map[cbp_index];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
166 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
167 int map[3]= {2,1,0};
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
168 w->cbp_table_index= map[cbp_index];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
169 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
170
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
171 if(w->mspel_bit) put_bits(&s->pb, 1, s->mspel);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
172
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
173 if(w->abt_flag){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
174 put_bits(&s->pb, 1, w->per_mb_abt^1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
175 if(!w->per_mb_abt){
5098
997c368e6433 Rename code012() to ff_code012(), and remove static qualifier: paves the way
gpoirier
parents: 4950
diff changeset
176 ff_code012(&s->pb, w->abt_type);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
177 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
178 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
179
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
180 if(w->per_mb_rl_bit) put_bits(&s->pb, 1, s->per_mb_rl_table);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
181
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
182 if(!s->per_mb_rl_table){
5098
997c368e6433 Rename code012() to ff_code012(), and remove static qualifier: paves the way
gpoirier
parents: 4950
diff changeset
183 ff_code012(&s->pb, s->rl_table_index);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
184 s->rl_chroma_table_index = s->rl_table_index;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
185 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
186 put_bits(&s->pb, 1, s->dc_table_index);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
187 put_bits(&s->pb, 1, s->mv_table_index);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
188
1943
62beeb1a8676 seems wmv8 doesnt use intra-inter prediction
michael
parents: 1938
diff changeset
189 s->inter_intra_pred= 0;//(s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
190 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
191 s->esc3_level_length= 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
192 s->esc3_run_length= 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
193
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
194 return 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
195 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
196
5127
4dbe6578f811 misc spelling fixes
diego
parents: 5098
diff changeset
197 /* Nearly identical to wmv1 but that is just because we do not use the
4dbe6578f811 misc spelling fixes
diego
parents: 5098
diff changeset
198 * useless M$ crap features. It is duplicated here in case someone wants
4dbe6578f811 misc spelling fixes
diego
parents: 5098
diff changeset
199 * to add support for these crap features. */
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
200 void ff_wmv2_encode_mb(MpegEncContext * s,
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
201 DCTELEM block[6][64],
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
202 int motion_x, int motion_y)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
203 {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
204 Wmv2Context * const w= (Wmv2Context*)s;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
205 int cbp, coded_cbp, i;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
206 int pred_x, pred_y;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
207 uint8_t *coded_block;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
208
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
209 handle_slices(s);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
210
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
211 if (!s->mb_intra) {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
212 /* compute cbp */
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
213 cbp = 0;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
214 for (i = 0; i < 6; i++) {
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
215 if (s->block_last_index[i] >= 0)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
216 cbp |= 1 << (5 - i);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
217 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
218
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
219 put_bits(&s->pb,
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
220 wmv2_inter_table[w->cbp_table_index][cbp + 64][1],
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
221 wmv2_inter_table[w->cbp_table_index][cbp + 64][0]);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
222
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
223 /* motion vector */
1938
e2501e6e7ff7 unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents: 1668
diff changeset
224 h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
225 msmpeg4_encode_motion(s, motion_x - pred_x,
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
226 motion_y - pred_y);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
227 } else {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
228 /* compute cbp */
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
229 cbp = 0;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
230 coded_cbp = 0;
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
231 for (i = 0; i < 6; i++) {
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
232 int val, pred;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
233 val = (s->block_last_index[i] >= 1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
234 cbp |= val << (5 - i);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
235 if (i < 4) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
236 /* predict value for close blocks only for luma */
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
237 pred = coded_block_pred(s, i, &coded_block);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
238 *coded_block = val;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
239 val = val ^ pred;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
240 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
241 coded_cbp |= val << (5 - i);
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
242 }
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
243 #if 0
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
244 if (coded_cbp)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
245 printf("cbp=%x %x\n", cbp, coded_cbp);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
246 #endif
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
247
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
248 if (s->pict_type == I_TYPE) {
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
249 put_bits(&s->pb,
2474
81a9f883a17a In that patch:
michael
parents: 2031
diff changeset
250 ff_msmp4_mb_i_table[coded_cbp][1], ff_msmp4_mb_i_table[coded_cbp][0]);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
251 } else {
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
252 put_bits(&s->pb,
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
253 wmv2_inter_table[w->cbp_table_index][cbp][1],
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
254 wmv2_inter_table[w->cbp_table_index][cbp][0]);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
255 }
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
256 put_bits(&s->pb, 1, 0); /* no AC prediction yet */
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
257 if(s->inter_intra_pred){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
258 s->h263_aic_dir=0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
259 put_bits(&s->pb, table_inter_intra[s->h263_aic_dir][1], table_inter_intra[s->h263_aic_dir][0]);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
260 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
261 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
262
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
263 for (i = 0; i < 6; i++) {
5178
b215d5a5fa9a static (inline) X => ff_X
benoit
parents: 5127
diff changeset
264 ff_msmpeg4_encode_block(s, block[i], i);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
265 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
266 }
4950
665c61d35b52 Replace general CONFIG_ENCODERS by more fine-grained CONFIG_WMV2_ENCODER.
diego
parents: 4947
diff changeset
267 #endif //CONFIG_WMV2_ENCODER
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
268
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
269 static void parse_mb_skip(Wmv2Context * w){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
270 int mb_x, mb_y;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
271 MpegEncContext * const s= &w->s;
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1163
diff changeset
272 uint32_t * const mb_type= s->current_picture_ptr->mb_type;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
273
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
274 w->skip_type= get_bits(&s->gb, 2);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
275 switch(w->skip_type){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
276 case SKIP_TYPE_NONE:
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
277 for(mb_y=0; mb_y<s->mb_height; mb_y++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
278 for(mb_x=0; mb_x<s->mb_width; mb_x++){
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1163
diff changeset
279 mb_type[mb_y*s->mb_stride + mb_x]= MB_TYPE_16x16 | MB_TYPE_L0;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
280 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
281 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
282 break;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
283 case SKIP_TYPE_MPEG:
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
284 for(mb_y=0; mb_y<s->mb_height; mb_y++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
285 for(mb_x=0; mb_x<s->mb_width; mb_x++){
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1163
diff changeset
286 mb_type[mb_y*s->mb_stride + mb_x]= (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_L0;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
287 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
288 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
289 break;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
290 case SKIP_TYPE_ROW:
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
291 for(mb_y=0; mb_y<s->mb_height; mb_y++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
292 if(get_bits1(&s->gb)){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
293 for(mb_x=0; mb_x<s->mb_width; mb_x++){
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1163
diff changeset
294 mb_type[mb_y*s->mb_stride + mb_x]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
295 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
296 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
297 for(mb_x=0; mb_x<s->mb_width; mb_x++){
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1163
diff changeset
298 mb_type[mb_y*s->mb_stride + mb_x]= (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_L0;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
299 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
300 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
301 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
302 break;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
303 case SKIP_TYPE_COL:
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
304 for(mb_x=0; mb_x<s->mb_width; mb_x++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
305 if(get_bits1(&s->gb)){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
306 for(mb_y=0; mb_y<s->mb_height; mb_y++){
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1163
diff changeset
307 mb_type[mb_y*s->mb_stride + mb_x]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
308 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
309 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
310 for(mb_y=0; mb_y<s->mb_height; mb_y++){
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1163
diff changeset
311 mb_type[mb_y*s->mb_stride + mb_x]= (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_L0;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
312 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
313 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
314 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
315 break;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
316 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
317 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
318
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
319 static int decode_ext_header(Wmv2Context *w){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
320 MpegEncContext * const s= &w->s;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
321 GetBitContext gb;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
322 int fps;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
323 int code;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
324
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
325 if(s->avctx->extradata_size<4) return -1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
326
1025
1f9afd8b9131 GetBitContext.size is allways multiplied by 8 -> use size_in_bits to avoid useless *8 in a few inner loops
michaelni
parents: 983
diff changeset
327 init_get_bits(&gb, s->avctx->extradata, s->avctx->extradata_size*8);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
328
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
329 fps = get_bits(&gb, 5);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
330 s->bit_rate = get_bits(&gb, 11)*1024;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
331 w->mspel_bit = get_bits1(&gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
332 w->flag3 = get_bits1(&gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
333 w->abt_flag = get_bits1(&gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
334 w->j_type_bit = get_bits1(&gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
335 w->top_left_mv_flag= get_bits1(&gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
336 w->per_mb_rl_bit = get_bits1(&gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
337 code = get_bits(&gb, 3);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
338
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
339 if(code==0) return -1;
1092
f59c3f66363b MpegEncContext.(i)dct_* -> DspContext.(i)dct_*
michaelni
parents: 1070
diff changeset
340
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
341 s->slice_height = s->mb_height / code;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
342
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
343 if(s->avctx->debug&FF_DEBUG_PICT_INFO){
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
344 av_log(s->avctx, AV_LOG_DEBUG, "fps:%d, br:%d, qpbit:%d, abt_flag:%d, j_type_bit:%d, tl_mv_flag:%d, mbrl_bit:%d, code:%d, flag3:%d, slices:%d\n",
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
345 fps, s->bit_rate, w->mspel_bit, w->abt_flag, w->j_type_bit, w->top_left_mv_flag, w->per_mb_rl_bit, code, w->flag3,
983
ca2a303ea039 fixed wmv2 slices
michaelni
parents: 936
diff changeset
346 code);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
347 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
348 return 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
349 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
350
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
351 int ff_wmv2_decode_picture_header(MpegEncContext * s)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
352 {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
353 Wmv2Context * const w= (Wmv2Context*)s;
1183
03b97d87dcdd 10l (use before malloc)
michaelni
parents: 1177
diff changeset
354 int code;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
355
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
356 #if 0
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
357 {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
358 int i;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
359 for(i=0; i<s->gb.size*8; i++)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
360 printf("%d", get_bits1(&s->gb));
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
361 // get_bits1(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
362 printf("END\n");
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
363 return -1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
364 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
365 #endif
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
366 if(s->picture_number==0)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
367 decode_ext_header(w);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
368
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
369 s->pict_type = get_bits(&s->gb, 1) + 1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
370 if(s->pict_type == I_TYPE){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
371 code = get_bits(&s->gb, 7);
2810
b866af0c02d6 Reduce verbosity.
diego
parents: 2655
diff changeset
372 av_log(s->avctx, AV_LOG_DEBUG, "I7:%X/\n", code);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
373 }
1651
ccf7c96a630f h263 modified quantization fix
michael
parents: 1598
diff changeset
374 s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
1183
03b97d87dcdd 10l (use before malloc)
michaelni
parents: 1177
diff changeset
375 if(s->qscale < 0)
03b97d87dcdd 10l (use before malloc)
michaelni
parents: 1177
diff changeset
376 return -1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
377
1183
03b97d87dcdd 10l (use before malloc)
michaelni
parents: 1177
diff changeset
378 return 0;
03b97d87dcdd 10l (use before malloc)
michaelni
parents: 1177
diff changeset
379 }
03b97d87dcdd 10l (use before malloc)
michaelni
parents: 1177
diff changeset
380
03b97d87dcdd 10l (use before malloc)
michaelni
parents: 1177
diff changeset
381 int ff_wmv2_decode_secondary_picture_header(MpegEncContext * s)
03b97d87dcdd 10l (use before malloc)
michaelni
parents: 1177
diff changeset
382 {
03b97d87dcdd 10l (use before malloc)
michaelni
parents: 1177
diff changeset
383 Wmv2Context * const w= (Wmv2Context*)s;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
384
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
385 if (s->pict_type == I_TYPE) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
386 if(w->j_type_bit) w->j_type= get_bits1(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
387 else w->j_type= 0; //FIXME check
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
388
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
389 if(!w->j_type){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
390 if(w->per_mb_rl_bit) s->per_mb_rl_table= get_bits1(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
391 else s->per_mb_rl_table= 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
392
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
393 if(!s->per_mb_rl_table){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
394 s->rl_chroma_table_index = decode012(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
395 s->rl_table_index = decode012(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
396 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
397
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
398 s->dc_table_index = get_bits1(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
399 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
400 s->inter_intra_pred= 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
401 s->no_rounding = 1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
402 if(s->avctx->debug&FF_DEBUG_PICT_INFO){
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
403 av_log(s->avctx, AV_LOG_DEBUG, "qscale:%d rlc:%d rl:%d dc:%d mbrl:%d j_type:%d \n",
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
404 s->qscale,
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
405 s->rl_chroma_table_index,
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
406 s->rl_table_index,
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
407 s->dc_table_index,
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
408 s->per_mb_rl_table,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
409 w->j_type);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
410 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
411 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
412 int cbp_index;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
413 w->j_type=0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
414
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
415 parse_mb_skip(w);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
416 cbp_index= decode012(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
417 if(s->qscale <= 10){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
418 int map[3]= {0,2,1};
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
419 w->cbp_table_index= map[cbp_index];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
420 }else if(s->qscale <= 20){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
421 int map[3]= {1,0,2};
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
422 w->cbp_table_index= map[cbp_index];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
423 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
424 int map[3]= {2,1,0};
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
425 w->cbp_table_index= map[cbp_index];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
426 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
427
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
428 if(w->mspel_bit) s->mspel= get_bits1(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
429 else s->mspel= 0; //FIXME check
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
430
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
431 if(w->abt_flag){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
432 w->per_mb_abt= get_bits1(&s->gb)^1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
433 if(!w->per_mb_abt){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
434 w->abt_type= decode012(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
435 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
436 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
437
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
438 if(w->per_mb_rl_bit) s->per_mb_rl_table= get_bits1(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
439 else s->per_mb_rl_table= 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
440
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
441 if(!s->per_mb_rl_table){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
442 s->rl_table_index = decode012(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
443 s->rl_chroma_table_index = s->rl_table_index;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
444 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
445
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
446 s->dc_table_index = get_bits1(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
447 s->mv_table_index = get_bits1(&s->gb);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
448
1943
62beeb1a8676 seems wmv8 doesnt use intra-inter prediction
michael
parents: 1938
diff changeset
449 s->inter_intra_pred= 0;//(s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
450 s->no_rounding ^= 1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
451
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
452 if(s->avctx->debug&FF_DEBUG_PICT_INFO){
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
453 av_log(s->avctx, AV_LOG_DEBUG, "rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d mspel:%d per_mb_abt:%d abt_type:%d cbp:%d ii:%d\n",
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
454 s->rl_table_index,
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
455 s->rl_chroma_table_index,
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
456 s->dc_table_index,
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
457 s->mv_table_index,
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
458 s->per_mb_rl_table,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
459 s->qscale,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
460 s->mspel,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
461 w->per_mb_abt,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
462 w->abt_type,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
463 w->cbp_table_index,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
464 s->inter_intra_pred);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
465 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
466 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
467 s->esc3_level_length= 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
468 s->esc3_run_length= 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
469
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
470 s->picture_number++; //FIXME ?
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
471
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
472
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
473 // if(w->j_type)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
474 // return wmv2_decode_j_picture(w); //FIXME
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
475
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
476 if(w->j_type){
2628
511e3afc43e1 Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents: 2522
diff changeset
477 av_log(s->avctx, AV_LOG_ERROR, "J-type picture is not supported\n");
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
478 return -1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
479 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
480
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
481 return 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
482 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
483
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
484 static inline int wmv2_decode_motion(Wmv2Context *w, int *mx_ptr, int *my_ptr){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
485 MpegEncContext * const s= &w->s;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
486 int ret;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
487
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
488 ret= msmpeg4_decode_motion(s, mx_ptr, my_ptr);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
489
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
490 if(ret<0) return -1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
491
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
492 if((((*mx_ptr)|(*my_ptr)) & 1) && s->mspel)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
493 w->hshift= get_bits1(&s->gb);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
494 else
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
495 w->hshift= 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
496
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
497 //printf("%d %d ", *mx_ptr, *my_ptr);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
498
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
499 return 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
500 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
501
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
502 static int16_t *wmv2_pred_motion(Wmv2Context *w, int *px, int *py){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
503 MpegEncContext * const s= &w->s;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
504 int xy, wrap, diff, type;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
505 int16_t *A, *B, *C, *mot_val;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
506
1938
e2501e6e7ff7 unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents: 1668
diff changeset
507 wrap = s->b8_stride;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
508 xy = s->block_index[0];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
509
1668
30746f429df6 move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents: 1651
diff changeset
510 mot_val = s->current_picture.motion_val[0][xy];
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
511
1668
30746f429df6 move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents: 1651
diff changeset
512 A = s->current_picture.motion_val[0][xy - 1];
30746f429df6 move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents: 1651
diff changeset
513 B = s->current_picture.motion_val[0][xy - wrap];
30746f429df6 move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents: 1651
diff changeset
514 C = s->current_picture.motion_val[0][xy + 2 - wrap];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
515
2818
cdc7a2341165 segfault fix
michael
parents: 2810
diff changeset
516 if(s->mb_x && !s->first_slice_line && !s->mspel && w->top_left_mv_flag)
4001
34fdffe98bd0 Rename ABS macro to FFABS.
diego
parents: 3947
diff changeset
517 diff= FFMAX(FFABS(A[0] - B[0]), FFABS(A[1] - B[1]));
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
518 else
2818
cdc7a2341165 segfault fix
michael
parents: 2810
diff changeset
519 diff=0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
520
2818
cdc7a2341165 segfault fix
michael
parents: 2810
diff changeset
521 if(diff >= 8)
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
522 type= get_bits1(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
523 else
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
524 type= 2;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
525
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
526 if(type == 0){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
527 *px= A[0];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
528 *py= A[1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
529 }else if(type == 1){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
530 *px= B[0];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
531 *py= B[1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
532 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
533 /* special case for first (slice) line */
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
534 if (s->first_slice_line) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
535 *px = A[0];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
536 *py = A[1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
537 } else {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
538 *px = mid_pred(A[0], B[0], C[0]);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
539 *py = mid_pred(A[1], B[1], C[1]);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
540 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
541 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
542
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
543 return mot_val;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
544 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
545
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
546 static inline int wmv2_decode_inter_block(Wmv2Context *w, DCTELEM *block, int n, int cbp){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
547 MpegEncContext * const s= &w->s;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
548 static const int sub_cbp_table[3]= {2,3,1};
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
549 int sub_cbp;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
550
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
551 if(!cbp){
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
552 s->block_last_index[n] = -1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
553
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
554 return 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
555 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
556
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
557 if(w->per_block_abt)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
558 w->abt_type= decode012(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
559 #if 0
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
560 if(w->per_block_abt)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
561 printf("B%d", w->abt_type);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
562 #endif
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
563 w->abt_type_table[n]= w->abt_type;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
564
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
565 if(w->abt_type){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
566 // const uint8_t *scantable= w->abt_scantable[w->abt_type-1].permutated;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
567 const uint8_t *scantable= w->abt_scantable[w->abt_type-1].scantable;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
568 // const uint8_t *scantable= w->abt_type-1 ? w->abt_scantable[1].permutated : w->abt_scantable[0].scantable;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
569
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
570 sub_cbp= sub_cbp_table[ decode012(&s->gb) ];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
571 // printf("S%d", sub_cbp);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
572
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
573 if(sub_cbp&1){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
574 if (msmpeg4_decode_block(s, block, n, 1, scantable) < 0)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
575 return -1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
576 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
577
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
578 if(sub_cbp&2){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
579 if (msmpeg4_decode_block(s, w->abt_block2[n], n, 1, scantable) < 0)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
580 return -1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
581 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
582 s->block_last_index[n] = 63;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
583
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
584 return 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
585 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
586 return msmpeg4_decode_block(s, block, n, 1, s->inter_scantable.permutated);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
587 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
588 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
589
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
590 static void wmv2_add_block(Wmv2Context *w, DCTELEM *block1, uint8_t *dst, int stride, int n){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
591 MpegEncContext * const s= &w->s;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
592
2655
ab7bd4722cef fix block corruption caused by clear_blocks() optimization
michael
parents: 2637
diff changeset
593 if (s->block_last_index[n] >= 0) {
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
594 switch(w->abt_type_table[n]){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
595 case 0:
2655
ab7bd4722cef fix block corruption caused by clear_blocks() optimization
michael
parents: 2637
diff changeset
596 s->dsp.idct_add (dst, stride, block1);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
597 break;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
598 case 1:
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
599 simple_idct84_add(dst , stride, block1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
600 simple_idct84_add(dst + 4*stride, stride, w->abt_block2[n]);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
601 memset(w->abt_block2[n], 0, 64*sizeof(DCTELEM));
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
602 break;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
603 case 2:
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
604 simple_idct48_add(dst , stride, block1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
605 simple_idct48_add(dst + 4 , stride, w->abt_block2[n]);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
606 memset(w->abt_block2[n], 0, 64*sizeof(DCTELEM));
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
607 break;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
608 default:
1598
932d306bf1dc av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 1524
diff changeset
609 av_log(s->avctx, AV_LOG_ERROR, "internal error in WMV2 abt\n");
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
610 }
2655
ab7bd4722cef fix block corruption caused by clear_blocks() optimization
michael
parents: 2637
diff changeset
611 }
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
612 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
613
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
614 void ff_wmv2_add_mb(MpegEncContext *s, DCTELEM block1[6][64], uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
615 Wmv2Context * const w= (Wmv2Context*)s;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
616
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
617 wmv2_add_block(w, block1[0], dest_y , s->linesize, 0);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
618 wmv2_add_block(w, block1[1], dest_y + 8 , s->linesize, 1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
619 wmv2_add_block(w, block1[2], dest_y + 8*s->linesize, s->linesize, 2);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
620 wmv2_add_block(w, block1[3], dest_y + 8 + 8*s->linesize, s->linesize, 3);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
621
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
622 if(s->flags&CODEC_FLAG_GRAY) return;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
623
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
624 wmv2_add_block(w, block1[4], dest_cb , s->uvlinesize, 4);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
625 wmv2_add_block(w, block1[5], dest_cr , s->uvlinesize, 5);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
626 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
627
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
628 void ff_mspel_motion(MpegEncContext *s,
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
629 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
630 uint8_t **ref_picture, op_pixels_func (*pix_op)[4],
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
631 int motion_x, int motion_y, int h)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
632 {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
633 Wmv2Context * const w= (Wmv2Context*)s;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
634 uint8_t *ptr;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
635 int dxy, offset, mx, my, src_x, src_y, v_edge_pos, linesize, uvlinesize;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
636 int emu=0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
637
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
638 dxy = ((motion_y & 1) << 1) | (motion_x & 1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
639 dxy = 2*dxy + w->hshift;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
640 src_x = s->mb_x * 16 + (motion_x >> 1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
641 src_y = s->mb_y * 16 + (motion_y >> 1);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
642
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
643 /* WARNING: do no forget half pels */
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
644 v_edge_pos = s->v_edge_pos;
4594
a96d905dcbaa Add av_ prefix to clip functions
reimar
parents: 4333
diff changeset
645 src_x = av_clip(src_x, -16, s->width);
a96d905dcbaa Add av_ prefix to clip functions
reimar
parents: 4333
diff changeset
646 src_y = av_clip(src_y, -16, s->height);
4333
018b316baca7 maybe fixing a segfault
michael
parents: 4001
diff changeset
647
018b316baca7 maybe fixing a segfault
michael
parents: 4001
diff changeset
648 if(src_x<=-16 || src_x >= s->width)
018b316baca7 maybe fixing a segfault
michael
parents: 4001
diff changeset
649 dxy &= ~3;
018b316baca7 maybe fixing a segfault
michael
parents: 4001
diff changeset
650 if(src_y<=-16 || src_y >= s->height)
018b316baca7 maybe fixing a segfault
michael
parents: 4001
diff changeset
651 dxy &= ~4;
018b316baca7 maybe fixing a segfault
michael
parents: 4001
diff changeset
652
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
653 linesize = s->linesize;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
654 uvlinesize = s->uvlinesize;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
655 ptr = ref_picture[0] + (src_y * linesize) + src_x;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
656
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
657 if(s->flags&CODEC_FLAG_EMU_EDGE){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
658 if(src_x<1 || src_y<1 || src_x + 17 >= s->h_edge_pos
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
659 || src_y + h+1 >= v_edge_pos){
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
660 ff_emulated_edge_mc(s->edge_emu_buffer, ptr - 1 - s->linesize, s->linesize, 19, 19,
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
661 src_x-1, src_y-1, s->h_edge_pos, s->v_edge_pos);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
662 ptr= s->edge_emu_buffer + 1 + s->linesize;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
663 emu=1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
664 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
665 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
666
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
667 s->dsp.put_mspel_pixels_tab[dxy](dest_y , ptr , linesize);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
668 s->dsp.put_mspel_pixels_tab[dxy](dest_y+8 , ptr+8 , linesize);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
669 s->dsp.put_mspel_pixels_tab[dxy](dest_y +8*linesize, ptr +8*linesize, linesize);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
670 s->dsp.put_mspel_pixels_tab[dxy](dest_y+8+8*linesize, ptr+8+8*linesize, linesize);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
671
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
672 if(s->flags&CODEC_FLAG_GRAY) return;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
673
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
674 if (s->out_format == FMT_H263) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
675 dxy = 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
676 if ((motion_x & 3) != 0)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
677 dxy |= 1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
678 if ((motion_y & 3) != 0)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
679 dxy |= 2;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
680 mx = motion_x >> 2;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
681 my = motion_y >> 2;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
682 } else {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
683 mx = motion_x / 2;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
684 my = motion_y / 2;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
685 dxy = ((my & 1) << 1) | (mx & 1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
686 mx >>= 1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
687 my >>= 1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
688 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
689
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
690 src_x = s->mb_x * 8 + mx;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
691 src_y = s->mb_y * 8 + my;
4594
a96d905dcbaa Add av_ prefix to clip functions
reimar
parents: 4333
diff changeset
692 src_x = av_clip(src_x, -8, s->width >> 1);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
693 if (src_x == (s->width >> 1))
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
694 dxy &= ~1;
4594
a96d905dcbaa Add av_ prefix to clip functions
reimar
parents: 4333
diff changeset
695 src_y = av_clip(src_y, -8, s->height >> 1);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
696 if (src_y == (s->height >> 1))
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
697 dxy &= ~2;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
698 offset = (src_y * uvlinesize) + src_x;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
699 ptr = ref_picture[1] + offset;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
700 if(emu){
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
701 ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9,
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
702 src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
703 ptr= s->edge_emu_buffer;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
704 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
705 pix_op[1][dxy](dest_cb, ptr, uvlinesize, h >> 1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
706
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
707 ptr = ref_picture[2] + offset;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
708 if(emu){
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
709 ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9,
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
710 src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
711 ptr= s->edge_emu_buffer;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
712 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
713 pix_op[1][dxy](dest_cr, ptr, uvlinesize, h >> 1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
714 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
715
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
716
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
717 static int wmv2_decode_mb(MpegEncContext *s, DCTELEM block[6][64])
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
718 {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
719 Wmv2Context * const w= (Wmv2Context*)s;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
720 int cbp, code, i;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
721 uint8_t *coded_val;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
722
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
723 if(w->j_type) return 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
724
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
725 if (s->pict_type == P_TYPE) {
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1163
diff changeset
726 if(IS_SKIP(s->current_picture.mb_type[s->mb_y * s->mb_stride + s->mb_x])){
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
727 /* skip mb */
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
728 s->mb_intra = 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
729 for(i=0;i<6;i++)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
730 s->block_last_index[i] = -1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
731 s->mv_dir = MV_DIR_FORWARD;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
732 s->mv_type = MV_TYPE_16X16;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
733 s->mv[0][0][0] = 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
734 s->mv[0][0][1] = 0;
2628
511e3afc43e1 Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents: 2522
diff changeset
735 s->mb_skipped = 1;
1185
michaelni
parents: 1183
diff changeset
736 w->hshift=0;
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
737 return 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
738 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
739
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
740 code = get_vlc2(&s->gb, mb_non_intra_vlc[w->cbp_table_index].table, MB_NON_INTRA_VLC_BITS, 3);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
741 if (code < 0)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
742 return -1;
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
743 s->mb_intra = (~code & 0x40) >> 6;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
744
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
745 cbp = code & 0x3f;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
746 } else {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
747 s->mb_intra = 1;
2474
81a9f883a17a In that patch:
michael
parents: 2031
diff changeset
748 code = get_vlc2(&s->gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
749 if (code < 0){
1598
932d306bf1dc av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 1524
diff changeset
750 av_log(s->avctx, AV_LOG_ERROR, "II-cbp illegal at %d %d\n", s->mb_x, s->mb_y);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
751 return -1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
752 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
753 /* predict coded block pattern */
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
754 cbp = 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
755 for(i=0;i<6;i++) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
756 int val = ((code >> (5 - i)) & 1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
757 if (i < 4) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
758 int pred = coded_block_pred(s, i, &coded_val);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
759 val = val ^ pred;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
760 *coded_val = val;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
761 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
762 cbp |= val << (5 - i);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
763 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
764 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
765
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
766 if (!s->mb_intra) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
767 int mx, my;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
768 //printf("P at %d %d\n", s->mb_x, s->mb_y);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
769 wmv2_pred_motion(w, &mx, &my);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
770
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
771 if(cbp){
2632
67171616ead6 avoid unneeded clear_blocks()
michael
parents: 2628
diff changeset
772 s->dsp.clear_blocks(s->block[0]);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
773 if(s->per_mb_rl_table){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
774 s->rl_table_index = decode012(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
775 s->rl_chroma_table_index = s->rl_table_index;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
776 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
777
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
778 if(w->abt_flag && w->per_mb_abt){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
779 w->per_block_abt= get_bits1(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
780 if(!w->per_block_abt)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
781 w->abt_type= decode012(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
782 }else
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
783 w->per_block_abt=0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
784 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
785
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
786 if (wmv2_decode_motion(w, &mx, &my) < 0)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
787 return -1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
788
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
789 s->mv_dir = MV_DIR_FORWARD;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
790 s->mv_type = MV_TYPE_16X16;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
791 s->mv[0][0][0] = mx;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
792 s->mv[0][0][1] = my;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
793
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
794 for (i = 0; i < 6; i++) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
795 if (wmv2_decode_inter_block(w, block[i], i, (cbp >> (5 - i)) & 1) < 0)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
796 {
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
797 av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding inter block: %d x %d (%d)\n", s->mb_x, s->mb_y, i);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
798 return -1;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
799 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
800 }
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
801 } else {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
802 //if(s->pict_type==P_TYPE)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
803 // printf("%d%d ", s->inter_intra_pred, cbp);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
804 //printf("I at %d %d %d %06X\n", s->mb_x, s->mb_y, ((cbp&3)? 1 : 0) +((cbp&0x3C)? 2 : 0), show_bits(&s->gb, 24));
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
805 s->ac_pred = get_bits1(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
806 if(s->inter_intra_pred){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
807 s->h263_aic_dir= get_vlc2(&s->gb, inter_intra_vlc.table, INTER_INTRA_VLC_BITS, 1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
808 // printf("%d%d %d %d/", s->ac_pred, s->h263_aic_dir, s->mb_x, s->mb_y);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
809 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
810 if(s->per_mb_rl_table && cbp){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
811 s->rl_table_index = decode012(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
812 s->rl_chroma_table_index = s->rl_table_index;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
813 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
814
2632
67171616ead6 avoid unneeded clear_blocks()
michael
parents: 2628
diff changeset
815 s->dsp.clear_blocks(s->block[0]);
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
816 for (i = 0; i < 6; i++) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
817 if (msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
818 {
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
819 av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding intra block: %d x %d (%d)\n", s->mb_x, s->mb_y, i);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
820 return -1;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
821 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
822 }
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
823 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
824
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
825 return 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
826 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
827
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
828 static int wmv2_decode_init(AVCodecContext *avctx){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
829 Wmv2Context * const w= avctx->priv_data;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
830
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
831 if(ff_h263_decode_init(avctx) < 0)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
832 return -1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
833
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
834 wmv2_common_init(w);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2818
diff changeset
835
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
836 return 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
837 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
838
4947
6a4e8b52dc7b Allow conditional compilation of H.263-related decoders.
diego
parents: 4594
diff changeset
839 #ifdef CONFIG_WMV2_DECODER
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
840 AVCodec wmv2_decoder = {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
841 "wmv2",
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
842 CODEC_TYPE_VIDEO,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
843 CODEC_ID_WMV2,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
844 sizeof(Wmv2Context),
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
845 wmv2_decode_init,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
846 NULL,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
847 ff_h263_decode_end,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
848 ff_h263_decode_frame,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
849 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
850 };
4947
6a4e8b52dc7b Allow conditional compilation of H.263-related decoders.
diego
parents: 4594
diff changeset
851 #endif
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
852
4950
665c61d35b52 Replace general CONFIG_ENCODERS by more fine-grained CONFIG_WMV2_ENCODER.
diego
parents: 4947
diff changeset
853 #ifdef CONFIG_WMV2_ENCODER
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
854 AVCodec wmv2_encoder = {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
855 "wmv2",
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
856 CODEC_TYPE_VIDEO,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
857 CODEC_ID_WMV2,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
858 sizeof(Wmv2Context),
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
859 wmv2_encode_init,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
860 MPV_encode_picture,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
861 MPV_encode_end,
3741
b5436ea83910 1000l copy and paste typo
michael
parents: 3740
diff changeset
862 .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1},
936
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
863 };
1070
6da5ae9ee199 more #ifdef CONFIG_ENCODERS patch by (Wolfgang Hesseler <qv at multimediaware dot com>) with modifications by me (s/WOLFGANG/CONFIG_ENCODERS/ and some other fixes)
michaelni
parents: 1064
diff changeset
864 #endif