Refactoring NVDEC decoder & VideoPlayerControl2
This commit is contained in:
145
vav2/platforms/windows/tests/headless/src/QuickD3DTest.cpp
Normal file
145
vav2/platforms/windows/tests/headless/src/QuickD3DTest.cpp
Normal file
@@ -0,0 +1,145 @@
|
||||
#include <windows.h>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <chrono>
|
||||
#include "VavCore/VavCore.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
SetConsoleCP(CP_UTF8);
|
||||
SetConsoleOutputCP(CP_UTF8);
|
||||
|
||||
std::cout << "=== VavCore D3D11 Surface Decoding Test ===" << std::endl;
|
||||
std::cout << std::endl;
|
||||
|
||||
if (argc < 2) {
|
||||
std::cout << "Usage: " << argv[0] << " <video_file.webm>" << std::endl;
|
||||
std::cout << "Example: " << argv[0] << " D:\\Project\\video-av1\\sample\\simple_test.webm" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string filePath = argv[1];
|
||||
std::cout << "Testing video file: " << filePath << std::endl;
|
||||
std::cout << std::endl;
|
||||
|
||||
// Initialize VavCore
|
||||
std::cout << "[1] Initializing VavCore..." << std::endl;
|
||||
VavCoreResult result = vavcore_initialize();
|
||||
if (result != VAVCORE_SUCCESS) {
|
||||
std::cout << "[ERROR] Failed to initialize VavCore: " << vavcore_get_error_string(result) << std::endl;
|
||||
return 1;
|
||||
}
|
||||
std::cout << "[SUCCESS] VavCore initialized" << std::endl;
|
||||
std::cout << "Version: " << vavcore_get_version_string() << std::endl;
|
||||
std::cout << std::endl;
|
||||
|
||||
// Create player
|
||||
std::cout << "[2] Creating VavCore player..." << std::endl;
|
||||
VavCorePlayer* player = vavcore_create_player();
|
||||
if (!player) {
|
||||
std::cout << "[ERROR] Failed to create player" << std::endl;
|
||||
vavcore_cleanup();
|
||||
return 1;
|
||||
}
|
||||
std::cout << "[SUCCESS] Player created" << std::endl;
|
||||
std::cout << std::endl;
|
||||
|
||||
// Set decoder type to NVDEC
|
||||
std::cout << "[3] Setting decoder type to NVDEC..." << std::endl;
|
||||
result = vavcore_set_decoder_type(player, VAVCORE_DECODER_NVDEC);
|
||||
if (result != VAVCORE_SUCCESS) {
|
||||
std::cout << "[ERROR] Failed to set decoder type: " << vavcore_get_error_string(result) << std::endl;
|
||||
vavcore_destroy_player(player);
|
||||
vavcore_cleanup();
|
||||
return 1;
|
||||
}
|
||||
std::cout << "[SUCCESS] Decoder type set to NVDEC" << std::endl;
|
||||
std::cout << std::endl;
|
||||
|
||||
// Open video file
|
||||
std::cout << "[4] Opening video file..." << std::endl;
|
||||
result = vavcore_open_file(player, filePath.c_str());
|
||||
if (result != VAVCORE_SUCCESS) {
|
||||
std::cout << "[ERROR] Failed to open file: " << vavcore_get_error_string(result) << std::endl;
|
||||
vavcore_destroy_player(player);
|
||||
vavcore_cleanup();
|
||||
return 1;
|
||||
}
|
||||
std::cout << "[SUCCESS] Video file opened" << std::endl;
|
||||
std::cout << std::endl;
|
||||
|
||||
// Get metadata
|
||||
std::cout << "[5] Getting video metadata..." << std::endl;
|
||||
VavCoreVideoMetadata metadata;
|
||||
result = vavcore_get_metadata(player, &metadata);
|
||||
if (result != VAVCORE_SUCCESS) {
|
||||
std::cout << "[ERROR] Failed to get metadata: " << vavcore_get_error_string(result) << std::endl;
|
||||
vavcore_close_file(player);
|
||||
vavcore_destroy_player(player);
|
||||
vavcore_cleanup();
|
||||
return 1;
|
||||
}
|
||||
std::cout << "[SUCCESS] Video metadata:" << std::endl;
|
||||
std::cout << " Resolution: " << metadata.width << "x" << metadata.height << std::endl;
|
||||
std::cout << " FPS: " << std::fixed << std::setprecision(2) << metadata.frame_rate << std::endl;
|
||||
std::cout << " Frames: " << metadata.total_frames << std::endl;
|
||||
std::cout << " Duration: " << std::fixed << std::setprecision(2) << metadata.duration_seconds << "s" << std::endl;
|
||||
std::cout << " Codec: " << metadata.codec_name << std::endl;
|
||||
std::cout << std::endl;
|
||||
|
||||
// Decode first 10 frames (CPU path to verify basic decoding)
|
||||
std::cout << "[6] Decoding first 10 frames (CPU decoding for verification)..." << std::endl;
|
||||
int successCount = 0;
|
||||
int errorCount = 0;
|
||||
|
||||
auto startTime = std::chrono::high_resolution_clock::now();
|
||||
|
||||
for (int i = 0; i < 10 && i < metadata.total_frames; i++) {
|
||||
VavCoreVideoFrame frame = {};
|
||||
result = vavcore_decode_next_frame(player, &frame);
|
||||
|
||||
if (result == VAVCORE_SUCCESS) {
|
||||
successCount++;
|
||||
double timestamp_sec = frame.timestamp_us / 1000000.0;
|
||||
std::cout << " Frame " << (i + 1) << ": SUCCESS"
|
||||
<< " (" << frame.width << "x" << frame.height
|
||||
<< ", timestamp: " << std::fixed << std::setprecision(3) << timestamp_sec << "s)" << std::endl;
|
||||
vavcore_free_frame(&frame);
|
||||
} else {
|
||||
errorCount++;
|
||||
std::cout << " Frame " << (i + 1) << ": FAILED - " << vavcore_get_error_string(result) << std::endl;
|
||||
}
|
||||
|
||||
if (vavcore_is_end_of_file(player)) {
|
||||
std::cout << " End of file reached" << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
auto endTime = std::chrono::high_resolution_clock::now();
|
||||
double totalTime = std::chrono::duration<double, std::milli>(endTime - startTime).count();
|
||||
|
||||
std::cout << std::endl;
|
||||
std::cout << "=== Test Results ===" << std::endl;
|
||||
std::cout << "Success: " << successCount << " frames" << std::endl;
|
||||
std::cout << "Errors: " << errorCount << " frames" << std::endl;
|
||||
std::cout << "Total time: " << std::fixed << std::setprecision(2) << totalTime << "ms" << std::endl;
|
||||
if (successCount > 0) {
|
||||
double avgTime = totalTime / successCount;
|
||||
double fps = 1000.0 / avgTime;
|
||||
std::cout << "Average per frame: " << avgTime << "ms" << std::endl;
|
||||
std::cout << "Achievable FPS: " << std::fixed << std::setprecision(1) << fps << std::endl;
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
std::cout << std::endl;
|
||||
std::cout << "[7] Cleaning up..." << std::endl;
|
||||
vavcore_close_file(player);
|
||||
vavcore_destroy_player(player);
|
||||
vavcore_cleanup();
|
||||
std::cout << "[SUCCESS] Cleanup completed" << std::endl;
|
||||
|
||||
std::cout << std::endl;
|
||||
std::cout << "=== Test " << (errorCount == 0 ? "PASSED" : "FAILED") << " ===" << std::endl;
|
||||
return (errorCount == 0) ? 0 : 1;
|
||||
}
|
||||
Reference in New Issue
Block a user