camera_usb
Classes | Public Member Functions | Static Public Attributes | List of all members
camera::CamGst Class Reference

#include <cam_gst.h>

Public Member Functions

 CamGst (std::string const &device)
 
 ~CamGst ()
 
void createDefaultPipeline (bool check_for_valid_params=false, uint32_t width=DEFAULT_WIDTH, uint32_t height=DEFAULT_HEIGHT, uint32_t fps=DEFAULT_FPS, uint32_t bpp=DEFAULT_BPP, base::samples::frame::frame_mode_t mode=base::samples::frame::MODE_UNDEFINED, uint32_t jpeg_quality=DEFAULT_JPEG_QUALITY)
 
void deletePipeline ()
 
bool startPipeline ()
 
void stopPipeline ()
 
bool getBuffer (std::vector< uint8_t > &buffer, bool blocking_read=false, int32_t timeout=0)
 
bool skipBuffer ()
 
bool storeImageToFile (std::vector< uint8_t > const &buffer, std::string const &file_name)
 
bool hasNewBuffer ()
 
bool isPipelineRunning ()
 
int getFileDescriptor ()
 

Static Public Attributes

static const uint32_t DEFAULT_WIDTH = 640
 
static const uint32_t DEFAULT_HEIGHT = 480
 
static const uint32_t DEFAULT_FPS = 10
 
static const uint32_t DEFAULT_BPP = 24
 
static const uint32_t DEFAULT_JPEG_QUALITY = 85
 
static const uint32_t DEFAULT_PIPELINE_TIMEOUT = 4000000
 

Detailed Description

Allows to create a default GStreamer pipeline, which requests images using v4l2src, converts them to jpegs and gives access to the image data. Successfully tested with the Microsoft LifeCam Cinema Web camera and the Gumstix e-CAM32 camera.

Constructor & Destructor Documentation

camera::CamGst::CamGst ( std::string const &  device)

Initialize GStreamer and starts the GMainLoop in its own thread.

Parameters
deviceOnly used to configure the GStreamer source (e.g. /dev/video0).
cam_configPointer to a CamConfig object, used to get a valid image size and fps and for general configurations.
camera::CamGst::~CamGst ( )

Stops the GMainLoop and its thread.

Member Function Documentation

void camera::CamGst::createDefaultPipeline ( bool  check_for_valid_params = false,
uint32_t  width = DEFAULT_WIDTH,
uint32_t  height = DEFAULT_HEIGHT,
uint32_t  fps = DEFAULT_FPS,
uint32_t  bpp = DEFAULT_BPP,
base::samples::frame::frame_mode_t  mode = base::samples::frame::MODE_UNDEFINED,
uint32_t  jpeg_quality = DEFAULT_JPEG_QUALITY 
)

Creates a simple pipeline to write images with the requested format to a buffer.

Parameters
check_for_valid_paramsIf set to true the parameters (width, height, fps) are validated. If they are not valid on the camera valid parameters are used. In addition if you pass 0 for a parameter, the last valid parameter on the camera will be used. E.g. 'createDefaultPipeline(true,0,0,0,80)' would just change the JPEG quality. But for this functionality a CamConfig object has to be created, which uses the same device like GStreamer what should be avoided. In addition using this method within the CamUsb driver is not necessary because all parameters have been validated and set already.
If set to false the pipeline may not be created if the parameters are not supported by the camera (a CamGstException may be thrown).
modeValid modes: MODE_GRAYSCALE, MODE_RGB, MODE_UYVY, MODE_JPEG. If MODE_UNDEFINED is passed the raw image video/x-raw-yuv will be requested.
Returns
If an error occurs a CamGstException is thrown.
void camera::CamGst::deletePipeline ( )

Deletes pipeline, clears buffer.

bool camera::CamGst::getBuffer ( std::vector< uint8_t > &  buffer,
bool  blocking_read = false,
int32_t  timeout = 0 
)

Allows to request a copy of the new image.

Parameters
bufferWill receive the image if available.
blocking_readIf true, method will return as soon as a new image is available.
timeoutMax. time to wait for the frame in msec. < 1 means no timeout.
Returns
blocking-read not active: true if a new image is available, otherwise false.
blocking_read active: Returns true as soon as a new image is available or false after 'timeout' msec.
int camera::CamGst::getFileDescriptor ( )
inline

Returns the file descriptor used by GStreamer. The pipeline has to be running, otherwise -1 will be returned.

Returns
The fd or -1 if not available.
bool camera::CamGst::hasNewBuffer ( )
inline

True if a new buffer is available.

bool camera::CamGst::isPipelineRunning ( )
inline
bool camera::CamGst::skipBuffer ( )

Just sets mNewBuffer to false.

Returns
True if a new buffer was available.
bool camera::CamGst::startPipeline ( )

Starts current pipeline in another a intern GStreamer thread. Pipeline has to be already created. Restarting may not work, in this case an error message will be printed and false will be returned.

Warning
Just stopping and starting a pipeline may not work. You should delete and recreate the pipeline instead!
Returns
True if its already running or could be started.
void camera::CamGst::stopPipeline ( )
Warning
Just stopping and starting a pipeline may not work. You should delete and recreate the pipeline instead!
bool camera::CamGst::storeImageToFile ( std::vector< uint8_t > const &  buffer,
std::string const &  file_name 
)

Stores the image to a file.

Returns
false if the file could not be opened or not all of the bytes could be written.

Member Data Documentation

const uint32_t camera::CamGst::DEFAULT_BPP = 24
static
const uint32_t camera::CamGst::DEFAULT_FPS = 10
static
const uint32_t camera::CamGst::DEFAULT_HEIGHT = 480
static
const uint32_t camera::CamGst::DEFAULT_JPEG_QUALITY = 85
static
const uint32_t camera::CamGst::DEFAULT_PIPELINE_TIMEOUT = 4000000
static
const uint32_t camera::CamGst::DEFAULT_WIDTH = 640
static

The documentation for this class was generated from the following files: