comparison mpegvideo_xvmc.c @ 8835:8c11ebbca9b3 libavcodec

whitespace cosmetics: consistent (more or less) K&R style
author diego
date Sat, 14 Feb 2009 16:14:26 +0000
parents 1f4d7469a663
children 4c175e9d492e
comparison
equal deleted inserted replaced
8834:1f4d7469a663 8835:8c11ebbca9b3
34 //XvMC emulation could be performed 34 //XvMC emulation could be performed
35 35
36 #include "xvmc.h" 36 #include "xvmc.h"
37 37
38 //set s->block 38 //set s->block
39 void XVMC_init_block(MpegEncContext *s){ 39 void XVMC_init_block(MpegEncContext *s)
40 {
40 struct xvmc_render_state * render; 41 struct xvmc_render_state * render;
41 render = (struct xvmc_render_state*)s->current_picture.data[2]; 42 render = (struct xvmc_render_state*)s->current_picture.data[2];
42 assert(render != NULL); 43 assert(render != NULL);
43 if( (render == NULL) || (render->magic != MP_XVMC_RENDER_MAGIC) ){ 44 if ((render == NULL) || (render->magic != MP_XVMC_RENDER_MAGIC)) {
44 assert(0); 45 assert(0);
45 return;//make sure that this is a render packet 46 return;//make sure that this is a render packet
46 } 47 }
47 s->block =(DCTELEM *)(render->data_blocks+(render->next_free_data_block_num)*64); 48 s->block =(DCTELEM *)(render->data_blocks+(render->next_free_data_block_num)*64);
48 } 49 }
49 50
50 void XVMC_pack_pblocks(MpegEncContext *s, int cbp){ 51 void XVMC_pack_pblocks(MpegEncContext *s, int cbp)
52 {
51 int i,j; 53 int i,j;
52 const int mb_block_count = 4+(1<<s->chroma_format); 54 const int mb_block_count = 4 + (1 << s->chroma_format);
53 55
54 j=0; 56 j = 0;
55 cbp<<= 12-mb_block_count; 57 cbp <<= 12-mb_block_count;
56 for(i=0; i<mb_block_count; i++){ 58 for (i = 0; i < mb_block_count; i++) {
57 if(cbp & (1<<11)) { 59 if (cbp & (1<<11)) {
58 s->pblocks[i] = (short *)(&s->block[(j++)]); 60 s->pblocks[i] = (short *)(&s->block[(j++)]);
59 }else{ 61 }else{
60 s->pblocks[i] = NULL; 62 s->pblocks[i] = NULL;
61 } 63 }
62 cbp+=cbp; 64 cbp+=cbp;
63 } 65 }
64 } 66 }
65 67
66 //These functions should be called on every new field and/or frame. 68 //These functions should be called on every new field and/or frame.
67 //They should be safe if they are called a few times for the same field! 69 //They should be safe if they are called a few times for the same field!
68 int XVMC_field_start(MpegEncContext*s, AVCodecContext *avctx){ 70 int XVMC_field_start(MpegEncContext*s, AVCodecContext *avctx)
71 {
69 struct xvmc_render_state * render, * last, * next; 72 struct xvmc_render_state * render, * last, * next;
70 73
71 assert(avctx != NULL); 74 assert(avctx != NULL);
72 75
73 render = (struct xvmc_render_state*)s->current_picture.data[2]; 76 render = (struct xvmc_render_state*)s->current_picture.data[2];
74 assert(render != NULL); 77 assert(render != NULL);
75 if( (render == NULL) || (render->magic != MP_XVMC_RENDER_MAGIC) ) 78 if ((render == NULL) || (render->magic != MP_XVMC_RENDER_MAGIC))
76 return -1;//make sure that this is render packet 79 return -1;//make sure that this is render packet
77 80
78 render->picture_structure = s->picture_structure; 81 render->picture_structure = s->picture_structure;
79 render->flags = (s->first_field)? 0: XVMC_SECOND_FIELD; 82 render->flags = (s->first_field)? 0: XVMC_SECOND_FIELD;
80 83
89 return 0;// no prediction from other frames 92 return 0;// no prediction from other frames
90 case FF_B_TYPE: 93 case FF_B_TYPE:
91 next = (struct xvmc_render_state*)s->next_picture.data[2]; 94 next = (struct xvmc_render_state*)s->next_picture.data[2];
92 assert(next!=NULL); 95 assert(next!=NULL);
93 assert(next->state & MP_XVMC_STATE_PREDICTION); 96 assert(next->state & MP_XVMC_STATE_PREDICTION);
94 if(next == NULL) return -1; 97 if (next == NULL)
95 if(next->magic != MP_XVMC_RENDER_MAGIC) return -1; 98 return -1;
99 if (next->magic != MP_XVMC_RENDER_MAGIC)
100 return -1;
96 render->p_future_surface = next->p_surface; 101 render->p_future_surface = next->p_surface;
97 //no return here, going to set forward prediction 102 //no return here, going to set forward prediction
98 case FF_P_TYPE: 103 case FF_P_TYPE:
99 last = (struct xvmc_render_state*)s->last_picture.data[2]; 104 last = (struct xvmc_render_state*)s->last_picture.data[2];
100 if(last == NULL)// && !s->first_field) 105 if (last == NULL)// && !s->first_field)
101 last = render;//predict second field from the first 106 last = render;//predict second field from the first
102 if(last->magic != MP_XVMC_RENDER_MAGIC) return -1; 107 if (last->magic != MP_XVMC_RENDER_MAGIC)
108 return -1;
103 assert(last->state & MP_XVMC_STATE_PREDICTION); 109 assert(last->state & MP_XVMC_STATE_PREDICTION);
104 render->p_past_surface = last->p_surface; 110 render->p_past_surface = last->p_surface;
105 return 0; 111 return 0;
106 } 112 }
107 113
108 return -1; 114 return -1;
109 } 115 }
110 116
111 void XVMC_field_end(MpegEncContext *s){ 117 void XVMC_field_end(MpegEncContext *s)
118 {
112 struct xvmc_render_state * render; 119 struct xvmc_render_state * render;
113 render = (struct xvmc_render_state*)s->current_picture.data[2]; 120 render = (struct xvmc_render_state*)s->current_picture.data[2];
114 assert(render != NULL); 121 assert(render != NULL);
115 122
116 if(render->filled_mv_blocks_num > 0){ 123 if (render->filled_mv_blocks_num > 0)
117 ff_draw_horiz_band(s,0,0); 124 ff_draw_horiz_band(s,0,0);
118 } 125 }
119 } 126
120 127 void XVMC_decode_mb(MpegEncContext *s)
121 void XVMC_decode_mb(MpegEncContext *s){ 128 {
122 XvMCMacroBlock * mv_block; 129 XvMCMacroBlock * mv_block;
123 struct xvmc_render_state * render; 130 struct xvmc_render_state * render;
124 int i,cbp,blocks_per_mb; 131 int i,cbp,blocks_per_mb;
125 132
126 const int mb_xy = s->mb_y * s->mb_stride + s->mb_x; 133 const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
127 134
128 135
129 if(s->encoding){ 136 if (s->encoding) {
130 av_log(s->avctx, AV_LOG_ERROR, "XVMC doesn't support encoding!!!\n"); 137 av_log(s->avctx, AV_LOG_ERROR, "XVMC doesn't support encoding!!!\n");
131 return; 138 return;
132 } 139 }
133 140
134 //from MPV_decode_mb(), 141 //from MPV_decode_mb(),
158 render->filled_mv_blocks_num ]; 165 render->filled_mv_blocks_num ];
159 166
160 mv_block->x = s->mb_x; 167 mv_block->x = s->mb_x;
161 mv_block->y = s->mb_y; 168 mv_block->y = s->mb_y;
162 mv_block->dct_type = s->interlaced_dct;//XVMC_DCT_TYPE_FRAME/FIELD; 169 mv_block->dct_type = s->interlaced_dct;//XVMC_DCT_TYPE_FRAME/FIELD;
163 if(s->mb_intra){ 170 if (s->mb_intra){
164 mv_block->macroblock_type = XVMC_MB_TYPE_INTRA;//no MC, all done 171 mv_block->macroblock_type = XVMC_MB_TYPE_INTRA;//no MC, all done
165 }else{ 172 }else{
166 mv_block->macroblock_type = XVMC_MB_TYPE_PATTERN; 173 mv_block->macroblock_type = XVMC_MB_TYPE_PATTERN;
167 174
168 if(s->mv_dir & MV_DIR_FORWARD){ 175 if (s->mv_dir & MV_DIR_FORWARD) {
169 mv_block->macroblock_type|= XVMC_MB_TYPE_MOTION_FORWARD; 176 mv_block->macroblock_type|= XVMC_MB_TYPE_MOTION_FORWARD;
170 //pmv[n][dir][xy]=mv[dir][n][xy] 177 //pmv[n][dir][xy]=mv[dir][n][xy]
171 mv_block->PMV[0][0][0] = s->mv[0][0][0]; 178 mv_block->PMV[0][0][0] = s->mv[0][0][0];
172 mv_block->PMV[0][0][1] = s->mv[0][0][1]; 179 mv_block->PMV[0][0][1] = s->mv[0][0][1];
173 mv_block->PMV[1][0][0] = s->mv[0][1][0]; 180 mv_block->PMV[1][0][0] = s->mv[0][1][0];
174 mv_block->PMV[1][0][1] = s->mv[0][1][1]; 181 mv_block->PMV[1][0][1] = s->mv[0][1][1];
175 } 182 }
176 if(s->mv_dir & MV_DIR_BACKWARD){ 183 if (s->mv_dir & MV_DIR_BACKWARD) {
177 mv_block->macroblock_type|=XVMC_MB_TYPE_MOTION_BACKWARD; 184 mv_block->macroblock_type|=XVMC_MB_TYPE_MOTION_BACKWARD;
178 mv_block->PMV[0][1][0] = s->mv[1][0][0]; 185 mv_block->PMV[0][1][0] = s->mv[1][0][0];
179 mv_block->PMV[0][1][1] = s->mv[1][0][1]; 186 mv_block->PMV[0][1][1] = s->mv[1][0][1];
180 mv_block->PMV[1][1][0] = s->mv[1][1][0]; 187 mv_block->PMV[1][1][0] = s->mv[1][1][0];
181 mv_block->PMV[1][1][1] = s->mv[1][1][1]; 188 mv_block->PMV[1][1][1] = s->mv[1][1][1];
188 case MV_TYPE_16X8: 195 case MV_TYPE_16X8:
189 mv_block->motion_type = XVMC_PREDICTION_16x8; 196 mv_block->motion_type = XVMC_PREDICTION_16x8;
190 break; 197 break;
191 case MV_TYPE_FIELD: 198 case MV_TYPE_FIELD:
192 mv_block->motion_type = XVMC_PREDICTION_FIELD; 199 mv_block->motion_type = XVMC_PREDICTION_FIELD;
193 if(s->picture_structure == PICT_FRAME){ 200 if (s->picture_structure == PICT_FRAME) {
194 mv_block->PMV[0][0][1]<<=1; 201 mv_block->PMV[0][0][1] <<= 1;
195 mv_block->PMV[1][0][1]<<=1; 202 mv_block->PMV[1][0][1] <<= 1;
196 mv_block->PMV[0][1][1]<<=1; 203 mv_block->PMV[0][1][1] <<= 1;
197 mv_block->PMV[1][1][1]<<=1; 204 mv_block->PMV[1][1][1] <<= 1;
198 } 205 }
199 break; 206 break;
200 case MV_TYPE_DMV: 207 case MV_TYPE_DMV:
201 mv_block->motion_type = XVMC_PREDICTION_DUAL_PRIME; 208 mv_block->motion_type = XVMC_PREDICTION_DUAL_PRIME;
202 if(s->picture_structure == PICT_FRAME){ 209 if (s->picture_structure == PICT_FRAME) {
203 210
204 mv_block->PMV[0][0][0] = s->mv[0][0][0];//top from top 211 mv_block->PMV[0][0][0] = s->mv[0][0][0];//top from top
205 mv_block->PMV[0][0][1] = s->mv[0][0][1]<<1; 212 mv_block->PMV[0][0][1] = s->mv[0][0][1]<<1;
206 213
207 mv_block->PMV[0][1][0] = s->mv[0][0][0];//bottom from bottom 214 mv_block->PMV[0][1][0] = s->mv[0][0][0];//bottom from bottom
223 } 230 }
224 231
225 mv_block->motion_vertical_field_select = 0; 232 mv_block->motion_vertical_field_select = 0;
226 233
227 //set correct field references 234 //set correct field references
228 if(s->mv_type == MV_TYPE_FIELD || s->mv_type == MV_TYPE_16X8){ 235 if (s->mv_type == MV_TYPE_FIELD || s->mv_type == MV_TYPE_16X8) {
229 if( s->field_select[0][0] ) mv_block->motion_vertical_field_select|=1; 236 if (s->field_select[0][0])
230 if( s->field_select[1][0] ) mv_block->motion_vertical_field_select|=2; 237 mv_block->motion_vertical_field_select |= 1;
231 if( s->field_select[0][1] ) mv_block->motion_vertical_field_select|=4; 238 if (s->field_select[1][0])
232 if( s->field_select[1][1] ) mv_block->motion_vertical_field_select|=8; 239 mv_block->motion_vertical_field_select |= 2;
240 if (s->field_select[0][1])
241 mv_block->motion_vertical_field_select |= 4;
242 if (s->field_select[1][1])
243 mv_block->motion_vertical_field_select |= 8;
233 } 244 }
234 }//!intra 245 }//!intra
235 //time to handle data blocks; 246 //time to handle data blocks;
236 mv_block->index = render->next_free_data_block_num; 247 mv_block->index = render->next_free_data_block_num;
237 248
238 blocks_per_mb = 6; 249 blocks_per_mb = 6;
239 if( s->chroma_format >= 2){ 250 if (s->chroma_format >= 2) {
240 blocks_per_mb = 4 + (1 << (s->chroma_format)); 251 blocks_per_mb = 4 + (1 << (s->chroma_format));
241 } 252 }
242 253
243 // calculate cbp 254 // calculate cbp
244 cbp = 0; 255 cbp = 0;
245 for(i=0; i<blocks_per_mb; i++) { 256 for (i = 0; i < blocks_per_mb; i++) {
246 cbp+= cbp; 257 cbp+= cbp;
247 if(s->block_last_index[i] >= 0) 258 if (s->block_last_index[i] >= 0)
248 cbp++; 259 cbp++;
249 } 260 }
250 261
251 if(s->flags & CODEC_FLAG_GRAY){ 262 if (s->flags & CODEC_FLAG_GRAY) {
252 if(s->mb_intra){//intra frames are always full chroma block 263 if (s->mb_intra){//intra frames are always full chroma block
253 for(i=4; i<blocks_per_mb; i++){ 264 for (i = 4; i < blocks_per_mb; i++) {
254 memset(s->pblocks[i],0,sizeof(short)*8*8);//so we need to clear them 265 memset(s->pblocks[i],0,sizeof(short)*8*8);//so we need to clear them
255 if(!render->unsigned_intra) 266 if (!render->unsigned_intra)
256 s->pblocks[i][0] = 1<<10; 267 s->pblocks[i][0] = 1 << 10;
257 } 268 }
258 }else{ 269 }else{
259 cbp&= 0xf << (blocks_per_mb - 4); 270 cbp &= 0xf << (blocks_per_mb - 4);
260 blocks_per_mb = 4;//luminance blocks only 271 blocks_per_mb = 4;//luminance blocks only
261 } 272 }
262 } 273 }
263 mv_block->coded_block_pattern = cbp; 274 mv_block->coded_block_pattern = cbp;
264 if(cbp == 0) 275 if (cbp == 0)
265 mv_block->macroblock_type &= ~XVMC_MB_TYPE_PATTERN; 276 mv_block->macroblock_type &= ~XVMC_MB_TYPE_PATTERN;
266 277
267 for(i=0; i<blocks_per_mb; i++){ 278 for (i = 0; i < blocks_per_mb; i++) {
268 if(s->block_last_index[i] >= 0){ 279 if (s->block_last_index[i] >= 0) {
269 // I do not have unsigned_intra MOCO to test, hope it is OK. 280 // I do not have unsigned_intra MOCO to test, hope it is OK.
270 if( (s->mb_intra) && ( render->idct || (!render->idct && !render->unsigned_intra)) ) 281 if ((s->mb_intra) && (render->idct || (!render->idct && !render->unsigned_intra)))
271 s->pblocks[i][0]-=1<<10; 282 s->pblocks[i][0] -= 1 << 10;
272 if(!render->idct){ 283 if (!render->idct) {
273 s->dsp.idct(s->pblocks[i]); 284 s->dsp.idct(s->pblocks[i]);
274 //!!TODO!clip!!! 285 //!!TODO!clip!!!
275 } 286 }
276 //copy blocks only if the codec doesn't support pblocks reordering 287 //copy blocks only if the codec doesn't support pblocks reordering
277 if(s->avctx->xvmc_acceleration == 1){ 288 if (s->avctx->xvmc_acceleration == 1) {
278 memcpy(&render->data_blocks[(render->next_free_data_block_num)*64], 289 memcpy(&render->data_blocks[(render->next_free_data_block_num)*64],
279 s->pblocks[i],sizeof(short)*8*8); 290 s->pblocks[i],sizeof(short)*8*8);
280 } 291 }
281 render->next_free_data_block_num++; 292 render->next_free_data_block_num++;
282 } 293 }
285 296
286 assert(render->filled_mv_blocks_num <= render->total_number_of_mv_blocks); 297 assert(render->filled_mv_blocks_num <= render->total_number_of_mv_blocks);
287 assert(render->next_free_data_block_num <= render->total_number_of_data_blocks); 298 assert(render->next_free_data_block_num <= render->total_number_of_data_blocks);
288 299
289 300
290 if(render->filled_mv_blocks_num >= render->total_number_of_mv_blocks) 301 if (render->filled_mv_blocks_num >= render->total_number_of_mv_blocks)
291 ff_draw_horiz_band(s,0,0); 302 ff_draw_horiz_band(s,0,0);
292 } 303 }