Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: media/base/pipeline_unittest.cc

Issue 15993018: Reland: Use a shared thread for media operations (round 3). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/base/pipeline.cc ('k') | webkit/mocks/test_media_stream_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <vector> 5 #include <vector>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/test/simple_test_clock.h" 10 #include "base/test/simple_test_clock.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 // streams. 98 // streams.
99 DemuxerStream* null_pointer = NULL; 99 DemuxerStream* null_pointer = NULL;
100 EXPECT_CALL(*demuxer_, GetStream(_)) 100 EXPECT_CALL(*demuxer_, GetStream(_))
101 .WillRepeatedly(Return(null_pointer)); 101 .WillRepeatedly(Return(null_pointer));
102 102
103 EXPECT_CALL(*demuxer_, GetStartTime()) 103 EXPECT_CALL(*demuxer_, GetStartTime())
104 .WillRepeatedly(Return(base::TimeDelta())); 104 .WillRepeatedly(Return(base::TimeDelta()));
105 } 105 }
106 106
107 virtual ~PipelineTest() { 107 virtual ~PipelineTest() {
108 // Shutdown sequence. 108 if (!pipeline_ || !pipeline_->IsRunning())
109 if (pipeline_->IsRunning()) { 109 return;
110 EXPECT_CALL(*demuxer_, Stop(_))
111 .WillOnce(RunClosure<0>());
112 110
113 if (audio_stream_) 111 ExpectStop();
114 EXPECT_CALL(*audio_renderer_, Stop(_))
115 .WillOnce(RunClosure<0>());
116
117 if (video_stream_)
118 EXPECT_CALL(*video_renderer_, Stop(_))
119 .WillOnce(RunClosure<0>());
120 }
121 112
122 // Expect a stop callback if we were started. 113 // Expect a stop callback if we were started.
123 EXPECT_CALL(callbacks_, OnStop()); 114 EXPECT_CALL(callbacks_, OnStop());
124 pipeline_->Stop(base::Bind(&CallbackHelper::OnStop, 115 pipeline_->Stop(base::Bind(&CallbackHelper::OnStop,
125 base::Unretained(&callbacks_))); 116 base::Unretained(&callbacks_)));
126 message_loop_.RunUntilIdle(); 117 message_loop_.RunUntilIdle();
127
128 filter_collection_.reset();
129 pipeline_.reset();
130 } 118 }
131 119
132 protected: 120 protected:
133 // Sets up expectations to allow the demuxer to initialize. 121 // Sets up expectations to allow the demuxer to initialize.
134 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; 122 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector;
135 void InitializeDemuxer(MockDemuxerStreamVector* streams, 123 void InitializeDemuxer(MockDemuxerStreamVector* streams,
136 const base::TimeDelta& duration) { 124 const base::TimeDelta& duration) {
137 EXPECT_CALL(callbacks_, OnDurationChange()); 125 EXPECT_CALL(callbacks_, OnDurationChange());
138 EXPECT_CALL(*demuxer_, Initialize(_, _)) 126 EXPECT_CALL(*demuxer_, Initialize(_, _))
139 .WillOnce(DoAll(SetDemuxerProperties(duration), 127 .WillOnce(DoAll(SetDemuxerProperties(duration),
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 pipeline_->Seek(seek_time, 266 pipeline_->Seek(seek_time,
279 base::Bind(&CallbackHelper::OnSeek, 267 base::Bind(&CallbackHelper::OnSeek,
280 base::Unretained(&callbacks_))); 268 base::Unretained(&callbacks_)));
281 269
282 // We expect the time to be updated only after the seek has completed. 270 // We expect the time to be updated only after the seek has completed.
283 EXPECT_NE(seek_time, pipeline_->GetMediaTime()); 271 EXPECT_NE(seek_time, pipeline_->GetMediaTime());
284 message_loop_.RunUntilIdle(); 272 message_loop_.RunUntilIdle();
285 EXPECT_EQ(seek_time, pipeline_->GetMediaTime()); 273 EXPECT_EQ(seek_time, pipeline_->GetMediaTime());
286 } 274 }
287 275
276 void ExpectStop() {
277 if (demuxer_)
278 EXPECT_CALL(*demuxer_, Stop(_)).WillOnce(RunClosure<0>());
279
280 if (audio_stream_)
281 EXPECT_CALL(*audio_renderer_, Stop(_)).WillOnce(RunClosure<0>());
282
283 if (video_stream_)
284 EXPECT_CALL(*video_renderer_, Stop(_)).WillOnce(RunClosure<0>());
285 }
286
288 // Fixture members. 287 // Fixture members.
289 StrictMock<CallbackHelper> callbacks_; 288 StrictMock<CallbackHelper> callbacks_;
290 base::SimpleTestClock test_clock_; 289 base::SimpleTestClock test_clock_;
291 base::MessageLoop message_loop_; 290 base::MessageLoop message_loop_;
292 scoped_ptr<Pipeline> pipeline_; 291 scoped_ptr<Pipeline> pipeline_;
293 292
294 scoped_ptr<FilterCollection> filter_collection_; 293 scoped_ptr<FilterCollection> filter_collection_;
295 scoped_ptr<MockDemuxer> demuxer_; 294 scoped_ptr<MockDemuxer> demuxer_;
296 MockVideoRenderer* video_renderer_; 295 MockVideoRenderer* video_renderer_;
297 MockAudioRenderer* audio_renderer_; 296 MockAudioRenderer* audio_renderer_;
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 EXPECT_EQ(pipeline_->GetMediaTime(), seek_time); 828 EXPECT_EQ(pipeline_->GetMediaTime(), seek_time);
830 829
831 // Now that the seek is complete, verify that time updates advance the current 830 // Now that the seek is complete, verify that time updates advance the current
832 // time. 831 // time.
833 base::TimeDelta new_time = seek_time + base::TimeDelta::FromMilliseconds(100); 832 base::TimeDelta new_time = seek_time + base::TimeDelta::FromMilliseconds(100);
834 audio_time_cb_.Run(new_time, new_time); 833 audio_time_cb_.Run(new_time, new_time);
835 834
836 EXPECT_EQ(pipeline_->GetMediaTime(), new_time); 835 EXPECT_EQ(pipeline_->GetMediaTime(), new_time);
837 } 836 }
838 837
838 static void DeletePipeline(scoped_ptr<Pipeline> pipeline) {
839 // |pipeline| will go out of scope.
840 }
841
842 TEST_F(PipelineTest, DeleteAfterStop) {
843 CreateAudioStream();
844 MockDemuxerStreamVector streams;
845 streams.push_back(audio_stream());
846 InitializeDemuxer(&streams);
847 InitializeAudioRenderer(audio_stream(), false);
848 InitializePipeline(PIPELINE_OK);
849
850 ExpectStop();
851
852 Pipeline* pipeline = pipeline_.get();
853 pipeline->Stop(base::Bind(&DeletePipeline, base::Passed(&pipeline_)));
854 message_loop_.RunUntilIdle();
855 }
856
839 class PipelineTeardownTest : public PipelineTest { 857 class PipelineTeardownTest : public PipelineTest {
840 public: 858 public:
841 enum TeardownState { 859 enum TeardownState {
842 kInitDemuxer, 860 kInitDemuxer,
843 kInitAudioRenderer, 861 kInitAudioRenderer,
844 kInitVideoRenderer, 862 kInitVideoRenderer,
845 kPausing, 863 kPausing,
846 kFlushing, 864 kFlushing,
847 kSeeking, 865 kSeeking,
848 kPrerolling, 866 kPrerolling,
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 INSTANTIATE_TEARDOWN_TEST(Error, InitAudioRenderer); 1170 INSTANTIATE_TEARDOWN_TEST(Error, InitAudioRenderer);
1153 INSTANTIATE_TEARDOWN_TEST(Error, InitVideoRenderer); 1171 INSTANTIATE_TEARDOWN_TEST(Error, InitVideoRenderer);
1154 INSTANTIATE_TEARDOWN_TEST(Error, Pausing); 1172 INSTANTIATE_TEARDOWN_TEST(Error, Pausing);
1155 INSTANTIATE_TEARDOWN_TEST(Error, Flushing); 1173 INSTANTIATE_TEARDOWN_TEST(Error, Flushing);
1156 INSTANTIATE_TEARDOWN_TEST(Error, Seeking); 1174 INSTANTIATE_TEARDOWN_TEST(Error, Seeking);
1157 INSTANTIATE_TEARDOWN_TEST(Error, Prerolling); 1175 INSTANTIATE_TEARDOWN_TEST(Error, Prerolling);
1158 INSTANTIATE_TEARDOWN_TEST(Error, Starting); 1176 INSTANTIATE_TEARDOWN_TEST(Error, Starting);
1159 INSTANTIATE_TEARDOWN_TEST(Error, Playing); 1177 INSTANTIATE_TEARDOWN_TEST(Error, Playing);
1160 1178
1161 } // namespace media 1179 } // namespace media
OLDNEW
« no previous file with comments | « media/base/pipeline.cc ('k') | webkit/mocks/test_media_stream_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698