Update of /cvsroot/playerstage/code/player/server/drivers/camera/v4l
In directory
sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18421/server/drivers/camera/v4l
Modified Files:
camerav4l.cc v4lcapture.c v4lcapture.h v4lframe.c v4lframe.h
Log Message:
applied patch 1815600
Index: v4lcapture.h
===================================================================
RCS file:
/cvsroot/playerstage/code/player/server/drivers/camera/v4l/v4lcapture.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** v4lcapture.h 26 Jan 2006 13:31:11 -0000 1.2
--- v4lcapture.h 18 Oct 2007 22:33:27 -0000 1.3
***************
*** 64,67 ****
--- 64,71 ----
//==========================================================================
+ #ifndef VIDEO_PALETTE_JPEG
+ #define VIDEO_PALETTE_JPEG 21
+ #endif
+
// Standard device for fg_open()
#define FG_DEFAULT_DEVICE "/dev/video0"
***************
*** 134,137 ****
--- 138,142 ----
FRAMEGRABBER* fg_open( const char *dev );
+ int fg_enable_capture( FRAMEGRABBER* fg, int flag );
//--------------------------------------------------------------------------
***************
*** 167,170 ****
--- 172,176 ----
FRAME* fg_grab( FRAMEGRABBER* fg );
+ int fg_read(FRAMEGRABBER * fg, FRAME * fr);
//--------------------------------------------------------------------------
***************
*** 325,329 ****
// Description: Sets the picture brightness to the specified value.
//
! // Parameters: int br Brightness (in percent)
//
// Returns: 0 Success
--- 331,335 ----
// Description: Sets the picture brightness to the specified value.
//
! // Parameters: int br Brightness (integer value)
//
// Returns: 0 Success
***************
*** 341,345 ****
// Description: Sets the picture contrast to the specified value.
//
! // Parameters: int ct Contrast (in percent)
//
// Returns: 0 Success
--- 347,351 ----
// Description: Sets the picture contrast to the specified value.
//
! // Parameters: int ct Contrast (integer value)
//
// Returns: 0 Success
***************
*** 350,353 ****
--- 356,361 ----
int fg_set_contrast( FRAMEGRABBER* fg, int ct );
+ int fg_set_hue( FRAMEGRABBER* fg, int hue );
+ int fg_set_colour( FRAMEGRABBER* fg, int clr );
//--------------------------------------------------------------------------
Index: camerav4l.cc
===================================================================
RCS file:
/cvsroot/playerstage/code/player/server/drivers/camera/v4l/camerav4l.cc,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -d -r1.30 -r1.31
*** camerav4l.cc 23 Aug 2007 19:58:43 -0000 1.30
--- camerav4l.cc 18 Oct 2007 22:33:27 -0000 1.31
***************
*** 55,59 ****
- port (string)
- Default: "/dev/video0"
! - %Device to read video data from.
- source (integer)
--- 55,59 ----
- port (string)
- Default: "/dev/video0"
! - Device to read video data from.
- source (integer)
***************
*** 80,83 ****
--- 80,84 ----
- YUV420P (planar YUV data converted to 24-bit color images)
- YUV420P_GREY (planar YUV data; will produce 8-bit monochrome images)
+ - JPEG (for some webcams)
- Note that not all capture modes are supported by Player's internal image
format; in these modes, images will be translated to the closest matching
***************
*** 93,101 ****
- max_buffer (integer)
! - Default: -1 (dont set)
- Limit the maximum number of buffers to use for grabbing. This reduces
latency, but also
potentially reduces throughput. Use this if you are reading slowly from
the player
driver and dont want to get stale frames
Note that some of these options may not be honoured by the underlying
V4L kernel driver (it may not support a given image size, for
--- 94,126 ----
- max_buffer (integer)
! - Default: -1 (do not set)
- Limit the maximum number of buffers to use for grabbing. This reduces
latency, but also
potentially reduces throughput. Use this if you are reading slowly from
the player
driver and dont want to get stale frames
+ - brightness (integer)
+ - Default: -1 (do not set)
+
+ - hue (integer)
+ - Default: -1 (do not set)
+
+ - colour (integer)
+ - Default: -1 (do not set)
+
+ - contrast (integer)
+ - Default: -1 (do not set)
+
+ - read_mode (integer)
+ - Default: 0
+ - Set to 1 if read should be used instead of grab (in most cases it isn't a
good idea!)
+
+ - publish_interval (integer)
+ - Default: 0
+ - how many second between publishing real images (may break your client
app!)
+
+ - sleep_nsec (integer)
+ - Default: 10000000 (=10ms which gives max 100 fps)
+ - timespec value for nanosleep()
+
Note that some of these options may not be honoured by the underlying
V4L kernel driver (it may not support a given image size, for
***************
*** 160,170 ****
#include "ccvt.h" // For YUV420P-->RGB conversion
-
- const timespec NSLEEP_TIME = {0, 10000000}; // (0s, 10 ms) => max 100 fps
-
// Time for timestamps
extern PlayerTime *GlobalTime;
-
// Driver for detecting laser retro-reflectors.
class CameraV4L : public Driver
--- 185,191 ----
***************
*** 223,230 ****
// unpack jpeg data from ov519 based cameras
private: int have_ov519;
!
// Capture timestamp
private: uint32_t tsec, tusec;
// Data to send to server
private: player_camera_data_t data;
--- 244,267 ----
// unpack jpeg data from ov519 based cameras
private: int have_ov519;
!
! private: int brightness;
!
! private: int hue;
!
! private: int colour;
!
! private: int contrast;
!
! private: int read_mode;
!
! private: int publish_interval;
!
! private: int sleep_nsec;
!
// Capture timestamp
private: uint32_t tsec, tusec;
+ private: time_t publish_time;
+
// Data to send to server
private: player_camera_data_t data;
***************
*** 253,257 ****
section,
true,
! PLAYER_MSGQUEUE_DEFAULT_MAXLEN,
PLAYER_CAMERA_CODE)
{
--- 290,294 ----
section,
true,
! 1, // 1 instead of PLAYER_MSGQUEUE_DEFAULT_MAXLEN
PLAYER_CAMERA_CODE)
{
***************
*** 292,295 ****
--- 329,334 ----
this->palette = cf->ReadString(section, "mode", "RGB888");
+ this->max_buffer = cf->ReadInt(section, "max_buffer", -1);
+
// Save frames?
this->save = cf->ReadInt(section, "save", 0);
***************
*** 298,306 ****
this->have_ov519 = cf->ReadInt(section, "have_ov519", 0);
! // unpack ov519
! this->max_buffer = cf->ReadInt(section, "max_buffer", -1);
!
! return;
}
--- 337,353 ----
this->have_ov519 = cf->ReadInt(section, "have_ov519", 0);
! this->brightness = cf->ReadInt(section, "brightness", -1);
! this->hue = cf->ReadInt(section, "hue", -1);
!
! this->colour = cf->ReadInt(section, "colour", -1);
!
! this->contrast = cf->ReadInt(section, "contrast", -1);
!
! this->read_mode = cf->ReadInt(section, "read_mode", 0);
!
! this->publish_interval = cf->ReadInt(section, "publish_interval", 0);
!
! this->sleep_nsec = cf->ReadInt(section, "sleep_nsec", 10000000);
}
***************
*** 371,374 ****
--- 418,428 ----
this->depth = 8;
}
+ else if (strcasecmp(this->palette, "JPEG") == 0)
+ {
+ fg_set_format(this->fg, VIDEO_PALETTE_JPEG );
+ this->frame = frame_new(this->width, this->height, VIDEO_PALETTE_JPEG );
+ this->data.format = PLAYER_CAMERA_FORMAT_RGB888;
+ this->depth = 24;
+ }
else
{
***************
*** 409,415 ****
--- 463,476 ----
{
struct timeval time;
+ struct timespec tspec;
int frameno;
char filename[256];
+ if (this->brightness > 0) fg_set_brightness(this->fg, this->brightness);
+ if (this->hue > 0) fg_set_hue(this->fg, this->hue);
+ if (this->colour > 0) fg_set_colour(this->fg, this->colour);
+ if (this->contrast > 0) fg_set_contrast(this->fg, this->contrast);
+
+ this->publish_time = 0;
frameno = 0;
***************
*** 417,421 ****
{
// Go to sleep for a while (this is a polling loop).
! nanosleep(&NSLEEP_TIME, NULL);
// Test if we are supposed to cancel this thread.
--- 478,484 ----
{
// Go to sleep for a while (this is a polling loop).
! tspec.tv_sec = 0;
! tspec.tv_nsec = this->sleep_nsec;
! nanosleep(&tspec, NULL);
// Test if we are supposed to cancel this thread.
***************
*** 431,435 ****
// Grab the next frame (blocking)
! fg_grab_frame(this->fg, this->frame);
// Write data to server
--- 494,504 ----
// Grab the next frame (blocking)
! if (this->read_mode)
! {
! fg_read(this->fg, this->frame);
! } else
! {
! fg_grab_frame(this->fg, this->frame);
! }
// Write data to server
***************
*** 481,512 ****
{
int i;
! size_t image_count, size;
unsigned char * ptr1, * ptr2;
- // Compute size of image
- image_count = this->width * this->height * this->depth / 8;
-
// Set the image properties
this->data.width = this->width;
this->data.height = this->height;
this->data.bpp = this->depth;
! this->data.image_count = image_count;
this->data.compression = PLAYER_CAMERA_COMPRESS_RAW;
! assert(image_count <= sizeof(this->data.image));
if (have_ov519)
{
this->data.image_count = (*(unsigned short *)(frame->data))*8;
this->data.compression = PLAYER_CAMERA_COMPRESS_JPEG;
memcpy(data.image, &(((char*)frame->data)[2]), data.image_count);
}
else
{
// Copy the image pixels
! if ((this->frame->format == VIDEO_PALETTE_YUV420P)&&
(this->data.format == PLAYER_CAMERA_FORMAT_RGB888))
{// do conversion to RGB (which is bgr at the moment for some reason?)
! assert(image_count <= (size_t) this->rgb_converted_frame->size);
ccvt_420p_bgr24(this->width, this->height,
(unsigned char*) this->frame->data,
--- 550,591 ----
{
int i;
! size_t size;
unsigned char * ptr1, * ptr2;
// Set the image properties
this->data.width = this->width;
this->data.height = this->height;
this->data.bpp = this->depth;
! this->data.image_count = this->width * this->height * this->depth / 8;
this->data.compression = PLAYER_CAMERA_COMPRESS_RAW;
! assert(data.image_count <= sizeof(this->data.image));
if (have_ov519)
{
this->data.image_count = (*(unsigned short *)(frame->data))*8;
+ assert(data.image_count > 0);
+ assert(data.image_count <= sizeof(this->data.image));
+ assert(data.image_count <= ((size_t)(this->frame->size)));
this->data.compression = PLAYER_CAMERA_COMPRESS_JPEG;
memcpy(data.image, &(((char*)frame->data)[2]), data.image_count);
}
+ else if (this->fg->picture.palette == VIDEO_PALETTE_JPEG)
+ {
+ this->data.compression = PLAYER_CAMERA_COMPRESS_JPEG;
+ memcpy(&i, this->frame->data, sizeof(int));
+ data.image_count = i;
+ assert(data.image_count > 0);
+ assert(data.image_count <= sizeof(this->data.image));
+ assert(data.image_count <= ((size_t)(this->frame->size)));
+ memcpy(data.image, ((unsigned char *)(this->frame->data)) + sizeof(int),
data.image_count);
+ }
else
{
// Copy the image pixels
! if ((this->frame->format == VIDEO_PALETTE_YUV420P) &&
(this->data.format == PLAYER_CAMERA_FORMAT_RGB888))
{// do conversion to RGB (which is bgr at the moment for some reason?)
! assert(data.image_count <= (size_t)
this->rgb_converted_frame->size);
ccvt_420p_bgr24(this->width, this->height,
(unsigned char*) this->frame->data,
***************
*** 516,520 ****
else
{
! assert(image_count <= (size_t) this->frame->size);
ptr1 = (unsigned char *)this->frame->data;
}
--- 595,599 ----
else
{
! assert(data.image_count <= (size_t) this->frame->size);
ptr1 = (unsigned char *)this->frame->data;
}
***************
*** 534,538 ****
case 32:
for (i = 0; i < ((this->width) * (this->height)); i++)
! {
ptr2[0] = ptr1[2];
ptr2[1] = ptr1[1];
--- 613,617 ----
case 32:
for (i = 0; i < ((this->width) * (this->height)); i++)
! {
ptr2[0] = ptr1[2];
ptr2[1] = ptr1[1];
***************
*** 544,548 ****
break;
default:
! memcpy(ptr2, ptr1, image_count);
}
}
--- 623,627 ----
break;
default:
! memcpy(ptr2, ptr1, data.image_count);
}
}
***************
*** 550,556 ****
// Copy data to server
size = sizeof(this->data) - sizeof(this->data.image) + data.image_count;
- /* We should do this to be efficient */
Publish(this->device_addr,
PLAYER_MSGTYPE_DATA, PLAYER_CAMERA_DATA_STATE,
--- 629,646 ----
// Copy data to server
size = sizeof(this->data) - sizeof(this->data.image) + data.image_count;
+ /* We should do this to be efficient */
+ if (this->publish_interval)
+ {
+ if ((time(NULL) - (this->publish_time)) < (this->publish_interval))
+ {
+ this->data.width = 0;
+ this->data.height = 0;
+ this->data.bpp = 0;
+ this->data.image_count = 0;
+ size = sizeof(this->data) - sizeof(this->data.image);
+ } else this->publish_time = time(NULL);
+ }
Publish(this->device_addr,
PLAYER_MSGTYPE_DATA, PLAYER_CAMERA_DATA_STATE,
***************
*** 559,562 ****
return;
}
-
-
--- 649,650 ----
Index: v4lframe.h
===================================================================
RCS file:
/cvsroot/playerstage/code/player/server/drivers/camera/v4l/v4lframe.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** v4lframe.h 10 Jun 2004 17:56:37 -0000 1.1
--- v4lframe.h 18 Oct 2007 22:33:27 -0000 1.2
***************
*** 57,60 ****
--- 57,64 ----
//--------------------------------------------------------------------------
+ #ifndef VIDEO_PALETTE_JPEG
+ #define VIDEO_PALETTE_JPEG 21
+ #endif
+
typedef struct
{
Index: v4lframe.c
===================================================================
RCS file:
/cvsroot/playerstage/code/player/server/drivers/camera/v4l/v4lframe.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** v4lframe.c 23 Sep 2004 01:03:13 -0000 1.2
--- v4lframe.c 18 Oct 2007 22:33:27 -0000 1.3
***************
*** 111,114 ****
--- 111,119 ----
break;
+ case VIDEO_PALETTE_JPEG:
+ // 3 bytes per pixel
+ size = pixels * 3;
+ break;
+
default:
// Unsupported!
Index: v4lcapture.c
===================================================================
RCS file:
/cvsroot/playerstage/code/player/server/drivers/camera/v4l/v4lcapture.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** v4lcapture.c 9 Jul 2007 17:17:59 -0000 1.8
--- v4lcapture.c 18 Oct 2007 22:33:27 -0000 1.9
***************
*** 381,384 ****
--- 381,387 ----
{
int capture_frame = fg->cur_frame + 1;
+ int i;
+ int insize, count;
+ unsigned char * buf;
//----------------------
***************
*** 438,445 ****
}
! // Save video buffer into our own memory
! memcpy( fr->data,
! fg->mb_map + fg->mbuf.offsets[fg->cur_frame],
! frame_get_size( fr ) );
// Move along to the next one
--- 441,466 ----
}
! if ((fg->picture.palette) == VIDEO_PALETTE_JPEG)
! {
! buf = (unsigned char *)(fg->mb_map + fg->mbuf.offsets[fg->cur_frame]);
! insize = frame_get_size(fr) - sizeof(int);
! count = insize - 1;
! for (i = 1024; i < count; i++)
! {
! if (buf[i] == 0xff) if (buf[i + 1] == 0xd9)
! {
! insize = i + 10;
! break;
! }
! }
! memcpy(fr->data, &insize, sizeof(int));
! memcpy(((unsigned char *)(fr->data)) + sizeof(int), buf, insize);
! } else
! {
! // Save video buffer into our own memory
! memcpy( fr->data,
! fg->mb_map + fg->mbuf.offsets[fg->cur_frame],
! frame_get_size( fr ) );
! }
// Move along to the next one
***************
*** 464,472 ****
}
//--------------------------------------------------------------------------
int fg_set_brightness( FRAMEGRABBER* fg, int br )
{
! fg->picture.brightness = FG_PERCENT( br );
if ( ioctl( fg->fd, VIDIOCSPICT, &(fg->picture) ) < 0 )
--- 485,511 ----
}
+ int fg_read(FRAMEGRABBER * fg, FRAME * fr)
+ {
+ int count;
+
+ if ((fg->picture.palette) == VIDEO_PALETTE_JPEG)
+ {
+ count = read(fg->fd, ((unsigned char *)(fr->data)) + sizeof(int),
frame_get_size(fr) - sizeof(int));
+ memcpy(fr->data, &count, sizeof(int));
+ } else count = read(fg->fd, fr->data, frame_get_size(fr));
+ return count;
+ }
+
//--------------------------------------------------------------------------
int fg_set_brightness( FRAMEGRABBER* fg, int br )
{
! if ( ioctl( fg->fd, VIDIOCGPICT, &(fg->picture) ) < 0 )
! {
! perror( "fg_set_brightness(): get attribute failed" );
! return -1;
! }
!
! fg->picture.brightness = br;
if ( ioctl( fg->fd, VIDIOCSPICT, &(fg->picture) ) < 0 )
***************
*** 481,487 ****
//--------------------------------------------------------------------------
int fg_set_contrast( FRAMEGRABBER* fg, int ct )
{
! fg->picture.contrast = FG_PERCENT( ct );
if ( ioctl( fg->fd, VIDIOCSPICT, &(fg->picture) ) < 0 )
--- 520,574 ----
//--------------------------------------------------------------------------
+ int fg_set_hue( FRAMEGRABBER* fg, int hue )
+ {
+ if ( ioctl( fg->fd, VIDIOCGPICT, &(fg->picture) ) < 0 )
+ {
+ perror( "fg_set_hue(): get attribute failed" );
+ return -1;
+ }
+
+ fg->picture.hue = hue;
+
+ if ( ioctl( fg->fd, VIDIOCSPICT, &(fg->picture) ) < 0 )
+ {
+ perror( "fg_set_hue(): set attribute failed" );
+ return -1;
+ }
+
+ return 0;
+ }
+
+ //--------------------------------------------------------------------------
+
+ int fg_set_colour( FRAMEGRABBER* fg, int clr )
+ {
+ if ( ioctl( fg->fd, VIDIOCGPICT, &(fg->picture) ) < 0 )
+ {
+ perror( "fg_set_colour(): get attribute failed" );
+ return -1;
+ }
+
+ fg->picture.colour = clr;
+
+ if ( ioctl( fg->fd, VIDIOCSPICT, &(fg->picture) ) < 0 )
+ {
+ perror( "fg_set_colour(): set attribute failed" );
+ return -1;
+ }
+
+ return 0;
+ }
+
+ //--------------------------------------------------------------------------
+
int fg_set_contrast( FRAMEGRABBER* fg, int ct )
{
! if ( ioctl( fg->fd, VIDIOCGPICT, &(fg->picture) ) < 0 )
! {
! perror( "fg_set_contrast(): get attribute failed" );
! return -1;
! }
!
! fg->picture.contrast = ct;
if ( ioctl( fg->fd, VIDIOCSPICT, &(fg->picture) ) < 0 )
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit