The Camera API provides functions for capturing video from PlayStation Eye and compatible USB cameras, including control over camera settings, video formats, and frame capture.
Initialization
cameraInit
Initialize the camera library.
Returns 0 on success, error code on failure
Example:
#include <io/camera.h>
#include <sysmodule/sysmodule.h>
// Load camera module
SysLoadModule (SYSMODULE_CAM);
// Initialize camera
if ( cameraInit () != 0 ) {
printf ( "Failed to initialize camera \n " );
return - 1 ;
}
cameraEnd
End camera operations and cleanup resources.
Returns 0 on success, error code on failure
Camera Detection
cameraIsAvailable
Check if a camera is available at the specified device number.
s32 cameraIsAvailable (s32 num );
Returns non-zero if camera is available, 0 otherwise
cameraIsAttached
Check if a camera is physically attached.
s32 cameraIsAttached (s32 num );
cameraGetType
Get the type of the connected camera.
s32 cameraGetType (s32 num , cameraType * type );
Pointer to receive camera type
Camera Types:
typedef enum _camera_type {
CAM_TYPE_UNKNOWN, // Unknown camera
CAM_TYPE_EYETOY, // EyeToy camera (PS2)
CAM_TYPE_PLAYSTATION_EYE, // PlayStation Eye (PS3)
CAM_TYPE_USBVIDEO_CLASS, // Generic USB video class camera
} cameraType;
Opening and Closing
cameraOpenEx
Open a camera with extended configuration.
s32 cameraOpenEx (s32 num , cameraInfoEx * info );
Camera device number (typically 0)
Pointer to cameraInfoEx structure with camera configuration
Returns 0 on success, error code on failure
cameraInfoEx Structure:
typedef struct _camera_info_ex {
cameraFormat format; // Video format
cameraResolution resolution; // Video resolution
s32 framerate; // Frame rate (FPS)
u32 buffer; // Buffer address
s32 bytesize; // Buffer size in bytes
s32 width; // Frame width (output)
s32 height; // Frame height (output)
s32 dev_num; // Device number
s32 guid; // Device GUID
s32 info_ver; // Info version
sys_mem_container_t container; // Memory container
s32 readmode; // Read mode
u32 pbuf [ 2 ]; // Ping-pong buffers
} cameraInfoEx;
Show cameraInfoEx Configuration
Video format:
CAM_FORM_JPG: JPEG format
CAM_FORM_RAW8: Raw 8-bit
CAM_FORM_YUV422: YUV 4:2:2
CAM_FORM_RAW10: Raw 10-bit
CAM_FORM_RGBA: RGBA format
CAM_FORM_YUV420: YUV 4:2:0
Video resolution:
CAM_RESO_VGA: 640x480
CAM_RESO_QVGA: 320x240
CAM_RESO_WGA: Widescreen
CAM_RESO_SPECIFIED: Custom resolution
Desired frame rate (e.g., 30, 60, 120 FPS)
Memory container for camera buffers (can be 0 for auto-allocation)
Example:
cameraInfoEx cam_info;
memset ( & cam_info , 0 , sizeof (cameraInfoEx));
// Configure camera
cam_info.format = CAM_FORM_YUV422;
cam_info.resolution = CAM_RESO_VGA; // 640x480
cam_info.framerate = 30 ;
cam_info.container = 0 ; // Auto-allocate memory
// Open camera
if ( cameraOpenEx ( 0 , & cam_info ) != 0 ) {
printf ( "Failed to open camera \n " );
return - 1 ;
}
printf ( "Camera opened: %d x %d @ %d FPS \n " ,
cam_info.width, cam_info.height, cam_info.framerate);
printf ( "Buffer size: %d bytes \n " , cam_info.bytesize);
cameraClose
Close a camera device.
s32 cameraClose (s32 num );
cameraIsOpen
Check if a camera is currently open.
s32 cameraIsOpen (s32 num );
Returns non-zero if camera is open, 0 otherwise
Starting and Stopping Capture
cameraStart
Start video capture from the camera.
s32 cameraStart (s32 num );
Returns 0 on success, error code on failure
cameraStop
Stop video capture.
cameraIsStarted
Check if camera capture is active.
s32 cameraIsStarted (s32 num );
Returns non-zero if capture is started, 0 otherwise
Reading Frames
cameraReadEx
Read a frame from the camera (extended version).
s32 cameraReadEx (s32 num , cameraReadInfo * info );
Pointer to cameraReadInfo structure to receive frame information
Returns 0 on success, error code on failure
cameraReadInfo Structure:
typedef struct _camera_read_info {
s32 version; // Version number
u32 frame; // Frame number
u32 readcount; // Read count
s64 timestamp; // Frame timestamp
u32 buffer; // Buffer address containing frame data
} cameraReadInfo;
Example:
cameraReadInfo read_info;
u32 frame_count = 0 ;
while (running) {
// Read frame
if ( cameraReadEx ( 0 , & read_info) == 0 ) {
frame_count ++ ;
// Access frame data
u8 * frame_data = (u8 * ) read_info . buffer ;
printf ( "Frame %d : timestamp= %lld , buffer=0x %08X \n " ,
read_info . frame , read_info . timestamp , read_info . buffer );
// Process frame data here
// ...
// Signal read complete
cameraReadComplete ( 0 , read_info . buffer , 0 );
}
}
cameraRead
Read a frame from the camera (simple version).
s32 cameraRead (s32 num , u32 * frame , u32 * readcount );
Pointer to receive frame number
Pointer to receive read count
cameraReadComplete
Signal that frame processing is complete and buffer can be reused.
s32 cameraReadComplete (s32 num , u32 buf , u32 arg );
Buffer address from cameraReadEx
Additional argument (typically 0)
Camera Attributes
cameraGetAttribute
Get a camera attribute value.
s32 cameraGetAttribute (s32 num , cameraAttrib attribute , u32 * arg0 , u32 * arg1 );
Pointer to receive first attribute value
Pointer to receive second attribute value
cameraSetAttribute
Set a camera attribute value.
s32 cameraSetAttribute (s32 num , cameraAttrib attribute , u32 arg0 , u32 arg1 );
Common Camera Attributes:
Show Image Quality Attributes
CAM_ATTR_GAIN // Camera gain
CAM_ATTR_EXPOSURE // Exposure time
CAM_ATTR_BRIGHTNESS // Brightness level
CAM_ATTR_SATURATION // Color saturation
CAM_ATTR_GAMMA // Gamma correction
CAM_ATTR_RED_BLUE_GAIN // Red/blue gain (white balance)
CAM_ATTR_GREEN_GAIN // Green gain
CAM_ATTR_AUTO_EXPOSURE // Auto exposure control
CAM_ATTR_AUTO_GAIN_CONTROL // Auto gain control
CAM_ATTR_AUTO_WHITE_BALANCE // Auto white balance
CAM_ATTR_AUTO_BRIGHTNESS // Auto brightness
CAM_ATTR_BACKLIGHT_COMPENSATION // Backlight compensation
CAM_ATTR_LED // LED control
CAM_ATTR_AUDIO_GAIN // Audio gain (for cameras with mic)
CAM_ATTR_MIRROR_FLAG // Mirror/flip image
CAM_ATTR_DENOISE // Noise reduction
CAM_ATTR_FRAMERATE_ADJUST // Frame rate adjustment
CAM_ATTR_PIXEL_OUTLIER_FILTER // Pixel outlier filtering
Example - Adjusting Camera Settings:
// Enable auto exposure
cameraSetAttribute ( 0 , CAM_ATTR_AUTO_EXPOSURE, 1 , 0 );
// Set brightness
cameraSetAttribute ( 0 , CAM_ATTR_BRIGHTNESS, 128 , 0 ); // 0-255
// Set exposure manually
cameraSetAttribute ( 0 , CAM_ATTR_AUTO_EXPOSURE, 0 , 0 ); // Disable auto
cameraSetAttribute ( 0 , CAM_ATTR_EXPOSURE, 500 , 0 ); // Set value
// Enable mirror mode
cameraSetAttribute ( 0 , CAM_ATTR_MIRROR_FLAG, 1 , 0 );
// Control LED (PlayStation Eye)
cameraSetAttribute ( 0 , CAM_ATTR_LED, 1 , 0 ); // Turn on LED
// Get current gain
u32 gain_value, unused;
cameraGetAttribute ( 0 , CAM_ATTR_GAIN, & gain_value , & unused );
printf ( "Current gain: %d \n " , gain_value);
Utility Functions
cameraGetBufferSize
Get the required buffer size for camera frames.
s32 cameraGetBufferSize (s32 num , cameraInfoEx * info );
cameraGetBufferInfoEx
Get extended buffer information.
s32 cameraGetBufferInfoEx (s32 num , cameraInfoEx * info );
cameraReset
Reset the camera to default settings.
s32 cameraReset (s32 num );
cameraGetDeviceGUID
Get the camera’s unique GUID.
s32 cameraGetDeviceGUID (s32 num , u32 * guid );
Event Notifications
cameraSetNotifyEventQueue
Set an event queue for camera notifications.
s32 cameraSetNotifyEventQueue (u64 key );
cameraSetNotifyEventQueue2
Set an event queue with additional parameters.
s32 cameraSetNotifyEventQueue2 (u64 key , u64 source , u64 flag );
cameraRemoveNotifyEventQueue
Remove a camera event queue.
s32 cameraRemoveNotifyEventQueue (u64 key );
cameraRemoveNotifyEventQueue2
Remove a camera event queue (alternate version).
s32 cameraRemoveNotifyEventQueue2 (u64 key );
Extension Units
For advanced camera control:
cameraPrepExtensionUnit
Prepare camera extension unit.
s32 cameraPrepExtensionUnit (s32 num , u8 * guidExtCode );
cameraCtrlExtensionUnit
Control camera extension unit.
s32 cameraCtrlExtensionUnit (s32 num , u8 req , u16 wval , u16 wlen , u8 * data );
cameraGetExtensionUnit
Get data from extension unit.
s32 cameraGetExtensionUnit (s32 num , u16 wval , u16 wlen , u8 * data );
cameraSetExtensionUnit
Set data to extension unit.
s32 cameraSetExtensionUnit (s32 num , u16 wval , u16 wlen , u8 * data );
Error Codes
#define CAMERA_ERRO_DOUBLE_INIT 0x 80140801 // Already initialized
#define CAMERA_ERRO_NEED_INIT 0x 80140803 // Not initialized
#define CAMERA_ERRO_BAD_PARAM 0x 80140804 // Invalid parameter
#define CAMERA_ERRO_DOUBLE_OPEN 0x 80140805 // Already open
#define CAMERA_ERRO_NEED_OPEN 0x 80140806 // Not open
#define CAMERA_ERRO_NO_DEVICE_FOUND 0x 80140807 // No device found
#define CAMERA_ERRO_DEVICE_DEACTIVATED 0x 80140808 // Device deactivated
#define CAMERA_ERRO_NEED_START 0x 80140809 // Capture not started
#define CAMERA_ERRO_UNKNOWN_FORMAT 0x 8014080a // Unknown format
#define CAMERA_ERRO_UNKNOWN_RESOLUTION 0x 8014080b // Unknown resolution
#define CAMERA_ERRO_BAD_FRAMERATE 0x 8014080c // Invalid frame rate
#define CAMERA_ERRO_TIMEOUT 0x 8014080d // Operation timeout
#define CAMERA_ERRO_BUSY 0x 8014080e // Device busy
#define CAMERA_ERRO_FATAL 0x 8014080f // Fatal error
#define CAMERA_ERRO_MUTEX 0x 80140810 // Mutex error
Complete Example
#include <io/camera.h>
#include <sysmodule/sysmodule.h>
#include <stdio.h>
#include <unistd.h>
int main () {
cameraType type;
cameraInfoEx cam_info;
cameraReadInfo read_info;
// Load camera module
SysLoadModule (SYSMODULE_CAM);
// Initialize camera
if ( cameraInit () != 0 ) {
printf ( "Failed to initialize camera \n " );
return - 1 ;
}
// Check if camera is available
if ( ! cameraIsAvailable ( 0 )) {
printf ( "No camera available \n " );
cameraEnd ();
return - 1 ;
}
// Get camera type
cameraGetType ( 0 , & type);
switch (type) {
case CAM_TYPE_PLAYSTATION_EYE:
printf ( "PlayStation Eye detected \n " );
break ;
case CAM_TYPE_EYETOY:
printf ( "EyeToy detected \n " );
break ;
case CAM_TYPE_USBVIDEO_CLASS:
printf ( "USB Video Class camera detected \n " );
break ;
default :
printf ( "Unknown camera type \n " );
break ;
}
// Configure camera
memset ( & cam_info, 0 , sizeof (cameraInfoEx));
cam_info . format = CAM_FORM_YUV422;
cam_info . resolution = CAM_RESO_VGA; // 640x480
cam_info . framerate = 30 ;
cam_info . container = 0 ;
// Open camera
if ( cameraOpenEx ( 0 , & cam_info) != 0 ) {
printf ( "Failed to open camera \n " );
cameraEnd ();
return - 1 ;
}
printf ( "Camera opened: %d x %d @ %d FPS \n " ,
cam_info . width , cam_info . height , cam_info . framerate );
printf ( "Buffer size: %d bytes \n " , cam_info . bytesize );
// Configure camera settings
cameraSetAttribute ( 0 , CAM_ATTR_AUTO_EXPOSURE, 1 , 0 );
cameraSetAttribute ( 0 , CAM_ATTR_AUTO_WHITE_BALANCE, 1 , 0 );
cameraSetAttribute ( 0 , CAM_ATTR_BRIGHTNESS, 128 , 0 );
cameraSetAttribute ( 0 , CAM_ATTR_LED, 1 , 0 ); // Turn on LED
// Start capture
if ( cameraStart ( 0 ) != 0 ) {
printf ( "Failed to start camera \n " );
cameraClose ( 0 );
cameraEnd ();
return - 1 ;
}
printf ( "Capturing frames... \n " );
// Capture loop
int frame_count = 0 ;
while (frame_count < 300 ) { // Capture 300 frames (10 seconds at 30fps)
if ( cameraReadEx ( 0 , & read_info) == 0 ) {
frame_count ++ ;
// Access frame data
u8 * frame_data = (u8 * ) read_info . buffer ;
printf ( "Frame %d captured (timestamp: %lld ) \n " ,
read_info . frame , read_info . timestamp );
// Process frame data here
// For YUV422: 2 bytes per pixel
// Total size: width * height * 2
// Signal read complete
cameraReadComplete ( 0 , read_info . buffer , 0 );
} else {
usleep ( 10000 ); // Wait if no frame available
}
}
// Cleanup
printf ( "Stopping camera... \n " );
cameraStop ( 0 );
cameraClose ( 0 );
cameraEnd ();
SysUnloadModule (SYSMODULE_CAM);
printf ( "Done. Captured %d frames. \n " , frame_count);
return 0 ;
}