Mercurial > libavcodec.hg
comparison mpeg12.c @ 1580:628bf341e099 libavcodec
XvMC speedup by removing one memcpy and doing MB packing
author | iive |
---|---|
date | Mon, 27 Oct 2003 23:22:43 +0000 |
parents | fca47124001d |
children | b69b086f5570 |
comparison
equal
deleted
inserted
replaced
1579:039cb2296de2 | 1580:628bf341e099 |
---|---|
70 static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred); | 70 static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred); |
71 | 71 |
72 #ifdef HAVE_XVMC | 72 #ifdef HAVE_XVMC |
73 extern int XVMC_field_start(MpegEncContext *s, AVCodecContext *avctx); | 73 extern int XVMC_field_start(MpegEncContext *s, AVCodecContext *avctx); |
74 extern int XVMC_field_end(MpegEncContext *s); | 74 extern int XVMC_field_end(MpegEncContext *s); |
75 extern void XVMC_pack_pblocks(MpegEncContext *s,int cbp); | |
76 extern void XVMC_init_block(s);//set s->block | |
75 #endif | 77 #endif |
76 | 78 |
77 #ifdef CONFIG_ENCODERS | 79 #ifdef CONFIG_ENCODERS |
78 static uint8_t (*mv_penalty)[MAX_MV*2+1]= NULL; | 80 static uint8_t (*mv_penalty)[MAX_MV*2+1]= NULL; |
79 static uint8_t fcode_tab[MAX_MV*2+1]; | 81 static uint8_t fcode_tab[MAX_MV*2+1]; |
1081 | 1083 |
1082 skip_bits1(&s->gb); /* marker */ | 1084 skip_bits1(&s->gb); /* marker */ |
1083 }else | 1085 }else |
1084 memset(s->last_mv, 0, sizeof(s->last_mv)); /* reset mv prediction */ | 1086 memset(s->last_mv, 0, sizeof(s->last_mv)); /* reset mv prediction */ |
1085 s->mb_intra = 1; | 1087 s->mb_intra = 1; |
1088 #ifdef HAVE_XVMC | |
1089 //one 1 we memcpy blocks in xvmcvideo | |
1090 if(s->avctx->xvmc_acceleration > 1){ | |
1091 XVMC_pack_pblocks(s,-1);//inter are always full blocks | |
1092 if(s->swap_uv){ | |
1093 exchange_uv(s); | |
1094 } | |
1095 } | |
1096 #endif | |
1086 | 1097 |
1087 if (s->codec_id == CODEC_ID_MPEG2VIDEO) { | 1098 if (s->codec_id == CODEC_ID_MPEG2VIDEO) { |
1088 for(i=0;i<6;i++) { | 1099 for(i=0;i<6;i++) { |
1089 if (mpeg2_decode_block_intra(s, block[i], i) < 0) | 1100 if (mpeg2_decode_block_intra(s, s->pblocks[i], i) < 0) |
1090 return -1; | 1101 return -1; |
1091 } | 1102 } |
1092 } else { | 1103 } else { |
1093 for(i=0;i<6;i++) { | 1104 for(i=0;i<6;i++) { |
1094 if (mpeg1_decode_block_intra(s, block[i], i) < 0) | 1105 if (mpeg1_decode_block_intra(s, s->pblocks[i], i) < 0) |
1095 return -1; | 1106 return -1; |
1096 } | 1107 } |
1097 } | 1108 } |
1098 } else { | 1109 } else { |
1099 if (mb_type & MB_TYPE_ZERO_MV){ | 1110 if (mb_type & MB_TYPE_ZERO_MV){ |
1260 fprintf(stderr, "invalid cbp at %d %d\n", s->mb_x, s->mb_y); | 1271 fprintf(stderr, "invalid cbp at %d %d\n", s->mb_x, s->mb_y); |
1261 return -1; | 1272 return -1; |
1262 } | 1273 } |
1263 cbp++; | 1274 cbp++; |
1264 | 1275 |
1276 #ifdef HAVE_XVMC | |
1277 //on 1 we memcpy blocks in xvmcvideo | |
1278 if(s->avctx->xvmc_acceleration > 1){ | |
1279 XVMC_pack_pblocks(s,cbp); | |
1280 if(s->swap_uv){ | |
1281 exchange_uv(s); | |
1282 } | |
1283 } | |
1284 #endif | |
1285 | |
1265 if (s->codec_id == CODEC_ID_MPEG2VIDEO) { | 1286 if (s->codec_id == CODEC_ID_MPEG2VIDEO) { |
1266 for(i=0;i<6;i++) { | 1287 for(i=0;i<6;i++) { |
1267 if (cbp & 32) { | 1288 if (cbp & 32) { |
1268 if (mpeg2_decode_block_non_intra(s, block[i], i) < 0) | 1289 if (mpeg2_decode_block_non_intra(s, s->pblocks[i], i) < 0) |
1269 return -1; | 1290 return -1; |
1270 } else { | 1291 } else { |
1271 s->block_last_index[i] = -1; | 1292 s->block_last_index[i] = -1; |
1272 } | 1293 } |
1273 cbp+=cbp; | 1294 cbp+=cbp; |
1274 } | 1295 } |
1275 } else { | 1296 } else { |
1276 for(i=0;i<6;i++) { | 1297 for(i=0;i<6;i++) { |
1277 if (cbp & 32) { | 1298 if (cbp & 32) { |
1278 if (mpeg1_decode_block_inter(s, block[i], i) < 0) | 1299 if (mpeg1_decode_block_inter(s, s->pblocks[i], i) < 0) |
1279 return -1; | 1300 return -1; |
1280 } else { | 1301 } else { |
1281 s->block_last_index[i] = -1; | 1302 s->block_last_index[i] = -1; |
1282 } | 1303 } |
1283 cbp+=cbp; | 1304 cbp+=cbp; |
1958 mpeg_decode_picture_coding_extension(s); | 1979 mpeg_decode_picture_coding_extension(s); |
1959 break; | 1980 break; |
1960 } | 1981 } |
1961 } | 1982 } |
1962 | 1983 |
1963 static void exchange_uv(AVFrame *f){ | 1984 static void exchange_uv(MpegEncContext *s){ |
1964 uint8_t *t= f->data[1]; | 1985 short * tmp; |
1965 f->data[1]= f->data[2]; | 1986 |
1966 f->data[2]= t; | 1987 tmp = s->pblocks[4]; |
1988 s->pblocks[4] = s->pblocks[5]; | |
1989 s->pblocks[5] = tmp; | |
1967 } | 1990 } |
1968 | 1991 |
1969 #define DECODE_SLICE_FATAL_ERROR -2 | 1992 #define DECODE_SLICE_FATAL_ERROR -2 |
1970 #define DECODE_SLICE_ERROR -1 | 1993 #define DECODE_SLICE_ERROR -1 |
1971 #define DECODE_SLICE_OK 0 | 1994 #define DECODE_SLICE_OK 0 |
2091 s->resync_mb_y= s->mb_y = start_code; | 2114 s->resync_mb_y= s->mb_y = start_code; |
2092 s->mb_skip_run= 0; | 2115 s->mb_skip_run= 0; |
2093 ff_init_block_index(s); | 2116 ff_init_block_index(s); |
2094 | 2117 |
2095 for(;;) { | 2118 for(;;) { |
2119 #ifdef HAVE_XVMC | |
2120 //one 1 we memcpy blocks in xvmcvideo | |
2121 if(s->avctx->xvmc_acceleration > 1) | |
2122 XVMC_init_block(s);//set s->block | |
2123 #endif | |
2124 | |
2096 s->dsp.clear_blocks(s->block[0]); | 2125 s->dsp.clear_blocks(s->block[0]); |
2097 | 2126 |
2098 ret = mpeg_decode_mb(s, s->block); | 2127 ret = mpeg_decode_mb(s, s->block); |
2099 | 2128 |
2100 dprintf("ret=%d\n", ret); | 2129 dprintf("ret=%d\n", ret); |
2131 s->dest[2] += 8; | 2160 s->dest[2] += 8; |
2132 | 2161 |
2133 MPV_decode_mb(s, s->block); | 2162 MPV_decode_mb(s, s->block); |
2134 | 2163 |
2135 if (++s->mb_x >= s->mb_width) { | 2164 if (++s->mb_x >= s->mb_width) { |
2136 if(s->avctx->codec_tag == ff_get_fourcc("VCR2")) | |
2137 exchange_uv((AVFrame*)s->current_picture_ptr); | |
2138 | 2165 |
2139 ff_draw_horiz_band(s, 16*s->mb_y, 16); | 2166 ff_draw_horiz_band(s, 16*s->mb_y, 16); |
2140 | |
2141 if(s->avctx->codec_tag == ff_get_fourcc("VCR2")) | |
2142 exchange_uv((AVFrame*)s->current_picture_ptr); | |
2143 | 2167 |
2144 s->mb_x = 0; | 2168 s->mb_x = 0; |
2145 s->mb_y++; | 2169 s->mb_y++; |
2146 | 2170 |
2147 if(s->mb_y<<field_pic >= s->mb_height){ | 2171 if(s->mb_y<<field_pic >= s->mb_height){ |
2231 if (s->last_picture_ptr != NULL) { | 2255 if (s->last_picture_ptr != NULL) { |
2232 *pict= *(AVFrame*)s->last_picture_ptr; | 2256 *pict= *(AVFrame*)s->last_picture_ptr; |
2233 ff_print_debug_info(s, s->last_picture_ptr); | 2257 ff_print_debug_info(s, s->last_picture_ptr); |
2234 } | 2258 } |
2235 } | 2259 } |
2236 if(s->avctx->codec_tag == ff_get_fourcc("VCR2")) | |
2237 exchange_uv(pict); | |
2238 | 2260 |
2239 return 1; | 2261 return 1; |
2240 } else { | 2262 } else { |
2241 return 0; | 2263 return 0; |
2242 } | 2264 } |
2292 avctx->bit_rate = s->bit_rate; | 2314 avctx->bit_rate = s->bit_rate; |
2293 | 2315 |
2294 //get_format() or set_video(width,height,aspect,pix_fmt); | 2316 //get_format() or set_video(width,height,aspect,pix_fmt); |
2295 //until then pix_fmt may be changed right after codec init | 2317 //until then pix_fmt may be changed right after codec init |
2296 if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT ) | 2318 if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT ) |
2297 avctx->idct_algo = FF_IDCT_SIMPLE; | 2319 if( avctx->idct_algo == FF_IDCT_AUTO ) |
2320 avctx->idct_algo = FF_IDCT_SIMPLE; | |
2298 | 2321 |
2299 if (MPV_common_init(s) < 0) | 2322 if (MPV_common_init(s) < 0) |
2300 return -1; | 2323 return -1; |
2301 s1->mpeg_enc_ctx_allocated = 1; | 2324 s1->mpeg_enc_ctx_allocated = 1; |
2325 s->swap_uv = 0;//just in case vcr2 and mpeg2 stream have been concatinated | |
2302 } | 2326 } |
2303 | 2327 |
2304 skip_bits(&s->gb, 10); /* vbv_buffer_size */ | 2328 skip_bits(&s->gb, 10); /* vbv_buffer_size */ |
2305 skip_bits(&s->gb, 1); | 2329 skip_bits(&s->gb, 1); |
2306 | 2330 |
2376 s->avctx = avctx; | 2400 s->avctx = avctx; |
2377 | 2401 |
2378 //get_format() or set_video(width,height,aspect,pix_fmt); | 2402 //get_format() or set_video(width,height,aspect,pix_fmt); |
2379 //until then pix_fmt may be changed right after codec init | 2403 //until then pix_fmt may be changed right after codec init |
2380 if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT ) | 2404 if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT ) |
2381 avctx->idct_algo = FF_IDCT_SIMPLE; | 2405 if( avctx->idct_algo == FF_IDCT_AUTO ) |
2406 avctx->idct_algo = FF_IDCT_SIMPLE; | |
2382 | 2407 |
2383 if (MPV_common_init(s) < 0) | 2408 if (MPV_common_init(s) < 0) |
2384 return -1; | 2409 return -1; |
2410 exchange_uv(s);//common init reset pblocks, so we swap them here | |
2411 s->swap_uv = 1;// in case of xvmc we need to swap uv for each MB | |
2385 s1->mpeg_enc_ctx_allocated = 1; | 2412 s1->mpeg_enc_ctx_allocated = 1; |
2386 | 2413 |
2387 for(i=0;i<64;i++) { | 2414 for(i=0;i<64;i++) { |
2388 int j= s->dsp.idct_permutation[i]; | 2415 int j= s->dsp.idct_permutation[i]; |
2389 v = ff_mpeg1_default_intra_matrix[i]; | 2416 v = ff_mpeg1_default_intra_matrix[i]; |
2632 static int mpeg_mc_decode_init(AVCodecContext *avctx){ | 2659 static int mpeg_mc_decode_init(AVCodecContext *avctx){ |
2633 Mpeg1Context *s; | 2660 Mpeg1Context *s; |
2634 | 2661 |
2635 if( !(avctx->slice_flags & SLICE_FLAG_CODED_ORDER) ) | 2662 if( !(avctx->slice_flags & SLICE_FLAG_CODED_ORDER) ) |
2636 return -1; | 2663 return -1; |
2637 if( !(avctx->slice_flags & SLICE_FLAG_ALLOW_FIELD) ) | 2664 if( !(avctx->slice_flags & SLICE_FLAG_ALLOW_FIELD) ){ |
2638 dprintf("mpeg12.c: XvMC decoder will work better if SLICE_FLAG_ALLOW_FIELD is set\n"); | 2665 dprintf("mpeg12.c: XvMC decoder will work better if SLICE_FLAG_ALLOW_FIELD is set\n"); |
2639 | 2666 } |
2640 mpeg_decode_init(avctx); | 2667 mpeg_decode_init(avctx); |
2641 s = avctx->priv_data; | 2668 s = avctx->priv_data; |
2642 | 2669 |
2643 avctx->pix_fmt = PIX_FMT_XVMC_MPEG2_IDCT; | 2670 avctx->pix_fmt = PIX_FMT_XVMC_MPEG2_IDCT; |
2644 avctx->xvmc_acceleration = 1; | 2671 avctx->xvmc_acceleration = 2;//2 - the blocks are packed! |
2645 | 2672 |
2646 return 0; | 2673 return 0; |
2647 } | 2674 } |
2648 | 2675 |
2649 AVCodec mpeg_xvmc_decoder = { | 2676 AVCodec mpeg_xvmc_decoder = { |