[vlc-devel] [PATCH] transcode: encoder: forward video context with format

Alexandre Janniaux ajanni at videolabs.io
Fri Jul 17 10:21:12 CEST 2020


The video context was correctly forwarded from the beginning of the
filter chains up to the user filter chain but the output video context
of the user filter chain was never used.

As we call transcode_encoder_update_format_in only for video, add the
video context there to forward it too. If the function starts to be used
in audio too, it could probably be splitted into a different function
instead.

The code also forward NULL video context after the opening of the
decoder, but since the video context is now extracted asynchronously
from the decoder_UpdateVideoOutput call, this part should probably be
moved to the associated callback instead.
---
 modules/stream_out/transcode/encoder/encoder.c | 9 ++++++++-
 modules/stream_out/transcode/encoder/encoder.h | 2 +-
 modules/stream_out/transcode/video.c           | 5 +++--
 3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/modules/stream_out/transcode/encoder/encoder.c b/modules/stream_out/transcode/encoder/encoder.c
index 2c893326636..210e04f4cba 100644
--- a/modules/stream_out/transcode/encoder/encoder.c
+++ b/modules/stream_out/transcode/encoder/encoder.c
@@ -124,10 +124,17 @@ const es_format_t *transcode_encoder_format_out( const transcode_encoder_t *p_en
     return &p_enc->p_encoder->fmt_out;
 }
 
-void transcode_encoder_update_format_in( transcode_encoder_t *p_enc, const es_format_t *fmt )
+void transcode_encoder_update_format_in( transcode_encoder_t *p_enc, const es_format_t *fmt,
+                                         struct vlc_video_context *vctx )
 {
     es_format_Clean( &p_enc->p_encoder->fmt_in );
     es_format_Copy( &p_enc->p_encoder->fmt_in, fmt );
+
+    if( p_enc->p_encoder->vctx_in != NULL )
+        vlc_video_context_Release( p_enc->p_encoder->vctx_in );
+    if( vctx )
+        vlc_video_context_Hold( vctx );
+    p_enc->p_encoder->vctx_in = vctx;
 }
 
 void transcode_encoder_update_format_out( transcode_encoder_t *p_enc, const es_format_t *fmt )
diff --git a/modules/stream_out/transcode/encoder/encoder.h b/modules/stream_out/transcode/encoder/encoder.h
index 30a83547702..b176c4ad7bc 100644
--- a/modules/stream_out/transcode/encoder/encoder.h
+++ b/modules/stream_out/transcode/encoder/encoder.h
@@ -65,7 +65,7 @@ void transcode_encoder_config_clean( transcode_encoder_config_t * );
 
 const es_format_t *transcode_encoder_format_in( const transcode_encoder_t * );
 const es_format_t *transcode_encoder_format_out( const transcode_encoder_t * );
-void transcode_encoder_update_format_in( transcode_encoder_t *, const es_format_t * );
+void transcode_encoder_update_format_in( transcode_encoder_t *, const es_format_t *, struct vlc_video_context * );
 void transcode_encoder_update_format_out( transcode_encoder_t *, const es_format_t * );
 
 block_t * transcode_encoder_encode( transcode_encoder_t *, void * );
diff --git a/modules/stream_out/transcode/video.c b/modules/stream_out/transcode/video.c
index 094c1a357fc..2bb4cc768ca 100644
--- a/modules/stream_out/transcode/video.c
+++ b/modules/stream_out/transcode/video.c
@@ -250,7 +250,7 @@ int transcode_video_init( sout_stream_t *p_stream, const es_format_t *p_fmt,
     p_enc_owner->enc.cbs = &encoder_video_transcode_cbs;
 
     /* Will use this format as encoder input for now */
-    transcode_encoder_update_format_in( id->encoder, &encoder_tested_fmt_in );
+    transcode_encoder_update_format_in( id->encoder, &encoder_tested_fmt_in, NULL /* TODO */ );
 
     es_format_Clean( &encoder_tested_fmt_in );
 
@@ -389,11 +389,12 @@ static int transcode_video_filters_init( sout_stream_t *p_stream,
         filter_chain_Reset( id->p_uf_chain, p_src, src_ctx, p_dst );
         filter_chain_AppendFromString( id->p_uf_chain, p_cfg->psz_filters );
         p_src = filter_chain_GetFmtOut( id->p_uf_chain );
+        src_ctx = filter_chain_GetVideoCtxOut( id->p_uf_chain );
         debug_format( p_stream, p_src );
    }
 
     /* Update encoder so it matches filters output */
-    transcode_encoder_update_format_in( id->encoder, p_src );
+    transcode_encoder_update_format_in( id->encoder, p_src, src_ctx );
 
     /* SPU Sources */
     if( p_cfg->video.psz_spu_sources )
-- 
2.27.0



More information about the vlc-devel mailing list