| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/gpu/android_video_surface_chooser_impl.h" | 5 #include "media/gpu/android_video_surface_chooser_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 void UseOverlayImpl(std::unique_ptr<AndroidOverlay> overlay) { | 33 void UseOverlayImpl(std::unique_ptr<AndroidOverlay> overlay) { |
| 34 UseOverlay(overlay.get()); | 34 UseOverlay(overlay.get()); |
| 35 | 35 |
| 36 // Also take ownership of the overlay, so that it's not destroyed. | 36 // Also take ownership of the overlay, so that it's not destroyed. |
| 37 overlay_ = std::move(overlay); | 37 overlay_ = std::move(overlay); |
| 38 } | 38 } |
| 39 | 39 |
| 40 // Note that this won't clear |overlay_|, which is helpful. | 40 // Note that this won't clear |overlay_|, which is helpful. |
| 41 MOCK_METHOD0(UseSurfaceTexture, void(void)); | 41 MOCK_METHOD0(UseSurfaceTexture, void(void)); |
| 42 MOCK_METHOD1(StopUsingOverlayImmediately, void(AndroidOverlay*)); | |
| 43 | 42 |
| 44 private: | 43 private: |
| 45 std::unique_ptr<AndroidOverlay> overlay_; | 44 std::unique_ptr<AndroidOverlay> overlay_; |
| 46 }; | 45 }; |
| 47 | 46 |
| 48 } // namespace | 47 } // namespace |
| 49 | 48 |
| 50 namespace media { | 49 namespace media { |
| 51 | 50 |
| 52 // Unit tests for AndroidVideoSurfaceChooserImpl | 51 // Unit tests for AndroidVideoSurfaceChooserImpl |
| (...skipping 20 matching lines...) Expand all Loading... |
| 73 // checking expectations. | 72 // checking expectations. |
| 74 // Note that it might already be null. | 73 // Note that it might already be null. |
| 75 destruction_observer_ = nullptr; | 74 destruction_observer_ = nullptr; |
| 76 } | 75 } |
| 77 | 76 |
| 78 // Start the chooser, providing |factory| as the initial factory. | 77 // Start the chooser, providing |factory| as the initial factory. |
| 79 void StartChooser(AndroidOverlayFactoryCB factory) { | 78 void StartChooser(AndroidOverlayFactoryCB factory) { |
| 80 chooser_->Initialize( | 79 chooser_->Initialize( |
| 81 base::Bind(&MockClient::UseOverlayImpl, base::Unretained(&client_)), | 80 base::Bind(&MockClient::UseOverlayImpl, base::Unretained(&client_)), |
| 82 base::Bind(&MockClient::UseSurfaceTexture, base::Unretained(&client_)), | 81 base::Bind(&MockClient::UseSurfaceTexture, base::Unretained(&client_)), |
| 83 base::Bind(&MockClient::StopUsingOverlayImmediately, | |
| 84 base::Unretained(&client_)), | |
| 85 std::move(factory)); | 82 std::move(factory)); |
| 86 } | 83 } |
| 87 | 84 |
| 88 // AndroidOverlayFactoryCB is a RepeatingCallback, so we can't just bind | 85 // AndroidOverlayFactoryCB is a RepeatingCallback, so we can't just bind |
| 89 // something that uses unique_ptr. RepeatingCallback needs to copy it. | 86 // something that uses unique_ptr. RepeatingCallback needs to copy it. |
| 90 class Factory { | 87 class Factory { |
| 91 public: | 88 public: |
| 92 Factory(std::unique_ptr<MockAndroidOverlay> overlay, | 89 Factory(std::unique_ptr<MockAndroidOverlay> overlay, |
| 93 base::RepeatingCallback<void()> create_overlay_cb) | 90 base::RepeatingCallback<void()> create_overlay_cb) |
| 94 : overlay_(std::move(overlay)), | 91 : overlay_(std::move(overlay)), |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 testing::Mock::VerifyAndClearExpectations(this); | 190 testing::Mock::VerifyAndClearExpectations(this); |
| 194 | 191 |
| 195 // The overlay may be destroyed at any time after we send OverlayFailed. It | 192 // The overlay may be destroyed at any time after we send OverlayFailed. It |
| 196 // doesn't have to be destroyed. We just care that it hasn't been destroyed | 193 // doesn't have to be destroyed. We just care that it hasn't been destroyed |
| 197 // before now. | 194 // before now. |
| 198 destruction_observer_ = nullptr; | 195 destruction_observer_ = nullptr; |
| 199 EXPECT_CALL(client_, UseSurfaceTexture()); | 196 EXPECT_CALL(client_, UseSurfaceTexture()); |
| 200 overlay_callbacks_.OverlayFailed.Run(); | 197 overlay_callbacks_.OverlayFailed.Run(); |
| 201 } | 198 } |
| 202 | 199 |
| 203 TEST_F(AndroidVideoSurfaceChooserImplTest, | |
| 204 OnSurfaceDestroyedSendsNotification) { | |
| 205 // If |chooser_| is notified about OnSurfaceDestroyed, then |client_| should | |
| 206 // also be notified. | |
| 207 | |
| 208 EXPECT_CALL(*this, MockOnOverlayCreated()); | |
| 209 StartChooser(FactoryFor(std::move(overlay_))); | |
| 210 EXPECT_CALL(client_, UseOverlay(NotNull())); | |
| 211 overlay_callbacks_.OverlayReady.Run(); | |
| 212 | |
| 213 testing::Mock::VerifyAndClearExpectations(&client_); | |
| 214 testing::Mock::VerifyAndClearExpectations(this); | |
| 215 | |
| 216 // Switch to a surface texture. OnSurfaceDestroyed should still be sent. | |
| 217 EXPECT_CALL(client_, UseSurfaceTexture()); | |
| 218 chooser_->ReplaceOverlayFactory(AndroidOverlayFactoryCB()); | |
| 219 testing::Mock::VerifyAndClearExpectations(&client_); | |
| 220 | |
| 221 EXPECT_CALL(client_, StopUsingOverlayImmediately(NotNull())); | |
| 222 overlay_callbacks_.SurfaceDestroyed.Run(); | |
| 223 } | |
| 224 | |
| 225 TEST_F(AndroidVideoSurfaceChooserImplTest, | |
| 226 OnSurfaceDestroyedSendsNotificationAfterSwitch) { | |
| 227 // This tests two things. First: | |
| 228 // If |chooser_| is notified about OnSurfaceDestroyed, then |client_| should | |
| 229 // also be notified even if |chooser_| has already told |client_| to | |
| 230 // transition to SurfaceTexture. It has no idea if |client_| has actually | |
| 231 // transitioned, so it has to notify it to stop immediately, in case it | |
| 232 // hasn't. Second: |chooser_| should notify |client_| to switch to surface | |
| 233 // texture if it provided an overlay, and the factory is changed. This | |
| 234 // indicates that whoever provided the factory is revoking it, so we shouldn't | |
| 235 // be using overlays from that factory anymore. We specifically test overlay | |
| 236 // => no factory, since |chooser_| could elide multiple calls to switch to | |
| 237 // surface texture. | |
| 238 // | |
| 239 // We test these together, since switching the factory is the only way we have | |
| 240 // to make |chooser_| transition to SurfaceTexture without sending destroyed. | |
| 241 | |
| 242 EXPECT_CALL(*this, MockOnOverlayCreated()); | |
| 243 StartChooser(FactoryFor(std::move(overlay_))); | |
| 244 EXPECT_CALL(client_, UseOverlay(NotNull())); | |
| 245 overlay_callbacks_.OverlayReady.Run(); | |
| 246 | |
| 247 testing::Mock::VerifyAndClearExpectations(&client_); | |
| 248 testing::Mock::VerifyAndClearExpectations(this); | |
| 249 | |
| 250 // Switch factories, to notify the client back to switch to SurfaceTexture. | |
| 251 EXPECT_CALL(client_, UseSurfaceTexture()); | |
| 252 chooser_->ReplaceOverlayFactory(AndroidOverlayFactoryCB()); | |
| 253 testing::Mock::VerifyAndClearExpectations(&client_); | |
| 254 | |
| 255 // Destroy the original surface. | |
| 256 EXPECT_CALL(client_, StopUsingOverlayImmediately(NotNull())); | |
| 257 overlay_callbacks_.SurfaceDestroyed.Run(); | |
| 258 } | |
| 259 | |
| 260 TEST_F(AndroidVideoSurfaceChooserImplTest, NullLaterOverlayUsesSurfaceTexture) { | 200 TEST_F(AndroidVideoSurfaceChooserImplTest, NullLaterOverlayUsesSurfaceTexture) { |
| 261 // If an overlay factory is provided after startup that returns a null overlay | 201 // If an overlay factory is provided after startup that returns a null overlay |
| 262 // from CreateOverlay, |chooser_| should, at most, notify |client_| to use | 202 // from CreateOverlay, |chooser_| should, at most, notify |client_| to use |
| 263 // SurfaceTexture zero or more times. | 203 // SurfaceTexture zero or more times. |
| 264 | 204 |
| 265 // Start with SurfaceTexture. | 205 // Start with SurfaceTexture. |
| 266 EXPECT_CALL(client_, UseSurfaceTexture()); | 206 EXPECT_CALL(client_, UseSurfaceTexture()); |
| 267 StartChooser(AndroidOverlayFactoryCB()); | 207 StartChooser(AndroidOverlayFactoryCB()); |
| 268 testing::Mock::VerifyAndClearExpectations(&client_); | 208 testing::Mock::VerifyAndClearExpectations(&client_); |
| 269 | 209 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 chooser_->ReplaceOverlayFactory(FactoryFor(std::move(overlay_))); | 252 chooser_->ReplaceOverlayFactory(FactoryFor(std::move(overlay_))); |
| 313 testing::Mock::VerifyAndClearExpectations(&client_); | 253 testing::Mock::VerifyAndClearExpectations(&client_); |
| 314 testing::Mock::VerifyAndClearExpectations(this); | 254 testing::Mock::VerifyAndClearExpectations(this); |
| 315 | 255 |
| 316 // Notify |chooser_| that the overlay is ready. | 256 // Notify |chooser_| that the overlay is ready. |
| 317 EXPECT_CALL(client_, UseOverlay(NotNull())); | 257 EXPECT_CALL(client_, UseOverlay(NotNull())); |
| 318 overlay_callbacks_.OverlayReady.Run(); | 258 overlay_callbacks_.OverlayReady.Run(); |
| 319 } | 259 } |
| 320 | 260 |
| 321 } // namespace media | 261 } // namespace media |
| OLD | NEW |