Commit 58d47ae9 authored by Alexander Alekhin's avatar Alexander Alekhin

Merge pull request #11633 from alalek:issue_10546

parents 9d91c635 c94fe0c7
...@@ -265,8 +265,6 @@ struct buffer ...@@ -265,8 +265,6 @@ struct buffer
size_t length; size_t length;
}; };
static unsigned int n_buffers = 0;
struct CvCaptureCAM_V4L CV_FINAL : public CvCapture struct CvCaptureCAM_V4L CV_FINAL : public CvCapture
{ {
int deviceHandle; int deviceHandle;
...@@ -347,43 +345,10 @@ static int icvSetPropertyCAM_V4L( CvCaptureCAM_V4L* capture, int property_id, ...@@ -347,43 +345,10 @@ static int icvSetPropertyCAM_V4L( CvCaptureCAM_V4L* capture, int property_id,
/*********************** Implementations ***************************************/ /*********************** Implementations ***************************************/
static int numCameras = 0;
static int indexList = 0;
CvCaptureCAM_V4L::~CvCaptureCAM_V4L() { CvCaptureCAM_V4L::~CvCaptureCAM_V4L() {
icvCloseCAM_V4L(this); icvCloseCAM_V4L(this);
} }
/* Simple test program: Find number of Video Sources available.
Start from 0 and go to MAX_CAMERAS while checking for the device with that name.
If it fails on the first attempt of /dev/video0, then check if /dev/video is valid.
Returns the global numCameras with the correct value (we hope) */
static void icvInitCapture_V4L() {
int deviceHandle;
int CameraNumber;
char deviceName[MAX_DEVICE_DRIVER_NAME];
CameraNumber = 0;
while(CameraNumber < MAX_CAMERAS) {
/* Print the CameraNumber at the end of the string with a width of one character */
sprintf(deviceName, "/dev/video%1d", CameraNumber);
/* Test using an open to see if this new device name really does exists. */
deviceHandle = open(deviceName, O_RDONLY);
if (deviceHandle != -1) {
/* This device does indeed exist - add it to the total so far */
// add indexList
indexList|=(1 << CameraNumber);
numCameras++;
}
if (deviceHandle != -1)
close(deviceHandle);
/* Set up to test the next /dev/video source in line */
CameraNumber++;
} /* End while */
}; /* End icvInitCapture_V4L */
static bool try_palette_v4l2(CvCaptureCAM_V4L* capture) static bool try_palette_v4l2(CvCaptureCAM_V4L* capture)
{ {
capture->form = v4l2_format(); capture->form = v4l2_format();
...@@ -690,7 +655,7 @@ static int _capture_V4L2 (CvCaptureCAM_V4L *capture) ...@@ -690,7 +655,7 @@ static int _capture_V4L2 (CvCaptureCAM_V4L *capture)
unsigned int buffer_number = capture->bufferSize; unsigned int buffer_number = capture->bufferSize;
try_again: try_again:
capture->req.count = buffer_number; capture->req.count = buffer_number;
capture->req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; capture->req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
...@@ -726,7 +691,7 @@ static int _capture_V4L2 (CvCaptureCAM_V4L *capture) ...@@ -726,7 +691,7 @@ static int _capture_V4L2 (CvCaptureCAM_V4L *capture)
} }
} }
for (n_buffers = 0; n_buffers < capture->req.count; ++n_buffers) for (unsigned int n_buffers = 0; n_buffers < capture->req.count; ++n_buffers)
{ {
v4l2_buffer buf = v4l2_buffer(); v4l2_buffer buf = v4l2_buffer();
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
...@@ -785,39 +750,48 @@ static bool v4l2_reset( CvCaptureCAM_V4L* capture) { ...@@ -785,39 +750,48 @@ static bool v4l2_reset( CvCaptureCAM_V4L* capture) {
bool CvCaptureCAM_V4L::open(int _index) bool CvCaptureCAM_V4L::open(int _index)
{ {
int autoindex = 0; cv::String name;
char _deviceName[MAX_DEVICE_DRIVER_NAME];
if (!numCameras)
icvInitCapture_V4L(); /* Haven't called icvInitCapture yet - do it now! */
if (!numCameras)
return false; /* Are there any /dev/video input sources? */
//search index in indexList
if ( (_index>-1) && ! ((1 << _index) & indexList) )
{
fprintf( stderr, "VIDEOIO ERROR: V4L: index %d is not correct!\n",_index);
return false; /* Did someone ask for not correct video source number? */
}
/* Select camera, or rather, V4L video source */ /* Select camera, or rather, V4L video source */
if (_index<0) { // Asking for the first device available if (_index < 0) // Asking for the first device available
for (; autoindex<MAX_CAMERAS;autoindex++) {
if (indexList & (1<<autoindex)) for (int autoindex = 0; autoindex < MAX_CAMERAS; ++autoindex)
{
name = cv::format("/dev/video%d", autoindex);
/* Test using an open to see if this new device name really does exists. */
int h = ::open(name.c_str(), O_RDONLY);
if (h != -1)
{
::close(h);
_index = autoindex;
break; break;
if (autoindex==MAX_CAMERAS) }
}
if (_index < 0)
{
fprintf(stderr, "VIDEOIO ERROR: V4L: can't find camera device\n");
name.clear();
return false; return false;
_index=autoindex; }
autoindex++;// i can recall icvOpenCAM_V4l with index=-1 for next camera }
else
{
name = cv::format("/dev/video%d", _index);
} }
/* Print the CameraNumber at the end of the string with a width of one character */ /* Print the CameraNumber at the end of the string with a width of one character */
sprintf(_deviceName, "/dev/video%1d", _index); bool res = open(name.c_str());
return open(_deviceName); if (!res)
{
fprintf(stderr, "VIDEOIO ERROR: V4L: can't open camera by index %d\n", _index);
}
return res;
} }
bool CvCaptureCAM_V4L::open(const char* _deviceName) bool CvCaptureCAM_V4L::open(const char* _deviceName)
{ {
#ifndef NDEBUG
fprintf(stderr, "(DEBUG) V4L: opening %s\n", _deviceName);
#endif
FirstCapture = 1; FirstCapture = 1;
width = DEFAULT_V4L_WIDTH; width = DEFAULT_V4L_WIDTH;
height = DEFAULT_V4L_HEIGHT; height = DEFAULT_V4L_HEIGHT;
...@@ -1014,13 +988,13 @@ move_411_block(int yTL, int yTR, int yBL, int yBR, int u, int v, ...@@ -1014,13 +988,13 @@ move_411_block(int yTL, int yTR, int yBL, int yBR, int u, int v,
int r, g, b; int r, g, b;
g = guScale * u + gvScale * v; g = guScale * u + gvScale * v;
// if (force_rgb) { // if (force_rgb) {
// r = buScale * u; // r = buScale * u;
// b = rvScale * v; // b = rvScale * v;
// } else { // } else {
r = rvScale * v; r = rvScale * v;
b = buScale * u; b = buScale * u;
// } // }
yTL *= yScale; yTR *= yScale; yTL *= yScale; yTR *= yScale;
yBL *= yScale; yBR *= yScale; yBL *= yScale; yBR *= yScale;
...@@ -1325,7 +1299,7 @@ static int init_done = 0; ...@@ -1325,7 +1299,7 @@ static int init_done = 0;
Each entry at index x in the table represents the codeword Each entry at index x in the table represents the codeword
present at the MSB of byte x. present at the MSB of byte x.
*/ */
static void sonix_decompress_init(void) static void sonix_decompress_init(void)
{ {
int i; int i;
...@@ -1403,7 +1377,7 @@ static void sonix_decompress_init(void) ...@@ -1403,7 +1377,7 @@ static void sonix_decompress_init(void)
Returns 0 if the operation was successful. Returns 0 if the operation was successful.
Returns <0 if operation failed. Returns <0 if operation failed.
*/ */
static int sonix_decompress(int width, int height, unsigned char *inp, unsigned char *outp) static int sonix_decompress(int width, int height, unsigned char *inp, unsigned char *outp)
{ {
int row, col; int row, col;
...@@ -1859,13 +1833,13 @@ static void icvCloseCAM_V4L( CvCaptureCAM_V4L* capture ){ ...@@ -1859,13 +1833,13 @@ static void icvCloseCAM_V4L( CvCaptureCAM_V4L* capture ){
perror ("Unable to stop the stream"); perror ("Unable to stop the stream");
} }
for (unsigned int n_buffers_ = 0; n_buffers_ < MAX_V4L_BUFFERS; ++n_buffers_) for (unsigned int n_buffers = 0; n_buffers < MAX_V4L_BUFFERS; ++n_buffers)
{ {
if (capture->buffers[n_buffers_].start) { if (capture->buffers[n_buffers].start) {
if (-1 == munmap (capture->buffers[n_buffers_].start, capture->buffers[n_buffers_].length)) { if (-1 == munmap (capture->buffers[n_buffers].start, capture->buffers[n_buffers].length)) {
perror ("munmap"); perror ("munmap");
} else { } else {
capture->buffers[n_buffers_].start = 0; capture->buffers[n_buffers].start = 0;
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment