comparison libmpcodecs/vd_ffmpeg.c @ 11420:b99147bd6cce

Support for paletted codecs in ffmpeg Support buffer hints from ffmpeg codecs Support ffmpeg image formats bgr24, rgb555, pal8
author rtognimp
date Sun, 09 Nov 2003 23:55:28 +0000
parents 8770be0a5bb5
children 568efdc13e60
comparison
equal deleted inserted replaced
11419:d43c2028c00a 11420:b99147bd6cce
179 ctx->pic = avcodec_alloc_picture(); 179 ctx->pic = avcodec_alloc_picture();
180 #endif 180 #endif
181 ctx->avctx = avcodec_alloc_context(); 181 ctx->avctx = avcodec_alloc_context();
182 avctx = ctx->avctx; 182 avctx = ctx->avctx;
183 183
184 #if LIBAVCODEC_BUILD >= 4691
185 if(lavc_codec->capabilities&CODEC_CAP_CR)
186 avctx->cr_available = 1;
187 #endif
188
184 #ifdef HAVE_XVMC 189 #ifdef HAVE_XVMC
185 if(lavc_codec->id == CODEC_ID_MPEG2VIDEO_XVMC){ 190 if(lavc_codec->id == CODEC_ID_MPEG2VIDEO_XVMC){
186 printf("vd_ffmpeg: XVMC accelerated MPEG2\n"); 191 printf("vd_ffmpeg: XVMC accelerated MPEG2\n");
187 assert(ctx->do_dr1);//these are must to! 192 assert(ctx->do_dr1);//these are must to!
188 assert(ctx->do_slices); //it is (vo_)ffmpeg bug if this fails 193 assert(ctx->do_slices); //it is (vo_)ffmpeg bug if this fails
274 { 279 {
275 avctx->extradata_size = sh->bih->biSize-sizeof(BITMAPINFOHEADER); 280 avctx->extradata_size = sh->bih->biSize-sizeof(BITMAPINFOHEADER);
276 avctx->extradata = malloc(avctx->extradata_size); 281 avctx->extradata = malloc(avctx->extradata_size);
277 memcpy(avctx->extradata, sh->bih+1, avctx->extradata_size); 282 memcpy(avctx->extradata, sh->bih+1, avctx->extradata_size);
278 } 283 }
284 /* Pass palette to codec */
285 #if LIBAVCODEC_BUILD >= 4689
286 if (sh->bih && (sh->bih->biBitCount <= 8)) {
287 avctx->palctrl = (AVPaletteControl*)calloc(1,sizeof(AVPaletteControl));
288 avctx->palctrl->palette_changed = 1;
289 if (sh->bih->biSize-sizeof(BITMAPINFOHEADER))
290 /* Palette size in biSize */
291 memcpy(avctx->palctrl->palette, sh->bih+1,
292 min(sh->bih->biSize-sizeof(BITMAPINFOHEADER), AVPALETTE_SIZE));
293 else
294 /* Palette size in biClrUsed */
295 memcpy(avctx->palctrl->palette, sh->bih+1,
296 min(sh->bih->biClrUsed * 4, AVPALETTE_SIZE));
297 }
298 #endif
279 if (sh->ImageDesc && 299 if (sh->ImageDesc &&
280 sh->format == mmioFOURCC('S','V','Q','3')){ 300 sh->format == mmioFOURCC('S','V','Q','3')){
281 avctx->extradata_size = *(int*)sh->ImageDesc; 301 avctx->extradata_size = *(int*)sh->ImageDesc;
282 avctx->extradata = malloc(avctx->extradata_size); 302 avctx->extradata = malloc(avctx->extradata_size);
283 memcpy(avctx->extradata, ((int*)sh->ImageDesc)+1, avctx->extradata_size); 303 memcpy(avctx->extradata, ((int*)sh->ImageDesc)+1, avctx->extradata_size);
316 mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantCloseCodec); 336 mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantCloseCodec);
317 337
318 if (avctx->extradata_size) 338 if (avctx->extradata_size)
319 free(avctx->extradata); 339 free(avctx->extradata);
320 avctx->extradata=NULL; 340 avctx->extradata=NULL;
341 if (avctx->palctrl)
342 free(avctx->palctrl);
343 avctx->palctrl=NULL;
321 if(avctx->slice_offset!=NULL) 344 if(avctx->slice_offset!=NULL)
322 free(avctx->slice_offset); 345 free(avctx->slice_offset);
323 avctx->slice_offset=NULL; 346 avctx->slice_offset=NULL;
324 347
325 if (avctx) 348 if (avctx)
411 case PIX_FMT_YUV444P: ctx->best_csp=IMGFMT_444P;break; //photo jpeg 434 case PIX_FMT_YUV444P: ctx->best_csp=IMGFMT_444P;break; //photo jpeg
412 case PIX_FMT_YUV411P: ctx->best_csp=IMGFMT_411P;break; //dv ntsc 435 case PIX_FMT_YUV411P: ctx->best_csp=IMGFMT_411P;break; //dv ntsc
413 case PIX_FMT_YUV422: ctx->best_csp=IMGFMT_YUY2;break; //huffyuv perhaps in the future 436 case PIX_FMT_YUV422: ctx->best_csp=IMGFMT_YUY2;break; //huffyuv perhaps in the future
414 case PIX_FMT_RGB24 : ctx->best_csp=IMGFMT_BGR24;break; //huffyuv 437 case PIX_FMT_RGB24 : ctx->best_csp=IMGFMT_BGR24;break; //huffyuv
415 case PIX_FMT_RGBA32: ctx->best_csp=IMGFMT_BGR32;break; //huffyuv / mjpeg 438 case PIX_FMT_RGBA32: ctx->best_csp=IMGFMT_BGR32;break; //huffyuv / mjpeg
439 case PIX_FMT_BGR24 : ctx->best_csp=IMGFMT_BGR24;break; //8bps
440 case PIX_FMT_RGB555: ctx->best_csp=IMGFMT_BGR15;break; //rpza,cram
441 case PIX_FMT_PAL8: ctx->best_csp=IMGFMT_BGR8;break; //8bps,mrle,cram
416 #ifdef HAVE_XVMC 442 #ifdef HAVE_XVMC
417 case PIX_FMT_XVMC_MPEG2_MC:ctx->best_csp=IMGFMT_XVMC_MOCO_MPEG2;break; 443 case PIX_FMT_XVMC_MPEG2_MC:ctx->best_csp=IMGFMT_XVMC_MOCO_MPEG2;break;
418 case PIX_FMT_XVMC_MPEG2_IDCT:ctx->best_csp=IMGFMT_XVMC_IDCT_MPEG2;break; 444 case PIX_FMT_XVMC_MPEG2_IDCT:ctx->best_csp=IMGFMT_XVMC_IDCT_MPEG2;break;
419 #endif 445 #endif
420 default: 446 default:
421 ctx->best_csp=0; 447 ctx->best_csp=0;
422 } 448 }
423
424 if (!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h, ctx->best_csp)) 449 if (!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h, ctx->best_csp))
425 return -1; 450 return -1;
426 } 451 }
427 return 0; 452 return 0;
428 } 453 }
438 int align=15; 463 int align=15;
439 //printf("get_buffer %d %d %d\n", pic->reference, ctx->ip_count, ctx->b_count); 464 //printf("get_buffer %d %d %d\n", pic->reference, ctx->ip_count, ctx->b_count);
440 if(avctx->pix_fmt == PIX_FMT_YUV410P) 465 if(avctx->pix_fmt == PIX_FMT_YUV410P)
441 align=63; //yes seriously, its really needed (16x16 chroma blocks in SVQ1 -> 64x64) 466 align=63; //yes seriously, its really needed (16x16 chroma blocks in SVQ1 -> 64x64)
442 467
468 #if LIBAVCODEC_BUILD >= 4691
469 if (pic->buffer_hints) {
470 mp_msg(MSGT_DECVIDEO,MSGL_DBG2, "Buffer hints: %u\n", pic->buffer_hints);
471 type = MP_IMGTYPE_TEMP;
472 if (pic->buffer_hints & FF_BUFFER_HINTS_READABLE)
473 flags |= MP_IMGFLAG_READABLE;
474 if (pic->buffer_hints & FF_BUFFER_HINTS_PRESERVE) {
475 type = MP_IMGTYPE_STATIC;
476 flags |= MP_IMGFLAG_PRESERVE;
477 }
478 if (pic->buffer_hints & FF_BUFFER_HINTS_REUSABLE) {
479 type = MP_IMGTYPE_STATIC;
480 flags |= MP_IMGFLAG_PRESERVE;
481 }
482 flags|=(!avctx->hurry_up && ctx->do_slices) ?
483 MP_IMGFLAG_DRAW_CALLBACK:0;
484 mp_msg(MSGT_DECVIDEO,MSGL_DBG2, type == MP_IMGTYPE_STATIC ? "using STATIC\n" : "using TEMP\n");
485 } else {
486 #endif
443 if(!pic->reference){ 487 if(!pic->reference){
444 ctx->b_count++; 488 ctx->b_count++;
445 flags|=(!avctx->hurry_up && ctx->do_slices) ? 489 flags|=(!avctx->hurry_up && ctx->do_slices) ?
446 MP_IMGFLAG_DRAW_CALLBACK:0; 490 MP_IMGFLAG_DRAW_CALLBACK:0;
447 }else{ 491 }else{
448 ctx->ip_count++; 492 ctx->ip_count++;
449 flags|= MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE 493 flags|= MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE
450 | (ctx->do_slices ? MP_IMGFLAG_DRAW_CALLBACK : 0); 494 | (ctx->do_slices ? MP_IMGFLAG_DRAW_CALLBACK : 0);
451 } 495 }
496 #if LIBAVCODEC_BUILD >= 4691
497 }
498 #endif
452 499
453 if(init_vo(sh)<0){ 500 if(init_vo(sh)<0){
454 avctx->release_buffer= avcodec_default_release_buffer; 501 avctx->release_buffer= avcodec_default_release_buffer;
455 avctx->get_buffer= avcodec_default_get_buffer; 502 avctx->get_buffer= avcodec_default_get_buffer;
456 return avctx->get_buffer(avctx, pic); 503 return avctx->get_buffer(avctx, pic);
457 } 504 }
458 505
506 #if LIBAVCODEC_BUILD >= 4691
507 if (!pic->buffer_hints) {
508 #endif
459 if(ctx->b_count>1 || ctx->ip_count>2){ 509 if(ctx->b_count>1 || ctx->ip_count>2){
460 printf("DR1 failure\n"); 510 printf("DR1 failure\n");
461 511
462 ctx->do_dr1=0; //FIXME 512 ctx->do_dr1=0; //FIXME
463 avctx->get_buffer= avcodec_default_get_buffer; 513 avctx->get_buffer= avcodec_default_get_buffer;
468 type= MP_IMGTYPE_IPB; 518 type= MP_IMGTYPE_IPB;
469 }else{ 519 }else{
470 type= MP_IMGTYPE_IP; 520 type= MP_IMGTYPE_IP;
471 } 521 }
472 mp_msg(MSGT_DECVIDEO,MSGL_DBG2, type== MP_IMGTYPE_IPB ? "using IPB\n" : "using IP\n"); 522 mp_msg(MSGT_DECVIDEO,MSGL_DBG2, type== MP_IMGTYPE_IPB ? "using IPB\n" : "using IP\n");
523 #if LIBAVCODEC_BUILD >= 4691
524 }
525 #endif
473 526
474 mpi= mpcodecs_get_image(sh,type, flags, 527 mpi= mpcodecs_get_image(sh,type, flags,
475 (width+align)&(~align), (height+align)&(~align)); 528 (width+align)&(~align), (height+align)&(~align));
476 529
477 // ok, let's see what did we get: 530 // ok, let's see what did we get:
479 !(mpi->flags&MP_IMGFLAG_DIRECT)){ 532 !(mpi->flags&MP_IMGFLAG_DIRECT)){
480 // nice, filter/vo likes draw_callback :) 533 // nice, filter/vo likes draw_callback :)
481 avctx->draw_horiz_band= draw_slice; 534 avctx->draw_horiz_band= draw_slice;
482 } else 535 } else
483 avctx->draw_horiz_band= NULL; 536 avctx->draw_horiz_band= NULL;
537
538 // Palette support: libavcodec copies palette to *data[1]
539 if (mpi->bpp == 8)
540 mpi->planes[1] = malloc(AVPALETTE_SIZE);
541
484 pic->data[0]= mpi->planes[0]; 542 pic->data[0]= mpi->planes[0];
485 pic->data[1]= mpi->planes[1]; 543 pic->data[1]= mpi->planes[1];
486 pic->data[2]= mpi->planes[2]; 544 pic->data[2]= mpi->planes[2];
487 545
488 #if 0 546 #if 0
550 if(mpi->flags&MP_IMGFLAG_PRESERVE) 608 if(mpi->flags&MP_IMGFLAG_PRESERVE)
551 ctx->ip_count--; 609 ctx->ip_count--;
552 else 610 else
553 ctx->b_count--; 611 ctx->b_count--;
554 } 612 }
613
614 // Palette support: free palette buffer allocated in get_buffer
615 if ((mpi->bpp == 8) && (mpi->planes[1] != NULL))
616 free(mpi->planes[1]);
617
555 #if LIBAVCODEC_BUILD >= 4644 618 #if LIBAVCODEC_BUILD >= 4644
556 if(pic->type!=FF_BUFFER_TYPE_USER){ 619 if(pic->type!=FF_BUFFER_TYPE_USER){
557 avcodec_default_release_buffer(avctx, pic); 620 avcodec_default_release_buffer(avctx, pic);
558 return; 621 return;
559 } 622 }