Files
video-v1/vav2/platforms/windows/tests/integration/Program.cs

278 lines
10 KiB
C#
Raw Normal View History

using System;
using VavCore.Wrapper;
using VavCoreClass = VavCore.Wrapper.VavCore;
namespace VavCoreTest;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("=== VavCore.Wrapper P/Invoke Test ===");
Console.WriteLine();
// Test 1: Library Initialization
Console.WriteLine("Test 1: Library Initialization");
try
{
bool initialized = VavCoreClass.Initialize();
Console.WriteLine($" VavCore.Initialize(): {(initialized ? "SUCCESS" : "FAILED")}");
}
catch (Exception ex)
{
Console.WriteLine($" ERROR: {ex.Message}");
Console.WriteLine($" Exception Type: {ex.GetType().Name}");
if (ex.InnerException != null)
{
Console.WriteLine($" Inner Exception: {ex.InnerException.Message}");
}
}
Console.WriteLine();
// Test 2: Version Information
Console.WriteLine("Test 2: Version Information");
try
{
string version = VavCoreClass.GetVersion();
Console.WriteLine($" VavCore Version: {version}");
}
catch (Exception ex)
{
Console.WriteLine($" ERROR getting version: {ex.Message}");
}
Console.WriteLine();
// Test 3: Platform Information
Console.WriteLine("Test 3: Platform Information");
try
{
var optimalDecoder = VavCoreClass.GetOptimalDecoderType();
Console.WriteLine($" Optimal Decoder: {optimalDecoder}");
}
catch (Exception ex)
{
Console.WriteLine($" ERROR getting platform info: {ex.Message}");
}
Console.WriteLine();
// Test 4: Player Creation and Basic Operations
Console.WriteLine("Test 4: Player Creation and Basic Operations");
VavCoreClass? player = null;
try
{
player = new VavCoreClass();
Console.WriteLine(" Player created successfully");
// Test basic properties
Console.WriteLine($" Player is open: {player.IsOpen}");
Console.WriteLine($" Player is end of file: {player.IsEndOfFile}");
// Test decoder configuration
bool decoderSet = player.SetDecoderType(VavCoreClass.DecoderType.Auto);
Console.WriteLine($" Set Auto decoder: {(decoderSet ? "SUCCESS" : "FAILED")}");
bool qualitySet = player.SetQualityMode(VavCoreClass.QualityMode.Fast);
Console.WriteLine($" Set Fast quality mode: {(qualitySet ? "SUCCESS" : "FAILED")}");
}
catch (Exception ex)
{
Console.WriteLine($" ERROR creating player: {ex.Message}");
if (ex.InnerException != null)
{
Console.WriteLine($" Inner Exception: {ex.InnerException.Message}");
}
}
Console.WriteLine();
// Test 5: File Operations (if test file exists)
Console.WriteLine("Test 5: File Operations");
if (player != null)
{
try
{
// Try common test file paths
string[] testFiles = {
@"D:\Project\video-av1\sample\output.webm",
2025-09-28 09:13:03 +09:00
@"D:\Project\video-av1\sample\simple_test.webm",
@"sample.webm",
@"test.webm"
};
bool fileOpened = false;
string usedFile = "";
foreach (string testFile in testFiles)
{
if (System.IO.File.Exists(testFile))
{
Console.WriteLine($" Attempting to open: {testFile}");
fileOpened = player.OpenFile(testFile);
if (fileOpened)
{
usedFile = testFile;
Console.WriteLine($" File opened successfully: {testFile}");
break;
}
else
{
Console.WriteLine($" Failed to open: {testFile}");
}
}
}
if (!fileOpened)
{
Console.WriteLine(" No test files found or could be opened");
}
else
{
// Test metadata
if (player.GetMetadata(out var metadata))
{
Console.WriteLine($" Video Resolution: {metadata.Width}x{metadata.Height}");
Console.WriteLine($" Frame Rate: {metadata.FrameRate:F2} fps");
Console.WriteLine($" Duration: {metadata.DurationSeconds:F2} seconds");
Console.WriteLine($" Total Frames: {metadata.TotalFrames}");
}
else
{
Console.WriteLine(" Failed to get metadata");
}
// Test frame decoding
Console.WriteLine(" Testing frame decoding:");
int frameCount = 0;
2025-09-28 09:13:03 +09:00
for (int i = 0; i < 20; i++)
{
if (player.DecodeNextFrame(out var frame))
{
frameCount++;
Console.WriteLine($" Frame {frameCount}: {frame.Width}x{frame.Height}, " +
$"Timestamp: {frame.TimestampSeconds:F3}s");
}
else
{
Console.WriteLine($" Failed to decode frame {i + 1}");
break;
}
if (player.IsEndOfFile)
{
Console.WriteLine(" Reached end of file");
break;
}
}
// Test seeking
Console.WriteLine(" Testing seek functionality:");
if (player.Reset())
{
Console.WriteLine(" Reset to beginning: SUCCESS");
}
else
{
Console.WriteLine(" Reset to beginning: FAILED");
}
if (player.SeekToTime(1.0))
{
Console.WriteLine(" Seek to 1.0 seconds: SUCCESS");
if (player.DecodeNextFrame(out var seekFrame))
{
Console.WriteLine($" Frame after seek: Timestamp {seekFrame.TimestampSeconds:F3}s");
}
}
else
{
Console.WriteLine(" Seek to 1.0 seconds: FAILED");
}
// Test performance metrics
if (player.GetPerformanceMetrics(out var metrics))
{
Console.WriteLine(" Performance Metrics:");
Console.WriteLine($" Frames Decoded: {metrics.FramesDecoded}");
Console.WriteLine($" Frames Dropped: {metrics.FramesDropped}");
Console.WriteLine($" Average Decode Time: {metrics.AverageDecodeTimeMs:F2}ms");
Console.WriteLine($" Current FPS: {metrics.CurrentFps:F2}");
Console.WriteLine($" Quality Level: {metrics.CurrentQualityLevel}");
}
// Test user-friendly helpers
Console.WriteLine(" Video Info Dictionary:");
var videoInfo = player.GetVideoInfo();
foreach (var kvp in videoInfo)
{
Console.WriteLine($" {kvp.Key}: {kvp.Value}");
}
Console.WriteLine(" Stats Dictionary:");
var stats = player.GetStats();
foreach (var kvp in stats)
{
Console.WriteLine($" {kvp.Key}: {kvp.Value}");
}
// Close file
player.CloseFile();
Console.WriteLine(" File closed successfully");
}
}
catch (Exception ex)
{
Console.WriteLine($" ERROR in file operations: {ex.Message}");
if (ex.InnerException != null)
{
Console.WriteLine($" Inner Exception: {ex.InnerException.Message}");
}
}
}
Console.WriteLine();
// Test 6: Surface Types
Console.WriteLine("Test 6: Surface Types");
try
{
Console.WriteLine(" Available Surface Types:");
var surfaceTypes = Enum.GetValues<VavCoreClass.SurfaceType>();
foreach (var surfaceType in surfaceTypes)
{
Console.WriteLine($" {surfaceType} = {(int)surfaceType}");
}
Console.WriteLine(" Available Decoder Types:");
var decoderTypes = Enum.GetValues<VavCoreClass.DecoderType>();
foreach (var decoderType in decoderTypes)
{
Console.WriteLine($" {decoderType} = {(int)decoderType}");
}
Console.WriteLine(" Available Quality Modes:");
var qualityModes = Enum.GetValues<VavCoreClass.QualityMode>();
foreach (var qualityMode in qualityModes)
{
Console.WriteLine($" {qualityMode} = {(int)qualityMode}");
}
}
catch (Exception ex)
{
Console.WriteLine($" ERROR listing enums: {ex.Message}");
}
Console.WriteLine();
// Test 7: Cleanup
Console.WriteLine("Test 7: Cleanup");
try
{
player?.Dispose();
Console.WriteLine(" Player disposed successfully");
}
catch (Exception ex)
{
Console.WriteLine($" ERROR during disposal: {ex.Message}");
}
Console.WriteLine();
Console.WriteLine("=== VavCore.Wrapper Test Completed ===");
}
}