Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/threading/simple_thread.h" | 10 #include "base/threading/simple_thread.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 EXPECT_CALL(*mocks_->demuxer(), GetStartTime()) | 106 EXPECT_CALL(*mocks_->demuxer(), GetStartTime()) |
| 107 .WillRepeatedly(Return(base::TimeDelta())); | 107 .WillRepeatedly(Return(base::TimeDelta())); |
| 108 } | 108 } |
| 109 | 109 |
| 110 virtual ~PipelineTest() { | 110 virtual ~PipelineTest() { |
| 111 // Shutdown sequence. | 111 // Shutdown sequence. |
| 112 if (pipeline_->IsRunning()) { | 112 if (pipeline_->IsRunning()) { |
| 113 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) | 113 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) |
| 114 .WillOnce(RunClosure()); | 114 .WillOnce(RunClosure()); |
| 115 | 115 |
| 116 // TODO(scherkus): Don't pause+flush on shutdown, | 116 if (audio_stream_) |
| 117 // see http://crbug.com/110228 | 117 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); |
| 118 if (audio_stream_) { | |
| 119 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) | |
| 120 .WillOnce(RunClosure()); | |
| 121 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) | |
| 122 .WillOnce(RunClosure()); | |
| 123 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)) | |
| 124 .WillOnce(RunClosure()); | |
| 125 } | |
| 126 | 118 |
| 127 if (video_stream_) { | 119 if (video_stream_) |
| 128 EXPECT_CALL(*mocks_->video_renderer(), Pause(_)) | 120 EXPECT_CALL(*mocks_->video_renderer(), Stop(_)).WillOnce(RunClosure()); |
| 129 .WillOnce(RunClosure()); | |
| 130 EXPECT_CALL(*mocks_->video_renderer(), Flush(_)) | |
| 131 .WillOnce(RunClosure()); | |
| 132 EXPECT_CALL(*mocks_->video_renderer(), Stop(_)) | |
| 133 .WillOnce(RunClosure()); | |
| 134 } | |
| 135 } | 121 } |
| 136 | 122 |
| 137 // Expect a stop callback if we were started. | 123 // Expect a stop callback if we were started. |
| 138 EXPECT_CALL(callbacks_, OnStop()); | 124 EXPECT_CALL(callbacks_, OnStop()); |
| 139 pipeline_->Stop(base::Bind(&CallbackHelper::OnStop, | 125 pipeline_->Stop(base::Bind(&CallbackHelper::OnStop, |
| 140 base::Unretained(&callbacks_))); | 126 base::Unretained(&callbacks_))); |
| 141 message_loop_.RunAllPending(); | 127 message_loop_.RunAllPending(); |
| 142 | 128 |
| 143 pipeline_ = NULL; | 129 pipeline_ = NULL; |
| 144 mocks_.reset(); | 130 mocks_.reset(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 // Sets up expectations on the callback and initializes the pipeline. Called | 201 // Sets up expectations on the callback and initializes the pipeline. Called |
| 216 // after tests have set expectations any filters they wish to use. | 202 // after tests have set expectations any filters they wish to use. |
| 217 void InitializePipeline(PipelineStatus start_status) { | 203 void InitializePipeline(PipelineStatus start_status) { |
| 218 EXPECT_CALL(callbacks_, OnStart(start_status)); | 204 EXPECT_CALL(callbacks_, OnStart(start_status)); |
| 219 | 205 |
| 220 if (start_status == PIPELINE_OK) { | 206 if (start_status == PIPELINE_OK) { |
| 221 EXPECT_CALL(callbacks_, OnBufferingState(Pipeline::kHaveMetadata)); | 207 EXPECT_CALL(callbacks_, OnBufferingState(Pipeline::kHaveMetadata)); |
| 222 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); | 208 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); |
| 223 | 209 |
| 224 if (audio_stream_) { | 210 if (audio_stream_) { |
| 225 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(0.0f)); | 211 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(0.0f)).Times(2); |
| 226 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(1.0f)); | 212 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(1.0f)); |
| 227 | 213 |
| 228 // Startup sequence. | 214 // Startup sequence. |
| 229 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(base::TimeDelta(), _)) | 215 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(base::TimeDelta(), _)) |
| 230 .WillOnce(RunPipelineStatusCB()); | 216 .WillOnce(RunPipelineStatusCB()); |
| 231 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) | 217 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) |
| 232 .WillOnce(RunClosure()); | 218 .WillOnce(RunClosure()); |
| 233 } | 219 } |
| 234 EXPECT_CALL(callbacks_, OnBufferingState(Pipeline::kPrerollCompleted)); | 220 EXPECT_CALL(callbacks_, OnBufferingState(Pipeline::kPrerollCompleted)); |
| 235 } | 221 } |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 259 } | 245 } |
| 260 | 246 |
| 261 MockDemuxerStream* video_stream() { | 247 MockDemuxerStream* video_stream() { |
| 262 return video_stream_; | 248 return video_stream_; |
| 263 } | 249 } |
| 264 | 250 |
| 265 void ExpectSeek(const base::TimeDelta& seek_time) { | 251 void ExpectSeek(const base::TimeDelta& seek_time) { |
| 266 // Every filter should receive a call to Seek(). | 252 // Every filter should receive a call to Seek(). |
| 267 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _)) | 253 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _)) |
| 268 .WillOnce(RunPipelineStatusCB()); | 254 .WillOnce(RunPipelineStatusCB()); |
| 255 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(_)); | |
| 269 | 256 |
| 270 if (audio_stream_) { | 257 if (audio_stream_) { |
| 271 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) | 258 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) |
| 272 .WillOnce(RunClosure()); | 259 .WillOnce(RunClosure()); |
| 273 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) | 260 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) |
| 274 .WillOnce(RunClosure()); | 261 .WillOnce(RunClosure()); |
| 275 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(seek_time, _)) | 262 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(seek_time, _)) |
| 276 .WillOnce(RunPipelineStatusCB()); | 263 .WillOnce(RunPipelineStatusCB()); |
| 264 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(_)).Times(2); | |
| 265 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(_)); | |
|
acolwell GONE FROM CHROMIUM
2012/09/06 09:19:10
I really would prefer it if we could avoid changin
scherkus (not reviewing)
2012/09/06 15:33:20
Even though we chatted about rolling out my playba
| |
| 277 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) | 266 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) |
| 278 .WillOnce(RunClosure()); | 267 .WillOnce(RunClosure()); |
| 279 } | 268 } |
| 280 | 269 |
| 281 if (video_stream_) { | 270 if (video_stream_) { |
| 282 EXPECT_CALL(*mocks_->video_renderer(), Pause(_)) | 271 EXPECT_CALL(*mocks_->video_renderer(), Pause(_)) |
| 283 .WillOnce(RunClosure()); | 272 .WillOnce(RunClosure()); |
| 284 EXPECT_CALL(*mocks_->video_renderer(), Flush(_)) | 273 EXPECT_CALL(*mocks_->video_renderer(), Flush(_)) |
| 285 .WillOnce(RunClosure()); | 274 .WillOnce(RunClosure()); |
| 286 EXPECT_CALL(*mocks_->video_renderer(), Preroll(seek_time, _)) | 275 EXPECT_CALL(*mocks_->video_renderer(), Preroll(seek_time, _)) |
| 287 .WillOnce(RunPipelineStatusCB()); | 276 .WillOnce(RunPipelineStatusCB()); |
| 277 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(_)); | |
| 288 EXPECT_CALL(*mocks_->video_renderer(), Play(_)) | 278 EXPECT_CALL(*mocks_->video_renderer(), Play(_)) |
| 289 .WillOnce(RunClosure()); | 279 .WillOnce(RunClosure()); |
| 290 } | 280 } |
| 291 | 281 |
| 292 EXPECT_CALL(callbacks_, OnBufferingState(Pipeline::kPrerollCompleted)); | 282 EXPECT_CALL(callbacks_, OnBufferingState(Pipeline::kPrerollCompleted)); |
| 293 | 283 |
| 294 // We expect a successful seek callback. | 284 // We expect a successful seek callback. |
| 295 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK)); | 285 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK)); |
| 296 } | 286 } |
| 297 | 287 |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 703 InitializePipeline(PIPELINE_OK); | 693 InitializePipeline(PIPELINE_OK); |
| 704 | 694 |
| 705 float playback_rate = 1.0f; | 695 float playback_rate = 1.0f; |
| 706 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(playback_rate)); | 696 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(playback_rate)); |
| 707 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(playback_rate)); | 697 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(playback_rate)); |
| 708 pipeline_->SetPlaybackRate(playback_rate); | 698 pipeline_->SetPlaybackRate(playback_rate); |
| 709 message_loop_.RunAllPending(); | 699 message_loop_.RunAllPending(); |
| 710 | 700 |
| 711 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5); | 701 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5); |
| 712 | 702 |
| 713 // Seek() isn't called as the demuxer errors out first. | 703 // Preroll() isn't called as the demuxer errors out first. |
| 714 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) | 704 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) |
| 715 .WillOnce(RunClosure()); | 705 .WillOnce(RunClosure()); |
| 716 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) | 706 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) |
| 717 .WillOnce(RunClosure()); | 707 .WillOnce(RunClosure()); |
| 718 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)) | 708 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)) |
| 719 .WillOnce(RunClosure()); | 709 .WillOnce(RunClosure()); |
| 720 | 710 |
| 721 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _)) | 711 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _)) |
| 722 .WillOnce(RunPipelineStatusCBWithStatus(PIPELINE_ERROR_READ)); | 712 .WillOnce(RunPipelineStatusCBWithStatus(PIPELINE_ERROR_READ)); |
| 723 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) | 713 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 859 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _)) | 849 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _)) |
| 860 .WillOnce(DoAll(InvokeWithoutArgs(&closure, &base::Closure::Run), | 850 .WillOnce(DoAll(InvokeWithoutArgs(&closure, &base::Closure::Run), |
| 861 RunPipelineStatusCB())); | 851 RunPipelineStatusCB())); |
| 862 | 852 |
| 863 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) | 853 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) |
| 864 .WillOnce(RunClosure()); | 854 .WillOnce(RunClosure()); |
| 865 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) | 855 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) |
| 866 .WillOnce(RunClosure()); | 856 .WillOnce(RunClosure()); |
| 867 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(seek_time, _)) | 857 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(seek_time, _)) |
| 868 .WillOnce(RunPipelineStatusCB()); | 858 .WillOnce(RunPipelineStatusCB()); |
| 859 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(_)); | |
| 860 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(_)).Times(2); | |
| 861 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(_)); | |
| 869 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) | 862 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) |
| 870 .WillOnce(RunClosure()); | 863 .WillOnce(RunClosure()); |
| 871 | 864 |
| 872 EXPECT_CALL(callbacks_, OnBufferingState(Pipeline::kPrerollCompleted)); | 865 EXPECT_CALL(callbacks_, OnBufferingState(Pipeline::kPrerollCompleted)); |
| 873 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK)); | 866 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK)); |
| 874 DoSeek(seek_time); | 867 DoSeek(seek_time); |
| 875 | 868 |
| 876 EXPECT_EQ(pipeline_->GetMediaTime(), seek_time); | 869 EXPECT_EQ(pipeline_->GetMediaTime(), seek_time); |
| 877 | 870 |
| 878 // Now that the seek is complete, verify that time updates advance the current | 871 // Now that the seek is complete, verify that time updates advance the current |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 965 case kInitAudioDecoder: | 958 case kInitAudioDecoder: |
| 966 case kInitAudioRenderer: | 959 case kInitAudioRenderer: |
| 967 case kInitVideoRenderer: | 960 case kInitVideoRenderer: |
| 968 DoInitialize(state, stop_or_error); | 961 DoInitialize(state, stop_or_error); |
| 969 break; | 962 break; |
| 970 | 963 |
| 971 case kPausing: | 964 case kPausing: |
| 972 case kFlushing: | 965 case kFlushing: |
| 973 case kSeeking: | 966 case kSeeking: |
| 974 case kPrerolling: | 967 case kPrerolling: |
| 975 case kStarting: { | 968 case kStarting: |
| 976 DoInitialize(state, stop_or_error); | 969 DoInitialize(state, stop_or_error); |
| 970 DoSeek(state, stop_or_error); | |
| 971 break; | |
| 977 | 972 |
| 978 InSequence s; | 973 case kPlaying: |
| 979 if (stop_or_error == kStop) { | 974 DoInitialize(state, stop_or_error); |
| 980 ExpectSeekStop(state); | 975 DoStopOrError(stop_or_error); |
| 981 } else { | |
| 982 ExpectSeekError(state); | |
| 983 } | |
| 984 DoSeek(); | |
| 985 break; | 976 break; |
| 986 } | |
| 987 | |
| 988 case kPlaying: { | |
| 989 DoInitialize(state, stop_or_error); | |
| 990 | |
| 991 InSequence s; | |
| 992 if (stop_or_error == kStop) { | |
| 993 ExpectStop(); | |
| 994 DoStop(); | |
| 995 } else { | |
| 996 ExpectPlaybackError(); | |
| 997 DoPlaybackError(); | |
| 998 } | |
| 999 break; | |
| 1000 } | |
| 1001 } | 977 } |
| 1002 } | 978 } |
| 1003 | 979 |
| 1004 private: | 980 private: |
| 1005 // TODO(scherkus): We do radically different things whether teardown is | 981 // TODO(scherkus): We do radically different things whether teardown is |
| 1006 // invoked via stop vs error. The teardown path should be the same, | 982 // invoked via stop vs error. The teardown path should be the same, |
| 1007 // see http://crbug.com/110228 | 983 // see http://crbug.com/110228 |
| 1008 void DoInitialize(TeardownState state, StopOrError stop_or_error) { | 984 void DoInitialize(TeardownState state, StopOrError stop_or_error) { |
| 1009 PipelineStatus expected_status = | 985 PipelineStatus expected_status = |
| 1010 SetInitializeExpectations(state, stop_or_error); | 986 SetInitializeExpectations(state, stop_or_error); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1104 return status; | 1080 return status; |
| 1105 } | 1081 } |
| 1106 | 1082 |
| 1107 EXPECT_CALL(*mocks_->video_renderer(), | 1083 EXPECT_CALL(*mocks_->video_renderer(), |
| 1108 Initialize(_, _, _, _, _, _, _, _, _, _)) | 1084 Initialize(_, _, _, _, _, _, _, _, _, _)) |
| 1109 .WillOnce(RunPipelineStatusCB2()); | 1085 .WillOnce(RunPipelineStatusCB2()); |
| 1110 | 1086 |
| 1111 EXPECT_CALL(callbacks_, OnBufferingState(Pipeline::kHaveMetadata)); | 1087 EXPECT_CALL(callbacks_, OnBufferingState(Pipeline::kHaveMetadata)); |
| 1112 | 1088 |
| 1113 // If we get here it's a successful initialization. | 1089 // If we get here it's a successful initialization. |
| 1114 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); | |
| 1115 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(0.0f)); | |
| 1116 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(0.0f)); | |
| 1117 | |
| 1118 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(1.0f)); | |
| 1119 | |
| 1120 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(base::TimeDelta(), _)) | 1090 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(base::TimeDelta(), _)) |
| 1121 .WillOnce(RunPipelineStatusCB()); | 1091 .WillOnce(RunPipelineStatusCB()); |
| 1122 EXPECT_CALL(*mocks_->video_renderer(), Preroll(base::TimeDelta(), _)) | 1092 EXPECT_CALL(*mocks_->video_renderer(), Preroll(base::TimeDelta(), _)) |
| 1123 .WillOnce(RunPipelineStatusCB()); | 1093 .WillOnce(RunPipelineStatusCB()); |
| 1124 | 1094 |
| 1095 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); | |
| 1096 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(0.0f)).Times(2); | |
| 1097 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(0.0f)); | |
| 1098 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(1.0f)); | |
| 1099 | |
| 1125 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) | 1100 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) |
| 1126 .WillOnce(RunClosure()); | 1101 .WillOnce(RunClosure()); |
| 1127 EXPECT_CALL(*mocks_->video_renderer(), Play(_)) | 1102 EXPECT_CALL(*mocks_->video_renderer(), Play(_)) |
| 1128 .WillOnce(RunClosure()); | 1103 .WillOnce(RunClosure()); |
| 1129 | 1104 |
| 1130 if (status == PIPELINE_OK) | 1105 if (status == PIPELINE_OK) |
| 1131 EXPECT_CALL(callbacks_, OnBufferingState(Pipeline::kPrerollCompleted)); | 1106 EXPECT_CALL(callbacks_, OnBufferingState(Pipeline::kPrerollCompleted)); |
| 1132 | 1107 |
| 1133 return status; | 1108 return status; |
| 1134 } | 1109 } |
| 1135 | 1110 |
| 1136 void ExpectSeekStop(TeardownState state) { | 1111 void DoSeek(TeardownState state, StopOrError stop_or_error) { |
| 1112 InSequence s; | |
| 1113 PipelineStatus status = SetSeekExpectations(state, stop_or_error); | |
| 1114 | |
| 1115 EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); | |
| 1116 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); | |
| 1117 EXPECT_CALL(*mocks_->video_renderer(), Stop(_)).WillOnce(RunClosure()); | |
| 1118 EXPECT_CALL(callbacks_, OnSeek(status)); | |
| 1119 | |
| 1120 if (status == PIPELINE_OK) { | |
| 1121 EXPECT_CALL(callbacks_, OnStop()); | |
| 1122 } | |
| 1123 | |
| 1124 pipeline_->Seek(base::TimeDelta::FromSeconds(10), base::Bind( | |
| 1125 &CallbackHelper::OnSeek, base::Unretained(&callbacks_))); | |
| 1126 message_loop_.RunAllPending(); | |
| 1127 } | |
| 1128 | |
| 1129 PipelineStatus SetSeekExpectations(TeardownState state, | |
| 1130 StopOrError stop_or_error) { | |
| 1131 PipelineStatus status = PIPELINE_OK; | |
| 1137 base::Closure stop_cb = base::Bind( | 1132 base::Closure stop_cb = base::Bind( |
| 1138 &CallbackHelper::OnStop, base::Unretained(&callbacks_)); | 1133 &CallbackHelper::OnStop, base::Unretained(&callbacks_)); |
| 1139 | 1134 |
| 1140 if (state == kPausing) { | 1135 if (state == kPausing) { |
| 1141 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) | 1136 if (stop_or_error == kStop) { |
| 1142 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunClosure())); | 1137 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) |
| 1143 } else { | 1138 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunClosure())); |
| 1144 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)).WillOnce(RunClosure()); | 1139 } else { |
| 1145 } | 1140 status = PIPELINE_ERROR_READ; |
| 1141 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) | |
| 1142 .WillOnce(DoAll(SetError(pipeline_, status), RunClosure())); | |
| 1143 } | |
| 1146 | 1144 |
| 1147 EXPECT_CALL(*mocks_->video_renderer(), Pause(_)).WillOnce(RunClosure()); | 1145 return status; |
| 1148 | |
| 1149 if (state == kFlushing) { | |
| 1150 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) | |
| 1151 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunClosure())); | |
| 1152 } else { | |
| 1153 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)).WillOnce(RunClosure()); | |
| 1154 } | |
| 1155 | |
| 1156 EXPECT_CALL(*mocks_->video_renderer(), Flush(_)).WillOnce(RunClosure()); | |
| 1157 | |
| 1158 if (state == kSeeking) { | |
| 1159 EXPECT_CALL(*mocks_->demuxer(), Seek(_, _)) | |
| 1160 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunPipelineStatusCB())); | |
| 1161 } else { | |
| 1162 EXPECT_CALL(*mocks_->demuxer(), Seek(_, _)) | |
| 1163 .WillOnce(RunPipelineStatusCB()); | |
| 1164 } | |
| 1165 | |
| 1166 if (state == kPrerolling) { | |
| 1167 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(_, _)) | |
| 1168 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunPipelineStatusCB())); | |
| 1169 } else { | |
| 1170 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(_, _)) | |
| 1171 .WillOnce(RunPipelineStatusCB()); | |
| 1172 } | |
| 1173 | |
| 1174 EXPECT_CALL(*mocks_->video_renderer(), Preroll(_, _)) | |
| 1175 .WillOnce(RunPipelineStatusCB()); | |
| 1176 | |
| 1177 if (state == kStarting) { | |
| 1178 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) | |
| 1179 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunClosure())); | |
| 1180 } else { | |
| 1181 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)).WillOnce(RunClosure()); | |
| 1182 } | |
| 1183 | |
| 1184 EXPECT_CALL(*mocks_->video_renderer(), Play(_)).WillOnce(RunClosure()); | |
| 1185 | |
| 1186 EXPECT_CALL(callbacks_, OnBufferingState(Pipeline::kPrerollCompleted)); | |
| 1187 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK)); | |
| 1188 ExpectStop(); | |
| 1189 } | |
| 1190 | |
| 1191 void ExpectSeekError(TeardownState state) { | |
| 1192 SetSeekErrorExpectations(state); | |
| 1193 | |
| 1194 // Executed after the error is raised. | |
| 1195 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_ERROR_READ)); | |
| 1196 EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); | |
| 1197 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); | |
| 1198 EXPECT_CALL(*mocks_->video_renderer(), Stop(_)).WillOnce(RunClosure()); | |
| 1199 } | |
| 1200 | |
| 1201 void SetSeekErrorExpectations(TeardownState state) { | |
| 1202 if (state == kPausing) { | |
| 1203 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) | |
| 1204 .WillOnce(DoAll(SetError(pipeline_, PIPELINE_ERROR_READ), | |
| 1205 RunClosure())); | |
| 1206 EXPECT_CALL(*mocks_->video_renderer(), Pause(_)).WillOnce(RunClosure()); | |
| 1207 return; | |
| 1208 } | 1146 } |
| 1209 | 1147 |
| 1210 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)).WillOnce(RunClosure()); | 1148 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)).WillOnce(RunClosure()); |
| 1211 EXPECT_CALL(*mocks_->video_renderer(), Pause(_)).WillOnce(RunClosure()); | 1149 EXPECT_CALL(*mocks_->video_renderer(), Pause(_)).WillOnce(RunClosure()); |
| 1212 | 1150 |
| 1213 if (state == kFlushing) { | 1151 if (state == kFlushing) { |
| 1214 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) | 1152 if (stop_or_error == kStop) { |
| 1215 .WillOnce(DoAll(SetError(pipeline_, PIPELINE_ERROR_READ), | 1153 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) |
| 1216 RunClosure())); | 1154 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunClosure())); |
| 1217 EXPECT_CALL(*mocks_->video_renderer(), Flush(_)).WillOnce(RunClosure()); | 1155 } else { |
| 1218 return; | 1156 status = PIPELINE_ERROR_READ; |
| 1157 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) | |
| 1158 .WillOnce(DoAll(SetError(pipeline_, status), RunClosure())); | |
| 1159 } | |
| 1160 | |
| 1161 return status; | |
| 1219 } | 1162 } |
| 1220 | 1163 |
| 1221 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)).WillOnce(RunClosure()); | 1164 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)).WillOnce(RunClosure()); |
| 1222 EXPECT_CALL(*mocks_->video_renderer(), Flush(_)).WillOnce(RunClosure()); | 1165 EXPECT_CALL(*mocks_->video_renderer(), Flush(_)).WillOnce(RunClosure()); |
| 1223 | 1166 |
| 1224 if (state == kSeeking) { | 1167 if (state == kSeeking) { |
| 1225 EXPECT_CALL(*mocks_->demuxer(), Seek(_, _)) | 1168 if (stop_or_error == kStop) { |
| 1226 .WillOnce(RunPipelineStatusCBWithStatus(PIPELINE_ERROR_READ)); | 1169 EXPECT_CALL(*mocks_->demuxer(), Seek(_, _)) |
| 1227 return; | 1170 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunPipelineStatusCB())); |
| 1171 } else { | |
| 1172 status = PIPELINE_ERROR_READ; | |
| 1173 EXPECT_CALL(*mocks_->demuxer(), Seek(_, _)) | |
| 1174 .WillOnce(RunPipelineStatusCBWithStatus(status)); | |
| 1175 } | |
| 1176 | |
| 1177 return status; | |
| 1228 } | 1178 } |
| 1229 | 1179 |
| 1230 EXPECT_CALL(*mocks_->demuxer(), Seek(_, _)) | 1180 EXPECT_CALL(*mocks_->demuxer(), Seek(_, _)) |
| 1231 .WillOnce(RunPipelineStatusCB()); | 1181 .WillOnce(RunPipelineStatusCB()); |
| 1182 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(0.0f)); | |
| 1232 | 1183 |
| 1233 if (state == kPrerolling) { | 1184 if (state == kPrerolling) { |
| 1234 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(_, _)) | 1185 if (stop_or_error == kStop) { |
| 1235 .WillOnce(RunPipelineStatusCBWithStatus(PIPELINE_ERROR_READ)); | 1186 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(_, _)) |
| 1236 return; | 1187 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunPipelineStatusCB())); |
| 1188 } else { | |
| 1189 status = PIPELINE_ERROR_READ; | |
| 1190 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(_, _)) | |
| 1191 .WillOnce(RunPipelineStatusCBWithStatus(status)); | |
| 1192 } | |
| 1193 | |
| 1194 return status; | |
| 1237 } | 1195 } |
| 1238 | 1196 |
| 1239 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(_, _)) | 1197 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(_, _)) |
| 1240 .WillOnce(RunPipelineStatusCB()); | 1198 .WillOnce(RunPipelineStatusCB()); |
| 1241 EXPECT_CALL(*mocks_->video_renderer(), Preroll(_, _)) | 1199 EXPECT_CALL(*mocks_->video_renderer(), Preroll(_, _)) |
| 1242 .WillOnce(RunPipelineStatusCB()); | 1200 .WillOnce(RunPipelineStatusCB()); |
| 1243 | 1201 |
| 1202 // Playback rate and volume are updated prior to starting. | |
| 1203 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); | |
| 1204 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(0.0f)); | |
| 1205 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(0.0f)); | |
| 1206 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(1.0f)); | |
| 1207 | |
| 1244 if (state == kStarting) { | 1208 if (state == kStarting) { |
| 1245 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) | 1209 if (stop_or_error == kStop) { |
| 1246 .WillOnce(DoAll(SetError(pipeline_, PIPELINE_ERROR_READ), | 1210 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) |
| 1247 RunClosure())); | 1211 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunClosure())); |
| 1248 EXPECT_CALL(*mocks_->video_renderer(), Play(_)).WillOnce(RunClosure()); | 1212 } else { |
| 1249 return; | 1213 status = PIPELINE_ERROR_READ; |
| 1214 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) | |
| 1215 .WillOnce(DoAll(SetError(pipeline_, status), RunClosure())); | |
| 1216 } | |
| 1217 return status; | |
| 1250 } | 1218 } |
| 1251 | 1219 |
| 1252 NOTREACHED() << "Unexpected TeardownState: " << state; | 1220 NOTREACHED() << "State not supported: " << state; |
| 1221 return status; | |
| 1253 } | 1222 } |
| 1254 | 1223 |
| 1255 void ExpectStop() { | 1224 void DoStopOrError(StopOrError stop_or_error) { |
| 1256 // TODO(scherkus): Don't pause+flush, see http://crbug.com/110228 | 1225 InSequence s; |
| 1257 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)).WillOnce(RunClosure()); | 1226 |
| 1258 EXPECT_CALL(*mocks_->video_renderer(), Pause(_)).WillOnce(RunClosure()); | |
| 1259 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)).WillOnce(RunClosure()); | |
| 1260 EXPECT_CALL(*mocks_->video_renderer(), Flush(_)).WillOnce(RunClosure()); | |
| 1261 EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); | 1227 EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); |
| 1262 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); | 1228 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); |
| 1263 EXPECT_CALL(*mocks_->video_renderer(), Stop(_)).WillOnce(RunClosure()); | 1229 EXPECT_CALL(*mocks_->video_renderer(), Stop(_)).WillOnce(RunClosure()); |
| 1264 | 1230 |
| 1265 EXPECT_CALL(callbacks_, OnStop()); | 1231 if (stop_or_error == kStop) { |
| 1266 } | 1232 EXPECT_CALL(callbacks_, OnStop()); |
| 1233 pipeline_->Stop(base::Bind( | |
| 1234 &CallbackHelper::OnStop, base::Unretained(&callbacks_))); | |
| 1235 } else { | |
| 1236 EXPECT_CALL(callbacks_, OnError(PIPELINE_ERROR_READ)); | |
| 1237 pipeline_->SetErrorForTesting(PIPELINE_ERROR_READ); | |
| 1238 } | |
| 1267 | 1239 |
| 1268 void ExpectPlaybackError() { | |
| 1269 // TODO(scherkus): Don't pause+flush, see http://crbug.com/110228 | |
| 1270 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)).WillOnce(RunClosure()); | |
| 1271 EXPECT_CALL(*mocks_->video_renderer(), Pause(_)).WillOnce(RunClosure()); | |
| 1272 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)).WillOnce(RunClosure()); | |
| 1273 EXPECT_CALL(*mocks_->video_renderer(), Flush(_)).WillOnce(RunClosure()); | |
| 1274 EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); | |
| 1275 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); | |
| 1276 EXPECT_CALL(*mocks_->video_renderer(), Stop(_)).WillOnce(RunClosure()); | |
| 1277 | |
| 1278 EXPECT_CALL(callbacks_, OnError(PIPELINE_ERROR_READ)); | |
| 1279 } | |
| 1280 | |
| 1281 void DoSeek() { | |
| 1282 pipeline_->Seek(base::TimeDelta::FromSeconds(10), base::Bind( | |
| 1283 &CallbackHelper::OnSeek, base::Unretained(&callbacks_))); | |
| 1284 message_loop_.RunAllPending(); | 1240 message_loop_.RunAllPending(); |
| 1285 } | 1241 } |
| 1286 | 1242 |
| 1287 void DoStop() { | |
| 1288 pipeline_->Stop(base::Bind( | |
| 1289 &CallbackHelper::OnStop, base::Unretained(&callbacks_))); | |
| 1290 message_loop_.RunAllPending(); | |
| 1291 } | |
| 1292 | |
| 1293 void DoPlaybackError() { | |
| 1294 pipeline_->SetErrorForTesting(PIPELINE_ERROR_READ); | |
| 1295 message_loop_.RunAllPending(); | |
| 1296 } | |
| 1297 | |
| 1298 DISALLOW_COPY_AND_ASSIGN(PipelineTeardownTest); | 1243 DISALLOW_COPY_AND_ASSIGN(PipelineTeardownTest); |
| 1299 }; | 1244 }; |
| 1300 | 1245 |
| 1301 #define INSTANTIATE_TEARDOWN_TEST(stop_or_error, state) \ | 1246 #define INSTANTIATE_TEARDOWN_TEST(stop_or_error, state) \ |
| 1302 TEST_F(PipelineTeardownTest, stop_or_error##_##state) { \ | 1247 TEST_F(PipelineTeardownTest, stop_or_error##_##state) { \ |
| 1303 RunTest(k##state, k##stop_or_error); \ | 1248 RunTest(k##state, k##stop_or_error); \ |
| 1304 } | 1249 } |
| 1305 | 1250 |
| 1306 INSTANTIATE_TEARDOWN_TEST(Stop, InitDemuxer); | 1251 INSTANTIATE_TEARDOWN_TEST(Stop, InitDemuxer); |
| 1307 INSTANTIATE_TEARDOWN_TEST(Stop, InitAudioDecoder); | 1252 INSTANTIATE_TEARDOWN_TEST(Stop, InitAudioDecoder); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1319 INSTANTIATE_TEARDOWN_TEST(Error, InitAudioRenderer); | 1264 INSTANTIATE_TEARDOWN_TEST(Error, InitAudioRenderer); |
| 1320 INSTANTIATE_TEARDOWN_TEST(Error, InitVideoRenderer); | 1265 INSTANTIATE_TEARDOWN_TEST(Error, InitVideoRenderer); |
| 1321 INSTANTIATE_TEARDOWN_TEST(Error, Pausing); | 1266 INSTANTIATE_TEARDOWN_TEST(Error, Pausing); |
| 1322 INSTANTIATE_TEARDOWN_TEST(Error, Flushing); | 1267 INSTANTIATE_TEARDOWN_TEST(Error, Flushing); |
| 1323 INSTANTIATE_TEARDOWN_TEST(Error, Seeking); | 1268 INSTANTIATE_TEARDOWN_TEST(Error, Seeking); |
| 1324 INSTANTIATE_TEARDOWN_TEST(Error, Prerolling); | 1269 INSTANTIATE_TEARDOWN_TEST(Error, Prerolling); |
| 1325 INSTANTIATE_TEARDOWN_TEST(Error, Starting); | 1270 INSTANTIATE_TEARDOWN_TEST(Error, Starting); |
| 1326 INSTANTIATE_TEARDOWN_TEST(Error, Playing); | 1271 INSTANTIATE_TEARDOWN_TEST(Error, Playing); |
| 1327 | 1272 |
| 1328 } // namespace media | 1273 } // namespace media |
| OLD | NEW |