[RFC 15/15] android/client-audio: Fix getting audio module on Android

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Getting audio module results with -EADDRINUSE on socket binding when
running on Android. Therefore we need to stop mediaserver for
successfull connection.
---
 android/client/if-audio.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/android/client/if-audio.c b/android/client/if-audio.c
index 66f8364..71f9dad 100644
--- a/android/client/if-audio.c
+++ b/android/client/if-audio.c
@@ -99,6 +99,9 @@ static void init_p(int argc, const char **argv)
 	int err;
 	const hw_module_t *module;
 	audio_hw_device_t *device;
+	int timeout = 1500; /* in ms */
+	int t = 300;
+
 
 	err = hw_get_module_by_class(AUDIO_HARDWARE_MODULE_ID,
 					AUDIO_HARDWARE_MODULE_ID_A2DP, &module);
@@ -107,8 +110,27 @@ static void init_p(int argc, const char **argv)
 		return;
 	}
 
+init_audio:
 	err = audio_hw_device_open(module, &device);
 	if (err) {
+		if (err == -EADDRINUSE && t < timeout) {
+			int err2;
+
+			/* We need to Stop media server to bind to socket. */
+			haltest_info("Trying to stop media server...\n");
+
+			err2 = system("/system/bin/setprop ctl.stop media");
+			if (err2) {
+				haltest_error("audio_hw_device_open returned",
+								" %d\n", err);
+				return;
+			}
+
+			usleep(t);
+			t += t;
+			goto init_audio;
+		}
+
 		haltest_error("audio_hw_device_open returned %d\n", err);
 		return;
 	}
@@ -358,6 +380,9 @@ static void cleanup_p(int argc, const char **argv)
 	}
 
 	if_audio = NULL;
+
+	/* get the media server back up and running */
+	err = system("/system/bin/setprop ctl.start media");
 }
 
 static void suspend_p(int argc, const char **argv)
-- 
1.8.5.2

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux