CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-bytedeco--libdc1394

JavaCPP Presets for libdc1394 - Java bindings for controlling IEEE 1394 (FireWire) digital cameras following IIDC/DCAM specifications

Pending
Overview
Eval results
Files

logging.mddocs/

Logging

Error reporting, debug logging, and message handling system for libdc1394.

Capabilities

Log Message Functions

Built-in logging functions for error reporting and debugging.

/**
 * Logs an error message
 * @param format Error message string
 */
void dc1394_log_error(String format);

/**
 * Logs a warning message  
 * @param format Warning message string
 */
void dc1394_log_warning(String format);

/**
 * Logs a debug message
 * @param format Debug message string
 */
void dc1394_log_debug(String format);

Usage Example:

import org.bytedeco.libdc1394.*;
import static org.bytedeco.libdc1394.global.dc1394.*;

// Basic logging usage
dc1394_log_error("Camera initialization failed");
dc1394_log_warning("Using default video mode");
dc1394_log_debug("Frame capture completed successfully");

// Logging with context information
dc1394_log_error("Failed to set video mode " + video_mode + " for camera " + 
                 Long.toHexString(camera.guid()));
dc1394_log_warning("Camera " + camera.model() + " does not support feature " + feature);
dc1394_log_debug("Captured frame " + frame_count + " at timestamp " + timestamp);

Custom Log Handlers

Register custom log handlers to redirect log messages to your application's logging system.

/**
 * Registers a custom log handler for specified log types
 * @param type Log level (DC1394_LOG_ERROR, DC1394_LOG_WARNING, DC1394_LOG_DEBUG)
 * @param log_handler Custom handler function
 * @param user User data passed to handler
 * @return DC1394_SUCCESS on success, error code on failure
 */
int dc1394_log_register_handler(int type, Log_handler_int_BytePointer_Pointer log_handler, 
                               Pointer user);

/**
 * Restores the default log handler for specified log type
 * @param type Log level to reset to default handler
 * @return DC1394_SUCCESS on success, error code on failure
 */
int dc1394_log_set_default_handler(int type);

Usage Example:

import org.bytedeco.libdc1394.*;
import org.bytedeco.libdc1394.global.dc1394.*;
import org.bytedeco.javacpp.*;

// Custom log handler implementation
public class CustomLogHandler extends Log_handler_int_BytePointer_Pointer {
    @Override
    public void call(int type, BytePointer message, Pointer user) {
        String msg = message.getString();
        String level;
        
        switch (type) {
            case DC1394_LOG_ERROR:
                level = "ERROR";
                break;
            case DC1394_LOG_WARNING:
                level = "WARNING";  
                break;
            case DC1394_LOG_DEBUG:
                level = "DEBUG";
                break;
            default:
                level = "UNKNOWN";
                break;
        }
        
        // Forward to your application's logging system
        System.err.println("[libdc1394 " + level + "] " + msg);
        
        // Or use a more sophisticated logging framework
        // logger.log(convertLevel(type), msg);
    }
}

// Register custom handlers
CustomLogHandler handler = new CustomLogHandler();
dc1394_log_register_handler(DC1394_LOG_ERROR, handler, null);
dc1394_log_register_handler(DC1394_LOG_WARNING, handler, null);
dc1394_log_register_handler(DC1394_LOG_DEBUG, handler, null);

// Now all libdc1394 log messages will go through your custom handler
dc1394_log_error("This will be handled by custom handler");

// Restore default handler when needed
dc1394_log_set_default_handler(DC1394_LOG_ERROR);

Advanced Logging Integration

Example showing integration with popular Java logging frameworks:

import org.bytedeco.libdc1394.*;
import org.bytedeco.libdc1394.global.dc1394.*;
import org.bytedeco.javacpp.*;
import java.util.logging.Logger;
import java.util.logging.Level;

public class LoggingIntegration {
    private static final Logger logger = Logger.getLogger("libdc1394");
    
    // Log handler that integrates with java.util.logging
    public static class JULLogHandler extends Log_handler_int_BytePointer_Pointer {
        @Override
        public void call(int type, BytePointer message, Pointer user) {
            String msg = message.getString();
            Level level;
            
            switch (type) {
                case DC1394_LOG_ERROR:
                    level = Level.SEVERE;
                    break;
                case DC1394_LOG_WARNING:
                    level = Level.WARNING;
                    break;
                case DC1394_LOG_DEBUG:
                    level = Level.FINE;
                    break;
                default:
                    level = Level.INFO;
                    break;
            }
            
            logger.log(level, msg);
        }
    }
    
    // Log handler for SLF4J integration
    public static class SLF4JLogHandler extends Log_handler_int_BytePointer_Pointer {
        private final org.slf4j.Logger slf4jLogger = 
            org.slf4j.LoggerFactory.getLogger("libdc1394");
            
        @Override
        public void call(int type, BytePointer message, Pointer user) {
            String msg = message.getString();
            
            switch (type) {
                case DC1394_LOG_ERROR:
                    slf4jLogger.error(msg);
                    break;
                case DC1394_LOG_WARNING:
                    slf4jLogger.warn(msg);
                    break;
                case DC1394_LOG_DEBUG:
                    slf4jLogger.debug(msg);
                    break;
                default:
                    slf4jLogger.info(msg);
                    break;
            }
        }
    }
    
    public static void setupJavaUtilLogging() {
        JULLogHandler handler = new JULLogHandler();
        dc1394_log_register_handler(DC1394_LOG_ERROR, handler, null);
        dc1394_log_register_handler(DC1394_LOG_WARNING, handler, null);
        dc1394_log_register_handler(DC1394_LOG_DEBUG, handler, null);
    }
    
    public static void setupSLF4JLogging() {
        SLF4JLogHandler handler = new SLF4JLogHandler();  
        dc1394_log_register_handler(DC1394_LOG_ERROR, handler, null);
        dc1394_log_register_handler(DC1394_LOG_WARNING, handler, null);
        dc1394_log_register_handler(DC1394_LOG_DEBUG, handler, null);
    }
}

Contextual Logging Helper

Create a helper class for more structured logging with context:

import org.bytedeco.libdc1394.*;
import static org.bytedeco.libdc1394.global.dc1394.*;

public class DC1394Logger {
    private final String context;
    
    public DC1394Logger(String context) {
        this.context = context;
    }
    
    public void error(String message) {
        dc1394_log_error("[" + context + "] " + message);
    }
    
    public void error(String message, Exception e) {
        dc1394_log_error("[" + context + "] " + message + ": " + e.getMessage());
    }
    
    public void warning(String message) {
        dc1394_log_warning("[" + context + "] " + message);
    }
    
    public void debug(String message) {
        dc1394_log_debug("[" + context + "] " + message);
    }
    
    public void logResult(String operation, int result) {
        if (result == DC1394_SUCCESS) {
            debug(operation + " completed successfully");
        } else {
            BytePointer error_desc = dc1394_error_get_string(result);
            error(operation + " failed: " + error_desc.getString() + " (code: " + result + ")");
        }
    }
    
    public void logCameraInfo(dc1394camera_t camera) {
        debug("Camera info - GUID: " + Long.toHexString(camera.guid()) + 
              ", Model: " + camera.model() + 
              ", Vendor: " + camera.vendor());
    }
    
    public void logFrameInfo(dc1394video_frame_t frame) {
        debug("Frame info - Size: " + frame.size(0) + "x" + frame.size(1) + 
              ", Bytes: " + frame.image_bytes() + 
              ", Timestamp: " + frame.timestamp());
    }
}

// Usage example
public class CameraApplication {
    private final DC1394Logger logger = new DC1394Logger("CameraApp");
    
    public void initializeCamera() {
        dc1394_t d = dc1394_new();
        if (d == null) {
            logger.error("Failed to initialize libdc1394 context");
            return;
        }
        logger.debug("libdc1394 context created successfully");
        
        dc1394camera_list_t list = new dc1394camera_list_t();
        int err = dc1394_camera_enumerate(d, list);
        logger.logResult("Camera enumeration", err);
        
        if (err == DC1394_SUCCESS && list.num() > 0) {
            logger.debug("Found " + list.num() + " cameras");
            
            dc1394camera_t camera = dc1394_camera_new(d, list.ids().guid());
            if (camera != null) {
                logger.logCameraInfo(camera);
            } else {
                logger.error("Failed to create camera instance");
            }
        }
    }
}

Log Levels and Constants

// Log level constants
static final int DC1394_LOG_ERROR = 768;      // Error messages
static final int DC1394_LOG_WARNING = 769;    // Warning messages  
static final int DC1394_LOG_DEBUG = 770;      // Debug messages

Best Practices

Logging Strategy

  1. Use appropriate log levels:

    • ERROR: Critical failures that prevent operation
    • WARNING: Issues that don't prevent operation but should be noted
    • DEBUG: Detailed information for troubleshooting
  2. Include context in messages:

    dc1394_log_error("Camera " + Long.toHexString(camera.guid()) + 
                     " failed to set mode " + video_mode);
  3. Log function results:

    int err = dc1394_video_set_mode(camera, video_mode);
    if (err != DC1394_SUCCESS) {
        dc1394_log_error("Video mode setting failed: " + 
                         dc1394_error_get_string(err).getString());
    }

Performance Considerations

Debug logging can impact performance. Use conditional logging for high-frequency operations:

private static final boolean DEBUG_ENABLED = 
    System.getProperty("dc1394.debug", "false").equals("true");

public void captureFrame() {
    // High-frequency operation
    int err = dc1394_capture_dequeue(camera, DC1394_CAPTURE_POLICY_WAIT, frame);
    
    if (DEBUG_ENABLED && err == DC1394_SUCCESS) {
        dc1394_log_debug("Frame captured successfully");
    } else if (err != DC1394_SUCCESS) {
        // Always log errors
        dc1394_log_error("Frame capture failed: " + err);
    }
}

Exception Handling Integration

Combine logging with proper exception handling:

public void setupCamera() throws CameraException {
    try {
        int err = dc1394_video_set_mode(camera, video_mode);
        if (err != DC1394_SUCCESS) {
            String error_msg = "Failed to set video mode: " + 
                             dc1394_error_get_string(err).getString();
            dc1394_log_error(error_msg);
            throw new CameraException(error_msg, err);
        }
        dc1394_log_debug("Video mode set successfully");
    } catch (Exception e) {
        dc1394_log_error("Unexpected exception in camera setup: " + e.getMessage());
        throw new CameraException("Camera setup failed", e);
    }
}

This logging system provides comprehensive error reporting and debugging capabilities for libdc1394 applications.

Install with Tessl CLI

npx tessl i tessl/maven-org-bytedeco--libdc1394

docs

camera-features.md

format7.md

image-conversion.md

index.md

iso-resource-management.md

logging.md

system-management.md

trigger-control.md

utility-functions.md

video-capture.md

video-modes.md

tile.json