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

Side by Side Diff: webkit/media/android/audio_decoder_android.cc

Issue 14522002: Handle decoding of vorbis files better on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 7 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 unified diff | Download patch
« no previous file with comments | « webkit/glue/webkitplatformsupport_impl.cc ('k') | webkit/media/audio_decoder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/media/audio_decoder.h" 5 #include "webkit/media/audio_decoder.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <limits.h> 9 #include <limits.h>
10 #include <sys/mman.h> 10 #include <sys/mman.h>
11 #include <unistd.h> 11 #include <unistd.h>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/file_descriptor_posix.h" 15 #include "base/file_descriptor_posix.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/posix/eintr_wrapper.h" 17 #include "base/posix/eintr_wrapper.h"
18 #include "base/shared_memory.h" 18 #include "base/shared_memory.h"
19 #include "media/base/android/webaudio_media_codec_info.h"
19 #include "media/base/audio_bus.h" 20 #include "media/base/audio_bus.h"
20 #include "media/base/limits.h" 21 #include "media/base/limits.h"
21 #include "third_party/WebKit/Source/Platform/chromium/public/WebAudioBus.h" 22 #include "third_party/WebKit/Source/Platform/chromium/public/WebAudioBus.h"
22 23
23 namespace webkit_media { 24 namespace webkit_media {
24 25
25 class AudioDecoderIO { 26 class AudioDecoderIO {
26 public: 27 public:
27 AudioDecoderIO(const char* data, size_t data_size); 28 AudioDecoderIO(const char* data, size_t data_size);
28 ~AudioDecoderIO(); 29 ~AudioDecoderIO();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 base::SharedMemoryHandle encoded_data_handle; 112 base::SharedMemoryHandle encoded_data_handle;
112 audio_decoder.ShareEncodedToProcess(&encoded_data_handle); 113 audio_decoder.ShareEncodedToProcess(&encoded_data_handle);
113 base::FileDescriptor fd(audio_decoder.write_fd(), true); 114 base::FileDescriptor fd(audio_decoder.write_fd(), true);
114 115
115 DVLOG(1) << "DecodeAudioFileData: Starting MediaCodec"; 116 DVLOG(1) << "DecodeAudioFileData: Starting MediaCodec";
116 117
117 // Start MediaCodec processing in the browser which will read from 118 // Start MediaCodec processing in the browser which will read from
118 // encoded_data_handle for our shared memory and write the decoded 119 // encoded_data_handle for our shared memory and write the decoded
119 // PCM samples (16-bit integer) to our pipe. 120 // PCM samples (16-bit integer) to our pipe.
120 121
121 runner.Run(encoded_data_handle, fd); 122 runner.Run(encoded_data_handle, fd, data_size);
122 123
123 // First, read the number of channels, the sample rate, and the 124 // First, read the number of channels, the sample rate, and the
124 // number of frames and a flag indicating if the file is an 125 // number of frames and a flag indicating if the file is an
125 // ogg/vorbis file. This must be coordinated with 126 // ogg/vorbis file. This must be coordinated with
126 // WebAudioMediaCodecBridge! 127 // WebAudioMediaCodecBridge!
127 // 128 //
128 // TODO(rtoy): If we know the number of samples, we can create the 129 // TODO(rtoy): If we know the number of samples, we can create the
129 // destination bus directly and do the conversion directly to the 130 // destination bus directly and do the conversion directly to the
130 // bus instead of buffering up everything before saving the data to 131 // bus instead of buffering up everything before saving the data to
131 // the bus. 132 // the bus.
132 133
133 int input_fd = audio_decoder.read_fd(); 134 int input_fd = audio_decoder.read_fd();
134 unsigned long info[4]; 135 struct media::WebAudioMediaCodecInfo info;
135 136
136 DVLOG(1) << "Reading audio file info from fd " << input_fd; 137 DVLOG(1) << "Reading audio file info from fd " << input_fd;
137 ssize_t nread = HANDLE_EINTR(read(input_fd, info, sizeof(info))); 138 ssize_t nread = HANDLE_EINTR(read(input_fd, &info, sizeof(info)));
138 DVLOG(1) << "read: " << nread << " bytes:\n" 139 DVLOG(1) << "read: " << nread << " bytes:\n"
139 << " 0: number of channels = " << info[0] << "\n" 140 << " 0: number of channels = " << info.channel_count << "\n"
140 << " 1: sample rate = " << info[1] << "\n" 141 << " 1: sample rate = " << info.sample_rate << "\n"
141 << " 2: number of frames = " << info[2] << "\n" 142 << " 2: number of frames = " << info.number_of_frames << "\n";
142 << " 3: is vorbis = " << info[3];
143 143
144 if (nread != sizeof(info)) 144 if (nread != sizeof(info))
145 return false; 145 return false;
146 146
147 unsigned number_of_channels = info[0]; 147 unsigned number_of_channels = info.channel_count;
148 double file_sample_rate = static_cast<double>(info[1]); 148 double file_sample_rate = static_cast<double>(info.sample_rate);
149 149
150 // Sanity checks 150 // Sanity checks
151 if (!number_of_channels || 151 if (!number_of_channels ||
152 number_of_channels > media::limits::kMaxChannels || 152 number_of_channels > media::limits::kMaxChannels ||
153 file_sample_rate < media::limits::kMinSampleRate || 153 file_sample_rate < media::limits::kMinSampleRate ||
154 file_sample_rate > media::limits::kMaxSampleRate) { 154 file_sample_rate > media::limits::kMaxSampleRate) {
155 return false; 155 return false;
156 } 156 }
157 157
158 int16_t pipe_data[PIPE_BUF / sizeof(int16_t)]; 158 int16_t pipe_data[PIPE_BUF / sizeof(int16_t)];
(...skipping 29 matching lines...) Expand all
188 destination_bus->channelData(k)[decoded_frames] = 188 destination_bus->channelData(k)[decoded_frames] =
189 sample * (sample < 0 ? kMinScale : kMaxScale); 189 sample * (sample < 0 ? kMinScale : kMaxScale);
190 } 190 }
191 ++decoded_frames; 191 ++decoded_frames;
192 } 192 }
193 193
194 return true; 194 return true;
195 } 195 }
196 196
197 } // namespace webkit_media 197 } // namespace webkit_media
OLDNEW
« no previous file with comments | « webkit/glue/webkitplatformsupport_impl.cc ('k') | webkit/media/audio_decoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698