| 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 "media/base/pipeline_impl.h" | 5 #include "media/base/pipeline_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 875 break; | 875 break; |
| 876 | 876 |
| 877 case kFlushing: | 877 case kFlushing: |
| 878 case kSeeking: | 878 case kSeeking: |
| 879 DoInitialize(state, stop_or_error); | 879 DoInitialize(state, stop_or_error); |
| 880 DoSeek(state, stop_or_error); | 880 DoSeek(state, stop_or_error); |
| 881 break; | 881 break; |
| 882 | 882 |
| 883 case kPlaying: | 883 case kPlaying: |
| 884 DoInitialize(state, stop_or_error); | 884 DoInitialize(state, stop_or_error); |
| 885 DoStopOrError(stop_or_error); | 885 DoStopOrError(stop_or_error, true); |
| 886 break; | 886 break; |
| 887 | 887 |
| 888 case kSuspending: | 888 case kSuspending: |
| 889 case kSuspended: | 889 case kSuspended: |
| 890 case kResuming: | 890 case kResuming: |
| 891 DoInitialize(state, stop_or_error); | 891 DoInitialize(state, stop_or_error); |
| 892 DoSuspend(state, stop_or_error); | 892 DoSuspend(state, stop_or_error); |
| 893 break; | 893 break; |
| 894 } | 894 } |
| 895 } | 895 } |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1038 return status; | 1038 return status; |
| 1039 } | 1039 } |
| 1040 | 1040 |
| 1041 NOTREACHED() << "State not supported: " << state; | 1041 NOTREACHED() << "State not supported: " << state; |
| 1042 return status; | 1042 return status; |
| 1043 } | 1043 } |
| 1044 | 1044 |
| 1045 void DoSuspend(TeardownState state, StopOrError stop_or_error) { | 1045 void DoSuspend(TeardownState state, StopOrError stop_or_error) { |
| 1046 PipelineStatus status = SetSuspendExpectations(state, stop_or_error); | 1046 PipelineStatus status = SetSuspendExpectations(state, stop_or_error); |
| 1047 | 1047 |
| 1048 if (state != kSuspended) { | 1048 if (state == kResuming) { |
| 1049 // DoStopOrError() handles these for kSuspended. | |
| 1050 EXPECT_CALL(*demuxer_, Stop()); | 1049 EXPECT_CALL(*demuxer_, Stop()); |
| 1051 if (status == PIPELINE_OK) { | 1050 if (status == PIPELINE_OK) |
| 1052 ExpectPipelineStopAndDestroyPipeline(); | 1051 ExpectPipelineStopAndDestroyPipeline(); |
| 1053 } | |
| 1054 } | 1052 } |
| 1055 | 1053 |
| 1056 PipelineImplTest::DoSuspend(); | 1054 PipelineImplTest::DoSuspend(); |
| 1057 | 1055 |
| 1058 if (state == kSuspended) { | 1056 if (state == kResuming) { |
| 1059 DoStopOrError(stop_or_error); | |
| 1060 } else if (state == kResuming) { | |
| 1061 PipelineImplTest::DoResume(base::TimeDelta()); | 1057 PipelineImplTest::DoResume(base::TimeDelta()); |
| 1058 return; |
| 1062 } | 1059 } |
| 1060 |
| 1061 // kSuspended, kSuspending never throw errors, since Resume() is always able |
| 1062 // to restore the pipeline to a pristine state. |
| 1063 DoStopOrError(stop_or_error, false); |
| 1063 } | 1064 } |
| 1064 | 1065 |
| 1065 PipelineStatus SetSuspendExpectations(TeardownState state, | 1066 PipelineStatus SetSuspendExpectations(TeardownState state, |
| 1066 StopOrError stop_or_error) { | 1067 StopOrError stop_or_error) { |
| 1067 PipelineStatus status = PIPELINE_OK; | 1068 PipelineStatus status = PIPELINE_OK; |
| 1068 base::Closure stop_cb = | 1069 base::Closure stop_cb = |
| 1069 base::Bind(&CallbackHelper::OnStop, base::Unretained(&callbacks_)); | 1070 base::Bind(&CallbackHelper::OnStop, base::Unretained(&callbacks_)); |
| 1070 | 1071 |
| 1071 EXPECT_CALL(*renderer_, SetPlaybackRate(0)); | 1072 EXPECT_CALL(*renderer_, SetPlaybackRate(0)); |
| 1072 if (state == kSuspended || state == kResuming) { | 1073 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)); |
| 1073 EXPECT_CALL(*renderer_, Flush(_)) | 1074 EXPECT_CALL(callbacks_, OnSuspend(PIPELINE_OK)); |
| 1074 .WillOnce(DoAll( | 1075 EXPECT_CALL(*renderer_, Flush(_)) |
| 1075 SetBufferingState(&buffering_state_cb_, BUFFERING_HAVE_NOTHING), | 1076 .WillOnce(DoAll( |
| 1076 RunClosure<0>())); | 1077 SetBufferingState(&buffering_state_cb_, BUFFERING_HAVE_NOTHING), |
| 1077 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)); | 1078 RunClosure<0>())); |
| 1078 EXPECT_CALL(callbacks_, OnSuspend(PIPELINE_OK)); | 1079 if (state == kResuming) { |
| 1079 if (state == kResuming) { | |
| 1080 if (stop_or_error == kStop) { | |
| 1081 EXPECT_CALL(*demuxer_, Seek(_, _)) | |
| 1082 .WillOnce(DoAll(Stop(pipeline_.get(), stop_cb), | |
| 1083 RunCallback<1>(PIPELINE_OK))); | |
| 1084 EXPECT_CALL(callbacks_, OnResume(PIPELINE_OK)); | |
| 1085 } else { | |
| 1086 status = PIPELINE_ERROR_READ; | |
| 1087 EXPECT_CALL(*demuxer_, Seek(_, _)).WillOnce(RunCallback<1>(status)); | |
| 1088 EXPECT_CALL(callbacks_, OnResume(status)); | |
| 1089 } | |
| 1090 } | |
| 1091 return status; | |
| 1092 } else if (state == kSuspending) { | |
| 1093 if (stop_or_error == kStop) { | 1080 if (stop_or_error == kStop) { |
| 1094 EXPECT_CALL(*renderer_, Flush(_)) | 1081 EXPECT_CALL(*demuxer_, Seek(_, _)) |
| 1095 .WillOnce(DoAll( | 1082 .WillOnce(DoAll(Stop(pipeline_.get(), stop_cb), |
| 1096 Stop(pipeline_.get(), stop_cb), | 1083 RunCallback<1>(PIPELINE_OK))); |
| 1097 SetBufferingState(&buffering_state_cb_, BUFFERING_HAVE_NOTHING), | 1084 EXPECT_CALL(callbacks_, OnResume(PIPELINE_OK)); |
| 1098 RunClosure<0>())); | |
| 1099 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)); | |
| 1100 EXPECT_CALL(callbacks_, OnSuspend(PIPELINE_OK)); | |
| 1101 } else { | 1085 } else { |
| 1102 status = PIPELINE_ERROR_READ; | 1086 status = PIPELINE_ERROR_READ; |
| 1103 EXPECT_CALL(*renderer_, Flush(_)) | 1087 EXPECT_CALL(*demuxer_, Seek(_, _)).WillOnce(RunCallback<1>(status)); |
| 1104 .WillOnce(SetError(pipeline_.get(), status)); | 1088 EXPECT_CALL(callbacks_, OnResume(status)); |
| 1105 EXPECT_CALL(callbacks_, OnSuspend(status)); | |
| 1106 } | 1089 } |
| 1107 return status; | 1090 } else if (state != kSuspended && state != kSuspending) { |
| 1091 NOTREACHED() << "State not supported: " << state; |
| 1108 } | 1092 } |
| 1109 | 1093 |
| 1110 NOTREACHED() << "State not supported: " << state; | |
| 1111 return status; | 1094 return status; |
| 1112 } | 1095 } |
| 1113 | 1096 |
| 1114 void DoStopOrError(StopOrError stop_or_error) { | 1097 void DoStopOrError(StopOrError stop_or_error, bool expect_errors) { |
| 1115 InSequence s; | 1098 InSequence s; |
| 1116 | 1099 |
| 1117 EXPECT_CALL(*demuxer_, Stop()); | |
| 1118 | |
| 1119 switch (stop_or_error) { | 1100 switch (stop_or_error) { |
| 1120 case kStop: | 1101 case kStop: |
| 1102 EXPECT_CALL(*demuxer_, Stop()); |
| 1121 ExpectPipelineStopAndDestroyPipeline(); | 1103 ExpectPipelineStopAndDestroyPipeline(); |
| 1122 pipeline_->Stop( | 1104 pipeline_->Stop( |
| 1123 base::Bind(&CallbackHelper::OnStop, base::Unretained(&callbacks_))); | 1105 base::Bind(&CallbackHelper::OnStop, base::Unretained(&callbacks_))); |
| 1124 break; | 1106 break; |
| 1125 | 1107 |
| 1126 case kError: | 1108 case kError: |
| 1127 EXPECT_CALL(callbacks_, OnError(PIPELINE_ERROR_READ)); | 1109 if (expect_errors) { |
| 1110 EXPECT_CALL(*demuxer_, Stop()); |
| 1111 EXPECT_CALL(callbacks_, OnError(PIPELINE_ERROR_READ)); |
| 1112 } |
| 1128 pipeline_->SetErrorForTesting(PIPELINE_ERROR_READ); | 1113 pipeline_->SetErrorForTesting(PIPELINE_ERROR_READ); |
| 1129 break; | 1114 break; |
| 1130 | 1115 |
| 1131 case kErrorAndStop: | 1116 case kErrorAndStop: |
| 1132 EXPECT_CALL(callbacks_, OnError(PIPELINE_ERROR_READ)); | 1117 EXPECT_CALL(*demuxer_, Stop()); |
| 1118 if (expect_errors) |
| 1119 EXPECT_CALL(callbacks_, OnError(PIPELINE_ERROR_READ)); |
| 1133 ExpectPipelineStopAndDestroyPipeline(); | 1120 ExpectPipelineStopAndDestroyPipeline(); |
| 1134 pipeline_->SetErrorForTesting(PIPELINE_ERROR_READ); | 1121 pipeline_->SetErrorForTesting(PIPELINE_ERROR_READ); |
| 1135 message_loop_.RunUntilIdle(); | 1122 message_loop_.RunUntilIdle(); |
| 1136 pipeline_->Stop( | 1123 pipeline_->Stop( |
| 1137 base::Bind(&CallbackHelper::OnStop, base::Unretained(&callbacks_))); | 1124 base::Bind(&CallbackHelper::OnStop, base::Unretained(&callbacks_))); |
| 1138 break; | 1125 break; |
| 1139 } | 1126 } |
| 1140 | 1127 |
| 1141 message_loop_.RunUntilIdle(); | 1128 message_loop_.RunUntilIdle(); |
| 1142 } | 1129 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1164 INSTANTIATE_TEARDOWN_TEST(Error, Seeking); | 1151 INSTANTIATE_TEARDOWN_TEST(Error, Seeking); |
| 1165 INSTANTIATE_TEARDOWN_TEST(Error, Playing); | 1152 INSTANTIATE_TEARDOWN_TEST(Error, Playing); |
| 1166 INSTANTIATE_TEARDOWN_TEST(Error, Suspending); | 1153 INSTANTIATE_TEARDOWN_TEST(Error, Suspending); |
| 1167 INSTANTIATE_TEARDOWN_TEST(Error, Suspended); | 1154 INSTANTIATE_TEARDOWN_TEST(Error, Suspended); |
| 1168 INSTANTIATE_TEARDOWN_TEST(Error, Resuming); | 1155 INSTANTIATE_TEARDOWN_TEST(Error, Resuming); |
| 1169 | 1156 |
| 1170 INSTANTIATE_TEARDOWN_TEST(ErrorAndStop, Playing); | 1157 INSTANTIATE_TEARDOWN_TEST(ErrorAndStop, Playing); |
| 1171 INSTANTIATE_TEARDOWN_TEST(ErrorAndStop, Suspended); | 1158 INSTANTIATE_TEARDOWN_TEST(ErrorAndStop, Suspended); |
| 1172 | 1159 |
| 1173 } // namespace media | 1160 } // namespace media |
| OLD | NEW |