From 8c3c9f8ba66a1bbda71efb50c8f7c87476f1bd95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Cerveau?= Date: Tue, 26 Nov 2024 12:48:38 +0100 Subject: [PATCH] Logger: add a log system instead of std::cout Add a logger with level from ERROR to DEBUG --- common/include/Logger.h | 96 +++++++++++++++ .../VkVideoCore/VulkanVideoCapabilities.h | 29 ++--- common/libs/VkCodecUtils/Helpers.h | 13 +- common/libs/VkCodecUtils/ProgramConfig.h | 13 +- .../VkCodecUtils/VulkanComputePipeline.cpp | 2 +- .../libs/VkCodecUtils/VulkanDeviceContext.cpp | 67 +++++------ .../VkCodecUtils/VulkanFilterYuvCompute.cpp | 7 +- common/libs/VkCodecUtils/VulkanFrame.cpp | 69 +++++------ .../VkCodecUtils/VulkanShaderCompiler.cpp | 6 +- .../VkCodecUtils/VulkanVideoProcessor.cpp | 37 +++--- common/libs/VkCodecUtils/VulkanVideoUtils.cpp | 27 +++-- vk_video_encoder/demos/vk-video-enc/Main.cpp | 12 +- .../libs/VkVideoEncoder/VkEncoderConfig.cpp | 34 ++++-- .../libs/VkVideoEncoder/VkEncoderConfig.h | 37 +++--- .../VkVideoEncoder/VkEncoderConfigAV1.cpp | 22 ++-- .../VkVideoEncoder/VkEncoderConfigH264.cpp | 22 ++-- .../VkVideoEncoder/VkEncoderConfigH265.cpp | 51 ++++---- .../libs/VkVideoEncoder/VkEncoderDpbH265.cpp | 9 +- .../libs/VkVideoEncoder/VkVideoEncoder.cpp | 112 +++++++++--------- .../libs/VkVideoEncoder/VkVideoEncoderAV1.cpp | 22 ++-- .../VkVideoEncoder/VkVideoEncoderH264.cpp | 14 +-- .../VkVideoEncoder/VkVideoEncoderH265.cpp | 16 +-- .../VkVideoEncoder/VkVideoGopStructure.cpp | 27 +++-- vk_video_encoder/src/vulkan_video_encoder.cpp | 10 +- .../test/vulkan-video-enc/Main.cpp | 9 +- 25 files changed, 446 insertions(+), 317 deletions(-) create mode 100644 common/include/Logger.h diff --git a/common/include/Logger.h b/common/include/Logger.h new file mode 100644 index 00000000..bbf66f4c --- /dev/null +++ b/common/include/Logger.h @@ -0,0 +1,96 @@ +#ifndef LOGGER_H_ +#define LOGGER_H_ + +#include +#include +#include +#include + +// Enum for log levels +enum LogLevel { + NONE = 0, // Use this to disable logging + ERROR, + WARNING, + INFO, + DEBUG +}; + +#define LOG_S_DEBUG Logger::instance()(LogLevel::DEBUG) +#define LOG_S_INFO Logger::instance()(LogLevel::INFO) +#define LOG_S_WARN Logger::instance()(LogLevel::WARNING) +#define LOG_S_ERROR Logger::instance()(LogLevel::ERROR) + +#define LOG_DEBUG(ARGS ...) Logger::instance().printf(LogLevel::DEBUG, ## ARGS) +#define LOG_INFO(ARGS...) Logger::instance().printf(LogLevel::INFO, ## ARGS) +#define LOG_WARN(ARGS...) Logger::instance().printf(LogLevel::WARNING, ## ARGS) +#define LOG_ERROR(ARGS...) Logger::instance().printf(LogLevel::ERROR, ## ARGS) + +class Logger { +private: + std::ostream& os; // The output stream (e.g., std::cout or std::ofstream) + std::ostream& err; // The error stream (e.g., std::cerr) + LogLevel currentLevel; // Current log level + LogLevel messageLevel; // The log level for the current message + +public: + static Logger &instance () + { + static Logger instance; + return instance; + } + // Constructor to set the output stream and log level (default is INFO) + Logger(std::ostream& outStream = std::cout, std::ostream& errStream = std::cerr, LogLevel level = LogLevel::INFO) + : os(outStream), err(errStream), currentLevel(level), messageLevel(LogLevel::INFO) {} + + // Set the log level for the logger + void setLogLevel(int level) { + if (level > DEBUG) + level = DEBUG; + currentLevel = static_cast(level); + } + + // Set the log level for the current message + Logger& operator()(LogLevel level) { + messageLevel = level; + return *this; + } + + // Overload the << operator for generic types + template + Logger& operator<<(const T& data) { + if (messageLevel <= currentLevel) { + if (messageLevel == ERROR) + err << data; + else + os << data; + } + return *this; + } + + // Overload for stream manipulators (like std::endl) + typedef std::ostream& (*StreamManipulator)(std::ostream&); + Logger& operator<<(StreamManipulator manip) { + if (messageLevel <= currentLevel) { + if (messageLevel == ERROR) + err << manip; + else + os << manip; // Handle std::endl, std::flush, etc. + } + return *this; + } + + void printf(LogLevel level, const char* format, ...) { + if (level <= currentLevel) { + va_list args; + va_start(args, format); + if (level == ERROR) + vfprintf(stderr, format, args); + else + vfprintf(stdout,format, args); + va_end(args); + } + } +}; + + +#endif \ No newline at end of file diff --git a/common/include/VkVideoCore/VulkanVideoCapabilities.h b/common/include/VkVideoCore/VulkanVideoCapabilities.h index 549508a6..67bbce2d 100644 --- a/common/include/VkVideoCore/VulkanVideoCapabilities.h +++ b/common/include/VkVideoCore/VulkanVideoCapabilities.h @@ -22,6 +22,7 @@ #include "VkCodecUtils/VulkanDeviceContext.h" #include "VkCodecUtils/Helpers.h" #include "VkVideoCore/VkVideoCoreProfile.h" +#include "Logger.h" class VulkanVideoCapabilities { @@ -219,24 +220,24 @@ class VulkanVideoCapabilities } if (dumpData) { - std::cout << "\t\t\t" << ((videoProfile.GetCodecType() == VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_KHR) ? "h264" : "h265") << "decode capabilities: " << std::endl; + LOG_S_DEBUG << "\t\t\t" << ((videoProfile.GetCodecType() == VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_KHR) ? "h264" : "h265") << "decode capabilities: " << std::endl; if (pVideoCapabilities->flags & VK_VIDEO_CAPABILITY_SEPARATE_REFERENCE_IMAGES_BIT_KHR) { - std::cout << "\t\t\t" << "Use separate reference images" << std::endl; + LOG_S_DEBUG << "\t\t\t" << "Use separate reference images" << std::endl; } - std::cout << "\t\t\t" << "minBitstreamBufferOffsetAlignment: " << pVideoCapabilities->minBitstreamBufferOffsetAlignment << std::endl; - std::cout << "\t\t\t" << "minBitstreamBufferSizeAlignment: " << pVideoCapabilities->minBitstreamBufferSizeAlignment << std::endl; - std::cout << "\t\t\t" << "pictureAccessGranularity: " << pVideoCapabilities->pictureAccessGranularity.width << " x " << pVideoCapabilities->pictureAccessGranularity.height << std::endl; - std::cout << "\t\t\t" << "minCodedExtent: " << pVideoCapabilities->minCodedExtent.width << " x " << pVideoCapabilities->minCodedExtent.height << std::endl; - std::cout << "\t\t\t" << "maxCodedExtent: " << pVideoCapabilities->maxCodedExtent.width << " x " << pVideoCapabilities->maxCodedExtent.height << std::endl; - std::cout << "\t\t\t" << "maxDpbSlots: " << pVideoCapabilities->maxDpbSlots << std::endl; - std::cout << "\t\t\t" << "maxActiveReferencePictures: " << pVideoCapabilities->maxActiveReferencePictures << std::endl; + LOG_S_DEBUG << "\t\t\t" << "minBitstreamBufferOffsetAlignment: " << pVideoCapabilities->minBitstreamBufferOffsetAlignment << std::endl; + LOG_S_DEBUG << "\t\t\t" << "minBitstreamBufferSizeAlignment: " << pVideoCapabilities->minBitstreamBufferSizeAlignment << std::endl; + LOG_S_DEBUG << "\t\t\t" << "pictureAccessGranularity: " << pVideoCapabilities->pictureAccessGranularity.width << " x " << pVideoCapabilities->pictureAccessGranularity.height << std::endl; + LOG_S_DEBUG << "\t\t\t" << "minCodedExtent: " << pVideoCapabilities->minCodedExtent.width << " x " << pVideoCapabilities->minCodedExtent.height << std::endl; + LOG_S_DEBUG << "\t\t\t" << "maxCodedExtent: " << pVideoCapabilities->maxCodedExtent.width << " x " << pVideoCapabilities->maxCodedExtent.height << std::endl; + LOG_S_DEBUG << "\t\t\t" << "maxDpbSlots: " << pVideoCapabilities->maxDpbSlots << std::endl; + LOG_S_DEBUG << "\t\t\t" << "maxActiveReferencePictures: " << pVideoCapabilities->maxActiveReferencePictures << std::endl; if (videoProfile.GetCodecType() == VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_KHR) { const VkVideoDecodeH264CapabilitiesKHR* pH264DecCapabilities = (VkVideoDecodeH264CapabilitiesKHR*)pVideoDecodeCapabilities->pNext; - std::cout << "\t\t\t" << "maxLevelIdc: " << pH264DecCapabilities->maxLevelIdc << std::endl; - std::cout << "\t\t\t" << "fieldOffsetGranularity: " << pH264DecCapabilities->fieldOffsetGranularity.x << " x " << pH264DecCapabilities->fieldOffsetGranularity.y << std::endl; + LOG_S_DEBUG << "\t\t\t" << "maxLevelIdc: " << pH264DecCapabilities->maxLevelIdc << std::endl; + LOG_S_DEBUG << "\t\t\t" << "fieldOffsetGranularity: " << pH264DecCapabilities->fieldOffsetGranularity.x << " x " << pH264DecCapabilities->fieldOffsetGranularity.y << std::endl; if (strncmp(pVideoCapabilities->stdHeaderVersion.extensionName, VK_STD_VULKAN_VIDEO_CODEC_H264_DECODE_EXTENSION_NAME, @@ -247,7 +248,7 @@ class VulkanVideoCapabilities } } else if (videoProfile.GetCodecType() == VK_VIDEO_CODEC_OPERATION_DECODE_H265_BIT_KHR) { const VkVideoDecodeH265CapabilitiesKHR* pH265DecCapabilities = (VkVideoDecodeH265CapabilitiesKHR*)pVideoDecodeCapabilities->pNext; - std::cout << "\t\t\t" << "maxLevelIdc: " << pH265DecCapabilities->maxLevelIdc << std::endl; + LOG_S_DEBUG << "\t\t\t" << "maxLevelIdc: " << pH265DecCapabilities->maxLevelIdc << std::endl; if (strncmp(pVideoCapabilities->stdHeaderVersion.extensionName, VK_STD_VULKAN_VIDEO_CODEC_H265_DECODE_EXTENSION_NAME, sizeof (pVideoCapabilities->stdHeaderVersion.extensionName) - 1U) || @@ -301,9 +302,9 @@ class VulkanVideoCapabilities result = vkDevCtx->GetPhysicalDeviceVideoFormatPropertiesKHR(vkDevCtx->getPhysicalDevice(), &videoFormatInfo, &supportedFormatCount, pSupportedFormats); assert(result == VK_SUCCESS); if (dumpData) { - std::cout << "\t\t\t" << ((videoProfile.GetCodecType() == VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_KHR) ? "h264" : "h265") << "decode formats: " << std::endl; + LOG_S_DEBUG << "\t\t\t" << ((videoProfile.GetCodecType() == VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_KHR) ? "h264" : "h265") << "decode formats: " << std::endl; for (uint32_t fmt = 0; fmt < supportedFormatCount; fmt++) { - std::cout << "\t\t\t " << fmt << ": " << std::hex << pSupportedFormats[fmt].format << std::dec << std::endl; + LOG_S_DEBUG << "\t\t\t " << fmt << ": " << std::hex << pSupportedFormats[fmt].format << std::dec << std::endl; } } diff --git a/common/libs/VkCodecUtils/Helpers.h b/common/libs/VkCodecUtils/Helpers.h index 5fad9b6b..e4f24265 100644 --- a/common/libs/VkCodecUtils/Helpers.h +++ b/common/libs/VkCodecUtils/Helpers.h @@ -23,6 +23,7 @@ #include #include #include "HelpersDispatchTable.h" +#include "Logger.h" namespace vk { @@ -282,7 +283,7 @@ inline VkResult WaitAndGetStatus(const VkInterfaceFunctions* vkIf, VkDevice devi do { result = WaitAndResetFence(vkIf, device, fence, resetAfterWait, fenceName, fenceWaitTimeout, fenceTotalWaitTimeout); if (result != VK_SUCCESS) { - std::cout << "WaitForFences timeout " << fenceWaitTimeout + LOG_S_WARN << "WaitForFences timeout " << fenceWaitTimeout << " result " << result << " retry " << retryCount << std::endl << std::flush; VkQueryResultStatusKHR decodeStatus = VK_QUERY_RESULT_STATUS_NOT_READY_KHR; @@ -295,19 +296,19 @@ inline VkResult WaitAndGetStatus(const VkInterfaceFunctions* vkIf, VkDevice devi sizeof(decodeStatus), VK_QUERY_RESULT_WITH_STATUS_BIT_KHR); - printf("\nERROR: GetQueryPoolResults() result: 0x%x\n", queryResult); - std::cout << "\t +++++++++++++++++++++++++++< " << pictureIndex + LOG_ERROR("\nERROR: GetQueryPoolResults() result: 0x%x\n", queryResult); + LOG_S_WARN << "\t +++++++++++++++++++++++++++< " << pictureIndex << " >++++++++++++++++++++++++++++++" << std::endl; - std::cout << "\t => Decode Status for CurrPicIdx: " << pictureIndex << std::endl + LOG_S_WARN << "\t => Decode Status for CurrPicIdx: " << pictureIndex << std::endl << "\t\tdecodeStatus: " << decodeStatus << std::endl; if (queryResult == VK_ERROR_DEVICE_LOST) { - std::cout << "\t Dropping frame" << std::endl; + LOG_S_WARN << "\t Dropping frame" << std::endl; break; } if ((queryResult == VK_SUCCESS) && (decodeStatus == VK_QUERY_RESULT_STATUS_ERROR_KHR)) { - std::cout << "\t Decoding of the frame failed." << std::endl; + LOG_S_ERROR << "\t Decoding of the frame failed." << std::endl; break; } } diff --git a/common/libs/VkCodecUtils/ProgramConfig.h b/common/libs/VkCodecUtils/ProgramConfig.h index 04e0e573..b5bcfe63 100644 --- a/common/libs/VkCodecUtils/ProgramConfig.h +++ b/common/libs/VkCodecUtils/ProgramConfig.h @@ -26,9 +26,10 @@ #include #include #include -#include +#include #include #include "vulkan_interfaces.h" +#include "Logger.h" struct ProgramConfig { @@ -83,7 +84,7 @@ struct ProgramConfig { } using ProgramArgs = std::vector; - static bool showHelp(const char ** argv, const ProgramArgs &spec) { + static bool showHelp(const char ** argv, const ProgramArgs &spec) { std::cout << argv[0] << std::endl; for ( auto& flag : spec ) { std::stringstream ss; @@ -112,6 +113,12 @@ struct ProgramConfig { exit(EXIT_SUCCESS); return rtn; }}, + {"--logLevel", "-l", 1, "Set the log level", + [this](const char **args, const ProgramArgs &a) { + int logLevel = std::atoi(args[0]); + Logger::instance().setLogLevel(logLevel); + return true; + }}, {"--enableStrDemux", nullptr, 0, "Enable stream demuxing", [this](const char **, const ProgramArgs &a) { enableStreamDemuxing = true; @@ -347,7 +354,7 @@ struct ProgramConfig { std::cerr << "Missing arguments for \"" << argv[i] << "\"" << std::endl; exit(EXIT_FAILURE); } - disableValueCheck = true; + disableValueCheck = true; i++; } diff --git a/common/libs/VkCodecUtils/VulkanComputePipeline.cpp b/common/libs/VkCodecUtils/VulkanComputePipeline.cpp index 1763883b..dfd78fe8 100644 --- a/common/libs/VkCodecUtils/VulkanComputePipeline.cpp +++ b/common/libs/VkCodecUtils/VulkanComputePipeline.cpp @@ -45,7 +45,7 @@ VkResult VulkanComputePipeline::CreatePipeline(const VulkanDeviceContext* vkDevC const bool verbose = false; - if (verbose) printf("\nCompute shader code:\n %s", shaderCode); + if (verbose) LOG_DEBUG("\nCompute shader code:\n %s", shaderCode); DestroyShaderModule(); m_shaderModule = shaderCompiler.BuildGlslShader(shaderCode, diff --git a/common/libs/VkCodecUtils/VulkanDeviceContext.cpp b/common/libs/VkCodecUtils/VulkanDeviceContext.cpp index e31a0d81..480505f0 100644 --- a/common/libs/VkCodecUtils/VulkanDeviceContext.cpp +++ b/common/libs/VkCodecUtils/VulkanDeviceContext.cpp @@ -30,6 +30,7 @@ #include // std::find_if #include "VkCodecUtils/Helpers.h" #include "VkCodecUtils/VulkanDeviceContext.h" +#include "Logger.h" #if !defined(VK_USE_PLATFORM_WIN32_KHR) PFN_vkGetInstanceProcAddr VulkanDeviceContext::LoadVk(VulkanLibraryHandleType &vulkanLibHandle, @@ -124,23 +125,23 @@ VkResult VulkanDeviceContext::CheckAllInstanceLayers(bool verbose) std::vector layers; vk::enumerate(this, layers); - if (verbose) std::cout << "Enumerating instance layers:" << std::endl; + if (verbose) LOG_S_INFO << "Enumerating instance layers:" << std::endl; std::set layer_names; for (const auto &layer : layers) { layer_names.insert(layer.layerName); - if (verbose ) std::cout << '\t' << layer.layerName << std::endl; + if (verbose ) LOG_S_INFO << '\t' << layer.layerName << std::endl; } // all listed instance layers are required - if (verbose) std::cout << "Looking for instance layers:" << std::endl; + if (verbose) LOG_S_INFO << "Looking for instance layers:" << std::endl; for (uint32_t i = 0; i < m_reqInstanceLayers.size(); i++) { const char* name = m_reqInstanceLayers[i]; if (name == nullptr) { break; } - std::cout << '\t' << name << std::endl; + LOG_S_INFO << '\t' << name << std::endl; if (layer_names.find(name) == layer_names.end()) { - std::cerr << "AssertAllInstanceLayers() ERROR: requested instance layer" + LOG_S_ERROR << "AssertAllInstanceLayers() ERROR: requested instance layer" << name << " is missing!" << std::endl << std::flush; return VK_ERROR_LAYER_NOT_PRESENT; } @@ -178,23 +179,23 @@ VkResult VulkanDeviceContext::CheckAllInstanceExtensions(bool verbose) std::vector exts; vk::enumerate(this, nullptr, exts); - if (verbose) std::cout << "Enumerating instance extensions:" << std::endl; + if (verbose) LOG_S_INFO << "Enumerating instance extensions:" << std::endl; std::set ext_names; for (const auto &ext : exts) { ext_names.insert(ext.extensionName); - if (verbose) std::cout << '\t' << ext.extensionName << std::endl; + if (verbose) LOG_S_INFO << '\t' << ext.extensionName << std::endl; } // all listed instance extensions are required - if (verbose) std::cout << "Looking for instance extensions:" << std::endl; + if (verbose) LOG_S_INFO << "Looking for instance extensions:" << std::endl; for (uint32_t i = 0; i < m_reqInstanceExtensions.size(); i++) { const char* name = m_reqInstanceExtensions[i]; if (name == nullptr) { break; } - if (verbose) std::cout << '\t' << name << std::endl; + if (verbose) LOG_S_INFO << '\t' << name << std::endl; if (ext_names.find(name) == ext_names.end()) { - std::cerr << "AssertAllInstanceExtensions() ERROR: requested instance extension " + LOG_S_ERROR << "AssertAllInstanceExtensions() ERROR: requested instance extension " << name << " is missing!" << std::endl << std::flush; return VK_ERROR_EXTENSION_NOT_PRESENT; } @@ -253,7 +254,7 @@ bool VulkanDeviceContext::HasAllDeviceExtensions(VkPhysicalDevice physDevice, co if (ext_names.find(name) == ext_names.end()) { hasAllRequiredExtensions = false; if (printMissingDeviceExt) { - std::cerr << __FUNCTION__ + LOG_S_ERROR << __FUNCTION__ << ": ERROR: required device extension " << name << " is missing for device with name: " << printMissingDeviceExt << std::endl << std::flush; @@ -273,7 +274,7 @@ bool VulkanDeviceContext::HasAllDeviceExtensions(VkPhysicalDevice physDevice, co } if (ext_names.find(name) == ext_names.end()) { if (printMissingDeviceExt) { - std::cout << __FUNCTION__ + LOG_S_INFO << __FUNCTION__ << " : WARNING: requested optional device extension " << name << " is missing for device with name: " << printMissingDeviceExt << std::endl << std::flush; @@ -301,7 +302,7 @@ static int DumpSoLibs() auto* map = reinterpret_cast(p->ptr); while (map) { - std::cout << map->l_name << std::endl; + LOG_S_INFO << map->l_name << std::endl; // do something with |map| like with handle, returned by |dlopen()|. map = map->l_next; } @@ -438,7 +439,7 @@ VkResult VulkanDeviceContext::InitPhysicalDevice(int32_t deviceId, const uint8_t } if (!HasAllDeviceExtensions(physicalDevice, props.deviceName)) { - std::cerr << "ERROR: Found physical device with name: " << props.deviceName << std::hex + LOG_S_ERROR << "ERROR: Found physical device with name: " << props.deviceName << std::hex << ", vendor ID: " << props.vendorID << ", and device ID: " << props.deviceID << std::dec << " NOT having the required extensions!" << std::endl << std::flush; @@ -494,19 +495,19 @@ VkResult VulkanDeviceContext::InitPhysicalDevice(int32_t deviceId, const uint8_t videoDecodeQueueFamily = i; videoDecodeQueueCount = queue.queueFamilyProperties.queueCount; - if (dumpQueues) std::cout << "\t Found video decode only queue family " << i << + if (dumpQueues) LOG_S_INFO << "\t Found video decode only queue family " << i << " with " << queue.queueFamilyProperties.queueCount << " max num of queues." << std::endl; // Does the video decode queue also support transfer operations? if (queueFamilyFlags & VK_QUEUE_TRANSFER_BIT) { - if (dumpQueues) std::cout << "\t\t Video decode queue " << i << + if (dumpQueues) LOG_S_INFO << "\t\t Video decode queue " << i << " supports transfer operations" << std::endl; } // Does the video decode queue also support compute operations? if (queueFamilyFlags & VK_QUEUE_COMPUTE_BIT) { - if (dumpQueues) std::cout << "\t\t Video decode queue " << i << + if (dumpQueues) LOG_S_INFO << "\t\t Video decode queue " << i << " supports compute operations" << std::endl; } @@ -522,19 +523,19 @@ VkResult VulkanDeviceContext::InitPhysicalDevice(int32_t deviceId, const uint8_t videoEncodeQueueFamily = i; videoEncodeQueueCount = queue.queueFamilyProperties.queueCount; - if (dumpQueues) std::cout << "\t Found video encode only queue family " << i << + if (dumpQueues) LOG_S_INFO << "\t Found video encode only queue family " << i << " with " << queue.queueFamilyProperties.queueCount << " max num of queues." << std::endl; // Does the video encode queue also support transfer operations? if (queueFamilyFlags & VK_QUEUE_TRANSFER_BIT) { - if (dumpQueues) std::cout << "\t\t Video encode queue " << i << + if (dumpQueues) LOG_S_INFO << "\t\t Video encode queue " << i << " supports transfer operations" << std::endl; } // Does the video encode queue also support compute operations? if (queueFamilyFlags & VK_QUEUE_COMPUTE_BIT) { - if (dumpQueues) std::cout << "\t\t Video encode queue " << i << + if (dumpQueues) LOG_S_INFO << "\t\t Video encode queue " << i << " supports compute operations" << std::endl; } @@ -550,17 +551,17 @@ VkResult VulkanDeviceContext::InitPhysicalDevice(int32_t deviceId, const uint8_t (queueFamilyFlags & VK_QUEUE_GRAPHICS_BIT)) { gfxQueueFamily = i; foundQueueTypes |= queueFamilyFlags; - if (dumpQueues) std::cout << "\t Found graphics queue family " << i << " with " << queue.queueFamilyProperties.queueCount << " max num of queues." << std::endl; + if (dumpQueues) LOG_S_INFO << "\t Found graphics queue family " << i << " with " << queue.queueFamilyProperties.queueCount << " max num of queues." << std::endl; } else if ((requestQueueTypes & VK_QUEUE_COMPUTE_BIT) && (computeQueueFamilyOnly < 0) && ((VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT) == (queueFamilyFlags & (VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT)))) { computeQueueFamilyOnly = i; foundQueueTypes |= queueFamilyFlags; - if (dumpQueues) std::cout << "\t Found compute only queue family " << i << " with " << queue.queueFamilyProperties.queueCount << " max num of queues." << std::endl; + if (dumpQueues) LOG_S_INFO << "\t Found compute only queue family " << i << " with " << queue.queueFamilyProperties.queueCount << " max num of queues." << std::endl; } else if ((requestQueueTypes & VK_QUEUE_TRANSFER_BIT) && (transferQueueFamilyOnly < 0) && (VK_QUEUE_TRANSFER_BIT == (queueFamilyFlags & VK_QUEUE_TRANSFER_BIT))) { transferQueueFamilyOnly = i; foundQueueTypes |= queueFamilyFlags; - if (dumpQueues) std::cout << "\t Found transfer only queue family " << i << " with " << queue.queueFamilyProperties.queueCount << " max num of queues." << std::endl; + if (dumpQueues) LOG_S_INFO << "\t Found transfer only queue family " << i << " with " << queue.queueFamilyProperties.queueCount << " max num of queues." << std::endl; } // requires only COMPUTE for frameProcessor queues @@ -568,13 +569,13 @@ VkResult VulkanDeviceContext::InitPhysicalDevice(int32_t deviceId, const uint8_t (queueFamilyFlags & VK_QUEUE_COMPUTE_BIT)) { computeQueueFamily = i; foundQueueTypes |= queueFamilyFlags; - if (dumpQueues) std::cout << "\t Found compute queue family " << i << " with " << queue.queueFamilyProperties.queueCount << " max num of queues." << std::endl; + if (dumpQueues) LOG_S_INFO << "\t Found compute queue family " << i << " with " << queue.queueFamilyProperties.queueCount << " max num of queues." << std::endl; } // present queue must support the surface if ((pWsiDisplay != nullptr) && (presentQueueFamily < 0) && pWsiDisplay->PhysDeviceCanPresent(physicalDevice, i)) { - if (dumpQueues) std::cout << "\t Found present queue family " << i << "." << std::endl; + if (dumpQueues) LOG_S_INFO << "\t Found present queue family " << i << "." << std::endl; presentQueueFamily = i; } @@ -604,7 +605,7 @@ VkResult VulkanDeviceContext::InitPhysicalDevice(int32_t deviceId, const uint8_t PrintExtensions(true); } - std::cout << "*** Selected Vulkan physical device with name: " << props.deviceName << std::hex + LOG_S_INFO << "*** Selected Vulkan physical device with name: " << props.deviceName << std::hex << ", vendor ID: " << props.vendorID << ", and device ID: " << props.deviceID << std::dec << ", Num Decode Queues: " << m_videoDecodeNumQueues << ", Num Encode Queues: " << m_videoEncodeNumQueues @@ -613,7 +614,7 @@ VkResult VulkanDeviceContext::InitPhysicalDevice(int32_t deviceId, const uint8_t return VK_SUCCESS; } } - std::cerr << "ERROR: Found physical device with name: " << props.deviceName << std::hex + LOG_S_ERROR << "ERROR: Found physical device with name: " << props.deviceName << std::hex << ", vendor ID: " << props.vendorID << ", and device ID: " << props.deviceID << std::dec << " NOT having the required queue families!" << std::endl << std::flush; @@ -917,9 +918,9 @@ const char * VulkanDeviceContext::FindRequiredDeviceExtension(const char* name) void VulkanDeviceContext::PrintExtensions(bool deviceExt) const { const std::vector& extensions = deviceExt ? m_deviceExtensions : m_instanceExtensions; - std::cout << "###### List of " << (deviceExt ? "Device" : "Instance") << " Extensions: ######" << std::endl; + LOG_S_INFO << "###### List of " << (deviceExt ? "Device" : "Instance") << " Extensions: ######" << std::endl; for (const auto& e : extensions) { - std::cout << "\t " << e.extensionName << "(v." << e.specVersion << ")\n"; + LOG_S_INFO << "\t " << e.extensionName << "(v." << e.specVersion << ")\n"; } } @@ -928,13 +929,13 @@ VkResult VulkanDeviceContext::PopulateInstanceExtensions() uint32_t extensionsCount = 0; VkResult result = EnumerateInstanceExtensionProperties( nullptr, &extensionsCount, nullptr ); if ((result != VK_SUCCESS) || (extensionsCount == 0)) { - std::cout << "Could not get the number of instance extensions." << std::endl; + LOG_S_ERROR << "Could not get the number of instance extensions." << std::endl; return result; } m_instanceExtensions.resize( extensionsCount ); result = EnumerateInstanceExtensionProperties( nullptr, &extensionsCount, m_instanceExtensions.data() ); if ((result != VK_SUCCESS) || (extensionsCount == 0)) { - std::cout << "Could not enumerate instance extensions." << std::endl; + LOG_S_ERROR << "Could not enumerate instance extensions." << std::endl; return result; } return result; @@ -945,13 +946,13 @@ VkResult VulkanDeviceContext::PopulateDeviceExtensions() uint32_t extensions_count = 0; VkResult result = EnumerateDeviceExtensionProperties( m_physDevice, nullptr, &extensions_count, nullptr ); if ((result != VK_SUCCESS) || (extensions_count == 0)) { - std::cout << "Could not get the number of device extensions." << std::endl; + LOG_S_ERROR << "Could not get the number of device extensions." << std::endl; return result; } m_deviceExtensions.resize( extensions_count ); result = EnumerateDeviceExtensionProperties( m_physDevice, nullptr, &extensions_count, m_deviceExtensions.data() ); if ((result != VK_SUCCESS) || (extensions_count == 0)) { - std::cout << "Could not enumerate device extensions." << std::endl; + LOG_S_ERROR << "Could not enumerate device extensions." << std::endl; return result; } return result; diff --git a/common/libs/VkCodecUtils/VulkanFilterYuvCompute.cpp b/common/libs/VkCodecUtils/VulkanFilterYuvCompute.cpp index 8e93a305..4b7b69b4 100644 --- a/common/libs/VkCodecUtils/VulkanFilterYuvCompute.cpp +++ b/common/libs/VkCodecUtils/VulkanFilterYuvCompute.cpp @@ -17,6 +17,7 @@ #include "VulkanFilterYuvCompute.h" #include "nvidia_utils/vulkan/ycbcrvkinfo.h" +#include "Logger.h" VkResult VulkanFilterYuvCompute::Create(const VulkanDeviceContext* vkDevCtx, uint32_t queueFamilyIndex, @@ -291,7 +292,7 @@ size_t VulkanFilterYuvCompute::InitYCBCR2RGBA(std::string& computeShader) "}\n"; computeShader = shaderStr.str(); - std::cout << "\nCompute Shader:\n" << computeShader; + LOG_S_INFO << "\nCompute Shader:\n" << computeShader; return computeShader.size(); } @@ -348,7 +349,7 @@ size_t VulkanFilterYuvCompute::InitYCBCRCOPY(std::string& computeShader) "}\n"; computeShader = shaderStr.str(); - std::cout << "\nCompute Shader:\n" << computeShader; + LOG_S_DEBUG << "\nCompute Shader:\n" << computeShader; return computeShader.size(); } @@ -394,6 +395,6 @@ size_t VulkanFilterYuvCompute::InitYCBCRCLEAR(std::string& computeShader) "}\n"; computeShader = shaderStr.str(); - std::cout << "\nCompute Shader:\n" << computeShader; + LOG_S_DEBUG << "\nCompute Shader:\n" << computeShader; return computeShader.size(); } diff --git a/common/libs/VkCodecUtils/VulkanFrame.cpp b/common/libs/VkCodecUtils/VulkanFrame.cpp index 6b0c568b..d3abc52d 100644 --- a/common/libs/VkCodecUtils/VulkanFrame.cpp +++ b/common/libs/VkCodecUtils/VulkanFrame.cpp @@ -26,6 +26,7 @@ #include "VulkanFrame.h" #include "vk_enum_string_helper.h" #include "VkVideoCore/DecodeFrameBufferIf.h" +#include "Logger.h" template VulkanFrame::VulkanFrame(const VulkanDeviceContext* vkDevCtx, @@ -65,9 +66,9 @@ int VulkanFrame::AttachShell(const Shell& sh) const uint32_t apiPatchVersion = VK_API_VERSION_PATCH(m_physicalDevProps.apiVersion); if (m_physicalDevProps.apiVersion < VK_MAKE_API_VERSION(0, 1, 2, 199)) { - std::cerr << std::endl << "Incompatible Vulkan API version: " << apiMajorVersion << "." << apiMinorVersion << "." << apiPatchVersion << std::endl; - std::cerr << "Info: Driver version is: " << m_physicalDevProps.driverVersion << std::endl; - std::cerr << "Please upgrade your driver. The version supported is: 1.2.199 or later aka " << std::hex << VK_MAKE_API_VERSION(0, 1, 2, 199) << std::endl; + LOG_S_ERROR << std::endl << "Incompatible Vulkan API version: " << apiMajorVersion << "." << apiMinorVersion << "." << apiPatchVersion << std::endl; + LOG_S_ERROR << "Info: Driver version is: " << m_physicalDevProps.driverVersion << std::endl; + LOG_S_ERROR << "Please upgrade your driver. The version supported is: 1.2.199 or later aka " << std::hex << VK_MAKE_API_VERSION(0, 1, 2, 199) << std::endl; assert(!"Incompatible API version - please upgrade your driver."); return -1; } @@ -100,7 +101,7 @@ int VulkanFrame::AttachShell(const Shell& sh) (const float*)vertices, sizeof(vertices), sizeof(vertices) / sizeof(vertices[0]))) { - std::cerr << "VulkanVideoFrame: " << "File " << __FILE__ << "line " << __LINE__; + LOG_S_ERROR << "VulkanVideoFrame: " << "File " << __FILE__ << "line " << __LINE__; return -1; } @@ -287,11 +288,11 @@ bool VulkanFrame::OnFrame( int32_t renderIndex, bool displayTimeNow = false; float fps = GetFrameRateFps(displayTimeNow); if (displayTimeNow) { - std::cout << "\t\tFrame " << m_frameCount << ", FPS: " << fps << std::endl; + LOG_S_DEBUG << "\t\tFrame " << m_frameCount << ", FPS: " << fps << std::endl; } } else { uint64_t timeDiffNanoSec = GetTimeDiffNanoseconds(); - std::cout << "\t\t Time nanoseconds: " << timeDiffNanoSec << + LOG_S_DEBUG << "\t\t Time nanoseconds: " << timeDiffNanoSec << " milliseconds: " << timeDiffNanoSec / 1000 << " rate: " << 1000000000.0 / timeDiffNanoSec << std::endl; } @@ -322,7 +323,7 @@ bool VulkanFrame::OnFrame( int32_t renderIndex, assert(result == VK_SUCCESS); assert(decodeStatus == VK_QUERY_RESULT_STATUS_COMPLETE_KHR); if ((result != VK_SUCCESS) || (decodeStatus != VK_QUERY_RESULT_STATUS_COMPLETE_KHR)) { - fprintf(stderr, "\nERROR: GetQueryPoolResults() result: 0x%x\n", result); + LOG_ERROR( "\nERROR: GetQueryPoolResults() result: 0x%x\n", result); return false; } @@ -330,19 +331,19 @@ bool VulkanFrame::OnFrame( int32_t renderIndex, auto diffMilliseconds = std::chrono::duration_cast(deltaTime); auto diffMicroseconds = std::chrono::duration_cast(deltaTime); if (dumpDebug) { - std::cout << pLastDecodedFrame->pictureIndex << ": frameWaitTime: " << + LOG_S_DEBUG << pLastDecodedFrame->pictureIndex << ": frameWaitTime: " << diffMilliseconds.count() << "." << diffMicroseconds.count() << " mSec" << std::endl; } } else if (pLastDecodedFrame->frameCompleteFence != VkFence()) { VkResult result = m_vkDevCtx->WaitForFences(*m_vkDevCtx, 1, &pLastDecodedFrame->frameCompleteFence, true, 100 * 1000 * 1000 /* 100 mSec */); assert(result == VK_SUCCESS); if (result != VK_SUCCESS) { - fprintf(stderr, "\nERROR: WaitForFences() result: 0x%x\n", result); + LOG_ERROR("\nERROR: WaitForFences() result: 0x%x\n", result); } result = m_vkDevCtx->GetFenceStatus(*m_vkDevCtx, pLastDecodedFrame->frameCompleteFence); assert(result == VK_SUCCESS); if (result != VK_SUCCESS) { - fprintf(stderr, "\nERROR: GetFenceStatus() result: 0x%x\n", result); + LOG_ERROR("\nERROR: GetFenceStatus() result: 0x%x\n", result); } } } @@ -360,7 +361,7 @@ bool VulkanFrame::OnFrame( int32_t renderIndex, bool displayTimeNow = true; float fps = GetFrameRateFps(displayTimeNow); if (displayTimeNow) { - std::cout << "\t\tFrame " << m_frameCount << ", FPS: " << fps << std::endl; + LOG_S_DEBUG << "\t\tFrame " << m_frameCount << ", FPS: " << fps << std::endl; } } } @@ -371,14 +372,14 @@ bool VulkanFrame::OnFrame( int32_t renderIndex, VkSharedBaseObj imageResourceView; pLastDecodedFrame->imageViews[FrameDataType::IMAGE_VIEW_TYPE_OPTIMAL_DISPLAY].GetImageResourceView(imageResourceView); - std::cout << "<= Wait on picIdx: " << pLastDecodedFrame->pictureIndex - << "\t\tdisplayWidth: " << pLastDecodedFrame->displayWidth - << "\t\tdisplayHeight: " << pLastDecodedFrame->displayHeight - << "\t\tdisplayOrder: " << pLastDecodedFrame->displayOrder - << "\tdecodeOrder: " << pLastDecodedFrame->decodeOrder - << "\ttimestamp " << pLastDecodedFrame->timestamp - << "\tdstImageView " << (imageResourceView ? imageResourceView->GetImageResource()->GetImage() : VkImage()) - << std::endl; + LOG_S_DEBUG << "<= Wait on picIdx: " << pLastDecodedFrame->pictureIndex + << "\t\tdisplayWidth: " << pLastDecodedFrame->displayWidth + << "\t\tdisplayHeight: " << pLastDecodedFrame->displayHeight + << "\t\tdisplayOrder: " << pLastDecodedFrame->displayOrder + << "\tdecodeOrder: " << pLastDecodedFrame->decodeOrder + << "\ttimestamp " << pLastDecodedFrame->timestamp + << "\tdstImageView " << (imageResourceView ? imageResourceView->GetImageResource()->GetImage() : VkImage()) + << std::endl; } if (gfxRendererIsEnabled == false) { @@ -498,11 +499,11 @@ VkResult VulkanFrame::DrawFrame( int32_t renderIndex, m_videoRenderer->m_vertexBuffer); if (dumpDebug) { - std::cout << "Drawing Frame " << m_frameCount << " FB: " << renderIndex << std::endl; + LOG_S_DEBUG << "Drawing Frame " << m_frameCount << " FB: " << renderIndex << std::endl; } if (dumpDebug && inFrame) { - std::cout << "<= Present picIdx: " << inFrame->pictureIndex + LOG_S_DEBUG << "<= Present picIdx: " << inFrame->pictureIndex << "\t\tdisplayOrder: " << inFrame->displayOrder << "\tdecodeOrder: " << inFrame->decodeOrder << "\ttimestamp " << inFrame->timestamp @@ -518,19 +519,19 @@ VkResult VulkanFrame::DrawFrame( int32_t renderIndex, result = m_vkDevCtx->QueueWaitIdle(videoDecodeQueue); assert(result == VK_SUCCESS); if (result != VK_SUCCESS) { - fprintf(stderr, "\nERROR: QueueWaitIdle() result: 0x%x\n", result); + LOG_ERROR("\nERROR: QueueWaitIdle() result: 0x%x\n", result); } } } else { result = m_vkDevCtx->WaitForFences(*m_vkDevCtx, 1, &inFrame->frameCompleteFence, true, 100 * 1000 * 1000 /* 100 mSec */); assert(result == VK_SUCCESS); if (result != VK_SUCCESS) { - fprintf(stderr, "\nERROR: WaitForFences() result: 0x%x\n", result); + LOG_ERROR("\nERROR: WaitForFences() result: 0x%x\n", result); } result = m_vkDevCtx->GetFenceStatus(*m_vkDevCtx, inFrame->frameCompleteFence); assert(result == VK_SUCCESS); if (result != VK_SUCCESS) { - fprintf(stderr, "\nERROR: GetFenceStatus() result: 0x%x\n", result); + LOG_ERROR("\nERROR: GetFenceStatus() result: 0x%x\n", result); } } } @@ -547,12 +548,12 @@ VkResult VulkanFrame::DrawFrame( int32_t renderIndex, result = m_vkDevCtx->WaitForFences(*m_vkDevCtx, 1, &inFrame->frameCompleteFence, true, 100 * 1000 * 1000 /* 100 mSec */); assert(result == VK_SUCCESS); if (result != VK_SUCCESS) { - fprintf(stderr, "\nERROR: WaitForFences() result: 0x%x (%s)\n", result, string_VkResult(result)); + LOG_ERROR("\nERROR: WaitForFences() result: 0x%x (%s)\n", result, string_VkResult(result)); } result = m_vkDevCtx->GetFenceStatus(*m_vkDevCtx, inFrame->frameCompleteFence); assert(result == VK_SUCCESS); if (result != VK_SUCCESS) { - fprintf(stderr, "\nERROR: GetFenceStatus() result: 0x%x\n", result); + LOG_ERROR("\nERROR: GetFenceStatus() result: 0x%x\n", result); } } @@ -567,14 +568,14 @@ VkResult VulkanFrame::DrawFrame( int32_t renderIndex, VK_QUERY_RESULT_WITH_STATUS_BIT_KHR | VK_QUERY_RESULT_WAIT_BIT); assert(result == VK_SUCCESS); if (result != VK_SUCCESS) { - fprintf(stderr, "\nERROR: GetQueryPoolResults() result: 0x%x\n", result); + LOG_ERROR("\nERROR: GetQueryPoolResults() result: 0x%x\n", result); } assert(decodeStatus == VK_QUERY_RESULT_STATUS_COMPLETE_KHR); if (dumpDebug) { - std::cout << "\t +++++++++++++++++++++++++++< " << (inFrame ? inFrame->pictureIndex : -1) + LOG_S_DEBUG << "\t +++++++++++++++++++++++++++< " << (inFrame ? inFrame->pictureIndex : -1) << " >++++++++++++++++++++++++++++++" << std::endl; - std::cout << "\t => Decode Status for CurrPicIdx: " << (inFrame ? inFrame->pictureIndex : -1) << std::endl + LOG_S_DEBUG << "\t => Decode Status for CurrPicIdx: " << (inFrame ? inFrame->pictureIndex : -1) << std::endl << "\t\tdecodeStatus: " << decodeStatus << std::endl; } } @@ -633,19 +634,19 @@ VkResult VulkanFrame::DrawFrame( int32_t renderIndex, result = m_vkDevCtx->WaitForFences(*m_vkDevCtx, 1, &inFrame->frameCompleteFence, true, 100 * 1000 * 1000); assert(result == VK_SUCCESS); if (result != VK_SUCCESS) { - fprintf(stderr, "\nERROR: WaitForFences() result: 0x%x\n", result); + LOG_ERROR("\nERROR: WaitForFences() result: 0x%x\n", result); } result = m_vkDevCtx->GetFenceStatus(*m_vkDevCtx, inFrame->frameCompleteFence); assert(result == VK_SUCCESS); if (result != VK_SUCCESS) { - fprintf(stderr, "\nERROR: GetFenceStatus() result: 0x%x\n", result); + LOG_ERROR("\nERROR: GetFenceStatus() result: 0x%x\n", result); } } result = m_vkDevCtx->MultiThreadedQueueSubmit(VulkanDeviceContext::GRAPHICS, 0, 1, &primaryCmdSubmitInfo, frameConsumerDoneFence); if (result != VK_SUCCESS) { assert(result == VK_SUCCESS); - fprintf(stderr, "\nERROR: MultiThreadedQueueSubmit() result: 0x%x\n", result); + LOG_ERROR("\nERROR: MultiThreadedQueueSubmit() result: 0x%x\n", result); return result; } @@ -654,12 +655,12 @@ VkResult VulkanFrame::DrawFrame( int32_t renderIndex, result = m_vkDevCtx->WaitForFences(*m_vkDevCtx, 1, &frameConsumerDoneFence, true, fenceTimeout); assert(result == VK_SUCCESS); if (result != VK_SUCCESS) { - fprintf(stderr, "\nERROR: WaitForFences() result: 0x%x\n", result); + LOG_ERROR("\nERROR: WaitForFences() result: 0x%x\n", result); } result = m_vkDevCtx->GetFenceStatus(*m_vkDevCtx, frameConsumerDoneFence); assert(result == VK_SUCCESS); if (result != VK_SUCCESS) { - fprintf(stderr, "\nERROR: GetFenceStatus() result: 0x%x\n", result); + LOG_ERROR("\nERROR: GetFenceStatus() result: 0x%x\n", result); } } diff --git a/common/libs/VkCodecUtils/VulkanShaderCompiler.cpp b/common/libs/VkCodecUtils/VulkanShaderCompiler.cpp index 20fc073e..78317957 100644 --- a/common/libs/VkCodecUtils/VulkanShaderCompiler.cpp +++ b/common/libs/VkCodecUtils/VulkanShaderCompiler.cpp @@ -40,7 +40,7 @@ static shaderc_shader_kind getShadercShaderType(VkShaderStageFlagBits type) case VK_SHADER_STAGE_COMPUTE_BIT: return shaderc_glsl_compute_shader; default: - std::cerr << "VulkanShaderCompiler: " << "invalid VKShaderStageFlagBits" << "type = " << type; + LOG_S_ERROR << "VulkanShaderCompiler: " << "invalid VKShaderStageFlagBits" << "type = " << type; } return static_cast(-1); } @@ -75,7 +75,7 @@ VkShaderModule VulkanShaderCompiler::BuildGlslShader(const char *shaderCode, siz if (shaderc_result_get_compilation_status(spvShader) != shaderc_compilation_status_success) { - std::cerr << "Compilation error: \n" << shaderc_result_get_error_message(spvShader) << std::endl; + LOG_S_ERROR << "Compilation error: \n" << shaderc_result_get_error_message(spvShader) << std::endl; return VK_NULL_HANDLE; } @@ -90,7 +90,7 @@ VkShaderModule VulkanShaderCompiler::BuildGlslShader(const char *shaderCode, siz VkResult result = vkDevCtx->CreateShaderModule(*vkDevCtx, &shaderModuleCreateInfo, nullptr, &shaderModule); assert(result == VK_SUCCESS); if (result != VK_SUCCESS) { - std::cerr << "Failed to create shader module" << std::endl; + LOG_S_ERROR << "Failed to create shader module" << std::endl; return VK_NULL_HANDLE; } shaderc_result_release(spvShader); diff --git a/common/libs/VkCodecUtils/VulkanVideoProcessor.cpp b/common/libs/VkCodecUtils/VulkanVideoProcessor.cpp index 5b3f60c7..8c51df7e 100644 --- a/common/libs/VkCodecUtils/VulkanVideoProcessor.cpp +++ b/common/libs/VkCodecUtils/VulkanVideoProcessor.cpp @@ -33,6 +33,7 @@ #include "vulkan_interfaces.h" #include "nvidia_utils/vulkan/ycbcrvkinfo.h" #include "crcgenerator.h" +#include "Logger.h" inline void CheckInputFile(const char* szInFilePath) { @@ -72,7 +73,7 @@ int32_t VulkanVideoProcessor::Initialize(const VulkanDeviceContext* vkDevCtx, const bool verbose = false; if (vkDevCtx->GetVideoDecodeQueue(videoQueueIndx) == VkQueue()) { - std::cerr << "videoQueueIndx is out of bounds: " << videoQueueIndx << + LOG_S_ERROR << "videoQueueIndx is out of bounds: " << videoQueueIndx << " Max decode queues: " << vkDevCtx->GetVideoDecodeNumQueues() << std::endl; assert(!"Invalid Video Queue"); return -1; @@ -106,12 +107,12 @@ int32_t VulkanVideoProcessor::Initialize(const VulkanDeviceContext* vkDevCtx, result = VulkanVideoFrameBuffer::Create(vkDevCtx, m_vkVideoFrameBuffer); assert(result == VK_SUCCESS); if (result != VK_SUCCESS) { - fprintf(stderr, "\nERROR: Create VulkanVideoFrameBuffer result: 0x%x\n", result); + LOG_ERROR("\nERROR: Create VulkanVideoFrameBuffer result: 0x%x\n", result); } FILE* outFile = m_frameToFile.AttachFile(outputFileName); if ((outputFileName != nullptr) && (outFile == nullptr)) { - fprintf( stderr, "Error opening the output file %s", outputFileName); + LOG_ERROR("Error opening the output file %s", outputFileName); return -1; } @@ -143,7 +144,7 @@ int32_t VulkanVideoProcessor::Initialize(const VulkanDeviceContext* vkDevCtx, m_vkVideoDecoder); assert(result == VK_SUCCESS); if (result != VK_SUCCESS) { - fprintf(stderr, "\nERROR: Create VkVideoDecoder result: 0x%x\n", result); + LOG_ERROR("\nERROR: Create VkVideoDecoder result: 0x%x\n", result); } VkVideoCoreProfile videoProfile(m_videoStreamDemuxer->GetVideoCodec(), @@ -155,7 +156,7 @@ int32_t VulkanVideoProcessor::Initialize(const VulkanDeviceContext* vkDevCtx, if (!VulkanVideoCapabilities::IsCodecTypeSupported(vkDevCtx, vkDevCtx->GetVideoDecodeQueueFamilyIdx(), m_videoStreamDemuxer->GetVideoCodec())) { - std::cout << "*** The video codec " << VkVideoCoreProfile::CodecToName(m_videoStreamDemuxer->GetVideoCodec()) << " is not supported! ***" << std::endl; + LOG_S_ERROR << "*** The video codec " << VkVideoCoreProfile::CodecToName(m_videoStreamDemuxer->GetVideoCodec()) << " is not supported! ***" << std::endl; assert(!"The video codec is not supported"); return -1; } @@ -167,7 +168,7 @@ int32_t VulkanVideoProcessor::Initialize(const VulkanDeviceContext* vkDevCtx, videoDecodeCapabilities); if (result != VK_SUCCESS) { - std::cout << "*** Could not get Video Capabilities :" << result << " ***" << std::endl; + LOG_S_ERROR << "*** Could not get Video Capabilities :" << result << " ***" << std::endl; assert(!"Could not get Video Capabilities!"); return -result; } @@ -180,7 +181,7 @@ int32_t VulkanVideoProcessor::Initialize(const VulkanDeviceContext* vkDevCtx, (uint32_t)videoCapabilities.minBitstreamBufferSizeAlignment); assert(result == VK_SUCCESS); if (result != VK_SUCCESS) { - fprintf(stderr, "\nERROR: CreateParser() result: 0x%x\n", result); + LOG_ERROR("\nERROR: CreateParser() result: 0x%x\n", result); } m_loopCount = loopCount; @@ -259,7 +260,7 @@ void VulkanVideoProcessor::Deinit() void VulkanVideoProcessor::DumpVideoFormat(const VkParserDetectedVideoFormat* videoFormat, bool dumpData) { if (dumpData) { - std::cout << "Display Area : " << std::endl + LOG_S_DEBUG << "Display Area : " << std::endl << "\tLeft : " << videoFormat->display_area.left << std::endl << "\tRight : " << videoFormat->display_area.right << std::endl << "\tTop : " << videoFormat->display_area.top << std::endl @@ -267,7 +268,7 @@ void VulkanVideoProcessor::DumpVideoFormat(const VkParserDetectedVideoFormat* vi } if (dumpData) { - std::cout << "Geometry : " << std::endl + LOG_S_DEBUG << "Geometry : " << std::endl << "\tCoded Width : " << videoFormat->coded_width << std::endl << "\tDisplayed Width : " << videoFormat->display_area.right - videoFormat->display_area.left << std::endl << "\tCoded Height : " << videoFormat->coded_height << std::endl @@ -276,7 +277,7 @@ void VulkanVideoProcessor::DumpVideoFormat(const VkParserDetectedVideoFormat* vi const char* pCodec = VkVideoCoreProfile::CodecToName(videoFormat->codec); if (dumpData) { - std::cout << "Codec : " << pCodec << std::endl; + LOG_S_DEBUG << "Codec : " << pCodec << std::endl; } /* These below token numbers are based on "chroma_format_idc" from the spec. */ @@ -296,7 +297,7 @@ void VulkanVideoProcessor::DumpVideoFormat(const VkParserDetectedVideoFormat* vi assert(nvVideoChromaFormat[videoFormat->chromaSubsampling] != nullptr); const char* pVideoChromaFormat = nvVideoChromaFormat[videoFormat->chromaSubsampling]; if (dumpData) { - std::cout << "VideoChromaFormat : " << pVideoChromaFormat << std::endl; + LOG_S_DEBUG << "VideoChromaFormat : " << pVideoChromaFormat << std::endl; } static const char* VideoFormat[] = { @@ -314,7 +315,7 @@ void VulkanVideoProcessor::DumpVideoFormat(const VkParserDetectedVideoFormat* vi assert(videoFormat->video_signal_description.video_format < sizeof(VideoFormat)/sizeof(VideoFormat[0])); const char* pVideoFormat = VideoFormat[videoFormat->video_signal_description.video_format]; if (dumpData) { - std::cout << "VideoFormat : " << pVideoFormat << std::endl; + LOG_S_DEBUG << "VideoFormat : " << pVideoFormat << std::endl; } const char* ColorPrimaries[] = { @@ -334,7 +335,7 @@ void VulkanVideoProcessor::DumpVideoFormat(const VkParserDetectedVideoFormat* vi assert(videoFormat->video_signal_description.color_primaries < sizeof(ColorPrimaries)/sizeof(ColorPrimaries[0])); const char* pColorPrimaries = ColorPrimaries[videoFormat->video_signal_description.color_primaries]; if (dumpData) { - std::cout << "ColorPrimaries : " << pColorPrimaries << std::endl; + LOG_S_DEBUG << "ColorPrimaries : " << pColorPrimaries << std::endl; } const char* TransferCharacteristics[] = { @@ -360,7 +361,7 @@ void VulkanVideoProcessor::DumpVideoFormat(const VkParserDetectedVideoFormat* vi assert(videoFormat->video_signal_description.transfer_characteristics < sizeof(TransferCharacteristics)/sizeof(TransferCharacteristics[0])); const char* pTransferCharacteristics = TransferCharacteristics[videoFormat->video_signal_description.transfer_characteristics]; if (dumpData) { - std::cout << "TransferCharacteristics : " << pTransferCharacteristics << std::endl; + LOG_S_DEBUG << "TransferCharacteristics : " << pTransferCharacteristics << std::endl; } const char* MatrixCoefficients[] = { @@ -379,7 +380,7 @@ void VulkanVideoProcessor::DumpVideoFormat(const VkParserDetectedVideoFormat* vi assert(videoFormat->video_signal_description.matrix_coefficients < sizeof(MatrixCoefficients)/sizeof(MatrixCoefficients[0])); const char* pMatrixCoefficients = MatrixCoefficients[videoFormat->video_signal_description.matrix_coefficients]; if (dumpData) { - std::cout << "MatrixCoefficients : " << pMatrixCoefficients << std::endl; + LOG_S_DEBUG << "MatrixCoefficients : " << pMatrixCoefficients << std::endl; } } @@ -581,12 +582,12 @@ void VulkanVideoProcessor::Restart(void) bool VulkanVideoProcessor::StreamCompleted() { if (--m_loopCount > 0) { - std::cout << "Restarting video stream with loop number " << (m_loopCount + 1) << std::endl; + LOG_S_INFO << "Restarting video stream with loop number " << (m_loopCount + 1) << std::endl; // Reload the file stream Restart(); return false; } else { - std::cout << "End of Video Stream with status " << VK_SUCCESS << std::endl; + LOG_S_INFO << "End of Video Stream with status " << VK_SUCCESS << std::endl; return true; } } @@ -664,7 +665,7 @@ int32_t VulkanVideoProcessor::GetNextFrame(VulkanDecodedFrame* pFrame, bool* end if ((m_maxFrameCount != -1) && (m_videoFrameNum >= (uint32_t)m_maxFrameCount)) { // Tell the FrameProcessor we're done after this frame is drawn. - std::cout << "Number of video frames " << m_videoFrameNum + LOG_S_ERROR << "Number of video frames " << m_videoFrameNum << " of max frame number " << m_maxFrameCount << std::endl; m_videoStreamsCompleted = StreamCompleted(); *endOfStream = m_videoStreamsCompleted; diff --git a/common/libs/VkCodecUtils/VulkanVideoUtils.cpp b/common/libs/VkCodecUtils/VulkanVideoUtils.cpp index 22150bca..d8266482 100644 --- a/common/libs/VkCodecUtils/VulkanVideoUtils.cpp +++ b/common/libs/VkCodecUtils/VulkanVideoUtils.cpp @@ -22,11 +22,12 @@ #include "VulkanVideoUtils.h" #include +#include "Logger.h" // Vulkan call wrapper #define CALL_VK(func) \ if (VK_SUCCESS != (func)) { \ - std::cerr << "VkVideoUtils: " << "File " << __FILE__ << "line " << __LINE__; \ + LOG_S_ERROR << "VkVideoUtils: " << "File " << __FILE__ << "line " << __LINE__; \ assert(false); \ } @@ -43,7 +44,7 @@ using namespace Pattern; void VulkanSwapchainInfo::CreateSwapChain(const VulkanDeviceContext* vkDevCtx, VkSwapchainKHR swapchain) { - if (mVerbose) std::cout << "VkVideoUtils: " << "Enter Function: " << __FUNCTION__ << "File " << __FILE__ << "line " << __LINE__ << std::endl; + if (mVerbose) LOG_S_DEBUG << "VkVideoUtils: " << "Enter Function: " << __FUNCTION__ << "File " << __FILE__ << "line " << __LINE__ << std::endl; mInstance = vkDevCtx->getInstance(); m_vkDevCtx = vkDevCtx; @@ -77,7 +78,7 @@ void VulkanSwapchainInfo::CreateSwapChain(const VulkanDeviceContext* vkDevCtx, V m_vkDevCtx->GetPhysicalDeviceSurfaceFormatsKHR(vkDevCtx->getPhysicalDevice(), mSurface, &formatCount, formats); - std::cout << "VkVideoUtils: " << "VulkanSwapchainInfo - got " << formatCount << "surface formats"; + LOG_S_INFO << "VkVideoUtils: " << "VulkanSwapchainInfo - got " << formatCount << "surface formats"; uint32_t chosenFormat; for (chosenFormat = 0; chosenFormat < formatCount; chosenFormat++) { @@ -506,8 +507,8 @@ VkResult VulkanGraphicsPipeline::CreatePipeline(const VulkanDeviceContext* vkDev const bool verbose = false; - if (false) printf("\nVertex shader output code:\n %s", vss); - if (false) printf("\nFragment shader output code:\n %s", imageFss.str().c_str()); + if (false) LOG_DEBUG("\nVertex shader output code:\n %s", vss); + if (false) LOG_DEBUG("\nFragment shader output code:\n %s", imageFss.str().c_str()); const bool loadShadersFromFile = false; if (loadShadersFromFile) { @@ -536,7 +537,7 @@ VkResult VulkanGraphicsPipeline::CreatePipeline(const VulkanDeviceContext* vkDev m_vkDevCtx); m_fssCache.swap(imageFss); - if (verbose) printf("\nFragment shader cache output code:\n %s", m_fssCache.str().c_str()); + if (verbose) LOG_DEBUG("\nFragment shader cache output code:\n %s", m_fssCache.str().c_str()); } } @@ -848,14 +849,14 @@ VkResult VulkanRenderInfo::UpdatePerDrawContexts(VulkanPerDrawContext* pPerDrawC const VkSamplerYcbcrConversionCreateInfo* pSamplerYcbcrConversionCreateInfo) { - if (mVerbose) std::cout << "VkVideoUtils: " << "CreateVulkanSamplers " << pPerDrawContext->contextIndex << std::endl; + if (mVerbose) LOG_S_DEBUG << "VkVideoUtils: " << "CreateVulkanSamplers " << pPerDrawContext->contextIndex << std::endl; VkResult result = pPerDrawContext->samplerYcbcrConversion.CreateVulkanSampler(m_vkDevCtx, pSamplerCreateInfo, pSamplerYcbcrConversionCreateInfo); if (result != VK_SUCCESS) { return result; } - if (mVerbose) std::cout << "VkVideoUtils: " << "CreateDescriptorSet " << pPerDrawContext->contextIndex << std::endl; + if (mVerbose) LOG_S_DEBUG << "VkVideoUtils: " << "CreateDescriptorSet " << pPerDrawContext->contextIndex << std::endl; VkSampler immutableSampler = pPerDrawContext->samplerYcbcrConversion.GetSampler(); const std::vector setLayoutBindings{ @@ -880,7 +881,7 @@ VkResult VulkanRenderInfo::UpdatePerDrawContexts(VulkanPerDrawContext* pPerDrawC if (result != VK_SUCCESS) { return result; } - if (mVerbose) std::cout << "VkVideoUtils: " << "CreateGraphicsPipeline " << pPerDrawContext->contextIndex << std::endl; + if (mVerbose) LOG_S_DEBUG << "VkVideoUtils: " << "CreateGraphicsPipeline " << pPerDrawContext->contextIndex << std::endl; // Create graphics pipeline result = pPerDrawContext->gfxPipeline.CreatePipeline(m_vkDevCtx, pViewport, @@ -913,15 +914,15 @@ VkResult VulkanRenderInfo::CreatePerDrawContexts(const VulkanDeviceContext* vkDe VulkanPerDrawContext* pPerDrawContext = GetDrawContext(ctxsIndx); pPerDrawContext->m_vkDevCtx = vkDevCtx; pPerDrawContext->contextIndex = ctxsIndx; - if (mVerbose) std::cout << "VkVideoUtils: " << "Init pPerDrawContext " << ctxsIndx << std::endl; + if (mVerbose) LOG_S_DEBUG << "VkVideoUtils: " << "Init pPerDrawContext " << ctxsIndx << std::endl; - if (mVerbose) std::cout << "VkVideoUtils: " << "CreateCommandBufferPool " << pPerDrawContext->contextIndex << std::endl; + if (mVerbose) LOG_S_DEBUG << "VkVideoUtils: " << "CreateCommandBufferPool " << pPerDrawContext->contextIndex << std::endl; result = pPerDrawContext->commandBuffer.CreateCommandBufferPool(vkDevCtx, vkDevCtx->GetGfxQueueFamilyIdx()); if (result != VK_SUCCESS) { return result; } - if (mVerbose) std::cout << "VkVideoUtils: " << "CreateFrameBuffer " << pPerDrawContext->contextIndex << std::endl; + if (mVerbose) LOG_S_DEBUG << "VkVideoUtils: " << "CreateFrameBuffer " << pPerDrawContext->contextIndex << std::endl; result = pPerDrawContext->frameBuffer.CreateFrameBuffer(m_vkDevCtx, swapchain, pFbExtent2D, pSurfaceFormat, fbImages[ctxsIndx], renderPass); @@ -929,7 +930,7 @@ VkResult VulkanRenderInfo::CreatePerDrawContexts(const VulkanDeviceContext* vkDe return result; } - if (mVerbose) std::cout << "VkVideoUtils: " << "CreateSyncPrimitives " << pPerDrawContext->contextIndex << std::endl; + if (mVerbose) LOG_S_DEBUG << "VkVideoUtils: " << "CreateSyncPrimitives " << pPerDrawContext->contextIndex << std::endl; result = pPerDrawContext->syncPrimitives.CreateSyncPrimitives(m_vkDevCtx); if (result != VK_SUCCESS) { return result; diff --git a/vk_video_encoder/demos/vk-video-enc/Main.cpp b/vk_video_encoder/demos/vk-video-enc/Main.cpp index e9bf2a20..105d3d68 100644 --- a/vk_video_encoder/demos/vk-video-enc/Main.cpp +++ b/vk_video_encoder/demos/vk-video-enc/Main.cpp @@ -20,6 +20,7 @@ #include "VkCodecUtils/VulkanVideoEncodeDisplayQueue.h" #include "VkCodecUtils/VulkanEncoderFrameProcessor.h" #include "VkShell/Shell.h" +#include "Logger.h" int main(int argc, char** argv) { @@ -104,7 +105,7 @@ int main(int argc, char** argv) VkResult result = vkDevCtxt.InitVulkanDevice(encoderConfig->appName.c_str(), encoderConfig->verbose); if (result != VK_SUCCESS) { - printf("Could not initialize the Vulkan device!\n"); + LOG_ERROR("Could not initialize the Vulkan device!\n"); return -1; } @@ -150,6 +151,7 @@ int main(int argc, char** argv) VkSharedBaseObj frameProcessor; result = CreateEncoderFrameProcessor(&vkDevCtxt, videoQueue, frameProcessor); if (result != VK_SUCCESS) { + LOG_ERROR("Could not create the encoder frame processor!\n"); return -1; } @@ -271,7 +273,7 @@ int main(int argc, char** argv) for(; curFrameIndex < encoderConfig->numFrames; curFrameIndex++) { if (encoderConfig->verboseFrameStruct) { - std::cout << "####################################################################################" << std::endl + LOG_S_DEBUG << "####################################################################################" << std::endl << "Start processing current input frame index: " << curFrameIndex << std::endl; } @@ -281,18 +283,18 @@ int main(int argc, char** argv) // load frame data from the file result = encoder->LoadNextFrame(encodeFrameInfo); if (result != VK_SUCCESS) { - std::cout << "ERROR processing input frame index: " << curFrameIndex << std::endl; + LOG_S_ERROR << "ERROR processing input frame index: " << curFrameIndex << std::endl; break; } if (encoderConfig->verboseFrameStruct) { - std::cout << "End processing current input frame index: " << curFrameIndex << std::endl; + LOG_S_DEBUG << "End processing current input frame index: " << curFrameIndex << std::endl; } } encoder->WaitForThreadsToComplete(); - std::cout << "Done processing " << curFrameIndex << " input frames!" << std::endl + LOG_S_INFO << "Done processing " << curFrameIndex << " input frames!" << std::endl << "Encoded file's location is at " << encoderConfig->outputFileHandler.GetFileName() << std::endl; return 0; diff --git a/vk_video_encoder/libs/VkVideoEncoder/VkEncoderConfig.cpp b/vk_video_encoder/libs/VkVideoEncoder/VkEncoderConfig.cpp index e0c97554..25e45cc6 100644 --- a/vk_video_encoder/libs/VkVideoEncoder/VkEncoderConfig.cpp +++ b/vk_video_encoder/libs/VkVideoEncoder/VkEncoderConfig.cpp @@ -27,6 +27,7 @@ void printHelp(VkVideoCodecOperationFlagBitsKHR codec) -i, --input .yuv Input YUV File Name (YUV420p 8bpp only) \n\ -o, --output .264/5,ivf Output H264/5/AV1 File Name \n\ -c, --codec select codec type: avc (h264) or hevc (h265) or av1\n\ + --logLevel : select the log level, default 1 for errors\n\ --dpbMode : select DPB mode: layered, separate\n\ --inputWidth : Input Width \n\ --inputHeight : Input Height \n\ @@ -136,6 +137,18 @@ int EncoderConfig::ParseArguments(int argc, char *argv[]) appName = args[0]; + // Double argument list handling to have the log level ready during the argument parsing. + for (int32_t i = 1; i < argc; i++) { + if (args[i] == "-l" || args[i] == "--logLevel") { + u_int32_t logLevel = LogLevel::INFO; + if ((++i >= argc) || (sscanf(args[i].c_str(), "%u", &logLevel) != 1)) { + fprintf(stderr, "invalid parameter for %s\n", args[i - 1].c_str()); + return -1; + } + Logger::instance().setLogLevel(logLevel); + } + } + for (int32_t i = 1; i < argc; i++) { if (args[i] == "-i" || args[i] == "--input") { @@ -175,8 +188,15 @@ int EncoderConfig::ParseArguments(int argc, char *argv[]) fprintf(stderr, "Invalid codec: %s\n", codec_.c_str()); return -1; } - printf("Selected codec: %s\n", codec_.c_str()); + LOG_S_INFO << "Selected codec: " << codec_ << std::endl; i++; // Skip the next argument since it's the codec value + } else if (args[i] == "-l" || args[i] == "--logLevel") { + u_int32_t logLevel = LogLevel::INFO; + if ((++i >= argc) || (sscanf(args[i].c_str(), "%u", &logLevel) != 1)) { + fprintf(stderr, "invalid parameter for %s\n", args[i - 1].c_str()); + return -1; + } + Logger::instance().setLogLevel(logLevel); } else if (args[i] == "--dpbMode") { std::string dpbMode = args[i + 1]; if (dpbMode == "separate") { @@ -188,7 +208,7 @@ int EncoderConfig::ParseArguments(int argc, char *argv[]) fprintf(stderr, "Invalid DPB mode: %s\n", dpbMode.c_str()); return -1; } - printf("Selected DPB mode: %s\n", dpbMode.c_str()); + LOG_S_INFO << "Selected DPB mode:" << dpbMode << std::endl; i++; // Skip the next argument since it's the dpbMode value } else if (args[i] == "--inputWidth") { if ((++i >= argc) || (sscanf(args[i].c_str(), "%u", &input.width) != 1)) { @@ -299,7 +319,7 @@ int EncoderConfig::ParseArguments(int argc, char *argv[]) return -1; } gopStructure.SetGopFrameCount(gopFrameCount); - printf("Selected gopFrameCount: %d\n", gopFrameCount); + LOG_S_INFO << "Selected gopFrameCount: " << gopFrameCount << std::endl; } else if (args[i] == "--idrPeriod") { int32_t idrPeriod = EncoderConfig::DEFAULT_GOP_IDR_PERIOD; if (++i >= argc || sscanf(args[i].c_str(), "%d", &idrPeriod) != 1) { @@ -307,7 +327,7 @@ int EncoderConfig::ParseArguments(int argc, char *argv[]) return -1; } gopStructure.SetIdrPeriod(idrPeriod); - printf("Selected idrPeriod: %d\n", idrPeriod); + LOG_S_INFO << "Selected idrPeriod: " << idrPeriod << std::endl; } else if (args[i] == "--consecutiveBFrameCount") { uint8_t consecutiveBFrameCount = EncoderConfig::DEFAULT_CONSECUTIVE_B_FRAME_COUNT; if (++i >= argc || sscanf(args[i].c_str(), "%hhu", &consecutiveBFrameCount) != 1) { @@ -315,7 +335,7 @@ int EncoderConfig::ParseArguments(int argc, char *argv[]) return -1; } gopStructure.SetConsecutiveBFrameCount(consecutiveBFrameCount); - printf("Selected consecutiveBFrameCount: %d\n", consecutiveBFrameCount); + LOG_S_INFO << "Selected consecutiveBFrameCount: " << consecutiveBFrameCount << std::endl; } else if (args[i] == "--temporalLayerCount") { uint8_t temporalLayerCount = EncoderConfig::DEFAULT_TEMPORAL_LAYER_COUNT; if (++i >= argc || sscanf(args[i].c_str(), "%hhu", &temporalLayerCount) != 1) { @@ -323,7 +343,7 @@ int EncoderConfig::ParseArguments(int argc, char *argv[]) return -1; } gopStructure.SetTemporalLayerCount(temporalLayerCount); - printf("Selected temporalLayerCount: %d\n", temporalLayerCount); + LOG_S_INFO << "Selected temporalLayerCount: " << temporalLayerCount << std::endl; } else if (args[i] == "--lastFrameType") { VkVideoGopStructure::FrameType lastFrameType = VkVideoGopStructure::FRAME_TYPE_P; std::string frameTypeName = args[i + 1]; @@ -340,7 +360,7 @@ int EncoderConfig::ParseArguments(int argc, char *argv[]) } i++; // Skip the next argument since it's the frameTypeName value gopStructure.SetLastFrameType(lastFrameType); - printf("Selected frameTypeName: %s\n", gopStructure.GetFrameTypeName(lastFrameType)); + LOG_S_INFO << "Selected frameTypeName: " << gopStructure.GetFrameTypeName(lastFrameType) << std::endl; } else if (args[i] == "--closedGop") { gopStructure.SetClosedGop(); } else if (args[i] == "--qualityLevel") { diff --git a/vk_video_encoder/libs/VkVideoEncoder/VkEncoderConfig.h b/vk_video_encoder/libs/VkVideoEncoder/VkEncoderConfig.h index b47e2e36..f6566a0e 100644 --- a/vk_video_encoder/libs/VkVideoEncoder/VkEncoderConfig.h +++ b/vk_video_encoder/libs/VkVideoEncoder/VkEncoderConfig.h @@ -31,6 +31,7 @@ #include "VkVideoEncoder/VkVideoGopStructure.h" #include "VkVideoCore/VkVideoCoreProfile.h" #include "VkVideoCore/VulkanVideoCapabilities.h" +#include "Logger.h" struct EncoderConfigH264; struct EncoderConfigH265; @@ -115,13 +116,13 @@ struct EncoderInputImageParameters bool VerifyInputs() { if ((width == 0) || (height == 0)) { - fprintf(stderr, "Invalid input width (%d) and/or height(%d) parameters!", width, height); + LOG_S_ERROR << "Invalid input width" << width << " and/or height" << height << " parameters!" << std::endl; return false; } uint32_t bytesPerPixel = (bpp + 7) / 8; if ((bytesPerPixel < 1) || (bytesPerPixel > 2)) { - fprintf(stderr, "Invalid input bpp (%d) parameter!", bpp); + LOG_S_ERROR << "Invalid input bpp parameter: " << bpp << std::endl; return false; } @@ -172,7 +173,7 @@ struct EncoderInputImageParameters (numPlanes == 2)); if (vkFormat == VK_FORMAT_UNDEFINED) { - fprintf(stderr, "Invalid input parameters!"); + LOG_S_ERROR << "Invalid input parameters!" << std::endl; return false; } @@ -202,8 +203,8 @@ class EncoderInputFileHandler m_memMapedFile.unmap(); if (m_fileHandle != nullptr) { - if (fclose(m_fileHandle)) { - fprintf(stderr, "Failed to close input file %s", m_fileName); + if(fclose(m_fileHandle)) { + LOG_S_ERROR << "Failed to close input file " << m_fileName << std::endl; } m_fileHandle = nullptr; @@ -260,7 +261,7 @@ class EncoderInputFileHandler const uint64_t mappedLength = (uint64_t)m_memMapedFile.mapped_length(); if (mappedLength < offset) { - printf("File overflow at fileOffset %lld\n", (long long unsigned int)offset); + LOG_S_ERROR << "File overflow at fileOffset " << offset << std::endl; assert(!"Input file overflow"); return nullptr; } @@ -394,20 +395,19 @@ class EncoderInputFileHandler { m_fileHandle = fopen(m_fileName, "rb"); if (m_fileHandle == nullptr) { - fprintf(stderr, "Failed to open input file %s", m_fileName); + LOG_S_ERROR << "Failed to open input file " << m_fileName << std::endl; return 0; } std::error_code error; m_memMapedFile.map(m_fileName, 0, mio::map_entire_file, error); if (error) { - fprintf(stderr, "Failed to map the input file %s", m_fileName); const auto& errmsg = error.message(); - std::printf("error mapping file: %s, exiting...\n", errmsg.c_str()); + LOG_S_ERROR << "Failed to map the input file: " << m_fileName << " with error msg: " << errmsg << std::endl; return error.value(); } - printf("Input file size is: %zd\n", m_memMapedFile.length()); + LOG_S_DEBUG << "Input file size is: " << m_memMapedFile.length() << std::endl; return m_memMapedFile.length(); } @@ -447,7 +447,7 @@ class EncoderOutputFileHandler if (m_fileHandle != nullptr) { if(fclose(m_fileHandle)) { - fprintf(stderr, "Failed to close output file %s", m_fileName); + LOG_S_ERROR << "Failed to close output file " << m_fileName << std::endl; } m_fileHandle = nullptr; @@ -493,7 +493,7 @@ class EncoderOutputFileHandler { m_fileHandle = fopen(m_fileName, "wb"); if (m_fileHandle == nullptr) { - fprintf(stderr, "Failed to open output file %s", m_fileName); + LOG_S_ERROR << "Failed to open output file " << m_fileName << std::endl; return 0; } @@ -533,7 +533,7 @@ class EncoderQpMapFileHandler if (m_fileHandle != nullptr) { if(fclose(m_fileHandle)) { - fprintf(stderr, "Failed to close input file %s", m_fileName); + LOG_S_ERROR << "Failed to close input file " << m_fileName << std::endl; } m_fileHandle = nullptr; @@ -574,7 +574,7 @@ class EncoderQpMapFileHandler const uint64_t mappedLength = (uint64_t)m_memMapedFile.mapped_length(); if (mappedLength < fileOffset) { - printf("File overflow at fileOffset %llu\n", (unsigned long long int)fileOffset); + LOG_S_ERROR << "File overflow at fileOffset " << fileOffset << std::endl; assert(!"Input file overflow"); return nullptr; } @@ -586,20 +586,19 @@ class EncoderQpMapFileHandler { m_fileHandle = fopen(m_fileName, "rb"); if (m_fileHandle == nullptr) { - fprintf(stderr, "Failed to open input file %s", m_fileName); + LOG_S_ERROR << "Failed to open input file " << m_fileName << std::endl; return 0; } std::error_code error; m_memMapedFile.map(m_fileName, 0, mio::map_entire_file, error); if (error) { - fprintf(stderr, "Failed to map the input file %s", m_fileName); const auto& errmsg = error.message(); - std::printf("error mapping file: %s, exiting...\n", errmsg.c_str()); + LOG_S_ERROR << "Failed to map input file " << m_fileName << " error: " << errmsg.c_str() << std::endl; return error.value(); } - printf("Input file size is: %zd\n", m_memMapedFile.length()); + LOG_S_INFO << "Input file size is:" << m_memMapedFile.length() << std::endl; return m_memMapedFile.length(); } @@ -708,7 +707,6 @@ struct EncoderConfig : public VkVideoRefCountBase { uint32_t validateVerbose : 1; uint32_t verbose : 1; uint32_t verboseFrameStruct : 1; - uint32_t verboseMsg : 1; uint32_t enableFramePresent : 1; uint32_t enableFrameDirectModePresent : 1; uint32_t enableVideoDecoder : 1; @@ -792,7 +790,6 @@ struct EncoderConfig : public VkVideoRefCountBase { , validateVerbose(false) , verbose(false) , verboseFrameStruct(false) - , verboseMsg(true) , enableFramePresent(false) , enableFrameDirectModePresent(false) , enableVideoDecoder(false) diff --git a/vk_video_encoder/libs/VkVideoEncoder/VkEncoderConfigAV1.cpp b/vk_video_encoder/libs/VkVideoEncoder/VkEncoderConfigAV1.cpp index 6050c004..1ea7ffd2 100644 --- a/vk_video_encoder/libs/VkVideoEncoder/VkEncoderConfigAV1.cpp +++ b/vk_video_encoder/libs/VkVideoEncoder/VkEncoderConfigAV1.cpp @@ -194,21 +194,21 @@ VkResult EncoderConfigAV1::InitDeviceCapabilities(const VulkanDeviceContext* vkD quantizationMapCapabilities, av1QuantizationMapCapabilities); if (result != VK_SUCCESS) { - std::cout << "*** Could not get video capabilities :" << result << " ***" << std::endl; + LOG_S_ERROR << "*** Could not get video capabilities :" << result << " ***" << std::endl; assert(!"Coult not get Video Capabilities!"); return result; } - if (verboseMsg) { - std::cout << "\t\t\t" << VkVideoCoreProfile::CodecToName(codec) << "encode capabilities: " << std::endl; - std::cout << "\t\t\t" << "minBitstreamBufferOffsetAlignment: " << videoCapabilities.minBitstreamBufferOffsetAlignment << std::endl; - std::cout << "\t\t\t" << "minBitstreamBufferSizeAlignment: " << videoCapabilities.minBitstreamBufferSizeAlignment << std::endl; - std::cout << "\t\t\t" << "pictureAccessGranularity: " << videoCapabilities.pictureAccessGranularity.width << " x " << videoCapabilities.pictureAccessGranularity.height << std::endl; - std::cout << "\t\t\t" << "minExtent: " << videoCapabilities.minCodedExtent.width << " x " << videoCapabilities.minCodedExtent.height << std::endl; - std::cout << "\t\t\t" << "maxExtent: " << videoCapabilities.maxCodedExtent.width << " x " << videoCapabilities.maxCodedExtent.height << std::endl; - std::cout << "\t\t\t" << "maxDpbSlots: " << videoCapabilities.maxDpbSlots << std::endl; - std::cout << "\t\t\t" << "maxActiveReferencePictures: " << videoCapabilities.maxActiveReferencePictures << std::endl; - } + + LOG_S_INFO << "\t\t\t" << VkVideoCoreProfile::CodecToName(codec) << "encode capabilities: " << std::endl; + LOG_S_INFO << "\t\t\t" << "minBitstreamBufferOffsetAlignment: " << videoCapabilities.minBitstreamBufferOffsetAlignment << std::endl; + LOG_S_INFO << "\t\t\t" << "minBitstreamBufferSizeAlignment: " << videoCapabilities.minBitstreamBufferSizeAlignment << std::endl; + LOG_S_INFO << "\t\t\t" << "pictureAccessGranularity: " << videoCapabilities.pictureAccessGranularity.width << " x " << videoCapabilities.pictureAccessGranularity.height << std::endl; + LOG_S_INFO << "\t\t\t" << "minExtent: " << videoCapabilities.minCodedExtent.width << " x " << videoCapabilities.minCodedExtent.height << std::endl; + LOG_S_INFO << "\t\t\t" << "maxExtent: " << videoCapabilities.maxCodedExtent.width << " x " << videoCapabilities.maxCodedExtent.height << std::endl; + LOG_S_INFO << "\t\t\t" << "maxDpbSlots: " << videoCapabilities.maxDpbSlots << std::endl; + LOG_S_INFO << "\t\t\t" << "maxActiveReferencePictures: " << videoCapabilities.maxActiveReferencePictures << std::endl; + return VK_SUCCESS; } diff --git a/vk_video_encoder/libs/VkVideoEncoder/VkEncoderConfigH264.cpp b/vk_video_encoder/libs/VkVideoEncoder/VkEncoderConfigH264.cpp index 3d76c7c8..df26383d 100644 --- a/vk_video_encoder/libs/VkVideoEncoder/VkEncoderConfigH264.cpp +++ b/vk_video_encoder/libs/VkVideoEncoder/VkEncoderConfigH264.cpp @@ -358,21 +358,21 @@ VkResult EncoderConfigH264::InitDeviceCapabilities(const VulkanDeviceContext* vk quantizationMapCapabilities, h264QuantizationMapCapabilities); if (result != VK_SUCCESS) { - std::cout << "*** Could not get Video Capabilities :" << result << " ***" << std::endl; + LOG_S_ERROR << "*** Could not get Video Capabilities :" << result << " ***" << std::endl; assert(!"Could not get Video Capabilities!"); return result; } - if (verboseMsg) { - std::cout << "\t\t\t" << VkVideoCoreProfile::CodecToName(codec) << "encode capabilities: " << std::endl; - std::cout << "\t\t\t" << "minBitstreamBufferOffsetAlignment: " << videoCapabilities.minBitstreamBufferOffsetAlignment << std::endl; - std::cout << "\t\t\t" << "minBitstreamBufferSizeAlignment: " << videoCapabilities.minBitstreamBufferSizeAlignment << std::endl; - std::cout << "\t\t\t" << "pictureAccessGranularity: " << videoCapabilities.pictureAccessGranularity.width << " x " << videoCapabilities.pictureAccessGranularity.height << std::endl; - std::cout << "\t\t\t" << "minExtent: " << videoCapabilities.minCodedExtent.width << " x " << videoCapabilities.minCodedExtent.height << std::endl; - std::cout << "\t\t\t" << "maxExtent: " << videoCapabilities.maxCodedExtent.width << " x " << videoCapabilities.maxCodedExtent.height << std::endl; - std::cout << "\t\t\t" << "maxDpbSlots: " << videoCapabilities.maxDpbSlots << std::endl; - std::cout << "\t\t\t" << "maxActiveReferencePictures: " << videoCapabilities.maxActiveReferencePictures << std::endl; - std::cout << "\t\t\t" << "maxBPictureL0ReferenceCount: " << h264EncodeCapabilities.maxBPictureL0ReferenceCount << std::endl; + if (verbose) { + LOG_S_INFO << "\t\t\t" << VkVideoCoreProfile::CodecToName(codec) << "encode capabilities: " << std::endl; + LOG_S_INFO << "\t\t\t" << "minBitstreamBufferOffsetAlignment: " << videoCapabilities.minBitstreamBufferOffsetAlignment << std::endl; + LOG_S_INFO << "\t\t\t" << "minBitstreamBufferSizeAlignment: " << videoCapabilities.minBitstreamBufferSizeAlignment << std::endl; + LOG_S_INFO << "\t\t\t" << "pictureAccessGranularity: " << videoCapabilities.pictureAccessGranularity.width << " x " << videoCapabilities.pictureAccessGranularity.height << std::endl; + LOG_S_INFO << "\t\t\t" << "minExtent: " << videoCapabilities.minCodedExtent.width << " x " << videoCapabilities.minCodedExtent.height << std::endl; + LOG_S_INFO << "\t\t\t" << "maxExtent: " << videoCapabilities.maxCodedExtent.width << " x " << videoCapabilities.maxCodedExtent.height << std::endl; + LOG_S_INFO << "\t\t\t" << "maxDpbSlots: " << videoCapabilities.maxDpbSlots << std::endl; + LOG_S_INFO << "\t\t\t" << "maxActiveReferencePictures: " << videoCapabilities.maxActiveReferencePictures << std::endl; + LOG_S_INFO << "\t\t\t" << "maxBPictureL0ReferenceCount: " << h264EncodeCapabilities.maxBPictureL0ReferenceCount << std::endl; } return VK_SUCCESS; diff --git a/vk_video_encoder/libs/VkVideoEncoder/VkEncoderConfigH265.cpp b/vk_video_encoder/libs/VkVideoEncoder/VkEncoderConfigH265.cpp index 817fda82..10cd7a5f 100644 --- a/vk_video_encoder/libs/VkVideoEncoder/VkEncoderConfigH265.cpp +++ b/vk_video_encoder/libs/VkVideoEncoder/VkEncoderConfigH265.cpp @@ -78,21 +78,21 @@ VkResult EncoderConfigH265::InitDeviceCapabilities(const VulkanDeviceContext* vk quantizationMapCapabilities, h265QuantizationMapCapabilities); if (result != VK_SUCCESS) { - std::cout << "*** Could not get Video Capabilities :" << result << " ***" << std::endl; + LOG_S_ERROR << "*** Could not get Video Capabilities :" << result << " ***" << std::endl; assert(!"Could not get Video Capabilities!"); return result; } - if (verboseMsg) { - std::cout << "\t\t\t" << VkVideoCoreProfile::CodecToName(codec) << "encode capabilities: " << std::endl; - std::cout << "\t\t\t" << "minBitstreamBufferOffsetAlignment: " << videoCapabilities.minBitstreamBufferOffsetAlignment << std::endl; - std::cout << "\t\t\t" << "minBitstreamBufferSizeAlignment: " << videoCapabilities.minBitstreamBufferSizeAlignment << std::endl; - std::cout << "\t\t\t" << "pictureAccessGranularity: " << videoCapabilities.pictureAccessGranularity.width << " x " << videoCapabilities.pictureAccessGranularity.height << std::endl; - std::cout << "\t\t\t" << "minExtent: " << videoCapabilities.minCodedExtent.width << " x " << videoCapabilities.minCodedExtent.height << std::endl; - std::cout << "\t\t\t" << "maxExtent: " << videoCapabilities.maxCodedExtent.width << " x " << videoCapabilities.maxCodedExtent.height << std::endl; - std::cout << "\t\t\t" << "maxDpbSlots: " << videoCapabilities.maxDpbSlots << std::endl; - std::cout << "\t\t\t" << "maxActiveReferencePictures: " << videoCapabilities.maxActiveReferencePictures << std::endl; - std::cout << "\t\t\t" << "maxBPictureL0ReferenceCount: " << h265EncodeCapabilities.maxBPictureL0ReferenceCount << std::endl; + if (verbose) { + LOG_S_INFO << "\t\t\t" << VkVideoCoreProfile::CodecToName(codec) << "encode capabilities: " << std::endl; + LOG_S_INFO << "\t\t\t" << "minBitstreamBufferOffsetAlignment: " << videoCapabilities.minBitstreamBufferOffsetAlignment << std::endl; + LOG_S_INFO << "\t\t\t" << "minBitstreamBufferSizeAlignment: " << videoCapabilities.minBitstreamBufferSizeAlignment << std::endl; + LOG_S_INFO << "\t\t\t" << "pictureAccessGranularity: " << videoCapabilities.pictureAccessGranularity.width << " x " << videoCapabilities.pictureAccessGranularity.height << std::endl; + LOG_S_INFO << "\t\t\t" << "minExtent: " << videoCapabilities.minCodedExtent.width << " x " << videoCapabilities.minCodedExtent.height << std::endl; + LOG_S_INFO << "\t\t\t" << "maxExtent: " << videoCapabilities.maxCodedExtent.width << " x " << videoCapabilities.maxCodedExtent.height << std::endl; + LOG_S_INFO << "\t\t\t" << "maxDpbSlots: " << videoCapabilities.maxDpbSlots << std::endl; + LOG_S_INFO << "\t\t\t" << "maxActiveReferencePictures: " << videoCapabilities.maxActiveReferencePictures << std::endl; + LOG_S_INFO << "\t\t\t" << "maxBPictureL0ReferenceCount: " << h265EncodeCapabilities.maxBPictureL0ReferenceCount << std::endl; } return VK_SUCCESS; @@ -586,11 +586,10 @@ bool EncoderConfigH265::InitParamameters(VpsH265 *vpsInfo, SpsH265 *spsInfo, // pic_height_in_luma_samples shall not be equal to 0 and shall be an integer multiple of MinCbSizeY. spsInfo->sps.pic_height_in_luma_samples = picHeightAlignedToMinCbsY; - if (verbose) { - std::cout << "sps.pic_width_in_luma_samples: " << spsInfo->sps.pic_width_in_luma_samples - << ", sps.pic_height_in_luma_samples: " << spsInfo->sps.pic_height_in_luma_samples - << ", cuSize: " << (uint32_t)cuSize << ", cuMinSize: " << (uint32_t)cuMinSize << std::endl; - } + + LOG_S_DEBUG << "sps.pic_width_in_luma_samples: " << spsInfo->sps.pic_width_in_luma_samples + << ", sps.pic_height_in_luma_samples: " << spsInfo->sps.pic_height_in_luma_samples + << ", cuSize: " << (uint32_t)cuSize << ", cuMinSize: " << (uint32_t)cuMinSize << std::endl; spsInfo->sps.sps_video_parameter_set_id = vpsId; spsInfo->sps.sps_max_sub_layers_minus1 = 0; @@ -609,8 +608,8 @@ bool EncoderConfigH265::InitParamameters(VpsH265 *vpsInfo, SpsH265 *spsInfo, spsInfo->sps.log2_min_pcm_luma_coding_block_size_minus3 = (uint8_t)(minCbLog2SizeY - 3); spsInfo->sps.log2_diff_max_min_pcm_luma_coding_block_size = (uint8_t)(ctbLog2SizeY - minCbLog2SizeY); - if (verbose) { - std::cout << "sps.log2_min_luma_coding_block_size_minus3: " << (uint32_t)spsInfo->sps.log2_min_luma_coding_block_size_minus3 + + LOG_S_DEBUG << "sps.log2_min_luma_coding_block_size_minus3: " << (uint32_t)spsInfo->sps.log2_min_luma_coding_block_size_minus3 << ", sps.log2_diff_max_min_luma_coding_block_size: " << (uint32_t)spsInfo->sps.log2_diff_max_min_luma_coding_block_size << ", sps.log2_min_luma_transform_block_size_minus2: " << (uint32_t)spsInfo->sps.log2_min_luma_transform_block_size_minus2 << ", sps.log2_diff_max_min_luma_transform_block_size: " << (uint32_t)spsInfo->sps.log2_diff_max_min_luma_transform_block_size @@ -618,7 +617,6 @@ bool EncoderConfigH265::InitParamameters(VpsH265 *vpsInfo, SpsH265 *spsInfo, << ", sps.log2_min_pcm_luma_coding_block_size_minus3: " << (uint32_t)spsInfo->sps.log2_min_pcm_luma_coding_block_size_minus3 << ", sps.log2_diff_max_min_pcm_luma_coding_block_size: " << (uint32_t)spsInfo->sps.log2_diff_max_min_pcm_luma_coding_block_size << std::endl; - } const bool padToCtbSize = true; if (padToCtbSize) { @@ -635,14 +633,13 @@ bool EncoderConfigH265::InitParamameters(VpsH265 *vpsInfo, SpsH265 *spsInfo, (spsInfo->sps.conf_win_top_offset != 0) || (spsInfo->sps.conf_win_bottom_offset != 0)); - if (verbose) { - std::cout << "sps.conf_win_left_offset: " << spsInfo->sps.conf_win_left_offset - << ", sps.conf_win_right_offset: " << spsInfo->sps.conf_win_right_offset - << ", sps.conf_win_top_offset: " << spsInfo->sps.conf_win_top_offset - << ", sps.conf_win_bottom_offset: " << spsInfo->sps.conf_win_bottom_offset - << ", sps.flags.conformance_window_flag: " << spsInfo->sps.flags.conformance_window_flag - << std::endl; - } + + LOG_S_DEBUG << "sps.conf_win_left_offset: " << spsInfo->sps.conf_win_left_offset + << ", sps.conf_win_right_offset: " << spsInfo->sps.conf_win_right_offset + << ", sps.conf_win_top_offset: " << spsInfo->sps.conf_win_top_offset + << ", sps.conf_win_bottom_offset: " << spsInfo->sps.conf_win_bottom_offset + << ", sps.flags.conformance_window_flag: " << spsInfo->sps.flags.conformance_window_flag + << std::endl; spsInfo->sps.pScalingLists = NULL; diff --git a/vk_video_encoder/libs/VkVideoEncoder/VkEncoderDpbH265.cpp b/vk_video_encoder/libs/VkVideoEncoder/VkEncoderDpbH265.cpp index e873e009..8b3ed72d 100644 --- a/vk_video_encoder/libs/VkVideoEncoder/VkEncoderDpbH265.cpp +++ b/vk_video_encoder/libs/VkVideoEncoder/VkEncoderDpbH265.cpp @@ -23,6 +23,7 @@ #include #include "VkEncoderDpbH265.h" +#include "Logger.h" template static inline T clampl(T value, T minbound) { @@ -306,7 +307,7 @@ void VkEncDpbH265::ApplyReferencePictureSet(const StdVideoEncodeH265PictureInfo } if (numRefPics > (m_dpbSize - 1)) { - printf("too many reference frames (%d, max is %d)\n", numRefPics, (m_dpbSize - 1)); + LOG_S_WARN << "too many reference frames" << numRefPics << ", max is " << (m_dpbSize - 1) << std::endl; } assert(numRefPics <= STD_VIDEO_H265_MAX_NUM_LIST_REF); @@ -410,7 +411,7 @@ void VkEncDpbH265::ApplyReferencePictureSet(const StdVideoEncodeH265PictureInfo } } if (pRefPicSet->ltCurr[i] < 0) - printf("long-term reference picture not available (POC=%d)\n", pocLtCurr[i]); + LOG_S_WARN << "long-term reference picture not available POC=" << pocLtCurr[i] << std::endl; } for (int32_t i = 0; i < m_numPocLtFoll; i++) { @@ -454,7 +455,7 @@ void VkEncDpbH265::ApplyReferencePictureSet(const StdVideoEncodeH265PictureInfo } } if (pRefPicSet->stCurrBefore[i] < 0) - printf("short-term reference picture not available (POC=%d)\n", pocStCurrBefore[i]); + LOG_S_WARN << "short-term reference picture not available POC=" << pocStCurrBefore[i] << std::endl; } for (int32_t i = 0; i < m_numPocStCurrAfter; i++) { @@ -466,7 +467,7 @@ void VkEncDpbH265::ApplyReferencePictureSet(const StdVideoEncodeH265PictureInfo } } if (pRefPicSet->stCurrAfter[i] < 0) - printf("short-term reference picture not available (POC=%d)\n", pocStCurrAfter[i]); + LOG_S_WARN << "short-term reference picture not available POC=" << pocStCurrAfter[i] << std::endl; } for (int32_t i = 0; i < m_numPocStFoll; i++) { diff --git a/vk_video_encoder/libs/VkVideoEncoder/VkVideoEncoder.cpp b/vk_video_encoder/libs/VkVideoEncoder/VkVideoEncoder.cpp index bab27757..acc69767 100644 --- a/vk_video_encoder/libs/VkVideoEncoder/VkVideoEncoder.cpp +++ b/vk_video_encoder/libs/VkVideoEncoder/VkVideoEncoder.cpp @@ -411,17 +411,17 @@ VkResult VkVideoEncoder::AssembleBitstreamData(VkSharedBaseObjoutputFileHandler.GetFileHandle()); if (m_encoderConfig->verboseFrameStruct) { - std::cout << " == Non-Vcl data " << (nonVcl ? "SUCCESS" : "FAIL") - << " File Output non-VCL data with size: " << encodeFrameInfo->bitstreamHeaderBufferSize - << ", Input Order: " << encodeFrameInfo->gopPosition.inputOrder - << ", Encode Order: " << encodeFrameInfo->gopPosition.encodeOrder - << std::endl << std::flush; + LOG_S_DEBUG << " == Non-Vcl data " << (nonVcl ? "SUCCESS" : "FAIL") + << " File Output non-VCL data with size: " << encodeFrameInfo->bitstreamHeaderBufferSize + << ", Input Order: " << encodeFrameInfo->gopPosition.inputOrder + << ", Encode Order: " << encodeFrameInfo->gopPosition.encodeOrder + << std::endl << std::flush; } } VkResult result = encodeFrameInfo->encodeCmdBuffer->SyncHostOnCmdBuffComplete(false, "encoderEncodeFence"); if(result != VK_SUCCESS) { - fprintf(stderr, "\nWait on encoder complete fence has failed with result 0x%x.\n", result); + LOG_S_ERROR << "Wait on encoder complete fence has failed with result 0x" << result << std::endl; return result; } @@ -447,14 +447,16 @@ VkResult VkVideoEncoder::AssembleBitstreamData(VkSharedBaseObjoutputFileHandler.GetFileHandle()); if (m_encoderConfig->verboseFrameStruct) { - std::cout << " == Output VCL data " << (vcl ? "SUCCESS" : "FAIL") << " with size: " << encodeResult.bitstreamSize - << " and offset: " << encodeResult.bitstreamStartOffset - << ", Input Order: " << encodeFrameInfo->gopPosition.inputOrder - << ", Encode Order: " << encodeFrameInfo->gopPosition.encodeOrder << std::endl << std::flush; + LOG_S_DEBUG << " == Output VCL data " << (vcl ? "SUCCESS" : "FAIL") << " with size: " << encodeResult.bitstreamSize + << " and offset: " << encodeResult.bitstreamStartOffset + << ", Input Order: " << encodeFrameInfo->gopPosition.inputOrder + << ", Encode Order: " << encodeFrameInfo->gopPosition.encodeOrder << std::endl << std::flush; } return result; } @@ -480,7 +482,7 @@ VkResult VkVideoEncoder::InitEncoder(VkSharedBaseObj& encoderConf if (!VulkanVideoCapabilities::IsCodecTypeSupported(m_vkDevCtx, m_vkDevCtx->GetVideoEncodeQueueFamilyIdx(), encoderConfig->codec)) { - std::cout << "*** The video codec " << VkVideoCoreProfile::CodecToName(encoderConfig->codec) << " is not supported! ***" << std::endl; + LOG_S_ERROR << "*** The video codec " << VkVideoCoreProfile::CodecToName(encoderConfig->codec) << " is not supported! ***" << std::endl; assert(!"The video codec is not supported"); return VK_ERROR_INITIALIZATION_FAILED; } @@ -494,21 +496,21 @@ VkResult VkVideoEncoder::InitEncoder(VkSharedBaseObj& encoderConf if (encoderConfig->useDpbArray == false && (encoderConfig->videoCapabilities.flags & VK_VIDEO_CAPABILITY_SEPARATE_REFERENCE_IMAGES_BIT_KHR) == 0) { - std::cout << "Separate DPB was requested, but the implementation does not support it!" << std::endl; - std::cout << "Fallback to layered DPB!" << std::endl; + LOG_S_WARN << "Separate DPB was requested, but the implementation does not support it!" << std::endl; + LOG_S_WARN<< "Fallback to layered DPB!" << std::endl; encoderConfig->useDpbArray = true; } if (m_encoderConfig->enableQpMap) { if ((m_encoderConfig->qpMapMode == EncoderConfig::DELTA_QP_MAP) && ((m_encoderConfig->videoEncodeCapabilities.flags & VK_VIDEO_ENCODE_CAPABILITY_QUANTIZATION_DELTA_MAP_BIT_KHR) == 0)) { - std::cout << "Delta QP Map was requested, but the implementation does not support it!" << std::endl; + LOG_S_ERROR << "Delta QP Map was requested, but the implementation does not support it!" << std::endl; assert(!"Delta QP Map is not supported"); return VK_ERROR_INITIALIZATION_FAILED; } if ((m_encoderConfig->qpMapMode == EncoderConfig::EMPHASIS_MAP) && ((m_encoderConfig->videoEncodeCapabilities.flags & VK_VIDEO_ENCODE_CAPABILITY_EMPHASIS_MAP_BIT_KHR) == 0)) { - std::cout << "Emphasis Map was requested, but the implementation does not support it!" << std::endl; + LOG_S_ERROR << "Emphasis Map was requested, but the implementation does not support it!" << std::endl; assert(!"Emphasis QP Map is not supported"); return VK_ERROR_INITIALIZATION_FAILED; } @@ -519,14 +521,14 @@ VkResult VkVideoEncoder::InitEncoder(VkSharedBaseObj& encoderConf // gopStructure.Init() should be called after encoderConfig->InitDeviceCapabilities(). m_encoderConfig->gopStructure.Init(m_encoderConfig->numFrames); if (encoderConfig->GetMaxBFrameCount() < m_encoderConfig->gopStructure.GetConsecutiveBFrameCount()) { - std::cout << "Max consecutive B frames: " << (uint32_t)encoderConfig->GetMaxBFrameCount() << " lower than the configured one: " << (uint32_t)m_encoderConfig->gopStructure.GetConsecutiveBFrameCount() << std::endl; - std::cout << "Fallback to the max value: " << (uint32_t)m_encoderConfig->gopStructure.GetConsecutiveBFrameCount() << std::endl; + LOG_S_INFO << "Max consecutive B frames: " << (uint32_t)encoderConfig->GetMaxBFrameCount() << " lower than the configured one: " << (uint32_t)m_encoderConfig->gopStructure.GetConsecutiveBFrameCount() << std::endl; + LOG_S_INFO << "Fallback to the max value: " << (uint32_t)m_encoderConfig->gopStructure.GetConsecutiveBFrameCount() << std::endl; m_encoderConfig->gopStructure.SetConsecutiveBFrameCount(encoderConfig->GetMaxBFrameCount()); } - std::cout << std::endl << "GOP frame count: " << (uint32_t)m_encoderConfig->gopStructure.GetGopFrameCount(); - std::cout << ", IDR period: " << (uint32_t)m_encoderConfig->gopStructure.GetIdrPeriod(); - std::cout << ", Consecutive B frames: " << (uint32_t)m_encoderConfig->gopStructure.GetConsecutiveBFrameCount(); - std::cout << std::endl; + LOG_S_INFO << std::endl << "GOP frame count: " << (uint32_t)m_encoderConfig->gopStructure.GetGopFrameCount(); + LOG_S_INFO << ", IDR period: " << (uint32_t)m_encoderConfig->gopStructure.GetIdrPeriod(); + LOG_S_INFO << ", Consecutive B frames: " << (uint32_t)m_encoderConfig->gopStructure.GetConsecutiveBFrameCount(); + LOG_S_INFO << std::endl; const uint64_t maxFramesToDump = std::min(m_encoderConfig->numFrames, m_encoderConfig->gopStructure.GetGopFrameCount() + 19); m_encoderConfig->gopStructure.PrintGopStructure(maxFramesToDump); @@ -566,7 +568,7 @@ VkResult VkVideoEncoder::InitEncoder(VkSharedBaseObj& encoderConf formatCount, supportedDpbFormats); if(result != VK_SUCCESS) { - fprintf(stderr, "\nInitEncoder Error: Failed to get desired video format for the decoded picture buffer.\n"); + LOG_S_ERROR << "InitEncoder Error: Failed to get desired video format for the decoded picture buffer." << std::endl; return result; } @@ -575,7 +577,7 @@ VkResult VkVideoEncoder::InitEncoder(VkSharedBaseObj& encoderConf formatCount, supportedInFormats); if(result != VK_SUCCESS) { - fprintf(stderr, "\nInitEncoder Error: Failed to get desired video format for input images.\n"); + LOG_S_ERROR << "InitEncoder Error: Failed to get desired video format for input images." << std::endl; return result; } @@ -661,7 +663,7 @@ VkResult VkVideoEncoder::InitEncoder(VkSharedBaseObj& encoderConf result = VulkanVideoImagePool::Create(m_vkDevCtx, m_linearInputImagePool); if(result != VK_SUCCESS) { - fprintf(stderr, "\nInitEncoder Error: Failed to create linearInputImagePool.\n"); + LOG_S_ERROR << "InitEncoder Error: Failed to create linearInputImagePool." << std::endl; return result; } @@ -687,13 +689,13 @@ VkResult VkVideoEncoder::InitEncoder(VkSharedBaseObj& encoderConf true // useLinear ); if(result != VK_SUCCESS) { - fprintf(stderr, "\nInitEncoder Error: Failed to Configure linearInputImagePool.\n"); + LOG_S_ERROR << "InitEncoder Error: Failed to Configure linearInputImagePool." << std::endl; return result; } result = VulkanVideoImagePool::Create(m_vkDevCtx, m_inputImagePool); if(result != VK_SUCCESS) { - fprintf(stderr, "\nInitEncoder Error: Failed to create inputImagePool.\n"); + LOG_S_ERROR << "InitEncoder Error: Failed to create inputImagePool." << std::endl; return result; } @@ -715,7 +717,7 @@ VkResult VkVideoEncoder::InitEncoder(VkSharedBaseObj& encoderConf false // useLinear ); if(result != VK_SUCCESS) { - fprintf(stderr, "\nInitEncoder Error: Failed to Configure inputImagePool.\n"); + LOG_S_ERROR << "InitEncoder Error: Failed to Configure inputImagePool." << std::endl; return result; } @@ -787,7 +789,7 @@ VkResult VkVideoEncoder::InitEncoder(VkSharedBaseObj& encoderConf result = VulkanVideoImagePool::Create(m_vkDevCtx, m_dpbImagePool); if(result != VK_SUCCESS) { - fprintf(stderr, "\nInitEncoder Error: Failed to create dpbImagePool.\n"); + LOG_S_ERROR << "InitEncoder Error: Failed to create dpbImagePool." << std::endl; return result; } @@ -805,7 +807,7 @@ VkResult VkVideoEncoder::InitEncoder(VkSharedBaseObj& encoderConf false // useLinear ); if(result != VK_SUCCESS) { - fprintf(stderr, "\nInitEncoder Error: Failed to Configure inputImagePool.\n"); + LOG_S_ERROR << "InitEncoder Error: Failed to Configure inputImagePool." << std::endl; return result; } @@ -833,7 +835,7 @@ VkResult VkVideoEncoder::InitEncoder(VkSharedBaseObj& encoderConf nullptr, 0, bitstreamBuffer); assert(result == VK_SUCCESS); if (result != VK_SUCCESS) { - fprintf(stderr, "\nERROR: VulkanBitstreamBufferImpl::Create() result: 0x%x\n", result); + LOG_S_ERROR << "ERROR: VulkanBitstreamBufferImpl::Create() result: 0x" << result << std::endl; break; } @@ -847,7 +849,7 @@ VkResult VkVideoEncoder::InitEncoder(VkSharedBaseObj& encoderConf result = VulkanCommandBufferPool::Create(m_vkDevCtx, m_inputCommandBufferPool); if(result != VK_SUCCESS) { - fprintf(stderr, "\nInitEncoder Error: Failed to create m_inputCommandBufferPool.\n"); + LOG_S_ERROR << "InitEncoder Error: Failed to create m_inputCommandBufferPool." << std::endl; return result; } @@ -862,13 +864,13 @@ VkResult VkVideoEncoder::InitEncoder(VkSharedBaseObj& encoderConf true // createFences ); if(result != VK_SUCCESS) { - fprintf(stderr, "\nInitEncoder Error: Failed to Configure m_inputCommandBufferPool.\n"); + LOG_S_ERROR << "InitEncoder Error: Failed to Configure m_inputCommandBufferPool." << std::endl; return result; } result = VulkanCommandBufferPool::Create(m_vkDevCtx, m_encodeCommandBufferPool); if(result != VK_SUCCESS) { - fprintf(stderr, "\nInitEncoder Error: Failed to create m_encodeCommandBufferPool.\n"); + LOG_S_ERROR << "InitEncoder Error: Failed to create m_encodeCommandBufferPool." << std::endl; return result; } @@ -888,13 +890,13 @@ VkResult VkVideoEncoder::InitEncoder(VkSharedBaseObj& encoderConf true // createFences ); if(result != VK_SUCCESS) { - fprintf(stderr, "\nInitEncoder Error: Failed to Configure m_encodeCommandBufferPool.\n"); + LOG_S_ERROR << "InitEncoder Error: Failed to Configure m_encodeCommandBufferPool." << std::endl; return result; } result = CreateFrameInfoBuffersQueue(encoderConfig->numInputImages); if(result != VK_SUCCESS) { - fprintf(stderr, "\nInitEncoder Error: Failed to create FrameInfoBuffersQueue.\n"); + LOG_S_ERROR << "InitEncoder Error: Failed to create FrameInfoBuffersQueue." << std::endl; return result; } @@ -932,11 +934,11 @@ VkDeviceSize VkVideoEncoder::GetBitstreamBuffer(VkSharedBaseObjMemsetData(0x0, copySize, newSize - copySize); #endif if (debugBitstreamBufferDumpAlloc) { - std::cout << "\t\tFrom bitstream buffer pool with size " << newSize << " B, " << + LOG_S_DEBUG << "\t\tFrom bitstream buffer pool with size " << newSize << " B, " << newSize/1024 << " KB, " << newSize/1024/1024 << " MB" << std::endl; - std::cout << "\t\t\t FreeNodes " << m_bitstreamBuffersQueue.GetFreeNodesNumber(); - std::cout << " of MaxNodes " << m_bitstreamBuffersQueue.GetMaxNodes(); - std::cout << ", AvailableNodes " << m_bitstreamBuffersQueue.GetAvailableNodesNumber(); - std::cout << std::endl; + LOG_S_DEBUG << "\t\t\t FreeNodes " << m_bitstreamBuffersQueue.GetFreeNodesNumber(); + LOG_S_DEBUG << " of MaxNodes " << m_bitstreamBuffersQueue.GetMaxNodes(); + LOG_S_DEBUG << ", AvailableNodes " << m_bitstreamBuffersQueue.GetAvailableNodesNumber(); + LOG_S_DEBUG << std::endl; } } bitstreamBuffer = newBitstreamBuffer; if (newSize > m_streamBufferSize) { - std::cout << "\tAllocated bitstream buffer with size " << newSize << " B, " << + LOG_S_INFO << "\tAllocated bitstream buffer with size " << newSize << " B, " << newSize/1024 << " KB, " << newSize/1024/1024 << " MB" << std::endl; m_streamBufferSize = (size_t)newSize; } @@ -1443,10 +1445,8 @@ VkResult VkVideoEncoder::ProcessOrderedFrames(VkSharedBaseObjverbose) { - const std::string& description = pair.first; - std::cout << "====== Total number of frames processed by " << description << ": " << processedFramesCount << " : " << result << std::endl; - } + const std::string& description = pair.first; + LOG_S_DEBUG << "====== Total number of frames processed by " << description << ": " << processedFramesCount << " : " << result << std::endl; if (result != VK_SUCCESS) { break; @@ -1493,7 +1493,7 @@ void VkVideoEncoder::DumpStateInfo(const char* stageName, uint32_t ident, VkSharedBaseObj& encodeFrameInfo, int32_t frameIdx, uint32_t ofTotalFrames) const { - std::cout << std::string(ident, ' ') << "===> " + LOG_S_DEBUG << std::string(ident, ' ') << "===> " << VkVideoCoreProfile::CodecToName(m_encoderConfig->codec) << ": " << stageName << " [" << frameIdx << " of " << ofTotalFrames << "]" << " type " << VkVideoGopStructure::GetFrameTypeName(encodeFrameInfo->gopPosition.pictureType) @@ -1545,12 +1545,12 @@ int32_t VkVideoEncoder::DeinitEncoder() void VkVideoEncoder::ConsumerThread() { - std::cout << "ConsumerThread is stating now.\n" << std::endl; + LOG_S_DEBUG << "ConsumerThread is stating now.\n" << std::endl; do { VkSharedBaseObj encodeFrameInfo; bool success = m_encoderThreadQueue.WaitAndPop(encodeFrameInfo); if (success) { // 5 seconds in nanoseconds - std::cout << "==>>>> Consumed: " << (uint32_t)encodeFrameInfo->gopPosition.inputOrder + LOG_S_DEBUG << "==>>>> Consumed: " << (uint32_t)encodeFrameInfo->gopPosition.inputOrder << ", Order: " << (uint32_t)encodeFrameInfo->gopPosition.encodeOrder << std::endl << std::flush; VkResult result; @@ -1563,15 +1563,15 @@ void VkVideoEncoder::ConsumerThread() VkVideoEncodeFrameInfo::ReleaseChildrenFrames(encodeFrameInfo); assert(encodeFrameInfo == nullptr); if (result != VK_SUCCESS) { - std::cout << "Error processing frames from the frame thread!" << std::endl; + LOG_S_ERROR << "Error processing frames from the frame thread!" << std::endl; m_encoderThreadQueue.SetFlushAndExit(); } } else { bool shouldExit = m_encoderThreadQueue.ExitQueue(); - std::cout << "Thread should exit: " << (shouldExit ? "Yes" : "No") << std::endl; + LOG_S_DEBUG << "Thread should exit: " << (shouldExit ? "Yes" : "No") << std::endl; } } while (!m_encoderThreadQueue.ExitQueue()); - std::cout << "ConsumerThread is exiting now.\n" << std::endl; + LOG_S_DEBUG << "ConsumerThread is exiting now.\n" << std::endl; } diff --git a/vk_video_encoder/libs/VkVideoEncoder/VkVideoEncoderAV1.cpp b/vk_video_encoder/libs/VkVideoEncoder/VkVideoEncoderAV1.cpp index 042666ad..f3c21e18 100644 --- a/vk_video_encoder/libs/VkVideoEncoder/VkVideoEncoderAV1.cpp +++ b/vk_video_encoder/libs/VkVideoEncoder/VkVideoEncoderAV1.cpp @@ -83,7 +83,7 @@ VkResult VkVideoEncoderAV1::InitEncoderCodec(VkSharedBaseObj& enc VkResult result = InitEncoder(encoderConfig); if (result != VK_SUCCESS) { - fprintf(stderr, "\nERROR: InitEncoder() failed with ret(%d)\n", result); + LOG_S_ERROR << "ERROR: InitEncoder() failed with ret: " << result << std::endl; return result; } @@ -92,7 +92,7 @@ VkResult VkVideoEncoderAV1::InitEncoderCodec(VkSharedBaseObj& enc encodeCaps.maxSingleReferenceCount < 2 && encodeCaps.maxUnidirectionalCompoundReferenceCount == 0 && encodeCaps.maxBidirectionalCompoundReferenceCount == 0) { - std::cout << "B-frames were requested but the implementation does not support multiple reference frames!" << std::endl; + LOG_S_INFO << "B-frames were requested but the implementation does not support multiple reference frames!" << std::endl; assert(!"B-frames not supported"); return VK_ERROR_INITIALIZATION_FAILED; } @@ -117,14 +117,14 @@ VkResult VkVideoEncoderAV1::InitEncoderCodec(VkSharedBaseObj& enc nullptr, &sessionParameters); if (result != VK_SUCCESS) { - fprintf(stderr, "\nEncodeFrame Error: Failed to get create video session parameters.\n"); + LOG_S_ERROR << "EncodeFrame Error: Failed to get create video session parameters." << std::endl; return result; } result = VulkanVideoSessionParameters::Create(m_vkDevCtx, m_videoSession, sessionParameters, m_videoSessionParameters); if (result != VK_SUCCESS) { - fprintf(stderr, "\nEncodeFrame Error: Failed to get create video session object.\n"); + LOG_S_ERROR << "EncodeFrame Error: Failed to get create video session object." << std::endl; return result; } @@ -493,7 +493,7 @@ VkResult VkVideoEncoderAV1::EncodeFrame(VkSharedBaseObj& DumpStateInfo("input", 1, encodeFrameInfo); if (encodeFrameInfo->lastFrame) { - std::cout << "#### It is the last frame: " << encodeFrameInfo->frameInputOrderNum + LOG_S_INFO << "#### It is the last frame: " << encodeFrameInfo->frameInputOrderNum << " of type " << VkVideoGopStructure::GetFrameTypeName(encodeFrameInfo->gopPosition.pictureType) << " ###" << std::endl << std::flush; @@ -834,7 +834,7 @@ VkResult VkVideoEncoderAV1::AssembleBitstreamData(VkSharedBaseObjencodeCmdBuffer->SyncHostOnCmdBuffComplete(false, "encoderEncodeFence"); if(result != VK_SUCCESS) { - fprintf(stderr, "\nWait on encoder complete fence has failed with result 0x%x.\n", result); + LOG_S_ERROR << "Wait on encoder complete fence has failed with result 0x" << result << std::endl; return result; } @@ -862,7 +862,7 @@ VkResult VkVideoEncoderAV1::AssembleBitstreamData(VkSharedBaseObjverboseFrameStruct) { - std::cout << " == Output VCL data SUCCESS for " << frameIdx << " with size: " << encodeResult.bitstreamSize + LOG_S_DEBUG << " == Output VCL data SUCCESS for " << frameIdx << " with size: " << encodeResult.bitstreamSize << " and offset: " << encodeResult.bitstreamStartOffset << ", Input Order: " << (uint32_t)encodeFrameInfo->gopPosition.inputOrder << ", Encode Order: " << (uint32_t)encodeFrameInfo->gopPosition.encodeOrder << std::endl << std::flush; @@ -922,13 +922,13 @@ VkResult VkVideoEncoderAV1::AssembleBitstreamData(VkSharedBaseObjverboseFrameStruct) { - std::cout << ">>>>>> Assembly VCL index " << curIndex << " has size: " << frameSize + LOG_S_DEBUG << ">>>>>> Assembly VCL index " << curIndex << " has size: " << frameSize << std::endl << std::flush; } } if (m_encoderConfig->verboseFrameStruct) { - std::cout << ">>>>>> Assembly total VCL data at " << frameIdx << " is: " + LOG_S_DEBUG << ">>>>>> Assembly total VCL data at " << frameIdx << " is: " << framesSize - (2 + encodeFrameInfo->bitstreamHeaderBufferSize) << std::endl << std::flush; } @@ -957,7 +957,7 @@ VkResult VkVideoEncoderAV1::AssembleBitstreamData(VkSharedBaseObjoutputFileHandler.GetFileHandle()); if (m_encoderConfig->verboseFrameStruct) { - std::cout << " == Non-Vcl data " << (nonVcl ? "SUCCESS" : "FAIL") + LOG_S_DEBUG << " == Non-Vcl data " << (nonVcl ? "SUCCESS" : "FAIL") << " File Output non-VCL data with size: " << encodeFrameInfo->bitstreamHeaderBufferSize << ", Input Order: " << (uint32_t)encodeFrameInfo->gopPosition.inputOrder << ", Encode Order: " << (uint32_t)encodeFrameInfo->gopPosition.encodeOrder diff --git a/vk_video_encoder/libs/VkVideoEncoder/VkVideoEncoderH264.cpp b/vk_video_encoder/libs/VkVideoEncoder/VkVideoEncoderH264.cpp index fbbf1fb8..a1f57dd7 100644 --- a/vk_video_encoder/libs/VkVideoEncoder/VkVideoEncoderH264.cpp +++ b/vk_video_encoder/libs/VkVideoEncoder/VkVideoEncoderH264.cpp @@ -47,7 +47,7 @@ VkResult VkVideoEncoderH264::InitEncoderCodec(VkSharedBaseObj& en VkResult result = InitEncoder(encoderConfig); if (result != VK_SUCCESS) { - fprintf(stderr, "\nERROR: InitEncoder() failed with ret(%d)\n", result); + LOG_S_ERROR << "ERROR: InitEncoder() failed with ret: " << result << std::endl; return result; } @@ -77,14 +77,14 @@ VkResult VkVideoEncoderH264::InitEncoderCodec(VkSharedBaseObj& en nullptr, &sessionParameters); if(result != VK_SUCCESS) { - fprintf(stderr, "\nEncodeFrame Error: Failed to get create video session parameters.\n"); + LOG_S_ERROR << "EncodeFrame Error: Failed to get create video session parameters." << std::endl; return result; } result = VulkanVideoSessionParameters::Create(m_vkDevCtx, m_videoSession, sessionParameters, m_videoSessionParameters); if(result != VK_SUCCESS) { - fprintf(stderr, "\nEncodeFrame Error: Failed to get create video session object.\n"); + LOG_S_ERROR << "EncodeFrame Error: Failed to get create video session object." << std::endl; return result; } @@ -511,10 +511,10 @@ VkResult VkVideoEncoderH264::EncodeFrame(VkSharedBaseObj DumpStateInfo("input", 1, encodeFrameInfo); if (encodeFrameInfo->lastFrame) { - std::cout << "#### It is the last frame: " << encodeFrameInfo->frameInputOrderNum - << " of type " << VkVideoGopStructure::GetFrameTypeName(encodeFrameInfo->gopPosition.pictureType) - << " ###" - << std::endl << std::flush; + LOG_S_DEBUG << "#### It is the last frame: " << encodeFrameInfo->frameInputOrderNum + << " of type " << VkVideoGopStructure::GetFrameTypeName(encodeFrameInfo->gopPosition.pictureType) + << " ###" + << std::endl << std::flush; } } diff --git a/vk_video_encoder/libs/VkVideoEncoder/VkVideoEncoderH265.cpp b/vk_video_encoder/libs/VkVideoEncoder/VkVideoEncoderH265.cpp index d773930e..15ea0501 100644 --- a/vk_video_encoder/libs/VkVideoEncoder/VkVideoEncoderH265.cpp +++ b/vk_video_encoder/libs/VkVideoEncoder/VkVideoEncoderH265.cpp @@ -47,14 +47,14 @@ VkResult VkVideoEncoderH265::InitEncoderCodec(VkSharedBaseObj& en VkResult result = InitEncoder(encoderConfig); if (result != VK_SUCCESS) { - fprintf(stderr, "\nERROR: InitEncoder() failed with ret(%d)\n", result); + LOG_S_ERROR << "ERROR: InitEncoder() failed with ret: " << result << std::endl; return result; } // Initialize DPB m_dpb.DpbSequenceStart(m_maxDpbPicturesCount, (m_encoderConfig->numRefL0 > 0)); - std::cout << ", numRefL0: " << (uint32_t)m_encoderConfig->numRefL0 + LOG_S_DEBUG << ", numRefL0: " << (uint32_t)m_encoderConfig->numRefL0 << ", numRefL1: " << (uint32_t)m_encoderConfig->numRefL1 << std::endl; m_encoderConfig->GetRateControlParameters(&m_rateControlInfo, m_rateControlLayersInfo, &m_rateControlInfoH265, m_rateControlLayersInfoH265); @@ -92,14 +92,14 @@ VkResult VkVideoEncoderH265::InitEncoderCodec(VkSharedBaseObj& en nullptr, &sessionParameters); if(result != VK_SUCCESS) { - fprintf(stderr, "\nEncodeFrame Error: Failed to get create video session parameters.\n"); + LOG_S_ERROR << "\nEncodeFrame Error: Failed to get create video session parameters" << std::endl; return result; } result = VulkanVideoSessionParameters::Create(m_vkDevCtx, m_videoSession, sessionParameters, m_videoSessionParameters); if(result != VK_SUCCESS) { - fprintf(stderr, "\nEncodeFrame Error: Failed to get create video session object.\n"); + LOG_S_ERROR << "EncodeFrame Error: Failed to get create video session object." << std::endl; return result; } @@ -391,10 +391,10 @@ VkResult VkVideoEncoderH265::EncodeFrame(VkSharedBaseObj DumpStateInfo("input", 1, encodeFrameInfo); if (encodeFrameInfo->lastFrame) { - std::cout << "#### It is the last frame: " << encodeFrameInfo->frameInputOrderNum - << " of type " << VkVideoGopStructure::GetFrameTypeName(encodeFrameInfo->gopPosition.pictureType) - << " ###" - << std::endl << std::flush; + LOG_S_DEBUG << "#### It is the last frame: " << encodeFrameInfo->frameInputOrderNum + << " of type " << VkVideoGopStructure::GetFrameTypeName(encodeFrameInfo->gopPosition.pictureType) + << " ###" + << std::endl << std::flush; } } diff --git a/vk_video_encoder/libs/VkVideoEncoder/VkVideoGopStructure.cpp b/vk_video_encoder/libs/VkVideoEncoder/VkVideoGopStructure.cpp index 72caddb2..a37888ed 100644 --- a/vk_video_encoder/libs/VkVideoEncoder/VkVideoGopStructure.cpp +++ b/vk_video_encoder/libs/VkVideoEncoder/VkVideoGopStructure.cpp @@ -15,6 +15,7 @@ */ #include "VkVideoGopStructure.h" +#include "Logger.h" VkVideoGopStructure::VkVideoGopStructure(uint8_t gopFrameCount, int32_t idrPeriod, @@ -48,33 +49,33 @@ bool VkVideoGopStructure::Init(uint64_t maxNumFrames) void VkVideoGopStructure::PrintGopStructure(uint64_t numFrames) const { - std::cout << std::endl << "Input order: "; + LOG_S_INFO << std::endl << "Input order: "; for (uint64_t frameNum = 0; frameNum < numFrames; frameNum++) { - std::cout << std::setw(3) << frameNum << " "; + LOG_S_INFO << std::setw(3) << frameNum << " "; } - std::cout << std::endl << "Frame Type: "; + LOG_S_INFO << std::endl << "Frame Type: "; GopState gopState; GopPosition gopPos(gopState.positionInInputOrder); for (uint64_t frameNum = 0; frameNum < (numFrames - 1); frameNum++) { GetPositionInGOP(gopState, gopPos); - std::cout << std::setw(4) << GetFrameTypeName(gopPos.pictureType); + LOG_S_INFO << std::setw(4) << GetFrameTypeName(gopPos.pictureType); } GetPositionInGOP(gopState, gopPos, false, true); - std::cout << std::setw(4) << GetFrameTypeName(gopPos.pictureType); + LOG_S_INFO << std::setw(4) << GetFrameTypeName(gopPos.pictureType); - std::cout << std::endl << "Encode order: "; + LOG_S_INFO << std::endl << "Encode order: "; gopState = GopState(); for (uint64_t i = 0; i < (numFrames - 1); i++) { GetPositionInGOP(gopState, gopPos); - std::cout << std::setw(3) << gopPos.encodeOrder << " "; + LOG_S_INFO << std::setw(3) << gopPos.encodeOrder << " "; } GetPositionInGOP(gopState, gopPos, false, true); - std::cout << std::setw(3) << gopPos.encodeOrder << " "; + LOG_S_INFO << std::setw(3) << gopPos.encodeOrder << " "; - std::cout << std::endl; + LOG_S_INFO << std::endl; } void VkVideoGopStructure::DumpFrameGopStructure(GopState& gopState, @@ -83,18 +84,18 @@ void VkVideoGopStructure::DumpFrameGopStructure(GopState& gopState, GopPosition gopPos(gopState.positionInInputOrder); GetPositionInGOP(gopState, gopPos); - std::cout << " " << gopPos.inputOrder << ", " + LOG_S_DEBUG << " " << gopPos.inputOrder << ", " << "\t" << gopPos.encodeOrder << ", " << "\t" << (uint32_t)gopPos.inGop << ", " << "\t" << GetFrameTypeName(gopPos.pictureType); - std::cout << std::endl; + LOG_S_DEBUG << std::endl; } void VkVideoGopStructure::DumpFramesGopStructure(uint64_t firstFrameNumInInputOrder, uint64_t numFrames) const { - std::cout << "Input Encode Position Frame " << std::endl; - std::cout << "order order in GOP type " << std::endl; + LOG_S_DEBUG<< "Input Encode Position Frame " << std::endl; + LOG_S_DEBUG << "order order in GOP type " << std::endl; const uint64_t lastFrameNumInInputOrder = firstFrameNumInInputOrder + numFrames - 1; GopState gopState; for (uint64_t frameNumInDisplayOrder = firstFrameNumInInputOrder; frameNumInDisplayOrder < lastFrameNumInInputOrder; ++frameNumInDisplayOrder) { diff --git a/vk_video_encoder/src/vulkan_video_encoder.cpp b/vk_video_encoder/src/vulkan_video_encoder.cpp index 52a21811..b8f0485a 100644 --- a/vk_video_encoder/src/vulkan_video_encoder.cpp +++ b/vk_video_encoder/src/vulkan_video_encoder.cpp @@ -45,7 +45,7 @@ class VulkanVideoEncoderImpl : public VulkanVideoEncoder { { m_encoder->WaitForThreadsToComplete(); - std::cout << "Done processing " << m_lastFrameIndex << " input frames!" << std::endl + LOG_S_INFO << "Done processing " << m_lastFrameIndex << " input frames!" << std::endl << "Encoded file's location is at " << m_encoderConfig->outputFileHandler.GetFileName() << std::endl; @@ -126,7 +126,7 @@ VkResult VulkanVideoEncoderImpl::Initialize(VkVideoCodecOperationFlagBitsKHR vid result = m_vkDevCtxt.InitVulkanDevice(m_encoderConfig->appName.c_str(), m_encoderConfig->verbose); if (result != VK_SUCCESS) { - printf("Could not initialize the Vulkan device!\n"); + LOG_S_ERROR << "Could not initialize the Vulkan device!" << std::endl; return result; } @@ -218,7 +218,7 @@ VkResult VulkanVideoEncoderImpl::EncodeNextFrame(int64_t& frameNumEncoded) } if (m_encoderConfig->verboseFrameStruct) { - std::cout << "####################################################################################" << std::endl + LOG_S_DEBUG << "####################################################################################" << std::endl << "Start processing current input frame index: " << m_lastFrameIndex << std::endl; } @@ -228,14 +228,14 @@ VkResult VulkanVideoEncoderImpl::EncodeNextFrame(int64_t& frameNumEncoded) // load frame data from the file VkResult result = m_encoder->LoadNextFrame(encodeFrameInfo); if (result != VK_SUCCESS) { - std::cout << "ERROR processing input frame index: " << m_lastFrameIndex << std::endl; + LOG_S_ERROR << "ERROR processing input frame index: " << m_lastFrameIndex << std::endl; return result; } frameNumEncoded = encodeFrameInfo->frameInputOrderNum; if (m_encoderConfig->verboseFrameStruct) { - std::cout << "End processing current input frame index: " << m_lastFrameIndex << std::endl; + LOG_S_DEBUG << "End processing current input frame index: " << m_lastFrameIndex << std::endl; } m_lastFrameIndex++; diff --git a/vk_video_encoder/test/vulkan-video-enc/Main.cpp b/vk_video_encoder/test/vulkan-video-enc/Main.cpp index 536729f6..b3c8e88f 100644 --- a/vk_video_encoder/test/vulkan-video-enc/Main.cpp +++ b/vk_video_encoder/test/vulkan-video-enc/Main.cpp @@ -16,6 +16,7 @@ #include #include "vulkan_video_encoder.h" +#include "Logger.h" int main(int argc, char** argv) { @@ -25,7 +26,7 @@ int main(int argc, char** argv) argc, argv, vulkanVideoEncoder); if (result != VK_SUCCESS) { - std::cerr << "Error creating the encoder instance: " << result << std::endl; + LOG_S_ERROR << "Error creating the encoder instance: " << result << std::endl; } int64_t numFrames = vulkanVideoEncoder->GetNumberOfFrames(); @@ -35,16 +36,16 @@ int main(int argc, char** argv) int64_t frameNumEncoded = -1; result = vulkanVideoEncoder->EncodeNextFrame(frameNumEncoded); if (result != VK_SUCCESS) { - std::cerr << "Error encoding frame: " << frameNum << ", error: " << result << std::endl; + LOG_S_ERROR << "Error encoding frame: " << frameNum << ", error: " << result << std::endl; } } result = vulkanVideoEncoder->GetBitstream(); if (result != VK_SUCCESS) { - std::cerr << "Error obtaining the encoded bitstream file: " << result << std::endl; + LOG_S_ERROR << "Error obtaining the encoded bitstream file: " << result << std::endl; } - std::cout << "Exit encoder test" << std::endl; + LOG_S_INFO << "Exit encoder test successfully" << std::endl; }