| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_decode_accelerator.h" | 5 #include "media/gpu/android_video_decode_accelerator.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 MOCK_METHOD0(MockReplaceOverlayFactory, void()); | 244 MOCK_METHOD0(MockReplaceOverlayFactory, void()); |
| 245 | 245 |
| 246 // We guarantee that we'll only clear this during destruction, so that you | 246 // We guarantee that we'll only clear this during destruction, so that you |
| 247 // may treat it as "pointer that lasts as long as |this| does". | 247 // may treat it as "pointer that lasts as long as |this| does". |
| 248 base::WeakPtr<FakeOverlayChooser> GetWeakPtrForTesting() { | 248 base::WeakPtr<FakeOverlayChooser> GetWeakPtrForTesting() { |
| 249 return weak_factory_.GetWeakPtr(); | 249 return weak_factory_.GetWeakPtr(); |
| 250 } | 250 } |
| 251 | 251 |
| 252 void Initialize(UseOverlayCB use_overlay_cb, | 252 void Initialize(UseOverlayCB use_overlay_cb, |
| 253 UseSurfaceTextureCB use_surface_texture_cb, | 253 UseSurfaceTextureCB use_surface_texture_cb, |
| 254 StopUsingOverlayImmediatelyCB stop_immediately_cb, | |
| 255 AndroidOverlayFactoryCB initial_factory) override { | 254 AndroidOverlayFactoryCB initial_factory) override { |
| 256 MockInitialize(); | 255 MockInitialize(); |
| 257 | 256 |
| 258 factory_ = std::move(initial_factory); | 257 factory_ = std::move(initial_factory); |
| 259 use_overlay_cb_ = std::move(use_overlay_cb); | 258 use_overlay_cb_ = std::move(use_overlay_cb); |
| 260 use_surface_texture_cb_ = std::move(use_surface_texture_cb); | 259 use_surface_texture_cb_ = std::move(use_surface_texture_cb); |
| 261 stop_immediately_cb_ = std::move(stop_immediately_cb); | |
| 262 } | 260 } |
| 263 | 261 |
| 264 void ReplaceOverlayFactory(AndroidOverlayFactoryCB factory) override { | 262 void ReplaceOverlayFactory(AndroidOverlayFactoryCB factory) override { |
| 265 MockReplaceOverlayFactory(); | 263 MockReplaceOverlayFactory(); |
| 266 factory_ = std::move(factory); | 264 factory_ = std::move(factory); |
| 267 } | 265 } |
| 268 | 266 |
| 269 // Notify AVDA to use a surface texture. | 267 // Notify AVDA to use a surface texture. |
| 270 void ProvideSurfaceTexture() { | 268 void ProvideSurfaceTexture() { |
| 271 use_surface_texture_cb_.Run(); | 269 use_surface_texture_cb_.Run(); |
| 272 base::RunLoop().RunUntilIdle(); | 270 base::RunLoop().RunUntilIdle(); |
| 273 } | 271 } |
| 274 | 272 |
| 275 void ProvideOverlay(std::unique_ptr<AndroidOverlay> overlay) { | 273 void ProvideOverlay(std::unique_ptr<AndroidOverlay> overlay) { |
| 276 use_overlay_cb_.Run(std::move(overlay)); | 274 use_overlay_cb_.Run(std::move(overlay)); |
| 277 base::RunLoop().RunUntilIdle(); | 275 base::RunLoop().RunUntilIdle(); |
| 278 } | 276 } |
| 279 | 277 |
| 280 void StopImmediately(AndroidOverlay* overlay) { | |
| 281 stop_immediately_cb_.Run(overlay); | |
| 282 base::RunLoop().RunUntilIdle(); | |
| 283 } | |
| 284 | |
| 285 UseOverlayCB use_overlay_cb_; | 278 UseOverlayCB use_overlay_cb_; |
| 286 UseSurfaceTextureCB use_surface_texture_cb_; | 279 UseSurfaceTextureCB use_surface_texture_cb_; |
| 287 StopUsingOverlayImmediatelyCB stop_immediately_cb_; | |
| 288 | 280 |
| 289 AndroidOverlayFactoryCB factory_; | 281 AndroidOverlayFactoryCB factory_; |
| 290 | 282 |
| 291 base::WeakPtrFactory<FakeOverlayChooser> weak_factory_; | 283 base::WeakPtrFactory<FakeOverlayChooser> weak_factory_; |
| 292 | 284 |
| 293 private: | 285 private: |
| 294 DISALLOW_COPY_AND_ASSIGN(FakeOverlayChooser); | 286 DISALLOW_COPY_AND_ASSIGN(FakeOverlayChooser); |
| 295 }; | 287 }; |
| 296 | 288 |
| 297 } // namespace | 289 } // namespace |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 void InitializeAVDAWithOverlay() { | 339 void InitializeAVDAWithOverlay() { |
| 348 config_.surface_id = 123; | 340 config_.surface_id = 123; |
| 349 ASSERT_TRUE(InitializeAVDA()); | 341 ASSERT_TRUE(InitializeAVDA()); |
| 350 base::RunLoop().RunUntilIdle(); | 342 base::RunLoop().RunUntilIdle(); |
| 351 ASSERT_TRUE(chooser_->factory_); | 343 ASSERT_TRUE(chooser_->factory_); |
| 352 | 344 |
| 353 // Have the factory provide an overlay, and verify that codec creation is | 345 // Have the factory provide an overlay, and verify that codec creation is |
| 354 // provided with that overlay. | 346 // provided with that overlay. |
| 355 std::unique_ptr<MockAndroidOverlay> overlay = | 347 std::unique_ptr<MockAndroidOverlay> overlay = |
| 356 base::MakeUnique<MockAndroidOverlay>(); | 348 base::MakeUnique<MockAndroidOverlay>(); |
| 349 overlay_callbacks_ = overlay->GetCallbacks(); |
| 350 |
| 357 // Set the expectations first, since ProvideOverlay might cause callbacks. | 351 // Set the expectations first, since ProvideOverlay might cause callbacks. |
| 358 EXPECT_CALL(codec_allocator_, | 352 EXPECT_CALL(codec_allocator_, |
| 359 MockCreateMediaCodecAsync(overlay.get(), nullptr)); | 353 MockCreateMediaCodecAsync(overlay.get(), nullptr)); |
| 360 chooser_->ProvideOverlay(std::move(overlay)); | 354 chooser_->ProvideOverlay(std::move(overlay)); |
| 361 | 355 |
| 362 // Provide the codec so that we can check if it's freed properly. | 356 // Provide the codec so that we can check if it's freed properly. |
| 363 EXPECT_CALL(client_, NotifyInitializationComplete(true)); | 357 EXPECT_CALL(client_, NotifyInitializationComplete(true)); |
| 364 codec_allocator_.ProvideMockCodecAsync(); | 358 codec_allocator_.ProvideMockCodecAsync(); |
| 365 base::RunLoop().RunUntilIdle(); | 359 base::RunLoop().RunUntilIdle(); |
| 366 } | 360 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 scoped_refptr<gl::GLSurface> surface_; | 397 scoped_refptr<gl::GLSurface> surface_; |
| 404 scoped_refptr<gl::GLContext> context_; | 398 scoped_refptr<gl::GLContext> context_; |
| 405 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 399 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
| 406 NiceMock<gpu::gles2::MockGLES2Decoder> gl_decoder_; | 400 NiceMock<gpu::gles2::MockGLES2Decoder> gl_decoder_; |
| 407 NiceMock<MockVDAClient> client_; | 401 NiceMock<MockVDAClient> client_; |
| 408 FakeCodecAllocator codec_allocator_; | 402 FakeCodecAllocator codec_allocator_; |
| 409 VideoDecodeAccelerator::Config config_; | 403 VideoDecodeAccelerator::Config config_; |
| 410 | 404 |
| 411 AndroidVideoDecodeAccelerator::PlatformConfig platform_config_; | 405 AndroidVideoDecodeAccelerator::PlatformConfig platform_config_; |
| 412 | 406 |
| 407 // Set by InitializeAVDAWithOverlay() |
| 408 MockAndroidOverlay::Callbacks overlay_callbacks_; |
| 409 |
| 413 // We maintain a weak ref to this since AVDA owns it. | 410 // We maintain a weak ref to this since AVDA owns it. |
| 414 base::WeakPtr<FakeOverlayChooser> chooser_; | 411 base::WeakPtr<FakeOverlayChooser> chooser_; |
| 415 | 412 |
| 416 // This must be a unique pointer to a VDA, not an AVDA, to ensure the | 413 // This must be a unique pointer to a VDA, not an AVDA, to ensure the |
| 417 // the default_delete specialization that calls Destroy() will be used. | 414 // the default_delete specialization that calls Destroy() will be used. |
| 418 std::unique_ptr<VideoDecodeAccelerator> vda_; | 415 std::unique_ptr<VideoDecodeAccelerator> vda_; |
| 419 | 416 |
| 420 AndroidVideoDecodeAccelerator* avda() { | 417 AndroidVideoDecodeAccelerator* avda() { |
| 421 return reinterpret_cast<AndroidVideoDecodeAccelerator*>(vda_.get()); | 418 return reinterpret_cast<AndroidVideoDecodeAccelerator*>(vda_.get()); |
| 422 } | 419 } |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 SKIP_IF_MEDIACODEC_IS_NOT_AVAILABLE(); | 544 SKIP_IF_MEDIACODEC_IS_NOT_AVAILABLE(); |
| 548 | 545 |
| 549 InitializeAVDAWithOverlay(); | 546 InitializeAVDAWithOverlay(); |
| 550 | 547 |
| 551 // It would be nice if we knew that this was a surface texture. As it is, we | 548 // It would be nice if we knew that this was a surface texture. As it is, we |
| 552 // just destroy the VDA and expect that we're provided with one. Hopefully, | 549 // just destroy the VDA and expect that we're provided with one. Hopefully, |
| 553 // AVDA is actually calling SetSurface properly. | 550 // AVDA is actually calling SetSurface properly. |
| 554 EXPECT_CALL(*codec_allocator_.most_recent_codec(), SetSurface(_)) | 551 EXPECT_CALL(*codec_allocator_.most_recent_codec(), SetSurface(_)) |
| 555 .WillOnce(Return(true)); | 552 .WillOnce(Return(true)); |
| 556 codec_allocator_.codec_destruction_observer()->DestructionIsOptional(); | 553 codec_allocator_.codec_destruction_observer()->DestructionIsOptional(); |
| 557 chooser_->StopImmediately(codec_allocator_.most_recent_overlay()); | 554 overlay_callbacks_.SurfaceDestroyed.Run(); |
| 555 base::RunLoop().RunUntilIdle(); |
| 558 | 556 |
| 559 EXPECT_CALL(codec_allocator_, | 557 EXPECT_CALL(codec_allocator_, |
| 560 MockReleaseMediaCodec(codec_allocator_.most_recent_codec(), | 558 MockReleaseMediaCodec(codec_allocator_.most_recent_codec(), |
| 561 nullptr, NotNull())); | 559 nullptr, NotNull())); |
| 562 vda_ = nullptr; | 560 vda_ = nullptr; |
| 563 base::RunLoop().RunUntilIdle(); | 561 base::RunLoop().RunUntilIdle(); |
| 564 } | 562 } |
| 565 | 563 |
| 566 TEST_F(AndroidVideoDecodeAcceleratorTest, SwitchesToSurfaceTextureEventually) { | 564 TEST_F(AndroidVideoDecodeAcceleratorTest, SwitchesToSurfaceTextureEventually) { |
| 567 // Provide a surface, and a codec, then request that AVDA switches to a | 565 // Provide a surface, and a codec, then request that AVDA switches to a |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 platform_config_.allow_setsurface = false; | 662 platform_config_.allow_setsurface = false; |
| 665 InitializeAVDAWithOverlay(); | 663 InitializeAVDAWithOverlay(); |
| 666 EXPECT_CALL(*codec_allocator_.most_recent_codec(), SetSurface(_)).Times(0); | 664 EXPECT_CALL(*codec_allocator_.most_recent_codec(), SetSurface(_)).Times(0); |
| 667 | 665 |
| 668 // This should free the codec. | 666 // This should free the codec. |
| 669 EXPECT_CALL( | 667 EXPECT_CALL( |
| 670 codec_allocator_, | 668 codec_allocator_, |
| 671 MockReleaseMediaCodec(codec_allocator_.most_recent_codec(), | 669 MockReleaseMediaCodec(codec_allocator_.most_recent_codec(), |
| 672 codec_allocator_.most_recent_overlay(), nullptr)); | 670 codec_allocator_.most_recent_overlay(), nullptr)); |
| 673 codec_allocator_.codec_destruction_observer()->ExpectDestruction(); | 671 codec_allocator_.codec_destruction_observer()->ExpectDestruction(); |
| 674 chooser_->StopImmediately(codec_allocator_.most_recent_overlay()); | 672 overlay_callbacks_.SurfaceDestroyed.Run(); |
| 675 base::RunLoop().RunUntilIdle(); | 673 base::RunLoop().RunUntilIdle(); |
| 676 | 674 |
| 677 // Verify that the codec has been released, since |vda_| will be destroyed | 675 // Verify that the codec has been released, since |vda_| will be destroyed |
| 678 // soon. The expectations must be met before that. | 676 // soon. The expectations must be met before that. |
| 679 testing::Mock::VerifyAndClearExpectations(&codec_allocator_); | 677 testing::Mock::VerifyAndClearExpectations(&codec_allocator_); |
| 680 codec_allocator_.codec_destruction_observer()->DestructionIsOptional(); | 678 codec_allocator_.codec_destruction_observer()->DestructionIsOptional(); |
| 681 } | 679 } |
| 682 | 680 |
| 683 TEST_F(AndroidVideoDecodeAcceleratorTest, | 681 TEST_F(AndroidVideoDecodeAcceleratorTest, |
| 684 MultipleSurfaceTextureCallbacksAreIgnored) { | 682 MultipleSurfaceTextureCallbacksAreIgnored) { |
| 685 // Ask AVDA to switch to ST when it's already using ST, nothing should happen. | 683 // Ask AVDA to switch to ST when it's already using ST, nothing should happen. |
| 686 SKIP_IF_MEDIACODEC_IS_NOT_AVAILABLE(); | 684 SKIP_IF_MEDIACODEC_IS_NOT_AVAILABLE(); |
| 687 | 685 |
| 688 InitializeAVDAWithSurfaceTexture(); | 686 InitializeAVDAWithSurfaceTexture(); |
| 689 | 687 |
| 690 // This should do nothing. | 688 // This should do nothing. |
| 691 EXPECT_CALL(*codec_allocator_.most_recent_codec(), SetSurface(_)).Times(0); | 689 EXPECT_CALL(*codec_allocator_.most_recent_codec(), SetSurface(_)).Times(0); |
| 692 chooser_->ProvideSurfaceTexture(); | 690 chooser_->ProvideSurfaceTexture(); |
| 693 | 691 |
| 694 base::RunLoop().RunUntilIdle(); | 692 base::RunLoop().RunUntilIdle(); |
| 695 } | 693 } |
| 696 | 694 |
| 697 } // namespace media | 695 } // namespace media |
| OLD | NEW |