[vlc-commits] [Git][videolan/vlc][master] 5 commits: transcode: simplify encoder closes

Steve Lhomme (@robUx4) gitlab at videolan.org
Mon Jan 30 16:51:16 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
357c70f1 by Alaric Senat at 2023-01-30T16:31:44+00:00
transcode: simplify encoder closes

`module_unneed` is now called in one single place.

- - - - -
d899a2d3 by Alaric Senat at 2023-01-30T16:31:44+00:00
transcode: video_enc: rename `close` to `stop`

Now, this function only interrupts and join the encoder threads.

- - - - -
0d61cd2d by Alaric Senat at 2023-01-30T16:31:44+00:00
transcode: encoder: properly close

Single `module_unneed` calls aren't enough to properly close encoders as
their disable callbacks are stored independently from the module.
As a side effect, this patch fixes a double-free where the custom
`close` callback was called after the `module_unneed` call in the
encoder destroy function:

```
READ of size 8 at 0x619000050498 thread T10 (vlc-input)
    #0 0x7f83c0e72a67 in CloseEncoder ../../modules/codec/x264.c:1523
    #1 0x7f83d64b7613 in vlc_encoder_Destroy ../../src/input/decoder_helpers.c:176
    #2 0x7f83ccb31986 in transcode_encoder_delete ../../modules/stream_out/transcode/encoder/encoder.c:55
    #3 0x7f83ccb53203 in transcode_video_clean ../../modules/stream_out/transcode/video.c:405
    #4 0x7f83ccb2f6ac in Del ../../modules/stream_out/transcode/transcode.c:736
    #5 0x7f83d679814f in sout_StreamIdDel ../../src/stream_output/stream_output.c:707
    #6 0x7f83d6791cc3 in sout_InputDelete ../../src/stream_output/stream_output.c:155
    #7 ...

0x619000050498 is located 1048 bytes inside of 1072-byte region [0x619000050080,0x6190000504b0)
freed by thread T10 (vlc-input) here:
    #0 0x7f83d73b6388 in __interceptor_free.part.0 (/lib64/libasan.so.8+0xb9388)
    #1 0x7f83d6740fcd in vlc_objres_clear ../../src/misc/objres.c:93
    #2 0x7f83d640265d in module_unneed ../../src/modules/modules.c:307
    #3 0x7f83ccb3f212 in transcode_encoder_video_close ../../modules/stream_out/transcode/encoder/video.c:390
    #4 0x7f83ccb331a2 in transcode_encoder_close ../../modules/stream_out/transcode/encoder/encoder.c:188
    #5 0x7f83ccb53178 in transcode_video_clean ../../modules/stream_out/transcode/video.c:404
    #6 0x7f83ccb2f6ac in Del ../../modules/stream_out/transcode/transcode.c:736
    #7 ...
```

- - - - -
9c93ba93 by Alaric Senat at 2023-01-30T16:31:44+00:00
transcode: ensure encoder is stopped on destroy

This makes the destroy procedure implicitly the same than the closing
with extra resource removal steps.

- - - - -
d23d3574 by Alaric Senat at 2023-01-30T16:31:44+00:00
transcode: encoder: remove redundant `close` calls

Destroying the encoder should implicitly call the correct close
callbacks.

- - - - -


6 changed files:

- modules/stream_out/transcode/audio.c
- modules/stream_out/transcode/encoder/encoder.c
- modules/stream_out/transcode/encoder/encoder_priv.h
- modules/stream_out/transcode/encoder/video.c
- modules/stream_out/transcode/spu.c
- modules/stream_out/transcode/video.c


Changes:

=====================================
modules/stream_out/transcode/audio.c
=====================================
@@ -201,7 +201,6 @@ int transcode_audio_init( sout_stream_t *p_stream, const es_format_t *p_fmt,
 void transcode_audio_clean( sout_stream_t *p_stream, sout_stream_id_sys_t *id )
 {
     /* Close encoder */
-    transcode_encoder_close( id->encoder );
     transcode_encoder_delete( id->encoder );
 
     es_format_Clean( &id->decoder_out );


=====================================
modules/stream_out/transcode/encoder/encoder.c
=====================================
@@ -48,6 +48,7 @@ void transcode_encoder_delete( transcode_encoder_t *p_enc )
     {
         if( p_enc->p_encoder->fmt_in.i_cat == VIDEO_ES )
         {
+            transcode_encoder_video_stop( p_enc );
             block_ChainRelease( p_enc->p_buffers );
             picture_fifo_Delete( p_enc->pp_pics );
         }
@@ -182,16 +183,17 @@ void transcode_encoder_close( transcode_encoder_t *p_enc )
     if( !p_enc->p_encoder->p_module )
         return;
 
-    switch( p_enc->p_encoder->fmt_in.i_cat )
+    if( p_enc->p_encoder->fmt_in.i_cat == VIDEO_ES )
+        transcode_encoder_video_stop( p_enc );
+
+    if( p_enc->p_encoder->ops != NULL && p_enc->p_encoder->ops->close != NULL )
     {
-        case VIDEO_ES:
-            transcode_encoder_video_close( p_enc );
-            break;
-        default:
-            module_unneed( p_enc->p_encoder, p_enc->p_encoder->p_module );
-            break;
+        p_enc->p_encoder->ops->close( p_enc->p_encoder );
+        p_enc->p_encoder->ops = NULL;
     }
 
+    module_unneed( p_enc->p_encoder, p_enc->p_encoder->p_module );
+
     p_enc->p_encoder->p_module = NULL;
 }
 


=====================================
modules/stream_out/transcode/encoder/encoder_priv.h
=====================================
@@ -40,7 +40,7 @@ int transcode_encoder_video_open( transcode_encoder_t *p_enc,
 int transcode_encoder_spu_open( transcode_encoder_t *p_enc,
                                 const transcode_encoder_config_t *p_cfg );
 
-void transcode_encoder_video_close( transcode_encoder_t *p_enc );
+void transcode_encoder_video_stop( transcode_encoder_t *p_enc );
 
 block_t * transcode_encoder_video_encode( transcode_encoder_t *p_enc, picture_t *p_pic );
 block_t * transcode_encoder_audio_encode( transcode_encoder_t *p_enc, block_t *p_block );


=====================================
modules/stream_out/transcode/encoder/video.c
=====================================
@@ -375,7 +375,7 @@ int transcode_encoder_video_drain( transcode_encoder_t *p_enc, block_t **out )
     return VLC_SUCCESS;
 }
 
-void transcode_encoder_video_close( transcode_encoder_t *p_enc )
+void transcode_encoder_video_stop( transcode_encoder_t *p_enc )
 {
     if( p_enc->b_threaded && !p_enc->b_abort )
     {
@@ -385,10 +385,6 @@ void transcode_encoder_video_close( transcode_encoder_t *p_enc )
         vlc_mutex_unlock( &p_enc->lock_out );
         vlc_join( p_enc->thread, NULL );
     }
-
-    /* Close encoder */
-    module_unneed( p_enc->p_encoder, p_enc->p_encoder->p_module );
-    p_enc->p_encoder->p_module = NULL;
 }
 
 int transcode_encoder_video_open( transcode_encoder_t *p_enc,


=====================================
modules/stream_out/transcode/spu.c
=====================================
@@ -141,7 +141,6 @@ int transcode_spu_init( sout_stream_t *p_stream, const es_format_t *p_fmt,
         {
             msg_Err( p_stream, "cannot output transcoded stream %4.4s",
                                (char *) &id->p_enccfg->i_codec );
-            transcode_encoder_close( id->encoder );
             transcode_encoder_delete( id->encoder );
             module_unneed( id->p_decoder, id->p_decoder->p_module );
             id->p_decoder->p_module = NULL;
@@ -162,10 +161,7 @@ void transcode_spu_clean( sout_stream_t *p_stream, sout_stream_id_sys_t *id)
 
     /* Close encoder */
     if( id->encoder )
-    {
-        transcode_encoder_close( id->encoder );
         transcode_encoder_delete( id->encoder );
-    }
 }
 
 int transcode_spu_process( sout_stream_t *p_stream,


=====================================
modules/stream_out/transcode/video.c
=====================================
@@ -398,10 +398,7 @@ void transcode_video_clean( sout_stream_id_sys_t *id )
 {
     /* Close encoder, but only if one was opened. */
     if ( id->encoder )
-    {
-        transcode_encoder_close( id->encoder );
         transcode_encoder_delete( id->encoder );
-    }
 
     es_format_Clean( &id->decoder_out );
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/727232f41ae160f1a880c83dbe3e56c6f1254c6d...d23d357447ffc4fdadee8fe4a1f82e532186b797

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/727232f41ae160f1a880c83dbe3e56c6f1254c6d...d23d357447ffc4fdadee8fe4a1f82e532186b797
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list