Skip to content

Commit a5d2076

Browse files
committed
Optimization information printing
1 parent d2300cf commit a5d2076

4 files changed

Lines changed: 14 additions & 12 deletions

File tree

examples/desktop/0-print_camera_c.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ bool frame_callback(const CcapVideoFrame* frame, void* userData) {
1717

1818
CcapVideoFrameInfo frameInfo;
1919
if (ccap_video_frame_get_info(frame, &frameInfo)) {
20-
printf("Frame %d: %dx%d, format=%d, timestamp=%d\n",
20+
printf("Frame %d: %dx%d, format=%d, timestamp=%llu\n",
2121
frameCount, frameInfo.width, frameInfo.height,
22-
frameInfo.pixelFormat, (int)frameInfo.timestamp);
22+
frameInfo.pixelFormat, frameInfo.timestamp);
2323
}
2424

2525
// Return false to keep the frame available for grab()
@@ -71,14 +71,17 @@ int main() {
7171
// Get device info
7272
CcapDeviceInfo deviceInfo;
7373
if (ccap_provider_get_device_info(provider, &deviceInfo)) {
74-
printf("Device: %s\n", deviceInfo.deviceName ? deviceInfo.deviceName : "Unknown");
74+
printf("Device: %s\n", deviceInfo.deviceName[0] ? deviceInfo.deviceName : "Unknown");
7575
printf("Supported pixel formats: %zu\n", deviceInfo.pixelFormatCount);
7676
printf("Supported resolutions: %zu\n", deviceInfo.resolutionCount);
7777

7878
if (deviceInfo.resolutionCount > 0) {
79-
printf("First resolution: %dx%d\n",
80-
deviceInfo.supportedResolutions[0].width,
81-
deviceInfo.supportedResolutions[0].height);
79+
printf("Supported resolutions:\n");
80+
for (size_t i = 0; i < deviceInfo.resolutionCount; i++) {
81+
printf(" %zu: %dx%d\n", i + 1,
82+
deviceInfo.supportedResolutions[i].width,
83+
deviceInfo.supportedResolutions[i].height);
84+
}
8285
}
8386
}
8487

@@ -127,4 +130,4 @@ int main() {
127130

128131
printf("Example completed successfully\n");
129132
return 0;
130-
}
133+
}

include/ccap_def.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ using ErrorCallback = std::function<void(ErrorCode errorCode, const std::string&
279279
* @param errorCode The error code to convert
280280
* @return English description of the error
281281
*/
282-
std::string errorCodeToString(ErrorCode errorCode);
282+
std::string_view errorCodeToString(ErrorCode errorCode);
283283

284284
/**
285285
* @brief Interface for memory allocation, primarily used to allocate the `data` field in `ccap::Frame`.

src/ccap_c.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,8 @@ bool ccap_set_error_callback(CcapErrorCallback callback, void* userData) {
394394

395395
const char* ccap_error_code_to_string(CcapErrorCode errorCode) {
396396
ccap::ErrorCode cppErrorCode = static_cast<ccap::ErrorCode>(static_cast<uint32_t>(errorCode));
397-
static thread_local std::string errorString;
398-
errorString = ccap::errorCodeToString(cppErrorCode);
399-
return errorString.c_str();
397+
std::string_view result = ccap::errorCodeToString(cppErrorCode);
398+
return result.data(); // std::string_view::data() returns const char*, safe for string literals
400399
}
401400

402401
const char* ccap_get_version(void) {

src/ccap_utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ void setLogLevel(LogLevel level) {
247247
#endif
248248
}
249249

250-
std::string errorCodeToString(ErrorCode errorCode) {
250+
std::string_view errorCodeToString(ErrorCode errorCode) {
251251
switch (errorCode) {
252252
case ErrorCode::None:
253253
return "No error";

0 commit comments

Comments
 (0)