diff options
author | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-09 15:58:16 +0000 |
---|---|---|
committer | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-09 15:58:16 +0000 |
commit | cee323423df2894048258daa02e2b1c3c24e7c46 (patch) | |
tree | 88b6b5da7c1b92daae8c1ff206d2f3c7399814f3 /media | |
parent | 4b571e6b3efa2f510f64de4718a1f37a9542a251 (diff) | |
download | chromium_src-cee323423df2894048258daa02e2b1c3c24e7c46.zip chromium_src-cee323423df2894048258daa02e2b1c3c24e7c46.tar.gz chromium_src-cee323423df2894048258daa02e2b1c3c24e7c46.tar.bz2 |
Remove the silly notion of MIME types from media code.
This was one of the first things I checked into Chromium and I've been wanting to remove it for a long, long time now.
BUG=28206
TEST=media_unittests
Review URL: http://codereview.chromium.org/6623087
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77468 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
28 files changed, 97 insertions, 279 deletions
diff --git a/media/base/composite_filter.cc b/media/base/composite_filter.cc index 7d26035..3e7b60c 100644 --- a/media/base/composite_filter.cc +++ b/media/base/composite_filter.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -69,10 +69,6 @@ bool CompositeFilter::AddFilter(scoped_refptr<Filter> filter) { return true; } -const char* CompositeFilter::major_mime_type() const { - return ""; -} - void CompositeFilter::set_host(FilterHost* host) { DCHECK_EQ(message_loop_, MessageLoop::current()); DCHECK(host); diff --git a/media/base/composite_filter.h b/media/base/composite_filter.h index daac421..5fa8531 100644 --- a/media/base/composite_filter.h +++ b/media/base/composite_filter.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -25,7 +25,6 @@ class CompositeFilter : public Filter { bool AddFilter(scoped_refptr<Filter> filter); // media::Filter methods. - virtual const char* major_mime_type() const; virtual void set_host(FilterHost* host); virtual FilterHost* host(); virtual void Play(FilterCallback* play_callback); diff --git a/media/base/filters.cc b/media/base/filters.cc index eff50b4..1328dd1 100644 --- a/media/base/filters.cc +++ b/media/base/filters.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -12,10 +12,6 @@ Filter::Filter() : host_(NULL) {} Filter::~Filter() {} -const char* Filter::major_mime_type() const { - return ""; -} - void Filter::set_host(FilterHost* host) { DCHECK(host); DCHECK(!host_); @@ -74,22 +70,6 @@ bool DataSource::IsUrlSupported(const std::string& url) { return true; } -const char* AudioDecoder::major_mime_type() const { - return mime_type::kMajorTypeAudio; -} - -const char* AudioRenderer::major_mime_type() const { - return mime_type::kMajorTypeAudio; -} - -const char* VideoDecoder::major_mime_type() const { - return mime_type::kMajorTypeVideo; -} - -const char* VideoRenderer::major_mime_type() const { - return mime_type::kMajorTypeVideo; -} - void* DemuxerStream::QueryInterface(const char* interface_id) { return NULL; } diff --git a/media/base/filters.h b/media/base/filters.h index 06f44c2..11bf526 100644 --- a/media/base/filters.h +++ b/media/base/filters.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -53,9 +53,6 @@ class Filter : public base::RefCountedThreadSafe<Filter> { public: Filter(); - // Return the major mime type for this filter. - virtual const char* major_mime_type() const; - // Sets the private member |host_|. This is the first method called by // the FilterHost after a filter is created. The host holds a strong // reference to the filter. The reference held by the host is guaranteed @@ -156,6 +153,12 @@ class Demuxer : public Filter { class DemuxerStream : public base::RefCountedThreadSafe<DemuxerStream> { public: + enum Type { + UNKNOWN, + AUDIO, + VIDEO, + }; + // Schedules a read. When the |read_callback| is called, the downstream // filter takes ownership of the buffer by AddRef()'ing the buffer. // @@ -173,6 +176,9 @@ class DemuxerStream : public base::RefCountedThreadSafe<DemuxerStream> { return (NULL != i); }; + // Returns the type of stream. + virtual Type type() = 0; + // Returns the media format of this stream. virtual const MediaFormat& media_format() = 0; @@ -194,8 +200,6 @@ class DemuxerStream : public base::RefCountedThreadSafe<DemuxerStream> { class VideoDecoder : public Filter { public: - virtual const char* major_mime_type() const; - // Initialize a VideoDecoder with the given DemuxerStream, executing the // callback upon completion. // stats_callback is used to update global pipeline statistics. @@ -238,8 +242,6 @@ class VideoDecoder : public Filter { class AudioDecoder : public Filter { public: - virtual const char* major_mime_type() const; - // Initialize a AudioDecoder with the given DemuxerStream, executing the // callback upon completion. // stats_callback is used to update global pipeline statistics. @@ -277,8 +279,6 @@ class AudioDecoder : public Filter { class VideoRenderer : public Filter { public: - virtual const char* major_mime_type() const; - // Initialize a VideoRenderer with the given VideoDecoder, executing the // callback upon completion. virtual void Initialize(VideoDecoder* decoder, FilterCallback* callback, @@ -292,8 +292,6 @@ class VideoRenderer : public Filter { class AudioRenderer : public Filter { public: - virtual const char* major_mime_type() const; - // Initialize a AudioRenderer with the given AudioDecoder, executing the // callback upon completion. virtual void Initialize(AudioDecoder* decoder, FilterCallback* callback) = 0; diff --git a/media/base/media_format.cc b/media/base/media_format.cc index 80c60e0..45df6b6 100644 --- a/media/base/media_format.cc +++ b/media/base/media_format.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,52 +6,6 @@ namespace media { -namespace mime_type { - -// Represents a URL, typically used to create a DataSourceInterface. -// Expected keys: -// kURL String The URL -const char kURL[] = "text/x-url"; - -// Represents a generic byte stream, typically from a DataSourceInterface. -// Expected keys: -// None -const char kApplicationOctetStream[] = "application/octet-stream"; - -// Represents encoded audio data, typically from an DemuxerStreamInterface. -// Expected keys: -// None -const char kMPEGAudio[] = "audio/mpeg"; -const char kAACAudio[] = "audio/aac"; - -// Represents encoded video data, typically from a DemuxerStreamInterface. -// Expected keys: -// None -const char kH264AnnexB[] = "video/x-h264-annex-b"; - -// Represents decoded audio data, typically from an AudioDecoderInterface. -// Expected keys: -// kChannels Integer Number of audio channels -// kSampleRate Integer Audio sample rate (i.e., 44100) -// kSampleBits Integer Audio bits-per-sample (i.e., 16) -const char kUncompressedAudio[] = "audio/x-uncompressed"; - -// Represents decoded video data, typically from a VideoDecoderInterface. -// Other information, such as surface format (i.e., YV12), stride and planes are -// included with the buffer itself and is not part of the MediaFormat. -// Expected keys: -// kWidth Integer Display width of the surface -// kHeight Integer Display height of the surface -const char kUncompressedVideo[] = "video/x-uncompressed"; - -// Major types of media types begin with the prefix "audio/" or "video/". -const char kMajorTypeVideo[] = "video/"; -const char kMajorTypeAudio[] = "audio/"; - -} // namespace mime_type - -// Common keys. -const char MediaFormat::kMimeType[] = "MimeType"; const char MediaFormat::kURL[] = "URL"; const char MediaFormat::kSurfaceFormat[] = "SurfaceFormat"; const char MediaFormat::kSurfaceType[] = "SurfaceType"; @@ -60,10 +14,8 @@ const char MediaFormat::kSampleBits[] = "SampleBits"; const char MediaFormat::kChannels[] = "Channels"; const char MediaFormat::kWidth[] = "Width"; const char MediaFormat::kHeight[] = "Height"; -const char MediaFormat::kFFmpegCodecID[] = "FFmpegCodecID"; -MediaFormat::MediaFormat() { -} +MediaFormat::MediaFormat() {} MediaFormat::~MediaFormat() { Clear(); diff --git a/media/base/media_format.h b/media/base/media_format.h index 7b53d63..781afd4 100644 --- a/media/base/media_format.h +++ b/media/base/media_format.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -12,40 +12,16 @@ namespace media { -// Common MIME types. -namespace mime_type { -extern const char kURL[]; -extern const char kApplicationOctetStream[]; -extern const char kMPEGAudio[]; -extern const char kAACAudio[]; -extern const char kH264AnnexB[]; -extern const char kUncompressedAudio[]; -extern const char kUncompressedVideo[]; -extern const char kUncompressedVideoEglImage[]; -extern const char kMajorTypeAudio[]; -extern const char kMajorTypeVideo[]; -} // namespace mime_type - // MediaFormat is used to describe the output of a Filter to determine whether // a downstream filter can accept the output from an upstream filter. -// In general, every MediaFormat contains a MIME type describing its output as -// well as additional key-values describing additional details. -// -// For example, an audio decoder could output audio/x-uncompressed and include -// additional key-values such as the number of channels and the sample rate. -// An audio renderer would use this information to properly initialize the -// audio hardware before playback started. // -// It's also perfectly acceptable to create your own MIME types and standards -// to allow communication between two filters that goes beyond the basics -// described here. For example, you could write a video decoder that outputs -// a MIME type video/x-special for which your video renderer knows it's some -// special form of decompressed video output that regular video renderers -// couldn't handle. +// For example, an audio decoder could output key-values for the number of +// channels and the sample rate. A downstream audio renderer would use this +// information to properly initialize the audio hardware before playback +// started. class MediaFormat { public: // Common keys. - static const char kMimeType[]; static const char kURL[]; static const char kSurfaceType[]; static const char kSurfaceFormat[]; @@ -54,7 +30,6 @@ class MediaFormat { static const char kChannels[]; static const char kWidth[]; static const char kHeight[]; - static const char kFFmpegCodecID[]; MediaFormat(); ~MediaFormat(); diff --git a/media/base/mock_filters.h b/media/base/mock_filters.h index e54e5da..dd391ac 100644 --- a/media/base/mock_filters.h +++ b/media/base/mock_filters.h @@ -119,6 +119,7 @@ class MockDemuxerStream : public DemuxerStream { MockDemuxerStream(); // DemuxerStream implementation. + MOCK_METHOD0(type, Type()); MOCK_METHOD0(media_format, const MediaFormat&()); MOCK_METHOD1(Read, void(Callback1<Buffer*>::Type* read_callback)); MOCK_METHOD1(QueryInterface, void*(const char* interface_id)); diff --git a/media/base/pipeline.h b/media/base/pipeline.h index 0b87d29..8e7a8db 100644 --- a/media/base/pipeline.h +++ b/media/base/pipeline.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -121,11 +121,11 @@ class Pipeline : public base::RefCountedThreadSafe<Pipeline> { // Returns true if there has been network activity. virtual bool IsNetworkActive() const = 0; - // If the |major_mime_type| exists in the pipeline and is being rendered, this - // method will return true. Types are defined in media/base/media_foramt.h. - // For example, to determine if a pipeline contains video: - // bool has_video = pipeline->IsRendered(mime_type::kMajorTypeVideo); - virtual bool IsRendered(const std::string& major_mime_type) const = 0; + // Returns true if the media has audio. + virtual bool HasAudio() const = 0; + + // Returns true if the media has video. + virtual bool HasVideo() const = 0; // Gets the current playback rate of the pipeline. When the pipeline is // started, the playback rate will be 0.0f. A rate of 1.0f indicates diff --git a/media/base/pipeline_impl.cc b/media/base/pipeline_impl.cc index 9bce38c..d4009c8 100644 --- a/media/base/pipeline_impl.cc +++ b/media/base/pipeline_impl.cc @@ -135,11 +135,14 @@ bool PipelineImpl::IsNetworkActive() const { return network_activity_; } -bool PipelineImpl::IsRendered(const std::string& major_mime_type) const { +bool PipelineImpl::HasAudio() const { base::AutoLock auto_lock(lock_); - bool is_rendered = (rendered_mime_types_.find(major_mime_type) != - rendered_mime_types_.end()); - return is_rendered; + return has_audio_; +} + +bool PipelineImpl::HasVideo() const { + base::AutoLock auto_lock(lock_); + return has_video_; } float PipelineImpl::GetPlaybackRate() const { @@ -321,10 +324,11 @@ void PipelineImpl::ResetState() { volume_ = 1.0f; playback_rate_ = 0.0f; error_ = PIPELINE_OK; + has_audio_ = false; + has_video_ = false; waiting_for_clock_update_ = false; audio_disabled_ = false; clock_->SetTime(kZero); - rendered_mime_types_.clear(); } void PipelineImpl::set_state(State next_state) { @@ -509,18 +513,6 @@ void PipelineImpl::DisableAudioRenderer() { NewRunnableMethod(this, &PipelineImpl::DisableAudioRendererTask)); } -void PipelineImpl::InsertRenderedMimeType(const std::string& major_mime_type) { - DCHECK(IsRunning()); - base::AutoLock auto_lock(lock_); - rendered_mime_types_.insert(major_mime_type); -} - -bool PipelineImpl::HasRenderedMimeTypes() const { - DCHECK(IsRunning()); - base::AutoLock auto_lock(lock_); - return !rendered_mime_types_.empty(); -} - // Called from any thread. void PipelineImpl::OnFilterInitialize() { // Continue the initialize task by proceeding to the next stage. @@ -627,7 +619,8 @@ void PipelineImpl::InitializeTask() { set_state(kInitAudioRenderer); // Returns false if there's no audio stream. if (InitializeAudioRenderer(pipeline_init_state_->audio_decoder_)) { - InsertRenderedMimeType(mime_type::kMajorTypeAudio); + base::AutoLock auto_lock(lock_); + has_audio_ = true; return; } } @@ -644,13 +637,14 @@ void PipelineImpl::InitializeTask() { if (state_ == kInitVideoDecoder) { set_state(kInitVideoRenderer); if (InitializeVideoRenderer(pipeline_init_state_->video_decoder_)) { - InsertRenderedMimeType(mime_type::kMajorTypeVideo); + base::AutoLock auto_lock(lock_); + has_video_ = true; return; } } if (state_ == kInitVideoRenderer) { - if (!IsPipelineOk() || !HasRenderedMimeTypes()) { + if (!IsPipelineOk() || !(HasAudio() || HasVideo())) { SetError(PIPELINE_ERROR_COULD_NOT_RENDER); return; } @@ -856,11 +850,8 @@ void PipelineImpl::NotifyNetworkEventTask() { void PipelineImpl::DisableAudioRendererTask() { DCHECK_EQ(MessageLoop::current(), message_loop_); - // |rendered_mime_types_| is read through public methods so we need to lock - // this variable. base::AutoLock auto_lock(lock_); - rendered_mime_types_.erase(mime_type::kMajorTypeAudio); - + has_audio_ = false; audio_disabled_ = true; // Notify all filters of disabled audio renderer. If the filter isn't @@ -929,9 +920,7 @@ void PipelineImpl::FilterStateTransitionTask() { base::AutoLock auto_lock(lock_); // We use audio stream to update the clock. So if there is such a stream, // we pause the clock until we receive a valid timestamp. - waiting_for_clock_update_ = - rendered_mime_types_.find(mime_type::kMajorTypeAudio) != - rendered_mime_types_.end(); + waiting_for_clock_update_ = has_audio_; if (!waiting_for_clock_update_) clock_->Play(); @@ -1073,7 +1062,7 @@ bool PipelineImpl::InitializeAudioDecoder( DCHECK(IsPipelineOk()); scoped_refptr<DemuxerStream> stream = - FindDemuxerStream(demuxer, mime_type::kMajorTypeAudio); + FindDemuxerStream(demuxer, DemuxerStream::AUDIO); if (!stream) return false; @@ -1103,7 +1092,7 @@ bool PipelineImpl::InitializeVideoDecoder( DCHECK(IsPipelineOk()); scoped_refptr<DemuxerStream> stream = - FindDemuxerStream(demuxer, mime_type::kMajorTypeVideo); + FindDemuxerStream(demuxer, DemuxerStream::VIDEO); if (!stream) return false; @@ -1175,15 +1164,13 @@ bool PipelineImpl::InitializeVideoRenderer( scoped_refptr<DemuxerStream> PipelineImpl::FindDemuxerStream( const scoped_refptr<Demuxer>& demuxer, - std::string major_mime_type) { + DemuxerStream::Type type) { DCHECK(demuxer); const int num_outputs = demuxer->GetNumberOfStreams(); for (int i = 0; i < num_outputs; ++i) { std::string value; - if (demuxer->GetStream(i)->media_format().GetAsString( - MediaFormat::kMimeType, &value) && - !value.compare(0, major_mime_type.length(), major_mime_type)) { + if (demuxer->GetStream(i)->type() == type) { return demuxer->GetStream(i); } } diff --git a/media/base/pipeline_impl.h b/media/base/pipeline_impl.h index e817eed..fa4b5d1 100644 --- a/media/base/pipeline_impl.h +++ b/media/base/pipeline_impl.h @@ -78,7 +78,8 @@ class PipelineImpl : public Pipeline, public FilterHost { virtual bool IsRunning() const; virtual bool IsInitialized() const; virtual bool IsNetworkActive() const; - virtual bool IsRendered(const std::string& major_mime_type) const; + virtual bool HasAudio() const; + virtual bool HasVideo() const; virtual float GetPlaybackRate() const; virtual void SetPlaybackRate(float playback_rate); virtual float GetVolume() const; @@ -172,13 +173,6 @@ class PipelineImpl : public Pipeline, public FilterHost { virtual void SetCurrentReadPosition(int64 offset); virtual int64 GetCurrentReadPosition(); - // Method called during initialization to insert a mime type into the - // |rendered_mime_types_| set. - void InsertRenderedMimeType(const std::string& major_mime_type); - - // Method called during initialization to determine if we rendered anything. - bool HasRenderedMimeTypes() const; - // Callback executed by filters upon completing initialization. void OnFilterInitialize(); @@ -267,10 +261,11 @@ class PipelineImpl : public Pipeline, public FilterHost { bool InitializeAudioRenderer(const scoped_refptr<AudioDecoder>& decoder); bool InitializeVideoRenderer(const scoped_refptr<VideoDecoder>& decoder); - // Helper to find the demuxer of |major_mime_type| from Demuxer. + // Returns a reference to the DemuxerStream of the requested type if it + // exists, NULL otherwise. scoped_refptr<DemuxerStream> FindDemuxerStream( const scoped_refptr<Demuxer>& demuxer, - std::string major_mime_type); + DemuxerStream::Type type); // Kicks off destroying filters. Called by StopTask() and ErrorChangedTask(). // When we start to tear down the pipeline, we will consider two cases: @@ -359,9 +354,9 @@ class PipelineImpl : public Pipeline, public FilterHost { // reset the pipeline state, and restore this to PIPELINE_OK. PipelineError error_; - // Vector of major mime types that have been rendered by this pipeline. - typedef std::set<std::string> RenderedMimeTypesSet; - RenderedMimeTypesSet rendered_mime_types_; + // Whether the media contains rendered audio and video streams. + bool has_audio_; + bool has_video_; // The following data members are only accessed by tasks posted to // |message_loop_|. diff --git a/media/base/pipeline_impl_unittest.cc b/media/base/pipeline_impl_unittest.cc index 0762cb35..b583879 100644 --- a/media/base/pipeline_impl_unittest.cc +++ b/media/base/pipeline_impl_unittest.cc @@ -79,9 +79,6 @@ class PipelineImplTest : public ::testing::Test { &CallbackHelper::OnStop)); message_loop_.RunAllPending(); - // Free allocated media formats (if any). - STLDeleteElements(&stream_media_formats_); - mocks_.reset(); } @@ -125,19 +122,11 @@ class PipelineImplTest : public ::testing::Test { } } - // Create a stream with an associated media format. - StrictMock<MockDemuxerStream>* CreateStream(const std::string& mime_type) { + StrictMock<MockDemuxerStream>* CreateStream(DemuxerStream::Type type) { StrictMock<MockDemuxerStream>* stream = new StrictMock<MockDemuxerStream>(); - - // Sets the mime type of this stream's media format, which is usually - // checked to determine the type of decoder to create. - MediaFormat* media_format = new MediaFormat(); - media_format->SetAsString(MediaFormat::kMimeType, mime_type); - EXPECT_CALL(*stream, media_format()) - .WillRepeatedly(ReturnRef(*media_format)); - stream_media_formats_.push_back(media_format); - + EXPECT_CALL(*stream, type()) + .WillRepeatedly(Return(type)); return stream; } @@ -209,11 +198,11 @@ class PipelineImplTest : public ::testing::Test { } void CreateAudioStream() { - audio_stream_ = CreateStream("audio/x-foo"); + audio_stream_ = CreateStream(DemuxerStream::AUDIO); } void CreateVideoStream() { - video_stream_ = CreateStream("video/x-foo"); + video_stream_ = CreateStream(DemuxerStream::VIDEO); } MockDemuxerStream* audio_stream() { @@ -269,9 +258,6 @@ class PipelineImplTest : public ::testing::Test { scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream_; scoped_refptr<StrictMock<MockDemuxerStream> > video_stream_; - typedef std::vector<MediaFormat*> MediaFormatVector; - MediaFormatVector stream_media_formats_; - private: DISALLOW_COPY_AND_ASSIGN(PipelineImplTest); }; @@ -291,9 +277,8 @@ TEST_F(PipelineImplTest, NotStarted) { EXPECT_FALSE(pipeline_->IsRunning()); EXPECT_FALSE(pipeline_->IsInitialized()); - EXPECT_FALSE(pipeline_->IsRendered("")); - EXPECT_FALSE(pipeline_->IsRendered(mime_type::kMajorTypeAudio)); - EXPECT_FALSE(pipeline_->IsRendered(mime_type::kMajorTypeVideo)); + EXPECT_FALSE(pipeline_->HasAudio()); + EXPECT_FALSE(pipeline_->HasVideo()); // Setting should still work. EXPECT_EQ(0.0f, pipeline_->GetPlaybackRate()); @@ -424,8 +409,8 @@ TEST_F(PipelineImplTest, AudioStream) { InitializePipeline(); EXPECT_TRUE(pipeline_->IsInitialized()); EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); - EXPECT_TRUE(pipeline_->IsRendered(media::mime_type::kMajorTypeAudio)); - EXPECT_FALSE(pipeline_->IsRendered(media::mime_type::kMajorTypeVideo)); + EXPECT_TRUE(pipeline_->HasAudio()); + EXPECT_FALSE(pipeline_->HasVideo()); } TEST_F(PipelineImplTest, VideoStream) { @@ -441,8 +426,8 @@ TEST_F(PipelineImplTest, VideoStream) { InitializePipeline(); EXPECT_TRUE(pipeline_->IsInitialized()); EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); - EXPECT_FALSE(pipeline_->IsRendered(media::mime_type::kMajorTypeAudio)); - EXPECT_TRUE(pipeline_->IsRendered(media::mime_type::kMajorTypeVideo)); + EXPECT_FALSE(pipeline_->HasAudio()); + EXPECT_TRUE(pipeline_->HasVideo()); } TEST_F(PipelineImplTest, AudioVideoStream) { @@ -462,8 +447,8 @@ TEST_F(PipelineImplTest, AudioVideoStream) { InitializePipeline(); EXPECT_TRUE(pipeline_->IsInitialized()); EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); - EXPECT_TRUE(pipeline_->IsRendered(media::mime_type::kMajorTypeAudio)); - EXPECT_TRUE(pipeline_->IsRendered(media::mime_type::kMajorTypeVideo)); + EXPECT_TRUE(pipeline_->HasAudio()); + EXPECT_TRUE(pipeline_->HasVideo()); } TEST_F(PipelineImplTest, Seek) { @@ -618,8 +603,8 @@ TEST_F(PipelineImplTest, DisableAudioRenderer) { InitializePipeline(); EXPECT_TRUE(pipeline_->IsInitialized()); EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); - EXPECT_TRUE(pipeline_->IsRendered(mime_type::kMajorTypeAudio)); - EXPECT_TRUE(pipeline_->IsRendered(mime_type::kMajorTypeVideo)); + EXPECT_TRUE(pipeline_->HasAudio()); + EXPECT_TRUE(pipeline_->HasVideo()); EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(1.0f)) .WillOnce(DisableAudioRenderer(mocks_->audio_renderer())); @@ -676,8 +661,8 @@ TEST_F(PipelineImplTest, DisableAudioRendererDuringInit) { InitializePipeline(); EXPECT_TRUE(pipeline_->IsInitialized()); EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); - EXPECT_FALSE(pipeline_->IsRendered(mime_type::kMajorTypeAudio)); - EXPECT_TRUE(pipeline_->IsRendered(mime_type::kMajorTypeVideo)); + EXPECT_FALSE(pipeline_->HasAudio()); + EXPECT_TRUE(pipeline_->HasVideo()); // Verify that ended event is fired when video ends. EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) diff --git a/media/ffmpeg/ffmpeg_common.cc b/media/ffmpeg/ffmpeg_common.cc index 08228fd..244d2729 100644 --- a/media/ffmpeg/ffmpeg_common.cc +++ b/media/ffmpeg/ffmpeg_common.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,11 +6,6 @@ namespace media { -namespace mime_type { - -const char kFFmpegAudio[] = "audio/x-ffmpeg"; -const char kFFmpegVideo[] = "video/x-ffmpeg"; - -} // namespace mime_type +// TODO(scherkus): combine ffmpeg_common.h with ffmpeg_util.h } // namespace media diff --git a/media/ffmpeg/ffmpeg_common.h b/media/ffmpeg/ffmpeg_common.h index 4250233..714a6a1 100644 --- a/media/ffmpeg/ffmpeg_common.h +++ b/media/ffmpeg/ffmpeg_common.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -48,15 +48,6 @@ class ScopedPtrAVFreePacket { } }; - -// FFmpeg MIME types. -namespace mime_type { - -extern const char kFFmpegAudio[]; -extern const char kFFmpegVideo[]; - -} // namespace mime_type - } // namespace media #endif // MEDIA_FFMPEG_FFMPEG_COMMON_H_ diff --git a/media/filters/audio_renderer_base.cc b/media/filters/audio_renderer_base.cc index 9d7783f..4dec0a4 100644 --- a/media/filters/audio_renderer_base.cc +++ b/media/filters/audio_renderer_base.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -259,12 +259,9 @@ bool AudioRendererBase::ParseMediaFormat(const MediaFormat& media_format, 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) && + return 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; + media_format.GetAsInteger(MediaFormat::kSampleBits, sample_bits_out); } void AudioRendererBase::SetPlaybackRate(float playback_rate) { diff --git a/media/filters/audio_renderer_base_unittest.cc b/media/filters/audio_renderer_base_unittest.cc index ae8e515..c1af178 100644 --- a/media/filters/audio_renderer_base_unittest.cc +++ b/media/filters/audio_renderer_base_unittest.cc @@ -58,8 +58,6 @@ class AudioRendererBaseTest : public ::testing::Test { .WillRepeatedly(Invoke(this, &AudioRendererBaseTest::EnqueueCallback)); // Sets the essential media format keys for this decoder. - decoder_media_format_.SetAsString(MediaFormat::kMimeType, - mime_type::kUncompressedAudio); decoder_media_format_.SetAsInteger(MediaFormat::kChannels, 1); decoder_media_format_.SetAsInteger(MediaFormat::kSampleRate, 44100); decoder_media_format_.SetAsInteger(MediaFormat::kSampleBits, 16); diff --git a/media/filters/decoder_base.h b/media/filters/decoder_base.h index 2d660c9..086aa96 100644 --- a/media/filters/decoder_base.h +++ b/media/filters/decoder_base.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -221,8 +221,6 @@ class DecoderBase : public Decoder { if (!*success) { this->host()->SetError(PIPELINE_ERROR_DECODE); } else { - // TODO(scherkus): subclass shouldn't mutate superclass media format. - DCHECK(!media_format_.empty()) << "Subclass did not set media_format_"; state_ = kInitialized; } } diff --git a/media/filters/decoder_base_unittest.cc b/media/filters/decoder_base_unittest.cc index f0d4117..296bd13c7 100644 --- a/media/filters/decoder_base_unittest.cc +++ b/media/filters/decoder_base_unittest.cc @@ -62,7 +62,6 @@ class MockDecoderImpl : public DecoderBase< public: explicit MockDecoderImpl(MessageLoop* message_loop) : DecoderBase<MockDecoder, MockDecoderOutput>(message_loop) { - media_format_.SetAsString(MediaFormat::kMimeType, "mock"); } virtual ~MockDecoderImpl() {} diff --git a/media/filters/ffmpeg_audio_decoder.cc b/media/filters/ffmpeg_audio_decoder.cc index 254222d..b01977b 100644 --- a/media/filters/ffmpeg_audio_decoder.cc +++ b/media/filters/ffmpeg_audio_decoder.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -81,8 +81,6 @@ void FFmpegAudioDecoder::DoInitialize(DemuxerStream* demuxer_stream, av_get_bits_per_sample_fmt(codec_context_->sample_fmt)); media_format_.SetAsInteger(MediaFormat::kSampleRate, codec_context_->sample_rate); - media_format_.SetAsString(MediaFormat::kMimeType, - mime_type::kUncompressedAudio); // Prepare the output buffer. output_buffer_.reset(static_cast<uint8*>(av_malloc(kOutputBufferSize))); diff --git a/media/filters/ffmpeg_demuxer.cc b/media/filters/ffmpeg_demuxer.cc index d482c83..cd1a132 100644 --- a/media/filters/ffmpeg_demuxer.cc +++ b/media/filters/ffmpeg_demuxer.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -59,22 +59,17 @@ FFmpegDemuxerStream::FFmpegDemuxerStream(FFmpegDemuxer* demuxer, AVStream* stream) : demuxer_(demuxer), stream_(stream), + type_(UNKNOWN), stopped_(false) { DCHECK(demuxer_); // Determine our media format. switch (stream->codec->codec_type) { case CODEC_TYPE_AUDIO: - media_format_.SetAsString(MediaFormat::kMimeType, - mime_type::kFFmpegAudio); - media_format_.SetAsInteger(MediaFormat::kFFmpegCodecID, - stream->codec->codec_id); + type_ = AUDIO; break; case CODEC_TYPE_VIDEO: - media_format_.SetAsString(MediaFormat::kMimeType, - mime_type::kFFmpegVideo); - media_format_.SetAsInteger(MediaFormat::kFFmpegCodecID, - stream->codec->codec_id); + type_ = VIDEO; break; default: NOTREACHED(); @@ -154,6 +149,10 @@ base::TimeDelta FFmpegDemuxerStream::duration() { return duration_; } +DemuxerStream::Type FFmpegDemuxerStream::type() { + return type_; +} + const MediaFormat& FFmpegDemuxerStream::media_format() { return media_format_; } diff --git a/media/filters/ffmpeg_demuxer.h b/media/filters/ffmpeg_demuxer.h index 2123563..2ab78ae 100644 --- a/media/filters/ffmpeg_demuxer.h +++ b/media/filters/ffmpeg_demuxer.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -72,6 +72,7 @@ class FFmpegDemuxerStream : public DemuxerStream, public AVStreamProvider { virtual base::TimeDelta duration(); // DemuxerStream implementation. + virtual Type type(); virtual const MediaFormat& media_format(); virtual void Read(Callback1<Buffer*>::Type* read_callback); // Bitstream converter to convert input packet. @@ -80,8 +81,6 @@ class FFmpegDemuxerStream : public DemuxerStream, public AVStreamProvider { // AVStreamProvider implementation. virtual AVStream* GetAVStream(); - - protected: virtual void* QueryInterface(const char* interface_id); @@ -101,6 +100,7 @@ class FFmpegDemuxerStream : public DemuxerStream, public AVStreamProvider { FFmpegDemuxer* demuxer_; AVStream* stream_; + Type type_; MediaFormat media_format_; base::TimeDelta duration_; bool discontinuous_; diff --git a/media/filters/ffmpeg_demuxer_unittest.cc b/media/filters/ffmpeg_demuxer_unittest.cc index c492493..50ebb1e 100644 --- a/media/filters/ffmpeg_demuxer_unittest.cc +++ b/media/filters/ffmpeg_demuxer_unittest.cc @@ -234,10 +234,7 @@ TEST_F(FFmpegDemuxerTest, Initialize_Successful) { scoped_refptr<DemuxerStream> stream = demuxer_->GetStream(DS_STREAM_VIDEO); AVStreamProvider* av_stream_provider = NULL; ASSERT_TRUE(stream); - std::string mime_type; - EXPECT_TRUE( - stream->media_format().GetAsString(MediaFormat::kMimeType, &mime_type)); - EXPECT_STREQ(mime_type::kFFmpegVideo, mime_type.c_str()); + EXPECT_EQ(DemuxerStream::VIDEO, stream->type()); EXPECT_TRUE(stream->QueryInterface(&av_stream_provider)); EXPECT_TRUE(av_stream_provider); EXPECT_EQ(&streams_[AV_STREAM_VIDEO], av_stream_provider->GetAVStream()); @@ -246,9 +243,7 @@ TEST_F(FFmpegDemuxerTest, Initialize_Successful) { stream = demuxer_->GetStream(DS_STREAM_AUDIO); av_stream_provider = NULL; ASSERT_TRUE(stream); - EXPECT_TRUE(stream->media_format().GetAsString(MediaFormat::kMimeType, - &mime_type)); - EXPECT_STREQ(mime_type::kFFmpegAudio, mime_type.c_str()); + EXPECT_EQ(DemuxerStream::AUDIO, stream->type()); EXPECT_TRUE(stream->QueryInterface(&av_stream_provider)); EXPECT_TRUE(av_stream_provider); EXPECT_EQ(&streams_[AV_STREAM_AUDIO], av_stream_provider->GetAVStream()); diff --git a/media/filters/ffmpeg_video_decoder.cc b/media/filters/ffmpeg_video_decoder.cc index 378f410..698423b 100644 --- a/media/filters/ffmpeg_video_decoder.cc +++ b/media/filters/ffmpeg_video_decoder.cc @@ -110,8 +110,6 @@ void FFmpegVideoDecoder::OnInitializeComplete(const VideoCodecInfo& info) { AutoCallbackRunner done_runner(initialize_callback_.release()); if (info.success) { - media_format_.SetAsString(MediaFormat::kMimeType, - mime_type::kUncompressedVideo); media_format_.SetAsInteger(MediaFormat::kWidth, info.stream_info.surface_width); media_format_.SetAsInteger(MediaFormat::kHeight, diff --git a/media/filters/ffmpeg_video_decoder_unittest.cc b/media/filters/ffmpeg_video_decoder_unittest.cc index 0ddcdf9..2b3fc9b 100644 --- a/media/filters/ffmpeg_video_decoder_unittest.cc +++ b/media/filters/ffmpeg_video_decoder_unittest.cc @@ -133,9 +133,6 @@ ACTION_P(EngineSeek, engine) { class FFmpegVideoDecoderTest : public testing::Test { protected: FFmpegVideoDecoderTest() { - MediaFormat media_format; - media_format.SetAsString(MediaFormat::kMimeType, mime_type::kFFmpegVideo); - // Create an FFmpegVideoDecoder, and MockVideoDecodeEngine. // // TODO(ajwong): Break the test's dependency on FFmpegVideoDecoder. @@ -265,11 +262,8 @@ TEST_F(FFmpegVideoDecoderTest, Initialize_Successful) { // Test that the output media format is an uncompressed video surface that // matches the dimensions specified by FFmpeg. const MediaFormat& media_format = decoder_->media_format(); - std::string mime_type; int width = 0; int height = 0; - EXPECT_TRUE(media_format.GetAsString(MediaFormat::kMimeType, &mime_type)); - EXPECT_STREQ(mime_type::kUncompressedVideo, mime_type.c_str()); EXPECT_TRUE(media_format.GetAsInteger(MediaFormat::kWidth, &width)); EXPECT_EQ(kWidth, width); EXPECT_TRUE(media_format.GetAsInteger(MediaFormat::kHeight, &height)); diff --git a/media/filters/file_data_source.cc b/media/filters/file_data_source.cc index 64c61fb..9fd93a5 100644 --- a/media/filters/file_data_source.cc +++ b/media/filters/file_data_source.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -41,8 +41,6 @@ void FileDataSource::Initialize(const std::string& url, callback->Run(); return; } - media_format_.SetAsString(MediaFormat::kMimeType, - mime_type::kApplicationOctetStream); media_format_.SetAsString(MediaFormat::kURL, url); host()->SetTotalBytes(file_size_); host()->SetBufferedBytes(file_size_); diff --git a/media/filters/omx_video_decoder.cc b/media/filters/omx_video_decoder.cc index 73816f9..c8962a3 100644 --- a/media/filters/omx_video_decoder.cc +++ b/media/filters/omx_video_decoder.cc @@ -102,8 +102,6 @@ void OmxVideoDecoder::OnInitializeComplete(const VideoCodecInfo& info) { AutoCallbackRunner done_runner(initialize_callback_.release()); if (info.success) { - media_format_.SetAsString(MediaFormat::kMimeType, - mime_type::kUncompressedVideo); media_format_.SetAsInteger(MediaFormat::kWidth, info.stream_info.surface_width); media_format_.SetAsInteger(MediaFormat::kHeight, diff --git a/media/filters/video_renderer_base.cc b/media/filters/video_renderer_base.cc index 9ed236b..493de69 100644 --- a/media/filters/video_renderer_base.cc +++ b/media/filters/video_renderer_base.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -49,12 +49,6 @@ bool VideoRendererBase::ParseMediaFormat( VideoFrame::SurfaceType* surface_type_out, VideoFrame::Format* surface_format_out, int* width_out, int* height_out) { - std::string mime_type; - if (!media_format.GetAsString(MediaFormat::kMimeType, &mime_type)) - return false; - if (mime_type.compare(mime_type::kUncompressedVideo) != 0) - return false; - int surface_type; if (!media_format.GetAsInteger(MediaFormat::kSurfaceType, &surface_type)) return false; diff --git a/media/filters/video_renderer_base_unittest.cc b/media/filters/video_renderer_base_unittest.cc index aa5cad1..60861f9 100644 --- a/media/filters/video_renderer_base_unittest.cc +++ b/media/filters/video_renderer_base_unittest.cc @@ -58,8 +58,6 @@ class VideoRendererBaseTest : public ::testing::Test { .WillRepeatedly(Invoke(this, &VideoRendererBaseTest::EnqueueCallback)); // Sets the essential media format keys for this decoder. - decoder_media_format_.SetAsString(MediaFormat::kMimeType, - mime_type::kUncompressedVideo); decoder_media_format_.SetAsInteger(MediaFormat::kSurfaceType, VideoFrame::TYPE_SYSTEM_MEMORY); decoder_media_format_.SetAsInteger(MediaFormat::kSurfaceFormat, diff --git a/media/tools/player_x11/player_x11.cc b/media/tools/player_x11/player_x11.cc index 2e75994..39504ff 100644 --- a/media/tools/player_x11/player_x11.cc +++ b/media/tools/player_x11/player_x11.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -266,7 +266,7 @@ int main(int argc, char** argv) { g_running = true; // Check if video is present. - audio_only = !pipeline->IsRendered(media::mime_type::kMajorTypeVideo); + audio_only = !pipeline->HasVideo(); message_loop.PostTask(FROM_HERE, NewRunnableFunction(PeriodicalUpdate, pipeline, |