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

Unified Diff: webkit/media/audio_decoder.cc

Issue 11137005: Make sure that DecodeAudioFileData() always returns an AudioBus of the exact length of the file (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 2 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
« media/filters/audio_file_reader.h ('K') | « media/filters/audio_file_reader.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/media/audio_decoder.cc
===================================================================
--- webkit/media/audio_decoder.cc (revision 160749)
+++ webkit/media/audio_decoder.cc (working copy)
@@ -40,7 +40,6 @@
size_t number_of_channels = reader.channels();
double file_sample_rate = reader.sample_rate();
- double duration = reader.duration().InSecondsF();
size_t number_of_frames = static_cast<size_t>(reader.number_of_frames());
// Apply sanity checks to make sure crazy values aren't coming out of
@@ -51,14 +50,6 @@
file_sample_rate > media::limits::kMaxSampleRate)
return false;
- DVLOG(1) << "Decoding file data -"
- << " data: " << data
- << " data size: " << data_size
- << " duration: " << duration
- << " number of frames: " << number_of_frames
- << " sample rate: " << file_sample_rate
- << " number of channels: " << number_of_channels;
-
// Allocate and configure the output audio channel data.
destination_bus->initialize(number_of_channels,
number_of_frames,
@@ -75,7 +66,28 @@
number_of_frames, audio_data);
// Decode the audio file data.
- return reader.Read(audio_bus.get());
+ // 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());
+
+ // 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);
+ }
+
+ 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
+ << " sample rate: " << file_sample_rate
+ << " number of channels: " << number_of_channels;
+
+ return actual_frames > 0;
}
} // namespace webkit_media
« media/filters/audio_file_reader.h ('K') | « media/filters/audio_file_reader.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698