Mercurial > mplayer.hg
comparison libmpcodecs/vd_ffmpeg.c @ 28556:85d1ab476ad5
Extend get_buffer to handle the XvMC case and remove mc_get_buffer
author | reimar |
---|---|
date | Sun, 15 Feb 2009 14:10:47 +0000 |
parents | 71232187cac5 |
children | 60aba4efaa8f |
comparison
equal
deleted
inserted
replaced
28555:71232187cac5 | 28556:85d1ab476ad5 |
---|---|
59 int y, int type, int height); | 59 int y, int type, int height); |
60 | 60 |
61 #if CONFIG_XVMC | 61 #if CONFIG_XVMC |
62 static enum PixelFormat get_format(struct AVCodecContext *avctx, | 62 static enum PixelFormat get_format(struct AVCodecContext *avctx, |
63 const enum PixelFormat *pix_fmt); | 63 const enum PixelFormat *pix_fmt); |
64 static int mc_get_buffer(AVCodecContext *avctx, AVFrame *pic); | |
65 #endif | 64 #endif |
66 | 65 |
67 static int lavc_param_workaround_bugs= FF_BUG_AUTODETECT; | 66 static int lavc_param_workaround_bugs= FF_BUG_AUTODETECT; |
68 static int lavc_param_error_resilience=2; | 67 static int lavc_param_error_resilience=2; |
69 static int lavc_param_error_concealment=3; | 68 static int lavc_param_error_concealment=3; |
248 mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_MPCODECS_XVMCAcceleratedCodec); | 247 mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_MPCODECS_XVMCAcceleratedCodec); |
249 assert(ctx->do_dr1);//these are must to! | 248 assert(ctx->do_dr1);//these are must to! |
250 assert(ctx->do_slices); //it is (vo_)ffmpeg bug if this fails | 249 assert(ctx->do_slices); //it is (vo_)ffmpeg bug if this fails |
251 avctx->flags|= CODEC_FLAG_EMU_EDGE;//do i need that??!! | 250 avctx->flags|= CODEC_FLAG_EMU_EDGE;//do i need that??!! |
252 avctx->get_format= get_format;//for now only this decoder will use it | 251 avctx->get_format= get_format;//for now only this decoder will use it |
253 avctx->get_buffer= mc_get_buffer; | 252 avctx->get_buffer= get_buffer; |
254 avctx->release_buffer= release_buffer; | 253 avctx->release_buffer= release_buffer; |
255 avctx->draw_horiz_band = draw_slice; | 254 avctx->draw_horiz_band = draw_slice; |
256 avctx->slice_flags=SLICE_FLAG_CODED_ORDER|SLICE_FLAG_ALLOW_FIELD; | 255 avctx->slice_flags=SLICE_FLAG_CODED_ORDER|SLICE_FLAG_ALLOW_FIELD; |
257 }else | 256 }else |
258 #endif /* CONFIG_XVMC */ | 257 #endif /* CONFIG_XVMC */ |
549 avctx->release_buffer= avcodec_default_release_buffer; | 548 avctx->release_buffer= avcodec_default_release_buffer; |
550 avctx->get_buffer= avcodec_default_get_buffer; | 549 avctx->get_buffer= avcodec_default_get_buffer; |
551 return avctx->get_buffer(avctx, pic); | 550 return avctx->get_buffer(avctx, pic); |
552 } | 551 } |
553 | 552 |
553 if (IMGFMT_IS_XVMC(ctx->best_csp)) { | |
554 type = MP_IMGTYPE_NUMBERED | (0xffff << 16); | |
555 } else | |
554 if (!pic->buffer_hints) { | 556 if (!pic->buffer_hints) { |
555 if(ctx->b_count>1 || ctx->ip_count>2){ | 557 if(ctx->b_count>1 || ctx->ip_count>2){ |
556 mp_msg(MSGT_DECVIDEO, MSGL_WARN, MSGTR_MPCODECS_DRIFailure); | 558 mp_msg(MSGT_DECVIDEO, MSGL_WARN, MSGTR_MPCODECS_DRIFailure); |
557 | 559 |
558 ctx->do_dr1=0; //FIXME | 560 ctx->do_dr1=0; //FIXME |
576 !(mpi->flags&MP_IMGFLAG_DIRECT)){ | 578 !(mpi->flags&MP_IMGFLAG_DIRECT)){ |
577 // nice, filter/vo likes draw_callback :) | 579 // nice, filter/vo likes draw_callback :) |
578 avctx->draw_horiz_band= draw_slice; | 580 avctx->draw_horiz_band= draw_slice; |
579 } else | 581 } else |
580 avctx->draw_horiz_band= NULL; | 582 avctx->draw_horiz_band= NULL; |
583 #if CONFIG_XVMC | |
584 if(IMGFMT_IS_XVMC(mpi->imgfmt)) { | |
585 struct xvmc_pixfmt_render *render = mpi->priv;//same as data[2] | |
586 avctx->draw_horiz_band= draw_slice; | |
587 if(!avctx->xvmc_acceleration) { | |
588 mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_MPCODECS_McGetBufferShouldWorkOnlyWithXVMC); | |
589 assert(0); | |
590 exit(1); | |
591 // return -1;//!!fixme check error conditions in ffmpeg | |
592 } | |
593 if(!(mpi->flags & MP_IMGFLAG_DIRECT)) { | |
594 mp_msg(MSGT_DECVIDEO, MSGL_ERR, MSGTR_MPCODECS_OnlyBuffersAllocatedByVoXvmcAllowed); | |
595 assert(0); | |
596 exit(1); | |
597 // return -1;//!!fixme check error conditions in ffmpeg | |
598 } | |
599 if(mp_msg_test(MSGT_DECVIDEO, MSGL_DBG5)) | |
600 mp_msg(MSGT_DECVIDEO, MSGL_DBG5, "vd_ffmpeg::get_buffer (xvmc render=%p)\n", render); | |
601 assert(render != 0); | |
602 assert(render->magic_id == AV_XVMC_RENDER_MAGIC); | |
603 render->state |= AV_XVMC_STATE_PREDICTION; | |
604 } | |
605 #endif | |
581 | 606 |
582 // Palette support: libavcodec copies palette to *data[1] | 607 // Palette support: libavcodec copies palette to *data[1] |
583 if (mpi->bpp == 8) | 608 if (mpi->bpp == 8) |
584 mpi->planes[1] = av_malloc(AVPALETTE_SIZE); | 609 mpi->planes[1] = av_malloc(AVPALETTE_SIZE); |
585 | 610 |
865 sh_video_t *sh = avctx->opaque; | 890 sh_video_t *sh = avctx->opaque; |
866 int i; | 891 int i; |
867 | 892 |
868 if(avctx->xvmc_acceleration){ | 893 if(avctx->xvmc_acceleration){ |
869 vd_ffmpeg_ctx *ctx = sh->context; | 894 vd_ffmpeg_ctx *ctx = sh->context; |
870 avctx->get_buffer= mc_get_buffer; | 895 avctx->get_buffer= get_buffer; |
871 avctx->release_buffer= release_buffer; | 896 avctx->release_buffer= release_buffer; |
872 avctx->draw_horiz_band = draw_slice; | 897 avctx->draw_horiz_band = draw_slice; |
873 mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_MPCODECS_XVMCAcceleratedMPEG2); | 898 mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_MPCODECS_XVMCAcceleratedMPEG2); |
874 assert(ctx->do_dr1);//these are must to! | 899 assert(ctx->do_dr1);//these are must to! |
875 assert(ctx->do_slices); //it is (vo_)ffmpeg bug if this fails | 900 assert(ctx->do_slices); //it is (vo_)ffmpeg bug if this fails |
882 return fmt[i]; | 907 return fmt[i]; |
883 } | 908 } |
884 return fmt[0]; | 909 return fmt[0]; |
885 } | 910 } |
886 | 911 |
887 static int mc_get_buffer(AVCodecContext *avctx, AVFrame *pic){ | |
888 sh_video_t *sh = avctx->opaque; | |
889 vd_ffmpeg_ctx *ctx = sh->context; | |
890 mp_image_t *mpi=NULL; | |
891 struct xvmc_pixfmt_render *render; | |
892 int flags= MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE| | |
893 MP_IMGFLAG_DRAW_CALLBACK; | |
894 | |
895 // printf("vd_ffmpeg::mc_get_buffer (xvmc) %d %d %d\n", pic->reference, ctx->ip_count, ctx->b_count); | |
896 if(!avctx->xvmc_acceleration){ | |
897 mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_MPCODECS_McGetBufferShouldWorkOnlyWithXVMC); | |
898 assert(0); | |
899 exit(1); | |
900 // return -1;//!!fixme check error conditions | |
901 } | |
902 if(mp_msg_test(MSGT_DECVIDEO, MSGL_DBG5)) | |
903 mp_msg(MSGT_DECVIDEO, MSGL_DBG5, "vd_ffmpeg::mc_get_buffer\n"); | |
904 | |
905 if(init_vo(sh, avctx->pix_fmt) < 0){ | |
906 mp_msg(MSGT_DECVIDEO, MSGL_WARN, MSGTR_MPCODECS_UnexpectedInitVoError); | |
907 exit(1); | |
908 // return -1;//!!fixme check error conditions | |
909 } | |
910 | |
911 | |
912 | |
913 if(!pic->reference){ | |
914 ctx->b_count++; | |
915 }else{ | |
916 ctx->ip_count++; | |
917 flags|= MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE; | |
918 } | |
919 | |
920 mpi= mpcodecs_get_image(sh, MP_IMGTYPE_IPB, flags, | |
921 avctx->width, avctx->height); | |
922 if(mpi==NULL){ | |
923 mp_msg(MSGT_DECVIDEO, MSGL_ERR, MSGTR_MPCODECS_UnrecoverableErrorRenderBuffersNotTaken); | |
924 assert(0); | |
925 exit(1); | |
926 // return -1;//!!fixme check error conditions in ffmpeg | |
927 }; | |
928 | |
929 if((mpi->flags & MP_IMGFLAG_DIRECT) == 0){ | |
930 mp_msg(MSGT_DECVIDEO, MSGL_ERR, MSGTR_MPCODECS_OnlyBuffersAllocatedByVoXvmcAllowed); | |
931 assert(0); | |
932 exit(1); | |
933 // return -1;//!!fixme check error conditions in ffmpeg | |
934 } | |
935 | |
936 pic->data[0]= mpi->planes[0]; | |
937 pic->data[1]= mpi->planes[1]; | |
938 pic->data[2]= mpi->planes[2]; | |
939 | |
940 | |
941 /* Note, some (many) codecs in libavcodec must have stride1==stride2 && no changes between frames | |
942 * lavc will check that and die with an error message, if its not true | |
943 */ | |
944 pic->linesize[0]= mpi->stride[0]; | |
945 pic->linesize[1]= mpi->stride[1]; | |
946 pic->linesize[2]= mpi->stride[2]; | |
947 | |
948 pic->opaque = mpi; | |
949 | |
950 if(pic->reference){ | |
951 //I or P frame | |
952 pic->age= ctx->ip_age[0]; | |
953 | |
954 ctx->ip_age[0]= ctx->ip_age[1]+1; | |
955 ctx->ip_age[1]= 1; | |
956 ctx->b_age++; | |
957 }else{ | |
958 //B frame | |
959 pic->age= ctx->b_age; | |
960 | |
961 ctx->ip_age[0]++; | |
962 ctx->ip_age[1]++; | |
963 ctx->b_age=1; | |
964 } | |
965 | |
966 pic->type= FF_BUFFER_TYPE_USER; | |
967 | |
968 render=(struct xvmc_pixfmt_render *)mpi->priv;//same as data[2] | |
969 if(mp_msg_test(MSGT_DECVIDEO, MSGL_DBG5)) | |
970 mp_msg(MSGT_DECVIDEO, MSGL_DBG5, "vd_ffmpeg::mc_get_buffer (render=%p)\n", render); | |
971 assert(render != 0); | |
972 assert(render->magic_id == AV_XVMC_RENDER_MAGIC); | |
973 render->state |= AV_XVMC_STATE_PREDICTION; | |
974 return 0; | |
975 } | |
976 | |
977 #endif /* CONFIG_XVMC */ | 912 #endif /* CONFIG_XVMC */ |