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

Unified Diff: media/filters/audio_file_reader.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
Index: media/filters/audio_file_reader.cc
===================================================================
--- media/filters/audio_file_reader.cc (revision 160749)
+++ media/filters/audio_file_reader.cc (working copy)
@@ -35,7 +35,12 @@
base::TimeDelta AudioFileReader::duration() const {
const AVRational av_time_base = {1, AV_TIME_BASE};
- return ConvertFromTimeBase(av_time_base, format_context_->duration);
+
+ // Add one microsecond to avoid rounding-down errors which can occur when
+ // |duration| has been calculated from an exact number of sample-frames.
+ // One microsecond is much less than the time of a single sample-frame
+ // at any real-world sample-rate.
+ return ConvertFromTimeBase(av_time_base, format_context_->duration + 1);
}
int64 AudioFileReader::number_of_frames() const {
@@ -110,13 +115,13 @@
}
}
-bool AudioFileReader::Read(AudioBus* audio_bus) {
+int AudioFileReader::Read(AudioBus* audio_bus) {
DCHECK(format_context_ && codec_context_) <<
"AudioFileReader::Read() : reader is not opened!";
DCHECK_EQ(audio_bus->channels(), channels());
DaleCurtis 2012/10/12 22:42:02 Style violation: Remove DCHECK() since this is han
Chris Rogers 2012/10/12 23:22:29 This isn't part of this CL On 2012/10/12 22:42:02
DaleCurtis 2012/10/13 01:10:35 I know, but it's a good idea to fix these things i
if (audio_bus->channels() != channels())
- return false;
+ return 0;
size_t bytes_per_sample = av_get_bytes_per_sample(codec_context_->sample_fmt);
@@ -187,8 +192,9 @@
audio_bus->ZeroFramesPartial(
current_frame, audio_bus->frames() - current_frame);
- // Fail if nothing has been decoded, otherwise return partial data.
- return current_frame > 0;
+ // Returns the actual number of sample-frames decoded.
+ // Ideally this represents the "true" exact length of the file.
+ return current_frame;
}
} // namespace media

Powered by Google App Engine
This is Rietveld 408576698