This commit is contained in:
2025-10-13 22:55:54 +09:00
parent 146a861a2e
commit a41983ff65
11 changed files with 832 additions and 132 deletions

View File

@@ -248,4 +248,168 @@ TEST_F(MediaCodecAV1DecoderTest, HardwareAccelerationDetection) {
} else {
SUCCEED() << "Decoder reports software decoding (may be emulator)";
}
}
// Test 13: Async mode support and initialization
TEST_F(MediaCodecAV1DecoderTest, AsyncModeSupport) {
LOGI("Test: AsyncModeSupport");
auto codecs = decoder->GetAvailableCodecs();
if (codecs.empty()) {
GTEST_SKIP() << "No AV1 codecs available for async mode test";
}
// Initialize decoder first
VideoMetadata metadata;
metadata.width = 1920;
metadata.height = 1080;
metadata.frame_rate = 30.0;
metadata.codec_type = VideoCodecType::AV1;
bool initSuccess = decoder->Initialize(metadata);
if (!initSuccess) {
GTEST_SKIP() << "Cannot test async mode without successful initialization";
}
// Check async mode support
bool supportsAsync = decoder->SupportsAsyncMode();
LOGI("Async mode supported: %s", supportsAsync ? "YES" : "NO");
// On API 29+, async mode should be supported
EXPECT_TRUE(supportsAsync) << "Async mode should be supported on API 29+";
SUCCEED() << "Async mode support verified";
}
// Test 14: Async mode enable/disable cycle
TEST_F(MediaCodecAV1DecoderTest, AsyncModeEnableDisableCycle) {
LOGI("Test: AsyncModeEnableDisableCycle");
auto codecs = decoder->GetAvailableCodecs();
if (codecs.empty()) {
GTEST_SKIP() << "No AV1 codecs available for async mode cycle test";
}
// Initialize decoder
VideoMetadata metadata;
metadata.width = 1920;
metadata.height = 1080;
metadata.frame_rate = 30.0;
metadata.codec_type = VideoCodecType::AV1;
bool initSuccess = decoder->Initialize(metadata);
if (!initSuccess) {
GTEST_SKIP() << "Cannot test async mode cycle without successful initialization";
}
if (!decoder->SupportsAsyncMode()) {
GTEST_SKIP() << "Device doesn't support async mode";
}
// Async mode should be enabled during initialization
// Try to disable and re-enable
bool disableSuccess = decoder->EnableAsyncMode(false);
LOGI("Async mode disable: %s", disableSuccess ? "SUCCESS" : "FAILED");
bool enableSuccess = decoder->EnableAsyncMode(true);
LOGI("Async mode enable: %s", enableSuccess ? "SUCCESS" : "FAILED");
EXPECT_TRUE(enableSuccess) << "Should be able to re-enable async mode";
SUCCEED() << "Async mode enable/disable cycle completed";
}
// Test 15: SetVulkanDevice and MediaCodec reconfiguration
TEST_F(MediaCodecAV1DecoderTest, VulkanDeviceReconfiguration) {
LOGI("Test: VulkanDeviceReconfiguration");
auto codecs = decoder->GetAvailableCodecs();
if (codecs.empty()) {
GTEST_SKIP() << "No AV1 codecs available for Vulkan reconfiguration test";
}
// Initialize decoder
VideoMetadata metadata;
metadata.width = 1920;
metadata.height = 1080;
metadata.frame_rate = 30.0;
metadata.codec_type = VideoCodecType::AV1;
bool initSuccess = decoder->Initialize(metadata);
if (!initSuccess) {
GTEST_SKIP() << "Cannot test Vulkan reconfiguration without successful initialization";
}
// Create dummy Vulkan handles (null pointers for testing)
// In real scenario, these would be actual Vulkan objects
void* vk_device = reinterpret_cast<void*>(0x1234);
void* vk_instance = reinterpret_cast<void*>(0x5678);
void* vk_physical_device = reinterpret_cast<void*>(0x9ABC);
// SetVulkanDevice should trigger MediaCodec reconfiguration
// This will internally call:
// 1. CleanupAsyncMode()
// 2. AMediaCodec_stop()
// 3. AMediaCodec_configure() with ImageReader surface
// 4. InitializeAsyncMode() + EnableAsyncMode()
// 5. AMediaCodec_start()
bool vulkanSuccess = decoder->SetVulkanDevice(vk_device, vk_instance, vk_physical_device);
LOGI("SetVulkanDevice result: %s", vulkanSuccess ? "SUCCESS" : "FAILED");
// Note: This may fail on emulators or devices without proper Vulkan support
// The important thing is that it doesn't crash
if (vulkanSuccess) {
SUCCEED() << "Vulkan device set successfully - MediaCodec reconfigured";
} else {
LOGI("Vulkan device setup failed (expected on emulator)");
SUCCEED() << "Vulkan reconfiguration handled gracefully";
}
}
// Test 16: Async callbacks persistence after MediaCodec reconfiguration
TEST_F(MediaCodecAV1DecoderTest, AsyncCallbacksPersistenceAfterReconfiguration) {
LOGI("Test: AsyncCallbacksPersistenceAfterReconfiguration");
auto codecs = decoder->GetAvailableCodecs();
if (codecs.empty()) {
GTEST_SKIP() << "No AV1 codecs available";
}
// Initialize decoder
VideoMetadata metadata;
metadata.width = 1920;
metadata.height = 1080;
metadata.frame_rate = 30.0;
metadata.codec_type = VideoCodecType::AV1;
bool initSuccess = decoder->Initialize(metadata);
if (!initSuccess) {
GTEST_SKIP() << "Cannot test without successful initialization";
}
if (!decoder->SupportsAsyncMode()) {
GTEST_SKIP() << "Device doesn't support async mode";
}
// Verify async mode is active
bool asyncActive1 = decoder->SupportsAsyncMode();
LOGI("Async mode active before reconfiguration: %s", asyncActive1 ? "YES" : "NO");
// Simulate reconfiguration by calling Reset which internally may reconfigure
decoder->Reset();
// Re-initialize
initSuccess = decoder->Initialize(metadata);
if (!initSuccess) {
GTEST_SKIP() << "Cannot test without re-initialization";
}
// Verify async mode is still active after reconfiguration
bool asyncActive2 = decoder->SupportsAsyncMode();
LOGI("Async mode active after reconfiguration: %s", asyncActive2 ? "YES" : "NO");
EXPECT_TRUE(asyncActive2) << "Async mode should persist after reconfiguration";
SUCCEED() << "Async callbacks persistence verified";
}