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

Steve Lhomme robux4 at ycbcr.xyz
Mon Jul 20 11:16:53 CEST 2020


On 2020-07-20 10:52, Alexandre Janniaux wrote:
> Hi,
> 
> Yes I can, but I already started some refactor work to remove
> this part anyway. :)
> 
> However, now that I rethink this part, it might not be correct
> and always erase video context. I need to recheck what might be
> done on update, and maybe finish my automatic tests before merging
> just to be sure of most cases.

Because of the refcounting it is usually better to add a reference to 
the new one, then remove a reference from the old one, in case they are 
the same. (if that's what you mean by "always erase video context")

> Regards,
> --
> Alexandre Janniaux
> Videolabs
> 
> On Mon, Jul 20, 2020 at 09:58:13AM +0200, Steve Lhomme wrote:
>> LGTM.
>>
>> You may add a comment in the TODO to explain what you expect to be done
>> here.
>>
>> For example, further up in the code there is:
>> /* TODO id->p_decoder->vctx_out*/
>>
>> It's wrong now since we don't store the video context there anymore. We just
>> send an update when it changes (with the matching format) and pass it in
>> pictures.
>>
>> On 2020-07-17 10:21, Alexandre Janniaux wrote:
>>> 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
>>>
>>> _______________________________________________
>>> vlc-devel mailing list
>>> To unsubscribe or modify your subscription options:
>>> https://mailman.videolan.org/listinfo/vlc-devel
>>>
>> _______________________________________________
>> vlc-devel mailing list
>> To unsubscribe or modify your subscription options:
>> https://mailman.videolan.org/listinfo/vlc-devel
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
> 


More information about the vlc-devel mailing list