]> git.sesse.net Git - vlc/commitdiff
aout: move packet FIFO management to plugins that need it
authorRémi Denis-Courmont <remi@remlab.net>
Thu, 4 Aug 2011 12:36:23 +0000 (15:36 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Thu, 4 Aug 2011 15:16:10 +0000 (18:16 +0300)
16 files changed:
include/vlc_aout.h
modules/audio_output/adummy.c
modules/audio_output/alsa.c
modules/audio_output/audioqueue.c
modules/audio_output/auhal.c
modules/audio_output/directx.c
modules/audio_output/file.c
modules/audio_output/jack.c
modules/audio_output/opensles_android.c
modules/audio_output/oss.c
modules/audio_output/portaudio.c
modules/audio_output/pulse.c
modules/audio_output/waveout.c
src/audio_output/aout_internal.h
src/audio_output/output.c
src/libvlccore.sym

index 102a68b58cf8bb9780103a0d2c8f86f7d803f46c..0d77cb0921801e5b8286cdfd2a4ee1c3103c9e08 100644 (file)
@@ -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;
 };
 
 /**
index f17b8f021972b75b87be65a6d5fa1260b151a682..048b9ec4fbdd6ecb34d95051cf026b7ed03bf2ac 100644 (file)
@@ -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 );
index 2eb6e5d542f23a67886635c0575f1419154e18c9..b0f91667d5df87d58e96bbe7eb6e41b8e2303d3e 100644 (file)
@@ -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 );
index 07f84472fb8cae3302d943cf603c035a2b058833..f7e5c53d59646b6455d2d215c572b88afd8358f8 100644 (file)
@@ -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);
 }
 
index 069979eae9382438d4f72438e321c1216821f5cc..325770cb5a9f6ca83bfa07e44cc54b94f8ed6a05 100644 (file)
@@ -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 );
 }
 
index 1736fc6690c4f4f1d7309b043885fdaaea8778cc..a373a71a4093996635cef46fa8aa99c49a084f5a 100644 (file)
@@ -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;
 
index a9aa5f17133de803b237bf4859520e85db3435f1..2bcca29efae24ee911e3b242a2232afce49f3bbb 100644 (file)
@@ -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" );
index a0257892d56b563843d41a3eeef04cdfde4b8c5e..8a34ceb3f39c94ef0a4abaa35afc5f3b5dae8930 100644 (file)
@@ -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 );
 }
index d53002457247c93bcd8a9af04ea148c8bc34268f..cd343cbb4ace0d6020809683fefdb21529b3d393 100644 (file)
@@ -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;
index 0a888adf74c45abacd171211c78b147ae8fdf7f2..704a70dab75c28753a388a4c1c7a04e719410696 100644 (file)
@@ -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 );
 }
 
index dd65f379b1826c4795d76d9d7efd2cb965e05fb5..797dbeff21b760a92568ebf367b0cc61b88ec518 100644 (file)
@@ -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 */
index ab4a4e0efd2ac5777c0df2551b64cfc99a06b327..3aae9e4c589518834ff631f1315e5ae75671ee72 100644 (file)
@@ -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") },
index 0ff5cb93f6c9459c9c8379c0b3d9140223f35b53..1cd427c66016f65879672cbb1a1442df3d506e55 100644 (file)
@@ -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 );
 }
 
index 0208775d574e789f5f48013508106aef38d2a214..fc30a0b03235fdfc6b9ba917f152d544bc3bb1ed 100644 (file)
@@ -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
index 44c818cbce06b6adfbaaa95990b82d86f3ece8d1..34233cbffc51f9428f9c9bc4ac1b92b38c802a0f 100644 (file)
@@ -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 );
index f5e53181830b527eed347b67f1229391d4e965db..44f2a6127ab35d92ed6b4b12d5841061eb52c7c7 100644 (file)
@@ -21,6 +21,8 @@ aout_FormatPrepare
 aout_FormatPrint
 aout_FormatPrintChannels
 aout_OutputNextBuffer
+aout_PacketInit
+aout_PacketDestroy
 aout_PacketPlay
 aout_PacketPause
 aout_PacketFlush