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

Unified Diff: content/renderer/media/android/audio_decoder_android.cc

Issue 164023007: Correctly handle any number of channels in WebAudio file decoder on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/media/android/audio_decoder_android.cc
diff --git a/content/renderer/media/android/audio_decoder_android.cc b/content/renderer/media/android/audio_decoder_android.cc
index 97dc22aa98537d584182788ec386f5772025136f..bb3e7687a14135f5d02f1efc2f3219101ce854b7 100644
--- a/content/renderer/media/android/audio_decoder_android.cc
+++ b/content/renderer/media/android/audio_decoder_android.cc
@@ -405,21 +405,30 @@ static void CopyPcmDataToBus(int input_fd,
int16_t pipe_data[PIPE_BUF / sizeof(int16_t)];
size_t decoded_frames = 0;
+ size_t current_sample_in_frame = 0;
ssize_t nread;
while ((nread = HANDLE_EINTR(read(input_fd, pipe_data, sizeof(pipe_data)))) >
0) {
size_t samples_in_pipe = nread / sizeof(int16_t);
- for (size_t m = 0; m < samples_in_pipe; m += number_of_channels) {
+
+ // The pipe may not contain a whole number of frames. This is
+ // especially true if the number of channels is greater than
+ // 2. Thus, keep track of which sample in a frame is being
+ // processed, so we handle the boundary at the end of the pipe
+ // correctly.
+ for (size_t m = 0; m < samples_in_pipe; ++m) {
if (decoded_frames >= number_of_frames)
break;
- for (size_t k = 0; k < number_of_channels; ++k) {
- int16_t sample = pipe_data[m + k];
- destination_bus->channelData(k)[decoded_frames] =
- ConvertSampleToFloat(sample);
+ destination_bus->channelData(current_sample_in_frame)[decoded_frames] =
+ ConvertSampleToFloat(pipe_data[m]);
+ ++current_sample_in_frame;
+
+ if (current_sample_in_frame >= number_of_channels) {
+ current_sample_in_frame = 0;
+ ++decoded_frames;
}
- ++decoded_frames;
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698