changeset 5592:b545d56314d2

yuy2 support, fixed bug of dropping frame after config_vo calls
author arpi
date Sat, 13 Apr 2002 13:40:26 +0000
parents 9243e8988e0f
children cd819650484d
files libmpcodecs/vd_ffmpeg.c
diffstat 1 files changed, 29 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libmpcodecs/vd_ffmpeg.c	Sat Apr 13 12:46:14 2002 +0000
+++ b/libmpcodecs/vd_ffmpeg.c	Sat Apr 13 13:40:26 2002 +0000
@@ -23,6 +23,9 @@
 
 LIBVD_EXTERN(ffmpeg)
 
+#include "../postproc/rgb2rgb.h"
+
+
 #ifdef USE_LIBAVCODEC_SO
 #include <libffmpeg/avcodec.h>
 #else
@@ -40,6 +43,8 @@
     int last_aspect;
     int do_slices;
     int vo_inited;
+    int convert;
+    int yuy2_support;
 } vd_ffmpeg_ctx;
 
 //#ifdef FF_POSTPROCESS
@@ -48,6 +53,13 @@
 
 // to set/get/query special features/parameters
 static int control(sh_video_t *sh,int cmd,void* arg,...){
+    vd_ffmpeg_ctx *ctx = sh->context;
+    switch(cmd){
+    case VDCTRL_QUERY_FORMAT:
+	if( (*((int*)arg)) == IMGFMT_YV12 ) return CONTROL_TRUE;
+	if( (*((int*)arg)) == IMGFMT_YUY2 && ctx->yuy2_support ) return CONTROL_TRUE;
+	return CONTROL_FALSE;
+    }
     return CONTROL_UNKNOWN;
 }
 
@@ -135,7 +147,7 @@
 
     if(len<=0) return NULL; // skipped frame
     
-    if(ctx->vo_inited){
+    if(ctx->vo_inited && !ctx->convert){
 	mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, MP_IMGFLAG_PRESERVE |
 	    (ctx->do_slices?MP_IMGFLAG_DRAW_CALLBACK:0),
 	    sh->disp_w, sh->disp_h);
@@ -177,8 +189,22 @@
 	sh->disp_w = avctx->width;
 	sh->disp_h = avctx->height;
 	ctx->vo_inited=1;
-    	if (mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YV12))
+	ctx->yuy2_support=(avctx->pix_fmt==PIX_FMT_YUV422P);
+    	if (!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,
+	    ctx->yuy2_support ? IMGFMT_YUY2 : IMGFMT_YV12))
     		return NULL;
+	ctx->convert=(sh->codec->outfmt[sh->outfmtidx]==IMGFMT_YUY2);
+    }
+    
+    if(!mpi && ctx->convert){
+	// do yuv422p -> yuy2 conversion:
+        mpi=mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
+	    avctx->width, avctx->height);
+	if(!mpi) return NULL;
+	yuv422ptoyuy2(lavc_picture.data[0],lavc_picture.data[1],lavc_picture.data[2],
+	    mpi->planes[0],avctx->width,avctx->height,
+	    lavc_picture.linesize[0],lavc_picture.linesize[1],mpi->stride[0]);
+	return mpi;
     }
     
     if(!mpi)
@@ -197,6 +223,7 @@
     mpi->stride[2]=lavc_picture.linesize[2];
 
     if(avctx->pix_fmt==PIX_FMT_YUV422P){
+	// we have 422p but user wants yv12 (420p)
 	mpi->stride[1]*=2;
 	mpi->stride[2]*=2;
     }