Cam2x


flammablepiss said:
Could you do it for the ps2 I TOY ?
As it would be camera that many people will have ?
It should be supported using the OV51x driver.
 
Last edited by a moderator:
When I try to use cam2xlib, I am missing "linux/types.h" and "linux/videodev.h" when compiling. Can you tell me where to get them?
 
JanGunheD said:
When I try to use cam2xlib, I am missing "linux/types.h" and "linux/videodev.h" when compiling. Can you tell me where to get them?
They are available in the kernel sources: types.h videodev.h
 
Last edited by a moderator:
Thanks,

now there is "just" a linker problem left, it seems to be unable to find the functions in libcam2x.a (see errors below). The lib itself "libcam2x.a" is found (there is a file not found error when renaming the -lcam2x parameter below deliberately to something wrong), just the functions inside seem to be not found. It looks inside "GP2X_Dev\Tools\arm-gp2x-linux\lib", where most of the libs also have counterparts ending with .so and .la etc., maybe that is also needed for libcam2x.a? Besides, I am using the Dev-C++ Tool that comes with the GP2X.

These are the error-messages:

Compiler: gp2x
Building Makefile: "C:\...\Test_2_V6\Makefile.gp2x"
Führt make... aus
make.exe -f "C:\...\Test_2_V6\Makefile.gp2x" all
cygwin-mkdir -p "gp2x"

gcc.exe -c main.c -o gp2x/main.o -I"C:/Programme/GP2X_Dev/Tools/arm-gp2x-linux/include" -I"C:/Programme/GP2X_Dev/Tools/include" -I"C:/Programme/GP2X_Dev/Tools/include/SDL" -D_REENTRANT -DGP2X -DPLATFORM_GP2X

gcc.exe gp2x/main.o -o Test_2_V1.gpe -L"C:/Programme/GP2X_Dev/Tools/arm-gp2x-linux/lib" -lcam2x -lSDL_image -lSDL_mixer -lSDL_ttf -lSDL_inifile -lSDL -lpng -ljpeg -lvorbisidec -lmad -lfreetype -lz -lunicodefont

gp2x/main.o: In function `Terminate':
main.c:(.text+0x18): undefined reference to `Cam2X_CloseCamera'
gp2x/main.o: In function `main':
main.c:(.text+0x614): undefined reference to `Cam2X_OpenCamera'
main.c:(.text+0xe6c): undefined reference to `Cam2X_GetNewFrame'
main.c:(.text+0xe78): undefined reference to `Cam2X_AdjustBrightness'
collect2: ld returned 1 exit status
make.exe: *** [Test_2_V1.gpe] Error 1

Ausführung beendet
 
my logitech quickcam messenger #2 seems to not work

I use the last version of cam2x
I load the driver (z_load_all.gpe)
it goes back to menu
the test does nothing
if I run photocam2x I have this message : "No video device found"

do we need to install a lib (ryleh or else) on the GP2X ?

Someone has the same cam and Succeed to run it ?


ps : sorry for my english <french inside>
 
mikapoil said:
my logitech quickcam messenger #2 seems to not work

I use the last version of cam2x
I load the driver (z_load_all.gpe)
it goes back to menu
the test does nothing
if I run photocam2x I have this message : "No video device found"

do we need to install a lib (ryleh or else) on the GP2X ?

Someone has the same cam and Succeed to run it ?
ps : sorry for my english <french inside>


Hi,

I crosscompiled a few drivers that should support a lot of webcams, all 2.4 kernel drivers. I remember having problems finding drivers for logitech quickcams. If you get the message "No video device found" it means that the driver did not register your webcam. You could post some output of the dmesg command. If you don't have telnet, launch this script from the menu:
CODE
#!/bin/sh
dmesg > dmesg_output.txt
/usr/gp2x/gp2xmenu &


You should post the contents of the file (first run load_all.gpe then connect your webcam then run that script).

Probably there will be an error message saying that no driver was found that registered the webcam. The easiest way to find a driver for the webcam is connecting it to a linux pc and see what driver it uses for it and then try to crosscompile that driver for the gp2x. If that doesn't work then it is possible that no 2.4 driver exists and you are not able to use it on the gp2x unless you write the driver yourself.
 
Last edited by a moderator:
i am trying :

so i run load_all.gpe then connect your webcam then run that script...
and there ...nothing : black screen
i wait few minutes but nothing new
so i turn off my GP2X

I have a .txt

CODE
**>>ecc error unfixed on chunk 1563:0
**>>ecc error unfixed on chunk 1563:1
**>>Block 48 marked for retirement
**>>ecc error unfixed on chunk 1564:0
**>>ecc error unfixed on chunk 1564:1
**>>Block 48 marked for retirement
**>>ecc error unfixed on chunk 1565:0
**>>ecc error unfixed on chunk 1565:1
**>>Block 48 marked for retirement
**>>ecc error unfixed on chunk 1566:0
**>>ecc error unfixed on chunk 1566:1
**>>Block 48 marked for retirement
**>>ecc error unfixed on chunk 1567:0
**>>ecc error unfixed on chunk 1567:1
**>>Block 48 marked for retirement
**>>ecc error unfixed on chunk 1568:0
**>>ecc error unfixed on chunk 1568:1
**>>Block 49 marked for retirement
**>>ecc error unfixed on chunk 1569:1
**>>Block 49 marked for retirement
**>>ecc error unfixed on chunk 1570:0
**>>ecc error unfixed on chunk 1570:1
**>>Block 49 marked for retirement
**>>ecc error unfixed on chunk 1571:0
**>>ecc error unfixed on chunk 1571:1
**>>Block 49 marked for retirement
**>>ecc error unfixed on chunk 1572:1
**>>Block 49 marked for retirement
**>>ecc error unfixed on chunk 1573:0
**>>ecc error unfixed on chunk 1573:1
**>>Block 49 marked for retirement
**>>ecc error unfixed on chunk 1574:0
**>>ecc error unfixed on chunk 1574:1
**>>Block 49 marked for retirement
usb.c: registered new driver ov51x
ov51x.c: v1.65-1.11-mark : ov51x USB Camera Driver
ov519_decomp.c: v1.4 : OV519 JPEG Decompression Module
ov518_decomp.c: v1.3 : OV518 Decompression Module
ov511_decomp.c: v1.6 : OV511 Decompression Module
usb.c: registered new driver stv680
stv680.c: [usb_stv680_init:1711] STV(i): usb camera driver version v0.25.GP2X registering
stv680.c: STV0680 USB Camera Driver v0.25.GP2X
usb.c: registered new driver spca5xx
spca5xx_.c: spca5xx driver 00.60.00.GP2X registered
V4L-Driver for Vision CPiA based cameras v0.8.5
USB driver for Vision CPiA based cameras v0.8.5
usb.c: registered new driver cpia
pwc Philips webcam module version 9.0.2.GP2X loaded.
pwc Supports Philips PCA645/646, PCVC675/680/690, PCVC720[40]/730/740/750 & PCVC830/840.
pwc Also supports the Askey VC010, various Logitech Quickcams, Samsung MPC-C10 and MPC-C30,
pwc the Creative WebCam 5 & Pro Ex, SOTEC Afina Eye and Visionite VCS-UC300 and VCS-UM100.
usb.c: registered new driver Philips webcam
pwc Philips webcam decompressor routines version 9.0-BETA-2
pwc Supports all cameras supported by the main module (pwc).
pwc Adding decompressor for model 645.
pwc Adding decompressor for model 646.
pwc Adding decompressor for model 675.
pwc Adding decompressor for model 680.
pwc Adding decompressor for model 690.
pwc Adding decompressor for model 720.
pwc Adding decompressor for model 730.
pwc Adding decompressor for model 740.
pwc Adding decompressor for model 750.
usb.c: registered new driver quickcam
hub.c: port 1, portstatus 100, change 0, 12 Mb/s
hub.c: port 2, portstatus 100, change 0, 12 Mb/s
hub.c: port 3, portstatus 100, change 0, 12 Mb/s
hub.c: port 4, portstatus 101, change 1, 12 Mb/s
hub.c: port 4 connection change
hub.c: port 4, portstatus 101, change 1, 12 Mb/s
hub.c: port 4, portstatus 101, change 0, 12 Mb/s
hub.c: port 4, portstatus 101, change 0, 12 Mb/s
hub.c: port 4, portstatus 101, change 0, 12 Mb/s
hub.c: port 4, portstatus 101, change 0, 12 Mb/s
hub.c: port 4, portstatus 103, change 10, 12 Mb/s
hub.c: new USB device <NULL>-1.4, assigned address 5
usb.c: kmalloc IF c18d2f40, numif 3
usb.c: skipped 4 class/vendor specific interface descriptors
usb.c: skipped 2 class/vendor specific interface descriptors
usb.c: skipping descriptor 0x25
usb.c: skipped 1 class/vendor specific endpoint descriptors
usb.c: new device strings: Mfr=0, Product=1, SerialNumber=0
usb.c: USB device number 5 default language ID 0x409
Product: Camera
usb.c: unhandled interfaces on device
usb.c: USB device 5 (vend/prod 0x46d/0x8f0) is not claimed by any active driver.
Length = 18
DescriptorType = 01
USB version = 2.00
Vendor:product = 046d:08f0
MaxPacketSize0 = 8
NumConfigurations = 1
Device version = 1.00
Device Class:SubClass:protocol = ff:ff:ff
Vendor class
Configuration:
bLength = 9
bDescriptorType = 02
wTotalLength = 00ad
bNumInterfaces = 03
bConfigurationValue = 01
iConfiguration = 00
bmAttributes = a0
MaxPower = 100mA

Interface: 0
Alternate Setting: 0
bLength = 9
bDescriptorType = 04
bInterfaceNumber = 00
bAlternateSetting = 00
bNumEndpoints = 02
bInterface Class:SubClass:protocol = ff:ff:ff
iInterface = 00
Endpoint:
bLength = 7
bDescriptorType = 05
bEndpointAddress = 81 (in)
bmAttributes = 01 (Isochronous)
wMaxPacketSize = 0000
bInterval = 01
Endpoint:
bLength = 7
bDescriptorType = 05
bEndpointAddress = 82 (in)
bmAttributes = 03 (Interrupt)
wMaxPacketSize = 0001
bInterval = 10
Alternate Setting: 1
bLength = 9
bDescriptorType = 04
bInterfaceNumber = 00
bAlternateSetting = 01
bNumEndpoints = 02
bInterface Class:SubClass:protocol = ff:ff:ff
iInterface = 00
Endpoint:
bLength = 7
bDescriptorType = 05
bEndpointAddress = 81 (in)
bmAttributes = 01 (Isochronous)
wMaxPacketSize = 03ff
bInterval = 01
Endpoint:
bLength = 7
bDescriptorType = 05
bEndpointAddress = 82 (in)
bmAttributes = 03 (Interrupt)
wMaxPacketSize = 0001
bInterval = 10

Interface: 1
Alternate Setting: 0
bLength = 9
bDescriptorType = 04
bInterfaceNumber = 01
bAlternateSetting = 00
bNumEndpoints = 00
bInterface Class:SubClass:protocol = 01:01:00
iInterface = 00

Interface: 2
Alternate Setting: 0
bLength = 9
bDescriptorType = 04
bInterfaceNumber = 02
bAlternateSetting = 00
bNumEndpoints = 01
bInterface Class:SubClass:protocol = 01:02:00
iInterface = 00
Endpoint:
bLength = 9 (Audio)
bDescriptorType = 05
bEndpointAddress = 83 (in)
bmAttributes = 01 (Isochronous)
wMaxPacketSize = 0000
bInterval = 01
bRefresh = 00
bSynchAddress = 00
Alternate Setting: 1
bLength = 9
bDescriptorType = 04
bInterfaceNumber = 02
bAlternateSetting = 01
bNumEndpoints = 01
bInterface Class:SubClass:protocol = 01:02:00
iInterface = 00
Endpoint:
bLength = 9 (Audio)
bDescriptorType = 05
bEndpointAddress = 83 (in)
bmAttributes = 01 (Isochronous)
wMaxPacketSize = 0034
bInterval = 01
bRefresh = 00
bSynchAddress = 00
usb.c: kusbd: /sbin/hotplug add 5
kusbd_policy: /sbin/hotplug add 5, ret=0x0
usb.c: kusbd: /sbin/hotplug add 5
kusbd_policy: /sbin/hotplug add 5, ret=0x0
usb.c: kusbd: /sbin/hotplug add 5
kusbd_policy: /sbin/hotplug add 5, ret=0x0
**>>ecc error unfixed on chunk 1772:0
**>>ecc error unfixed on chunk 1772:1
**>>Block 55 marked for retirement



if you can tell me more about that ...

because I don't know enough about linux to do anything...
i just can search on net to show you :
linux driver for quickcam messenger
and
improved linux driver for quickcam messenger
 
finally I buy a eye toy camera (sleh-00031)...
but it's not the end of my problem

i will not explain just see the photo
you will understand



how correct this problem ?
 
mikapoil said:
finally I buy a eye toy camera (sleh-00031)...
but it's not the end of my problem

i will not explain just see the photo
you will understand

[ img ]http://pix.nofrag.com/0/e/1/4a46efbbd14c73f2735ab63e79d8f.jpg[ /img ]

how correct this problem ?


Strange, does the photo seems to "move up" or it is just the bottom part that has to be put on top? You could "fix" this by first copying the bottom part and then put the top part after it, that way you should have a valid picture.

I don't know why this happens, I just recompiled a lot of drivers, only with one driver I made some changes. So that problem has to exist in the drivers itself for linux (in an old version) or is caused by a faulty webcam.
 
Last edited by a moderator:
I had the same problem with my Eye Toy, disabeling the code that automatically adapts the picture-brightness directly in cam2x (for which you kindly gave me the source) solved the problem, and the eye toy seems to adjust the brighness automatically to some extent anyway.

Lithosphere said:
mikapoil said:
finally I buy a eye toy camera (sleh-00031)...
but it's not the end of my problem

i will not explain just see the photo
you will understand

[ img ]http://pix.nofrag.com/0/e/1/4a46efbbd14c73f2735ab63e79d8f.jpg[ /img ]

how correct this problem ?


Strange, does the photo seems to "move up" or it is just the bottom part that has to be put on top? You could "fix" this by first copying the bottom part and then put the top part after it, that way you should have a valid picture.

I don't know why this happens, I just recompiled a lot of drivers, only with one driver I made some changes. So that problem has to exist in the drivers itself for linux (in an old version) or is caused by a faulty webcam.
 
Last edited by a moderator:
Lithosphere said:
mikapoil said:
finally I buy a eye toy camera (sleh-00031)...
but it's not the end of my problem

i will not explain just see the photo
you will understand

[ img ]http://pix.nofrag.com/0/e/1/4a46efbbd14c73f2735ab63e79d8f.jpg[ /img ]

how correct this problem ?


Strange, does the photo seems to "move up" or it is just the bottom part that has to be put on top? You could "fix" this by first copying the bottom part and then put the top part after it, that way you should have a valid picture.

I don't know why this happens, I just recompiled a lot of drivers, only with one driver I made some changes. So that problem has to exist in the drivers itself for linux (in an old version) or is caused by a faulty webcam.

I test this cam under windows it work fine
(i use this driver http://eocp.sourceforge.net/inframe.php?lo...p;name=Download)
but on my GP2X the video move up (or down sometimes)
but not all the time
i think jangunhed explain why...


JanGunheD said:
I had the same problem with my Eye Toy, disabeling the code that automatically adapts the picture-brightness directly in cam2x (for which you kindly gave me the source) solved the problem, and the eye toy seems to adjust the brighness automatically to some extent anyway.

Lithosphere said:
mikapoil said:
finally I buy a eye toy camera (sleh-00031)...
but it's not the end of my problem

i will not explain just see the photo
you will understand

[ img ]http://pix.nofrag.com/0/e/1/4a46efbbd14c73f2735ab63e79d8f.jpg[ /img ]

how correct this problem ?


Strange, does the photo seems to "move up" or it is just the bottom part that has to be put on top? You could "fix" this by first copying the bottom part and then put the top part after it, that way you should have a valid picture.

I don't know why this happens, I just recompiled a lot of drivers, only with one driver I made some changes. So that problem has to exist in the drivers itself for linux (in an old version) or is caused by a faulty webcam.



can you send me (or put a link to download) your version please ?
because i'am a noob !
 
Last edited by a moderator:
@Lithosphere :
Could you do a fixed version for eyetoy with the improvement mentionned by JanGunheD ?
....a little update

or permit to JanGunheD to distribuate "his" version...
 
mikapoil said:
@Lithosphere :
Could you do a fixed version for eyetoy with the improvement mentionned by JanGunheD ?
....a little update

or permit to JanGunheD to distribuate "his" version...


He can distribute his version. After all he should be able to test it with a camera and already have a working version. If he doesn't give it, I will try to take a look at it.
 
Last edited by a moderator:
we talk about with JanGunheD but he has crashed his HDD
he gave me the 2 files modified
but there is 2 problems
i don't have the sourcecode of your application
and ...i'm not able to recompile

So i ask your help
thanks if you can

i put the 2 files he has changed there
(thinking it's not a problem for JanGunheD)

cam2x.h

------------

/*
* libCam2X - Webcam Library for GP2X
*
* by Lithosphere
*/

/* threaded not finished yet */
#define CAM2X_NO_PTHREAD 1

#ifndef H_CAM2X
#define H_CAM2X

#include <linux/types.h>
#include <linux/videodev.h>

#ifndef CAM2X_NO_PTHREAD
#include <pthread.h>
#endif


typedef struct{
int fd; /* Video Device */
struct video_capability cap; /* Video Capability */
struct video_window win; /* Video Window */
struct video_picture vpic; /* Video Picture */

unsigned char *buffer;

#ifndef CAM2X_NO_PTHREAD
unsigned char* double_buff[2];
int current_frame;
int new_frame;
int active_grab;
pthread_t capture_thread;
pthread_mutex_t conditional_mutex;
pthread_mutex_t conditional_mutex_new_frame;
pthread_cond_t conditional_cond;
#endif

} Cam2X_Device;

Cam2X_Device* Cam2X_OpenCamera();
Cam2X_Device* Cam2X_OpenCameraDevice(char* videodevice, int width, int height, int depth, int palette);

int Cam2X_SetWidthHeightDepth(Cam2X_Device* cam2x, int width, int height, int depth, int palette);
void Cam2X_GetWidthHeightDepth(Cam2X_Device* cam2x);
int Cam2X_AdjustBrightness(Cam2X_Device* cam2x);

void Cam2X_GetNewFrame(Cam2X_Device* cam2x);

#ifndef CAM2X_NO_PTHREAD
void* Cam2X_Threaded(void* cam2x_arg);
int Cam2X_CheckNewFrame(Cam2X_Device* cam2x);
#endif

void Cam2X_CloseCamera(Cam2X_Device* cam2x);

#endif






cam2x.c

------------

/*
* libCam2X
*
*/
#include <stdio.h> /* printf */
#include <stdlib.h> /* malloc, free */
#include <fcntl.h> /* open */
#include <unistd.h> /* read, close */
#include <sys/ioctl.h> /* ioctl */

#include <linux/types.h>
#include <linux/videodev.h> /* structs for v4l */

#include <string.h> /* strerror */
#include <errno.h> /* strerror */

#include "cam2x.h"

#ifndef CAM2X_NO_PTHREAD
#include <sys/mman.h>
#include <pthread.h>
#endif

Cam2X_Device* Cam2X_OpenCamera(){
return Cam2X_OpenCameraDevice("/dev/video0", 320, 240, 24, VIDEO_PALETTE_RGB24);
}

Cam2X_Device* Cam2X_OpenCameraDevice(char* videodevice, int width, int height, int depth, int palette) {
Cam2X_Device* cam2x;
int ret;
#ifndef CAM2X_NO_PTHREAD
int i;
#endif

printf("CAM2X: Allocating size for Cam2X_Device\n");
cam2x = (Cam2X_Device*) malloc( sizeof(Cam2X_Device) );

/* Open video4linux device */
printf("CAM2X: Opening %s\n", videodevice);
cam2x->fd = open(videodevice, O_RDWR);
if (cam2x->fd < 0) {
// unable to open
printf("CAM2X: Unable to open %s: %s\n", videodevice, strerror(errno));
free(cam2x);
return NULL;
}

printf("CAM2X: Checking for valid v4l device and loading values for %s\n", videodevice);
if (ioctl(cam2x->fd, VIDIOCGCAP, &cam2x->cap) < 0 ||
ioctl(cam2x->fd, VIDIOCGWIN, &cam2x->win) < 0 ||
ioctl(cam2x->fd, VIDIOCGPICT, &cam2x->vpic) < 0) {
// device is not a v4l device
printf("CAM2X: %s not a v4l device: %s\n", videodevice, strerror(errno));
close(cam2x->fd);
free(cam2x);
return NULL;
}

/* Set resolution if needed */
if((width && height) || (depth || palette)){
printf("CAM2X: Setting resolution %s\n", videodevice);

ret=Cam2X_SetWidthHeightDepth(cam2x, width, height, depth, palette);
if ( ret == -2) {
printf("CAM2X: Invalid resolution!\n");
close(cam2x->fd);
free(cam2x);
return NULL;
}else if(ret==-1){
close(cam2x->fd);
free(cam2x);
return NULL;
}
}

/* allocate buffer */
printf("CAM2X: Going to allocate data...\n");
cam2x->buffer = (unsigned char*)malloc(cam2x->win.width * cam2x->win.height * cam2x->vpic.depth);
if (!cam2x->buffer) {
printf("CAM2X: Out of memory.\n");
close(cam2x->fd);
free(cam2x);
return NULL;
}

#ifndef CAM2X_NO_PTHREAD
/*
if (i=ioctl(cam2x->fd, VIDIOCGMBUF, &cam2x->mbuf) < 0) {
close(cam2x->fd);
free(cam2x);
return NULL;
}


printf("Mmapping framebuffers ofzo %d %s %d\n", i, videodevice, cam2x->mbuf.size);
//cam2x->mem_mmap = (unsigned char *)mmap(0, cam2x->mbuf.size, PROT_READ | PROT_WRITE, MAP_SHARED, cam2x->fd, 0);
printf("Done mmapping\n");


for (i=0;i<2;i++) {
cam2x->mmap.frame = i;
cam2x->mmap.width = cam2x->win.width;
cam2x->mmap.height = cam2x->win.height;
cam2x->mmap.format = cam2x->vpic.palette;

ioctl(cam2x->fd, VIDIOCSYNC, &cam2x->mmap);
if (ioctl(cam2x->fd, VIDIOCMCAPTURE, &cam2x->mmap) < 0) {
close(cam2x->fd);
free(cam2x);
return NULL;
}
}
*/
for (i=0;i<2;i++)
cam2x->double_buff = (unsigned char*)malloc(cam2x->win.width * cam2x->win.height * cam2x->vpic.depth / 8);

pthread_mutex_init(&cam2x->conditional_mutex, NULL);
pthread_mutex_init(&cam2x->conditional_mutex_new_frame, NULL);
pthread_cond_init(&cam2x->conditional_cond, NULL);
cam2x->new_frame = 0;
cam2x->current_frame = 0;
cam2x->active_grab = 1;

pthread_create( &cam2x->capture_thread, NULL, Cam2X_Threaded, (void *)cam2x);

#endif

/* Calculate brightness */
/*int max_check = 6; // limit brightness checks (eyetoy camera problem)
do {
Cam2X_GetNewFrame(cam2x);

printf("CAM2X: Recalculate brightness\n");
} while (Cam2X_AdjustBrightness(cam2x) > 6 && --max_check);*/

return cam2x;
}

#ifndef CAM2X_NO_PTHREAD
void* Cam2X_Threaded(void* cam2x_arg) {
Cam2X_Device* cam2x = (Cam2X_Device*) cam2x_arg;

printf("Capturing thread created\n");

do{
/*ioctl(cam2x->fd, VIDIOCSYNC, &cam2x->mmap[cam2x->current_frame]);
ioctl(cam2x->fd, VIDIOCMCAPTURE, &cam2x->mmap[cam2x->current_frame]);
*/
printf("CAM2X: # Reading frame to %d\n", cam2x->current_frame);
read(cam2x->fd, cam2x->double_buff[cam2x->current_frame], cam2x->win.width * cam2x->win.height * cam2x->vpic.depth);
printf("CAM2X: # Done reading\n");

printf("CAM2X: # Locking\n");
pthread_mutex_lock( &cam2x->conditional_mutex );
printf("CAM2X: # Done locking\n");

cam2x->current_frame = cam2x->current_frame ? 0 : 1;

printf("CAM2X: # Unlocking\n");
pthread_mutex_unlock( &cam2x->conditional_mutex );
printf("CAM2X: # Done unlocking\n");

printf("CAM2X: # Locking New Frame\n");
pthread_mutex_lock( &cam2x->conditional_mutex_new_frame);
cam2x->new_frame = 1;
printf("CAM2X: # Done locking New Frame\n");

printf("CAM2X: # Unlocking New Frame\n");
pthread_mutex_unlock( &cam2x->conditional_mutex_new_frame );
printf("CAM2X: # Done unlocking New Frame\n");

pthread_cond_signal( &cam2x->conditional_cond );

if(!cam2x->active_grab)
break;

printf("CAM2X: # Waiting for new_frame %d == 0\n", cam2x->new_frame);
while(cam2x->new_frame)
pthread_cond_wait(&cam2x->conditional_cond, &cam2x->conditional_mutex);

printf("CAM2X: # Done waiting for new_frame %d == 0\n", cam2x->new_frame);
}while(1);

return NULL;
}
#endif


int Cam2X_SetWidthHeightDepth(Cam2X_Device* cam2x, int width, int height, int depth, int palette){

/* Reset size if needed */
fprintf (stderr, "cam2x->cap.maxwidth=%d.\n", cam2x->cap.maxwidth);
fprintf (stderr, "cam2x->cap.minwidth=%d.\n", cam2x->cap.minwidth);
fprintf (stderr, "cam2x->cap.maxheight=%d.\n", cam2x->cap.maxheight);
fprintf (stderr, "cam2x->cap.minheight=%d.\n", cam2x->cap.minheight);
if(width && height){
if (cam2x->cap.maxwidth < width || width < cam2x->cap.minwidth ||
cam2x->cap.maxheight < height || height < cam2x->cap.minheight)
return -2;

cam2x->win.width = width;
cam2x->win.height = height;
cam2x->win.flags=0;

if (ioctl(cam2x->fd, VIDIOCSWIN, &cam2x->win) < 0) {
ioctl(cam2x->fd, VIDIOCGWIN, &cam2x->win);
return -1;
}
}

/* Adjust color depth / palette */
if (depth || palette) {
if (depth)
cam2x->vpic.depth = depth;
if (palette)
cam2x->vpic.palette = palette;

if (ioctl(cam2x->fd, VIDIOCSPICT, &cam2x->vpic) < 0) {
ioctl(cam2x->fd, VIDIOCGPICT, &cam2x->vpic);
return -1;
}
}

return 0;
}

//Added by Jan:
int Cam2X_SetXYWidthHeight(Cam2X_Device* cam2x, int x, int y, int width, int height){

/* Reset size if needed */
fprintf (stderr, "cam2x->cap.maxwidth=%d.\n", cam2x->cap.maxwidth);
fprintf (stderr, "cam2x->cap.minwidth=%d.\n", cam2x->cap.minwidth);
fprintf (stderr, "cam2x->cap.maxheight=%d.\n", cam2x->cap.maxheight);
fprintf (stderr, "cam2x->cap.minheight=%d.\n", cam2x->cap.minheight);
if(width && height){
if (cam2x->cap.maxwidth < width || width < cam2x->cap.minwidth ||
cam2x->cap.maxheight < height || height < cam2x->cap.minheight)
return -2;

if (x<0 || y<0)
return -2;

cam2x->win.x = x;
cam2x->win.y = y;
cam2x->win.width = width;
cam2x->win.height = height;
cam2x->win.flags=0;

if (ioctl(cam2x->fd, VIDIOCSWIN, &cam2x->win) < 0) {
ioctl(cam2x->fd, VIDIOCGWIN, &cam2x->win);
return -1;
}
}

return 0;
}

void Cam2X_GetWidthHeightDepth(Cam2X_Device* cam2x){
ioctl(cam2x->fd, VIDIOCGWIN, &cam2x->win);
ioctl(cam2x->fd, VIDIOCGPICT, &cam2x->vpic);

printf("\nCAM2X: ----------------------\n");
printf("CAM2X: Max width: %d\nCAM2X: Max height: %d\n", cam2x->cap.maxwidth, cam2x->cap.maxheight);
printf("CAM2X: Current width: %d\nCAM2X: Current height: %d\n", cam2x->win.width, cam2x->win.height);
printf("CAM2X: Current depth: %d\nCAM2X: Current palette: %d\n", cam2x->vpic.depth, cam2x->vpic.palette);
printf("CAM2X: ------------------------\n\n");
}

/* Calculate the brightness, average of all colors of all pixels has to be 128 - 24bit only */
int Cam2X_AdjustBrightness(Cam2X_Device* cam2x) {
long i, tot = 0, size = cam2x->win.width * cam2x->win.width;
int brightness_adjust = 255;

for (i=0;i<size*3;i++)
tot += cam2x->buffer;

brightness_adjust = (128 - tot/(size*3))/3;

if(brightness_adjust < 3){
cam2x->vpic.brightness += (brightness_adjust << 8); /* brightness: 0-65535*/

ioctl(cam2x->fd, VIDIOCSPICT, &cam2x->vpic);
}

return brightness_adjust;
}

#ifdef CAM2X_NO_PTHREAD
void Cam2X_GetNewFrame(Cam2X_Device* cam2x) {
read(cam2x->fd, cam2x->buffer, cam2x->win.width * cam2x->win.height * cam2x->vpic.depth);
}
#else
void Cam2X_GetNewFrame(Cam2X_Device* cam2x) {
int frame = cam2x->current_frame;
printf("CAM2X: Locking\n");
pthread_mutex_lock( &cam2x->conditional_mutex );
printf("CAM2X: Done Locking\n");

printf("CAM2X: New frame: %d\n",cam2x->new_frame);

while(!cam2x->new_frame)
pthread_cond_wait(&cam2x->conditional_cond, &cam2x->conditional_mutex);

printf("CAM2X: New frame: %d\n",cam2x->new_frame);

printf("CAM2X: Copy frame %d to main buffer\n", frame);
//memcpy((void*)cam2x->buffer, &cam2x->double_buff[frame], cam2x->win.width * cam2x->win.height * cam2x->vpic.depth / 8);
printf("CAM2X: Done copying frame %d to main buffer\n", frame);

printf("CAM2X: Unlocking\n");
pthread_mutex_unlock( &cam2x->conditional_mutex_new_frame );
printf("CAM2X: Done Unlocking\n");

printf("CAM2X: Locking New Frame\n");
pthread_mutex_lock( &cam2x->conditional_mutex_new_frame );
printf("CAM2X: Done Locking New Frame\n");

cam2x->new_frame = 0;
pthread_cond_signal( &cam2x->conditional_cond );

printf("CAM2X: Unlocking New Frame\n");
pthread_mutex_unlock( &cam2x->conditional_mutex_new_frame);
printf("CAM2X: Done Unlocking New Frame\n");


}
int Cam2X_CheckNewFrame(Cam2X_Device* cam2x) {
int ret;
pthread_mutex_lock( &cam2x->conditional_mutex );
ret = cam2x->new_frame;
pthread_mutex_unlock( &cam2x->conditional_mutex );
return ret;
}
#endif

void Cam2X_CloseCamera(Cam2X_Device* cam2x){
#ifndef CAM2X_NO_PTHREAD
pthread_mutex_lock( &cam2x->conditional_mutex );
cam2x->active_grab = 0;
pthread_mutex_unlock( &cam2x->conditional_mutex );
#endif

close(cam2x->fd);
free(cam2x->buffer);
free(cam2x);
}
 
mikapoil said:
we talk about with JanGunheD but he has crashed his HDD
he gave me the 2 files modified
but there is 2 problems
i don't have the sourcecode of your application
and ...i'm not able to recompile

So i ask your help
thanks if you can

i put the 2 files he has changed there
(thinking it's not a problem for JanGunheD)

Ok, I have a copy of that code. I recompiled photocam2x with the modified versions of cam2x.c|h. I didn't test it so I don't know if it will work: http://www.sendspace.com/file/ws3lqi .
 
Last edited by a moderator:
tested but not approuved...

the video move again (up or down)
and the video seems to be more ...red

but the problem is really a problem of brightness
because i can have a good video when i don't have much light

Do JanGunheD forget something ?
 
His modifications disabled the brightness correction. So I don't know what is causing this.
 
Back
Top