Skip to content

Commit 9d61627

Browse files
committed
vkvideoencoder: use logger.h instead of cout or printf
1 parent 8a2072a commit 9d61627

File tree

14 files changed

+276
-265
lines changed

14 files changed

+276
-265
lines changed

vk_video_encoder/demos/vk-video-enc/Main.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "VkCodecUtils/VulkanVideoEncodeDisplayQueue.h"
2121
#include "VkCodecUtils/VulkanEncoderFrameProcessor.h"
2222
#include "VkShell/Shell.h"
23+
#include "Logger.h"
2324

2425
int main(int argc, char** argv)
2526
{
@@ -104,7 +105,7 @@ int main(int argc, char** argv)
104105
VkResult result = vkDevCtxt.InitVulkanDevice(encoderConfig->appName.c_str(), VK_NULL_HANDLE,
105106
encoderConfig->verbose);
106107
if (result != VK_SUCCESS) {
107-
printf("Could not initialize the Vulkan device!\n");
108+
LOG_ERROR("Could not initialize the Vulkan device!\n");
108109
return -1;
109110
}
110111

@@ -154,6 +155,7 @@ int main(int argc, char** argv)
154155
VkSharedBaseObj<FrameProcessor> frameProcessor;
155156
result = CreateEncoderFrameProcessor(&vkDevCtxt, frameProcessor);
156157
if (result != VK_SUCCESS) {
158+
LOG_ERROR("Could not create the encoder frame processor!\n");
157159
return -1;
158160
}
159161

@@ -287,7 +289,7 @@ int main(int argc, char** argv)
287289
for(; curFrameIndex < encoderConfig->numFrames; curFrameIndex++) {
288290

289291
if (encoderConfig->verboseFrameStruct) {
290-
std::cout << "####################################################################################" << std::endl
292+
LOG_S_DEBUG << "####################################################################################" << std::endl
291293
<< "Start processing current input frame index: " << curFrameIndex << std::endl;
292294
}
293295

@@ -297,18 +299,18 @@ int main(int argc, char** argv)
297299
// load frame data from the file
298300
result = encoder->LoadNextFrame(encodeFrameInfo);
299301
if (result != VK_SUCCESS) {
300-
std::cout << "ERROR processing input frame index: " << curFrameIndex << std::endl;
302+
LOG_S_ERROR << "ERROR processing input frame index: " << curFrameIndex << std::endl;
301303
break;
302304
}
303305

304306
if (encoderConfig->verboseFrameStruct) {
305-
std::cout << "End processing current input frame index: " << curFrameIndex << std::endl;
307+
LOG_S_DEBUG << "End processing current input frame index: " << curFrameIndex << std::endl;
306308
}
307309
}
308310

309311
encoder->WaitForThreadsToComplete();
310312

311-
std::cout << "Done processing " << curFrameIndex << " input frames!" << std::endl
313+
LOG_S_INFO << "Done processing " << curFrameIndex << " input frames!" << std::endl
312314
<< "Encoded file's location is at " << encoderConfig->outputFileHandler.GetFileName()
313315
<< std::endl;
314316
return 0;

vk_video_encoder/libs/VkVideoEncoder/VkEncoderConfig.cpp

Lines changed: 86 additions & 72 deletions
Large diffs are not rendered by default.

vk_video_encoder/libs/VkVideoEncoder/VkEncoderConfig.h

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "VkVideoCore/VkVideoCoreProfile.h"
3333
#include "VkVideoCore/VulkanVideoCapabilities.h"
3434
#include "VkCodecUtils/VulkanFilterYuvCompute.h"
35+
#include "Logger.h"
3536

3637
struct EncoderConfigH264;
3738
struct EncoderConfigH265;
@@ -116,13 +117,13 @@ struct EncoderInputImageParameters
116117
bool VerifyInputs()
117118
{
118119
if ((width == 0) || (height == 0)) {
119-
fprintf(stderr, "Invalid input width (%d) and/or height(%d) parameters!", width, height);
120+
LOG_S_ERROR << "Invalid input width" << width << " and/or height" << height << " parameters!" << std::endl;
120121
return false;
121122
}
122123

123124
uint32_t bytesPerPixel = (bpp + 7) / 8;
124125
if ((bytesPerPixel < 1) || (bytesPerPixel > 2)) {
125-
fprintf(stderr, "Invalid input bpp (%d) parameter!", bpp);
126+
LOG_S_ERROR << "Invalid input bpp parameter: " << bpp << std::endl;
126127
return false;
127128
}
128129

@@ -173,7 +174,7 @@ struct EncoderInputImageParameters
173174
(numPlanes == 2));
174175

175176
if (vkFormat == VK_FORMAT_UNDEFINED) {
176-
fprintf(stderr, "Invalid input parameters!");
177+
LOG_S_ERROR << "Invalid input parameters!" << std::endl;
177178
return false;
178179
}
179180

@@ -204,8 +205,8 @@ class EncoderInputFileHandler
204205
m_memMapedFile.unmap();
205206

206207
if (m_fileHandle != nullptr) {
207-
if (fclose(m_fileHandle)) {
208-
fprintf(stderr, "Failed to close input file %s", m_fileName);
208+
if(fclose(m_fileHandle)) {
209+
LOG_S_ERROR << "Failed to close input file " << m_fileName << std::endl;
209210
}
210211

211212
m_fileHandle = nullptr;
@@ -262,7 +263,7 @@ class EncoderInputFileHandler
262263

263264
const uint64_t mappedLength = (uint64_t)m_memMapedFile.mapped_length();
264265
if (mappedLength < offset) {
265-
printf("File overflow at fileOffset %lld\n", (long long unsigned int)offset);
266+
LOG_S_ERROR << "File overflow at fileOffset " << offset << std::endl;
266267
assert(!"Input file overflow");
267268
return nullptr;
268269
}
@@ -425,22 +426,19 @@ class EncoderInputFileHandler
425426
{
426427
m_fileHandle = fopen(m_fileName, "rb");
427428
if (m_fileHandle == nullptr) {
428-
fprintf(stderr, "Failed to open input file %s", m_fileName);
429+
LOG_S_ERROR << "Failed to open input file " << m_fileName << std::endl;
429430
return 0;
430431
}
431432

432433
std::error_code error;
433434
m_memMapedFile.map(m_fileName, 0, mio::map_entire_file, error);
434435
if (error) {
435-
fprintf(stderr, "Failed to map the input file %s", m_fileName);
436436
const auto& errmsg = error.message();
437-
std::printf("error mapping file: %s, exiting...\n", errmsg.c_str());
437+
LOG_S_ERROR << "Failed to map the input file: " << m_fileName << " with error msg: " << errmsg << std::endl;
438438
return error.value();
439439
}
440440

441-
if (m_verbose) {
442-
printf("Input file size is: %zd\n", m_memMapedFile.length());
443-
}
441+
LOG_DEBUG_CONFIG ("Input file size is: %zd\n", m_memMapedFile.length());
444442

445443
return m_memMapedFile.length();
446444
}
@@ -481,7 +479,7 @@ class EncoderOutputFileHandler
481479

482480
if (m_fileHandle != nullptr) {
483481
if(fclose(m_fileHandle)) {
484-
fprintf(stderr, "Failed to close output file %s", m_fileName);
482+
LOG_S_ERROR << "Failed to close output file " << m_fileName << std::endl;
485483
}
486484

487485
m_fileHandle = nullptr;
@@ -527,7 +525,7 @@ class EncoderOutputFileHandler
527525
{
528526
m_fileHandle = fopen(m_fileName, "wb");
529527
if (m_fileHandle == nullptr) {
530-
fprintf(stderr, "Failed to open output file %s", m_fileName);
528+
LOG_S_ERROR << "Failed to open output file " << m_fileName << std::endl;
531529
return 0;
532530
}
533531

@@ -568,7 +566,7 @@ class EncoderQpMapFileHandler
568566

569567
if (m_fileHandle != nullptr) {
570568
if(fclose(m_fileHandle)) {
571-
fprintf(stderr, "Failed to close input file %s", m_fileName);
569+
LOG_S_ERROR << "Failed to close input file " << m_fileName << std::endl;
572570
}
573571

574572
m_fileHandle = nullptr;
@@ -609,7 +607,7 @@ class EncoderQpMapFileHandler
609607

610608
const uint64_t mappedLength = (uint64_t)m_memMapedFile.mapped_length();
611609
if (mappedLength < fileOffset) {
612-
printf("File overflow at fileOffset %llu\n", (unsigned long long int)fileOffset);
610+
LOG_S_ERROR << "File overflow at fileOffset " << fileOffset << std::endl;
613611
assert(!"Input file overflow");
614612
return nullptr;
615613
}
@@ -621,22 +619,19 @@ class EncoderQpMapFileHandler
621619
{
622620
m_fileHandle = fopen(m_fileName, "rb");
623621
if (m_fileHandle == nullptr) {
624-
fprintf(stderr, "Failed to open input file %s", m_fileName);
622+
LOG_S_ERROR << "Failed to open input file " << m_fileName << std::endl;
625623
return 0;
626624
}
627625

628626
std::error_code error;
629627
m_memMapedFile.map(m_fileName, 0, mio::map_entire_file, error);
630628
if (error) {
631-
fprintf(stderr, "Failed to map the input file %s", m_fileName);
632629
const auto& errmsg = error.message();
633-
std::printf("error mapping file: %s, exiting...\n", errmsg.c_str());
630+
LOG_S_ERROR << "Failed to map input file " << m_fileName << " error: " << errmsg.c_str() << std::endl;
634631
return error.value();
635632
}
636633

637-
if (m_verbose) {
638-
printf("Input file size is: %zd\n", m_memMapedFile.length());
639-
}
634+
LOG_DEBUG_CONFIG ("Input file size is: %zd\n", m_memMapedFile.length());
640635

641636
return m_memMapedFile.length();
642637
}

vk_video_encoder/libs/VkVideoEncoder/VkEncoderConfigAV1.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define READ_PARAM(i, param, type) { \
2020
int32_t data = 0; \
2121
if ((++i >= argc) || (sscanf(argv[i], "%d", &data) != 1)) { \
22-
fprintf(stderr, "invalid parameter"); \
22+
LOG_ERROR_CONFIG("invalid parameter"); \
2323
return -1; \
2424
} else { \
2525
param = (type)data; \
@@ -140,7 +140,7 @@ int EncoderConfigAV1::DoParseArguments(int argc, char* argv[])
140140
}
141141
} else if (args[i] == "--profile"){
142142
if (++i >= argc) {
143-
fprintf(stderr, "invalid parameter for %s\n", args[i-1].c_str());
143+
LOG_ERROR_CONFIG("invalid parameter for %s", args[i-1].c_str());
144144
return -1;
145145
}
146146
std::string prfl = args[i];
@@ -152,11 +152,11 @@ int EncoderConfigAV1::DoParseArguments(int argc, char* argv[])
152152
profile = STD_VIDEO_AV1_PROFILE_PROFESSIONAL;
153153
} else {
154154
// Invalid profile
155-
fprintf(stderr, "Invalid profile: %s\n", prfl.c_str());
155+
LOG_ERROR_CONFIG("Invalid profile: %s", prfl.c_str());
156156
return -1;
157157
}
158158
} else {
159-
fprintf(stderr, "Unrecognized option: %s\n", argv[i]);
159+
LOG_ERROR_CONFIG("Unrecognized option: %s", argv[i]);
160160
//printAV1Help();
161161
return -1;
162162
}
@@ -194,21 +194,21 @@ VkResult EncoderConfigAV1::InitDeviceCapabilities(const VulkanDeviceContext* vkD
194194
quantizationMapCapabilities,
195195
av1QuantizationMapCapabilities);
196196
if (result != VK_SUCCESS) {
197-
std::cout << "*** Could not get video capabilities :" << result << " ***" << std::endl;
197+
LOG_S_ERROR << "*** Could not get video capabilities :" << result << " ***" << std::endl;
198198
assert(!"Coult not get Video Capabilities!");
199199
return result;
200200
}
201201

202-
if (verboseMsg) {
203-
std::cout << "\t\t\t" << VkVideoCoreProfile::CodecToName(codec) << "encode capabilities: " << std::endl;
204-
std::cout << "\t\t\t" << "minBitstreamBufferOffsetAlignment: " << videoCapabilities.minBitstreamBufferOffsetAlignment << std::endl;
205-
std::cout << "\t\t\t" << "minBitstreamBufferSizeAlignment: " << videoCapabilities.minBitstreamBufferSizeAlignment << std::endl;
206-
std::cout << "\t\t\t" << "pictureAccessGranularity: " << videoCapabilities.pictureAccessGranularity.width << " x " << videoCapabilities.pictureAccessGranularity.height << std::endl;
207-
std::cout << "\t\t\t" << "minExtent: " << videoCapabilities.minCodedExtent.width << " x " << videoCapabilities.minCodedExtent.height << std::endl;
208-
std::cout << "\t\t\t" << "maxExtent: " << videoCapabilities.maxCodedExtent.width << " x " << videoCapabilities.maxCodedExtent.height << std::endl;
209-
std::cout << "\t\t\t" << "maxDpbSlots: " << videoCapabilities.maxDpbSlots << std::endl;
210-
std::cout << "\t\t\t" << "maxActiveReferencePictures: " << videoCapabilities.maxActiveReferencePictures << std::endl;
211-
}
202+
203+
LOG_S_INFO << "\t\t\t" << VkVideoCoreProfile::CodecToName(codec) << "encode capabilities: " << std::endl;
204+
LOG_S_INFO << "\t\t\t" << "minBitstreamBufferOffsetAlignment: " << videoCapabilities.minBitstreamBufferOffsetAlignment << std::endl;
205+
LOG_S_INFO << "\t\t\t" << "minBitstreamBufferSizeAlignment: " << videoCapabilities.minBitstreamBufferSizeAlignment << std::endl;
206+
LOG_S_INFO << "\t\t\t" << "pictureAccessGranularity: " << videoCapabilities.pictureAccessGranularity.width << " x " << videoCapabilities.pictureAccessGranularity.height << std::endl;
207+
LOG_S_INFO << "\t\t\t" << "minExtent: " << videoCapabilities.minCodedExtent.width << " x " << videoCapabilities.minCodedExtent.height << std::endl;
208+
LOG_S_INFO << "\t\t\t" << "maxExtent: " << videoCapabilities.maxCodedExtent.width << " x " << videoCapabilities.maxCodedExtent.height << std::endl;
209+
LOG_S_INFO << "\t\t\t" << "maxDpbSlots: " << videoCapabilities.maxDpbSlots << std::endl;
210+
LOG_S_INFO << "\t\t\t" << "maxActiveReferencePictures: " << videoCapabilities.maxActiveReferencePictures << std::endl;
211+
212212

213213
return VK_SUCCESS;
214214
}

vk_video_encoder/libs/VkVideoEncoder/VkEncoderConfigH264.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -358,21 +358,21 @@ VkResult EncoderConfigH264::InitDeviceCapabilities(const VulkanDeviceContext* vk
358358
quantizationMapCapabilities,
359359
h264QuantizationMapCapabilities);
360360
if (result != VK_SUCCESS) {
361-
std::cout << "*** Could not get Video Capabilities :" << result << " ***" << std::endl;
361+
LOG_S_ERROR << "*** Could not get Video Capabilities :" << result << " ***" << std::endl;
362362
assert(!"Could not get Video Capabilities!");
363363
return result;
364364
}
365365

366-
if (verboseMsg) {
367-
std::cout << "\t\t\t" << VkVideoCoreProfile::CodecToName(codec) << "encode capabilities: " << std::endl;
368-
std::cout << "\t\t\t" << "minBitstreamBufferOffsetAlignment: " << videoCapabilities.minBitstreamBufferOffsetAlignment << std::endl;
369-
std::cout << "\t\t\t" << "minBitstreamBufferSizeAlignment: " << videoCapabilities.minBitstreamBufferSizeAlignment << std::endl;
370-
std::cout << "\t\t\t" << "pictureAccessGranularity: " << videoCapabilities.pictureAccessGranularity.width << " x " << videoCapabilities.pictureAccessGranularity.height << std::endl;
371-
std::cout << "\t\t\t" << "minExtent: " << videoCapabilities.minCodedExtent.width << " x " << videoCapabilities.minCodedExtent.height << std::endl;
372-
std::cout << "\t\t\t" << "maxExtent: " << videoCapabilities.maxCodedExtent.width << " x " << videoCapabilities.maxCodedExtent.height << std::endl;
373-
std::cout << "\t\t\t" << "maxDpbSlots: " << videoCapabilities.maxDpbSlots << std::endl;
374-
std::cout << "\t\t\t" << "maxActiveReferencePictures: " << videoCapabilities.maxActiveReferencePictures << std::endl;
375-
std::cout << "\t\t\t" << "maxBPictureL0ReferenceCount: " << h264EncodeCapabilities.maxBPictureL0ReferenceCount << std::endl;
366+
if (verbose) {
367+
LOG_S_INFO << "\t\t\t" << VkVideoCoreProfile::CodecToName(codec) << "encode capabilities: " << std::endl;
368+
LOG_S_INFO << "\t\t\t" << "minBitstreamBufferOffsetAlignment: " << videoCapabilities.minBitstreamBufferOffsetAlignment << std::endl;
369+
LOG_S_INFO << "\t\t\t" << "minBitstreamBufferSizeAlignment: " << videoCapabilities.minBitstreamBufferSizeAlignment << std::endl;
370+
LOG_S_INFO << "\t\t\t" << "pictureAccessGranularity: " << videoCapabilities.pictureAccessGranularity.width << " x " << videoCapabilities.pictureAccessGranularity.height << std::endl;
371+
LOG_S_INFO << "\t\t\t" << "minExtent: " << videoCapabilities.minCodedExtent.width << " x " << videoCapabilities.minCodedExtent.height << std::endl;
372+
LOG_S_INFO << "\t\t\t" << "maxExtent: " << videoCapabilities.maxCodedExtent.width << " x " << videoCapabilities.maxCodedExtent.height << std::endl;
373+
LOG_S_INFO << "\t\t\t" << "maxDpbSlots: " << videoCapabilities.maxDpbSlots << std::endl;
374+
LOG_S_INFO << "\t\t\t" << "maxActiveReferencePictures: " << videoCapabilities.maxActiveReferencePictures << std::endl;
375+
LOG_S_INFO << "\t\t\t" << "maxBPictureL0ReferenceCount: " << h264EncodeCapabilities.maxBPictureL0ReferenceCount << std::endl;
376376
}
377377

378378
return VK_SUCCESS;

0 commit comments

Comments
 (0)