[MPlayer-dev-eng] [PATCH] ve_lavc delayed frames

Loren Merritt lorenm at u.washington.edu
Wed Dec 1 21:02:04 CET 2004


On Wed, 1 Dec 2004, Moritz Bunkus wrote:

>> For example, I could reduce the size of the diff by adding function
>> prototypes instead of reordering code.
>
> It's definitely better to use prototypes. Even if there are changes in
> the functions, too... Or especially then.

ok, here's a more concise patch with equivalent functionality.

--Loren Merritt
-------------- next part --------------
Index: libmpcodecs/ve_lavc.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/ve_lavc.c,v
retrieving revision 1.105
diff -u -r1.105 ve_lavc.c
--- libmpcodecs/ve_lavc.c	28 Nov 2004 18:37:49 -0000	1.105
+++ libmpcodecs/ve_lavc.c	1 Dec 2004 19:49:17 -0000
@@ -324,6 +324,8 @@
 #define FF_QP2LAMBDA 1
 #endif
 
+static int encode_frame(struct vf_instance_s* vf, AVFrame *pic);
+
 static int config(struct vf_instance_s* vf,
         int width, int height, int d_width, int d_height,
 	unsigned int flags, unsigned int outfmt){
@@ -740,7 +742,14 @@
 
 static int control(struct vf_instance_s* vf, int request, void* data){
 
-    return CONTROL_UNKNOWN;
+    switch(request){
+        case VFCTRL_FLUSH_FRAMES:
+            if(vf->priv->codec->capabilities & CODEC_CAP_DELAY)
+                while(encode_frame(vf, NULL) > 0);
+            return CONTROL_TRUE;
+        default:
+            return CONTROL_UNKNOWN;
+    }
 }
 
 static int query_format(struct vf_instance_s* vf, unsigned int fmt){
@@ -781,8 +790,6 @@
 }
 
 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){
-    const char pict_type_char[5]= {'?', 'I', 'P', 'B', 'S'};
-    int out_size;
     AVFrame *pic= vf->priv->pic;
 
     pic->data[0]=mpi->planes[0];
@@ -804,9 +811,18 @@
     }
 #endif
 
+    return (encode_frame(vf, pic) >= 0);
+}
+
+static int encode_frame(struct vf_instance_s* vf, AVFrame *pic){
+    const char pict_type_char[5]= {'?', 'I', 'P', 'B', 'S'};
+    int out_size;
+
 	out_size = avcodec_encode_video(lavc_venc_context, mux_v->buffer, mux_v->buffer_size,
 	    pic);
 
+    if(out_size == 0)
+        return 0;
            
     muxer_write_chunk(mux_v,out_size,lavc_venc_context->coded_frame->key_frame?0x10:0);
         
@@ -835,7 +851,7 @@
                 perror("fopen");
                 lavc_param_psnr=0; // disable block
                 mp_msg(MSGT_MENCODER,MSGL_ERR,"Can't open %s for writing. Check its permissions.\n",filename);
-                return 0; 
+                return -1;
                 /*exit(1);*/
             }
         }
@@ -870,7 +886,7 @@
     /* store stats if there are any */
     if(lavc_venc_context->stats_out && stats_file) 
         fprintf(stats_file, "%s", lavc_venc_context->stats_out);
-    return 1;
+    return out_size;
 }
 
 static void uninit(struct vf_instance_s* vf){


More information about the MPlayer-dev-eng mailing list