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

Unified Diff: media/filters/audio_file_reader.cc

Issue 187223002: Always round up to the next full frame when sizing WebAudio decodes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rietveld!!! Created 6 years, 10 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 | « media/filters/audio_file_reader.h ('k') | media/filters/audio_file_reader_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/filters/audio_file_reader.cc
diff --git a/media/filters/audio_file_reader.cc b/media/filters/audio_file_reader.cc
index 74538e73ca68fba80b89f16ea6f9bbcd42053af6..535d72ce8086dc0824303fc67e9a65ccb90a6afb 100644
--- a/media/filters/audio_file_reader.cc
+++ b/media/filters/audio_file_reader.cc
@@ -4,6 +4,8 @@
#include "media/filters/audio_file_reader.h"
+#include <cmath>
+
#include "base/logging.h"
#include "base/time/time.h"
#include "media/base/audio_bus.h"
@@ -25,21 +27,6 @@ AudioFileReader::~AudioFileReader() {
Close();
}
-base::TimeDelta AudioFileReader::duration() const {
- const AVRational av_time_base = {1, AV_TIME_BASE};
-
- // 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, glue_->format_context()->duration + 1);
-}
-
-int64 AudioFileReader::number_of_frames() const {
- return static_cast<int64>(duration().InSecondsF() * sample_rate());
-}
-
bool AudioFileReader::Open() {
glue_.reset(new FFmpegGlue(protocol_));
AVFormatContext* format_context = glue_->format_context();
@@ -202,8 +189,10 @@ int AudioFileReader::Read(AudioBus* audio_bus) {
}
// Truncate, if necessary, if the destination isn't big enough.
- if (current_frame + frames_read > audio_bus->frames())
+ if (current_frame + frames_read > audio_bus->frames()) {
+ DLOG(ERROR) << "Truncating decoded data due to output size.";
frames_read = audio_bus->frames() - current_frame;
+ }
// Deinterleave each channel and convert to 32bit floating-point with
// nominal range -1.0 -> +1.0. If the output is already in float planar
@@ -242,4 +231,19 @@ int AudioFileReader::Read(AudioBus* audio_bus) {
return current_frame;
}
+base::TimeDelta AudioFileReader::GetDuration() const {
Raymond Toy (Google) 2014/03/05 18:28:00 Why move the code around?
DaleCurtis 2014/03/05 19:27:35 http://google-styleguide.googlecode.com/svn/trunk/
+ const AVRational av_time_base = {1, AV_TIME_BASE};
+
+ // 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,
+ glue_->format_context()->duration + 1);
+}
+
+int AudioFileReader::GetNumberOfFrames() const {
+ return static_cast<int>(ceil(GetDuration().InSecondsF() * sample_rate()));
+}
+
} // namespace media
« no previous file with comments | « media/filters/audio_file_reader.h ('k') | media/filters/audio_file_reader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698