[vlc-commits] sout: transcode: refactor drain
Francois Cartegnie
git at videolan.org
Wed Aug 29 17:11:52 CEST 2018
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Aug 29 15:36:50 2018 +0200| [2e5bc0cc650278fc8c35bb4d3fd993eda67d9b0a] | committer: Francois Cartegnie
sout: transcode: refactor drain
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=2e5bc0cc650278fc8c35bb4d3fd993eda67d9b0a
---
modules/stream_out/transcode/audio.c | 6 +-----
modules/stream_out/transcode/encoder/audio.c | 10 +++++++++
modules/stream_out/transcode/encoder/encoder.c | 18 ++++++++++++++++
modules/stream_out/transcode/encoder/encoder.h | 1 +
.../stream_out/transcode/encoder/encoder_priv.h | 3 +++
modules/stream_out/transcode/encoder/video.c | 25 ++++++++++++++++++++++
modules/stream_out/transcode/video.c | 18 ++++------------
7 files changed, 62 insertions(+), 19 deletions(-)
diff --git a/modules/stream_out/transcode/audio.c b/modules/stream_out/transcode/audio.c
index 47d9f3062a..ae357c30f9 100644
--- a/modules/stream_out/transcode/audio.c
+++ b/modules/stream_out/transcode/audio.c
@@ -354,11 +354,7 @@ error:
/* Drain encoder */
if( unlikely( !id->b_error && in == NULL ) && transcode_encoder_opened( id->encoder ) )
{
- block_t *p_block;
- do {
- p_block = transcode_encoder_encode( id->encoder, NULL );
- block_ChainAppend( out, p_block );
- } while( p_block );
+ transcode_encoder_drain( id->encoder, out );
}
return id->b_error ? VLC_EGENERIC : VLC_SUCCESS;
diff --git a/modules/stream_out/transcode/encoder/audio.c b/modules/stream_out/transcode/encoder/audio.c
index 47e76bcbde..6b2f72c518 100644
--- a/modules/stream_out/transcode/encoder/audio.c
+++ b/modules/stream_out/transcode/encoder/audio.c
@@ -201,3 +201,13 @@ block_t * transcode_encoder_audio_encode( transcode_encoder_t *p_enc, block_t *p
{
return p_enc->p_encoder->pf_encode_audio( p_enc->p_encoder, p_block );
}
+
+int transcode_encoder_audio_drain( transcode_encoder_t *p_enc, block_t **out )
+{
+ block_t *p_block;
+ do {
+ p_block = transcode_encoder_audio_encode( p_enc, NULL );
+ block_ChainAppend( out, p_block );
+ } while( p_block );
+ return VLC_SUCCESS;
+}
diff --git a/modules/stream_out/transcode/encoder/encoder.c b/modules/stream_out/transcode/encoder/encoder.c
index 3a2aca1f2f..ac50cb062a 100644
--- a/modules/stream_out/transcode/encoder/encoder.c
+++ b/modules/stream_out/transcode/encoder/encoder.c
@@ -201,6 +201,24 @@ int transcode_encoder_open( transcode_encoder_t *p_enc,
}
}
+int transcode_encoder_drain( transcode_encoder_t *p_enc, block_t **out )
+{
+ if( !transcode_encoder_opened( p_enc ) )
+ return VLC_EGENERIC;
+
+ switch( p_enc->p_encoder->fmt_in.i_cat )
+ {
+ case VIDEO_ES:
+ return transcode_encoder_video_drain( p_enc, out );
+ case AUDIO_ES:
+ return transcode_encoder_audio_drain( p_enc, out );
+ case SPU_ES:
+ return VLC_SUCCESS;
+ default:
+ return VLC_EGENERIC;
+ }
+}
+
int transcode_encoder_test( vlc_object_t *p_obj,
const transcode_encoder_config_t *p_cfg,
const es_format_t *p_dec_fmtin,
diff --git a/modules/stream_out/transcode/encoder/encoder.h b/modules/stream_out/transcode/encoder/encoder.h
index 888ad91dc5..b6030aa31a 100644
--- a/modules/stream_out/transcode/encoder/encoder.h
+++ b/modules/stream_out/transcode/encoder/encoder.h
@@ -76,6 +76,7 @@ void transcode_encoder_close( transcode_encoder_t * );
bool transcode_encoder_opened( const transcode_encoder_t * );
int transcode_encoder_open( transcode_encoder_t *, const transcode_encoder_config_t * );
+int transcode_encoder_drain( transcode_encoder_t *, block_t ** );
int transcode_encoder_test( vlc_object_t *p_obj,
const transcode_encoder_config_t *p_cfg,
diff --git a/modules/stream_out/transcode/encoder/encoder_priv.h b/modules/stream_out/transcode/encoder/encoder_priv.h
index 8fb16294fd..2875ae71a4 100644
--- a/modules/stream_out/transcode/encoder/encoder_priv.h
+++ b/modules/stream_out/transcode/encoder/encoder_priv.h
@@ -46,6 +46,9 @@ block_t * transcode_encoder_video_encode( transcode_encoder_t *p_enc, picture_t
block_t * transcode_encoder_audio_encode( transcode_encoder_t *p_enc, block_t *p_block );
block_t * transcode_encoder_spu_encode( transcode_encoder_t *p_enc, subpicture_t *p_spu );
+int transcode_encoder_audio_drain( transcode_encoder_t *p_enc, block_t **out );
+int transcode_encoder_video_drain( transcode_encoder_t *p_enc, block_t **out );
+
int transcode_encoder_video_test( vlc_object_t *p_obj,
const transcode_encoder_config_t *p_cfg,
const es_format_t *p_dec_fmtin,
diff --git a/modules/stream_out/transcode/encoder/video.c b/modules/stream_out/transcode/encoder/video.c
index 9bb1e7af17..0b84cb8d57 100644
--- a/modules/stream_out/transcode/encoder/video.c
+++ b/modules/stream_out/transcode/encoder/video.c
@@ -373,6 +373,31 @@ static void* EncoderThread( void *obj )
return NULL;
}
+int transcode_encoder_video_drain( transcode_encoder_t *p_enc, block_t **out )
+{
+ if( !p_enc->b_threaded )
+ {
+ block_t *p_block;
+ do {
+ p_block = transcode_encoder_encode( p_enc, NULL );
+ block_ChainAppend( out, p_block );
+ } while( p_block );
+ }
+ else
+ {
+ if( p_enc->b_threaded && !p_enc->b_abort )
+ {
+ vlc_mutex_lock( &p_enc->lock_out );
+ p_enc->b_abort = true;
+ vlc_cond_signal( &p_enc->cond );
+ vlc_mutex_unlock( &p_enc->lock_out );
+ vlc_join( p_enc->thread, NULL );
+ }
+ block_ChainAppend( out, transcode_encoder_get_output_async( p_enc ) );
+ }
+ return VLC_SUCCESS;
+}
+
void transcode_encoder_video_close( transcode_encoder_t *p_enc )
{
if( p_enc->b_threaded && !p_enc->b_abort )
diff --git a/modules/stream_out/transcode/video.c b/modules/stream_out/transcode/video.c
index 58591859f3..00dddbd9ad 100644
--- a/modules/stream_out/transcode/video.c
+++ b/modules/stream_out/transcode/video.c
@@ -578,21 +578,11 @@ error:
/* Drain encoder */
if( unlikely( !id->b_error && in == NULL ) && transcode_encoder_opened( id->encoder ) )
{
- if( id->p_enccfg->video.threads.i_count == 0 )
- {
- block_t *p_block;
- do {
- p_block = transcode_encoder_encode( id->encoder, NULL );
- block_ChainAppend( out, p_block );
- } while( p_block );
- }
- else
- {
- msg_Dbg( p_stream, "Flushing thread and waiting that");
- transcode_encoder_close( id->encoder );
- block_ChainAppend( out, transcode_encoder_get_output_async( id->encoder ) );
+ msg_Dbg( p_stream, "Flushing thread and waiting that");
+ if( transcode_encoder_drain( id->encoder, out ) == VLC_SUCCESS )
msg_Dbg( p_stream, "Flushing done");
- }
+ else
+ msg_Warn( p_stream, "Flushing failed");
}
return id->b_error ? VLC_EGENERIC : VLC_SUCCESS;
More information about the vlc-commits
mailing list