diff options
author | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-26 23:49:24 +0000 |
---|---|---|
committer | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-26 23:49:24 +0000 |
commit | 92b0417bd59b83f6a4908a6bb19ef833852faf08 (patch) | |
tree | 928d80c5d866f659fe6977f7d8817eeea8319b25 | |
parent | 9e717c32ba0e9710d06d2f3fac3a291f3d4e4ec5 (diff) | |
download | chromium_src-92b0417bd59b83f6a4908a6bb19ef833852faf08.zip chromium_src-92b0417bd59b83f6a4908a6bb19ef833852faf08.tar.gz chromium_src-92b0417bd59b83f6a4908a6bb19ef833852faf08.tar.bz2 |
Lots of files touched for a very simple change. Everywhere we used a const MediaFormat* we now
use a const MediaFormat&. This makes for simpler code and for better pointer reference safety.
Review URL: http://codereview.chromium.org/42635
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12623 0039d316-1c4b-4281-b951-d872f2087c98
30 files changed, 119 insertions, 122 deletions
diff --git a/chrome/renderer/media/audio_renderer_impl.cc b/chrome/renderer/media/audio_renderer_impl.cc index 5df76ba..9677b32 100644 --- a/chrome/renderer/media/audio_renderer_impl.cc +++ b/chrome/renderer/media/audio_renderer_impl.cc @@ -29,14 +29,14 @@ AudioRendererImpl::~AudioRendererImpl() { } bool AudioRendererImpl::IsMediaFormatSupported( - const media::MediaFormat* media_format) { + const media::MediaFormat& media_format) { int channels; int sample_rate; int sample_bits; return ParseMediaFormat(media_format, &channels, &sample_rate, &sample_bits); } -bool AudioRendererImpl::OnInitialize(const media::MediaFormat* media_format) { +bool AudioRendererImpl::OnInitialize(const media::MediaFormat& media_format) { // Parse integer values in MediaFormat. int channels; int sample_rate; @@ -156,7 +156,3 @@ void AudioRendererImpl::OnNotifyAudioPacketReady() { delegate_->view()->NotifyAudioPacketReady(stream_id_, filled); } } - -const media::MediaFormat* AudioRendererImpl::GetMediaFormat() { - return &media_format_; -} diff --git a/chrome/renderer/media/audio_renderer_impl.h b/chrome/renderer/media/audio_renderer_impl.h index c0a8257..d062bb0 100644 --- a/chrome/renderer/media/audio_renderer_impl.h +++ b/chrome/renderer/media/audio_renderer_impl.h @@ -108,7 +108,7 @@ class AudioRendererImpl : public media::AudioRendererBase { return new media::FilterFactoryImpl1<AudioRendererImpl, WebMediaPlayerDelegateImpl*>(delegate); } - static bool IsMediaFormatSupported(const media::MediaFormat* format); + static bool IsMediaFormatSupported(const media::MediaFormat& format); // Methods call from RenderView when audio related IPC messages are received // from browser process. @@ -123,7 +123,6 @@ class AudioRendererImpl : public media::AudioRendererBase { // Methods called on pipeline thread ---------------------------------------- // media::MediaFilter implementation. virtual void SetPlaybackRate(float rate); - const media::MediaFormat* GetMediaFormat(); // media::AudioRenderer implementation. virtual void SetVolume(float volume); @@ -134,7 +133,7 @@ class AudioRendererImpl : public media::AudioRendererBase { protected: // Methods called on audio renderer thread ---------------------------------- // These methods are called from AudioRendererBase. - virtual bool OnInitialize(const media::MediaFormat* media_format); + virtual bool OnInitialize(const media::MediaFormat& media_format); virtual void OnStop(); private: @@ -159,9 +158,6 @@ class AudioRendererImpl : public media::AudioRendererBase { WebMediaPlayerDelegateImpl* delegate_; - // A map of media format information. - media::MediaFormat media_format_; - // ID of the stream created in the browser process. int32 stream_id_; diff --git a/chrome/renderer/media/data_source_impl.cc b/chrome/renderer/media/data_source_impl.cc index e084413..51efb6f 100644 --- a/chrome/renderer/media/data_source_impl.cc +++ b/chrome/renderer/media/data_source_impl.cc @@ -215,10 +215,10 @@ void DataSourceImpl::OnInitialize(std::string uri) { "GET", GURL(uri), GURL(uri), - GURL(), // TODO(hclam): provide referer here. - "null", // TODO(abarth): provide frame_origin - "null", // TODO(abarth): provide main_frame_origin - std::string(), // Provide no header. + GURL(), // TODO(hclam): provide referer here. + "null", // TODO(abarth): provide frame_origin + "null", // TODO(abarth): provide main_frame_origin + std::string(), // Provide no header. // Prefer to load from cache, also enable downloading the file, the // resource will be saved to a single response data file if it's possible. net::LOAD_PREFERRING_CACHE | net::LOAD_ENABLE_DOWNLOAD_FILE, @@ -244,9 +244,9 @@ void DataSourceImpl::OnDownloadProgress(uint64 position, uint64 size) { AutoLock auto_lock(lock_); downloaded_bytes_ = position; if (!total_bytes_known_) { - if (size == kuint64max) + if (size == kuint64max) { total_bytes_ = position; - else { + } else { total_bytes_ = size; total_bytes_known_ = true; } @@ -308,6 +308,6 @@ std::string DataSourceImpl::GetURLForDebugging() { return uri_; } -const media::MediaFormat* DataSourceImpl::GetMediaFormat() { - return &media_format_; +const media::MediaFormat& DataSourceImpl::media_format() { + return media_format_; } diff --git a/chrome/renderer/media/data_source_impl.h b/chrome/renderer/media/data_source_impl.h index 9190b25..6f8d688 100644 --- a/chrome/renderer/media/data_source_impl.h +++ b/chrome/renderer/media/data_source_impl.h @@ -136,7 +136,7 @@ class DataSourceImpl : public media::DataSource, virtual bool SetPosition(int64 position); virtual bool GetSize(int64* size_out); - const media::MediaFormat* GetMediaFormat(); + const media::MediaFormat& media_format(); private: friend class media::FilterFactoryImpl1<DataSourceImpl, @@ -164,7 +164,7 @@ class DataSourceImpl : public media::DataSource, // in construction and can be accessed in all threads safely. WebMediaPlayerDelegateImpl* delegate_; - // Message loop of render thread. + // Message loop of render thread. MessageLoop* render_loop_; // A common lock for protecting members accessed by multiple threads. @@ -173,7 +173,7 @@ class DataSourceImpl : public media::DataSource, // A flag that indicates whether this object has been called to stop. bool stopped_; - // URI to the resource being downloaded. + // URI to the resource being downloaded. std::string uri_; // Members for keeping track of downloading progress. diff --git a/media/base/factory.h b/media/base/factory.h index 66bc377..91e5bc4 100644 --- a/media/base/factory.h +++ b/media/base/factory.h @@ -24,7 +24,7 @@ // // Returns true and assigns |filter_out| if the filter was created, false // and assigns NULL otherwise. -// static bool Create(MediaFormat* media_format, YourFilterType** filter_out); +// static bool Create(MediaFormat& media_format, YourFilterType** filter_out); // #ifndef MEDIA_BASE_FACTORY_H_ @@ -47,7 +47,7 @@ class FilterFactory : public base::RefCountedThreadSafe<FilterFactory> { // If the factory does not support the specific filter type or does not // support the |media_format| then NULL is returned. template <class Filter> - Filter* Create(const MediaFormat* media_format) { + Filter* Create(const MediaFormat& media_format) { return reinterpret_cast<Filter*>(Create(Filter::filter_type(), media_format)); } @@ -63,7 +63,7 @@ class FilterFactory : public base::RefCountedThreadSafe<FilterFactory> { // It is assumed that the MediaFilter interface can be safely cast to the // corresponding interface type (i.e., FILTER_AUDIO_DECODER -> AudioDecoder). virtual MediaFilter* Create(FilterType filter_type, - const MediaFormat* media_format) = 0; + const MediaFormat& media_format) = 0; friend class base::RefCountedThreadSafe<FilterFactory>; virtual ~FilterFactory() {} @@ -82,7 +82,7 @@ class FilterFactoryCollection : public FilterFactory { protected: // Attempts to create a filter by walking down the list of filter factories. - MediaFilter* Create(FilterType filter_type, const MediaFormat* media_format) { + MediaFilter* Create(FilterType filter_type, const MediaFormat& media_format) { MediaFilter* filter = NULL; for (FactoryVector::iterator factory = factories_.begin(); !filter && factory != factories_.end(); @@ -113,7 +113,7 @@ class FilterFactoryImpl0 : public FilterFactory { protected: virtual MediaFilter* Create(FilterType filter_type, - const MediaFormat* media_format) { + const MediaFormat& media_format) { Filter* filter = NULL; if (Filter::filter_type() == filter_type && Filter::IsMediaFormatSupported(media_format)) { @@ -142,7 +142,7 @@ class FilterFactoryImpl1 : public FilterFactory { protected: virtual MediaFilter* Create(FilterType filter_type, - const MediaFormat* media_format) { + const MediaFormat& media_format) { Filter* filter = NULL; if (Filter::filter_type() == filter_type && Filter::IsMediaFormatSupported(media_format)) { @@ -178,7 +178,7 @@ class InstanceFilterFactory : public FilterFactory { protected: virtual MediaFilter* Create(FilterType filter_type, - const MediaFormat* media_format) { + const MediaFormat& media_format) { if (Filter::filter_type() == filter_type && Filter::IsMediaFormatSupported(media_format)) { if (!create_called_) { diff --git a/media/base/filters.h b/media/base/filters.h index 7ceb9e8..6290e28 100644 --- a/media/base/filters.h +++ b/media/base/filters.h @@ -97,9 +97,9 @@ class DataSource : public MediaFilter { return FILTER_DATA_SOURCE; } - static bool IsMediaFormatSupported(const MediaFormat* media_format) { + static bool IsMediaFormatSupported(const MediaFormat& media_format) { std::string mime_type; - return (media_format->GetAsString(MediaFormat::kMimeType, &mime_type) && + return (media_format.GetAsString(MediaFormat::kMimeType, &mime_type) && mime_type == mime_type::kURL); } @@ -109,7 +109,7 @@ class DataSource : public MediaFilter { virtual bool Initialize(const std::string& url) = 0; // Returns the MediaFormat for this filter. - virtual const MediaFormat* GetMediaFormat() = 0; + virtual const MediaFormat& media_format() = 0; // Read the given amount of bytes into data, returns the number of bytes read // if successful, kReadError otherwise. @@ -134,9 +134,9 @@ class Demuxer : public MediaFilter { return FILTER_DEMUXER; } - static bool IsMediaFormatSupported(const MediaFormat* media_format) { + static bool IsMediaFormatSupported(const MediaFormat& media_format) { std::string mime_type; - return (media_format->GetAsString(MediaFormat::kMimeType, &mime_type) && + return (media_format.GetAsString(MediaFormat::kMimeType, &mime_type) && mime_type == mime_type::kApplicationOctetStream); } @@ -154,7 +154,7 @@ class Demuxer : public MediaFilter { class DemuxerStream : public base::RefCountedThreadSafe<DemuxerStream> { public: // Returns the MediaFormat for this filter. - virtual const MediaFormat* GetMediaFormat() = 0; + virtual const MediaFormat& media_format() = 0; // Schedules a read and takes ownership of the given buffer. virtual void Read(Assignable<Buffer>* buffer) = 0; @@ -198,7 +198,7 @@ class VideoDecoder : public MediaFilter { virtual bool Initialize(DemuxerStream* demuxer_stream) = 0; // Returns the MediaFormat for this filter. - virtual const MediaFormat* GetMediaFormat() = 0; + virtual const MediaFormat& media_format() = 0; // Schedules a read and takes ownership of the given buffer. virtual void Read(Assignable<VideoFrame>* video_frame) = 0; @@ -219,7 +219,7 @@ class AudioDecoder : public MediaFilter { virtual bool Initialize(DemuxerStream* demuxer_stream) = 0; // Returns the MediaFormat for this filter. - virtual const MediaFormat* GetMediaFormat() = 0; + virtual const MediaFormat& media_format() = 0; // Schedules a read and takes ownership of the given buffer. virtual void Read(Assignable<Buffer>* buffer) = 0; diff --git a/media/base/mock_media_filters.h b/media/base/mock_media_filters.h index 4f12c00..4695a65 100644 --- a/media/base/mock_media_filters.h +++ b/media/base/mock_media_filters.h @@ -124,8 +124,8 @@ class MockDataSource : public DataSource { } } - virtual const MediaFormat* GetMediaFormat() { - return &media_format_; + virtual const MediaFormat& media_format() { + return media_format_; } virtual size_t Read(uint8* data, size_t size) { @@ -210,8 +210,8 @@ class MockDemuxerStream : public DemuxerStream { } // Implementation of DemuxerStream. - virtual const MediaFormat* GetMediaFormat() { - return &media_format_; + virtual const MediaFormat& media_format() { + return media_format_; } virtual void Read(Assignable<Buffer>* buffer) { @@ -299,7 +299,7 @@ class MockAudioDecoder : public AudioDecoder { const MockFilterConfig*>(config); } - static bool IsMediaFormatSupported(const MediaFormat* media_format) { + static bool IsMediaFormatSupported(const MediaFormat& media_format) { return true; // TODO(ralphl): check for a supported format. } @@ -317,8 +317,8 @@ class MockAudioDecoder : public AudioDecoder { return true; } - virtual const MediaFormat* GetMediaFormat() { - return &media_format_; + virtual const MediaFormat& media_format() { + return media_format_; } virtual void Read(Assignable<Buffer>* buffer) { @@ -343,7 +343,7 @@ class MockAudioRenderer : public AudioRenderer { const MockFilterConfig*>(config); } - static bool IsMediaFormatSupported(const MediaFormat* media_format) { + static bool IsMediaFormatSupported(const MediaFormat& media_format) { return true; // TODO(ralphl): check for a supported format } @@ -375,7 +375,7 @@ class MockVideoDecoder : public VideoDecoder { const MockFilterConfig*>(config); } - static bool IsMediaFormatSupported(const MediaFormat* media_format) { + static bool IsMediaFormatSupported(const MediaFormat& media_format) { return true; // TODO(ralphl): check for a supported format. } @@ -425,8 +425,8 @@ class MockVideoDecoder : public VideoDecoder { return true; } - virtual const MediaFormat* GetMediaFormat() { - return &media_format_; + virtual const MediaFormat& media_format() { + return media_format_; } virtual void Read(Assignable<VideoFrame>* buffer) { @@ -482,7 +482,7 @@ class MockVideoRenderer : public VideoRenderer { const MockFilterConfig*>(config); } - static bool IsMediaFormatSupported(const MediaFormat* media_format) { + static bool IsMediaFormatSupported(const MediaFormat& media_format) { return true; // TODO(ralphl): check for a supported format } diff --git a/media/base/pipeline_impl.cc b/media/base/pipeline_impl.cc index 3e3a40d..a36da6c 100644 --- a/media/base/pipeline_impl.cc +++ b/media/base/pipeline_impl.cc @@ -418,13 +418,12 @@ void PipelineThread::Render(FilterFactory* filter_factory, Demuxer* demuxer) { const std::string major_mime_type = Decoder::major_mime_type(); const int num_outputs = demuxer->GetNumberOfStreams(); for (int i = 0; i < num_outputs; ++i) { - scoped_refptr<DemuxerStream> demuxer_stream = demuxer->GetStream(i); - const MediaFormat* stream_format = demuxer_stream->GetMediaFormat(); + scoped_refptr<DemuxerStream> stream = demuxer->GetStream(i); std::string value; - if (stream_format->GetAsString(MediaFormat::kMimeType, &value) && + if (stream->media_format().GetAsString(MediaFormat::kMimeType, &value) && 0 == value.compare(0, major_mime_type.length(), major_mime_type)) { scoped_refptr<Decoder> decoder = - CreateFilter<Decoder, DemuxerStream>(filter_factory, demuxer_stream); + CreateFilter<Decoder, DemuxerStream>(filter_factory, stream); if (PipelineOk()) { DCHECK(decoder); CreateFilter<Renderer, Decoder>(filter_factory, decoder); @@ -500,7 +499,7 @@ template <class Filter, class Source> scoped_refptr<Filter> PipelineThread::CreateFilter( FilterFactory* filter_factory, Source source, - const MediaFormat* media_format) { + const MediaFormat& media_format) { DCHECK(PipelineOk()); scoped_refptr<Filter> filter = filter_factory->Create<Filter>(media_format); if (!filter) { @@ -549,7 +548,7 @@ scoped_refptr<DataSource> PipelineThread::CreateDataSource( MediaFormat url_format; url_format.SetAsString(MediaFormat::kMimeType, mime_type::kURL); url_format.SetAsString(MediaFormat::kURL, url); - return CreateFilter<DataSource>(filter_factory, url, &url_format); + return CreateFilter<DataSource>(filter_factory, url, url_format); } // Called as a result of destruction of the thread. diff --git a/media/base/pipeline_impl.h b/media/base/pipeline_impl.h index a5b8c0e..c4c4393 100644 --- a/media/base/pipeline_impl.h +++ b/media/base/pipeline_impl.h @@ -266,7 +266,7 @@ class PipelineThread : public base::RefCountedThreadSafe<PipelineThread>, template <class Filter, class Source> scoped_refptr<Filter> CreateFilter(FilterFactory* filter_factory, Source source, - const MediaFormat* source_media_format); + const MediaFormat& source_media_format); // Creates a Filter and initilizes it with the given |source|. If a Filter // could not be created or an error occurred, this metod returns NULL and the @@ -278,7 +278,7 @@ class PipelineThread : public base::RefCountedThreadSafe<PipelineThread>, Source* source) { return CreateFilter<Filter, Source*>(filter_factory, source, - source->GetMediaFormat()); + source->media_format()); } // Creates a DataSource (the first filter in a pipeline), and initializes it diff --git a/media/filters/audio_renderer_base.cc b/media/filters/audio_renderer_base.cc index 880ca37..a444ba6 100644 --- a/media/filters/audio_renderer_base.cc +++ b/media/filters/audio_renderer_base.cc @@ -52,7 +52,7 @@ bool AudioRendererBase::Initialize(AudioDecoder* decoder) { } // Defer initialization until all scheduled reads have completed. - return OnInitialize(decoder_->GetMediaFormat()); + return OnInitialize(decoder_->media_format()); } void AudioRendererBase::OnAssignment(Buffer* buffer_in) { @@ -138,16 +138,16 @@ void AudioRendererBase::ScheduleRead() { } // static -bool AudioRendererBase::ParseMediaFormat(const MediaFormat* media_format, +bool AudioRendererBase::ParseMediaFormat(const MediaFormat& media_format, int* channels_out, int* sample_rate_out, int* sample_bits_out) { // TODO(scherkus): might be handy to support NULL parameters. std::string mime_type; - return media_format->GetAsString(MediaFormat::kMimeType, &mime_type) && - media_format->GetAsInteger(MediaFormat::kChannels, channels_out) && - media_format->GetAsInteger(MediaFormat::kSampleRate, sample_rate_out) && - media_format->GetAsInteger(MediaFormat::kSampleBits, sample_bits_out) && + return media_format.GetAsString(MediaFormat::kMimeType, &mime_type) && + media_format.GetAsInteger(MediaFormat::kChannels, channels_out) && + media_format.GetAsInteger(MediaFormat::kSampleRate, sample_rate_out) && + media_format.GetAsInteger(MediaFormat::kSampleBits, sample_bits_out) && mime_type.compare(mime_type::kUncompressedAudio) == 0; } diff --git a/media/filters/audio_renderer_base.h b/media/filters/audio_renderer_base.h index fd371e6..6553b12 100644 --- a/media/filters/audio_renderer_base.h +++ b/media/filters/audio_renderer_base.h @@ -43,13 +43,13 @@ class AudioRendererBase : public AudioRenderer { static const size_t kDefaultMaxQueueSize; // Only allow a factory to create this class. - AudioRendererBase(size_t max_queue_size); + explicit AudioRendererBase(size_t max_queue_size); virtual ~AudioRendererBase(); // Called by Initialize(). |media_format| is the format of the AudioDecoder. // Subclasses should return true if they were able to initialize, false // otherwise. - virtual bool OnInitialize(const MediaFormat* media_format) = 0; + virtual bool OnInitialize(const MediaFormat& media_format) = 0; // Called by Stop(). Subclasses should perform any necessary cleanup during // this time, such as stopping any running threads. @@ -70,7 +70,7 @@ class AudioRendererBase : public AudioRenderer { // Helper to parse a media format and return whether we were successful // retrieving all the information we care about. - static bool ParseMediaFormat(const MediaFormat* media_format, + static bool ParseMediaFormat(const MediaFormat& media_format, int* channels_out, int* sample_rate_out, int* sample_bits_out); diff --git a/media/filters/audio_renderer_impl.cc b/media/filters/audio_renderer_impl.cc index 7b66e14..55a1096 100644 --- a/media/filters/audio_renderer_impl.cc +++ b/media/filters/audio_renderer_impl.cc @@ -25,7 +25,7 @@ AudioRendererImpl::~AudioRendererImpl() { } bool AudioRendererImpl::IsMediaFormatSupported( - const MediaFormat* media_format) { + const MediaFormat& media_format) { int channels; int sample_rate; int sample_bits; @@ -66,7 +66,7 @@ void AudioRendererImpl::OnError(AudioOutputStream* stream, int code) { NOTIMPLEMENTED(); } -bool AudioRendererImpl::OnInitialize(const MediaFormat* media_format) { +bool AudioRendererImpl::OnInitialize(const MediaFormat& media_format) { // Parse out audio parameters. int channels; int sample_rate; diff --git a/media/filters/audio_renderer_impl.h b/media/filters/audio_renderer_impl.h index 85ebca0..b7e551b 100644 --- a/media/filters/audio_renderer_impl.h +++ b/media/filters/audio_renderer_impl.h @@ -29,7 +29,7 @@ class AudioRendererImpl : public AudioRendererBase, return new FilterFactoryImpl0<AudioRendererImpl>(); } - static bool IsMediaFormatSupported(const MediaFormat* media_format); + static bool IsMediaFormatSupported(const MediaFormat& media_format); // MediaFilter implementation. virtual void SetPlaybackRate(float playback_rate); @@ -49,7 +49,7 @@ class AudioRendererImpl : public AudioRendererBase, virtual ~AudioRendererImpl(); // AudioRendererBase implementation. - virtual bool OnInitialize(const MediaFormat* media_format); + virtual bool OnInitialize(const MediaFormat& media_format); virtual void OnStop(); private: diff --git a/media/filters/decoder_base.h b/media/filters/decoder_base.h index 685495d..adecbf2 100644 --- a/media/filters/decoder_base.h +++ b/media/filters/decoder_base.h @@ -58,7 +58,7 @@ class DecoderBase : public Decoder { } } - virtual const MediaFormat* GetMediaFormat() { return &media_format_; } + virtual const MediaFormat& media_format() { return media_format_; } // Audio or Video decoder. virtual void Read(Assignable<Output>* output) { diff --git a/media/filters/ffmpeg_audio_decoder.cc b/media/filters/ffmpeg_audio_decoder.cc index 378d865..74559d3 100644 --- a/media/filters/ffmpeg_audio_decoder.cc +++ b/media/filters/ffmpeg_audio_decoder.cc @@ -16,7 +16,7 @@ FFmpegAudioDecoder::~FFmpegAudioDecoder() { } // static -bool FFmpegAudioDecoder::IsMediaFormatSupported(const MediaFormat* format) { +bool FFmpegAudioDecoder::IsMediaFormatSupported(const MediaFormat& format) { NOTIMPLEMENTED(); return false; } diff --git a/media/filters/ffmpeg_audio_decoder.h b/media/filters/ffmpeg_audio_decoder.h index 9df354b..52ffde9 100644 --- a/media/filters/ffmpeg_audio_decoder.h +++ b/media/filters/ffmpeg_audio_decoder.h @@ -19,7 +19,7 @@ class FFmpegAudioDecoder : public DecoderBase<AudioDecoder, Buffer> { return new FilterFactoryImpl0<FFmpegAudioDecoder>(); } - static bool IsMediaFormatSupported(const MediaFormat* media_format); + static bool IsMediaFormatSupported(const MediaFormat& media_format); virtual bool OnInitialize(DemuxerStream* demuxer_stream); diff --git a/media/filters/ffmpeg_demuxer.cc b/media/filters/ffmpeg_demuxer.cc index 5fce5a4..0446325 100644 --- a/media/filters/ffmpeg_demuxer.cc +++ b/media/filters/ffmpeg_demuxer.cc @@ -123,8 +123,8 @@ void FFmpegDemuxerStream::EnqueuePacket(AVPacket* packet) { FulfillPendingReads(); } -const MediaFormat* FFmpegDemuxerStream::GetMediaFormat() { - return &media_format_; +const MediaFormat& FFmpegDemuxerStream::media_format() { + return media_format_; } void FFmpegDemuxerStream::Read(Assignable<Buffer>* buffer) { diff --git a/media/filters/ffmpeg_demuxer.h b/media/filters/ffmpeg_demuxer.h index 317969d..dea349d 100644 --- a/media/filters/ffmpeg_demuxer.h +++ b/media/filters/ffmpeg_demuxer.h @@ -57,7 +57,7 @@ class FFmpegDemuxerStream : public DemuxerStream { base::TimeDelta duration() { return duration_; } // DemuxerStream implementation. - virtual const MediaFormat* GetMediaFormat(); + virtual const MediaFormat& media_format(); virtual void Read(Assignable<Buffer>* buffer); AVStream* av_stream() { diff --git a/media/filters/ffmpeg_demuxer_unittest.cc b/media/filters/ffmpeg_demuxer_unittest.cc index b37196d..aeba6fe 100644 --- a/media/filters/ffmpeg_demuxer_unittest.cc +++ b/media/filters/ffmpeg_demuxer_unittest.cc @@ -148,12 +148,12 @@ TEST(FFmpegDemuxerTest, InitializeFailure) { // Should only accept application/octet-stream type. MediaFormat media_format; media_format.SetAsString(MediaFormat::kMimeType, "foo/x-bar"); - scoped_refptr<Demuxer> demuxer(factory->Create<Demuxer>(&media_format)); + scoped_refptr<Demuxer> demuxer(factory->Create<Demuxer>(media_format)); ASSERT_FALSE(demuxer); media_format.Clear(); media_format.SetAsString(MediaFormat::kMimeType, mime_type::kApplicationOctetStream); - demuxer = factory->Create<Demuxer>(&media_format); + demuxer = factory->Create<Demuxer>(media_format); ASSERT_TRUE(demuxer); // Prepare a filter host and data source for the demuxer. @@ -173,7 +173,7 @@ TEST(FFmpegDemuxerTest, InitializeFailure) { // Simulate av_find_stream_info failing. g_av_open_input_file = 0; g_av_find_stream_info = AVERROR_IO; - demuxer = factory->Create<Demuxer>(&media_format); + demuxer = factory->Create<Demuxer>(media_format); filter_host.reset(new MockFilterHost<Demuxer>(&pipeline, demuxer)); EXPECT_FALSE(demuxer->Initialize(data_source)); EXPECT_FALSE(filter_host->IsInitialized()); @@ -181,7 +181,7 @@ TEST(FFmpegDemuxerTest, InitializeFailure) { // Simulate media with no parseable streams. InitializeFFmpegMocks(); - demuxer = factory->Create<Demuxer>(&media_format); + demuxer = factory->Create<Demuxer>(media_format); filter_host.reset(new MockFilterHost<Demuxer>(&pipeline, demuxer)); EXPECT_FALSE(demuxer->Initialize(data_source)); EXPECT_FALSE(filter_host->IsInitialized()); @@ -192,7 +192,7 @@ TEST(FFmpegDemuxerTest, InitializeFailure) { g_format.streams[0] = &g_streams[0]; g_streams[0].codec = &g_data_codec; g_streams[0].duration = 10; - demuxer = factory->Create<Demuxer>(&media_format); + demuxer = factory->Create<Demuxer>(media_format); filter_host.reset(new MockFilterHost<Demuxer>(&pipeline, demuxer)); EXPECT_FALSE(demuxer->Initialize(data_source)); EXPECT_FALSE(filter_host->IsInitialized()); @@ -226,7 +226,7 @@ TEST(FFmpegDemuxerTest, InitializeStreams) { // Create our demuxer. scoped_refptr<FilterFactory> factory = FFmpegDemuxer::CreateFilterFactory(); scoped_refptr<Demuxer> demuxer - = factory->Create<Demuxer>(data_source->GetMediaFormat()); + = factory->Create<Demuxer>(data_source->media_format()); EXPECT_TRUE(demuxer); MockFilterHost<Demuxer> filter_host_b(&pipeline, demuxer); EXPECT_TRUE(demuxer->Initialize(data_source)); @@ -243,29 +243,35 @@ TEST(FFmpegDemuxerTest, InitializeStreams) { // First stream should be video. scoped_refptr<DemuxerStream> stream = demuxer->GetStream(0); ASSERT_TRUE(stream); - const MediaFormat* stream_format = stream->GetMediaFormat(); std::string mime_type; int result; - EXPECT_TRUE(stream_format->GetAsString(MediaFormat::kMimeType, &mime_type)); + EXPECT_TRUE( + stream->media_format().GetAsString(MediaFormat::kMimeType, &mime_type)); EXPECT_STREQ(mime_type::kFFmpegVideo, mime_type.c_str()); - EXPECT_TRUE(stream_format->GetAsInteger(kFFmpegCodecID, &result)); + EXPECT_TRUE( + stream->media_format().GetAsInteger(kFFmpegCodecID, &result)); EXPECT_EQ(CODEC_ID_THEORA, static_cast<CodecID>(result)); - EXPECT_TRUE(stream_format->GetAsInteger(MediaFormat::kHeight, &result)); + EXPECT_TRUE( + stream->media_format().GetAsInteger(MediaFormat::kHeight, &result)); EXPECT_EQ(g_video_codec.height, result); - EXPECT_TRUE(stream_format->GetAsInteger(MediaFormat::kWidth, &result)); + EXPECT_TRUE( + stream->media_format().GetAsInteger(MediaFormat::kWidth, &result)); EXPECT_EQ(g_video_codec.width, result); // Second stream should be audio. stream = demuxer->GetStream(1); ASSERT_TRUE(stream); - stream_format = stream->GetMediaFormat(); - EXPECT_TRUE(stream_format->GetAsString(MediaFormat::kMimeType, &mime_type)); + EXPECT_TRUE( + stream->media_format().GetAsString(MediaFormat::kMimeType, &mime_type)); EXPECT_STREQ(mime_type::kFFmpegAudio, mime_type.c_str()); - EXPECT_TRUE(stream_format->GetAsInteger(kFFmpegCodecID, &result)); + EXPECT_TRUE( + stream->media_format().GetAsInteger(kFFmpegCodecID, &result)); EXPECT_EQ(CODEC_ID_VORBIS, static_cast<CodecID>(result)); - EXPECT_TRUE(stream_format->GetAsInteger(MediaFormat::kChannels, &result)); + EXPECT_TRUE( + stream->media_format().GetAsInteger(MediaFormat::kChannels, &result)); EXPECT_EQ(g_audio_codec.channels, result); - EXPECT_TRUE(stream_format->GetAsInteger(MediaFormat::kSampleRate, &result)); + EXPECT_TRUE( + stream->media_format().GetAsInteger(MediaFormat::kSampleRate, &result)); EXPECT_EQ(g_audio_codec.sample_rate, result); } @@ -300,7 +306,7 @@ TEST(FFmpegDemuxerTest, Read) { // Create our demuxer. scoped_refptr<FilterFactory> factory = FFmpegDemuxer::CreateFilterFactory(); scoped_refptr<Demuxer> demuxer - = factory->Create<Demuxer>(data_source->GetMediaFormat()); + = factory->Create<Demuxer>(data_source->media_format()); EXPECT_TRUE(demuxer); MockFilterHost<Demuxer> filter_host_b(&pipeline, demuxer); EXPECT_TRUE(demuxer->Initialize(data_source)); @@ -335,7 +341,7 @@ TEST(FFmpegDemuxerTest, Read) { pipeline.RunAllTasks(); EXPECT_TRUE(buffer->assigned()); EXPECT_TRUE(buffer->buffer()); - EXPECT_EQ(audio_data, (uint8*)buffer->buffer()->GetData()); + EXPECT_EQ(audio_data, buffer->buffer()->GetData()); EXPECT_EQ(kDataSize, buffer->buffer()->GetDataSize()); // Prepare our test video packet. @@ -349,7 +355,7 @@ TEST(FFmpegDemuxerTest, Read) { pipeline.RunAllTasks(); EXPECT_TRUE(buffer->assigned()); EXPECT_TRUE(buffer->buffer()); - EXPECT_EQ(video_data, (uint8*)buffer->buffer()->GetData()); + EXPECT_EQ(video_data, buffer->buffer()->GetData()); EXPECT_EQ(kDataSize, buffer->buffer()->GetDataSize()); // Simulate end of stream. diff --git a/media/filters/ffmpeg_video_decoder.cc b/media/filters/ffmpeg_video_decoder.cc index dad8b88..f429ea6 100644 --- a/media/filters/ffmpeg_video_decoder.cc +++ b/media/filters/ffmpeg_video_decoder.cc @@ -16,7 +16,7 @@ FFmpegVideoDecoder::~FFmpegVideoDecoder() { } // static -bool FFmpegVideoDecoder::IsMediaFormatSupported(const MediaFormat* format) { +bool FFmpegVideoDecoder::IsMediaFormatSupported(const MediaFormat& format) { NOTIMPLEMENTED(); return false; } diff --git a/media/filters/ffmpeg_video_decoder.h b/media/filters/ffmpeg_video_decoder.h index 7e9fb91..a047823 100644 --- a/media/filters/ffmpeg_video_decoder.h +++ b/media/filters/ffmpeg_video_decoder.h @@ -19,7 +19,7 @@ class FFmpegVideoDecoder : public DecoderBase<VideoDecoder, VideoFrame> { return new FilterFactoryImpl0<FFmpegVideoDecoder>(); } - static bool IsMediaFormatSupported(const MediaFormat* media_format); + static bool IsMediaFormatSupported(const MediaFormat& media_format); virtual bool OnInitialize(DemuxerStream* demuxer_stream); diff --git a/media/filters/file_data_source.cc b/media/filters/file_data_source.cc index 854fea2..c622c04 100644 --- a/media/filters/file_data_source.cc +++ b/media/filters/file_data_source.cc @@ -53,8 +53,8 @@ void FileDataSource::Stop() { } } -const MediaFormat* FileDataSource::GetMediaFormat() { - return &media_format_; +const MediaFormat& FileDataSource::media_format() { + return media_format_; } size_t FileDataSource::Read(uint8* data, size_t size) { diff --git a/media/filters/file_data_source.h b/media/filters/file_data_source.h index 1c03cf0..c7bfdfd 100644 --- a/media/filters/file_data_source.h +++ b/media/filters/file_data_source.h @@ -29,7 +29,7 @@ class FileDataSource : public DataSource { // Implementation of DataSource. virtual bool Initialize(const std::string& url); - virtual const MediaFormat* GetMediaFormat(); + virtual const MediaFormat& media_format(); virtual size_t Read(uint8* data, size_t size); virtual bool GetPosition(int64* position_out); virtual bool SetPosition(int64 position); diff --git a/media/filters/file_data_source_unittest.cc b/media/filters/file_data_source_unittest.cc index 2545e7c..8512300 100644 --- a/media/filters/file_data_source_unittest.cc +++ b/media/filters/file_data_source_unittest.cc @@ -88,7 +88,7 @@ TEST(FileDataSourceTest, ReadData) { // Create our data source. scoped_refptr<FilterFactory> factory = FileDataSource::CreateFactory(); - FileDataSource* filter = factory->Create<FileDataSource>(&url_format); + FileDataSource* filter = factory->Create<FileDataSource>(url_format); EXPECT_TRUE(filter); // Create our mock pipeline and filter host and initialize the data source. diff --git a/media/filters/null_audio_renderer.cc b/media/filters/null_audio_renderer.cc index f30ed59..1d50e69 100644 --- a/media/filters/null_audio_renderer.cc +++ b/media/filters/null_audio_renderer.cc @@ -29,7 +29,7 @@ NullAudioRenderer::~NullAudioRenderer() { // static bool NullAudioRenderer::IsMediaFormatSupported( - const MediaFormat* media_format) { + const MediaFormat& media_format) { int channels; int sample_rate; int sample_bits; @@ -63,7 +63,7 @@ void NullAudioRenderer::ThreadMain() { } } -bool NullAudioRenderer::OnInitialize(const MediaFormat* media_format) { +bool NullAudioRenderer::OnInitialize(const MediaFormat& media_format) { // Parse out audio parameters. int channels; int sample_rate; diff --git a/media/filters/null_audio_renderer.h b/media/filters/null_audio_renderer.h index cf66648..824e13d 100644 --- a/media/filters/null_audio_renderer.h +++ b/media/filters/null_audio_renderer.h @@ -37,7 +37,7 @@ class NullAudioRenderer : public AudioRendererBase, PlatformThread::Delegate { } // Compatible with any audio/x-uncompressed MediaFormat. - static bool IsMediaFormatSupported(const MediaFormat* media_format); + static bool IsMediaFormatSupported(const MediaFormat& media_format); // MediaFilter implementation. virtual void SetPlaybackRate(float playback_rate); @@ -55,7 +55,7 @@ class NullAudioRenderer : public AudioRendererBase, PlatformThread::Delegate { virtual ~NullAudioRenderer(); // AudioRendererBase implementation. - virtual bool OnInitialize(const MediaFormat* media_format); + virtual bool OnInitialize(const MediaFormat& media_format); virtual void OnStop(); private: diff --git a/media/filters/test_video_decoder.h b/media/filters/test_video_decoder.h index 3ca6a3f..84d6e66 100644 --- a/media/filters/test_video_decoder.h +++ b/media/filters/test_video_decoder.h @@ -25,13 +25,13 @@ class TestVideoDecoder : public DecoderBase<VideoDecoder, VideoFrame> { } bool OnInitialize(DemuxerStream* demuxer_stream) { - const MediaFormat* media_format = demuxer_stream->GetMediaFormat(); + const MediaFormat& media_format = demuxer_stream->media_format(); std::string mime_type; int width, height; - if (media_format->GetAsString(MediaFormat::kMimeType, &mime_type) && + if (media_format.GetAsString(MediaFormat::kMimeType, &mime_type) && mime_type.compare(mime_type::kH264AnnexB) == 0 && - media_format->GetAsInteger(MediaFormat::kWidth, &width) && - media_format->GetAsInteger(MediaFormat::kHeight, &height)) { + media_format.GetAsInteger(MediaFormat::kWidth, &width) && + media_format.GetAsInteger(MediaFormat::kHeight, &height)) { video_width_ = width; video_height_ = height; media_format_.SetAsString(MediaFormat::kMimeType, @@ -59,9 +59,9 @@ class TestVideoDecoder : public DecoderBase<VideoDecoder, VideoFrame> { } } - static bool IsMediaFormatSupported(const MediaFormat* media_format) { + static bool IsMediaFormatSupported(const MediaFormat& media_format) { std::string mime_type; - return (media_format->GetAsString(MediaFormat::kMimeType, &mime_type) && + return (media_format.GetAsString(MediaFormat::kMimeType, &mime_type) && mime_type == mime_type::kH264AnnexB); } diff --git a/media/filters/test_video_renderer.h b/media/filters/test_video_renderer.h index f6c3c22..f9535f2 100644 --- a/media/filters/test_video_renderer.h +++ b/media/filters/test_video_renderer.h @@ -46,7 +46,7 @@ class TestVideoRenderer : public VideoRendererBase { size_t paint_called() { return paint_called_; } base::TimeDelta last_timestamp() { return last_timestamp_; } - static bool IsMediaFormatSupported(const MediaFormat* format) { + static bool IsMediaFormatSupported(const MediaFormat& format) { return VideoRendererBase::IsMediaFormatSupported(format); } diff --git a/media/filters/video_renderer_base.cc b/media/filters/video_renderer_base.cc index 57caf99..744942f 100644 --- a/media/filters/video_renderer_base.cc +++ b/media/filters/video_renderer_base.cc @@ -45,22 +45,22 @@ VideoRendererBase::~VideoRendererBase() { // static bool VideoRendererBase::IsMediaFormatSupported( - const MediaFormat* media_format) { + const MediaFormat& media_format) { int width; int height; return ParseMediaFormat(media_format, &width, &height); } // static -bool VideoRendererBase::ParseMediaFormat(const MediaFormat* media_format, +bool VideoRendererBase::ParseMediaFormat(const MediaFormat& media_format, int* width_out, int* height_out) { - DCHECK(media_format && width_out && height_out); + DCHECK(width_out && height_out); std::string mime_type; - return (media_format->GetAsString(MediaFormat::kMimeType, &mime_type) && + return (media_format.GetAsString(MediaFormat::kMimeType, &mime_type) && mime_type.compare(mime_type::kUncompressedVideo) == 0 && - media_format->GetAsInteger(MediaFormat::kWidth, width_out) && - media_format->GetAsInteger(MediaFormat::kHeight, height_out)); + media_format.GetAsInteger(MediaFormat::kWidth, width_out) && + media_format.GetAsInteger(MediaFormat::kHeight, height_out)); } void VideoRendererBase::Stop() { @@ -82,7 +82,7 @@ void VideoRendererBase::Stop() { bool VideoRendererBase::Initialize(VideoDecoder* decoder) { int width, height; decoder_ = decoder; - if (ParseMediaFormat(decoder_->GetMediaFormat(), &width, &height) && + if (ParseMediaFormat(decoder_->media_format(), &width, &height) && OnInitialize(width, height)) { host_->SetVideoSize(width, height); host_->SetTimeUpdateCallback( diff --git a/media/filters/video_renderer_base.h b/media/filters/video_renderer_base.h index 16566fc..2c51895 100644 --- a/media/filters/video_renderer_base.h +++ b/media/filters/video_renderer_base.h @@ -85,12 +85,12 @@ class VideoRendererBase : public VideoRenderer { void GetCurrentFrame(scoped_refptr<VideoFrame>* frame_out); // Answers question from the factory to see if we accept |format|. - static bool IsMediaFormatSupported(const MediaFormat* format); + static bool IsMediaFormatSupported(const MediaFormat& format); // Used by the IsMediaFormatSupported and Initialize methods. Examines the // |media_format| and returns true if the format is supported. Both output // parameters, |width_out| and |height_out| are required and must not be NULL. - static bool ParseMediaFormat(const MediaFormat* media_format, + static bool ParseMediaFormat(const MediaFormat& media_format, int* width_out, int* height_out); |