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

Unified Diff: media/base/android/webaudio_media_codec_bridge.cc

Issue 21618002: Fix slow playback of 1-channel MP3 and AAC files for WebAudio on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 4 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/base/android/webaudio_media_codec_bridge.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/android/webaudio_media_codec_bridge.cc
diff --git a/media/base/android/webaudio_media_codec_bridge.cc b/media/base/android/webaudio_media_codec_bridge.cc
index 6024a5916f5bdf832451662035cbde29478ead6f..94f059a9a1e82f99a47e91ddfcdd768b8c0c4ec7 100644
--- a/media/base/android/webaudio_media_codec_bridge.cc
+++ b/media/base/android/webaudio_media_codec_bridge.cc
@@ -17,6 +17,7 @@
#include "base/basictypes.h"
#include "base/logging.h"
#include "base/posix/eintr_wrapper.h"
+#include "base/stl_util.h"
#include "jni/WebAudioMediaCodecBridge_jni.h"
#include "media/base/android/webaudio_media_codec_info.h"
@@ -148,15 +149,35 @@ void WebAudioMediaCodecBridge::OnChunkDecoded(
JNIEnv* env,
jobject /*java object*/,
jobject buf,
- jint buf_size) {
+ jint buf_size,
+ jint input_channel_count,
+ jint output_channel_count) {
if (buf_size <= 0 || !buf)
return;
int8_t* buffer =
static_cast<int8_t*>(env->GetDirectBufferAddress(buf));
-
size_t count = static_cast<size_t>(buf_size);
+ std::vector<int16_t> decoded_data;
+
+ if (input_channel_count == 1 && output_channel_count == 2) {
+ // See crbug.com/266006. The file has one channel, but the
+ // decoder decided to return two channels. To be consistent with
+ // the number of channels in the file, only send one channel (the
+ // first).
+ int16_t* data = static_cast<int16_t*>(env->GetDirectBufferAddress(buf));
+ int frame_count = buf_size / sizeof(*data) / 2;
+
+ decoded_data.resize(frame_count);
+ for (int k = 0; k < frame_count; ++k) {
+ decoded_data[k] = *data;
+ data += 2;
+ }
+ buffer = reinterpret_cast<int8_t*>(vector_as_array(&decoded_data));
+ DCHECK(buffer);
+ count = frame_count * sizeof(*data);
+ }
// Write out the data to the pipe in small chunks if necessary.
while (count > 0) {
« no previous file with comments | « media/base/android/webaudio_media_codec_bridge.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698