[vlc-commits] opensles: implement mute/volume set

Rafaël Carré git at videolan.org
Sun Dec 16 17:25:03 CET 2012


vlc | branch: master | Rafaël Carré <funman at videolan.org> | Sun Dec 16 17:23:15 2012 +0100| [2762deeca977e0ae03a0a96fcdcac95eebac29c2] | committer: Rafaël Carré

opensles: implement mute/volume set

link with libm, and also with libdl which is needed

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=2762deeca977e0ae03a0a96fcdcac95eebac29c2
---

 modules/audio_output/Modules.am         |   10 ++++++---
 modules/audio_output/opensles_android.c |   36 ++++++++++++++++++++++++++++---
 2 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/modules/audio_output/Modules.am b/modules/audio_output/Modules.am
index 7ebd6d4..49c5ce7 100644
--- a/modules/audio_output/Modules.am
+++ b/modules/audio_output/Modules.am
@@ -1,13 +1,17 @@
 SOURCES_waveout = waveout.c windows_audio_common.h packet.c
 SOURCES_auhal = TPCircularBuffer.h TPCircularBuffer.c auhal.c packet.c
 SOURCES_audioqueue = audioqueue.c packet.c
-SOURCES_opensles_android = opensles_android.c
+
+libopensles_android_plugin_la_SOURCES = opensles_android.c
+libopensles_android_plugin_la_CFLAGS = $(AM_CFLAGS)
+libopensles_android_plugin_la_LIBADD = $(AM_LIBADD) -ldl
 
 libandroid_audiotrack_plugin_la_SOURCES = audiotrack.c
 libandroid_audiotrack_plugin_la_CFLAGS = $(AM_CFLAGS)
-libandroid_audiotrack_plugin_la_LIBADD = $(AM_LIBADD) -ldl
+libandroid_audiotrack_plugin_la_LIBADD = $(AM_LIBADD) -ldl -lm
+
 if HAVE_ANDROID
-libvlc_LTLIBRARIES += libandroid_audiotrack_plugin.la
+libvlc_LTLIBRARIES += libandroid_audiotrack_plugin.la libopensles_android_plugin.la
 endif
 
 libadummy_plugin_la_SOURCES = adummy.c
diff --git a/modules/audio_output/opensles_android.c b/modules/audio_output/opensles_android.c
index 762fd60..147d44a 100644
--- a/modules/audio_output/opensles_android.c
+++ b/modules/audio_output/opensles_android.c
@@ -35,6 +35,7 @@
 #include <vlc_aout.h>
 #include <assert.h>
 #include <dlfcn.h>
+#include <math.h>
 
 // For native audio
 #include <SLES/OpenSLES.h>
@@ -52,6 +53,8 @@
 #define Clear(a) (*a)->Clear(a)
 #define GetState(a, b) (*a)->GetState(a, b)
 #define SetPositionUpdatePeriod(a, b) (*a)->SetPositionUpdatePeriod(a, b)
+#define SetVolumeLevel(a, b) (*a)->SetVolumeLevel(a, b)
+#define SetMute(a, b) (*a)->SetMute(a, b)
 
 /*****************************************************************************
  * aout_sys_t: audio output method descriptor
@@ -65,6 +68,7 @@ struct aout_sys_t
     SLObjectItf                     outputMixObject;
     SLAndroidSimpleBufferQueueItf   playerBufferQueue;
     SLObjectItf                     playerObject;
+    SLVolumeItf                     volumeItf;
 
     SLPlayItf                       playerPlay;
 
@@ -155,6 +159,28 @@ static void Flush(audio_output_t *p_aout, bool drain)
     }
 }
 
+static int VolumeSet(audio_output_t *aout, float vol)
+{
+    /* Convert UI volume to linear factor (cube) */
+    vol = vol * vol * vol;
+
+    /* millibels from linear amplification */
+    int mb = lroundf(2000.f * log10f(vol));
+    if (mb < SL_MILLIBEL_MIN)
+        mb = SL_MILLIBEL_MIN;
+    else if (mb > 0)
+        mb = 0; /* maximum supported level could be higher: GetMaxVolumeLevel */
+
+    SLresult r = SetVolumeLevel(aout->sys->volumeItf, mb);
+    return (r == SL_RESULT_SUCCESS) ? 0 : -1;
+}
+
+static int MuteSet(audio_output_t *aout, bool mute)
+{
+    SLresult r = SetMute(aout->sys->volumeItf, mute);
+    return (r == SL_RESULT_SUCCESS) ? 0 : -1;
+}
+
 static void Pause(audio_output_t *p_aout, bool pause, mtime_t date)
 {
     (void)date;
@@ -388,8 +414,8 @@ static int Start( audio_output_t *p_aout, audio_sample_format_t *restrict fmt )
     SLDataSink audioSnk = {&loc_outmix, NULL};
 
     //create audio player
-    const SLInterfaceID ids2[] = { *SL_IID_ANDROIDSIMPLEBUFFERQUEUE };
-    static const SLboolean req2[] = { SL_BOOLEAN_TRUE };
+    const SLInterfaceID ids2[] = { *SL_IID_ANDROIDSIMPLEBUFFERQUEUE, *SL_IID_VOLUME };
+    static const SLboolean req2[] = { SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE };
     result = CreateAudioPlayer( engineEngine, &p_sys->playerObject, &audioSrc,
                                     &audioSnk, sizeof( ids2 ) / sizeof( *ids2 ),
                                     ids2, req2 );
@@ -401,6 +427,9 @@ static int Start( audio_output_t *p_aout, audio_sample_format_t *restrict fmt )
     result = GetInterface( p_sys->playerObject, *SL_IID_PLAY, &p_sys->playerPlay );
     CHECK_OPENSL_ERROR( "Failed to get player interface." );
 
+    result = GetInterface( p_sys->playerObject, *SL_IID_VOLUME, &p_sys->volumeItf );
+    CHECK_OPENSL_ERROR( "failed to get volume interface." );
+
     result = GetInterface( p_sys->playerObject, *SL_IID_ANDROIDSIMPLEBUFFERQUEUE,
                                                   &p_sys->playerBufferQueue );
     CHECK_OPENSL_ERROR( "Failed to get buff queue interface" );
@@ -409,7 +438,6 @@ static int Start( audio_output_t *p_aout, audio_sample_format_t *restrict fmt )
                                    (void*)p_aout);
     CHECK_OPENSL_ERROR( "Failed to register buff queue callback." );
 
-
     // set the player's state to playing
     result = SetPlayState( p_sys->playerPlay, SL_PLAYSTATE_PLAYING );
     CHECK_OPENSL_ERROR( "Failed to switch to playing state" );
@@ -426,6 +454,8 @@ static int Start( audio_output_t *p_aout, audio_sample_format_t *restrict fmt )
     p_aout->play               = Play;
     p_aout->pause              = Pause;
     p_aout->flush              = Flush;
+    p_aout->mute_set           = MuteSet;
+    p_aout->volume_set         = VolumeSet;
 
     SetPositionUpdatePeriod( p_sys->playerPlay, AOUT_MIN_PREPARE_TIME * 1000 / CLOCK_FREQ);
 



More information about the vlc-commits mailing list