]> git.sesse.net Git - vlc/blobdiff - modules/audio_output/kai.c
audioqueue: clean-up
[vlc] / modules / audio_output / kai.c
index 5f7d0a0311c657736b3ab0cb18eccc6b59b01d6b..f5b04463ed56e833d56c4d3936c8a42f14d08fba 100644 (file)
@@ -1,23 +1,23 @@
 /*****************************************************************************
  * kai.c : KAI audio output plugin for vlc
  *****************************************************************************
- * Copyright (C) 2010 the VideoLAN team
+ * Copyright (C) 2010 VLC authors and VideoLAN
  *
  * Authors: KO Myung-Hun <komh@chollian.net>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -47,6 +47,9 @@ struct aout_sys_t
 {
     aout_packet_t   packet;
     HKAI            hkai;
+    float           soft_gain;
+    bool            soft_mute;
+    audio_sample_format_t format;
 };
 
 /*****************************************************************************
@@ -58,6 +61,8 @@ static void Play  ( audio_output_t *_p_aout, block_t *block );
 
 static ULONG APIENTRY KaiCallback ( PVOID, PVOID, ULONG );
 
+#include "volume.h"
+
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
@@ -85,8 +90,8 @@ vlc_module_begin ()
     set_subcategory( SUBCAT_AUDIO_AOUT )
     add_string( "kai-audio-device", ppsz_kai_audio_device[0],
                 KAI_AUDIO_DEVICE_TEXT, KAI_AUDIO_DEVICE_LONGTEXT, false )
-        change_string_list( ppsz_kai_audio_device, ppsz_kai_audio_device_text,
-                            0 )
+        change_string_list( ppsz_kai_audio_device, ppsz_kai_audio_device_text )
+    add_sw_gain( )
     add_bool( "kai-audio-exclusive-mode", false,
               KAI_AUDIO_EXCLUSIVE_MODE_TEXT, KAI_AUDIO_EXCLUSIVE_MODE_LONGTEXT,
               true )
@@ -96,25 +101,16 @@ vlc_module_end ()
 /*****************************************************************************
  * Open: open the audio device
  *****************************************************************************/
-static int Open ( vlc_object_t *p_this )
+static int Start ( audio_output_t *p_aout, audio_sample_format_t *fmt )
 {
-    audio_output_t *p_aout = (audio_output_t *)p_this;
-    aout_sys_t *p_sys;
+    aout_sys_t *p_sys = p_aout->sys;
     char *psz_mode;
     ULONG i_kai_mode;
     KAISPEC ks_wanted, ks_obtained;
     int i_nb_channels;
     int i_bytes_per_frame;
     vlc_value_t val, text;
-    audio_format_t format =  p_aout->format;
-
-    /* Allocate structure */
-    p_aout->sys = calloc( 1, sizeof( aout_sys_t ) );
-
-    if( p_aout->sys == NULL )
-        return VLC_ENOMEM;
-
-    p_sys = p_aout->sys;
+    audio_sample_format_t format = *fmt;
 
     if( var_Get( p_aout, "audio-device", &val ) != VLC_ENOVAR )
     {
@@ -153,8 +149,8 @@ static int Open ( vlc_object_t *p_this )
             = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
     }
 
-    /* Support s16l only */
-    format.i_format = VLC_CODEC_S16L;
+    /* Support S16 only */
+    format.i_format = VLC_CODEC_S16N;
 
     aout_FormatPrepare( &format );
 
@@ -165,7 +161,7 @@ static int Open ( vlc_object_t *p_this )
     {
         msg_Err( p_aout, "cannot initialize KAI");
 
-        goto exit_free_sys;
+        return VLC_EGENERIC;
     }
 
     ks_wanted.usDeviceIndex   = 0;
@@ -197,15 +193,17 @@ static int Open ( vlc_object_t *p_this )
     msg_Dbg( p_aout, "obtained i_bytes_per_frame = %d",
              format.i_bytes_per_frame );
 
-    p_aout->format   = format;
+    p_sys->format = *fmt = format;
+
+    p_aout->time_get = aout_PacketTimeGet;
+    p_aout->play  = Play;
+    p_aout->pause = NULL;
+    p_aout->flush = aout_PacketFlush;
 
-    p_aout->pf_play  = Play;
-    p_aout->pf_pause = aout_PacketPause;
-    p_aout->pf_flush = aout_PacketFlush;
+    aout_SoftVolumeStart( p_aout );
 
     aout_PacketInit( p_aout, &p_sys->packet,
-                     ks_obtained.ulBufferSize / i_bytes_per_frame );
-    aout_VolumeSoftInit( p_aout );
+                     ks_obtained.ulBufferSize / i_bytes_per_frame, &format );
 
     if ( var_Type( p_aout, "audio-device" ) == 0 )
     {
@@ -241,9 +239,6 @@ static int Open ( vlc_object_t *p_this )
 exit_kai_done :
     kaiDone();
 
-exit_free_sys :
-    free( p_sys );
-
     return VLC_EGENERIC;
 }
 
@@ -262,16 +257,14 @@ static void Play (audio_output_t *p_aout, block_t *block)
 /*****************************************************************************
  * Close: close the audio device
  *****************************************************************************/
-static void Close ( vlc_object_t *p_this )
+static void Stop ( audio_output_t *p_aout )
 {
-    audio_output_t *p_aout = (audio_output_t *)p_this;
     aout_sys_t *p_sys = p_aout->sys;
 
     kaiClose( p_sys->hkai );
     kaiDone();
 
     aout_PacketDestroy( p_aout );
-    free( p_sys );
 }
 
 /*****************************************************************************
@@ -282,6 +275,7 @@ static ULONG APIENTRY KaiCallback( PVOID p_cb_data,
                                    ULONG i_buf_size )
 {
     audio_output_t *p_aout = (audio_output_t *)p_cb_data;
+    aout_sys_t *sys = p_aout->sys;
     block_t  *p_aout_buffer;
     mtime_t current_date, next_date;
     ULONG i_len;
@@ -291,9 +285,9 @@ static ULONG APIENTRY KaiCallback( PVOID p_cb_data,
      * remaining buffer.
      */
     next_date = mdate() + ( i_buf_size * 1000000LL
-                                       / p_aout->format.i_bytes_per_frame
-                                       / p_aout->format.i_rate
-                                       * p_aout->format.i_frame_length );
+                                       / sys->format.i_bytes_per_frame
+                                       / sys->format.i_rate
+                                       * sys->format.i_frame_length );
 
     for (i_len = 0; i_len < i_buf_size;)
     {
@@ -336,3 +330,26 @@ static ULONG APIENTRY KaiCallback( PVOID p_cb_data,
 
     return i_buf_size;
 }
+
+static int Open (vlc_object_t *obj)
+{
+    audio_output_t *aout = (audio_output_t *)obj;
+    aout_sys_t *sys = calloc( 1, sizeof( aout_sys_t ) );
+
+    if( unlikely( sys == NULL ))
+        return VLC_ENOMEM;
+
+    aout->sys = sys;
+    aout->start = Start;
+    aout->stop = Stop;
+    aout_SoftVolumeInit( aout );
+    return VLC_SUCCESS;
+}
+
+static void Close( vlc_object_t *obj )
+{
+    audio_output_t *aout = (audio_output_t *)obj;
+    aout_sys_t *sys = aout->sys;
+
+    free(sys);
+}