comparison libmpcodecs/vd_ffmpeg.c @ 28525:1e671b7bf2e0

Consistently place whitespace around * ( ) and ,
author reimar
date Sat, 14 Feb 2009 17:43:06 +0000
parents 3e0ccf5f272e
children 90da3cbfbdd9
comparison
equal deleted inserted replaced
28524:3e0ccf5f272e 28525:1e671b7bf2e0
54 54
55 static int get_buffer(AVCodecContext *avctx, AVFrame *pic); 55 static int get_buffer(AVCodecContext *avctx, AVFrame *pic);
56 static void release_buffer(AVCodecContext *avctx, AVFrame *pic); 56 static void release_buffer(AVCodecContext *avctx, AVFrame *pic);
57 57
58 #if CONFIG_XVMC 58 #if CONFIG_XVMC
59 static enum PixelFormat get_format(struct AVCodecContext * avctx, 59 static enum PixelFormat get_format(struct AVCodecContext *avctx,
60 const enum PixelFormat * pix_fmt); 60 const enum PixelFormat *pix_fmt);
61 static int mc_get_buffer(AVCodecContext *avctx, AVFrame *pic); 61 static int mc_get_buffer(AVCodecContext *avctx, AVFrame *pic);
62 static void mc_release_buffer(AVCodecContext *avctx, AVFrame *pic); 62 static void mc_release_buffer(AVCodecContext *avctx, AVFrame *pic);
63 static void mc_render_slice(struct AVCodecContext *s, 63 static void mc_render_slice(struct AVCodecContext *s,
64 AVFrame *src, int offset[4], 64 AVFrame *src, int offset[4],
65 int y, int type, int height); 65 int y, int type, int height);
118 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Unknown discard value %s\n", str); 118 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Unknown discard value %s\n", str);
119 return AVDISCARD_DEFAULT; 119 return AVDISCARD_DEFAULT;
120 } 120 }
121 121
122 // to set/get/query special features/parameters 122 // to set/get/query special features/parameters
123 static int control(sh_video_t *sh,int cmd,void* arg,...){ 123 static int control(sh_video_t *sh, int cmd, void *arg, ...){
124 vd_ffmpeg_ctx *ctx = sh->context; 124 vd_ffmpeg_ctx *ctx = sh->context;
125 AVCodecContext *avctx = ctx->avctx; 125 AVCodecContext *avctx = ctx->avctx;
126 switch(cmd){ 126 switch(cmd){
127 case VDCTRL_QUERY_FORMAT: 127 case VDCTRL_QUERY_FORMAT:
128 { 128 {
129 int format =(*((int*)arg)); 129 int format =(*((int *)arg));
130 if( format == ctx->best_csp ) return CONTROL_TRUE;//supported 130 if(format == ctx->best_csp) return CONTROL_TRUE;//supported
131 // possible conversions: 131 // possible conversions:
132 switch( format ){ 132 switch(format){
133 case IMGFMT_YV12: 133 case IMGFMT_YV12:
134 case IMGFMT_IYUV: 134 case IMGFMT_IYUV:
135 case IMGFMT_I420: 135 case IMGFMT_I420:
136 // "converted" using pointer/stride modification 136 // "converted" using pointer/stride modification
137 if(avctx->pix_fmt==PIX_FMT_YUV420P) return CONTROL_TRUE;// u/v swap 137 if(avctx->pix_fmt==PIX_FMT_YUV420P) return CONTROL_TRUE;// u/v swap
152 return avctx->has_b_frames + 10; 152 return avctx->has_b_frames + 10;
153 } 153 }
154 return CONTROL_UNKNOWN; 154 return CONTROL_UNKNOWN;
155 } 155 }
156 156
157 void mp_msp_av_log_callback(void* ptr, int level, const char* fmt, va_list vl) 157 void mp_msp_av_log_callback(void *ptr, int level, const char *fmt, va_list vl)
158 { 158 {
159 static int print_prefix=1; 159 static int print_prefix=1;
160 AVClass* avc= ptr ? *(AVClass**)ptr : NULL; 160 AVClass *avc= ptr ? *(AVClass **)ptr : NULL;
161 int type= MSGT_FIXME; 161 int type= MSGT_FIXME;
162 int mp_level; 162 int mp_level;
163 char buf[256]; 163 char buf[256];
164 164
165 switch(level){ 165 switch(level){
171 171
172 if (!mp_msg_test(type, mp_level)) return; 172 if (!mp_msg_test(type, mp_level)) return;
173 173
174 if(ptr){ 174 if(ptr){
175 if(!strcmp(avc->class_name, "AVCodecContext")){ 175 if(!strcmp(avc->class_name, "AVCodecContext")){
176 AVCodecContext * s= ptr; 176 AVCodecContext *s= ptr;
177 if(s->codec){ 177 if(s->codec){
178 if(s->codec->type == CODEC_TYPE_AUDIO){ 178 if(s->codec->type == CODEC_TYPE_AUDIO){
179 if(s->codec->decode) 179 if(s->codec->decode)
180 type= MSGT_DECAUDIO; 180 type= MSGT_DECAUDIO;
181 }else if(s->codec->type == CODEC_TYPE_VIDEO){ 181 }else if(s->codec->type == CODEC_TYPE_VIDEO){
183 type= MSGT_DECVIDEO; 183 type= MSGT_DECVIDEO;
184 } 184 }
185 //FIXME subtitles, encoders (what msgt for them? there is no appropriate ...) 185 //FIXME subtitles, encoders (what msgt for them? there is no appropriate ...)
186 } 186 }
187 }else if(!strcmp(avc->class_name, "AVFormatContext")){ 187 }else if(!strcmp(avc->class_name, "AVFormatContext")){
188 #if 0 //needs libavformat include FIXME iam too lazy to do this cleanly,probably the whole should be moved out of this file ... 188 #if 0 //needs libavformat include FIXME iam too lazy to do this cleanly, probably the whole should be moved out of this file ...
189 AVFormatContext * s= ptr; 189 AVFormatContext *s= ptr;
190 if(s->iformat) 190 if(s->iformat)
191 type= MSGT_DEMUXER; 191 type= MSGT_DEMUXER;
192 else if(s->oformat) 192 else if(s->oformat)
193 type= MSGT_MUXER; 193 type= MSGT_MUXER;
194 #endif 194 #endif
224 return 0; 224 return 0;
225 memset(ctx, 0, sizeof(vd_ffmpeg_ctx)); 225 memset(ctx, 0, sizeof(vd_ffmpeg_ctx));
226 226
227 lavc_codec = (AVCodec *)avcodec_find_decoder_by_name(sh->codec->dll); 227 lavc_codec = (AVCodec *)avcodec_find_decoder_by_name(sh->codec->dll);
228 if(!lavc_codec){ 228 if(!lavc_codec){
229 mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MissingLAVCcodec,sh->codec->dll); 229 mp_msg(MSGT_DECVIDEO, MSGL_ERR, MSGTR_MissingLAVCcodec, sh->codec->dll);
230 uninit(sh); 230 uninit(sh);
231 return 0; 231 return 0;
232 } 232 }
233 233
234 if(vd_use_slices && (lavc_codec->capabilities&CODEC_CAP_DRAW_HORIZ_BAND) && !do_vis_debug) 234 if(vd_use_slices && (lavc_codec->capabilities&CODEC_CAP_DRAW_HORIZ_BAND) && !do_vis_debug)
293 avctx->skip_idct = str2AVDiscard(lavc_param_skip_idct_str); 293 avctx->skip_idct = str2AVDiscard(lavc_param_skip_idct_str);
294 avctx->skip_frame = str2AVDiscard(lavc_param_skip_frame_str); 294 avctx->skip_frame = str2AVDiscard(lavc_param_skip_frame_str);
295 295
296 if(lavc_avopt){ 296 if(lavc_avopt){
297 if(parse_avopts(avctx, lavc_avopt) < 0){ 297 if(parse_avopts(avctx, lavc_avopt) < 0){
298 mp_msg(MSGT_DECVIDEO,MSGL_ERR, "Your options /%s/ look like gibberish to me pal\n", lavc_avopt); 298 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Your options /%s/ look like gibberish to me pal\n", lavc_avopt);
299 uninit(sh); 299 uninit(sh);
300 return 0; 300 return 0;
301 } 301 }
302 } 302 }
303 303
304 mp_dbg(MSGT_DECVIDEO,MSGL_DBG2,"libavcodec.size: %d x %d\n",avctx->width,avctx->height); 304 mp_dbg(MSGT_DECVIDEO, MSGL_DBG2, "libavcodec.size: %d x %d\n", avctx->width, avctx->height);
305 switch (sh->format) { 305 switch (sh->format) {
306 case mmioFOURCC('S','V','Q','3'): 306 case mmioFOURCC('S','V','Q','3'):
307 /* SVQ3 extradata can show up as sh->ImageDesc if demux_mov is used, or 307 /* SVQ3 extradata can show up as sh->ImageDesc if demux_mov is used, or
308 in the phony AVI header if demux_lavf is used. The first case is 308 in the phony AVI header if demux_lavf is used. The first case is
309 handled here; the second case falls through to the next section. */ 309 handled here; the second case falls through to the next section. */
310 if (sh->ImageDesc) { 310 if (sh->ImageDesc) {
311 avctx->extradata_size = (*(int*)sh->ImageDesc) - sizeof(int); 311 avctx->extradata_size = (*(int *)sh->ImageDesc) - sizeof(int);
312 avctx->extradata = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); 312 avctx->extradata = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
313 memcpy(avctx->extradata, ((int*)sh->ImageDesc)+1, avctx->extradata_size); 313 memcpy(avctx->extradata, ((int *)sh->ImageDesc)+1, avctx->extradata_size);
314 break; 314 break;
315 } 315 }
316 /* fallthrough */ 316 /* fallthrough */
317 317
318 case mmioFOURCC('A','V','R','n'): 318 case mmioFOURCC('A','V','R','n'):
331 { 331 {
332 int x; 332 int x;
333 uint8_t *p = avctx->extradata; 333 uint8_t *p = avctx->extradata;
334 334
335 for (x=0; x<avctx->extradata_size; x++) 335 for (x=0; x<avctx->extradata_size; x++)
336 mp_msg(MSGT_DECVIDEO, MSGL_INFO,"[%x] ", p[x]); 336 mp_msg(MSGT_DECVIDEO, MSGL_INFO, "[%x] ", p[x]);
337 mp_msg(MSGT_DECVIDEO, MSGL_INFO,"\n"); 337 mp_msg(MSGT_DECVIDEO, MSGL_INFO, "\n");
338 } 338 }
339 #endif 339 #endif
340 break; 340 break;
341 341
342 case mmioFOURCC('R', 'V', '1', '0'): 342 case mmioFOURCC('R', 'V', '1', '0'):
346 case mmioFOURCC('R', 'V', '4', '0'): 346 case mmioFOURCC('R', 'V', '4', '0'):
347 if(sh->bih->biSize<sizeof(*sh->bih)+8){ 347 if(sh->bih->biSize<sizeof(*sh->bih)+8){
348 /* only 1 packet per frame & sub_id from fourcc */ 348 /* only 1 packet per frame & sub_id from fourcc */
349 avctx->extradata_size= 8; 349 avctx->extradata_size= 8;
350 avctx->extradata = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); 350 avctx->extradata = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
351 ((uint32_t*)avctx->extradata)[0] = 0; 351 ((uint32_t *)avctx->extradata)[0] = 0;
352 ((uint32_t*)avctx->extradata)[1] = 352 ((uint32_t *)avctx->extradata)[1] =
353 (sh->format == mmioFOURCC('R', 'V', '1', '3')) ? 0x10003001 : 0x10000000; 353 (sh->format == mmioFOURCC('R', 'V', '1', '3')) ? 0x10003001 : 0x10000000;
354 } else { 354 } else {
355 /* has extra slice header (demux_rm or rm->avi streamcopy) */ 355 /* has extra slice header (demux_rm or rm->avi streamcopy) */
356 avctx->extradata_size = sh->bih->biSize-sizeof(BITMAPINFOHEADER); 356 avctx->extradata_size = sh->bih->biSize-sizeof(BITMAPINFOHEADER);
357 avctx->extradata = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); 357 avctx->extradata = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
370 memcpy(avctx->extradata, sh->bih+1, avctx->extradata_size); 370 memcpy(avctx->extradata, sh->bih+1, avctx->extradata_size);
371 break; 371 break;
372 } 372 }
373 /* Pass palette to codec */ 373 /* Pass palette to codec */
374 if (sh->bih && (sh->bih->biBitCount <= 8)) { 374 if (sh->bih && (sh->bih->biBitCount <= 8)) {
375 avctx->palctrl = calloc(1,sizeof(AVPaletteControl)); 375 avctx->palctrl = calloc(1, sizeof(AVPaletteControl));
376 avctx->palctrl->palette_changed = 1; 376 avctx->palctrl->palette_changed = 1;
377 if (sh->bih->biSize-sizeof(BITMAPINFOHEADER)) 377 if (sh->bih->biSize-sizeof(BITMAPINFOHEADER))
378 /* Palette size in biSize */ 378 /* Palette size in biSize */
379 memcpy(avctx->palctrl->palette, sh->bih+1, 379 memcpy(avctx->palctrl->palette, sh->bih+1,
380 FFMIN(sh->bih->biSize-sizeof(BITMAPINFOHEADER), AVPALETTE_SIZE)); 380 FFMIN(sh->bih->biSize-sizeof(BITMAPINFOHEADER), AVPALETTE_SIZE));
389 389
390 if(lavc_param_threads > 1) 390 if(lavc_param_threads > 1)
391 avcodec_thread_init(avctx, lavc_param_threads); 391 avcodec_thread_init(avctx, lavc_param_threads);
392 /* open it */ 392 /* open it */
393 if (avcodec_open(avctx, lavc_codec) < 0) { 393 if (avcodec_open(avctx, lavc_codec) < 0) {
394 mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantOpenCodec); 394 mp_msg(MSGT_DECVIDEO, MSGL_ERR, MSGTR_CantOpenCodec);
395 uninit(sh); 395 uninit(sh);
396 return 0; 396 return 0;
397 } 397 }
398 mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: libavcodec init OK!\n"); 398 mp_msg(MSGT_DECVIDEO, MSGL_V, "INFO: libavcodec init OK!\n");
399 return 1; //mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YV12); 399 return 1; //mpcodecs_config_vo(sh, sh->disp_w, sh->disp_h, IMGFMT_YV12);
400 } 400 }
401 401
402 // uninit driver 402 // uninit driver
403 static void uninit(sh_video_t *sh){ 403 static void uninit(sh_video_t *sh){
404 vd_ffmpeg_ctx *ctx = sh->context; 404 vd_ffmpeg_ctx *ctx = sh->context;
405 AVCodecContext *avctx = ctx->avctx; 405 AVCodecContext *avctx = ctx->avctx;
406 406
407 if(lavc_param_vstats){ 407 if(lavc_param_vstats){
408 int i; 408 int i;
409 for(i=1; i<32; i++){ 409 for(i=1; i<32; i++){
410 mp_msg(MSGT_DECVIDEO, MSGL_INFO,"QP: %d, count: %d\n", i, ctx->qp_stat[i]); 410 mp_msg(MSGT_DECVIDEO, MSGL_INFO, "QP: %d, count: %d\n", i, ctx->qp_stat[i]);
411 } 411 }
412 mp_msg(MSGT_DECVIDEO, MSGL_INFO,MSGTR_MPCODECS_ArithmeticMeanOfQP, 412 mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_MPCODECS_ArithmeticMeanOfQP,
413 ctx->qp_sum / avctx->coded_frame->coded_picture_number, 413 ctx->qp_sum / avctx->coded_frame->coded_picture_number,
414 1.0/(ctx->inv_qp_sum / avctx->coded_frame->coded_picture_number) 414 1.0/(ctx->inv_qp_sum / avctx->coded_frame->coded_picture_number)
415 ); 415 );
416 } 416 }
417 417
418 if (avctx) { 418 if (avctx) {
419 if (avctx->codec && avcodec_close(avctx) < 0) 419 if (avctx->codec && avcodec_close(avctx) < 0)
420 mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantCloseCodec); 420 mp_msg(MSGT_DECVIDEO, MSGL_ERR, MSGTR_CantCloseCodec);
421 421
422 av_freep(&avctx->extradata); 422 av_freep(&avctx->extradata);
423 av_freep(&avctx->palctrl); 423 av_freep(&avctx->palctrl);
424 av_freep(&avctx->slice_offset); 424 av_freep(&avctx->slice_offset);
425 } 425 }
431 } 431 }
432 432
433 static void draw_slice(struct AVCodecContext *s, 433 static void draw_slice(struct AVCodecContext *s,
434 AVFrame *src, int offset[4], 434 AVFrame *src, int offset[4],
435 int y, int type, int height){ 435 int y, int type, int height){
436 sh_video_t * sh = s->opaque; 436 sh_video_t *sh = s->opaque;
437 uint8_t *source[3]= {src->data[0] + offset[0], src->data[1] + offset[1], src->data[2] + offset[2]}; 437 uint8_t *source[3]= {src->data[0] + offset[0], src->data[1] + offset[1], src->data[2] + offset[2]};
438 #if 0 438 #if 0
439 int start=0, i; 439 int start=0, i;
440 int width= s->width; 440 int width= s->width;
441 int skip_stride= ((width<<lavc_param_lowres)+15)>>4; 441 int skip_stride= ((width<<lavc_param_lowres)+15)>>4;
448 else{ 448 else{
449 uint8_t *src2[3]= {src[0] + start*16, 449 uint8_t *src2[3]= {src[0] + start*16,
450 src[1] + start*8, 450 src[1] + start*8,
451 src[2] + start*8}; 451 src[2] + start*8};
452 //printf("%2d-%2d x %d\n", start, i, y); 452 //printf("%2d-%2d x %d\n", start, i, y);
453 mpcodecs_draw_slice (sh,src2, stride, (i-start)*16, height, start*16, y); 453 mpcodecs_draw_slice (sh, src2, stride, (i-start)*16, height, start*16, y);
454 start= i+1; 454 start= i+1;
455 } 455 }
456 } 456 }
457 } 457 }
458 }else 458 }else
522 case PIX_FMT_XVMC_MPEG2_IDCT:ctx->best_csp=IMGFMT_XVMC_IDCT_MPEG2;break; 522 case PIX_FMT_XVMC_MPEG2_IDCT:ctx->best_csp=IMGFMT_XVMC_IDCT_MPEG2;break;
523 #endif 523 #endif
524 default: 524 default:
525 ctx->best_csp=0; 525 ctx->best_csp=0;
526 } 526 }
527 if (!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h, ctx->best_csp)) 527 if (!mpcodecs_config_vo(sh, sh->disp_w, sh->disp_h, ctx->best_csp))
528 return -1; 528 return -1;
529 ctx->vo_initialized = 1; 529 ctx->vo_initialized = 1;
530 } 530 }
531 return 0; 531 return 0;
532 } 532 }
533 533
534 static int get_buffer(AVCodecContext *avctx, AVFrame *pic){ 534 static int get_buffer(AVCodecContext *avctx, AVFrame *pic){
535 sh_video_t * sh = avctx->opaque; 535 sh_video_t *sh = avctx->opaque;
536 vd_ffmpeg_ctx *ctx = sh->context; 536 vd_ffmpeg_ctx *ctx = sh->context;
537 mp_image_t* mpi=NULL; 537 mp_image_t *mpi=NULL;
538 int flags= MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE; 538 int flags= MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE;
539 int type= MP_IMGTYPE_IPB; 539 int type= MP_IMGTYPE_IPB;
540 int width= avctx->width; 540 int width= avctx->width;
541 int height= avctx->height; 541 int height= avctx->height;
542 int align=15; 542 int align=15;
543 //printf("get_buffer %d %d %d\n", pic->reference, ctx->ip_count, ctx->b_count); 543 //printf("get_buffer %d %d %d\n", pic->reference, ctx->ip_count, ctx->b_count);
544 if(avctx->pix_fmt == PIX_FMT_YUV410P) 544 if(avctx->pix_fmt == PIX_FMT_YUV410P)
545 align=63; //yes seriously, its really needed (16x16 chroma blocks in SVQ1 -> 64x64) 545 align=63; //yes seriously, its really needed (16x16 chroma blocks in SVQ1 -> 64x64)
546 546
547 if (pic->buffer_hints) { 547 if (pic->buffer_hints) {
548 mp_msg(MSGT_DECVIDEO,MSGL_DBG2, "Buffer hints: %u\n", pic->buffer_hints); 548 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "Buffer hints: %u\n", pic->buffer_hints);
549 type = MP_IMGTYPE_TEMP; 549 type = MP_IMGTYPE_TEMP;
550 if (pic->buffer_hints & FF_BUFFER_HINTS_READABLE) 550 if (pic->buffer_hints & FF_BUFFER_HINTS_READABLE)
551 flags |= MP_IMGFLAG_READABLE; 551 flags |= MP_IMGFLAG_READABLE;
552 if (pic->buffer_hints & FF_BUFFER_HINTS_PRESERVE) { 552 if (pic->buffer_hints & FF_BUFFER_HINTS_PRESERVE) {
553 type = MP_IMGTYPE_STATIC; 553 type = MP_IMGTYPE_STATIC;
557 type = MP_IMGTYPE_STATIC; 557 type = MP_IMGTYPE_STATIC;
558 flags |= MP_IMGFLAG_PRESERVE; 558 flags |= MP_IMGFLAG_PRESERVE;
559 } 559 }
560 flags|=(!avctx->hurry_up && ctx->do_slices) ? 560 flags|=(!avctx->hurry_up && ctx->do_slices) ?
561 MP_IMGFLAG_DRAW_CALLBACK:0; 561 MP_IMGFLAG_DRAW_CALLBACK:0;
562 mp_msg(MSGT_DECVIDEO,MSGL_DBG2, type == MP_IMGTYPE_STATIC ? "using STATIC\n" : "using TEMP\n"); 562 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, type == MP_IMGTYPE_STATIC ? "using STATIC\n" : "using TEMP\n");
563 } else { 563 } else {
564 if(!pic->reference){ 564 if(!pic->reference){
565 ctx->b_count++; 565 ctx->b_count++;
566 flags|=(!avctx->hurry_up && ctx->do_slices) ? 566 flags|=(!avctx->hurry_up && ctx->do_slices) ?
567 MP_IMGFLAG_DRAW_CALLBACK:0; 567 MP_IMGFLAG_DRAW_CALLBACK:0;
570 flags|= MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE 570 flags|= MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE
571 | (ctx->do_slices ? MP_IMGFLAG_DRAW_CALLBACK : 0); 571 | (ctx->do_slices ? MP_IMGFLAG_DRAW_CALLBACK : 0);
572 } 572 }
573 } 573 }
574 574
575 if(init_vo(sh,avctx->pix_fmt) < 0){ 575 if(init_vo(sh, avctx->pix_fmt) < 0){
576 avctx->release_buffer= avcodec_default_release_buffer; 576 avctx->release_buffer= avcodec_default_release_buffer;
577 avctx->get_buffer= avcodec_default_get_buffer; 577 avctx->get_buffer= avcodec_default_get_buffer;
578 return avctx->get_buffer(avctx, pic); 578 return avctx->get_buffer(avctx, pic);
579 } 579 }
580 580
590 if(avctx->has_b_frames){ 590 if(avctx->has_b_frames){
591 type= MP_IMGTYPE_IPB; 591 type= MP_IMGTYPE_IPB;
592 }else{ 592 }else{
593 type= MP_IMGTYPE_IP; 593 type= MP_IMGTYPE_IP;
594 } 594 }
595 mp_msg(MSGT_DECVIDEO,MSGL_DBG2, type== MP_IMGTYPE_IPB ? "using IPB\n" : "using IP\n"); 595 mp_msg(MSGT_DECVIDEO, MSGL_DBG2, type== MP_IMGTYPE_IPB ? "using IPB\n" : "using IP\n");
596 } 596 }
597 597
598 mpi= mpcodecs_get_image(sh,type, flags, 598 mpi= mpcodecs_get_image(sh, type, flags,
599 (width+align)&(~align), (height+align)&(~align)); 599 (width+align)&(~align), (height+align)&(~align));
600 600
601 // ok, let's see what did we get: 601 // ok, let's see what did we get:
602 if( mpi->flags&MP_IMGFLAG_DRAW_CALLBACK && 602 if(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK &&
603 !(mpi->flags&MP_IMGFLAG_DIRECT)){ 603 !(mpi->flags&MP_IMGFLAG_DIRECT)){
604 // nice, filter/vo likes draw_callback :) 604 // nice, filter/vo likes draw_callback :)
605 avctx->draw_horiz_band= draw_slice; 605 avctx->draw_horiz_band= draw_slice;
606 } else 606 } else
607 avctx->draw_horiz_band= NULL; 607 avctx->draw_horiz_band= NULL;
664 pic->type= FF_BUFFER_TYPE_USER; 664 pic->type= FF_BUFFER_TYPE_USER;
665 return 0; 665 return 0;
666 } 666 }
667 667
668 static void release_buffer(struct AVCodecContext *avctx, AVFrame *pic){ 668 static void release_buffer(struct AVCodecContext *avctx, AVFrame *pic){
669 mp_image_t* mpi= pic->opaque; 669 mp_image_t *mpi= pic->opaque;
670 sh_video_t * sh = avctx->opaque; 670 sh_video_t *sh = avctx->opaque;
671 vd_ffmpeg_ctx *ctx = sh->context; 671 vd_ffmpeg_ctx *ctx = sh->context;
672 int i; 672 int i;
673 673
674 //printf("release buffer %d %d %d\n", mpi ? mpi->flags&MP_IMGFLAG_PRESERVE : -99, ctx->ip_count, ctx->b_count); 674 //printf("release buffer %d %d %d\n", mpi ? mpi->flags&MP_IMGFLAG_PRESERVE : -99, ctx->ip_count, ctx->b_count);
675 675
710 for (i = 0; i < AVPALETTE_COUNT; i++) 710 for (i = 0; i < AVPALETTE_COUNT; i++)
711 p[i] = le2me_32(p[i]); 711 p[i] = le2me_32(p[i]);
712 } 712 }
713 713
714 // decode a frame 714 // decode a frame
715 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ 715 static mp_image_t *decode(sh_video_t *sh, void *data, int len, int flags){
716 int got_picture=0; 716 int got_picture=0;
717 int ret; 717 int ret;
718 vd_ffmpeg_ctx *ctx = sh->context; 718 vd_ffmpeg_ctx *ctx = sh->context;
719 AVFrame *pic= ctx->pic; 719 AVFrame *pic= ctx->pic;
720 AVCodecContext *avctx = ctx->avctx; 720 AVCodecContext *avctx = ctx->avctx;
721 mp_image_t* mpi=NULL; 721 mp_image_t *mpi=NULL;
722 int dr1= ctx->do_dr1; 722 int dr1= ctx->do_dr1;
723 723
724 if(len<=0) return NULL; // skipped frame 724 if(len<=0) return NULL; // skipped frame
725 725
726 //ffmpeg interlace (mpeg2) bug have been fixed. no need of -noslices 726 //ffmpeg interlace (mpeg2) bug have been fixed. no need of -noslices
743 ((int *)data)[0], ((int *)data)[1], ((int *)data)[2], ((int *)data)[3]); 743 ((int *)data)[0], ((int *)data)[1], ((int *)data)[2], ((int *)data)[3]);
744 ret = avcodec_decode_video(avctx, pic, 744 ret = avcodec_decode_video(avctx, pic,
745 &got_picture, data, len); 745 &got_picture, data, len);
746 746
747 dr1= ctx->do_dr1; 747 dr1= ctx->do_dr1;
748 if(ret<0) mp_msg(MSGT_DECVIDEO,MSGL_WARN, "Error while decoding frame!\n"); 748 if(ret<0) mp_msg(MSGT_DECVIDEO, MSGL_WARN, "Error while decoding frame!\n");
749 //printf("repeat: %d\n", pic->repeat_pict); 749 //printf("repeat: %d\n", pic->repeat_pict);
750 //-- vstats generation 750 //-- vstats generation
751 while(lavc_param_vstats){ // always one time loop 751 while(lavc_param_vstats){ // always one time loop
752 static FILE *fvstats=NULL; 752 static FILE *fvstats=NULL;
753 char filename[20]; 753 char filename[20];
762 struct tm *today; 762 struct tm *today;
763 today2 = time(NULL); 763 today2 = time(NULL);
764 today = localtime(&today2); 764 today = localtime(&today2);
765 sprintf(filename, "vstats_%02d%02d%02d.log", today->tm_hour, 765 sprintf(filename, "vstats_%02d%02d%02d.log", today->tm_hour,
766 today->tm_min, today->tm_sec); 766 today->tm_min, today->tm_sec);
767 fvstats = fopen(filename,"w"); 767 fvstats = fopen(filename, "w");
768 if(!fvstats) { 768 if(!fvstats) {
769 perror("fopen"); 769 perror("fopen");
770 lavc_param_vstats=0; // disable block 770 lavc_param_vstats=0; // disable block
771 break; 771 break;
772 /*exit(1);*/ 772 /*exit(1);*/
777 { 777 {
778 int x, y; 778 int x, y;
779 int w = ((avctx->width << lavc_param_lowres)+15) >> 4; 779 int w = ((avctx->width << lavc_param_lowres)+15) >> 4;
780 int h = ((avctx->height << lavc_param_lowres)+15) >> 4; 780 int h = ((avctx->height << lavc_param_lowres)+15) >> 4;
781 int8_t *q = pic->qscale_table; 781 int8_t *q = pic->qscale_table;
782 for( y = 0; y < h; y++ ) { 782 for(y = 0; y < h; y++) {
783 for( x = 0; x < w; x++ ) 783 for(x = 0; x < w; x++)
784 quality += (double)*(q+x); 784 quality += (double)*(q+x);
785 q += pic->qstride; 785 q += pic->qstride;
786 } 786 }
787 quality /= w * h; 787 quality /= w * h;
788 } 788 }
820 } 820 }
821 //-- 821 //--
822 822
823 if(!got_picture) return NULL; // skipped image 823 if(!got_picture) return NULL; // skipped image
824 824
825 if(init_vo(sh,avctx->pix_fmt) < 0) return NULL; 825 if(init_vo(sh, avctx->pix_fmt) < 0) return NULL;
826 826
827 if(dr1 && pic->opaque){ 827 if(dr1 && pic->opaque){
828 mpi= (mp_image_t*)pic->opaque; 828 mpi= (mp_image_t *)pic->opaque;
829 } 829 }
830 830
831 if(!mpi) 831 if(!mpi)
832 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, MP_IMGFLAG_PRESERVE, 832 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, MP_IMGFLAG_PRESERVE,
833 avctx->width, avctx->height); 833 avctx->width, avctx->height);
871 871
872 return mpi; 872 return mpi;
873 } 873 }
874 874
875 #if CONFIG_XVMC 875 #if CONFIG_XVMC
876 static enum PixelFormat get_format(struct AVCodecContext * avctx, 876 static enum PixelFormat get_format(struct AVCodecContext *avctx,
877 const enum PixelFormat * fmt){ 877 const enum PixelFormat *fmt){
878 sh_video_t * sh = avctx->opaque; 878 sh_video_t *sh = avctx->opaque;
879 int i; 879 int i;
880 880
881 if(avctx->xvmc_acceleration){ 881 if(avctx->xvmc_acceleration){
882 vd_ffmpeg_ctx *ctx = sh->context; 882 vd_ffmpeg_ctx *ctx = sh->context;
883 avctx->get_buffer= mc_get_buffer; 883 avctx->get_buffer= mc_get_buffer;
888 assert(ctx->do_slices); //it is (vo_)ffmpeg bug if this fails 888 assert(ctx->do_slices); //it is (vo_)ffmpeg bug if this fails
889 avctx->flags|= CODEC_FLAG_EMU_EDGE;//do i need that??!! 889 avctx->flags|= CODEC_FLAG_EMU_EDGE;//do i need that??!!
890 avctx->slice_flags=SLICE_FLAG_CODED_ORDER|SLICE_FLAG_ALLOW_FIELD; 890 avctx->slice_flags=SLICE_FLAG_CODED_ORDER|SLICE_FLAG_ALLOW_FIELD;
891 } 891 }
892 for(i=0;fmt[i]!=-1;i++){ 892 for(i=0;fmt[i]!=-1;i++){
893 mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_MPCODECS_TryingPixfmt,i); 893 mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_MPCODECS_TryingPixfmt, i);
894 if( init_vo(sh,fmt[i]) >= 0) 894 if(init_vo(sh, fmt[i]) >= 0)
895 return fmt[i]; 895 return fmt[i];
896 } 896 }
897 return fmt[0]; 897 return fmt[0];
898 } 898 }
899 899
900 static int mc_get_buffer(AVCodecContext *avctx, AVFrame *pic){ 900 static int mc_get_buffer(AVCodecContext *avctx, AVFrame *pic){
901 sh_video_t * sh = avctx->opaque; 901 sh_video_t *sh = avctx->opaque;
902 vd_ffmpeg_ctx *ctx = sh->context; 902 vd_ffmpeg_ctx *ctx = sh->context;
903 mp_image_t* mpi=NULL; 903 mp_image_t *mpi=NULL;
904 struct xvmc_render_state * render; 904 struct xvmc_render_state *render;
905 int flags= MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE| 905 int flags= MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE|
906 MP_IMGFLAG_DRAW_CALLBACK; 906 MP_IMGFLAG_DRAW_CALLBACK;
907 907
908 // printf("vd_ffmpeg::mc_get_buffer (xvmc) %d %d %d\n", pic->reference, ctx->ip_count, ctx->b_count); 908 // printf("vd_ffmpeg::mc_get_buffer (xvmc) %d %d %d\n", pic->reference, ctx->ip_count, ctx->b_count);
909 if(!avctx->xvmc_acceleration){ 909 if(!avctx->xvmc_acceleration){
912 exit(1); 912 exit(1);
913 // return -1;//!!fixme check error conditions 913 // return -1;//!!fixme check error conditions
914 } 914 }
915 assert(avctx->draw_horiz_band == mc_render_slice); 915 assert(avctx->draw_horiz_band == mc_render_slice);
916 assert(avctx->release_buffer == mc_release_buffer); 916 assert(avctx->release_buffer == mc_release_buffer);
917 if( mp_msg_test(MSGT_DECVIDEO,MSGL_DBG5) ) 917 if(mp_msg_test(MSGT_DECVIDEO, MSGL_DBG5))
918 mp_msg(MSGT_DECVIDEO, MSGL_DBG5, "vd_ffmpeg::mc_get_buffer\n"); 918 mp_msg(MSGT_DECVIDEO, MSGL_DBG5, "vd_ffmpeg::mc_get_buffer\n");
919 919
920 if(init_vo(sh,avctx->pix_fmt) < 0){ 920 if(init_vo(sh, avctx->pix_fmt) < 0){
921 mp_msg(MSGT_DECVIDEO, MSGL_WARN, MSGTR_MPCODECS_UnexpectedInitVoError); 921 mp_msg(MSGT_DECVIDEO, MSGL_WARN, MSGTR_MPCODECS_UnexpectedInitVoError);
922 exit(1); 922 exit(1);
923 // return -1;//!!fixme check error conditions 923 // return -1;//!!fixme check error conditions
924 } 924 }
925 925
930 }else{ 930 }else{
931 ctx->ip_count++; 931 ctx->ip_count++;
932 flags|= MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE; 932 flags|= MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE;
933 } 933 }
934 934
935 mpi= mpcodecs_get_image(sh, MP_IMGTYPE_IPB,flags , 935 mpi= mpcodecs_get_image(sh, MP_IMGTYPE_IPB, flags,
936 avctx->width, avctx->height); 936 avctx->width, avctx->height);
937 if(mpi==NULL){ 937 if(mpi==NULL){
938 mp_msg(MSGT_DECVIDEO, MSGL_ERR, MSGTR_MPCODECS_UnrecoverableErrorRenderBuffersNotTaken); 938 mp_msg(MSGT_DECVIDEO, MSGL_ERR, MSGTR_MPCODECS_UnrecoverableErrorRenderBuffersNotTaken);
939 assert(0); 939 assert(0);
940 exit(1); 940 exit(1);
941 // return -1;//!!fixme check error conditions in ffmpeg 941 // return -1;//!!fixme check error conditions in ffmpeg
942 }; 942 };
943 943
944 if( (mpi->flags & MP_IMGFLAG_DIRECT) == 0){ 944 if((mpi->flags & MP_IMGFLAG_DIRECT) == 0){
945 mp_msg(MSGT_DECVIDEO, MSGL_ERR, MSGTR_MPCODECS_OnlyBuffersAllocatedByVoXvmcAllowed); 945 mp_msg(MSGT_DECVIDEO, MSGL_ERR, MSGTR_MPCODECS_OnlyBuffersAllocatedByVoXvmcAllowed);
946 assert(0); 946 assert(0);
947 exit(1); 947 exit(1);
948 // return -1;//!!fixme check error conditions in ffmpeg 948 // return -1;//!!fixme check error conditions in ffmpeg
949 } 949 }
978 ctx->b_age=1; 978 ctx->b_age=1;
979 } 979 }
980 980
981 pic->type= FF_BUFFER_TYPE_USER; 981 pic->type= FF_BUFFER_TYPE_USER;
982 982
983 render=(struct xvmc_render_state*)mpi->priv;//same as data[2] 983 render=(struct xvmc_render_state *)mpi->priv;//same as data[2]
984 if( mp_msg_test(MSGT_DECVIDEO,MSGL_DBG5) ) 984 if(mp_msg_test(MSGT_DECVIDEO, MSGL_DBG5))
985 mp_msg(MSGT_DECVIDEO, MSGL_DBG5, "vd_ffmpeg::mc_get_buffer (render=%p)\n",render); 985 mp_msg(MSGT_DECVIDEO, MSGL_DBG5, "vd_ffmpeg::mc_get_buffer (render=%p)\n", render);
986 assert(render != 0); 986 assert(render != 0);
987 assert(render->magic == AV_XVMC_RENDER_MAGIC); 987 assert(render->magic == AV_XVMC_RENDER_MAGIC);
988 render->state |= AV_XVMC_STATE_PREDICTION; 988 render->state |= AV_XVMC_STATE_PREDICTION;
989 return 0; 989 return 0;
990 } 990 }
991 991
992 992
993 static void mc_release_buffer(AVCodecContext *avctx, AVFrame *pic){ 993 static void mc_release_buffer(AVCodecContext *avctx, AVFrame *pic){
994 mp_image_t* mpi= pic->opaque; 994 mp_image_t *mpi= pic->opaque;
995 sh_video_t * sh = avctx->opaque; 995 sh_video_t *sh = avctx->opaque;
996 vd_ffmpeg_ctx *ctx = sh->context; 996 vd_ffmpeg_ctx *ctx = sh->context;
997 struct xvmc_render_state * render; 997 struct xvmc_render_state *render;
998 int i; 998 int i;
999 999
1000 1000
1001 if(ctx->ip_count <= 2 && ctx->b_count<=1){ 1001 if(ctx->ip_count <= 2 && ctx->b_count<=1){
1002 if(mpi->flags&MP_IMGFLAG_PRESERVE) 1002 if(mpi->flags&MP_IMGFLAG_PRESERVE)
1005 ctx->b_count--; 1005 ctx->b_count--;
1006 } 1006 }
1007 1007
1008 //printf("R%X %X\n", pic->linesize[0], pic->data[0]); 1008 //printf("R%X %X\n", pic->linesize[0], pic->data[0]);
1009 //mark the surface as not requared for prediction 1009 //mark the surface as not requared for prediction
1010 render=(struct xvmc_render_state*)pic->data[2];//same as mpi->priv 1010 render=(struct xvmc_render_state *)pic->data[2];//same as mpi->priv
1011 if( mp_msg_test(MSGT_DECVIDEO,MSGL_DBG5) ) 1011 if(mp_msg_test(MSGT_DECVIDEO, MSGL_DBG5))
1012 mp_msg(MSGT_DECVIDEO, MSGL_DBG5, "vd_ffmpeg::mc_release_buffer (render=%p)\n",render); 1012 mp_msg(MSGT_DECVIDEO, MSGL_DBG5, "vd_ffmpeg::mc_release_buffer (render=%p)\n", render);
1013 assert(render!=NULL); 1013 assert(render!=NULL);
1014 assert(render->magic==AV_XVMC_RENDER_MAGIC); 1014 assert(render->magic==AV_XVMC_RENDER_MAGIC);
1015 render->state&=~AV_XVMC_STATE_PREDICTION; 1015 render->state&=~AV_XVMC_STATE_PREDICTION;
1016 for(i=0; i<4; i++){ 1016 for(i=0; i<4; i++){
1017 pic->data[i]= NULL; 1017 pic->data[i]= NULL;
1020 1020
1021 static void mc_render_slice(struct AVCodecContext *s, 1021 static void mc_render_slice(struct AVCodecContext *s,
1022 AVFrame *src, int offset[4], 1022 AVFrame *src, int offset[4],
1023 int y, int type, int height){ 1023 int y, int type, int height){
1024 int width= s->width; 1024 int width= s->width;
1025 sh_video_t * sh = s->opaque; 1025 sh_video_t *sh = s->opaque;
1026 uint8_t *source[3]= {src->data[0], src->data[1], src->data[2]}; 1026 uint8_t *source[3]= {src->data[0], src->data[1], src->data[2]};
1027 1027
1028 assert(src->linesize[0]==0 && src->linesize[1]==0 && src->linesize[2]==0); 1028 assert(src->linesize[0]==0 && src->linesize[1]==0 && src->linesize[2]==0);
1029 assert(offset[0]==0 && offset[1]==0 && offset[2]==0); 1029 assert(offset[0]==0 && offset[1]==0 && offset[2]==0);
1030 1030