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

Unified Diff: media/filters/audio_file_reader.cc

Issue 12224114: Guard against midstream audio configuration changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments. Created 7 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 58c4501b43f62b74d4a8021e64ab72708e4565a7..32627b04b10ad558bab4b4facc386da0a3c4552d 100644
--- a/media/filters/audio_file_reader.cc
+++ b/media/filters/audio_file_reader.cc
@@ -15,21 +15,16 @@ namespace media {
AudioFileReader::AudioFileReader(FFmpegURLProtocol* protocol)
: codec_context_(NULL),
stream_index_(0),
- protocol_(protocol) {
+ protocol_(protocol),
+ channels_(0),
+ sample_rate_(0),
+ av_sample_format_(0) {
}
AudioFileReader::~AudioFileReader() {
Close();
}
-int AudioFileReader::channels() const {
- return codec_context_->channels;
-}
-
-int AudioFileReader::sample_rate() const {
- return codec_context_->sample_rate;
-}
-
base::TimeDelta AudioFileReader::duration() const {
const AVRational av_time_base = {1, AV_TIME_BASE};
@@ -110,6 +105,11 @@ bool AudioFileReader::Open() {
return false;
}
+ // Store initial values to guard against midstream configuration changes.
+ channels_ = codec_context_->channels;
+ sample_rate_ = codec_context_->sample_rate;
+ av_sample_format_ = codec_context_->sample_fmt;
+
return true;
}
@@ -179,6 +179,22 @@ int AudioFileReader::Read(AudioBus* audio_bus) {
break;
}
+ if (av_frame->sample_rate != sample_rate_ ||
+ av_frame->channels != channels_ ||
+ av_frame->format != av_sample_format_) {
+ DLOG(ERROR) << "Unsupported midstream configuration change!"
+ << " Sample Rate: " << av_frame->sample_rate << " vs "
+ << sample_rate_
+ << ", Channels: " << av_frame->channels << " vs "
+ << channels_
+ << ", Sample Format: " << av_frame->format << " vs "
+ << av_sample_format_;
+
+ // This is an unrecoverable error, so bail out.
+ continue_decoding = false;
+ break;
+ }
+
// Truncate, if necessary, if the destination isn't big enough.
if (current_frame + frames_read > audio_bus->frames())
frames_read = audio_bus->frames() - current_frame;
« 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