[vlc-commits] trascode: reinit audio filters if audio format changes in midstream
Ilkka Ollakka
git at videolan.org
Sun Sep 22 16:03:57 CEST 2013
vlc | branch: master | Ilkka Ollakka <ileoo at videolan.org> | Sun Sep 22 12:24:52 2013 +0300| [a3a150b91f09620dc0d81c22db591a20faf4b2a5] | committer: Ilkka Ollakka
trascode: reinit audio filters if audio format changes in midstream
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a3a150b91f09620dc0d81c22db591a20faf4b2a5
---
modules/stream_out/transcode/audio.c | 55 ++++++++++++++++++++----------
modules/stream_out/transcode/transcode.h | 1 +
2 files changed, 38 insertions(+), 18 deletions(-)
diff --git a/modules/stream_out/transcode/audio.c b/modules/stream_out/transcode/audio.c
index bccd3a5..7a2b1e1 100644
--- a/modules/stream_out/transcode/audio.c
+++ b/modules/stream_out/transcode/audio.c
@@ -52,6 +52,31 @@ static int audio_update_format( decoder_t *p_dec )
return 0;
}
+static int transcode_audio_initialize_filters( sout_stream_t *p_stream, sout_stream_id_t *id, sout_stream_sys_t *p_sys, audio_sample_format_t *fmt_last )
+{
+ /* Load user specified audio filters */
+ /* XXX: These variable names come kinda out of nowhere... */
+ var_Create( p_stream, "audio-time-stretch", VLC_VAR_BOOL );
+ var_Create( p_stream, "audio-filter", VLC_VAR_STRING );
+ if( p_sys->psz_af )
+ var_SetString( p_stream, "audio-filter", p_sys->psz_af );
+ id->p_af_chain = aout_FiltersNew( p_stream, fmt_last,
+ &id->p_encoder->fmt_in.audio, NULL );
+ var_Destroy( p_stream, "audio-filter" );
+ var_Destroy( p_stream, "audio-time-stretch" );
+ if( id->p_af_chain == NULL )
+ {
+ msg_Err( p_stream, "Unable to initialize audio filters" );
+ module_unneed( id->p_encoder, id->p_encoder->p_module );
+ id->p_encoder->p_module = NULL;
+ module_unneed( id->p_decoder, id->p_decoder->p_module );
+ id->p_decoder->p_module = NULL;
+ return VLC_EGENERIC;
+ }
+ memcpy( fmt_last, &p_sys->fmt_audio, sizeof( audio_sample_format_t ) );
+ return VLC_SUCCESS;
+}
+
int transcode_audio_new( sout_stream_t *p_stream,
sout_stream_id_t *id )
{
@@ -128,25 +153,8 @@ int transcode_audio_new( sout_stream_t *p_stream,
}
aout_FormatPrepare( &id->p_encoder->fmt_in.audio );
- /* Load user specified audio filters */
- /* XXX: These variable names come kinda out of nowhere... */
- var_Create( p_stream, "audio-time-stretch", VLC_VAR_BOOL );
- var_Create( p_stream, "audio-filter", VLC_VAR_STRING );
- if( p_sys->psz_af )
- var_SetString( p_stream, "audio-filter", p_sys->psz_af );
- id->p_af_chain = aout_FiltersNew( p_stream, &fmt_last,
- &id->p_encoder->fmt_in.audio, NULL );
- var_Destroy( p_stream, "audio-filter" );
- var_Destroy( p_stream, "audio-time-stretch" );
- if( id->p_af_chain == NULL )
- {
- msg_Err( p_stream, "cannot connect audio filters chain" );
- module_unneed( id->p_encoder, id->p_encoder->p_module );
- id->p_encoder->p_module = NULL;
- module_unneed( id->p_decoder, id->p_decoder->p_module );
- id->p_decoder->p_module = NULL;
+ if( unlikely( transcode_audio_initialize_filters( p_stream, id, p_sys, &fmt_last ) != VLC_SUCCESS ) )
return VLC_EGENERIC;
- }
return VLC_SUCCESS;
}
@@ -212,6 +220,17 @@ int transcode_audio_process( sout_stream_t *p_stream,
p_audio_buf->i_dts = p_audio_buf->i_pts;
+ /* Check if audio format has changed, and filters need reinit */
+ if( unlikely( AOUT_FMTS_IDENTICAL( &id->p_decoder->fmt_out.audio, &p_sys->fmt_audio ) ) )
+ {
+ msg_Dbg( p_stream, "Audio changed, trying to reinitialize filters" );
+ if( id->p_af_chain != NULL )
+ aout_FiltersDelete( (vlc_object_t *)NULL, id->p_af_chain );
+ if( transcode_audio_initialize_filters( p_stream, id, p_sys, &id->p_decoder->fmt_out.audio ) != VLC_SUCCESS )
+ return VLC_EGENERIC;
+
+ }
+
/* Run filter chain */
p_audio_buf = aout_FiltersPlay( id->p_af_chain, p_audio_buf,
INPUT_RATE_DEFAULT );
diff --git a/modules/stream_out/transcode/transcode.h b/modules/stream_out/transcode/transcode.h
index 85651c9..00e7a6d 100644
--- a/modules/stream_out/transcode/transcode.h
+++ b/modules/stream_out/transcode/transcode.h
@@ -25,6 +25,7 @@ struct sout_stream_sys_t
/* Audio */
vlc_fourcc_t i_acodec; /* codec audio (0 if not transcode) */
+ audio_sample_format_t fmt_audio;
char *psz_aenc;
char *psz_alang;
config_chain_t *p_audio_cfg;
More information about the vlc-commits
mailing list