summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorcrogers@google.com <crogers@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-15 19:00:12 +0000
committercrogers@google.com <crogers@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-15 19:00:12 +0000
commit64b0ef6cb3a8131dba8668f4d2e3b453e1bb4ded (patch)
tree3d9d897c9f0fba27dbe328520b2a187794c8813c /media
parent9f273945c359cfd91b0807ba0bb3826461859979 (diff)
downloadchromium_src-64b0ef6cb3a8131dba8668f4d2e3b453e1bb4ded.zip
chromium_src-64b0ef6cb3a8131dba8668f4d2e3b453e1bb4ded.tar.gz
chromium_src-64b0ef6cb3a8131dba8668f4d2e3b453e1bb4ded.tar.bz2
Make sure that DecodeAudioFileData() always returns an AudioBus of the exact length of the file
BUG=none TEST=extensive manual testing, two Web Audio layout tests for decoding need to be re-baselined Review URL: https://codereview.chromium.org/11137005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@161914 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/filters/audio_file_reader.cc16
-rw-r--r--media/filters/audio_file_reader.h10
2 files changed, 19 insertions, 7 deletions
diff --git a/media/filters/audio_file_reader.cc b/media/filters/audio_file_reader.cc
index 628f951..eea0eed 100644
--- a/media/filters/audio_file_reader.cc
+++ b/media/filters/audio_file_reader.cc
@@ -35,7 +35,12 @@ int AudioFileReader::sample_rate() const {
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 @@ void AudioFileReader::Close() {
}
}
-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());
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 @@ bool AudioFileReader::Read(AudioBus* audio_bus) {
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
diff --git a/media/filters/audio_file_reader.h b/media/filters/audio_file_reader.h
index b8f54b6..726ab7d 100644
--- a/media/filters/audio_file_reader.h
+++ b/media/filters/audio_file_reader.h
@@ -37,12 +37,18 @@ class MEDIA_EXPORT AudioFileReader {
// |audio_data| must be of the same size as channels().
// The audio data will be decoded as floating-point linear PCM with
// a nominal range of -1.0 -> +1.0.
- // Returns |true| on success.
- bool Read(AudioBus* audio_bus);
+ // Returns the number of sample-frames actually read which will always be
+ // <= audio_bus->frames()
+ int Read(AudioBus* audio_bus);
// These methods can be called once Open() has been called.
int channels() const;
int sample_rate() const;
+
+ // Please note that duration() and number_of_frames() attempt to be accurate,
+ // but are only estimates. For some encoded formats, the actual duration
+ // of the file can only be determined once all the file data has been read.
+ // The Read() method returns the actual number of sample-frames it has read.
base::TimeDelta duration() const;
int64 number_of_frames() const;