From 8580499d4c2d8556ed1082b67884c2a3c61608dd Mon Sep 17 00:00:00 2001 From: "fischman@chromium.org" Date: Mon, 21 Mar 2011 19:44:14 +0000 Subject: Simplify the Demuxer interface to get streams by type. Before this change Demuxer's interface looked as if it could return multiple streams for a given type, but the implementations all assume/need at most a single stream per type. This change should make the (soon to be written) AdaptiveDemuxer{,Stream} less confusing. BUG=none TEST=trybots Review URL: http://codereview.chromium.org/6685122 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78908 0039d316-1c4b-4281-b951-d872f2087c98 --- media/base/filters.h | 18 +++++++----------- media/base/mock_filters.h | 3 +-- media/base/pipeline_impl.cc | 19 ++----------------- media/base/pipeline_impl.h | 6 ------ media/base/pipeline_impl_unittest.cc | 12 +++++++----- 5 files changed, 17 insertions(+), 41 deletions(-) (limited to 'media/base') diff --git a/media/base/filters.h b/media/base/filters.h index 654da5a..d6b962d 100644 --- a/media/base/filters.h +++ b/media/base/filters.h @@ -129,23 +129,13 @@ class DataSource : public Filter { virtual bool IsStreaming() = 0; }; - -class Demuxer : public Filter { - public: - // Returns the number of streams available - virtual size_t GetNumberOfStreams() = 0; - - // Returns the stream for the given index, NULL otherwise - virtual scoped_refptr GetStream(int stream_id) = 0; -}; - - class DemuxerStream : public base::RefCountedThreadSafe { public: enum Type { UNKNOWN, AUDIO, VIDEO, + NUM_TYPES, // Always keep this entry as the last one! }; // Schedules a read. When the |read_callback| is called, the downstream @@ -186,6 +176,12 @@ class DemuxerStream : public base::RefCountedThreadSafe { virtual ~DemuxerStream(); }; +class Demuxer : public Filter { + public: + // Returns the given stream type, or NULL if that type is not present. + virtual scoped_refptr GetStream(DemuxerStream::Type type) = 0; +}; + class VideoDecoder : public Filter { public: diff --git a/media/base/mock_filters.h b/media/base/mock_filters.h index 8004190..c108c57 100644 --- a/media/base/mock_filters.h +++ b/media/base/mock_filters.h @@ -110,8 +110,7 @@ class MockDemuxer : public Demuxer { // Demuxer implementation. MOCK_METHOD2(Initialize, void(DataSource* data_source, FilterCallback* callback)); - MOCK_METHOD0(GetNumberOfStreams, size_t()); - MOCK_METHOD1(GetStream, scoped_refptr(int stream_id)); + MOCK_METHOD1(GetStream, scoped_refptr(DemuxerStream::Type)); // Sets the TotalBytes, BufferedBytes, & Duration values to be sent to host() // when set_host() is called. diff --git a/media/base/pipeline_impl.cc b/media/base/pipeline_impl.cc index 7c71e66..2b66661 100644 --- a/media/base/pipeline_impl.cc +++ b/media/base/pipeline_impl.cc @@ -1058,7 +1058,7 @@ bool PipelineImpl::InitializeAudioDecoder( DCHECK(IsPipelineOk()); scoped_refptr stream = - FindDemuxerStream(demuxer, DemuxerStream::AUDIO); + demuxer->GetStream(DemuxerStream::AUDIO); if (!stream) return false; @@ -1088,7 +1088,7 @@ bool PipelineImpl::InitializeVideoDecoder( DCHECK(IsPipelineOk()); scoped_refptr stream = - FindDemuxerStream(demuxer, DemuxerStream::VIDEO); + demuxer->GetStream(DemuxerStream::VIDEO); if (!stream) return false; @@ -1158,21 +1158,6 @@ bool PipelineImpl::InitializeVideoRenderer( return true; } -scoped_refptr PipelineImpl::FindDemuxerStream( - const scoped_refptr& demuxer, - 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)->type() == type) { - return demuxer->GetStream(i); - } - } - return NULL; -} - void PipelineImpl::TearDownPipeline() { DCHECK_EQ(MessageLoop::current(), message_loop_); DCHECK_NE(kStopped, state_); diff --git a/media/base/pipeline_impl.h b/media/base/pipeline_impl.h index e50322b..32de091 100644 --- a/media/base/pipeline_impl.h +++ b/media/base/pipeline_impl.h @@ -289,12 +289,6 @@ class PipelineImpl : public Pipeline, public FilterHost { bool InitializeAudioRenderer(const scoped_refptr& decoder); bool InitializeVideoRenderer(const scoped_refptr& decoder); - // Returns a reference to the DemuxerStream of the requested type if it - // exists, NULL otherwise. - scoped_refptr FindDemuxerStream( - const scoped_refptr& demuxer, - 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: // 1. when pipeline has not been initialized, we will transit to stopping diff --git a/media/base/pipeline_impl_unittest.cc b/media/base/pipeline_impl_unittest.cc index c5593f3..396b69c 100644 --- a/media/base/pipeline_impl_unittest.cc +++ b/media/base/pipeline_impl_unittest.cc @@ -67,6 +67,12 @@ class PipelineImplTest : public ::testing::Test { &CallbackHelper::OnError), static_cast(NULL)); mocks_.reset(new MockFilterCollection()); + + // InitializeDemuxer adds overriding expectations for expected non-NULL + // streams. + DemuxerStream* null_pointer = NULL; + EXPECT_CALL(*mocks_->demuxer(), GetStream(_)) + .WillRepeatedly(Return(null_pointer)); } virtual ~PipelineImplTest() { @@ -90,8 +96,6 @@ class PipelineImplTest : public ::testing::Test { const base::TimeDelta& duration) { mocks_->demuxer()->SetTotalAndBufferedBytesAndDuration( kTotalBytes, kBufferedBytes, duration); - EXPECT_CALL(*mocks_->demuxer(), GetNumberOfStreams()) - .WillRepeatedly(Return(streams->size())); EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); EXPECT_CALL(*mocks_->demuxer(), Seek(base::TimeDelta(), NotNull())) .WillOnce(Invoke(&RunFilterCallback)); @@ -101,7 +105,7 @@ class PipelineImplTest : public ::testing::Test { // Configure the demuxer to return the streams. for (size_t i = 0; i < streams->size(); ++i) { scoped_refptr stream((*streams)[i]); - EXPECT_CALL(*mocks_->demuxer(), GetStream(i)) + EXPECT_CALL(*mocks_->demuxer(), GetStream(stream->type())) .WillRepeatedly(Return(stream)); } } @@ -353,8 +357,6 @@ TEST_F(PipelineImplTest, URLNotFound) { TEST_F(PipelineImplTest, NoStreams) { // Manually set these expectations because SetPlaybackRate() is not called if // we cannot fully initialize the pipeline. - EXPECT_CALL(*mocks_->demuxer(), GetNumberOfStreams()) - .WillRepeatedly(Return(0)); EXPECT_CALL(*mocks_->demuxer(), Stop(NotNull())) .WillOnce(Invoke(&RunStopFilterCallback)); // TODO(acolwell,fischman): see TODO in URLNotFound above. -- cgit v1.1