# include "config.h"
#endif
+#include <assert.h>
+
#include <vlc_common.h>
#include <stdio.h>
#include <vlc_input.h>
#include <vlc_vout.h> /* for vout_Request */
+#include <vlc_modules.h>
-#ifdef HAVE_ALLOCA_H
-# include <alloca.h>
-#endif
#include <vlc_aout.h>
+#include <vlc_filter.h>
#include <libvlc.h>
#include "aout_internal.h"
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
p_input->i_nb_resamplers = p_input->i_nb_filters = 0;
/* Prepare FIFO. */
- aout_FifoInit( p_aout, &p_input->mixer.fifo, p_aout->p_mixer->fmt.i_rate );
+ aout_FifoInit( p_aout, &p_input->mixer.fifo, p_aout->mixer_format.i_rate );
p_input->mixer.begin = NULL;
/* */
/* Prepare format structure */
chain_input_format = p_input->input;
- chain_output_format = p_aout->p_mixer->fmt;
+ chain_output_format = p_aout->mixer_format;
chain_output_format.i_rate = p_input->input.i_rate;
aout_FormatPrepare( &chain_output_format );
var_Create( p_aout, "audio-replay-gain-peak-protection",
VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
}
- if( var_Type( p_aout, "audio-time-stretch" ) == 0 )
- {
- var_Create( p_aout, "audio-time-stretch",
- VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
- }
psz_filters = var_GetString( p_aout, "audio-filter" );
psz_visual = var_GetString( p_aout, "audio-visual");
- psz_scaletempo = var_GetBool( p_aout, "audio-time-stretch" ) ? strdup( "scaletempo" ) : NULL;
+ psz_scaletempo = var_InheritBool( p_aout, "audio-time-stretch" ) ? strdup( "scaletempo" ) : NULL;
p_input->b_recycle_vout = psz_visual && *psz_visual;
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 )
{
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 */
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 );
/* 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 );
}
}
psz_parser );
free( p_filter->p_owner );
- vlc_object_detach( p_filter );
vlc_object_release( p_filter );
psz_parser = psz_next;
}
/* 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;
}
/* 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 */
}
/* Prepare hints for the buffer allocator. */
- p_input->input_alloc.i_alloc_type = AOUT_ALLOC_HEAP;
+ p_input->input_alloc.b_alloc = true;
p_input->input_alloc.i_bytes_per_sec = -1;
/* Create resamplers. */
- if ( !AOUT_FMT_NON_LINEAR( &p_aout->p_mixer->fmt ) )
+ if ( !AOUT_FMT_NON_LINEAR( &p_aout->mixer_format ) )
{
chain_output_format.i_rate = (__MAX(p_input->input.i_rate,
- p_aout->p_mixer->fmt.i_rate)
+ p_aout->mixer_format.i_rate)
* (100 + AOUT_MAX_RESAMPLING)) / 100;
- if ( chain_output_format.i_rate == p_aout->p_mixer->fmt.i_rate )
+ if ( chain_output_format.i_rate == p_aout->mixer_format.i_rate )
{
/* Just in case... */
chain_output_format.i_rate++;
if ( aout_FiltersCreatePipeline( p_aout, p_input->pp_resamplers,
&p_input->i_nb_resamplers,
&chain_output_format,
- &p_aout->p_mixer->fmt ) < 0 )
+ &p_aout->mixer_format ) < 0 )
{
inputFailure( p_aout, p_input, "couldn't set a resampler pipeline");
return -1;
aout_FiltersHintBuffers( p_aout, p_input->pp_resamplers,
p_input->i_nb_resamplers,
&p_input->input_alloc );
- p_input->input_alloc.i_alloc_type = AOUT_ALLOC_HEAP;
+ 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;
aout_FiltersHintBuffers( p_aout, p_input->pp_filters,
p_input->i_nb_filters,
&p_input->input_alloc );
- p_input->input_alloc.i_alloc_type = AOUT_ALLOC_HEAP;
+ p_input->input_alloc.b_alloc = true;
/* i_bytes_per_sec is still == -1 if no filters */
p_input->input_alloc.i_bytes_per_sec = __MAX(
/* Success */
p_input->b_error = false;
- p_input->b_restart = false;
p_input->i_last_input_rate = INPUT_RATE_DEFAULT;
return 0;
}
/*****************************************************************************
- * 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->p_mixer->fmt.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 )
{
/* 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
/* 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);
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 );
* 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;
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 :
* 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;
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
(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
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;
}
}
/* 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 );
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;
}
}
{
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,
+ .change_fmt = true,
+ .fmt = p_fmt,
+ .dpb_size = 1,
+ };
+ 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,
const char *psz_name, bool b_add )
{
- return AoutChangeFilterString( VLC_OBJECT(p_aout), p_aout,
- psz_variable, psz_name, b_add ) ? 1 : 0;
+ return aout_ChangeFilterString( VLC_OBJECT(p_aout), p_aout,
+ psz_variable, psz_name, b_add ) ? 1 : 0;
}
static int VisualizationCallback( vlc_object_t *p_this, char const *psz_cmd,