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

iso-resource-management.mddocs/

ISO Resource Management

IEEE 1394 (FireWire) bus resource allocation and management for bandwidth and channel allocation in libdc1394.

Capabilities

Channel Allocation

Manages IEEE 1394 isochronous channel allocation for camera communication.

/**
 * Allocates an IEEE 1394 isochronous channel for camera communication
 * @param camera Camera instance
 * @param channels_allowed Bitmask of allowed channels (0 = any channel)
 * @param channel Output parameter for allocated channel number
 * @return DC1394_SUCCESS on success, error code on failure
 */
int dc1394_iso_allocate_channel(dc1394camera_t camera, long channels_allowed, IntPointer channel);

/**
 * Releases a previously allocated IEEE 1394 isochronous channel
 * @param camera Camera instance
 * @param channel Channel number to release
 * @return DC1394_SUCCESS on success, error code on failure
 */
int dc1394_iso_release_channel(dc1394camera_t camera, int channel);

Usage Example:

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

// Allocate any available channel
IntPointer channel = new IntPointer(1);
int err = dc1394_iso_allocate_channel(camera, 0, channel);
if (err != DC1394_SUCCESS) {
    dc1394_log_error("Failed to allocate ISO channel: " + err);
    return;
}

System.out.println("Allocated ISO channel: " + channel.get());

// Use channel for video transmission...

// Always release the channel when done
dc1394_iso_release_channel(camera, channel.get());

Bandwidth Management

Manages IEEE 1394 isochronous bandwidth allocation for video streaming.

/**
 * Allocates IEEE 1394 isochronous bandwidth units for video streaming
 * @param camera Camera instance
 * @param bandwidth_units Number of bandwidth units to allocate
 * @return DC1394_SUCCESS on success, error code on failure
 */
int dc1394_iso_allocate_bandwidth(dc1394camera_t camera, int bandwidth_units);

/**
 * Releases previously allocated IEEE 1394 isochronous bandwidth
 * @param camera Camera instance  
 * @param bandwidth_units Number of bandwidth units to release
 * @return DC1394_SUCCESS on success, error code on failure
 */
int dc1394_iso_release_bandwidth(dc1394camera_t camera, int bandwidth_units);

Usage Example:

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

// Calculate required bandwidth for current video mode
IntPointer bandwidth = new IntPointer(1);
int err = dc1394_video_get_bandwidth_usage(camera, bandwidth);
if (err != DC1394_SUCCESS) {
    dc1394_log_error("Failed to get bandwidth usage: " + err);
    return;
}

// Allocate the required bandwidth
err = dc1394_iso_allocate_bandwidth(camera, bandwidth.get());
if (err != DC1394_SUCCESS) {
    dc1394_log_error("Failed to allocate bandwidth: " + err);
    return;
}

System.out.println("Allocated " + bandwidth.get() + " bandwidth units");

// Set up video transmission...

// Release bandwidth when done
dc1394_iso_release_bandwidth(camera, bandwidth.get());

Resource Persistence and Cleanup

Controls resource persistence across application restarts and provides cleanup functionality.

/**
 * Sets IEEE 1394 resources to persist across application restarts
 * Resources will remain allocated even if the application exits unexpectedly
 * @param camera Camera instance
 * @return DC1394_SUCCESS on success, error code on failure
 */
int dc1394_iso_set_persist(dc1394camera_t camera);

/**
 * Releases all IEEE 1394 resources (channels and bandwidth) allocated by this camera
 * Use this for cleanup when shutting down or in error conditions
 * @param camera Camera instance
 * @return DC1394_SUCCESS on success, error code on failure
 */
int dc1394_iso_release_all(dc1394camera_t camera);

Usage Example:

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

// For critical applications, set resources to persist
int err = dc1394_iso_set_persist(camera);
if (err != DC1394_SUCCESS) {
    dc1394_log_warning("Could not set resource persistence: " + err);
}

// Allocate resources and perform video operations...

// In error handling or shutdown code, release all resources
err = dc1394_iso_release_all(camera);
if (err != DC1394_SUCCESS) {
    dc1394_log_error("Failed to release all ISO resources: " + err);
}

Best Practices

Resource Management Pattern

Always follow this pattern for robust resource management:

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

public class ISOResourceExample {
    private dc1394camera_t camera;
    private IntPointer channel = new IntPointer(1);
    private int allocatedBandwidth = 0;
    
    public boolean setupVideoStreaming() {
        try {
            // 1. Allocate channel
            int err = dc1394_iso_allocate_channel(camera, 0, channel);
            if (err != DC1394_SUCCESS) {
                dc1394_log_error("Channel allocation failed: " + err);
                return false;
            }
            
            // 2. Get required bandwidth
            IntPointer bandwidth = new IntPointer(1);
            err = dc1394_video_get_bandwidth_usage(camera, bandwidth);
            if (err != DC1394_SUCCESS) {
                dc1394_log_error("Bandwidth query failed: " + err);
                cleanup();
                return false;
            }
            
            // 3. Allocate bandwidth
            allocatedBandwidth = bandwidth.get();
            err = dc1394_iso_allocate_bandwidth(camera, allocatedBandwidth);
            if (err != DC1394_SUCCESS) {
                dc1394_log_error("Bandwidth allocation failed: " + err);
                cleanup();
                return false;
            }
            
            System.out.println("ISO resources allocated successfully");
            System.out.println("Channel: " + channel.get() + ", Bandwidth: " + allocatedBandwidth);
            return true;
            
        } catch (Exception e) {
            dc1394_log_error("Exception during resource allocation: " + e.getMessage());
            cleanup();
            return false;
        }
    }
    
    public void cleanup() {
        // Always clean up in reverse order of allocation
        if (allocatedBandwidth > 0) {
            dc1394_iso_release_bandwidth(camera, allocatedBandwidth);
            allocatedBandwidth = 0;
        }
        
        if (channel.get() >= 0) {
            dc1394_iso_release_channel(camera, channel.get());
            channel.put(-1);
        }
    }
}

Multi-Camera Considerations

When working with multiple cameras, coordinate resource allocation:

// For multi-camera setups, allocate resources for all cameras first
List<dc1394camera_t> cameras = // ... initialized cameras
List<IntPointer> channels = new ArrayList<>();
int totalBandwidth = 0;

// Calculate total bandwidth requirements
for (dc1394camera_t camera : cameras) {
    IntPointer bandwidth = new IntPointer(1);
    dc1394_video_get_bandwidth_usage(camera, bandwidth);
    totalBandwidth += bandwidth.get();
}

// Check if total bandwidth is available before proceeding
if (totalBandwidth > MAX_AVAILABLE_BANDWIDTH) {
    dc1394_log_error("Insufficient bandwidth for all cameras: " + totalBandwidth);
    return false;
}

// Allocate resources for each camera
for (dc1394camera_t camera : cameras) {
    IntPointer channel = new IntPointer(1);
    dc1394_iso_allocate_channel(camera, 0, channel);
    channels.add(channel);
    
    IntPointer bandwidth = new IntPointer(1);
    dc1394_video_get_bandwidth_usage(camera, bandwidth);
    dc1394_iso_allocate_bandwidth(camera, bandwidth.get());
}

Error Handling

ISO resource functions return standard libdc1394 error codes:

int err = dc1394_iso_allocate_channel(camera, 0, channel);
switch (err) {
    case DC1394_SUCCESS:
        System.out.println("Channel allocated successfully");
        break;
    case DC1394_FAILURE:
        dc1394_log_error("General failure in channel allocation");
        break;
    case DC1394_MEMORY_ALLOCATION_FAILURE:
        dc1394_log_error("Out of memory during channel allocation");
        break;
    default:
        dc1394_log_error("Unexpected error in channel allocation: " + err);
        break;
}

Use dc1394_iso_release_all() in exception handlers to ensure cleanup:

try {
    // ISO resource operations...
} catch (Exception e) {
    dc1394_log_error("Exception occurred: " + e.getMessage());
    dc1394_iso_release_all(camera);  // Emergency cleanup
    throw e;
}

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