| 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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 vda_.reset(avda); | 178 vda_.reset(avda); |
| 179 | 179 |
| 180 bool result = vda_->Initialize(config_, &client_); | 180 bool result = vda_->Initialize(config_, &client_); |
| 181 base::RunLoop().RunUntilIdle(); | 181 base::RunLoop().RunUntilIdle(); |
| 182 return result; | 182 return result; |
| 183 } | 183 } |
| 184 | 184 |
| 185 // Initialize |vda_|, providing a new surface for it. You may get the surface | 185 // Initialize |vda_|, providing a new surface for it. You may get the surface |
| 186 // by asking |codec_allocator_|. | 186 // by asking |codec_allocator_|. |
| 187 void InitializeAVDAWithOverlay() { | 187 void InitializeAVDAWithOverlay() { |
| 188 config_.surface_id = 123; | 188 config_.overlay_info.surface_id = 123; |
| 189 ASSERT_TRUE(InitializeAVDA()); | 189 ASSERT_TRUE(InitializeAVDA()); |
| 190 base::RunLoop().RunUntilIdle(); | 190 base::RunLoop().RunUntilIdle(); |
| 191 ASSERT_TRUE(chooser_->factory_); | 191 ASSERT_TRUE(chooser_->factory_); |
| 192 | 192 |
| 193 // Have the factory provide an overlay, and verify that codec creation is | 193 // Have the factory provide an overlay, and verify that codec creation is |
| 194 // provided with that overlay. | 194 // provided with that overlay. |
| 195 std::unique_ptr<MockAndroidOverlay> overlay = | 195 std::unique_ptr<MockAndroidOverlay> overlay = |
| 196 base::MakeUnique<MockAndroidOverlay>(); | 196 base::MakeUnique<MockAndroidOverlay>(); |
| 197 overlay_callbacks_ = overlay->GetCallbacks(); | 197 overlay_callbacks_ = overlay->GetCallbacks(); |
| 198 | 198 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 LowEndDevicesSucceedInitWithoutASurface) { | 329 LowEndDevicesSucceedInitWithoutASurface) { |
| 330 // If AVDA decides that we should defer surface creation, then it should | 330 // If AVDA decides that we should defer surface creation, then it should |
| 331 // signal success before we provide a surface. It should still ask for a | 331 // signal success before we provide a surface. It should still ask for a |
| 332 // surface, though. | 332 // surface, though. |
| 333 SKIP_IF_MEDIACODEC_IS_NOT_AVAILABLE(); | 333 SKIP_IF_MEDIACODEC_IS_NOT_AVAILABLE(); |
| 334 | 334 |
| 335 // It would be nicer if we didn't just force this on, since we might do so | 335 // It would be nicer if we didn't just force this on, since we might do so |
| 336 // in a state that AVDA isn't supposed to handle (e.g., if we give it a | 336 // in a state that AVDA isn't supposed to handle (e.g., if we give it a |
| 337 // surface, then it would never decide to defer surface creation). | 337 // surface, then it would never decide to defer surface creation). |
| 338 platform_config_.force_deferred_surface_creation = true; | 338 platform_config_.force_deferred_surface_creation = true; |
| 339 config_.surface_id = SurfaceManager::kNoSurfaceID; | 339 config_.overlay_info.surface_id = SurfaceManager::kNoSurfaceID; |
| 340 | 340 |
| 341 EXPECT_CALL(*chooser_, MockInitialize()).Times(0); | 341 EXPECT_CALL(*chooser_, MockInitialize()).Times(0); |
| 342 EXPECT_CALL(client_, NotifyInitializationComplete(true)); | 342 EXPECT_CALL(client_, NotifyInitializationComplete(true)); |
| 343 | 343 |
| 344 InitializeAVDA(); | 344 InitializeAVDA(); |
| 345 } | 345 } |
| 346 | 346 |
| 347 TEST_F(AndroidVideoDecodeAcceleratorTest, | 347 TEST_F(AndroidVideoDecodeAcceleratorTest, |
| 348 AsyncInitWithSurfaceTextureAndDelete) { | 348 AsyncInitWithSurfaceTextureAndDelete) { |
| 349 // When configuring with a SurfaceTexture and deferred init, we should be | 349 // When configuring with a SurfaceTexture and deferred init, we should be |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 // If we ask AVDA to change to SurfaceTexture should be ignored on platforms | 486 // If we ask AVDA to change to SurfaceTexture should be ignored on platforms |
| 487 // that don't support SetSurface (pre-M or blacklisted). It should also | 487 // that don't support SetSurface (pre-M or blacklisted). It should also |
| 488 // ignore SurfaceTexture => overlay, but we don't check that. | 488 // ignore SurfaceTexture => overlay, but we don't check that. |
| 489 // | 489 // |
| 490 // Also note that there are other probably reasonable things to do (like | 490 // Also note that there are other probably reasonable things to do (like |
| 491 // signal an error), but we want to be sure that it doesn't try to SetSurface. | 491 // signal an error), but we want to be sure that it doesn't try to SetSurface. |
| 492 // We also want to be sure that, if it doesn't signal an error, that it also | 492 // We also want to be sure that, if it doesn't signal an error, that it also |
| 493 // doesn't get confused about which surface is in use. So, we assume that it | 493 // doesn't get confused about which surface is in use. So, we assume that it |
| 494 // doesn't signal an error, and we check that it releases the right surface | 494 // doesn't signal an error, and we check that it releases the right surface |
| 495 // with the codec. | 495 // with the codec. |
| 496 SKIP_IF_MEDIACODEC_IS_NOT_AVAILABLE(); |
| 496 EXPECT_CALL(client_, NotifyError(_)).Times(0); | 497 EXPECT_CALL(client_, NotifyError(_)).Times(0); |
| 497 | 498 |
| 498 platform_config_.allow_setsurface = false; | 499 platform_config_.allow_setsurface = false; |
| 499 InitializeAVDAWithOverlay(); | 500 InitializeAVDAWithOverlay(); |
| 500 EXPECT_CALL(*codec_allocator_.most_recent_codec(), SetSurface(_)).Times(0); | 501 EXPECT_CALL(*codec_allocator_.most_recent_codec(), SetSurface(_)).Times(0); |
| 501 | 502 |
| 502 // This should not switch to SurfaceTexture. | 503 // This should not switch to SurfaceTexture. |
| 503 chooser_->ProvideSurfaceTexture(); | 504 chooser_->ProvideSurfaceTexture(); |
| 504 LetAVDAUpdateSurface(); | 505 LetAVDAUpdateSurface(); |
| 505 } | 506 } |
| 506 | 507 |
| 507 TEST_F(AndroidVideoDecodeAcceleratorTest, | 508 TEST_F(AndroidVideoDecodeAcceleratorTest, |
| 508 OnSurfaceDestroyedWithoutSetSurfaceFreesTheCodec) { | 509 OnSurfaceDestroyedWithoutSetSurfaceFreesTheCodec) { |
| 509 // If AVDA receives OnSurfaceDestroyed without support for SetSurface, then it | 510 // If AVDA receives OnSurfaceDestroyed without support for SetSurface, then it |
| 510 // should free the codec. | 511 // should free the codec. |
| 512 SKIP_IF_MEDIACODEC_IS_NOT_AVAILABLE(); |
| 511 platform_config_.allow_setsurface = false; | 513 platform_config_.allow_setsurface = false; |
| 512 InitializeAVDAWithOverlay(); | 514 InitializeAVDAWithOverlay(); |
| 513 EXPECT_CALL(*codec_allocator_.most_recent_codec(), SetSurface(_)).Times(0); | 515 EXPECT_CALL(*codec_allocator_.most_recent_codec(), SetSurface(_)).Times(0); |
| 514 | 516 |
| 515 // This should free the codec. | 517 // This should free the codec. |
| 516 EXPECT_CALL( | 518 EXPECT_CALL( |
| 517 codec_allocator_, | 519 codec_allocator_, |
| 518 MockReleaseMediaCodec(codec_allocator_.most_recent_codec(), | 520 MockReleaseMediaCodec(codec_allocator_.most_recent_codec(), |
| 519 codec_allocator_.most_recent_overlay(), nullptr)); | 521 codec_allocator_.most_recent_overlay(), nullptr)); |
| 520 codec_allocator_.codec_destruction_observer()->ExpectDestruction(); | 522 codec_allocator_.codec_destruction_observer()->ExpectDestruction(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 534 | 536 |
| 535 InitializeAVDAWithSurfaceTexture(); | 537 InitializeAVDAWithSurfaceTexture(); |
| 536 | 538 |
| 537 // This should do nothing. | 539 // This should do nothing. |
| 538 EXPECT_CALL(*codec_allocator_.most_recent_codec(), SetSurface(_)).Times(0); | 540 EXPECT_CALL(*codec_allocator_.most_recent_codec(), SetSurface(_)).Times(0); |
| 539 chooser_->ProvideSurfaceTexture(); | 541 chooser_->ProvideSurfaceTexture(); |
| 540 | 542 |
| 541 base::RunLoop().RunUntilIdle(); | 543 base::RunLoop().RunUntilIdle(); |
| 542 } | 544 } |
| 543 | 545 |
| 546 TEST_F(AndroidVideoDecodeAcceleratorTest, |
| 547 OverlayInfoWithDuplicateSurfaceIDDoesntChangeTheFactory) { |
| 548 // Send OverlayInfo with duplicate info, and verify that it doesn't change |
| 549 // the factory. |
| 550 SKIP_IF_MEDIACODEC_IS_NOT_AVAILABLE(); |
| 551 InitializeAVDAWithOverlay(); |
| 552 |
| 553 EXPECT_CALL(*chooser_, MockReplaceOverlayFactory()).Times(0); |
| 554 OverlayInfo overlay_info = config_.overlay_info; |
| 555 avda()->SetOverlayInfo(overlay_info); |
| 556 } |
| 557 |
| 558 TEST_F(AndroidVideoDecodeAcceleratorTest, |
| 559 OverlayInfoWithNewSurfaceIDDoesChangeTheFactory) { |
| 560 // Send OverlayInfo with new surface info, and verify that it does change the |
| 561 // overlay factory. |
| 562 SKIP_IF_MEDIACODEC_IS_NOT_AVAILABLE(); |
| 563 InitializeAVDAWithOverlay(); |
| 564 |
| 565 EXPECT_CALL(*chooser_, MockReplaceOverlayFactory()).Times(1); |
| 566 OverlayInfo overlay_info = config_.overlay_info; |
| 567 overlay_info.surface_id++; |
| 568 avda()->SetOverlayInfo(overlay_info); |
| 569 } |
| 570 |
| 544 } // namespace media | 571 } // namespace media |
| OLD | NEW |