Hi,

Could you unload the driver (rmmod), quit the application and try again (i.e insmod the driver again and execute LiveCam)? I'm aware of this issue in the driver, and I got the same behavior with my previous test application, v4l2dumper.c .

BR,
Ilyes Gouta.

Torsten Spindler wrote:
When I open LiveCam and select Capture, the application hangs. The
bottom status line read 'BisonCam @ 0 FPS'.

Bye,
Torsten


On Sun, 2007-02-12 at 15:13 +0100, Ilyes Gouta wrote:
Hi Fellow,

I updated the m5602-ov9560-2 and livecam branches yesterday and I was wondering if you guys could give it a shot just to see if you can get something (using livecam, bayer stream only) from your sensors.

Just to recall it a bit, you can check out your livecam from the following URL:

https://livecam.svn.sourceforge.net/svnroot/livecam/trunk

LiveCam has the ability to alter the pitch of the pictures on the fly. The option is available through Debug | Adjust Pitch, from the application's menu.

Waiting for your reports.

BR,
Ilyes Gouta.

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
M560x-driver-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/m560x-driver-devel


/***************************************************************************
 *   Copyright (C) 2006 by Ilyes Gouta                                     *
 *   [EMAIL PROTECTED]                                                 *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <time.h>

#include <sys/time.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/mman.h>

#undef __STRICT_ANSI__
#include <linux/types.h>
#include <linux/videodev2.h>

#include <pthread.h>

#define CAPTURE_BUFFERS 32

static int fd;
static volatile int bCapture;
static pthread_t hThread;

static struct v4l2_buffer *pBuffers;
static struct v4l2_format fmt;
static unsigned char **pRawData;

static char* pFNPrefix;

void* WorkerThread(void* pData)
{
    struct v4l2_buffer buffer;
    struct timespec req, rem;
    char filename[256];
    int count = 0;
    FILE *hFile;

    while (bCapture)
    {
        buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        if (ioctl(fd, VIDIOC_DQBUF, &buffer) >= 0)
        {
            sprintf(filename, "%s%d.raw", pFNPrefix, count);
            printf("dumping frame %d (buffer index: %d) in %s\n", count, 
buffer.index, filename);
        
            hFile = fopen(filename, "wb");
            fwrite(pRawData[buffer.index], 1, fmt.fmt.pix.sizeimage, hFile);
            fclose(hFile);
        
            count++;
            if (!bCapture) break;
        
            buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
            ioctl(fd, VIDIOC_QBUF, &buffer);
        } else {
            printf("VIDIOC_DQBUF failed.\n");
        }

        /* wait for 30 ms */
        req.tv_sec = 0;
        req.tv_nsec = 33000000;
        nanosleep(&req, &rem);
    }

    return NULL;
}

void initialize()
{
    fd = -1;
    pBuffers = (struct v4l2_buffer*)malloc(CAPTURE_BUFFERS * sizeof(struct 
v4l2_buffer));
    pRawData = (unsigned char**)malloc(CAPTURE_BUFFERS * sizeof(unsigned 
char*));
}

void finalize()
{
    if (pBuffers) free(pBuffers);
    if (pRawData) free(pRawData);
    
    pBuffers = NULL;
    pRawData = NULL;
}

int start(char* devname)
{
    struct v4l2_capability caps;
    struct v4l2_requestbuffers request;
    int i, type, result;

    fd = open(devname, O_RDWR);
    if (fd == -1) return 0;

    if (ioctl(fd, VIDIOC_QUERYCAP, &caps) == -1) {
        close(fd); fd = -1;
        return 0;
    }

    printf("device name: %s\n", (char*)caps.card);

    if (!(caps.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
        close(fd); fd = -1;
        printf("device doesn't support V4L2.\n");
        return 0;
    }

    fcntl(fd, F_SETFD, FD_CLOEXEC);
    
    fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    fmt.fmt.pix.width = 640;
    fmt.fmt.pix.height = 480;
    fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_SBGGR8;
        
    result = ioctl(fd, VIDIOC_TRY_FMT, &fmt);
    if (result < 0) {
        printf("VIDIOC_TRY_FMT failed.\n");
    }
    
    printf("picture size: %d\n", fmt.fmt.pix.sizeimage);

    /* set the capture format */
    if (ioctl(fd, VIDIOC_S_FMT, &fmt) == -1) {
        close(fd); fd = -1;
        printf("device doesn't support this capture format.\n");
        return 0;
    }

    memset(&request, 0, sizeof(struct v4l2_requestbuffers));

    request.count = CAPTURE_BUFFERS;
    request.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    request.memory = V4L2_MEMORY_MMAP;

    /* set the type of the capture */
    if (ioctl(fd, VIDIOC_REQBUFS, &request) == -1) {
        close(fd); fd = -1;
        printf("VIDIOC_REQBUFS failed.\n");
        return 0;
    }

    for (i = 0; i < CAPTURE_BUFFERS; i++)
    {
        memset(&pBuffers[i], 0, sizeof(struct v4l2_buffer));

        pBuffers[i].index  = i;
        pBuffers[i].type   = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        pBuffers[i].memory = V4L2_MEMORY_MMAP;

        if (ioctl(fd, VIDIOC_QUERYBUF, &pBuffers[i], 0)) {
            close(fd); fd = -1;
            printf("VIDIOC_QUERYBUF failed.\n");
            return 0;
        }

        /* obtain a userspace pointer on the capture buffer */
        void *pData = mmap(NULL, pBuffers[i].length, PROT_READ | PROT_WRITE, 
MAP_SHARED, fd, pBuffers[i].m.offset);
        if (pData == (void*)-1) {
            close(fd); fd = -1;
            printf("mmap failed. buffer length: %d, offset:0x%x\n", 
pBuffers[i].length, pBuffers[i].m.offset);
            return 0;
        }

        pRawData[i] = (unsigned char*)pData;
    }

    /* queue the buffers for capture*/
    for (i = 0; i < CAPTURE_BUFFERS; i++) {
        ioctl(fd, VIDIOC_QBUF, &pBuffers[i]);
    }
    
    /* start the capture */
    type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    if (ioctl(fd, VIDIOC_STREAMON, &type) == -1) {
        close(fd); fd = -1;
        printf("failed starting capture.\n");
        return 0;
    }

    bCapture = 1;
    if (pthread_create(&hThread, NULL, WorkerThread, NULL)) {
        close(fd); fd = -1;
        return 0;
    }

    return 1;
}

void stop()
{
    if (fd == -1) return;

    bCapture = 0;

    /* stop the capture */
    int type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    ioctl(fd, VIDIOC_STREAMOFF, &type);

    pthread_join(hThread, NULL);
    close(fd); fd = -1;
}

int main(int argc, char** argv)
{
   if (argc != 2) {
      printf("usage:\n\t$ v4l2dumper <filename prefix>\n");
      return 0;
   }
   
   pFNPrefix = argv[1];
   
   initialize();
   
   if (start("/dev/video0")) {
        sleep(3);
        stop();
   }
   
   finalize();
   return 0;
}
-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
M560x-driver-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/m560x-driver-devel

Reply via email to