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

Unified Diff: webrtc/modules/audio_device/android/opensles_player.cc

Issue 1440623002: OpenSL ES stability improvements (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: nit Created 5 years, 1 month 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 | « webrtc/modules/audio_device/android/opensles_player.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/modules/audio_device/android/opensles_player.cc
diff --git a/webrtc/modules/audio_device/android/opensles_player.cc b/webrtc/modules/audio_device/android/opensles_player.cc
index b9ccfd594d36dad0d7b85fbe1f8dbd4f16249f09..d1edef227e652c11161250197d1aecc06cc0e1f7 100644
--- a/webrtc/modules/audio_device/android/opensles_player.cc
+++ b/webrtc/modules/audio_device/android/opensles_player.cc
@@ -15,6 +15,7 @@
#include "webrtc/base/arraysize.h"
#include "webrtc/base/checks.h"
#include "webrtc/base/format_macros.h"
+#include "webrtc/base/timeutils.h"
#include "webrtc/modules/audio_device/android/audio_manager.h"
#include "webrtc/modules/audio_device/fine_audio_buffer.h"
@@ -46,7 +47,8 @@ OpenSLESPlayer::OpenSLESPlayer(AudioManager* audio_manager)
engine_(nullptr),
player_(nullptr),
simple_buffer_queue_(nullptr),
- volume_(nullptr) {
+ volume_(nullptr),
+ last_play_time_(0) {
ALOGD("ctor%s", GetThreadInfo().c_str());
// Use native audio output parameters provided by the audio manager and
// define the PCM format structure.
@@ -95,6 +97,7 @@ int OpenSLESPlayer::InitPlayout() {
CreateMix();
initialized_ = true;
buffer_index_ = 0;
+ last_play_time_ = rtc::Time();
return 0;
}
@@ -233,7 +236,16 @@ void OpenSLESPlayer::AllocateDataBuffers() {
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(!simple_buffer_queue_);
RTC_CHECK(audio_device_buffer_);
- bytes_per_buffer_ = audio_parameters_.GetBytesPerBuffer();
+ // Don't use the lowest possible size as native buffer size. Instead,
+ // use 10ms to better match the frame size that WebRTC uses. It will result
+ // in a reduced risk for audio glitches and also in a more "clean" sequence
+ // of callbacks from the OpenSL ES thread in to WebRTC when asking for audio
+ // to render.
+ ALOGD("lowest possible buffer size: %" PRIuS,
+ audio_parameters_.GetBytesPerBuffer());
+ bytes_per_buffer_ = audio_parameters_.GetBytesPerFrame() *
+ audio_parameters_.frames_per_10ms_buffer();
+ RTC_DCHECK_GT(bytes_per_buffer_, audio_parameters_.GetBytesPerBuffer());
ALOGD("native buffer size: %" PRIuS, bytes_per_buffer_);
// Create a modified audio buffer class which allows us to ask for any number
// of samples (and not only multiple of 10ms) to match the native OpenSL ES
@@ -418,6 +430,15 @@ void OpenSLESPlayer::FillBufferQueue() {
}
void OpenSLESPlayer::EnqueuePlayoutData() {
+ // Check delta time between two successive callbacks and provide a warning
+ // if it becomes very large.
+ // TODO(henrika): using 100ms as upper limit but this value is rather random.
+ const uint32_t current_time = rtc::Time();
+ const uint32_t diff = current_time - last_play_time_;
+ if (diff > 100) {
+ ALOGW("Bad OpenSL ES playout timing, dT=%u [ms]", diff);
+ }
+ last_play_time_ = current_time;
// Read audio data from the WebRTC source using the FineAudioBuffer object
// to adjust for differences in buffer size between WebRTC (10ms) and native
// OpenSL ES.
« no previous file with comments | « webrtc/modules/audio_device/android/opensles_player.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698