Logo Search packages:      
Sourcecode: zebra version File versions  Download package

int zebra_processor_init ( zebra_processor_t processor,
const char *  video_device,
int  enable_display 
)

(re)initialization. opens a video input device and/or prepares to display output

Definition at line 466 of file processor.c.

References ZEBRA_ERR_SYSTEM, ZEBRA_ERR_UNSUPPORTED, zebra_negotiate_format(), zebra_processor_init(), zebra_video_create(), zebra_video_destroy(), zebra_video_get_fd(), zebra_video_get_height(), zebra_video_get_width(), zebra_video_init(), zebra_video_open(), zebra_window_attach(), zebra_window_create(), and zebra_window_destroy().

Referenced by zebra::Processor::init(), and zebra_processor_init().

{
    if(proc_lock(proc) < 0)
        return(-1);
    proc_destroy_thread(proc->video_thread, &proc->video_started);
    proc_destroy_thread(proc->input_thread, &proc->input_started);
    proc->video_started = proc->input_started = 0;
    int rc = 0;
    if(proc->video) {
        if(dev)
            zebra_video_open(proc->video, NULL);
        else {
            zebra_video_destroy(proc->video);
            proc->video = NULL;
        }
    }
    if(proc->window) {
        zebra_window_destroy(proc->window);
        proc->window = NULL;
        _zebra_window_close(proc);
    }

    if(!dev && !enable_display)
        /* nothing to do */
        goto done;

    if(enable_display) {
        proc->window = zebra_window_create();
        if(!proc->window) {
            rc = err_copy(proc, proc->window);
            goto done;
        }
    }

    if(dev) {
        proc->video = zebra_video_create();
        if(!proc->video ||
           zebra_video_open(proc->video, dev)) {
            rc = err_copy(proc, proc->video);
            goto done;
        }
        if(zebra_video_get_fd(proc->video) < 0 && proc->threaded) {
#ifdef HAVE_LIBPTHREAD
            /* spawn blocking video thread */
            if((rc = pthread_create(&proc->video_thread, NULL,
                                    proc_video_thread, proc))) {
                rc = err_capture_num(proc, SEV_ERROR, ZEBRA_ERR_SYSTEM,
                                     __func__, "spawning video thread", rc);
                goto done;
            }
            proc->video_started = 1;
            zprintf(4, "spawned video thread\n");
#endif
        }
    }

#ifdef HAVE_LIBPTHREAD
    if(proc->threaded && (proc->window ||
                          (proc->video && !proc->video_started))) {
        /* spawn input monitor thread */
        if((rc = pthread_create(&proc->input_thread, NULL,
                                proc_input_thread, proc))) {
            rc = err_capture_num(proc, SEV_ERROR, ZEBRA_ERR_SYSTEM, __func__,
                                 "spawning input thread", rc);
            goto done;
        }
        proc->input_started = 1;
        zprintf(4, "spawned input thread\n");
    }
#endif

    if(proc->window) {
        /* arbitrary default */
        int width = 640, height = 480;
        if(proc->video) {
            width = zebra_video_get_width(proc->video);
            height = zebra_video_get_height(proc->video);
        }

        if(_zebra_window_open(proc, "zebra barcode reader", width, height)) {
            rc = -1;
            goto done;
        }
        else if(zebra_window_attach(proc->window, proc->display, proc->xwin)) {
            rc = err_copy(proc, proc->window);
            goto done;
        }
    }

    if(proc->video && proc->force_input) {
        if(zebra_video_init(proc->video, proc->force_input))
            rc = err_copy(proc, proc->video);
    }
    else if(proc->video)
        while(zebra_negotiate_format(proc->video, proc->window)) {
            if(proc->video && proc->window) {
                fprintf(stderr,
                        "WARNING: no compatible input to output format\n"
                        "...trying again with output disabled\n");
                zebra_window_destroy(proc->window);
                proc->window = NULL;
            }
            else {
                zprintf(1, "ERROR: no compatible %s format\n",
                        (proc->video) ? "video input" : "window output");
                rc = err_capture(proc, SEV_ERROR, ZEBRA_ERR_UNSUPPORTED,
                                 __func__, "no compatible image format");
                goto done;
            }
        }

 done:
    proc_unlock(proc);
    return(rc);
}


Generated by  Doxygen 1.6.0   Back to index