Commit 297aefb7 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont
Browse files

aout: move packet FIFO management to plugins that need it

parent af6b8c3b
......@@ -175,7 +175,6 @@ struct audio_output
void (* pf_flush)( audio_output_t *, bool ); /**< Flush/drain callback
(optional, may be NULL) */
aout_volume_cb pf_volume_set; /**< Volume setter (or NULL) */
int i_nb_samples;
};
/**
......
......@@ -44,7 +44,6 @@ vlc_module_begin ()
add_shortcut( "dummy" )
vlc_module_end ()
#define FRAME_SIZE 2048
#define A52_FRAME_NB 1536
/*****************************************************************************
......@@ -73,7 +72,6 @@ static int Open( vlc_object_t * p_this )
}
else
p_aout->format.i_format = HAVE_FPU ? VLC_CODEC_FL32 : VLC_CODEC_S16N;
p_aout->i_nb_samples = A52_FRAME_NB;
/* Create the variable for the audio-device */
var_Create( p_aout, "audio-device", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
......
......@@ -52,6 +52,7 @@
*****************************************************************************/
struct aout_sys_t
{
aout_packet_t packet;
snd_pcm_t * p_snd_pcm;
unsigned int i_period_time;
......@@ -344,7 +345,7 @@ static int Open (vlc_object_t *obj)
pcm_format = SND_PCM_FORMAT_S16;
channels = 2;
p_aout->i_nb_samples = i_period_size = ALSA_SPDIF_PERIOD_SIZE;
i_period_size = ALSA_SPDIF_PERIOD_SIZE;
p_aout->format.i_bytes_per_frame = AOUT_SPDIF_SIZE;
p_aout->format.i_frame_length = A52_FRAME_NB;
......@@ -355,7 +356,7 @@ static int Open (vlc_object_t *obj)
i_buffer_size = ALSA_DEFAULT_BUFFER_SIZE;
channels = aout_FormatNbChannels( &p_aout->format );
p_aout->i_nb_samples = i_period_size = ALSA_DEFAULT_PERIOD_SIZE;
i_period_size = ALSA_DEFAULT_PERIOD_SIZE;
aout_VolumeSoftInit( p_aout );
}
......@@ -433,7 +434,6 @@ static int Open (vlc_object_t *obj)
snd_strerror( val ) );
goto error;
}
p_aout->i_nb_samples = i_period_size;
/* Set buffer size. */
val = snd_pcm_hw_params_set_buffer_size_near( p_sys->p_snd_pcm, p_hw,
......@@ -466,8 +466,7 @@ static int Open (vlc_object_t *obj)
/* Get Initial software parameters */
snd_pcm_sw_params_current( p_sys->p_snd_pcm, p_sw );
snd_pcm_sw_params_set_avail_min( p_sys->p_snd_pcm, p_sw,
p_aout->i_nb_samples );
snd_pcm_sw_params_set_avail_min( p_sys->p_snd_pcm, p_sw, i_period_size );
/* start playing when one period has been written */
val = snd_pcm_sw_params_set_start_threshold( p_sys->p_snd_pcm, p_sw,
ALSA_DEFAULT_PERIOD_SIZE);
......@@ -495,6 +494,7 @@ static int Open (vlc_object_t *obj)
p_sys->start_date = 0;
vlc_sem_init( &p_sys->wait, 0 );
aout_PacketInit (p_aout, &p_sys->packet, i_period_size);
/* Create ALSA thread and wait for its readiness. */
if( vlc_clone( &p_sys->thread, ALSAThread, p_aout,
......@@ -549,6 +549,7 @@ static void Close (vlc_object_t *obj)
vlc_cancel( p_sys->thread );
vlc_join( p_sys->thread, NULL );
vlc_sem_destroy( &p_sys->wait );
aout_PacketDestroy (p_aout);
snd_pcm_drop( p_sys->p_snd_pcm );
snd_pcm_close( p_sys->p_snd_pcm );
......
......@@ -35,7 +35,6 @@
#include <AudioToolBox/AudioToolBox.h>
#define FRAME_SIZE 2048
#define NUMBER_OF_BUFFERS 3
/*****************************************************************************
......@@ -46,6 +45,7 @@
*****************************************************************************/
struct aout_sys_t
{
aout_packet_t packet;
AudioQueueRef audioQueue;
};
......@@ -121,7 +121,7 @@ static int Open ( vlc_object_t *p_this )
p_aout->format.i_format = VLC_CODEC_S16L;
p_aout->format.i_physical_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
p_aout->format.i_rate = 44100;
p_aout->format.i_nb_samples = FRAME_SIZE;
aout_PacketInit(p_aout, &p_sys->packet, FRAME_SIZE);
p_aout->pf_play = aout_PacketPlay;
p_aout->pf_pause = aout_PacketPause;
p_aout->pf_flush = aout_PacketFlush;
......@@ -144,6 +144,7 @@ static void Close ( vlc_object_t *p_this )
AudioQueueStop(p_sys->audioQueue, false);
msg_Dbg(p_aout, "Disposing of AudioQueue");
AudioQueueDispose(p_sys->audioQueue, false);
aout_PacketDestroy(p_aout);
free (p_sys);
}
......
......@@ -79,6 +79,7 @@
*****************************************************************************/
struct aout_sys_t
{
aout_packet_t packet;
AudioDeviceID i_default_dev; /* Keeps DeviceID of defaultOutputDevice */
AudioDeviceID i_selected_dev; /* Keeps DeviceID of the selected device */
AudioDeviceIOProcID i_procID; /* DeviceID of current device */
......@@ -566,7 +567,7 @@ static int OpenAnalog( audio_output_t *p_aout )
/* Do the last VLC aout setups */
aout_FormatPrepare( &p_aout->format );
p_aout->i_nb_samples = FRAMESIZE;
aout_PacketInit( p_aout, &p_sys->packet, FRAMESIZE );
aout_VolumeSoftInit( p_aout );
/* set the IOproc callback */
......@@ -782,9 +783,9 @@ static int OpenSPDIF( audio_output_t * p_aout )
p_aout->format.i_format = VLC_CODEC_SPDIFL;
p_aout->format.i_bytes_per_frame = AOUT_SPDIF_SIZE;
p_aout->format.i_frame_length = A52_FRAME_NB;
p_aout->i_nb_samples = p_aout->format.i_frame_length;
p_aout->format.i_rate = (unsigned int)p_sys->stream_format.mSampleRate;
aout_FormatPrepare( &p_aout->format );
aout_PacketInit( p_aout, &p_sys->packet, A52_FRAME_NB );
aout_VolumeNoneInit( p_aout );
/* Add IOProc callback */
......@@ -904,6 +905,7 @@ static void Close( vlc_object_t * p_this )
if( err != noErr ) msg_Err( p_aout, "Could not release hogmode: [%4.4s]", (char *)&err );
}
aout_PacketDestroy( p_aout );
free( p_sys );
}
......
......@@ -64,6 +64,7 @@ typedef struct notification_thread_t
*****************************************************************************/
struct aout_sys_t
{
aout_packet_t packet;
HINSTANCE hdsound_dll; /* handle of the opened dsound dll */
char * psz_device; /* user defined device name */
......@@ -224,7 +225,6 @@ static int OpenAudio( vlc_object_t *p_this )
p_aout->format.i_format = VLC_CODEC_SPDIFL;
/* Calculate the frame size in bytes */
p_aout->i_nb_samples = A52_FRAME_NB;
p_aout->format.i_bytes_per_frame = AOUT_SPDIF_SIZE;
p_aout->format.i_frame_length = A52_FRAME_NB;
p_aout->sys->i_frame_size = p_aout->format.i_bytes_per_frame;
......@@ -241,6 +241,7 @@ static int OpenAudio( vlc_object_t *p_this )
return VLC_EGENERIC;
}
aout_PacketInit( p_aout, &p_sys->packet, A52_FRAME_NB );
aout_VolumeNoneInit( p_aout );
}
else
......@@ -294,8 +295,8 @@ static int OpenAudio( vlc_object_t *p_this )
}
/* Calculate the frame size in bytes */
p_aout->i_nb_samples = FRAME_SIZE;
aout_FormatPrepare( &p_aout->format );
aout_PacketInit( p_aout, &p_sys->packet, FRAME_SIZE );
aout_VolumeSoftInit( p_aout );
}
......@@ -613,6 +614,7 @@ static void CloseAudio( vlc_object_t *p_this )
if( p_sys->hdsound_dll ) FreeLibrary( p_sys->hdsound_dll );
free( p_aout->sys->p_device_guid );
aout_PacketDestroy( p_aout );
free( p_sys );
}
......@@ -1042,7 +1044,7 @@ static void* DirectSoundThread( void *data )
{
DWORD l_read;
int l_queued = 0, l_free_slots;
unsigned i_frame_siz = p_aout->i_nb_samples;
unsigned i_frame_siz = p_sys->packet.samples;
mtime_t mtime = mdate();
int i;
......
......@@ -36,7 +36,6 @@
#include <vlc_codecs.h> /* WAVEHEADER */
#include <vlc_fs.h>
#define FRAME_SIZE 2048
#define A52_FRAME_NB 1536
/*****************************************************************************
......@@ -193,16 +192,12 @@ static int Open( vlc_object_t * p_this )
p_aout->format.i_format = format_int[i];
if ( AOUT_FMT_NON_LINEAR( &p_aout->format ) )
{
p_aout->i_nb_samples = A52_FRAME_NB;
p_aout->format.i_bytes_per_frame = AOUT_SPDIF_SIZE;
p_aout->format.i_frame_length = A52_FRAME_NB;
aout_VolumeNoneInit( p_aout );
}
else
{
p_aout->i_nb_samples = FRAME_SIZE;
aout_VolumeSoftInit( p_aout );
}
/* Channels number */
i_channels = var_CreateGetInteger( p_this, "audiofile-channels" );
......
......@@ -50,6 +50,7 @@ typedef jack_default_audio_sample_t jack_sample_t;
*****************************************************************************/
struct aout_sys_t
{
aout_packet_t packet;
jack_client_t *p_jack_client;
jack_port_t **p_jack_ports;
jack_sample_t **p_jack_buffers;
......@@ -135,12 +136,13 @@ static int Open( vlc_object_t *p_this )
p_aout->pf_play = aout_PacketPlay;
p_aout->pf_pause = aout_PacketPause;
p_aout->pf_flush = aout_PacketFlush;
aout_PacketInit( p_aout, &p_sys->packet,
jack_get_buffer_size( p_sys->p_jack_client ) );
aout_VolumeSoftInit( p_aout );
/* JACK only supports fl32 format */
p_aout->format.i_format = VLC_CODEC_FL32;
// TODO add buffer size callback
p_aout->i_nb_samples = jack_get_buffer_size( p_sys->p_jack_client );
p_aout->format.i_rate = jack_get_sample_rate( p_sys->p_jack_client );
p_sys->i_channels = aout_FormatNbChannels( &p_aout->format );
......@@ -223,9 +225,8 @@ static int Open( vlc_object_t *p_this )
free( pp_in_ports );
}
msg_Dbg( p_aout, "JACK audio output initialized (%d channels, buffer "
"size=%d, rate=%d)", p_sys->i_channels,
p_aout->i_nb_samples, p_aout->format.i_rate );
msg_Dbg( p_aout, "JACK audio output initialized (%d channels, rate=%d)",
p_sys->i_channels, p_aout->format.i_rate );
error_out:
/* Clean up, if an error occurred */
......@@ -352,5 +353,6 @@ static void Close( vlc_object_t *p_this )
}
free( p_sys->p_jack_ports );
free( p_sys->p_jack_buffers );
aout_PacketDestroy( p_aout );
free( p_sys );
}
......@@ -257,7 +257,6 @@ static int Open( vlc_object_t * p_this )
// we want 16bit signed data little endian.
p_aout->format.i_format = VLC_CODEC_S16L;
p_aout->i_nb_samples = 2048;
p_aout->format.i_physical_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
p_aout->pf_play = Play;
p_aout->pf_pause = NULL;
......
......@@ -70,6 +70,7 @@
*****************************************************************************/
struct aout_sys_t
{
aout_packet_t packet;
int i_fd;
int i_fragstotal;
mtime_t max_buffer_duration;
......@@ -381,10 +382,10 @@ static int Open( vlc_object_t *p_this )
}
p_aout->format.i_format = VLC_CODEC_SPDIFL;
p_aout->i_nb_samples = A52_FRAME_NB;
p_aout->format.i_bytes_per_frame = AOUT_SPDIF_SIZE;
p_aout->format.i_frame_length = A52_FRAME_NB;
aout_PacketInit( p_aout, &p_sys->packet, A52_FRAME_NB );
aout_VolumeNoneInit( p_aout );
}
......@@ -485,22 +486,19 @@ static int Open( vlc_object_t *p_this )
free( p_sys );
return VLC_EGENERIC;
}
else
{
/* Number of fragments actually allocated */
p_aout->sys->i_fragstotal = audio_buf.fragstotal;
/* Maximum duration the soundcard's buffer can hold */
p_aout->sys->max_buffer_duration =
/* Number of fragments actually allocated */
p_aout->sys->i_fragstotal = audio_buf.fragstotal;
/* Maximum duration the soundcard's buffer can hold */
p_aout->sys->max_buffer_duration =
(mtime_t)audio_buf.fragstotal * audio_buf.fragsize * 1000000
/ p_aout->format.i_bytes_per_frame
/ p_aout->format.i_rate
* p_aout->format.i_frame_length;
p_aout->i_nb_samples = audio_buf.fragsize /
p_aout->format.i_bytes_per_frame;
}
aout_PacketInit( p_aout, &p_sys->packet,
audio_buf.fragsize/p_aout->format.i_bytes_per_frame );
aout_VolumeSoftInit( p_aout );
}
......@@ -532,6 +530,7 @@ static void Close( vlc_object_t * p_this )
ioctl( p_sys->i_fd, SNDCTL_DSP_RESET, NULL );
close( p_sys->i_fd );
aout_PacketDestroy( p_aout );
free( p_sys );
}
......
......@@ -63,6 +63,7 @@ typedef struct
struct aout_sys_t
{
aout_packet_t packet;
audio_output_t *p_aout;
PaStream *p_stream;
......@@ -328,6 +329,7 @@ static void Close ( vlc_object_t *p_this )
#endif
msg_Dbg( p_aout, "portaudio closed");
aout_PacketDestroy( p_aout );
free( p_sys );
}
......@@ -501,8 +503,8 @@ static int PAOpenStream( audio_output_t *p_aout )
/* Calculate the frame size in bytes */
p_sys->i_sample_size = 4 * i_channels;
p_aout->i_nb_samples = FRAME_SIZE;
aout_FormatPrepare( &p_aout->format );
aout_PacketInit( p_aout, &p_sys->packet, FRAME_SIZE );
aout_VolumeSoftInit( p_aout );
/* Check for channel reordering */
......
......@@ -791,8 +791,6 @@ static int Open(vlc_object_t *obj)
"prebuf=%u, minreq=%u",
pba->maxlength, pba->tlength, pba->prebuf, pba->minreq);
aout->i_nb_samples = pba->minreq / pa_frame_size(&ss);
var_Create(aout, "audio-device", VLC_VAR_INTEGER|VLC_VAR_HASCHOICE);
var_Change(aout, "audio-device", VLC_VAR_SETTEXT,
&(vlc_value_t){ .psz_string = (char *)_("Audio device") },
......
......@@ -111,6 +111,7 @@ vlc_module_end ()
*****************************************************************************/
struct aout_sys_t
{
aout_packet_t packet;
uint32_t i_wave_device_id; /* ID of selected output device */
HWAVEOUT h_waveout; /* handle to waveout instance */
......@@ -234,12 +235,12 @@ static int Open( vlc_object_t *p_this )
}
/* Calculate the frame size in bytes */
p_aout->i_nb_samples = A52_FRAME_NB;
p_aout->format.i_bytes_per_frame = AOUT_SPDIF_SIZE;
p_aout->format.i_frame_length = A52_FRAME_NB;
p_aout->sys->i_buffer_size =
p_aout->format.i_bytes_per_frame;
aout_PacketInit( p_aout, &p_aout->p_sys->packet, A52_FRAME_NB );
aout_VolumeNoneInit( p_aout );
}
else
......@@ -281,11 +282,11 @@ static int Open( vlc_object_t *p_this )
}
/* Calculate the frame size in bytes */
p_aout->i_nb_samples = FRAME_SIZE;
aout_FormatPrepare( &p_aout->format );
p_aout->sys->i_buffer_size = FRAME_SIZE *
p_aout->format.i_bytes_per_frame;
aout_PacketInit( p_aout, &p_aout->p_sys->packet, FRAME_SIZE );
aout_VolumeSoftInit( p_aout );
/* Check for hardware volume support */
......@@ -566,6 +567,7 @@ static void Close( vlc_object_t *p_this )
CloseHandle( p_sys->new_buffer_event);
free( p_sys->p_silence_buffer );
aout_PacketDestroy( p_aout );
free( p_sys );
}
......
......@@ -107,8 +107,6 @@ typedef struct
/* Filters between mixer and output */
filter_t *filters[AOUT_MAX_FILTERS];
int nb_filters;
aout_packet_t packet;
} aout_owner_t;
typedef struct
......
......@@ -161,9 +161,6 @@ int aout_OutputNew( audio_output_t *p_aout,
aout_FormatPrepare( &p_aout->format );
aout_FormatPrint( p_aout, "output", &p_aout->format );
/* Prepare FIFO. */
aout_PacketInit (p_aout, &owner->packet, p_aout->i_nb_samples);
/* Choose the mixer format. */
owner->mixer_format = p_aout->format;
if (AOUT_FMT_NON_LINEAR(&p_aout->format))
......@@ -218,7 +215,6 @@ void aout_OutputDelete( audio_output_t * p_aout )
aout_VolumeNoneInit( p_aout ); /* clear volume callback */
owner->module = NULL;
aout_FiltersDestroyPipeline (owner->filters, owner->nb_filters);
aout_PacketDestroy (p_aout);
}
/*****************************************************************************
......@@ -370,8 +366,7 @@ void aout_VolumeHardSet (audio_output_t *aout, float volume, bool mute)
static inline aout_packet_t *aout_packet (audio_output_t *aout)
{
aout_owner_t *owner = aout_owner (aout);
return &owner->packet;
return (aout_packet_t *)(aout->sys);
}
void aout_PacketInit (audio_output_t *aout, aout_packet_t *p, unsigned samples)
......@@ -444,9 +439,7 @@ static block_t *aout_OutputSlice (audio_output_t *p_aout)
{
aout_packet_t *p = aout_packet (p_aout);
aout_fifo_t *p_fifo = &p->partial;
const unsigned samples = p_aout->i_nb_samples;
/* FIXME: Remove this silly constraint. Just pass buffers as they come to
* "smart" audio outputs. */
const unsigned samples = p->samples;
assert( samples > 0 );
vlc_assert_locked( &p_aout->lock );
......
......@@ -21,6 +21,8 @@ aout_FormatPrepare
aout_FormatPrint
aout_FormatPrintChannels
aout_OutputNextBuffer
aout_PacketInit
aout_PacketDestroy
aout_PacketPlay
aout_PacketPause
aout_PacketFlush
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment