[vlc-devel] [PATCH 4/4] android/audio: move OpenSLES to streams submodules
Thomas Guillem
thomas at gllm.fr
Wed Dec 2 15:44:48 CET 2020
---
modules/audio_output/Makefile.am | 7 +-
modules/audio_output/android/device.c | 6 ++
modules/audio_output/android/device.h | 3 +
modules/audio_output/android/opensles.c | 97 ++++++++++---------------
4 files changed, 51 insertions(+), 62 deletions(-)
diff --git a/modules/audio_output/Makefile.am b/modules/audio_output/Makefile.am
index 3c6713f32ca..35b11e7e3aa 100644
--- a/modules/audio_output/Makefile.am
+++ b/modules/audio_output/Makefile.am
@@ -1,15 +1,14 @@
aoutdir = $(pluginsdir)/audio_output
aout_LTLIBRARIES =
-libopensles_android_plugin_la_SOURCES = audio_output/android/opensles.c
-libopensles_android_plugin_la_LIBADD = $(LIBDL) $(LIBM)
-
libandroid_audio_plugin_la_SOURCES = audio_output/android/audiotrack.c \
+ audio_output/android/opensles.c \
audio_output/android/device.c audio_output/android/device.h \
video_output/android/utils.c video_output/android/utils.h
+libandroid_audio_plugin_la_LIBADD = $(LIBDL) $(LIBM)
if HAVE_ANDROID
-aout_LTLIBRARIES += libandroid_audio_plugin.la libopensles_android_plugin.la
+aout_LTLIBRARIES += libandroid_audio_plugin.la
endif
libadummy_plugin_la_SOURCES = audio_output/adummy.c
diff --git a/modules/audio_output/android/device.c b/modules/audio_output/android/device.c
index 05bd81e003b..c5885d0f9bd 100644
--- a/modules/audio_output/android/device.c
+++ b/modules/audio_output/android/device.c
@@ -298,4 +298,10 @@ vlc_module_begin ()
set_callback(AudioTrack_Start)
add_shortcut("audiotrack")
add_shortcut("android_audiotrack")
+
+ add_submodule()
+ set_capability("aout stream", 170)
+ set_callback(OpenSLES_Start)
+ add_shortcut("opensles")
+ add_shortcut("android_opensles")
vlc_module_end ()
diff --git a/modules/audio_output/android/device.h b/modules/audio_output/android/device.h
index 740e259886c..d65f41103c3 100644
--- a/modules/audio_output/android/device.h
+++ b/modules/audio_output/android/device.h
@@ -61,3 +61,6 @@ typedef int (*aout_stream_start)(aout_stream_t *s, audio_sample_format_t *fmt,
int
AudioTrack_Start(aout_stream_t *, audio_sample_format_t *,
enum android_audio_device_type);
+int
+OpenSLES_Start(aout_stream_t *, audio_sample_format_t *,
+ enum android_audio_device_type);
diff --git a/modules/audio_output/android/opensles.c b/modules/audio_output/android/opensles.c
index 9e90b393d5e..aa4a49e912f 100644
--- a/modules/audio_output/android/opensles.c
+++ b/modules/audio_output/android/opensles.c
@@ -41,6 +41,8 @@
#include <SLES/OpenSLES.h>
#include <SLES/OpenSLES_Android.h>
+#include "device.h"
+
#include <jni.h>
JNIEnv *android_getEnv(vlc_object_t *p_obj, const char *psz_thread_name);
@@ -120,37 +122,16 @@ typedef struct
size_t samples;
} aout_sys_t;
-/*****************************************************************************
- * Local prototypes.
- *****************************************************************************/
-static int Open (vlc_object_t *);
-static void Close (vlc_object_t *);
-
-/*****************************************************************************
- * Module descriptor
- *****************************************************************************/
-
-vlc_module_begin ()
- set_description("OpenSLES audio output")
- set_shortname("OpenSLES")
- set_category(CAT_AUDIO)
- set_subcategory(SUBCAT_AUDIO_AOUT)
-
- set_capability("audio output", 170)
- add_shortcut("opensles", "android")
- set_callbacks(Open, Close)
-vlc_module_end ()
-
-/*****************************************************************************
- *
- *****************************************************************************/
+static int Open (aout_stream_t *);
+static void Close (aout_stream_t *);
+static void Stop (aout_stream_t *);
static inline int bytesPerSample(void)
{
return 2 /* S16 */ * 2 /* stereo */;
}
-static int TimeGet(audio_output_t* aout, vlc_tick_t* restrict drift)
+static int TimeGet(aout_stream_t* aout, vlc_tick_t* restrict drift)
{
aout_sys_t *sys = aout->sys;
@@ -177,7 +158,7 @@ static int TimeGet(audio_output_t* aout, vlc_tick_t* restrict drift)
return 0;
}
-static void Flush(audio_output_t *aout)
+static void Flush(aout_stream_t *aout)
{
aout_sys_t *sys = aout->sys;
@@ -197,11 +178,11 @@ static void Flush(audio_output_t *aout)
vlc_mutex_unlock(&sys->lock);
}
-static int VolumeSet(audio_output_t *aout, float vol)
+static void VolumeSet(aout_stream_t *aout, float vol)
{
aout_sys_t *sys = aout->sys;
if (!sys->volumeItf)
- return -1;
+ return;
/* Convert UI volume to linear factor (cube) */
vol = vol * vol * vol;
@@ -213,21 +194,19 @@ static int VolumeSet(audio_output_t *aout, float vol)
else if (mb > 0)
mb = 0; /* maximum supported level could be higher: GetMaxVolumeLevel */
- SLresult r = SetVolumeLevel(sys->volumeItf, mb);
- return (r == SL_RESULT_SUCCESS) ? 0 : -1;
+ SetVolumeLevel(sys->volumeItf, mb);
}
-static int MuteSet(audio_output_t *aout, bool mute)
+static void MuteSet(aout_stream_t *aout, bool mute)
{
aout_sys_t *sys = aout->sys;
if (!sys->volumeItf)
- return -1;
+ return;
- SLresult r = SetMute(sys->volumeItf, mute);
- return (r == SL_RESULT_SUCCESS) ? 0 : -1;
+ SetMute(sys->volumeItf, mute);
}
-static void Pause(audio_output_t *aout, bool pause, vlc_tick_t date)
+static void Pause(aout_stream_t *aout, bool pause, vlc_tick_t date)
{
(void)date;
aout_sys_t *sys = aout->sys;
@@ -235,7 +214,7 @@ static void Pause(audio_output_t *aout, bool pause, vlc_tick_t date)
pause ? SL_PLAYSTATE_PAUSED : SL_PLAYSTATE_PLAYING);
}
-static int WriteBuffer(audio_output_t *aout)
+static int WriteBuffer(aout_stream_t *aout)
{
aout_sys_t *sys = aout->sys;
const size_t unit_size = sys->samples_per_buf * bytesPerSample();
@@ -318,7 +297,7 @@ static int WriteBuffer(audio_output_t *aout)
/*****************************************************************************
* Play: play a sound
*****************************************************************************/
-static void Play(audio_output_t *aout, block_t *p_buffer, vlc_tick_t date)
+static void Play(aout_stream_t *aout, block_t *p_buffer, vlc_tick_t date)
{
aout_sys_t *sys = aout->sys;
@@ -341,7 +320,7 @@ static void Play(audio_output_t *aout, block_t *p_buffer, vlc_tick_t date)
static void PlayedCallback (SLAndroidSimpleBufferQueueItf caller, void *pContext)
{
(void)caller;
- audio_output_t *aout = pContext;
+ aout_stream_t *aout = pContext;
aout_sys_t *sys = aout->sys;
assert (caller == sys->playerBufferQueue);
@@ -351,7 +330,7 @@ static void PlayedCallback (SLAndroidSimpleBufferQueueItf caller, void *pContext
vlc_mutex_unlock(&sys->lock);
}
-static int aout_get_native_sample_rate(audio_output_t *aout)
+static int aout_get_native_sample_rate(aout_stream_t *aout)
{
JNIEnv *p_env;
if (!(p_env = android_getEnv(VLC_OBJECT(aout), "opensles")))
@@ -375,11 +354,17 @@ static int aout_get_native_sample_rate(audio_output_t *aout)
/*****************************************************************************
*
*****************************************************************************/
-static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
+int OpenSLES_Start(aout_stream_t *aout, audio_sample_format_t *restrict fmt,
+ enum android_audio_device_type adev)
{
+ (void) adev;
if (aout_FormatNbChannels(fmt) == 0 || !AOUT_FMT_LINEAR(fmt))
return VLC_EGENERIC;
+ int ret = Open(aout);
+ if (ret != VLC_SUCCESS)
+ return ret;
+
SLresult result;
aout_sys_t *sys = aout->sys;
@@ -479,6 +464,14 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
aout_FormatPrepare(fmt);
+ aout->stop = Stop;
+ aout->time_get = TimeGet;
+ aout->play = Play;
+ aout->pause = Pause;
+ aout->flush = Flush;
+ aout->mute_set = MuteSet;
+ aout->volume_set = VolumeSet;
+
return VLC_SUCCESS;
error:
@@ -489,11 +482,12 @@ error:
sys->volumeItf = NULL;
sys->playerPlay = NULL;
}
+ Close(aout);
return VLC_EGENERIC;
}
-static void Stop(audio_output_t *aout)
+static void Stop(aout_stream_t *aout)
{
aout_sys_t *sys = aout->sys;
@@ -505,18 +499,15 @@ static void Stop(audio_output_t *aout)
block_ChainRelease(sys->p_buffer_chain);
Destroy(sys->playerObject);
- sys->playerObject = NULL;
- sys->playerBufferQueue = NULL;
- sys->volumeItf = NULL;
- sys->playerPlay = NULL;
+
+ Close(aout);
}
/*****************************************************************************
*
*****************************************************************************/
-static void Close(vlc_object_t *obj)
+static void Close(aout_stream_t *aout)
{
- audio_output_t *aout = (audio_output_t *)obj;
aout_sys_t *sys = aout->sys;
Destroy(sys->outputMixObject);
@@ -525,9 +516,8 @@ static void Close(vlc_object_t *obj)
free(sys);
}
-static int Open (vlc_object_t *obj)
+static int Open (aout_stream_t *aout)
{
- audio_output_t *aout = (audio_output_t *)obj;
aout_sys_t *sys;
SLresult result;
@@ -590,15 +580,6 @@ static int Open (vlc_object_t *obj)
vlc_mutex_init(&sys->lock);
- aout->start = Start;
- aout->stop = Stop;
- aout->time_get = TimeGet;
- aout->play = Play;
- aout->pause = Pause;
- aout->flush = Flush;
- aout->mute_set = MuteSet;
- aout->volume_set = VolumeSet;
-
return VLC_SUCCESS;
error:
--
2.28.0
More information about the vlc-devel
mailing list