Chromium Code Reviews| Index: media/filters/audio_file_reader.cc |
| diff --git a/media/filters/audio_file_reader.cc b/media/filters/audio_file_reader.cc |
| index b20fd8d9ce35795b7ed94e5cea8177d80f0f25f0..2b8b919b190982d37264b5e0d2db5019a6b095e2 100644 |
| --- a/media/filters/audio_file_reader.cc |
| +++ b/media/filters/audio_file_reader.cc |
| @@ -28,6 +28,12 @@ AudioFileReader::~AudioFileReader() { |
| } |
| bool AudioFileReader::Open() { |
| + if (!OpenDemuxer()) |
| + return false; |
| + return OpenDecoder(); |
| +} |
| + |
| +bool AudioFileReader::OpenDemuxer() { |
| glue_.reset(new FFmpegGlue(protocol_)); |
| AVFormatContext* format_context = glue_->format_context(); |
| @@ -52,20 +58,21 @@ bool AudioFileReader::Open() { |
| if (!codec_context_) |
| return false; |
| - int result = avformat_find_stream_info(format_context, NULL); |
| - if (result < 0) { |
| - DLOG(WARNING) |
| - << "AudioFileReader::Open() : error in avformat_find_stream_info()"; |
| - return false; |
| - } |
| + const int result = avformat_find_stream_info(format_context, NULL); |
| + DLOG_IF(result < 0, WARNING) |
| + << "AudioFileReader::Open() : error in avformat_find_stream_info()"; |
| + return result >= 0; |
| +} |
| +bool AudioFileReader::OpenDecoder() { |
| AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id); |
| if (codec) { |
| // MP3 decodes to S16P which we don't support, tell it to use S16 instead. |
| if (codec_context_->sample_fmt == AV_SAMPLE_FMT_S16P) |
| codec_context_->request_sample_fmt = AV_SAMPLE_FMT_S16; |
| - if ((result = avcodec_open2(codec_context_, codec, NULL)) < 0) { |
| + const int result = avcodec_open2(codec_context_, codec, NULL); |
| + if (result < 0) { |
|
wolenetz
2014/06/19 20:56:47
nit: consistency : s/if.../DLOG_IF like you did ab
wolenetz
2014/06/19 21:00:16
actually, forget this nit... there's a case where
|
| DLOG(WARNING) << "AudioFileReader::Open() : could not open codec -" |
| << " result: " << result; |
| return false; |
| @@ -79,8 +86,7 @@ bool AudioFileReader::Open() { |
| return false; |
| } |
| } else { |
| - DLOG(WARNING) << "AudioFileReader::Open() : could not find codec -" |
| - << " result: " << result; |
| + DLOG(WARNING) << "AudioFileReader::Open() : could not find codec."; |
| return false; |
| } |
| @@ -96,7 +102,6 @@ bool AudioFileReader::Open() { |
| channels_ = codec_context_->channels; |
| sample_rate_ = codec_context_->sample_rate; |
| av_sample_format_ = codec_context_->sample_fmt; |
| - |
| return true; |
| } |
| @@ -240,6 +245,10 @@ int AudioFileReader::GetNumberOfFrames() const { |
| return static_cast<int>(ceil(GetDuration().InSecondsF() * sample_rate())); |
| } |
| +bool AudioFileReader::OpenDemuxerForTesting() { |
| + return OpenDemuxer(); |
| +} |
| + |
| bool AudioFileReader::ReadPacketForTesting(AVPacket* output_packet) { |
| return ReadPacket(output_packet); |
| } |
| @@ -257,4 +266,15 @@ bool AudioFileReader::ReadPacket(AVPacket* output_packet) { |
| return false; |
| } |
| +bool AudioFileReader::SeekForTesting(base::TimeDelta seek_time) { |
| + return av_seek_frame(glue_->format_context(), |
| + stream_index_, |
| + ConvertToTimeBase(codec_context_->time_base, seek_time), |
| + AVSEEK_FLAG_BACKWARD) >= 0; |
| +} |
| + |
| +const AVStream* AudioFileReader::GetAVStreamForTesting() const { |
| + return glue_->format_context()->streams[stream_index_]; |
| +} |
| + |
| } // namespace media |