| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/stl_util-inl.h" |
| 7 #include "base/waitable_event.h" | 8 #include "base/waitable_event.h" |
| 8 #include "media/base/pipeline_impl.h" | 9 #include "media/base/pipeline_impl.h" |
| 9 #include "media/base/media_format.h" | 10 #include "media/base/media_format.h" |
| 10 #include "media/base/filters.h" | 11 #include "media/base/filters.h" |
| 11 #include "media/base/factory.h" | 12 #include "media/base/factory.h" |
| 12 #include "media/base/filter_host.h" | 13 #include "media/base/filter_host.h" |
| 13 #include "media/base/mock_filters.h" | 14 #include "media/base/mock_filters.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 16 |
| 16 using ::testing::DoAll; | 17 using ::testing::DoAll; |
| 17 using ::testing::InSequence; | 18 using ::testing::InSequence; |
| 18 using ::testing::Invoke; | 19 using ::testing::Invoke; |
| 19 using ::testing::Mock; | 20 using ::testing::Mock; |
| 20 using ::testing::NotNull; | 21 using ::testing::NotNull; |
| 21 using ::testing::Return; | 22 using ::testing::Return; |
| 23 using ::testing::ReturnRef; |
| 22 using ::testing::StrictMock; | 24 using ::testing::StrictMock; |
| 23 | 25 |
| 24 namespace { | 26 namespace { |
| 25 | 27 |
| 26 // Total bytes of the data source. | 28 // Total bytes of the data source. |
| 27 const int kTotalBytes = 1024; | 29 const int kTotalBytes = 1024; |
| 28 | 30 |
| 29 // Buffered bytes of the data source. | 31 // Buffered bytes of the data source. |
| 30 const int kBufferedBytes = 1024; | 32 const int kBufferedBytes = 1024; |
| 31 | 33 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 virtual ~PipelineImplTest() { | 71 virtual ~PipelineImplTest() { |
| 70 if (!pipeline_->IsRunning()) { | 72 if (!pipeline_->IsRunning()) { |
| 71 return; | 73 return; |
| 72 } | 74 } |
| 73 | 75 |
| 74 // Expect a stop callback if we were started. | 76 // Expect a stop callback if we were started. |
| 75 EXPECT_CALL(callbacks_, OnStop()); | 77 EXPECT_CALL(callbacks_, OnStop()); |
| 76 pipeline_->Stop(NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), | 78 pipeline_->Stop(NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), |
| 77 &CallbackHelper::OnStop)); | 79 &CallbackHelper::OnStop)); |
| 78 message_loop_.RunAllPending(); | 80 message_loop_.RunAllPending(); |
| 81 |
| 82 // Free allocated media formats (if any). |
| 83 STLDeleteElements(&stream_media_formats_); |
| 79 } | 84 } |
| 80 | 85 |
| 81 protected: | 86 protected: |
| 82 // Sets up expectations to allow the data source to initialize. | 87 // Sets up expectations to allow the data source to initialize. |
| 83 void InitializeDataSource() { | 88 void InitializeDataSource() { |
| 84 EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull())) | 89 EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull())) |
| 85 .WillOnce(DoAll(SetTotalBytes(mocks_->data_source(), kTotalBytes), | 90 .WillOnce(DoAll(SetTotalBytes(mocks_->data_source(), kTotalBytes), |
| 86 SetBufferedBytes(mocks_->data_source(), kBufferedBytes), | 91 SetBufferedBytes(mocks_->data_source(), kBufferedBytes), |
| 87 Invoke(&RunFilterCallback))); | 92 Invoke(&RunFilterCallback))); |
| 88 EXPECT_CALL(*mocks_->data_source(), SetPlaybackRate(0.0f)); | 93 EXPECT_CALL(*mocks_->data_source(), SetPlaybackRate(0.0f)); |
| 89 EXPECT_CALL(*mocks_->data_source(), Seek(base::TimeDelta(), NotNull())) | 94 EXPECT_CALL(*mocks_->data_source(), Seek(base::TimeDelta(), NotNull())) |
| 90 .WillOnce(Invoke(&RunFilterCallback)); | 95 .WillOnce(Invoke(&RunFilterCallback)); |
| 91 EXPECT_CALL(*mocks_->data_source(), Stop()); | 96 EXPECT_CALL(*mocks_->data_source(), Stop()); |
| 97 EXPECT_CALL(*mocks_->data_source(), media_format()) |
| 98 .WillOnce(ReturnRef(data_source_media_format_)); |
| 92 } | 99 } |
| 93 | 100 |
| 94 // Sets up expectations to allow the demuxer to initialize. | 101 // Sets up expectations to allow the demuxer to initialize. |
| 95 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; | 102 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; |
| 96 void InitializeDemuxer(MockDemuxerStreamVector* streams, | 103 void InitializeDemuxer(MockDemuxerStreamVector* streams, |
| 97 const base::TimeDelta& duration) { | 104 const base::TimeDelta& duration) { |
| 98 EXPECT_CALL(*mocks_->demuxer(), | 105 EXPECT_CALL(*mocks_->demuxer(), |
| 99 Initialize(mocks_->data_source(), NotNull())) | 106 Initialize(mocks_->data_source(), NotNull())) |
| 100 .WillOnce(DoAll(SetDuration(mocks_->data_source(), duration), | 107 .WillOnce(DoAll(SetDuration(mocks_->data_source(), duration), |
| 101 Invoke(&RunFilterCallback))); | 108 Invoke(&RunFilterCallback))); |
| 102 EXPECT_CALL(*mocks_->demuxer(), GetNumberOfStreams()) | 109 EXPECT_CALL(*mocks_->demuxer(), GetNumberOfStreams()) |
| 103 .WillRepeatedly(Return(streams->size())); | 110 .WillRepeatedly(Return(streams->size())); |
| 104 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); | 111 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); |
| 105 EXPECT_CALL(*mocks_->demuxer(), Seek(base::TimeDelta(), NotNull())) | 112 EXPECT_CALL(*mocks_->demuxer(), Seek(base::TimeDelta(), NotNull())) |
| 106 .WillOnce(Invoke(&RunFilterCallback)); | 113 .WillOnce(Invoke(&RunFilterCallback)); |
| 107 EXPECT_CALL(*mocks_->demuxer(), Stop()); | 114 EXPECT_CALL(*mocks_->demuxer(), Stop()); |
| 108 | 115 |
| 109 // Configure the demuxer to return the streams. | 116 // Configure the demuxer to return the streams. |
| 110 for (size_t i = 0; i < streams->size(); ++i) { | 117 for (size_t i = 0; i < streams->size(); ++i) { |
| 111 scoped_refptr<DemuxerStream> stream = (*streams)[i]; | 118 scoped_refptr<DemuxerStream> stream = (*streams)[i]; |
| 112 EXPECT_CALL(*mocks_->demuxer(), GetStream(i)) | 119 EXPECT_CALL(*mocks_->demuxer(), GetStream(i)) |
| 113 .WillRepeatedly(Return(stream)); | 120 .WillRepeatedly(Return(stream)); |
| 114 } | 121 } |
| 115 } | 122 } |
| 116 | 123 |
| 124 // Create a stream with an associated media format. |
| 125 StrictMock<MockDemuxerStream>* CreateStream(const std::string& mime_type) { |
| 126 StrictMock<MockDemuxerStream>* stream = |
| 127 new StrictMock<MockDemuxerStream>(); |
| 128 |
| 129 // Sets the mime type of this stream's media format, which is usually |
| 130 // checked to determine the type of decoder to create. |
| 131 MediaFormat* media_format = new MediaFormat(); |
| 132 media_format->SetAsString(MediaFormat::kMimeType, mime_type); |
| 133 EXPECT_CALL(*stream, media_format()) |
| 134 .WillRepeatedly(ReturnRef(*media_format)); |
| 135 stream_media_formats_.push_back(media_format); |
| 136 |
| 137 return stream; |
| 138 } |
| 139 |
| 117 // Sets up expectations to allow the video decoder to initialize. | 140 // Sets up expectations to allow the video decoder to initialize. |
| 118 void InitializeVideoDecoder(MockDemuxerStream* stream) { | 141 void InitializeVideoDecoder(MockDemuxerStream* stream) { |
| 119 EXPECT_CALL(*mocks_->video_decoder(), Initialize(stream, NotNull())) | 142 EXPECT_CALL(*mocks_->video_decoder(), Initialize(stream, NotNull())) |
| 120 .WillOnce(Invoke(&RunFilterCallback)); | 143 .WillOnce(Invoke(&RunFilterCallback)); |
| 121 EXPECT_CALL(*mocks_->video_decoder(), SetPlaybackRate(0.0f)); | 144 EXPECT_CALL(*mocks_->video_decoder(), SetPlaybackRate(0.0f)); |
| 122 EXPECT_CALL(*mocks_->video_decoder(), Seek(base::TimeDelta(), NotNull())) | 145 EXPECT_CALL(*mocks_->video_decoder(), Seek(base::TimeDelta(), NotNull())) |
| 123 .WillOnce(Invoke(&RunFilterCallback)); | 146 .WillOnce(Invoke(&RunFilterCallback)); |
| 124 EXPECT_CALL(*mocks_->video_decoder(), Stop()); | 147 EXPECT_CALL(*mocks_->video_decoder(), Stop()); |
| 148 EXPECT_CALL(*mocks_->video_decoder(), media_format()) |
| 149 .WillOnce(ReturnRef(video_decoder_media_format_)); |
| 125 } | 150 } |
| 126 | 151 |
| 127 // Sets up expectations to allow the audio decoder to initialize. | 152 // Sets up expectations to allow the audio decoder to initialize. |
| 128 void InitializeAudioDecoder(MockDemuxerStream* stream) { | 153 void InitializeAudioDecoder(MockDemuxerStream* stream) { |
| 129 EXPECT_CALL(*mocks_->audio_decoder(), Initialize(stream, NotNull())) | 154 EXPECT_CALL(*mocks_->audio_decoder(), Initialize(stream, NotNull())) |
| 130 .WillOnce(Invoke(&RunFilterCallback)); | 155 .WillOnce(Invoke(&RunFilterCallback)); |
| 131 EXPECT_CALL(*mocks_->audio_decoder(), SetPlaybackRate(0.0f)); | 156 EXPECT_CALL(*mocks_->audio_decoder(), SetPlaybackRate(0.0f)); |
| 132 EXPECT_CALL(*mocks_->audio_decoder(), Seek(base::TimeDelta(), NotNull())) | 157 EXPECT_CALL(*mocks_->audio_decoder(), Seek(base::TimeDelta(), NotNull())) |
| 133 .WillOnce(Invoke(&RunFilterCallback)); | 158 .WillOnce(Invoke(&RunFilterCallback)); |
| 134 EXPECT_CALL(*mocks_->audio_decoder(), Stop()); | 159 EXPECT_CALL(*mocks_->audio_decoder(), Stop()); |
| 160 EXPECT_CALL(*mocks_->audio_decoder(), media_format()) |
| 161 .WillOnce(ReturnRef(audio_decoder_media_format_)); |
| 135 } | 162 } |
| 136 | 163 |
| 137 // Sets up expectations to allow the video renderer to initialize. | 164 // Sets up expectations to allow the video renderer to initialize. |
| 138 void InitializeVideoRenderer() { | 165 void InitializeVideoRenderer() { |
| 139 EXPECT_CALL(*mocks_->video_renderer(), | 166 EXPECT_CALL(*mocks_->video_renderer(), |
| 140 Initialize(mocks_->video_decoder(), NotNull())) | 167 Initialize(mocks_->video_decoder(), NotNull())) |
| 141 .WillOnce(Invoke(&RunFilterCallback)); | 168 .WillOnce(Invoke(&RunFilterCallback)); |
| 142 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(0.0f)); | 169 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(0.0f)); |
| 143 EXPECT_CALL(*mocks_->video_renderer(), Seek(base::TimeDelta(), NotNull())) | 170 EXPECT_CALL(*mocks_->video_renderer(), Seek(base::TimeDelta(), NotNull())) |
| 144 .WillOnce(Invoke(&RunFilterCallback)); | 171 .WillOnce(Invoke(&RunFilterCallback)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 167 &CallbackHelper::OnStart)); | 194 &CallbackHelper::OnStart)); |
| 168 message_loop_.RunAllPending(); | 195 message_loop_.RunAllPending(); |
| 169 } | 196 } |
| 170 | 197 |
| 171 // Fixture members. | 198 // Fixture members. |
| 172 StrictMock<CallbackHelper> callbacks_; | 199 StrictMock<CallbackHelper> callbacks_; |
| 173 MessageLoop message_loop_; | 200 MessageLoop message_loop_; |
| 174 scoped_refptr<PipelineImpl> pipeline_; | 201 scoped_refptr<PipelineImpl> pipeline_; |
| 175 scoped_refptr<media::MockFilterFactory> mocks_; | 202 scoped_refptr<media::MockFilterFactory> mocks_; |
| 176 | 203 |
| 204 MediaFormat data_source_media_format_; |
| 205 MediaFormat audio_decoder_media_format_; |
| 206 MediaFormat video_decoder_media_format_; |
| 207 |
| 208 typedef std::vector<MediaFormat*> MediaFormatVector; |
| 209 MediaFormatVector stream_media_formats_; |
| 210 |
| 177 private: | 211 private: |
| 178 DISALLOW_COPY_AND_ASSIGN(PipelineImplTest); | 212 DISALLOW_COPY_AND_ASSIGN(PipelineImplTest); |
| 179 }; | 213 }; |
| 180 | 214 |
| 181 // Test that playback controls methods no-op when the pipeline hasn't been | 215 // Test that playback controls methods no-op when the pipeline hasn't been |
| 182 // started. | 216 // started. |
| 183 TEST_F(PipelineImplTest, NotStarted) { | 217 TEST_F(PipelineImplTest, NotStarted) { |
| 184 const base::TimeDelta kZero; | 218 const base::TimeDelta kZero; |
| 185 | 219 |
| 186 // StrictMock<> will ensure these never get called, and valgrind/purify will | 220 // StrictMock<> will ensure these never get called, and valgrind/purify will |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 EXPECT_FALSE(pipeline_->IsInitialized()); | 307 EXPECT_FALSE(pipeline_->IsInitialized()); |
| 274 EXPECT_EQ(PIPELINE_ERROR_URL_NOT_FOUND, pipeline_->GetError()); | 308 EXPECT_EQ(PIPELINE_ERROR_URL_NOT_FOUND, pipeline_->GetError()); |
| 275 } | 309 } |
| 276 | 310 |
| 277 TEST_F(PipelineImplTest, NoStreams) { | 311 TEST_F(PipelineImplTest, NoStreams) { |
| 278 // Manually set these expectations because SetPlaybackRate() is not called if | 312 // Manually set these expectations because SetPlaybackRate() is not called if |
| 279 // we cannot fully initialize the pipeline. | 313 // we cannot fully initialize the pipeline. |
| 280 EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull())) | 314 EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull())) |
| 281 .WillOnce(Invoke(&RunFilterCallback)); | 315 .WillOnce(Invoke(&RunFilterCallback)); |
| 282 EXPECT_CALL(*mocks_->data_source(), Stop()); | 316 EXPECT_CALL(*mocks_->data_source(), Stop()); |
| 317 EXPECT_CALL(*mocks_->data_source(), media_format()) |
| 318 .WillOnce(ReturnRef(data_source_media_format_)); |
| 283 | 319 |
| 284 EXPECT_CALL(*mocks_->demuxer(), Initialize(mocks_->data_source(), NotNull())) | 320 EXPECT_CALL(*mocks_->demuxer(), Initialize(mocks_->data_source(), NotNull())) |
| 285 .WillOnce(Invoke(&RunFilterCallback)); | 321 .WillOnce(Invoke(&RunFilterCallback)); |
| 286 EXPECT_CALL(*mocks_->demuxer(), GetNumberOfStreams()) | 322 EXPECT_CALL(*mocks_->demuxer(), GetNumberOfStreams()) |
| 287 .WillRepeatedly(Return(0)); | 323 .WillRepeatedly(Return(0)); |
| 288 EXPECT_CALL(*mocks_->demuxer(), Stop()); | 324 EXPECT_CALL(*mocks_->demuxer(), Stop()); |
| 289 EXPECT_CALL(callbacks_, OnError()); | 325 EXPECT_CALL(callbacks_, OnError()); |
| 290 | 326 |
| 291 InitializePipeline(); | 327 InitializePipeline(); |
| 292 EXPECT_FALSE(pipeline_->IsInitialized()); | 328 EXPECT_FALSE(pipeline_->IsInitialized()); |
| 293 EXPECT_EQ(PIPELINE_ERROR_COULD_NOT_RENDER, pipeline_->GetError()); | 329 EXPECT_EQ(PIPELINE_ERROR_COULD_NOT_RENDER, pipeline_->GetError()); |
| 294 } | 330 } |
| 295 | 331 |
| 296 TEST_F(PipelineImplTest, AudioStream) { | 332 TEST_F(PipelineImplTest, AudioStream) { |
| 297 scoped_refptr<StrictMock<MockDemuxerStream> > stream = | 333 scoped_refptr<StrictMock<MockDemuxerStream> > stream = |
| 298 new StrictMock<MockDemuxerStream>("audio/x-foo"); | 334 CreateStream("audio/x-foo"); |
| 299 MockDemuxerStreamVector streams; | 335 MockDemuxerStreamVector streams; |
| 300 streams.push_back(stream); | 336 streams.push_back(stream); |
| 301 | 337 |
| 302 InitializeDataSource(); | 338 InitializeDataSource(); |
| 303 InitializeDemuxer(&streams, base::TimeDelta()); | 339 InitializeDemuxer(&streams, base::TimeDelta()); |
| 304 InitializeAudioDecoder(stream); | 340 InitializeAudioDecoder(stream); |
| 305 InitializeAudioRenderer(); | 341 InitializeAudioRenderer(); |
| 306 | 342 |
| 307 InitializePipeline(); | 343 InitializePipeline(); |
| 308 EXPECT_TRUE(pipeline_->IsInitialized()); | 344 EXPECT_TRUE(pipeline_->IsInitialized()); |
| 309 EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); | 345 EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); |
| 310 EXPECT_TRUE(pipeline_->IsRendered(media::mime_type::kMajorTypeAudio)); | 346 EXPECT_TRUE(pipeline_->IsRendered(media::mime_type::kMajorTypeAudio)); |
| 311 EXPECT_FALSE(pipeline_->IsRendered(media::mime_type::kMajorTypeVideo)); | 347 EXPECT_FALSE(pipeline_->IsRendered(media::mime_type::kMajorTypeVideo)); |
| 312 } | 348 } |
| 313 | 349 |
| 314 TEST_F(PipelineImplTest, VideoStream) { | 350 TEST_F(PipelineImplTest, VideoStream) { |
| 315 scoped_refptr<StrictMock<MockDemuxerStream> > stream = | 351 scoped_refptr<StrictMock<MockDemuxerStream> > stream = |
| 316 new StrictMock<MockDemuxerStream>("video/x-foo"); | 352 CreateStream("video/x-foo"); |
| 317 MockDemuxerStreamVector streams; | 353 MockDemuxerStreamVector streams; |
| 318 streams.push_back(stream); | 354 streams.push_back(stream); |
| 319 | 355 |
| 320 InitializeDataSource(); | 356 InitializeDataSource(); |
| 321 InitializeDemuxer(&streams, base::TimeDelta()); | 357 InitializeDemuxer(&streams, base::TimeDelta()); |
| 322 InitializeVideoDecoder(stream); | 358 InitializeVideoDecoder(stream); |
| 323 InitializeVideoRenderer(); | 359 InitializeVideoRenderer(); |
| 324 | 360 |
| 325 InitializePipeline(); | 361 InitializePipeline(); |
| 326 EXPECT_TRUE(pipeline_->IsInitialized()); | 362 EXPECT_TRUE(pipeline_->IsInitialized()); |
| 327 EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); | 363 EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); |
| 328 EXPECT_FALSE(pipeline_->IsRendered(media::mime_type::kMajorTypeAudio)); | 364 EXPECT_FALSE(pipeline_->IsRendered(media::mime_type::kMajorTypeAudio)); |
| 329 EXPECT_TRUE(pipeline_->IsRendered(media::mime_type::kMajorTypeVideo)); | 365 EXPECT_TRUE(pipeline_->IsRendered(media::mime_type::kMajorTypeVideo)); |
| 330 } | 366 } |
| 331 | 367 |
| 332 TEST_F(PipelineImplTest, AudioVideoStream) { | 368 TEST_F(PipelineImplTest, AudioVideoStream) { |
| 333 scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream = | 369 scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream = |
| 334 new StrictMock<MockDemuxerStream>("audio/x-foo"); | 370 CreateStream("audio/x-foo"); |
| 335 scoped_refptr<StrictMock<MockDemuxerStream> > video_stream = | 371 scoped_refptr<StrictMock<MockDemuxerStream> > video_stream = |
| 336 new StrictMock<MockDemuxerStream>("video/x-foo"); | 372 CreateStream("video/x-foo"); |
| 337 MockDemuxerStreamVector streams; | 373 MockDemuxerStreamVector streams; |
| 338 streams.push_back(audio_stream); | 374 streams.push_back(audio_stream); |
| 339 streams.push_back(video_stream); | 375 streams.push_back(video_stream); |
| 340 | 376 |
| 341 InitializeDataSource(); | 377 InitializeDataSource(); |
| 342 InitializeDemuxer(&streams, base::TimeDelta()); | 378 InitializeDemuxer(&streams, base::TimeDelta()); |
| 343 InitializeAudioDecoder(audio_stream); | 379 InitializeAudioDecoder(audio_stream); |
| 344 InitializeAudioRenderer(); | 380 InitializeAudioRenderer(); |
| 345 InitializeVideoDecoder(video_stream); | 381 InitializeVideoDecoder(video_stream); |
| 346 InitializeVideoRenderer(); | 382 InitializeVideoRenderer(); |
| 347 | 383 |
| 348 InitializePipeline(); | 384 InitializePipeline(); |
| 349 EXPECT_TRUE(pipeline_->IsInitialized()); | 385 EXPECT_TRUE(pipeline_->IsInitialized()); |
| 350 EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); | 386 EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); |
| 351 EXPECT_TRUE(pipeline_->IsRendered(media::mime_type::kMajorTypeAudio)); | 387 EXPECT_TRUE(pipeline_->IsRendered(media::mime_type::kMajorTypeAudio)); |
| 352 EXPECT_TRUE(pipeline_->IsRendered(media::mime_type::kMajorTypeVideo)); | 388 EXPECT_TRUE(pipeline_->IsRendered(media::mime_type::kMajorTypeVideo)); |
| 353 } | 389 } |
| 354 | 390 |
| 355 TEST_F(PipelineImplTest, Seek) { | 391 TEST_F(PipelineImplTest, Seek) { |
| 356 scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream = | 392 scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream = |
| 357 new StrictMock<MockDemuxerStream>("audio/x-foo"); | 393 CreateStream("audio/x-foo"); |
| 358 scoped_refptr<StrictMock<MockDemuxerStream> > video_stream = | 394 scoped_refptr<StrictMock<MockDemuxerStream> > video_stream = |
| 359 new StrictMock<MockDemuxerStream>("video/x-foo"); | 395 CreateStream("video/x-foo"); |
| 360 MockDemuxerStreamVector streams; | 396 MockDemuxerStreamVector streams; |
| 361 streams.push_back(audio_stream); | 397 streams.push_back(audio_stream); |
| 362 streams.push_back(video_stream); | 398 streams.push_back(video_stream); |
| 363 | 399 |
| 364 InitializeDataSource(); | 400 InitializeDataSource(); |
| 365 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(3000)); | 401 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(3000)); |
| 366 InitializeAudioDecoder(audio_stream); | 402 InitializeAudioDecoder(audio_stream); |
| 367 InitializeAudioRenderer(); | 403 InitializeAudioRenderer(); |
| 368 InitializeVideoDecoder(video_stream); | 404 InitializeVideoDecoder(video_stream); |
| 369 InitializeVideoRenderer(); | 405 InitializeVideoRenderer(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 393 &CallbackHelper::OnSeek)); | 429 &CallbackHelper::OnSeek)); |
| 394 | 430 |
| 395 // We expect the time to be updated only after the seek has completed. | 431 // We expect the time to be updated only after the seek has completed. |
| 396 EXPECT_TRUE(expected != pipeline_->GetCurrentTime()); | 432 EXPECT_TRUE(expected != pipeline_->GetCurrentTime()); |
| 397 message_loop_.RunAllPending(); | 433 message_loop_.RunAllPending(); |
| 398 EXPECT_TRUE(expected == pipeline_->GetCurrentTime()); | 434 EXPECT_TRUE(expected == pipeline_->GetCurrentTime()); |
| 399 } | 435 } |
| 400 | 436 |
| 401 TEST_F(PipelineImplTest, SetVolume) { | 437 TEST_F(PipelineImplTest, SetVolume) { |
| 402 scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream = | 438 scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream = |
| 403 new StrictMock<MockDemuxerStream>("audio/x-foo"); | 439 CreateStream("audio/x-foo"); |
| 404 MockDemuxerStreamVector streams; | 440 MockDemuxerStreamVector streams; |
| 405 streams.push_back(audio_stream); | 441 streams.push_back(audio_stream); |
| 406 | 442 |
| 407 InitializeDataSource(); | 443 InitializeDataSource(); |
| 408 InitializeDemuxer(&streams, base::TimeDelta()); | 444 InitializeDemuxer(&streams, base::TimeDelta()); |
| 409 InitializeAudioDecoder(audio_stream); | 445 InitializeAudioDecoder(audio_stream); |
| 410 InitializeAudioRenderer(); | 446 InitializeAudioRenderer(); |
| 411 | 447 |
| 412 // The audio renderer should receive a call to SetVolume(). | 448 // The audio renderer should receive a call to SetVolume(). |
| 413 float expected = 0.5f; | 449 float expected = 0.5f; |
| 414 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(expected)); | 450 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(expected)); |
| 415 | 451 |
| 416 // Initialize then set volume! | 452 // Initialize then set volume! |
| 417 InitializePipeline(); | 453 InitializePipeline(); |
| 418 pipeline_->SetVolume(expected); | 454 pipeline_->SetVolume(expected); |
| 419 } | 455 } |
| 420 | 456 |
| 421 TEST_F(PipelineImplTest, Properties) { | 457 TEST_F(PipelineImplTest, Properties) { |
| 422 scoped_refptr<StrictMock<MockDemuxerStream> > stream = | 458 scoped_refptr<StrictMock<MockDemuxerStream> > stream = |
| 423 new StrictMock<MockDemuxerStream>("video/x-foo"); | 459 CreateStream("video/x-foo"); |
| 424 MockDemuxerStreamVector streams; | 460 MockDemuxerStreamVector streams; |
| 425 streams.push_back(stream); | 461 streams.push_back(stream); |
| 426 | 462 |
| 427 InitializeDataSource(); | 463 InitializeDataSource(); |
| 428 base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); | 464 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); |
| 429 InitializeDemuxer(&streams, kDuration); | 465 InitializeDemuxer(&streams, kDuration); |
| 430 InitializeVideoDecoder(stream); | 466 InitializeVideoDecoder(stream); |
| 431 InitializeVideoRenderer(); | 467 InitializeVideoRenderer(); |
| 432 | 468 |
| 433 InitializePipeline(); | 469 InitializePipeline(); |
| 434 EXPECT_TRUE(pipeline_->IsInitialized()); | 470 EXPECT_TRUE(pipeline_->IsInitialized()); |
| 435 EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); | 471 EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); |
| 436 EXPECT_EQ(kDuration.ToInternalValue(), | 472 EXPECT_EQ(kDuration.ToInternalValue(), |
| 437 pipeline_->GetDuration().ToInternalValue()); | 473 pipeline_->GetDuration().ToInternalValue()); |
| 438 EXPECT_EQ(kTotalBytes, pipeline_->GetTotalBytes()); | 474 EXPECT_EQ(kTotalBytes, pipeline_->GetTotalBytes()); |
| 439 EXPECT_EQ(kBufferedBytes, pipeline_->GetBufferedBytes()); | 475 EXPECT_EQ(kBufferedBytes, pipeline_->GetBufferedBytes()); |
| 440 EXPECT_EQ(kDuration.ToInternalValue(), | 476 EXPECT_EQ(kDuration.ToInternalValue(), |
| 441 pipeline_->GetBufferedTime().ToInternalValue()); | 477 pipeline_->GetBufferedTime().ToInternalValue()); |
| 442 } | 478 } |
| 443 | 479 |
| 444 TEST_F(PipelineImplTest, BroadcastMessage) { | 480 TEST_F(PipelineImplTest, BroadcastMessage) { |
| 445 scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream = | 481 scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream = |
| 446 new StrictMock<MockDemuxerStream>("audio/x-foo"); | 482 CreateStream("audio/x-foo"); |
| 447 scoped_refptr<StrictMock<MockDemuxerStream> > video_stream = | 483 scoped_refptr<StrictMock<MockDemuxerStream> > video_stream = |
| 448 new StrictMock<MockDemuxerStream>("video/x-foo"); | 484 CreateStream("video/x-foo"); |
| 449 MockDemuxerStreamVector streams; | 485 MockDemuxerStreamVector streams; |
| 450 streams.push_back(audio_stream); | 486 streams.push_back(audio_stream); |
| 451 streams.push_back(video_stream); | 487 streams.push_back(video_stream); |
| 452 | 488 |
| 453 InitializeDataSource(); | 489 InitializeDataSource(); |
| 454 InitializeDemuxer(&streams, base::TimeDelta()); | 490 InitializeDemuxer(&streams, base::TimeDelta()); |
| 455 InitializeAudioDecoder(audio_stream); | 491 InitializeAudioDecoder(audio_stream); |
| 456 InitializeAudioRenderer(); | 492 InitializeAudioRenderer(); |
| 457 InitializeVideoDecoder(video_stream); | 493 InitializeVideoDecoder(video_stream); |
| 458 InitializeVideoRenderer(); | 494 InitializeVideoRenderer(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 477 EXPECT_CALL(*mocks_->video_decoder(), | 513 EXPECT_CALL(*mocks_->video_decoder(), |
| 478 OnReceivedMessage(kMsgDisableAudio)); | 514 OnReceivedMessage(kMsgDisableAudio)); |
| 479 EXPECT_CALL(*mocks_->video_renderer(), | 515 EXPECT_CALL(*mocks_->video_renderer(), |
| 480 OnReceivedMessage(kMsgDisableAudio)); | 516 OnReceivedMessage(kMsgDisableAudio)); |
| 481 | 517 |
| 482 mocks_->audio_renderer()->SetPlaybackRate(1.0f); | 518 mocks_->audio_renderer()->SetPlaybackRate(1.0f); |
| 483 } | 519 } |
| 484 | 520 |
| 485 TEST_F(PipelineImplTest, EndedCallback) { | 521 TEST_F(PipelineImplTest, EndedCallback) { |
| 486 scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream = | 522 scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream = |
| 487 new StrictMock<MockDemuxerStream>("audio/x-foo"); | 523 CreateStream("audio/x-foo"); |
| 488 scoped_refptr<StrictMock<MockDemuxerStream> > video_stream = | 524 scoped_refptr<StrictMock<MockDemuxerStream> > video_stream = |
| 489 new StrictMock<MockDemuxerStream>("video/x-foo"); | 525 CreateStream("video/x-foo"); |
| 490 MockDemuxerStreamVector streams; | 526 MockDemuxerStreamVector streams; |
| 491 streams.push_back(audio_stream); | 527 streams.push_back(audio_stream); |
| 492 streams.push_back(video_stream); | 528 streams.push_back(video_stream); |
| 493 | 529 |
| 494 // Set our ended callback. | 530 // Set our ended callback. |
| 495 pipeline_->SetPipelineEndedCallback( | 531 pipeline_->SetPipelineEndedCallback( |
| 496 NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), | 532 NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), |
| 497 &CallbackHelper::OnEnded)); | 533 &CallbackHelper::OnEnded)); |
| 498 | 534 |
| 499 InitializeDataSource(); | 535 InitializeDataSource(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 521 | 557 |
| 522 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded()) | 558 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded()) |
| 523 .WillOnce(Return(true)); | 559 .WillOnce(Return(true)); |
| 524 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) | 560 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) |
| 525 .WillOnce(Return(true)); | 561 .WillOnce(Return(true)); |
| 526 EXPECT_CALL(callbacks_, OnEnded()); | 562 EXPECT_CALL(callbacks_, OnEnded()); |
| 527 host->NotifyEnded(); | 563 host->NotifyEnded(); |
| 528 } | 564 } |
| 529 | 565 |
| 530 } // namespace media | 566 } // namespace media |
| OLD | NEW |