annotate wmv2.c @ 943:0566d1a8426f libavcodec

10l (int i)
author michael
date Mon, 30 Dec 2002 12:36:28 +0000
parents caa77cd960c0
children ca2a303ea039
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 *
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
4 * This library is free software; you can redistribute it and/or
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
5 * modify it under the terms of the GNU Lesser General Public
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
6 * License as published by the Free Software Foundation; either
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
7 * version 2 of the License, or (at your option) any later version.
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
8 *
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
9 * This library is distributed in the hope that it will be useful,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
12 * Lesser General Public License for more details.
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
13 *
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
14 * You should have received a copy of the GNU Lesser General Public
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
15 * License along with this library; if not, write to the Free Software
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
17 *
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
18 */
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
19
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
20 #include "simple_idct.h"
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
21
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
22 #define SKIP_TYPE_NONE 0
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
23 #define SKIP_TYPE_MPEG 1
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
24 #define SKIP_TYPE_ROW 2
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
25 #define SKIP_TYPE_COL 3
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
26
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
27
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
28 typedef struct Wmv2Context{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
29 MpegEncContext s;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
30 int j_type_bit;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
31 int j_type;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
32 int flag3;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
33 int flag63;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
34 int abt_flag;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
35 int abt_type;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
36 int abt_type_table[6];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
37 int per_mb_abt;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
38 int per_block_abt;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
39 int mspel_bit;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
40 int cbp_table_index;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
41 int top_left_mv_flag;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
42 int per_mb_rl_bit;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
43 int skip_type;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
44 int hshift;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
45
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
46 ScanTable abt_scantable[2];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
47 DCTELEM abt_block2[6][64] __align8;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
48 }Wmv2Context;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
49
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
50 static void wmv2_common_init(Wmv2Context * w){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
51 MpegEncContext * const s= &w->s;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
52
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
53 ff_init_scantable(s, &w->abt_scantable[0], wmv2_scantableA);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
54 ff_init_scantable(s, &w->abt_scantable[1], wmv2_scantableB);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
55 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
56
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
57 static int encode_ext_header(Wmv2Context *w){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
58 MpegEncContext * const s= &w->s;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
59 PutBitContext pb;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
60 int code;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
61
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
62 init_put_bits(&pb, s->avctx->extradata, s->avctx->extradata_size, NULL, NULL);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
63
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
64 put_bits(&pb, 5, s->frame_rate / FRAME_RATE_BASE); //yes 29.97 -> 29
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
65 put_bits(&pb, 11, FFMIN(s->bit_rate/1024, 2047));
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
66
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
67 put_bits(&pb, 1, w->mspel_bit=1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
68 put_bits(&pb, 1, w->flag3=1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
69 put_bits(&pb, 1, w->abt_flag=1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
70 put_bits(&pb, 1, w->j_type_bit=1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
71 put_bits(&pb, 1, w->top_left_mv_flag=0);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
72 put_bits(&pb, 1, w->per_mb_rl_bit=1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
73 put_bits(&pb, 3, code=1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
74
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
75 flush_put_bits(&pb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
76
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
77 s->slice_height = s->mb_height / code;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
78
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
79 return 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
80 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
81
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
82 static int wmv2_encode_init(AVCodecContext *avctx){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
83 Wmv2Context * const w= avctx->priv_data;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
84
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
85 if(MPV_encode_init(avctx) < 0)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
86 return -1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
87
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
88 wmv2_common_init(w);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
89
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
90 avctx->extradata_size= 4;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
91 avctx->extradata= av_mallocz(avctx->extradata_size + 10);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
92 encode_ext_header(w);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
93
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
94 return 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
95 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
96
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
97 static int wmv2_encode_end(AVCodecContext *avctx){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
98 Wmv2Context * const w= avctx->priv_data;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
99
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
100 if(MPV_encode_end(avctx) < 0)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
101 return -1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
102
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
103 avctx->extradata_size= 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
104 av_freep(&avctx->extradata);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
105
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
106 return 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
107 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
108
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
109 int ff_wmv2_encode_picture_header(MpegEncContext * s, int picture_number)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
110 {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
111 Wmv2Context * const w= (Wmv2Context*)s;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
112
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
113 put_bits(&s->pb, 1, s->pict_type - 1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
114 if(s->pict_type == I_TYPE){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
115 put_bits(&s->pb, 7, 0);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
116 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
117 put_bits(&s->pb, 5, s->qscale);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
118
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
119 s->dc_table_index = 1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
120 s->mv_table_index = 1; /* only if P frame */
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
121 // s->use_skip_mb_code = 1; /* only if P frame */
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
122 s->per_mb_rl_table = 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
123 s->mspel= 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
124 w->per_mb_abt=0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
125 w->abt_type=0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
126 w->j_type=0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
127
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
128 if (s->pict_type == I_TYPE) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
129 if(w->j_type_bit) put_bits(&s->pb, 1, w->j_type);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
130
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
131 if(w->per_mb_rl_bit) put_bits(&s->pb, 1, s->per_mb_rl_table);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
132
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
133 if(!s->per_mb_rl_table){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
134 code012(&s->pb, s->rl_chroma_table_index);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
135 code012(&s->pb, s->rl_table_index);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
136 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
137
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
138 put_bits(&s->pb, 1, s->dc_table_index);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
139
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
140 s->inter_intra_pred= 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
141 s->no_rounding = 1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
142 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
143 int cbp_index;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
144
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
145 put_bits(&s->pb, 2, SKIP_TYPE_NONE);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
146
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
147 code012(&s->pb, cbp_index=0);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
148 if(s->qscale <= 10){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
149 int map[3]= {0,2,1};
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
150 w->cbp_table_index= map[cbp_index];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
151 }else if(s->qscale <= 20){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
152 int map[3]= {1,0,2};
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
153 w->cbp_table_index= map[cbp_index];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
154 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
155 int map[3]= {2,1,0};
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
156 w->cbp_table_index= map[cbp_index];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
157 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
158
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
159 if(w->mspel_bit) put_bits(&s->pb, 1, s->mspel);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
160
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
161 if(w->abt_flag){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
162 put_bits(&s->pb, 1, w->per_mb_abt^1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
163 if(!w->per_mb_abt){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
164 code012(&s->pb, w->abt_type);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
165 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
166 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
167
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
168 if(w->per_mb_rl_bit) put_bits(&s->pb, 1, s->per_mb_rl_table);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
169
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
170 if(!s->per_mb_rl_table){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
171 code012(&s->pb, s->rl_table_index);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
172 s->rl_chroma_table_index = s->rl_table_index;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
173 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
174 put_bits(&s->pb, 1, s->dc_table_index);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
175 put_bits(&s->pb, 1, s->mv_table_index);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
176
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
177 s->inter_intra_pred= (s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
178 s->no_rounding ^= 1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
179 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
180 s->esc3_level_length= 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
181 s->esc3_run_length= 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
182
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
183 return 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
184 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
185
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
186 // nearly idential to wmv1 but thats just because we dont use the useless M$ crap features
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
187 // its duplicated here in case someone wants to add support for these carp features
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
188 void ff_wmv2_encode_mb(MpegEncContext * s,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
189 DCTELEM block[6][64],
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
190 int motion_x, int motion_y)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
191 {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
192 Wmv2Context * const w= (Wmv2Context*)s;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
193 int cbp, coded_cbp, i;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
194 int pred_x, pred_y;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
195 UINT8 *coded_block;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
196
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
197 handle_slices(s);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
198
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
199 if (!s->mb_intra) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
200 /* compute cbp */
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
201 set_stat(ST_INTER_MB);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
202 cbp = 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
203 for (i = 0; i < 6; i++) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
204 if (s->block_last_index[i] >= 0)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
205 cbp |= 1 << (5 - i);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
206 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
207
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
208 put_bits(&s->pb,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
209 wmv2_inter_table[w->cbp_table_index][cbp + 64][1],
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
210 wmv2_inter_table[w->cbp_table_index][cbp + 64][0]);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
211
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
212 /* motion vector */
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
213 h263_pred_motion(s, 0, &pred_x, &pred_y);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
214 msmpeg4_encode_motion(s, motion_x - pred_x,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
215 motion_y - pred_y);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
216 } else {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
217 /* compute cbp */
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
218 cbp = 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
219 coded_cbp = 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
220 for (i = 0; i < 6; i++) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
221 int val, pred;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
222 val = (s->block_last_index[i] >= 1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
223 cbp |= val << (5 - i);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
224 if (i < 4) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
225 /* predict value for close blocks only for luma */
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
226 pred = coded_block_pred(s, i, &coded_block);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
227 *coded_block = val;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
228 val = val ^ pred;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
229 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
230 coded_cbp |= val << (5 - i);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
231 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
232 #if 0
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
233 if (coded_cbp)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
234 printf("cbp=%x %x\n", cbp, coded_cbp);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
235 #endif
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
236
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
237 if (s->pict_type == I_TYPE) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
238 set_stat(ST_INTRA_MB);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
239 put_bits(&s->pb,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
240 table_mb_intra[coded_cbp][1], table_mb_intra[coded_cbp][0]);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
241 } else {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
242 put_bits(&s->pb,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
243 wmv2_inter_table[w->cbp_table_index][cbp][1],
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
244 wmv2_inter_table[w->cbp_table_index][cbp][0]);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
245 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
246 set_stat(ST_INTRA_MB);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
247 put_bits(&s->pb, 1, 0); /* no AC prediction yet */
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
248 if(s->inter_intra_pred){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
249 s->h263_aic_dir=0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
250 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
251 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
252 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
253
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
254 for (i = 0; i < 6; i++) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
255 msmpeg4_encode_block(s, block[i], i);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
256 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
257 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
258
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
259 static void parse_mb_skip(Wmv2Context * w){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
260 int mb_x, mb_y;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
261 MpegEncContext * const s= &w->s;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
262
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
263 w->skip_type= get_bits(&s->gb, 2);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
264 switch(w->skip_type){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
265 case SKIP_TYPE_NONE:
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
266 for(mb_y=0; mb_y<s->mb_height; mb_y++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
267 for(mb_x=0; mb_x<s->mb_width; mb_x++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
268 s->mb_type[mb_y*s->mb_width + mb_x]= 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
269 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
270 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
271 break;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
272 case SKIP_TYPE_MPEG:
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
273 for(mb_y=0; mb_y<s->mb_height; mb_y++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
274 for(mb_x=0; mb_x<s->mb_width; mb_x++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
275 s->mb_type[mb_y*s->mb_width + mb_x]= get_bits1(&s->gb) ? MB_TYPE_SKIPED : 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
276 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
277 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
278 break;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
279 case SKIP_TYPE_ROW:
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
280 for(mb_y=0; mb_y<s->mb_height; mb_y++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
281 if(get_bits1(&s->gb)){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
282 for(mb_x=0; mb_x<s->mb_width; mb_x++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
283 s->mb_type[mb_y*s->mb_width + mb_x]= MB_TYPE_SKIPED;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
284 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
285 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
286 for(mb_x=0; mb_x<s->mb_width; mb_x++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
287 s->mb_type[mb_y*s->mb_width + mb_x]= get_bits1(&s->gb) ? MB_TYPE_SKIPED : 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
288 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
289 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
290 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
291 break;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
292 case SKIP_TYPE_COL:
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
293 for(mb_x=0; mb_x<s->mb_width; mb_x++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
294 if(get_bits1(&s->gb)){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
295 for(mb_y=0; mb_y<s->mb_height; mb_y++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
296 s->mb_type[mb_y*s->mb_width + mb_x]= MB_TYPE_SKIPED;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
297 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
298 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
299 for(mb_y=0; mb_y<s->mb_height; mb_y++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
300 s->mb_type[mb_y*s->mb_width + mb_x]= get_bits1(&s->gb) ? MB_TYPE_SKIPED : 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
301 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
302 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
303 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
304 break;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
305 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
306 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
307
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
308 static int decode_ext_header(Wmv2Context *w){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
309 MpegEncContext * const s= &w->s;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
310 GetBitContext gb;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
311 int fps;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
312 int code;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
313
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
314 if(s->avctx->extradata_size<4) return -1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
315
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
316 init_get_bits(&gb, s->avctx->extradata, s->avctx->extradata_size);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
317
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
318 fps = get_bits(&gb, 5);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
319 s->bit_rate = get_bits(&gb, 11)*1024;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
320 w->mspel_bit = get_bits1(&gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
321 w->flag3 = get_bits1(&gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
322 w->abt_flag = get_bits1(&gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
323 w->j_type_bit = get_bits1(&gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
324 w->top_left_mv_flag= get_bits1(&gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
325 w->per_mb_rl_bit = get_bits1(&gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
326 code = get_bits(&gb, 3);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
327
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
328 if(code==0) return -1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
329
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
330 s->slice_height = s->mb_height / code;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
331
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
332 if(s->avctx->debug&FF_DEBUG_PICT_INFO){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
333 printf("fps:%d, br:%d, qpbit:%d, abt_flag:%d, j_type_bit:%d, tl_mv_flag:%d, mbrl_bit:%d, code:%d, flag3:%d\n",
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
334 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);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
335 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
336 return 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
337 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
338
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
339 int ff_wmv2_decode_picture_header(MpegEncContext * s)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
340 {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
341 Wmv2Context * const w= (Wmv2Context*)s;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
342 int code, i;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
343
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
344 #if 0
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
345 {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
346 int i;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
347 for(i=0; i<s->gb.size*8; i++)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
348 printf("%d", get_bits1(&s->gb));
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
349 // get_bits1(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
350 printf("END\n");
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
351 return -1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
352 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
353 #endif
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
354 if(s->picture_number==0)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
355 decode_ext_header(w);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
356
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
357 s->pict_type = get_bits(&s->gb, 1) + 1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
358 if(s->pict_type == I_TYPE){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
359 code = get_bits(&s->gb, 7);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
360 printf("I7:%X/\n", code);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
361 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
362 s->qscale = get_bits(&s->gb, 5);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
363
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
364 if (s->pict_type == I_TYPE) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
365 if(w->j_type_bit) w->j_type= get_bits1(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
366 else w->j_type= 0; //FIXME check
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
367
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
368 if(!w->j_type){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
369 if(w->per_mb_rl_bit) s->per_mb_rl_table= get_bits1(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
370 else s->per_mb_rl_table= 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
371
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
372 if(!s->per_mb_rl_table){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
373 s->rl_chroma_table_index = decode012(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
374 s->rl_table_index = decode012(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
375 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
376
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
377 s->dc_table_index = get_bits1(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
378 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
379 s->inter_intra_pred= 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
380 s->no_rounding = 1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
381 if(s->avctx->debug&FF_DEBUG_PICT_INFO){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
382 printf("qscale:%d rlc:%d rl:%d dc:%d mbrl:%d j_type:%d \n",
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
383 s->qscale,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
384 s->rl_chroma_table_index,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
385 s->rl_table_index,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
386 s->dc_table_index,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
387 s->per_mb_rl_table,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
388 w->j_type);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
389 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
390 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
391 int cbp_index;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
392 w->j_type=0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
393
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
394 parse_mb_skip(w);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
395 cbp_index= decode012(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
396 if(s->qscale <= 10){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
397 int map[3]= {0,2,1};
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
398 w->cbp_table_index= map[cbp_index];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
399 }else if(s->qscale <= 20){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
400 int map[3]= {1,0,2};
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
401 w->cbp_table_index= map[cbp_index];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
402 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
403 int map[3]= {2,1,0};
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
404 w->cbp_table_index= map[cbp_index];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
405 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
406
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
407 if(w->mspel_bit) s->mspel= get_bits1(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
408 else s->mspel= 0; //FIXME check
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
409
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
410 if(w->abt_flag){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
411 w->per_mb_abt= get_bits1(&s->gb)^1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
412 if(!w->per_mb_abt){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
413 w->abt_type= decode012(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
414 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
415 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
416
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
417 if(w->per_mb_rl_bit) s->per_mb_rl_table= get_bits1(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
418 else s->per_mb_rl_table= 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
419
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
420 if(!s->per_mb_rl_table){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
421 s->rl_table_index = decode012(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
422 s->rl_chroma_table_index = s->rl_table_index;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
423 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
424
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
425 s->dc_table_index = get_bits1(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
426 s->mv_table_index = get_bits1(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
427
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
428 s->inter_intra_pred= (s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
429 s->no_rounding ^= 1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
430
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
431 if(s->avctx->debug&FF_DEBUG_PICT_INFO){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
432 printf("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",
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
433 s->rl_table_index,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
434 s->rl_chroma_table_index,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
435 s->dc_table_index,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
436 s->mv_table_index,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
437 s->per_mb_rl_table,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
438 s->qscale,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
439 s->mspel,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
440 w->per_mb_abt,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
441 w->abt_type,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
442 w->cbp_table_index,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
443 s->inter_intra_pred);
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->esc3_level_length= 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
447 s->esc3_run_length= 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
448
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
449 if(s->avctx->debug&FF_DEBUG_SKIP){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
450 for(i=0; i<s->mb_num; i++){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
451 if(i%s->mb_width==0) printf("\n");
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
452 printf("%d", s->mb_type[i]);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
453 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
454 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
455 s->picture_number++; //FIXME ?
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
456
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
457
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
458 // if(w->j_type)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
459 // return wmv2_decode_j_picture(w); //FIXME
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
460
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
461 if(w->j_type){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
462 printf("J-type picture isnt supported\n");
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
463 return -1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
464 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
465
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
466 return 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
467 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
468
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
469 void ff_wmv2_decode_init(MpegEncContext *s){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
470 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
471
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
472 static inline int wmv2_decode_motion(Wmv2Context *w, int *mx_ptr, int *my_ptr){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
473 MpegEncContext * const s= &w->s;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
474 int ret;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
475
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
476 ret= msmpeg4_decode_motion(s, mx_ptr, my_ptr);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
477
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
478 if(ret<0) return -1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
479
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
480 if((((*mx_ptr)|(*my_ptr)) & 1) && s->mspel)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
481 w->hshift= get_bits1(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
482 else
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
483 w->hshift= 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
484
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
485 //printf("%d %d ", *mx_ptr, *my_ptr);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
486
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
487 return 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
488 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
489
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
490 static int16_t *wmv2_pred_motion(Wmv2Context *w, int *px, int *py){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
491 MpegEncContext * const s= &w->s;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
492 int xy, wrap, diff, type;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
493 INT16 *A, *B, *C, *mot_val;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
494
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
495 wrap = s->block_wrap[0];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
496 xy = s->block_index[0];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
497
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
498 mot_val = s->motion_val[xy];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
499
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
500 A = s->motion_val[xy - 1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
501 B = s->motion_val[xy - wrap];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
502 C = s->motion_val[xy + 2 - wrap];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
503
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
504 diff= FFMAX(ABS(A[0] - B[0]), ABS(A[1] - B[1]));
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
505
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
506 if(s->mb_x && s->mb_y && !s->mspel && w->top_left_mv_flag && diff >= 8)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
507 //FIXME top/left bit too if y=!0 && first_slice_line?
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
508 type= get_bits1(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
509 else
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
510 type= 2;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
511
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
512 if(type == 0){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
513 *px= A[0];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
514 *py= A[1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
515 }else if(type == 1){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
516 *px= B[0];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
517 *py= B[1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
518 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
519 /* special case for first (slice) line */
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
520 if (s->first_slice_line) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
521 *px = A[0];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
522 *py = A[1];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
523 } else {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
524 *px = mid_pred(A[0], B[0], C[0]);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
525 *py = mid_pred(A[1], B[1], C[1]);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
526 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
527 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
528
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
529 return mot_val;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
530 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
531
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
532 static inline int wmv2_decode_inter_block(Wmv2Context *w, DCTELEM *block, int n, int cbp){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
533 MpegEncContext * const s= &w->s;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
534 static const int sub_cbp_table[3]= {2,3,1};
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
535 int sub_cbp;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
536
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
537 if(!cbp){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
538 s->block_last_index[n] = -1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
539
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
540 return 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
541 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
542
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
543 if(w->per_block_abt)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
544 w->abt_type= decode012(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
545 #if 0
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
546 if(w->per_block_abt)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
547 printf("B%d", w->abt_type);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
548 #endif
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
549 w->abt_type_table[n]= w->abt_type;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
550
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
551 if(w->abt_type){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
552 // const uint8_t *scantable= w->abt_scantable[w->abt_type-1].permutated;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
553 const uint8_t *scantable= w->abt_scantable[w->abt_type-1].scantable;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
554 // 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
555
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
556 sub_cbp= sub_cbp_table[ decode012(&s->gb) ];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
557 // printf("S%d", sub_cbp);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
558
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
559 if(sub_cbp&1){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
560 if (msmpeg4_decode_block(s, block, n, 1, scantable) < 0)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
561 return -1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
562 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
563
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
564 if(sub_cbp&2){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
565 if (msmpeg4_decode_block(s, w->abt_block2[n], n, 1, scantable) < 0)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
566 return -1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
567 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
568 s->block_last_index[n] = 63;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
569
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
570 return 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
571 }else{
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
572 return msmpeg4_decode_block(s, block, n, 1, s->inter_scantable.permutated);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
573 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
574 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
575
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
576 static void wmv2_add_block(Wmv2Context *w, DCTELEM *block1, uint8_t *dst, int stride, int n){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
577 MpegEncContext * const s= &w->s;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
578 uint8_t temp[2][64];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
579 int i;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
580
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
581 if(w->abt_type_table[n] && 0){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
582 int a,b;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
583
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
584 a= block1[0];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
585 b= w->abt_block2[n][0];
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
586 block1[0]= a+b;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
587 w->abt_block2[n][0]= a-b;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
588 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
589
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
590 switch(w->abt_type_table[n]){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
591 case 0:
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
592 if (s->block_last_index[n] >= 0) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
593 s->idct_add (dst, stride, block1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
594 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
595 break;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
596 case 1:
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
597 simple_idct84_add(dst , stride, block1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
598 simple_idct84_add(dst + 4*stride, stride, w->abt_block2[n]);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
599 memset(w->abt_block2[n], 0, 64*sizeof(DCTELEM));
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
600 break;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
601 case 2:
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
602 simple_idct48_add(dst , stride, block1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
603 simple_idct48_add(dst + 4 , stride, w->abt_block2[n]);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
604 memset(w->abt_block2[n], 0, 64*sizeof(DCTELEM));
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
605 break;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
606 default:
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
607 fprintf(stderr, "internal error in WMV2 abt\n");
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
608 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
609 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
610
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
611 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
612 Wmv2Context * const w= (Wmv2Context*)s;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
613
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
614 wmv2_add_block(w, block1[0], dest_y , s->linesize, 0);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
615 wmv2_add_block(w, block1[1], dest_y + 8 , s->linesize, 1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
616 wmv2_add_block(w, block1[2], dest_y + 8*s->linesize, s->linesize, 2);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
617 wmv2_add_block(w, block1[3], dest_y + 8 + 8*s->linesize, s->linesize, 3);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
618
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
619 if(s->flags&CODEC_FLAG_GRAY) return;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
620
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
621 wmv2_add_block(w, block1[4], dest_cb , s->uvlinesize, 4);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
622 wmv2_add_block(w, block1[5], dest_cr , s->uvlinesize, 5);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
623 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
624
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
625 void ff_mspel_motion(MpegEncContext *s,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
626 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
627 UINT8 **ref_picture, op_pixels_func (*pix_op)[4],
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
628 int motion_x, int motion_y, int h)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
629 {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
630 Wmv2Context * const w= (Wmv2Context*)s;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
631 UINT8 *ptr;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
632 int dxy, offset, mx, my, src_x, src_y, v_edge_pos, linesize, uvlinesize;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
633 int emu=0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
634
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
635 dxy = ((motion_y & 1) << 1) | (motion_x & 1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
636 dxy = 2*dxy + w->hshift;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
637 src_x = s->mb_x * 16 + (motion_x >> 1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
638 src_y = s->mb_y * 16 + (motion_y >> 1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
639
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
640 /* WARNING: do no forget half pels */
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
641 v_edge_pos = s->v_edge_pos;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
642 src_x = clip(src_x, -16, s->width);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
643 src_y = clip(src_y, -16, s->height);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
644 linesize = s->linesize;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
645 uvlinesize = s->uvlinesize;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
646 ptr = ref_picture[0] + (src_y * linesize) + src_x;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
647
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
648 if(s->flags&CODEC_FLAG_EMU_EDGE){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
649 if(src_x<1 || src_y<1 || src_x + 17 >= s->h_edge_pos
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
650 || src_y + h+1 >= v_edge_pos){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
651 ff_emulated_edge_mc(s, ptr - 1 - s->linesize, s->linesize, 19, 19,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
652 src_x-1, src_y-1, s->h_edge_pos, s->v_edge_pos);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
653 ptr= s->edge_emu_buffer + 1 + s->linesize;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
654 emu=1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
655 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
656 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
657
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
658 s->dsp.put_mspel_pixels_tab[dxy](dest_y , ptr , linesize);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
659 s->dsp.put_mspel_pixels_tab[dxy](dest_y+8 , ptr+8 , linesize);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
660 s->dsp.put_mspel_pixels_tab[dxy](dest_y +8*linesize, ptr +8*linesize, linesize);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
661 s->dsp.put_mspel_pixels_tab[dxy](dest_y+8+8*linesize, ptr+8+8*linesize, linesize);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
662
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
663 if(s->flags&CODEC_FLAG_GRAY) return;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
664
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
665 if (s->out_format == FMT_H263) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
666 dxy = 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
667 if ((motion_x & 3) != 0)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
668 dxy |= 1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
669 if ((motion_y & 3) != 0)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
670 dxy |= 2;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
671 mx = motion_x >> 2;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
672 my = motion_y >> 2;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
673 } else {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
674 mx = motion_x / 2;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
675 my = motion_y / 2;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
676 dxy = ((my & 1) << 1) | (mx & 1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
677 mx >>= 1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
678 my >>= 1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
679 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
680
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
681 src_x = s->mb_x * 8 + mx;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
682 src_y = s->mb_y * 8 + my;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
683 src_x = clip(src_x, -8, s->width >> 1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
684 if (src_x == (s->width >> 1))
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
685 dxy &= ~1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
686 src_y = clip(src_y, -8, s->height >> 1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
687 if (src_y == (s->height >> 1))
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
688 dxy &= ~2;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
689 offset = (src_y * uvlinesize) + src_x;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
690 ptr = ref_picture[1] + offset;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
691 if(emu){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
692 ff_emulated_edge_mc(s, ptr, s->uvlinesize, 9, 9,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
693 src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
694 ptr= s->edge_emu_buffer;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
695 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
696 pix_op[1][dxy](dest_cb, ptr, uvlinesize, h >> 1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
697
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
698 ptr = ref_picture[2] + offset;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
699 if(emu){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
700 ff_emulated_edge_mc(s, ptr, s->uvlinesize, 9, 9,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
701 src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
702 ptr= s->edge_emu_buffer;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
703 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
704 pix_op[1][dxy](dest_cr, ptr, uvlinesize, h >> 1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
705 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
706
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
707
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
708 static int wmv2_decode_mb(MpegEncContext *s, DCTELEM block[6][64])
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
709 {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
710 Wmv2Context * const w= (Wmv2Context*)s;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
711 int cbp, code, i;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
712 UINT8 *coded_val;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
713
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
714 if(w->j_type) return 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
715
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
716 s->error_status_table[s->mb_x + s->mb_y*s->mb_width]= 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
717
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
718 if (s->pict_type == P_TYPE) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
719 if(s->mb_type[s->mb_y * s->mb_width + s->mb_x]&MB_TYPE_SKIPED){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
720 /* skip mb */
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
721 s->mb_intra = 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
722 for(i=0;i<6;i++)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
723 s->block_last_index[i] = -1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
724 s->mv_dir = MV_DIR_FORWARD;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
725 s->mv_type = MV_TYPE_16X16;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
726 s->mv[0][0][0] = 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
727 s->mv[0][0][1] = 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
728 s->mb_skiped = 1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
729 return 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
730 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
731
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
732 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
733 if (code < 0)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
734 return -1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
735 s->mb_intra = (~code & 0x40) >> 6;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
736
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
737 cbp = code & 0x3f;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
738 } else {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
739 s->mb_intra = 1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
740 code = get_vlc2(&s->gb, mb_intra_vlc.table, MB_INTRA_VLC_BITS, 2);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
741 if (code < 0){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
742 fprintf(stderr, "II-cbp illegal at %d %d\n", s->mb_x, s->mb_y);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
743 return -1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
744 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
745 /* predict coded block pattern */
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
746 cbp = 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
747 for(i=0;i<6;i++) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
748 int val = ((code >> (5 - i)) & 1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
749 if (i < 4) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
750 int pred = coded_block_pred(s, i, &coded_val);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
751 val = val ^ pred;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
752 *coded_val = val;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
753 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
754 cbp |= val << (5 - i);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
755 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
756 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
757
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
758 if (!s->mb_intra) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
759 int mx, my;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
760 //printf("P at %d %d\n", s->mb_x, s->mb_y);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
761 wmv2_pred_motion(w, &mx, &my);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
762
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
763 if(cbp){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
764 if(s->per_mb_rl_table){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
765 s->rl_table_index = decode012(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
766 s->rl_chroma_table_index = s->rl_table_index;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
767 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
768
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
769 if(w->abt_flag && w->per_mb_abt){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
770 w->per_block_abt= get_bits1(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
771 if(!w->per_block_abt)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
772 w->abt_type= decode012(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
773 }else
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
774 w->per_block_abt=0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
775 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
776
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
777 if (wmv2_decode_motion(w, &mx, &my) < 0)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
778 return -1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
779
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
780 s->mv_dir = MV_DIR_FORWARD;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
781 s->mv_type = MV_TYPE_16X16;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
782 s->mv[0][0][0] = mx;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
783 s->mv[0][0][1] = my;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
784
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
785 for (i = 0; i < 6; i++) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
786 if (wmv2_decode_inter_block(w, block[i], i, (cbp >> (5 - i)) & 1) < 0)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
787 {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
788 fprintf(stderr,"\nerror while decoding inter block: %d x %d (%d)\n", s->mb_x, s->mb_y, i);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
789 return -1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
790 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
791 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
792 } else {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
793 //if(s->pict_type==P_TYPE)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
794 // printf("%d%d ", s->inter_intra_pred, cbp);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
795 //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
796 s->ac_pred = get_bits1(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
797 if(s->inter_intra_pred){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
798 s->h263_aic_dir= get_vlc2(&s->gb, inter_intra_vlc.table, INTER_INTRA_VLC_BITS, 1);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
799 // 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
800 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
801 if(s->per_mb_rl_table && cbp){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
802 s->rl_table_index = decode012(&s->gb);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
803 s->rl_chroma_table_index = s->rl_table_index;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
804 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
805
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
806 for (i = 0; i < 6; i++) {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
807 if (msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
808 {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
809 fprintf(stderr,"\nerror while decoding intra block: %d x %d (%d)\n", s->mb_x, s->mb_y, i);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
810 return -1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
811 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
812 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
813 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
814
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
815 return 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
816 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
817
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
818 static int wmv2_decode_init(AVCodecContext *avctx){
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
819 Wmv2Context * const w= avctx->priv_data;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
820
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
821 if(ff_h263_decode_init(avctx) < 0)
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
822 return -1;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
823
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
824 wmv2_common_init(w);
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
825
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
826 return 0;
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
827 }
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
828
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
829 AVCodec wmv2_decoder = {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
830 "wmv2",
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
831 CODEC_TYPE_VIDEO,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
832 CODEC_ID_WMV2,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
833 sizeof(Wmv2Context),
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
834 wmv2_decode_init,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
835 NULL,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
836 ff_h263_decode_end,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
837 ff_h263_decode_frame,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
838 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
839 };
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
840
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
841 AVCodec wmv2_encoder = {
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
842 "wmv2",
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
843 CODEC_TYPE_VIDEO,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
844 CODEC_ID_WMV2,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
845 sizeof(Wmv2Context),
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
846 wmv2_encode_init,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
847 MPV_encode_picture,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
848 MPV_encode_end,
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
849 };
caa77cd960c0 qpel encoding
michaelni
parents:
diff changeset
850