OLD | NEW |
---|---|
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> |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 base::SharedMemoryHandle encoded_data_handle; | 111 base::SharedMemoryHandle encoded_data_handle; |
112 audio_decoder.ShareEncodedToProcess(&encoded_data_handle); | 112 audio_decoder.ShareEncodedToProcess(&encoded_data_handle); |
113 base::FileDescriptor fd(audio_decoder.write_fd(), true); | 113 base::FileDescriptor fd(audio_decoder.write_fd(), true); |
114 | 114 |
115 DVLOG(1) << "DecodeAudioFileData: Starting MediaCodec"; | 115 DVLOG(1) << "DecodeAudioFileData: Starting MediaCodec"; |
116 | 116 |
117 // Start MediaCodec processing in the browser which will read from | 117 // Start MediaCodec processing in the browser which will read from |
118 // encoded_data_handle for our shared memory and write the decoded | 118 // encoded_data_handle for our shared memory and write the decoded |
119 // PCM samples (16-bit integer) to our pipe. | 119 // PCM samples (16-bit integer) to our pipe. |
120 | 120 |
121 runner.Run(encoded_data_handle, fd); | 121 runner.Run(encoded_data_handle, fd, data_size); |
122 | 122 |
123 // First, read the number of channels, the sample rate, and the | 123 // First, read the number of channels, the sample rate, and the |
124 // number of frames and a flag indicating if the file is an | 124 // number of frames and a flag indicating if the file is an |
125 // ogg/vorbis file. This must be coordinated with | 125 // ogg/vorbis file. This must be coordinated with |
126 // WebAudioMediaCodecBridge! | 126 // WebAudioMediaCodecBridge! |
127 // | 127 // |
128 // TODO(rtoy): If we know the number of samples, we can create the | 128 // TODO(rtoy): If we know the number of samples, we can create the |
129 // destination bus directly and do the conversion directly to the | 129 // destination bus directly and do the conversion directly to the |
130 // bus instead of buffering up everything before saving the data to | 130 // bus instead of buffering up everything before saving the data to |
131 // the bus. | 131 // the bus. |
132 | 132 |
133 int input_fd = audio_decoder.read_fd(); | 133 int input_fd = audio_decoder.read_fd(); |
134 unsigned long info[4]; | 134 unsigned long info[3]; |
DaleCurtis
2013/04/30 17:44:17
Since you're reading / writing this structure acro
Raymond Toy (Google)
2013/04/30 19:53:16
Added the struct and a new header file to define i
| |
135 | 135 |
136 DVLOG(1) << "Reading audio file info from fd " << input_fd; | 136 DVLOG(1) << "Reading audio file info from fd " << input_fd; |
137 ssize_t nread = HANDLE_EINTR(read(input_fd, info, sizeof(info))); | 137 ssize_t nread = HANDLE_EINTR(read(input_fd, info, sizeof(info))); |
138 DVLOG(1) << "read: " << nread << " bytes:\n" | 138 DVLOG(1) << "read: " << nread << " bytes:\n" |
139 << " 0: number of channels = " << info[0] << "\n" | 139 << " 0: number of channels = " << info[0] << "\n" |
140 << " 1: sample rate = " << info[1] << "\n" | 140 << " 1: sample rate = " << info[1] << "\n" |
141 << " 2: number of frames = " << info[2] << "\n" | 141 << " 2: number of frames = " << info[2] << "\n"; |
142 << " 3: is vorbis = " << info[3]; | |
143 | 142 |
144 if (nread != sizeof(info)) | 143 if (nread != sizeof(info)) |
145 return false; | 144 return false; |
146 | 145 |
147 unsigned number_of_channels = info[0]; | 146 unsigned number_of_channels = info[0]; |
148 double file_sample_rate = static_cast<double>(info[1]); | 147 double file_sample_rate = static_cast<double>(info[1]); |
149 | 148 |
150 // Sanity checks | 149 // Sanity checks |
151 if (!number_of_channels || | 150 if (!number_of_channels || |
152 number_of_channels > media::limits::kMaxChannels || | 151 number_of_channels > media::limits::kMaxChannels || |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 destination_bus->channelData(k)[decoded_frames] = | 187 destination_bus->channelData(k)[decoded_frames] = |
189 sample * (sample < 0 ? kMinScale : kMaxScale); | 188 sample * (sample < 0 ? kMinScale : kMaxScale); |
190 } | 189 } |
191 ++decoded_frames; | 190 ++decoded_frames; |
192 } | 191 } |
193 | 192 |
194 return true; | 193 return true; |
195 } | 194 } |
196 | 195 |
197 } // namespace webkit_media | 196 } // namespace webkit_media |
OLD | NEW |