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 628f951b33a743663f6dc2b49bdd687e6c44baae..47194c8be78461fbcac8c22268a4c8a3f5b69741 100644 |
| --- a/media/filters/audio_file_reader.cc |
| +++ b/media/filters/audio_file_reader.cc |
| @@ -4,9 +4,7 @@ |
| #include "media/filters/audio_file_reader.h" |
| -#include <string> |
| -#include "base/basictypes.h" |
| -#include "base/string_util.h" |
| +#include "base/logging.h" |
| #include "base/time.h" |
| #include "media/base/audio_bus.h" |
| #include "media/ffmpeg/ffmpeg_common.h" |
| @@ -15,8 +13,7 @@ |
| namespace media { |
| AudioFileReader::AudioFileReader(FFmpegURLProtocol* protocol) |
| - : protocol_(protocol), |
| - format_context_(NULL), |
| + : glue_(new FFmpegGlue(protocol)), |
| codec_context_(NULL), |
| stream_index_(0) { |
| } |
| @@ -35,7 +32,7 @@ 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); |
| + return ConvertFromTimeBase(av_time_base, glue_->format_context()->duration); |
| } |
| int64 AudioFileReader::number_of_frames() const { |
| @@ -43,19 +40,11 @@ int64 AudioFileReader::number_of_frames() const { |
| } |
| bool AudioFileReader::Open() { |
| - // Add our data reader to the protocol list and get our unique key. |
| - std::string key = FFmpegGlue::GetInstance()->AddProtocol(protocol_); |
| + DCHECK(glue_.get()); |
|
scherkus (not reviewing)
2012/10/02 00:20:56
dcheck not useful
DaleCurtis
2012/10/02 01:24:23
Done.
|
| + AVFormatContext* format_context = glue_->format_context(); |
| // Open FFmpeg AVFormatContext. |
| - DCHECK(!format_context_); |
| - AVFormatContext* context = NULL; |
| - |
| - int result = avformat_open_input(&context, key.c_str(), NULL, NULL); |
| - |
| - // Remove our data reader from protocol list since avformat_open_input() setup |
| - // the AVFormatContext with the data reader. |
| - FFmpegGlue::GetInstance()->RemoveProtocol(protocol_); |
| - |
| + int result = glue_->OpenContext(); |
| if (result) { |
| DLOG(WARNING) |
| << "AudioFileReader::Open() : error in avformat_open_input() -" |
| @@ -63,13 +52,10 @@ bool AudioFileReader::Open() { |
| return false; |
| } |
| - DCHECK(context); |
| - format_context_ = context; |
| - |
| // Get the codec context. |
| codec_context_ = NULL; |
| - for (size_t i = 0; i < format_context_->nb_streams; ++i) { |
| - AVCodecContext* c = format_context_->streams[i]->codec; |
| + for (size_t i = 0; i < format_context->nb_streams; ++i) { |
| + AVCodecContext* c = format_context->streams[i]->codec; |
| if (c->codec_type == AVMEDIA_TYPE_AUDIO) { |
| codec_context_ = c; |
| stream_index_ = i; |
| @@ -81,7 +67,7 @@ bool AudioFileReader::Open() { |
| if (!codec_context_) |
| return false; |
| - avformat_find_stream_info(format_context_, NULL); |
| + avformat_find_stream_info(format_context, NULL); |
| AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id); |
| if (codec) { |
| if ((result = avcodec_open2(codec_context_, codec, NULL)) < 0) { |
| @@ -103,15 +89,10 @@ void AudioFileReader::Close() { |
| avcodec_close(codec_context_); |
| codec_context_ = NULL; |
| } |
| - |
| - if (format_context_) { |
| - avformat_close_input(&format_context_); |
| - format_context_ = NULL; |
| - } |
| } |
| bool AudioFileReader::Read(AudioBus* audio_bus) { |
| - DCHECK(format_context_ && codec_context_) << |
| + DCHECK(glue_.get() && codec_context_) << |
| "AudioFileReader::Read() : reader is not opened!"; |
| DCHECK_EQ(audio_bus->channels(), channels()); |
| @@ -129,7 +110,7 @@ bool AudioFileReader::Read(AudioBus* audio_bus) { |
| bool continue_decoding = true; |
| while (current_frame < audio_bus->frames() && continue_decoding && |
| - av_read_frame(format_context_, &packet) >= 0 && |
| + av_read_frame(glue_->format_context(), &packet) >= 0 && |
| av_dup_packet(&packet) >= 0) { |
| // Skip packets from other streams. |
| if (packet.stream_index != stream_index_) { |