| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/filters/audio_file_reader.h" | 5 #include "media/filters/audio_file_reader.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 sample_rate_(0), | 28 sample_rate_(0), |
| 29 av_sample_format_(0) {} | 29 av_sample_format_(0) {} |
| 30 | 30 |
| 31 AudioFileReader::~AudioFileReader() { | 31 AudioFileReader::~AudioFileReader() { |
| 32 Close(); | 32 Close(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 bool AudioFileReader::Open() { | 35 bool AudioFileReader::Open() { |
| 36 if (!OpenDemuxer()) | 36 if (!OpenDemuxer()) |
| 37 return false; | 37 return false; |
| 38 return OpenDecoder(); | 38 if (!OpenDecoder()) |
| 39 return false; |
| 40 |
| 41 // If the duration is unknown, fail out; this API can not work with streams of |
| 42 // unknown duration currently. |
| 43 return glue_->format_context()->duration != AV_NOPTS_VALUE; |
| 39 } | 44 } |
| 40 | 45 |
| 41 bool AudioFileReader::OpenDemuxer() { | 46 bool AudioFileReader::OpenDemuxer() { |
| 42 glue_.reset(new FFmpegGlue(protocol_)); | 47 glue_.reset(new FFmpegGlue(protocol_)); |
| 43 AVFormatContext* format_context = glue_->format_context(); | 48 AVFormatContext* format_context = glue_->format_context(); |
| 44 | 49 |
| 45 // Open FFmpeg AVFormatContext. | 50 // Open FFmpeg AVFormatContext. |
| 46 if (!glue_->OpenContext()) { | 51 if (!glue_->OpenContext()) { |
| 47 DLOG(WARNING) << "AudioFileReader::Open() : error in avformat_open_input()"; | 52 DLOG(WARNING) << "AudioFileReader::Open() : error in avformat_open_input()"; |
| 48 return false; | 53 return false; |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 current_frame, audio_bus->frames() - current_frame); | 246 current_frame, audio_bus->frames() - current_frame); |
| 242 | 247 |
| 243 // Returns the actual number of sample-frames decoded. | 248 // Returns the actual number of sample-frames decoded. |
| 244 // Ideally this represents the "true" exact length of the file. | 249 // Ideally this represents the "true" exact length of the file. |
| 245 return current_frame; | 250 return current_frame; |
| 246 } | 251 } |
| 247 | 252 |
| 248 base::TimeDelta AudioFileReader::GetDuration() const { | 253 base::TimeDelta AudioFileReader::GetDuration() const { |
| 249 const AVRational av_time_base = {1, AV_TIME_BASE}; | 254 const AVRational av_time_base = {1, AV_TIME_BASE}; |
| 250 | 255 |
| 251 // Estimated duration in micro seconds. | 256 DCHECK_NE(glue_->format_context()->duration, AV_NOPTS_VALUE); |
| 252 base::CheckedNumeric<int64_t> estimated_duration_us = | 257 base::CheckedNumeric<int64_t> estimated_duration_us = |
| 253 glue_->format_context()->duration; | 258 glue_->format_context()->duration; |
| 254 | 259 |
| 255 if (audio_codec_ == kCodecAAC) { | 260 if (audio_codec_ == kCodecAAC) { |
| 256 // For certain AAC-encoded files, FFMPEG's estimated frame count might not | 261 // For certain AAC-encoded files, FFMPEG's estimated frame count might not |
| 257 // be sufficient to capture the entire audio content that we want. This is | 262 // be sufficient to capture the entire audio content that we want. This is |
| 258 // especially noticeable for short files (< 10ms) resulting in silence | 263 // especially noticeable for short files (< 10ms) resulting in silence |
| 259 // throughout the decoded buffer. Thus we add the priming frames and the | 264 // throughout the decoded buffer. Thus we add the priming frames and the |
| 260 // remainder frames to the estimation. | 265 // remainder frames to the estimation. |
| 261 // (See: crbug.com/513178) | 266 // (See: crbug.com/513178) |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 glue_->format_context(), stream_index_, | 310 glue_->format_context(), stream_index_, |
| 306 ConvertToTimeBase(GetAVStreamForTesting()->time_base, seek_time), | 311 ConvertToTimeBase(GetAVStreamForTesting()->time_base, seek_time), |
| 307 AVSEEK_FLAG_BACKWARD) >= 0; | 312 AVSEEK_FLAG_BACKWARD) >= 0; |
| 308 } | 313 } |
| 309 | 314 |
| 310 const AVStream* AudioFileReader::GetAVStreamForTesting() const { | 315 const AVStream* AudioFileReader::GetAVStreamForTesting() const { |
| 311 return glue_->format_context()->streams[stream_index_]; | 316 return glue_->format_context()->streams[stream_index_]; |
| 312 } | 317 } |
| 313 | 318 |
| 314 } // namespace media | 319 } // namespace media |
| OLD | NEW |