Exemple #1
0
int bktr_next(struct context *cnt, unsigned char *map)
{
#ifdef HAVE_BKTR

    struct config *conf = &cnt->conf;
    struct video_dev *dev;
    int width, height;
    int dev_bktr = cnt->video_dev;
    int ret = -1;

    /* NOTE: Since this is a capture, we need to use capture dimensions. */
    width = cnt->rotate_data.cap_width;
    height = cnt->rotate_data.cap_height;

    pthread_mutex_lock(&bktr_mutex);
    dev = viddevs;

    while (dev) {
        if (dev->fd_device == dev_bktr)
            break;
        dev = dev->next;
    }

    pthread_mutex_unlock(&bktr_mutex);

    if (dev == NULL)
        return V4L2_FATAL_ERROR;

    if (dev->owner != cnt->threadnr) {
        pthread_mutex_lock(&dev->mutex);
        dev->owner = cnt->threadnr;
        dev->frames = conf->roundrobin_frames;
    }

    bktr_set_input(cnt, dev, map, width, height, conf->input, conf->norm,
                  conf->roundrobin_skip, conf->frequency);

    ret = bktr_capture(dev, map, width, height);

    if (--dev->frames <= 0) {
        dev->owner = -1;
        dev->frames = 0;
        pthread_mutex_unlock(&dev->mutex);
    }

    /* Rotate the image as specified */
    if (cnt->rotate_data.degrees > 0 || cnt->rotate_data.axis != FLIP_TYPE_NONE)
        rotate_map(cnt, map);

    return ret;
#else
    if (!cnt || !map) MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, "%s: BKTR is not enabled.");
    return -1;
#endif

}
Exemple #2
0
/**
 * netcam_image_conv
 *
 * Parameters:
 *      netcam          pointer to netcam_context
 *      cinfo           pointer to JPEG decompression context
 *      image           pointer to buffer of destination image (yuv420)
 *
 * Returns :  netcam->jpeg_error
 */
static int netcam_image_conv(netcam_context_ptr netcam,
                               struct jpeg_decompress_struct *cinfo,
                               unsigned char *image)
{
    JSAMPARRAY      line;           /* Array of decomp data lines */
    unsigned char  *wline;          /* Will point to line[0] */
    /* Working variables */
    int             linesize, i;
    unsigned char  *upic, *vpic;
    unsigned char  *pic = image;
    unsigned char   y;              /* Switch for decoding YUV data */
    unsigned int    width, height;

    width = cinfo->output_width;
    height = cinfo->output_height;

    if (width && ((width != netcam->width) || (height != netcam->height))) {
        MOTION_LOG(WRN, TYPE_NETCAM, NO_ERRNO,
                   "%s: JPEG image size %dx%d, JPEG was %dx%d",
                    netcam->width, netcam->height, width, height);
        jpeg_destroy_decompress(cinfo);
        netcam->jpeg_error |= 4;
        return netcam->jpeg_error;
    }
    /* Set the output pointers (these come from YUV411P definition. */
    upic = pic + width * height;
    vpic = upic + (width * height) / 4;


    /* YCbCr format will give us one byte each for YUV. */
    linesize = cinfo->output_width * 3;

    /* Allocate space for one line. */
    line = (cinfo->mem->alloc_sarray)((j_common_ptr) cinfo, JPOOL_IMAGE,
                                       cinfo->output_width * cinfo->output_components, 1);

    wline = line[0];
    y = 0;

    while (cinfo->output_scanline < height) {
        jpeg_read_scanlines(cinfo, line, 1);

        for (i = 0; i < linesize; i += 3) {
            pic[i / 3] = wline[i];
            if (i & 1) {
                upic[(i / 3) / 2] = wline[i + 1];
                vpic[(i / 3) / 2] = wline[i + 2];
            }
        }

        pic += linesize / 3;

        if (y++ & 1) {
            upic += width / 2;
            vpic += width / 2;
        }
    }

    jpeg_finish_decompress(cinfo);
    jpeg_destroy_decompress(cinfo);

    if (netcam->cnt->rotate_data.degrees > 0)
        /* Rotate as specified */
        rotate_map(netcam->cnt, image);

    MOTION_LOG(DBG, TYPE_NETCAM, NO_ERRNO, "%s: jpeg_error %d",
               netcam->jpeg_error);

    return netcam->jpeg_error;
}