X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Faudio_output%2Finput.c;h=85d439bbcbb254e9c9afa6947e75d6628b663e07;hb=4b9c63a36eded246ad9ef1ea0de0cf7b38d29ad9;hp=c7f396e16889effff6b56269119fcdd590895fbe;hpb=ac5d4e03b984753d8a350efa8f8399867fa20266;p=vlc diff --git a/src/audio_output/input.c b/src/audio_output/input.c index c7f396e168..85d439bbcb 100644 --- a/src/audio_output/input.c +++ b/src/audio_output/input.c @@ -42,6 +42,7 @@ #include /* for vout_Request */ #include +#include #include #include "aout_internal.h" @@ -63,8 +64,6 @@ static void ReplayGainSelect( aout_instance_t *, aout_input_t * ); static vout_thread_t *RequestVout( void *, vout_thread_t *, video_format_t *, bool ); -static vout_thread_t *RequestVoutFromFilter( void *, - vout_thread_t *, video_format_t *, bool ); /***************************************************************************** * aout_InputNew : allocate a new input and rework the filter pipeline @@ -250,7 +249,7 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_ while( psz_parser && *psz_parser ) { - aout_filter_t * p_filter = NULL; + filter_t * p_filter = NULL; if( p_input->i_nb_filters >= AOUT_MAX_FILTERS ) { @@ -283,27 +282,25 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_ continue; } - vlc_object_set_name( p_filter, psz_parser ); vlc_object_attach( p_filter , p_aout ); - p_filter->request_vout.pf_request_vout = RequestVoutFromFilter; - p_filter->request_vout.p_private = p_input; - p_filter->p_owner = malloc( sizeof(*p_filter->p_owner) ); p_filter->p_owner->p_aout = p_aout; p_filter->p_owner->p_input = p_input; /* request format */ - memcpy( &p_filter->input, &chain_output_format, + memcpy( &p_filter->fmt_in.audio, &chain_output_format, sizeof(audio_sample_format_t) ); - memcpy( &p_filter->output, &chain_output_format, + p_filter->fmt_in.i_codec = chain_output_format.i_format; + memcpy( &p_filter->fmt_out.audio, &chain_output_format, sizeof(audio_sample_format_t) ); - + p_filter->fmt_out.i_codec = chain_output_format.i_format; + p_filter->pf_audio_buffer_new = aout_FilterBufferNew; /* try to find the requested filter */ if( i_visual == 2 ) /* this can only be a visualization module */ { - p_filter->p_module = module_need( p_filter, "visualization", + p_filter->p_module = module_need( p_filter, "visualization2", psz_parser, true ); } else /* this can be a audio filter module as well as a visualization module */ @@ -314,13 +311,13 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_ if ( p_filter->p_module == NULL ) { /* if the filter requested a special format, retry */ - if ( !( AOUT_FMTS_IDENTICAL( &p_filter->input, + if ( !( AOUT_FMTS_IDENTICAL( &p_filter->fmt_in.audio, &chain_input_format ) - && AOUT_FMTS_IDENTICAL( &p_filter->output, + && AOUT_FMTS_IDENTICAL( &p_filter->fmt_out.audio, &chain_output_format ) ) ) { - aout_FormatPrepare( &p_filter->input ); - aout_FormatPrepare( &p_filter->output ); + aout_FormatPrepare( &p_filter->fmt_in.audio ); + aout_FormatPrepare( &p_filter->fmt_out.audio ); p_filter->p_module = module_need( p_filter, "audio filter", psz_parser, true ); @@ -328,12 +325,12 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_ /* try visual filters */ else { - memcpy( &p_filter->input, &chain_output_format, + memcpy( &p_filter->fmt_in.audio, &chain_output_format, sizeof(audio_sample_format_t) ); - memcpy( &p_filter->output, &chain_output_format, + memcpy( &p_filter->fmt_out.audio, &chain_output_format, sizeof(audio_sample_format_t) ); p_filter->p_module = module_need( p_filter, - "visualization", + "visualization2", psz_parser, true ); } } @@ -346,7 +343,6 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_ psz_parser ); free( p_filter->p_owner ); - vlc_object_detach( p_filter ); vlc_object_release( p_filter ); psz_parser = psz_next; @@ -354,19 +350,19 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_ } /* complete the filter chain if necessary */ - if ( !AOUT_FMTS_IDENTICAL( &chain_input_format, &p_filter->input ) ) + if ( !AOUT_FMTS_IDENTICAL( &chain_input_format, + &p_filter->fmt_in.audio ) ) { if ( aout_FiltersCreatePipeline( p_aout, p_input->pp_filters, &p_input->i_nb_filters, &chain_input_format, - &p_filter->input ) < 0 ) + &p_filter->fmt_in.audio ) < 0 ) { msg_Err( p_aout, "cannot add user filter %s (skipped)", psz_parser ); module_unneed( p_filter, p_filter->p_module ); free( p_filter->p_owner ); - vlc_object_detach( p_filter ); vlc_object_release( p_filter ); psz_parser = psz_next; @@ -375,9 +371,8 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_ } /* success */ - p_filter->b_continuity = false; p_input->pp_filters[p_input->i_nb_filters++] = p_filter; - memcpy( &chain_input_format, &p_filter->output, + memcpy( &chain_input_format, &p_filter->fmt_out.audio, sizeof( audio_sample_format_t ) ); if( i_visual == 0 ) /* scaletempo */ @@ -434,7 +429,7 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_ p_input->input_alloc.b_alloc = true; /* Setup the initial rate of the resampler */ - p_input->pp_resamplers[0]->input.i_rate = p_input->input.i_rate; + p_input->pp_resamplers[0]->fmt_in.audio.i_rate = p_input->input.i_rate; } p_input->i_resampling_type = AOUT_RESAMPLING_NONE; @@ -459,7 +454,6 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_ /* Success */ p_input->b_error = false; - p_input->b_restart = false; p_input->i_last_input_rate = INPUT_RATE_DEFAULT; return 0; @@ -496,48 +490,53 @@ int aout_InputDelete( aout_instance_t * p_aout, aout_input_t * p_input ) } /***************************************************************************** - * aout_InputPlay : play a buffer + * aout_InputCheckAndRestart : restart an input ***************************************************************************** - * This function must be entered with the input lock. + * This function must be entered with the input and mixer lock. *****************************************************************************/ -/* XXX Do not activate it !! */ -//#define AOUT_PROCESS_BEFORE_CHEKS -int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input, - aout_buffer_t * p_buffer, int i_input_rate ) +void aout_InputCheckAndRestart( aout_instance_t * p_aout, aout_input_t * p_input ) { - mtime_t start_date; + AOUT_ASSERT_MIXER_LOCKED; AOUT_ASSERT_INPUT_LOCKED; - if( p_input->b_restart ) - { - aout_fifo_t fifo; - uint8_t *p_first_byte_to_mix; - bool b_paused; - mtime_t i_pause_date; + if( !p_input->b_restart ) + return; - aout_lock_mixer( p_aout ); - aout_lock_input_fifos( p_aout ); + aout_lock_input_fifos( p_aout ); - /* A little trick to avoid loosing our input fifo and properties */ + /* A little trick to avoid loosing our input fifo and properties */ - p_first_byte_to_mix = p_input->mixer.begin; - fifo = p_input->mixer.fifo; - b_paused = p_input->b_paused; - i_pause_date = p_input->i_pause_date; + uint8_t *p_first_byte_to_mix = p_input->mixer.begin; + aout_fifo_t fifo = p_input->mixer.fifo; + bool b_paused = p_input->b_paused; + mtime_t i_pause_date = p_input->i_pause_date; - aout_FifoInit( p_aout, &p_input->mixer.fifo, p_aout->mixer_format.i_rate ); + aout_FifoInit( p_aout, &p_input->mixer.fifo, p_aout->mixer_format.i_rate ); - aout_InputDelete( p_aout, p_input ); + aout_InputDelete( p_aout, p_input ); - aout_InputNew( p_aout, p_input, &p_input->request_vout ); - p_input->mixer.begin = p_first_byte_to_mix; - p_input->mixer.fifo = fifo; - p_input->b_paused = b_paused; - p_input->i_pause_date = i_pause_date; + aout_InputNew( p_aout, p_input, &p_input->request_vout ); + p_input->mixer.begin = p_first_byte_to_mix; + p_input->mixer.fifo = fifo; + p_input->b_paused = b_paused; + p_input->i_pause_date = i_pause_date; - aout_unlock_input_fifos( p_aout ); - aout_unlock_mixer( p_aout ); - } + p_input->b_restart = false; + + aout_unlock_input_fifos( p_aout ); +} +/***************************************************************************** + * aout_InputPlay : play a buffer + ***************************************************************************** + * This function must be entered with the input lock. + *****************************************************************************/ +/* XXX Do not activate it !! */ +//#define AOUT_PROCESS_BEFORE_CHEKS +int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input, + aout_buffer_t * p_buffer, int i_input_rate ) +{ + mtime_t start_date; + AOUT_ASSERT_INPUT_LOCKED; if( i_input_rate != INPUT_RATE_DEFAULT && p_input->p_playback_rate_filter == NULL ) { @@ -549,19 +548,23 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input, /* Run pre-filters. */ aout_FiltersPlay( p_aout, p_input->pp_filters, p_input->i_nb_filters, &p_buffer ); + if( !p_buffer ) + return 0; /* Actually run the resampler now. */ if ( p_input->i_nb_resamplers > 0 ) { - const mtime_t i_date = p_buffer->start_date; + const mtime_t i_date = p_buffer->i_pts; aout_FiltersPlay( p_aout, p_input->pp_resamplers, p_input->i_nb_resamplers, &p_buffer ); } + if( !p_buffer ) + return 0; if( p_buffer->i_nb_samples <= 0 ) { - aout_BufferFree( p_buffer ); + block_Release( p_buffer ); return 0; } #endif @@ -569,7 +572,7 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input, /* Handle input rate change, but keep drift correction */ if( i_input_rate != p_input->i_last_input_rate ) { - unsigned int * const pi_rate = &p_input->p_playback_rate_filter->input.i_rate; + unsigned int * const pi_rate = &p_input->p_playback_rate_filter->fmt_in.audio.i_rate; #define F(r,ir) ( INPUT_RATE_DEFAULT * (r) / (ir) ) const int i_delta = *pi_rate - F(p_input->input.i_rate,p_input->i_last_input_rate); *pi_rate = F(p_input->input.i_rate + i_delta, i_input_rate); @@ -598,15 +601,16 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input, if ( p_input->i_resampling_type != AOUT_RESAMPLING_NONE ) msg_Warn( p_aout, "timing screwed, stopping resampling" ); inputResamplingStop( p_input ); + p_buffer->i_flags |= BLOCK_FLAG_DISCONTINUITY; start_date = 0; } - if ( p_buffer->start_date < mdate() + AOUT_MIN_PREPARE_TIME ) + if ( p_buffer->i_pts < mdate() + AOUT_MIN_PREPARE_TIME ) { /* The decoder gives us f*cked up PTS. It's its business, but we * can't present it anyway, so drop the buffer. */ msg_Warn( p_aout, "PTS is out of range (%"PRId64"), dropping buffer", - mdate() - p_buffer->start_date ); + mdate() - p_buffer->i_pts ); inputDrop( p_input, p_buffer ); inputResamplingStop( p_input ); @@ -617,10 +621,10 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input, * the audio. */ mtime_t i_pts_tolerance = 3 * AOUT_PTS_TOLERANCE * i_input_rate / INPUT_RATE_DEFAULT; if ( start_date != 0 && - ( start_date < p_buffer->start_date - i_pts_tolerance ) ) + ( start_date < p_buffer->i_pts - i_pts_tolerance ) ) { msg_Warn( p_aout, "audio drift is too big (%"PRId64"), clearing out", - start_date - p_buffer->start_date ); + start_date - p_buffer->i_pts ); aout_lock_input_fifos( p_aout ); aout_FifoSet( p_aout, &p_input->mixer.fifo, 0 ); p_input->mixer.begin = NULL; @@ -628,30 +632,32 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input, if ( p_input->i_resampling_type != AOUT_RESAMPLING_NONE ) msg_Warn( p_aout, "timing screwed, stopping resampling" ); inputResamplingStop( p_input ); + p_buffer->i_flags |= BLOCK_FLAG_DISCONTINUITY; start_date = 0; } else if ( start_date != 0 && - ( start_date > p_buffer->start_date + i_pts_tolerance) ) + ( start_date > p_buffer->i_pts + i_pts_tolerance) ) { msg_Warn( p_aout, "audio drift is too big (%"PRId64"), dropping buffer", - start_date - p_buffer->start_date ); + start_date - p_buffer->i_pts ); inputDrop( p_input, p_buffer ); return 0; } - if ( start_date == 0 ) start_date = p_buffer->start_date; + if ( start_date == 0 ) start_date = p_buffer->i_pts; #ifndef AOUT_PROCESS_BEFORE_CHEKS /* Run pre-filters. */ - aout_FiltersPlay( p_aout, p_input->pp_filters, p_input->i_nb_filters, - &p_buffer ); + aout_FiltersPlay( p_input->pp_filters, p_input->i_nb_filters, &p_buffer ); + if( !p_buffer ) + return 0; #endif /* Run the resampler if needed. * We first need to calculate the output rate of this resampler. */ if ( ( p_input->i_resampling_type == AOUT_RESAMPLING_NONE ) && - ( start_date < p_buffer->start_date - AOUT_PTS_TOLERANCE - || start_date > p_buffer->start_date + AOUT_PTS_TOLERANCE ) && + ( start_date < p_buffer->i_pts - AOUT_PTS_TOLERANCE + || start_date > p_buffer->i_pts + AOUT_PTS_TOLERANCE ) && p_input->i_nb_resamplers > 0 ) { /* Can happen in several circumstances : @@ -661,7 +667,7 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input, * synchronization * Solution : resample the buffer to avoid a scratch. */ - mtime_t drift = p_buffer->start_date - start_date; + mtime_t drift = p_buffer->i_pts - start_date; p_input->i_resamp_start_date = mdate(); p_input->i_resamp_start_drift = (int)drift; @@ -685,11 +691,11 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input, if( p_input->i_resampling_type == AOUT_RESAMPLING_UP ) { - p_input->pp_resamplers[0]->input.i_rate += 2; /* Hz */ + p_input->pp_resamplers[0]->fmt_in.audio.i_rate += 2; /* Hz */ } else { - p_input->pp_resamplers[0]->input.i_rate -= 2; /* Hz */ + p_input->pp_resamplers[0]->fmt_in.audio.i_rate -= 2; /* Hz */ } /* Check if everything is back to normal, in which case we can stop the @@ -698,15 +704,15 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input, (p_input->pp_resamplers[0] == p_input->p_playback_rate_filter) ? INPUT_RATE_DEFAULT * p_input->input.i_rate / i_input_rate : p_input->input.i_rate; - if( p_input->pp_resamplers[0]->input.i_rate == i_nominal_rate ) + if( p_input->pp_resamplers[0]->fmt_in.audio.i_rate == i_nominal_rate ) { p_input->i_resampling_type = AOUT_RESAMPLING_NONE; msg_Warn( p_aout, "resampling stopped after %"PRIi64" usec " "(drift: %"PRIi64")", mdate() - p_input->i_resamp_start_date, - p_buffer->start_date - start_date); + p_buffer->i_pts - start_date); } - else if( abs( (int)(p_buffer->start_date - start_date) ) < + else if( abs( (int)(p_buffer->i_pts - start_date) ) < abs( p_input->i_resamp_start_drift ) / 2 ) { /* if we reduced the drift from half, then it is time to switch @@ -718,13 +724,14 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input, p_input->i_resamp_start_drift = 0; } else if( p_input->i_resamp_start_drift && - ( abs( (int)(p_buffer->start_date - start_date) ) > + ( abs( (int)(p_buffer->i_pts - start_date) ) > abs( p_input->i_resamp_start_drift ) * 3 / 2 ) ) { /* If the drift is increasing and not decreasing, than something * is bad. We'd better stop the resampling right now. */ msg_Warn( p_aout, "timing screwed, stopping resampling" ); inputResamplingStop( p_input ); + p_buffer->i_flags |= BLOCK_FLAG_DISCONTINUITY; } } @@ -732,22 +739,21 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input, /* Actually run the resampler now. */ if ( p_input->i_nb_resamplers > 0 ) { - aout_FiltersPlay( p_aout, p_input->pp_resamplers, - p_input->i_nb_resamplers, + aout_FiltersPlay( p_input->pp_resamplers, p_input->i_nb_resamplers, &p_buffer ); } + if( !p_buffer ) + return 0; if( p_buffer->i_nb_samples <= 0 ) { - aout_BufferFree( p_buffer ); + block_Release( p_buffer ); return 0; } #endif /* Adding the start date will be managed by aout_FifoPush(). */ - p_buffer->end_date = start_date + - (p_buffer->end_date - p_buffer->start_date); - p_buffer->start_date = start_date; + p_buffer->i_pts = start_date; aout_lock_input_fifos( p_aout ); aout_FifoPush( p_aout, &p_input->mixer.fifo, p_buffer ); @@ -797,11 +803,10 @@ static void inputResamplingStop( aout_input_t *p_input ) p_input->i_resampling_type = AOUT_RESAMPLING_NONE; if( p_input->i_nb_resamplers != 0 ) { - p_input->pp_resamplers[0]->input.i_rate = + p_input->pp_resamplers[0]->fmt_in.audio.i_rate = ( p_input->pp_resamplers[0] == p_input->p_playback_rate_filter ) ? INPUT_RATE_DEFAULT * p_input->input.i_rate / p_input->i_last_input_rate : p_input->input.i_rate; - p_input->pp_resamplers[0]->b_continuity = false; } } @@ -810,17 +815,27 @@ static vout_thread_t *RequestVout( void *p_private, { aout_instance_t *p_aout = p_private; VLC_UNUSED(b_recycle); - return vout_Request( p_aout, p_vout, p_fmt ); + vout_configuration_t cfg = { + .vout = p_vout, + .input = NULL, + .fmt = p_fmt, + }; + return vout_Request( p_aout, &cfg ); } -static vout_thread_t *RequestVoutFromFilter( void *p_private, - vout_thread_t *p_vout, video_format_t *p_fmt, bool b_recycle ) +vout_thread_t *aout_filter_RequestVout( filter_t *p_filter, + vout_thread_t *p_vout, video_format_t *p_fmt ) { - aout_input_t *p_input = p_private; + aout_input_t *p_input = p_filter->p_owner->p_input; aout_request_vout_t *p_request = &p_input->request_vout; + /* XXX: this only works from audio input */ + /* If you want to use visualization filters from another place, you will + * need to add a new pf_aout_request_vout callback or store a pointer + * to aout_request_vout_t inside filter_t (i.e. a level of indirection). */ + return p_request->pf_request_vout( p_request->p_private, - p_vout, p_fmt, p_input->b_recycle_vout && b_recycle ); + p_vout, p_fmt, p_input->b_recycle_vout ); } static int ChangeFiltersString( aout_instance_t * p_aout, const char* psz_variable,