[Android] native audiotrack: add synchronisation and pause support
Rafaël Carré
git at videolan.org
Wed Jun 20 21:00:48 CEST 2012
android | branch: master | Rafaël Carré <funman at videolan.org> | Wed Jun 20 20:59:30 2012 +0200| [c7d10e49bd7a19113243654babf52bcd1cfe1292] | committer: Rafaël Carré
native audiotrack: add synchronisation and pause support
Pause by Dominique Martinet <asmadeus at codewreck.org>
> http://git.videolan.org/gitweb.cgi/android.git/?a=commit;h=c7d10e49bd7a19113243654babf52bcd1cfe1292
---
...Android-add-native-AudioTrack-aout-module.patch | 58 +++++++++++++++-----
1 file changed, 45 insertions(+), 13 deletions(-)
diff --git a/patches/0002-Android-add-native-AudioTrack-aout-module.patch b/patches/0002-Android-add-native-AudioTrack-aout-module.patch
index 61c87a3..a8eacd7 100644
--- a/patches/0002-Android-add-native-AudioTrack-aout-module.patch
+++ b/patches/0002-Android-add-native-AudioTrack-aout-module.patch
@@ -1,21 +1,21 @@
-From 3c946805a63828f4b7d5ee4a7d99a8546c74213c Mon Sep 17 00:00:00 2001
+From f812e399247f80d7d65b06da96b34ec332b276f0 Mon Sep 17 00:00:00 2001
From: Ming Hu <tewilove at gmail.com>
Date: Sun, 13 May 2012 22:20:34 +0200
-Subject: [PATCH 2/3] Android: add native AudioTrack aout module
+Subject: [PATCH 2/4] Android: add native AudioTrack aout module
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
---
configure.ac | 12 ++
modules/audio_output/Modules.am | 1 +
- modules/audio_output/audiotrack.c | 302 +++++++++++++++++++++++++++++++++++++
- 3 files changed, 315 insertions(+)
+ modules/audio_output/audiotrack.c | 333 +++++++++++++++++++++++++++++++++++++
+ 3 files changed, 346 insertions(+)
create mode 100644 modules/audio_output/audiotrack.c
diff --git a/configure.ac b/configure.ac
-index 8765b14..1bf7692 100644
+index 3b66640..5e0619b 100644
--- a/configure.ac
+++ b/configure.ac
-@@ -3536,6 +3536,18 @@ if test "${HAVE_ANDROID}" = "1"; then
+@@ -3538,6 +3538,18 @@ if test "${HAVE_ANDROID}" = "1"; then
fi
dnl
@@ -48,10 +48,10 @@ index ea30d4d..85f2b3d 100644
libadummy_plugin_la_CFLAGS = $(AM_CFLAGS)
diff --git a/modules/audio_output/audiotrack.c b/modules/audio_output/audiotrack.c
new file mode 100644
-index 0000000..78289af
+index 0000000..555b0b8
--- /dev/null
+++ b/modules/audio_output/audiotrack.c
-@@ -0,0 +1,301 @@
+@@ -0,0 +1,333 @@
+/*****************************************************************************
+ * audiotrack.c: Android native AudioTrack audio output module
+ *****************************************************************************
@@ -140,6 +140,8 @@ index 0000000..78289af
+typedef int (*AudioTrack_write)(void *, void const*, unsigned int);
+// _ZN7android10AudioTrack5flushEv
+typedef int (*AudioTrack_flush)(void *);
++// _ZN7android10AudioTrack5pauseEv
++typedef int (*AudioTrack_pause)(void *);
+
+struct aout_sys_t {
+ void *libmedia;
@@ -158,6 +160,7 @@ index 0000000..78289af
+ AudioTrack_stop at_stop;
+ AudioTrack_write at_write;
+ AudioTrack_flush at_flush;
++ AudioTrack_pause at_pause;
+};
+
+static void *InitLibrary(struct aout_sys_t *p_sys);
@@ -165,6 +168,7 @@ index 0000000..78289af
+static int Open(vlc_object_t *);
+static void Close(vlc_object_t *);
+static void Play(audio_output_t *, block_t *);
++static void Pause (audio_output_t *, bool, mtime_t);
+
+vlc_module_begin ()
+ set_shortname("AudioTrack")
@@ -176,7 +180,8 @@ index 0000000..78289af
+ set_callbacks(Open, Close)
+vlc_module_end ()
+
-+static void *InitLibrary(struct aout_sys_t *p_sys) {
++static void *InitLibrary(struct aout_sys_t *p_sys)
++{
+ /* DL Open libmedia */
+ void *p_library;
+ p_library = dlopen("libmedia.so", RTLD_NOW);
@@ -196,6 +201,7 @@ index 0000000..78289af
+ p_sys->at_stop = (AudioTrack_stop)(dlsym(p_library, "_ZN7android10AudioTrack4stopEv"));
+ p_sys->at_write = (AudioTrack_write)(dlsym(p_library, "_ZN7android10AudioTrack5writeEPKvj"));
+ p_sys->at_flush = (AudioTrack_flush)(dlsym(p_library, "_ZN7android10AudioTrack5flushEv"));
++ p_sys->at_pause = (AudioTrack_pause)(dlsym(p_library, "_ZN7android10AudioTrack5pauseEv"));
+
+ /* We need the first 3 or the last 1 */
+ if (!((p_sys->as_getOutputFrameCount && p_sys->as_getOutputLatency && p_sys->as_getOutputSamplingRate)
@@ -213,7 +219,8 @@ index 0000000..78289af
+ return p_library;
+}
+
-+static int Open(vlc_object_t *p_this) {
++static int Open(vlc_object_t *p_this)
++{
+ struct aout_sys_t *p_sys;
+ audio_output_t *p_aout = (audio_output_t*)(p_this);
+
@@ -325,13 +332,15 @@ index 0000000..78289af
+
+ p_aout->sys = p_sys;
+ p_aout->pf_play = Play;
++ p_aout->pf_pause = Pause;
+
+ p_sys->at_start(p_sys->AudioTrack);
+
+ return VLC_SUCCESS;
+}
+
-+static void Close(vlc_object_t *p_this) {
++static void Close(vlc_object_t *p_this)
++{
+ audio_output_t *p_aout = (audio_output_t*)p_this;
+ aout_sys_t *p_sys = p_aout->sys;
+
@@ -343,9 +352,21 @@ index 0000000..78289af
+ free(p_sys);
+}
+
-+static void Play(audio_output_t *p_aout, block_t *p_buffer) {
++static void Play(audio_output_t *p_aout, block_t *p_buffer)
++{
+ aout_sys_t *p_sys = p_aout->sys;
+
++ uint32_t latency;
++ int ret = p_sys->as_getOutputLatency(&latency, MUSIC);
++ if (!ret) {
++ mtime_t delay = latency * CLOCK_FREQ / 100;
++ if (latency != 55)
++ msg_Dbg(p_aout, "latency %d", latency);
++ aout_TimeReport(p_aout, p_buffer->i_pts - delay);
++ } else {
++ msg_Err(p_aout, "Could not get latency");
++ }
++
+ size_t length = 0;
+ while (length < p_buffer->i_buffer) {
+ length += p_sys->at_write(p_sys->AudioTrack, (char*)(p_buffer->p_buffer) + length, p_buffer->i_buffer - length);
@@ -353,6 +374,17 @@ index 0000000..78289af
+
+ block_Release( p_buffer );
+}
++
++static void Pause(audio_output_t *p_aout, bool pause, mtime_t date)
++{
++ aout_sys_t *p_sys = p_aout->sys;
++
++ if (pause) {
++ p_sys->at_pause(p_sys->AudioTrack);
++ } else {
++ p_sys->at_start(p_sys->AudioTrack);
++ }
++}
--
-1.7.5.4
+1.7.9.5
More information about the Android
mailing list