[vlc-devel] [PATCH 03/26] dmo: use different callbacks for the audio/video encoders

Steve Lhomme robux4 at ycbcr.xyz
Mon Jan 18 08:32:42 UTC 2021


Avoid using dirty casts.
---
 modules/codec/dmo/dmo.c | 127 +++++++++++++++++++++++-----------------
 1 file changed, 72 insertions(+), 55 deletions(-)

diff --git a/modules/codec/dmo/dmo.c b/modules/codec/dmo/dmo.c
index 5a14e2da282..7af404b6e9e 100644
--- a/modules/codec/dmo/dmo.c
+++ b/modules/codec/dmo/dmo.c
@@ -56,9 +56,10 @@ static int  DecoderOpen  ( vlc_object_t * );
 static void DecoderClose ( vlc_object_t * );
 static int DecodeBlock ( decoder_t *, block_t * );
 static void *DecoderThread( void * );
-static int  EncoderOpen  ( vlc_object_t * );
+static int  EncoderAudioOpen  ( vlc_object_t * );
+static int  EncoderVideoOpen  ( vlc_object_t * );
 static void EncoderClose ( vlc_object_t * );
-static block_t *EncodeBlock( encoder_t *, void * );
+static block_t *EncodeBlock( encoder_t *, block_t *, vlc_tick_t );
 
 static int  EncOpen  ( vlc_object_t * );
 
@@ -83,10 +84,10 @@ vlc_module_begin ()
     set_description( N_("DirectMedia Object encoder") )
     add_shortcut( "dmo" )
     set_capability( "audio encoder", 10 )
-    set_callbacks( EncoderOpen, EncoderClose )
+    set_callbacks( EncoderAudioOpen, EncoderClose )
     add_submodule()
       set_capability( "video encoder", 100 )
-      set_callbacks( EncoderOpen, EncoderClose )
+      set_callbacks( EncoderVideoOpen, EncoderClose )
 
 vlc_module_end ()
 
@@ -1027,10 +1028,62 @@ typedef struct
 
 } encoder_sys_t;
 
+static block_t * EncodeAudioBlock( encoder_t *p_enc, block_t *p_aout_buffer )
+{
+    if (p_aout_buffer == NULL)
+        return NULL;
+
+    block_t *p_block_in = block_Alloc( p_aout_buffer->i_buffer );
+    if (unlikely(p_block_in == NULL))
+        return NULL;
+
+    memcpy( p_block_in->p_buffer, p_aout_buffer->p_buffer,
+            p_block_in->i_buffer );
+
+    return EncodeBlock(p_enc, p_block_in, p_aout_buffer->i_pts);
+}
+
+static block_t * EncodeVideoBlock( encoder_t *p_enc, picture_t *p_pic )
+{
+    if (p_pic == NULL)
+        return NULL;
+
+    /* Get picture data */
+    int i_plane, i_line, i_width, i_src_stride;
+    uint8_t *p_dst;
+
+    int i_buffer = p_enc->fmt_in.video.i_visible_width *
+        p_enc->fmt_in.video.i_visible_height *
+        p_enc->fmt_in.video.i_bits_per_pixel / 8;
+
+    block_t *p_block_in = block_Alloc( i_buffer );
+    if (unlikely(p_block_in == NULL))
+        return NULL;
+
+    /* Copy picture stride by stride */
+    p_dst = p_block_in->p_buffer;
+    for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
+    {
+        uint8_t *p_src = p_pic->p[i_plane].p_pixels;
+        i_width = p_pic->p[i_plane].i_visible_pitch;
+        i_src_stride = p_pic->p[i_plane].i_pitch;
+
+        for( i_line = 0; i_line < p_pic->p[i_plane].i_visible_lines;
+                i_line++ )
+        {
+            memcpy( p_dst, p_src, i_width );
+            p_dst += i_width;
+            p_src += i_src_stride;
+        }
+    }
+
+    return EncodeBlock(p_enc, p_block_in, p_pic->date);
+}
+
 /*****************************************************************************
  * EncoderOpen: open dmo codec
  *****************************************************************************/
-static int EncoderOpen( vlc_object_t *p_this )
+static int EncoderAudioOpen( vlc_object_t *p_this )
 {
     encoder_t *p_enc = (encoder_t*)p_this;
 
@@ -1038,10 +1091,19 @@ static int EncoderOpen( vlc_object_t *p_this )
     if( i_ret != VLC_SUCCESS ) return i_ret;
 
     /* Set callbacks */
-    p_enc->pf_encode_video = (block_t *(*)(encoder_t *, picture_t *))
-        EncodeBlock;
-    p_enc->pf_encode_audio = (block_t *(*)(encoder_t *, block_t *))
-        EncodeBlock;
+    p_enc->pf_encode_audio = EncodeAudioBlock;
+
+    return VLC_SUCCESS;
+}
+static int EncoderVideoOpen( vlc_object_t *p_this )
+{
+    encoder_t *p_enc = (encoder_t*)p_this;
+
+    int i_ret = EncOpen( p_this );
+    if( i_ret != VLC_SUCCESS ) return i_ret;
+
+    /* Set callbacks */
+    p_enc->pf_encode_video = EncodeVideoBlock;
 
     return VLC_SUCCESS;
 }
@@ -1436,59 +1498,14 @@ static int EncOpen( vlc_object_t *p_this )
 /****************************************************************************
  * Encode: the whole thing
  ****************************************************************************/
-static block_t *EncodeBlock( encoder_t *p_enc, void *p_data )
+static block_t *EncodeBlock( encoder_t *p_enc, block_t *p_block_in, vlc_tick_t i_pts )
 {
     encoder_sys_t *p_sys = p_enc->p_sys;
     CMediaBuffer *p_in;
     block_t *p_chain = NULL;
-    block_t *p_block_in;
     uint32_t i_status;
     int i_result;
-    vlc_tick_t i_pts;
-
-    if( !p_data ) return NULL;
-
-    if( p_enc->fmt_out.i_cat == VIDEO_ES )
-    {
-        /* Get picture data */
-        int i_plane, i_line, i_width, i_src_stride;
-        picture_t *p_pic = (picture_t *)p_data;
-        uint8_t *p_dst;
 
-        int i_buffer = p_enc->fmt_in.video.i_visible_width *
-            p_enc->fmt_in.video.i_visible_height *
-            p_enc->fmt_in.video.i_bits_per_pixel / 8;
-
-        p_block_in = block_Alloc( i_buffer );
-
-        /* Copy picture stride by stride */
-        p_dst = p_block_in->p_buffer;
-        for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
-        {
-            uint8_t *p_src = p_pic->p[i_plane].p_pixels;
-            i_width = p_pic->p[i_plane].i_visible_pitch;
-            i_src_stride = p_pic->p[i_plane].i_pitch;
-
-            for( i_line = 0; i_line < p_pic->p[i_plane].i_visible_lines;
-                 i_line++ )
-            {
-                memcpy( p_dst, p_src, i_width );
-                p_dst += i_width;
-                p_src += i_src_stride;
-            }
-        }
-
-        i_pts = p_pic->date;
-    }
-    else
-    {
-        block_t *p_aout_buffer = (block_t *)p_data;
-        p_block_in = block_Alloc( p_aout_buffer->i_buffer );
-        memcpy( p_block_in->p_buffer, p_aout_buffer->p_buffer,
-                p_block_in->i_buffer );
-
-        i_pts = p_aout_buffer->i_pts;
-    }
 
     /* Feed input to the DMO */
     p_in = CMediaBufferCreate( p_block_in, p_block_in->i_buffer, true );
-- 
2.29.2



More information about the vlc-devel mailing list