Chromium Code Reviews| Index: content/renderer/media/audio_decoder.cc |
| diff --git a/content/renderer/media/audio_decoder.cc b/content/renderer/media/audio_decoder.cc |
| index ca1b2d2467a5a7e2046b53ecaa853ba0b9c0dd5d..ea62a0edea60fe33623e6e771c0c0110b4a1cd3a 100644 |
| --- a/content/renderer/media/audio_decoder.cc |
| +++ b/content/renderer/media/audio_decoder.cc |
| @@ -6,6 +6,7 @@ |
| #include <stdint.h> |
| +#include <iomanip> |
|
DaleCurtis
2017/02/09 18:47:36
?
Raymond Toy
2017/02/09 18:56:12
So I can std::fixed and std::setprecision so more
DaleCurtis
2017/02/09 22:42:20
Instead how about using TimeDelta::FromSecondsD().
Raymond Toy
2017/02/09 23:09:27
That produces the result in microseconds, which ma
|
| #include <vector> |
| #include "base/strings/string_util.h" |
| @@ -32,7 +33,9 @@ bool DecodeAudioFileData( |
| if (!destination_bus) |
| return false; |
| -#if !defined(MEDIA_DISABLE_FFMPEG) |
| +#if defined(MEDIA_DISABLE_FFMPEG) |
| + return false |
| +#else |
| // Uses the FFmpeg library for audio file reading. |
| InMemoryUrlProtocol url_protocol(reinterpret_cast<const uint8_t*>(data), |
| data_size, false); |
| @@ -43,7 +46,6 @@ bool DecodeAudioFileData( |
| size_t number_of_channels = reader.channels(); |
| double file_sample_rate = reader.sample_rate(); |
| - size_t number_of_frames = static_cast<size_t>(reader.GetNumberOfFrames()); |
| // Apply sanity checks to make sure crazy values aren't coming out of |
| // FFmpeg. |
| @@ -53,47 +55,42 @@ bool DecodeAudioFileData( |
| file_sample_rate > media::limits::kMaxSampleRate) |
| return false; |
| - // Allocate and configure the output audio channel data. |
| - destination_bus->initialize(number_of_channels, |
| - number_of_frames, |
| - file_sample_rate); |
| - |
| - // Wrap the channel pointers which will receive the decoded PCM audio. |
| - vector<float*> audio_data; |
| - audio_data.reserve(number_of_channels); |
| - for (size_t i = 0; i < number_of_channels; ++i) { |
| - audio_data.push_back(destination_bus->channelData(i)); |
| - } |
| + std::vector<std::unique_ptr<AudioBus>> decodedAudioPackets; |
|
DaleCurtis
2017/02/09 18:47:36
decoded_audio_packets.
Raymond Toy
2017/02/09 21:45:06
Done.
|
| + int number_of_frames = reader.Read(decodedAudioPackets); |
|
DaleCurtis
2017/02/09 18:47:36
Should be passing a pointer in?
Raymond Toy
2017/02/09 21:45:06
Done.
|
| - std::unique_ptr<AudioBus> audio_bus = |
| - AudioBus::WrapVector(number_of_frames, audio_data); |
| + if (number_of_frames <= 0) |
| + return false; |
| - // Decode the audio file data. |
| - // TODO(crogers): If our estimate was low, then we still may fail to read |
| - // all of the data from the file. |
| - size_t actual_frames = reader.Read(audio_bus.get()); |
| + // Allocate and configure the output audio channel data and then |
| + // copy the decoded data to the destination. |
| + destination_bus->initialize(number_of_channels, number_of_frames, |
| + file_sample_rate); |
| - // Adjust WebKit's bus to account for the actual file length |
| - // and valid data read. |
| - if (actual_frames != number_of_frames) { |
| - DCHECK_LE(actual_frames, number_of_frames); |
| - destination_bus->resizeSmaller(actual_frames); |
| + int dest_frame_offset = 0; |
| + for (auto&& packet : decodedAudioPackets) { |
|
DaleCurtis
2017/02/09 18:47:36
&& is not allowed per style guide.
Raymond Toy
2017/02/09 21:45:06
Done.
|
| + int packet_length = packet->frames(); |
| + for (size_t ch = 0; ch < number_of_channels; ++ch) { |
|
DaleCurtis
2017/02/09 18:47:36
Just use src->CopyPartialFramesTo(...)
Raymond Toy
2017/02/09 21:45:06
Unfortunately, destination_bus is not an AudioBus.
|
| + float* dst = destination_bus->channelData(ch); |
| + float* src = packet->channel(ch); |
| + DCHECK_LE(dest_frame_offset + packet_length, number_of_frames); |
| + memcpy(dst + dest_frame_offset, src, packet_length * sizeof(*dst)); |
| + } |
| + dest_frame_offset += packet_length; |
| } |
| - double duration = actual_frames / file_sample_rate; |
| - |
| - DVLOG(1) << "Decoded file data -" |
| - << " data: " << data |
| - << " data size: " << data_size |
| - << " duration: " << duration |
| - << " number of frames: " << actual_frames |
| + DVLOG(1) << "Decoded file data (unknown duration)-" |
| + << " data: " << data << " data size: " << data_size |
| + << " decoded duration: " << std::fixed << std::setprecision(6) |
| + << number_of_frames / file_sample_rate |
| + << " estimated duration (if available): " |
| + << (reader.HasKnownDuration() ? reader.GetNumberOfFrames() : 0) / |
| + file_sample_rate |
| + << " number of frames: " << number_of_frames |
| << " sample rate: " << file_sample_rate |
| << " number of channels: " << number_of_channels; |
| - return actual_frames > 0; |
| -#else |
| - return false; |
| -#endif // !defined(MEDIA_DISABLE_FFMPEG) |
| + return number_of_frames > 0; |
| +#endif // defined(MEDIA_DISABLE_FFMPEG) |
| } |
| } // namespace content |