summaryrefslogtreecommitdiffstats
path: root/media/base
diff options
context:
space:
mode:
authorfischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-21 19:44:14 +0000
committerfischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-21 19:44:14 +0000
commit8580499d4c2d8556ed1082b67884c2a3c61608dd (patch)
tree54c0eb963fa84748c69c575e54865b42da2b921b /media/base
parentc3f5f213d866eab2bfbb9cbf04fcd2ca7b856e31 (diff)
downloadchromium_src-8580499d4c2d8556ed1082b67884c2a3c61608dd.zip
chromium_src-8580499d4c2d8556ed1082b67884c2a3c61608dd.tar.gz
chromium_src-8580499d4c2d8556ed1082b67884c2a3c61608dd.tar.bz2
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
Diffstat (limited to 'media/base')
-rw-r--r--media/base/filters.h18
-rw-r--r--media/base/mock_filters.h3
-rw-r--r--media/base/pipeline_impl.cc19
-rw-r--r--media/base/pipeline_impl.h6
-rw-r--r--media/base/pipeline_impl_unittest.cc12
5 files changed, 17 insertions, 41 deletions
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<DemuxerStream> GetStream(int stream_id) = 0;
-};
-
-
class DemuxerStream : public base::RefCountedThreadSafe<DemuxerStream> {
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<DemuxerStream> {
virtual ~DemuxerStream();
};
+class Demuxer : public Filter {
+ public:
+ // Returns the given stream type, or NULL if that type is not present.
+ virtual scoped_refptr<DemuxerStream> 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<DemuxerStream>(int stream_id));
+ MOCK_METHOD1(GetStream, scoped_refptr<DemuxerStream>(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<DemuxerStream> stream =
- FindDemuxerStream(demuxer, DemuxerStream::AUDIO);
+ demuxer->GetStream(DemuxerStream::AUDIO);
if (!stream)
return false;
@@ -1088,7 +1088,7 @@ bool PipelineImpl::InitializeVideoDecoder(
DCHECK(IsPipelineOk());
scoped_refptr<DemuxerStream> stream =
- FindDemuxerStream(demuxer, DemuxerStream::VIDEO);
+ demuxer->GetStream(DemuxerStream::VIDEO);
if (!stream)
return false;
@@ -1158,21 +1158,6 @@ bool PipelineImpl::InitializeVideoRenderer(
return true;
}
-scoped_refptr<DemuxerStream> PipelineImpl::FindDemuxerStream(
- const scoped_refptr<Demuxer>& 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<AudioDecoder>& decoder);
bool InitializeVideoRenderer(const scoped_refptr<VideoDecoder>& decoder);
- // Returns a reference to the DemuxerStream of the requested type if it
- // exists, NULL otherwise.
- scoped_refptr<DemuxerStream> FindDemuxerStream(
- const scoped_refptr<Demuxer>& 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<PipelineStatusCallback*>(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<DemuxerStream> 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.