Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Unified Diff: media/audio/android/opensles_output.cc

Issue 2795743003: Enable high latency audio on Android N+ for basic playback.
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/audio/android/opensles_output.h ('k') | media/audio/audio_manager_base.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/android/opensles_output.cc
diff --git a/media/audio/android/opensles_output.cc b/media/audio/android/opensles_output.cc
index e6062362fad53b13538d52c5031e22e860d7d951..76f6165ecd0de2093f560ac2af5e0ee5b8d1156b 100644
--- a/media/audio/android/opensles_output.cc
+++ b/media/audio/android/opensles_output.cc
@@ -4,6 +4,7 @@
#include "media/audio/android/opensles_output.h"
+#include "base/android/build_info.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/time/time.h"
@@ -20,6 +21,26 @@
} \
} while (0)
+#if !defined(SL_ANDROID_KEY_PERFORMANCE_MODE)
+/** Audio Performance mode key */
+#define SL_ANDROID_KEY_PERFORMANCE_MODE \
+ ((const SLchar*)"androidPerformanceMode")
+
+/** Audio performance values */
+/* No specific performance requirement. Allows HW and SW pre/post
+ * processing. */
+#define SL_ANDROID_PERFORMANCE_NONE ((SLuint32)0x00000000)
+/* Priority given to latency. No HW or software pre/post processing.
+ * This is the default if no performance mode is specified. */
+#define SL_ANDROID_PERFORMANCE_LATENCY ((SLuint32)0x00000001)
+/* Priority given to latency while still allowing HW pre and post
+ * processing. */
+#define SL_ANDROID_PERFORMANCE_LATENCY_EFFECTS ((SLuint32)0x00000002)
+/* Priority given to power saving if latency is not a concern.
+ * Allows HW and SW pre/post processing. */
+#define SL_ANDROID_PERFORMANCE_POWER_SAVING ((SLuint32)0x00000003)
+#endif
+
namespace media {
OpenSLESOutputStream::OpenSLESOutputStream(AudioManagerAndroid* manager,
@@ -38,6 +59,7 @@ OpenSLESOutputStream::OpenSLESOutputStream(AudioManagerAndroid* manager,
muted_(false),
volume_(1.0),
samples_per_second_(params.sample_rate()),
+ use_high_latency_(params.latency_tag() == AudioLatency::LATENCY_PLAYBACK),
delay_calculator_(samples_per_second_) {
DVLOG(2) << "OpenSLESOutputStream::OpenSLESOutputStream("
<< "stream_type=" << stream_type << ")";
@@ -50,6 +72,11 @@ OpenSLESOutputStream::OpenSLESOutputStream(AudioManagerAndroid* manager,
format_.endianness = SL_BYTEORDER_LITTLEENDIAN;
format_.channelMask = ChannelCountToSLESChannelMask(params.channels());
audio_bus_ = AudioBus::Create(params);
+
+ if (use_high_latency_) {
+ LOG(ERROR) << "Enabling high latency audio with buffer size: "
+ << params.frames_per_buffer();
+ }
}
OpenSLESOutputStream::~OpenSLESOutputStream() {
@@ -272,12 +299,22 @@ bool OpenSLESOutputStream::CreatePlayer() {
// Set configuration using the stream type provided at construction.
LOG_ON_FAILURE_AND_RETURN(
- (*player_config)->SetConfiguration(player_config,
- SL_ANDROID_KEY_STREAM_TYPE,
- &stream_type_,
- sizeof(SLint32)),
+ (*player_config)
+ ->SetConfiguration(player_config, SL_ANDROID_KEY_STREAM_TYPE,
+ &stream_type_, sizeof(SLint32)),
false);
+ // Set configuration using the stream type provided at construction.
+ if (use_high_latency_ && base::android::BuildInfo::GetInstance()->sdk_int() >=
+ base::android::SDK_VERSION_NOUGAT) {
+ SLuint32 perf_mode = SL_ANDROID_PERFORMANCE_POWER_SAVING;
+ LOG_ON_FAILURE_AND_RETURN(
+ (*player_config)
+ ->SetConfiguration(player_config, SL_ANDROID_KEY_PERFORMANCE_MODE,
+ &perf_mode, sizeof(SLuint32)),
+ false);
+ }
+
// Realize the player object in synchronous mode.
LOG_ON_FAILURE_AND_RETURN(
player_object_->Realize(player_object_.Get(), SL_BOOLEAN_FALSE), false);
« no previous file with comments | « media/audio/android/opensles_output.h ('k') | media/audio/audio_manager_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698