Пример #1
0
int vid_start(struct context *cnt)
{
    struct config *conf = &cnt->conf;
    int fd_bktr = -1;

    if (conf->netcam_url) {
        fd_bktr = netcam_start(cnt);
        if (fd_bktr < 0) {
            netcam_cleanup(cnt->netcam, 1);
            cnt->netcam = NULL;
        }
    }    
#ifdef WITHOUT_V4L
    else 
        motion_log(LOG_ERR, 0, "%s: You must setup netcam_url", __FUNCTION__);    
#else
    else {
Пример #2
0
/**
 * vid_start
 *
 */
int vid_start(struct context *cnt)
{
    struct config *conf = &cnt->conf;
    int fd_bktr = -1;

    if (conf->netcam_url) {
        fd_bktr = netcam_start(cnt);
        if (fd_bktr < 0) {
            netcam_cleanup(cnt->netcam, 1);
            cnt->netcam = NULL;
        }
    }
#ifdef WITHOUT_V4L
    else
        MOTION_LOG(CRT, TYPE_VIDEO, NO_ERRNO, "%s: You must setup netcam_url");
#else
    else {
Пример #3
0
/**
 * vid_close
 *
 * vid_close is called from motion.c when a Motion thread is stopped or restarted
 */
void vid_close(struct context *cnt)   
{
#ifndef WITHOUT_V4L
    struct video_dev *dev = viddevs;
    struct video_dev *prev = NULL;
#endif

    /* Cleanup the netcam part */
    if (cnt->netcam) {
        netcam_cleanup(cnt->netcam, 0);
        cnt->netcam = NULL;
        return;
    } 

#ifndef WITHOUT_V4L

    /* Cleanup the v4l part */
    pthread_mutex_lock(&vid_mutex);
    while (dev) {
        if (dev->fd_bktr == cnt->video_dev)
            break;
            prev = dev;
            dev = dev->next;
        }
        pthread_mutex_unlock(&vid_mutex);
 
        /* Set it as closed in thread context */
        cnt->video_dev = -1;
 
        if (dev == NULL) {
            motion_log(LOG_ERR, 0, "%s: Unable to find video device", __FUNCTION__);   
            return;
        }

        if (--dev->usage_count == 0) {
            motion_log(LOG_INFO, 0, "%s: Closing video device %s", 
                       __FUNCTION__, dev->video_device);

            if (dev->fd_tuner > 0)
                close(dev->fd_tuner);
    
            if (dev->fd_bktr > 0) { 
                if (dev->capture_method == METEOR_CAP_CONTINOUS) {
                    dev->fd_tuner = METEOR_CAP_STOP_CONT;
                    ioctl(dev->fd_bktr, METEORCAPTUR, &dev->fd_tuner);
                }
                close(dev->fd_bktr);
                dev->fd_tuner = -1;
            }


            munmap(viddevs->v4l_buffers[0], viddevs->v4l_bufsize);
            viddevs->v4l_buffers[0] = MAP_FAILED;

            dev->fd_bktr = -1;
            pthread_mutex_lock(&vid_mutex);
            
            /* Remove from list */
            if (prev == NULL)
                viddevs = dev->next;
            else
                prev->next = dev->next;
             
            pthread_mutex_unlock(&vid_mutex);

            pthread_mutexattr_destroy(&dev->attr);
            pthread_mutex_destroy(&dev->mutex);
            free(dev);
        } else {
            motion_log(LOG_INFO, 0, "%s: Still %d users of video device %s, so we don't close it now", 
                       __FUNCTION__, dev->usage_count, dev->video_device);
            /* There is still at least one thread using this device
             * If we own it, release it
             */
            if (dev->owner == cnt->threadnr) {
                dev->frames = 0;
                dev->owner = -1;
                pthread_mutex_unlock(&dev->mutex);
            }
        }
#endif /* WITHOUT_V4L */
}