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

Unified Diff: content/renderer/media/audio_decoder.cc

Issue 2655783004: Decode entire in-memory file for WebAudio (Closed)
Patch Set: Clean up implementation. Created 3 years, 11 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 | media/filters/audio_file_reader.h » ('j') | media/filters/audio_file_reader.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..19a75f0748501fc8f33468a0614833b1829ead3e 100644
--- a/content/renderer/media/audio_decoder.cc
+++ b/content/renderer/media/audio_decoder.cc
@@ -32,7 +32,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 +45,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,6 +54,33 @@ bool DecodeAudioFileData(
file_sample_rate > media::limits::kMaxSampleRate)
return false;
+ if (!reader.HasKnownDuration()) {
+ // We don't have an estimated duration so read the entire stream.
+ std::unique_ptr<AudioBus> decodedAudio = reader.StreamingRead();
+
+ // Allocate and configure the output audio channel data.
DaleCurtis 2017/01/25 22:42:25 This adds an extra copy, how about returning the s
+ size_t number_of_frames = decodedAudio->frames();
+ destination_bus->initialize(number_of_channels, number_of_frames,
+ file_sample_rate);
+
+ for (size_t ch = 0; ch < number_of_channels; ++ch) {
+ DCHECK(destination_bus->channelData(ch));
+ memcpy(destination_bus->channelData(ch), decodedAudio->channel(ch),
+ number_of_frames * sizeof(float));
+ }
+ DVLOG(1) << "Decoded file data (unknown duration)-"
+ << " data: " << data << " data size: " << data_size
+ << " decoded duration: " << number_of_frames / file_sample_rate
+ << " number of frames: " << number_of_frames
+ << " sample rate: " << file_sample_rate
+ << " number of channels: " << number_of_channels;
+ return true;
+ }
+
+ // An estimated duration is available so we can use that to allocate
+ // memory for the decoded data.
+ size_t number_of_frames = static_cast<size_t>(reader.GetNumberOfFrames());
+
// Allocate and configure the output audio channel data.
destination_bus->initialize(number_of_channels,
number_of_frames,
@@ -91,9 +119,7 @@ bool DecodeAudioFileData(
<< " number of channels: " << number_of_channels;
return actual_frames > 0;
-#else
- return false;
-#endif // !defined(MEDIA_DISABLE_FFMPEG)
+#endif // defined(MEDIA_DISABLE_FFMPEG)
}
} // namespace content
« no previous file with comments | « no previous file | media/filters/audio_file_reader.h » ('j') | media/filters/audio_file_reader.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698