Files
video-v1/vav2/Vav2Player/Vav2UnitTest/tests/AV1DecoderTest.cpp

213 lines
7.5 KiB
C++
Raw Normal View History

2025-09-23 05:52:19 +09:00
#include "pch.h"
#include "MockWebMFileReader.h"
2025-09-25 21:54:50 +09:00
#include "../../VavCore/src/Decoder/AV1Decoder.h"
#include "../../VavCore/src/Decoder/VideoDecoderFactory.h"
2025-09-23 05:52:19 +09:00
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace Vav2PlayerUnitTests;
namespace Vav2PlayerUnitTests
{
TEST_CLASS(AV1DecoderTest)
{
public:
TEST_METHOD(AV1Decoder_Initialize_ValidMetadata_ShouldReturnTrue)
{
// Arrange
2025-09-25 21:54:50 +09:00
auto decoder = VideoDecoderFactory::CreateDecoder(VideoCodecType::AV1, VideoDecoderFactory::DecoderType::DAV1D);
2025-09-23 05:52:19 +09:00
VideoMetadata metadata;
metadata.width = 1920;
metadata.height = 1080;
metadata.codec_type = VideoCodecType::AV1;
metadata.frame_rate = 30.0;
// Act
bool result = decoder->Initialize(metadata);
// Assert
Assert::IsTrue(result);
Assert::IsTrue(decoder->IsInitialized());
}
TEST_METHOD(AV1Decoder_Initialize_InvalidMetadata_ShouldReturnFalse)
{
// Arrange
2025-09-25 21:54:50 +09:00
auto decoder = VideoDecoderFactory::CreateDecoder(VideoCodecType::AV1, VideoDecoderFactory::DecoderType::DAV1D);
2025-09-23 05:52:19 +09:00
VideoMetadata metadata;
metadata.width = 0; // Invalid width
metadata.height = 1080;
metadata.codec_type = VideoCodecType::AV1;
// Act
bool result = decoder->Initialize(metadata);
// Assert
Assert::IsFalse(result);
Assert::IsFalse(decoder->IsInitialized());
}
TEST_METHOD(VideoDecoderFactory_CreateAV1Decoder_ShouldReturnValidDecoder)
{
// Act
2025-09-25 21:54:50 +09:00
auto decoder = VideoDecoderFactory::CreateDecoder(VideoCodecType::AV1, VideoDecoderFactory::DecoderType::DAV1D);
2025-09-23 05:52:19 +09:00
// Assert
Assert::IsNotNull(decoder.get());
Assert::IsFalse(decoder->IsInitialized()); // Should not be initialized until Initialize() is called
}
TEST_METHOD(VideoDecoderFactory_CreateAutoDecoder_ShouldReturnValidDecoder)
{
// Act
auto decoder = VideoDecoderFactory::CreateDecoder(VideoCodecType::AV1, VideoDecoderFactory::DecoderType::AUTO);
// Assert
Assert::IsNotNull(decoder.get());
Assert::IsFalse(decoder->IsInitialized());
}
TEST_METHOD(AV1Decoder_Reset_AfterInitialization_ShouldSucceed)
{
// Arrange
2025-09-25 21:54:50 +09:00
auto decoder = VideoDecoderFactory::CreateDecoder(VideoCodecType::AV1, VideoDecoderFactory::DecoderType::DAV1D);
2025-09-23 05:52:19 +09:00
VideoMetadata metadata;
metadata.width = 1920;
metadata.height = 1080;
metadata.codec_type = VideoCodecType::AV1;
metadata.frame_rate = 30.0;
decoder->Initialize(metadata);
// Act
bool result = decoder->Reset();
// Assert
Assert::IsTrue(result);
Assert::IsTrue(decoder->IsInitialized()); // Should remain initialized after reset
}
TEST_METHOD(AV1Decoder_Cleanup_ShouldSetNotInitialized)
{
// Arrange
2025-09-25 21:54:50 +09:00
auto decoder = VideoDecoderFactory::CreateDecoder(VideoCodecType::AV1, VideoDecoderFactory::DecoderType::DAV1D);
2025-09-23 05:52:19 +09:00
VideoMetadata metadata;
metadata.width = 1920;
metadata.height = 1080;
metadata.codec_type = VideoCodecType::AV1;
metadata.frame_rate = 30.0;
decoder->Initialize(metadata);
Assert::IsTrue(decoder->IsInitialized());
// Act
decoder->Cleanup();
// Assert
Assert::IsFalse(decoder->IsInitialized());
}
// Note: GetSupportedFormats and GetAvailableDecoders methods don't exist yet
// Commenting out until these methods are implemented
/*
TEST_METHOD(AV1Decoder_GetSupportedFormats_ShouldReturnAV1)
{
// Arrange
2025-09-25 21:54:50 +09:00
auto decoder = VideoDecoderFactory::CreateDecoder(VideoCodecType::AV1, VideoDecoderFactory::DecoderType::DAV1D);
2025-09-23 05:52:19 +09:00
// Act
auto formats = decoder->GetSupportedFormats();
// Assert
Assert::IsTrue(formats.size() > 0);
// Check if AV1 is in the supported formats
bool foundAV1 = false;
for (const auto& format : formats) {
if (format == VideoCodecType::AV1) {
foundAV1 = true;
break;
}
}
Assert::IsTrue(foundAV1);
}
TEST_METHOD(VideoDecoderFactory_GetAvailableDecoders_ShouldIncludeAV1)
{
// Act
auto decoders = VideoDecoderFactory::GetAvailableDecoders();
// Assert
Assert::IsTrue(decoders.size() > 0);
// Check if AV1 decoder info is present
bool foundAV1 = false;
for (const auto& decoderInfo : decoders) {
if (decoderInfo.codec_type == VideoCodecType::AV1) {
foundAV1 = true;
Assert::IsFalse(decoderInfo.name.empty());
break;
}
}
Assert::IsTrue(foundAV1);
}
*/
TEST_METHOD(AV1Decoder_HardwareDecoder_CreationTest)
{
// Act - Try to create hardware decoder (may fail on systems without hardware support)
2025-09-25 21:54:50 +09:00
auto decoder = VideoDecoderFactory::CreateDecoder(VideoCodecType::AV1, VideoDecoderFactory::DecoderType::MEDIA_FOUNDATION);
2025-09-23 05:52:19 +09:00
// Assert - Should either succeed or return nullptr (graceful failure)
// This test mainly verifies that factory doesn't crash
if (decoder) {
// If hardware decoder is available, test basic functionality
VideoMetadata metadata;
metadata.width = 1920;
metadata.height = 1080;
metadata.codec_type = VideoCodecType::AV1;
metadata.frame_rate = 30.0;
// Hardware decoder may fail initialization on systems without support
// This is expected behavior, not a test failure
decoder->Initialize(metadata);
}
// Test passes if we reach here without crashing
Assert::IsTrue(true);
}
TEST_METHOD(AV1Decoder_Integration_WithMockReader)
{
// Arrange
MockWebMFileReader mockReader;
2025-09-25 21:54:50 +09:00
auto decoder = VideoDecoderFactory::CreateDecoder(VideoCodecType::AV1, VideoDecoderFactory::DecoderType::DAV1D);
2025-09-23 05:52:19 +09:00
mockReader.OpenFile("test.webm");
mockReader.SelectVideoTrack(1);
const auto& metadata = mockReader.GetVideoMetadata();
decoder->Initialize(metadata);
// Act - Try to decode first packet
VideoPacket packet;
bool readResult = mockReader.ReadNextPacket(packet);
VideoFrame frame;
bool decodeResult = false;
if (readResult && packet.data && packet.size > 0) {
// Note: This will likely fail with mock data since it's not real AV1
// But the test verifies the integration doesn't crash
decodeResult = decoder->DecodeFrame(packet, frame);
}
// Assert
Assert::IsTrue(readResult); // Mock reader should succeed
Assert::IsTrue(decoder->IsInitialized());
// decodeResult may be false since mock data isn't real AV1 - this is expected
}
};
}