Enables detailed logging during variable speed playback.

This commit adds support for dynamically enabling logging in the
variable speed library if log.tag.VariableSpeed is set.

After this change, you can enable logging by running:

adb shell setprop log.tag.VariableSpeed 1

Logging will be disabled after reboot or after running:

adb shell setprop log.tag.VariableSpeed ""

The logging in the library is quite verbose, so we do not want to enable
it by default.

Bug: 5253004
Change-Id: I3addde5552093eb0c4926b67245d578a7da0fb7a
diff --git a/variablespeed/jni/variablespeed.cc b/variablespeed/jni/variablespeed.cc
index 6162242..88eb783 100644
--- a/variablespeed/jni/variablespeed.cc
+++ b/variablespeed/jni/variablespeed.cc
@@ -26,6 +26,8 @@
 
 #include <vector>
 
+#include <sys/system_properties.h>
+
 // ****************************************************************************
 // Constants, utility methods, structures and other miscellany used throughout
 // this file.
@@ -91,6 +93,18 @@
   CHECK(SL_RESULT_SUCCESS == result);
 }
 
+// Whether logging should be enabled. Only used if LOG_OPENSL_API_CALL is
+// defined to use it.
+bool gLogEnabled = false;
+// The property to set in order to enable logging.
+const char *const kLogTagVariableSpeed = "log.tag.VariableSpeed";
+
+bool ShouldLog() {
+  char buffer[PROP_VALUE_MAX];
+  __system_property_get(kLogTagVariableSpeed, buffer);
+  return strlen(buffer) > 0;
+}
+
 }  // namespace
 
 // ****************************************************************************
@@ -155,8 +169,8 @@
 // ****************************************************************************
 // Macros for making working with OpenSL easier.
 
-// #define LOG_OPENSL_API_CALL(string) LOGV(string)
-#define LOG_OPENSL_API_CALL(string) false
+// Log based on the value of a property.
+#define LOG_OPENSL_API_CALL(string) (gLogEnabled && LOGV(string))
 
 // The regular macro: log an api call, make the api call, check the result.
 #define OpenSL(obj, method, ...) \
@@ -285,6 +299,8 @@
       audioStreamType_(audioStreamType),
       totalDurationMs_(0), decoderCurrentPosition_(0), startRequested_(false),
       stopRequested_(false), finishedDecoding_(false) {
+  // Determine whether we should log calls.
+  gLogEnabled = ShouldLog();
 }
 
 AudioEngine::~AudioEngine() {