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