#ifndef __cplusplus
#error "ccap_utils.h is for C++ only. For C language, please use ccap_utils_c.h instead."
#endif
#pragma once
#ifndef CCAP_UTILS_H
#define CCAP_UTILS_H
#include "ccap_core.h"
#include <string>
#include <string_view>
namespace ccap
{
CCAP_EXPORT std::string_view pixelFormatToString(PixelFormat format);
CCAP_EXPORT std::string dumpFrameToFile(VideoFrame* frame, std::string_view fileNameWithNoSuffix);
CCAP_EXPORT std::string dumpFrameToDirectory(VideoFrame* frame, std::string_view directory);
CCAP_EXPORT bool saveRgbDataAsBMP(const char* filename, const unsigned char* data, uint32_t w, uint32_t lineOffset, uint32_t h, bool isBGR, bool hasAlpha, bool isTopToBottom = false);
#ifndef CCAP_NO_LOG
#define _CCAP_LOG_ENABLED_ 1
#else
#define _CCAP_LOG_ENABLED_ 0
#endif
enum LogLevelConstants
{
kLogLevelErrorBit = 1,
kLogLevelWarningBit = 2,
kLogLevelInfoBit = 4,
kLogLevelVerboseBit = 8
};
enum class LogLevel
{
None = 0,
Error = kLogLevelErrorBit,
Warning = Error | kLogLevelWarningBit,
Info = Warning | kLogLevelInfoBit,
Verbose = Info | kLogLevelVerboseBit,
};
CCAP_EXPORT void setLogLevel(LogLevel level);
#if _CCAP_LOG_ENABLED_
extern CCAP_EXPORT LogLevel globalLogLevel;
inline bool operator&(LogLevel lhs, LogLevelConstants rhs)
{
return (static_cast<uint32_t>(lhs) & static_cast<uint32_t>(rhs));
}
inline bool errorLogEnabled() { return globalLogLevel & kLogLevelErrorBit; }
inline bool warningLogEnabled() { return globalLogLevel & kLogLevelWarningBit; }
inline bool infoLogEnabled() { return globalLogLevel & kLogLevelInfoBit; }
inline bool verboseLogEnabled() { return globalLogLevel & kLogLevelVerboseBit; }
#define CCAP_CALL_LOG(logLevel, ...) \
do \
{ \
if ((static_cast<uint32_t>(logLevel) & \
static_cast<uint32_t>(globalLogLevel)) == \
static_cast<uint32_t>(logLevel)) \
{ \
__VA_ARGS__; \
} \
} while (0)
#define CCAP_LOG(logLevel, ...) CCAP_CALL_LOG(logLevel, fprintf(stderr, __VA_ARGS__))
#define CCAP_LOG_E(...) CCAP_LOG(LogLevel::Error, __VA_ARGS__)
#define CCAP_LOG_W(...) CCAP_LOG(LogLevel::Warning, __VA_ARGS__)
#define CCAP_LOG_I(...) CCAP_LOG(LogLevel::Info, __VA_ARGS__)
#define CCAP_LOG_V(...) CCAP_LOG(LogLevel::Verbose, __VA_ARGS__)
#else
inline CCAP_CONSTEXPR bool errorLogEnabled() { return false; }
inline CCAP_CONSTEXPR bool warningLogEnabled() { return false; }
inline CCAP_CONSTEXPR bool infoLogEnabled() { return false; }
inline CCAP_CONSTEXPR bool verboseLogEnabled() { return false; }
#define CCAP_LOG_E(...) ((void)0)
#define CCAP_LOG_W(...) ((void)0)
#define CCAP_LOG_I(...) ((void)0)
#define CCAP_LOG_V(...) ((void)0)
#endif
}
#endif