Пример #1
0
bool
VideoInput::switchInput(const std::string& resource)
{
    DEBUG("MRL: '%s'", resource.c_str());

    if (switchPending_) {
        ERROR("Video switch already requested");
        return false;
    }

    // Switch off video input?
    if (resource.empty()) {
        clearOptions();
        switchPending_ = true;
        if (!loop_.isRunning())
            loop_.start();
        return true;
    }

    // Supported MRL schemes
    static const std::string sep = "://";

    const auto pos = resource.find(sep);
    if (pos == std::string::npos)
        return false;

    const auto prefix = resource.substr(0, pos);
    if ((pos + sep.size()) >= resource.size())
        return false;

    const auto suffix = resource.substr(pos + sep.size());

    bool valid = false;

    if (prefix == "v4l2") {
        /* Video4Linux2 */
        valid = initCamera(suffix);
    } else if (prefix == "display") {
        /* X11 display name */
        valid = initX11(suffix);
    } else if (prefix == "file") {
        /* Pathname */
        valid = initFile(suffix);
    }

    /* Unsupported MRL or failed initialization */
    if (valid) {
        switchPending_ = true;
        if (!loop_.isRunning())
            loop_.start();
    }
    else
        ERROR("Failed to init input for MRL '%s'\n", resource.c_str());

    return valid;
}
Пример #2
0
void	eglInit(int width, int height)
{
	m_width = width;
	m_height = height;
	#ifdef EGL_USE_X11
	initX11();
	#else
	initEglOnly();
	#endif
	EGLint ContextAttribList[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
	
	m_eglcontext = eglCreateContext( m_egldisplay, m_eglconfig, EGL_NO_CONTEXT, ContextAttribList);
	eglMakeCurrent(m_egldisplay, m_eglsurface, m_eglsurface, m_eglcontext);
	
	EGLint h, w;	
	eglQuerySurface(m_egldisplay, m_eglsurface, EGL_WIDTH, &w);
	eglQuerySurface(m_egldisplay, m_eglsurface, EGL_HEIGHT, &h);
	m_ymax = 0.1f * tan(45.0f * M_PI/360.0f);
	m_ymin = -m_ymax;
	m_xmin = m_ymin * ((GLfloat)w/(GLfloat)h);
	m_xmax = m_ymax * ((GLfloat)w/(GLfloat)h);
}
Пример #3
0
int initEGL(int n_buf)
{
#ifdef GLES_20
    EGLint  context_attr[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
#else
    typedef NativeDisplayType EGLNativeDisplayType;
    typedef NativeWindowType EGLNativeWindowType;
#endif

    EGLint            disp_w, disp_h;
    EGLNativeDisplayType disp_type;
    EGLNativeWindowType  window;
    EGLConfig         cfgs[2];
    EGLint            n_cfgs;
    EGLint            egl_attr[] = {
                         EGL_BUFFER_SIZE, EGL_DONT_CARE,
                         EGL_RED_SIZE,    8,
                         EGL_GREEN_SIZE,  8,
                         EGL_BLUE_SIZE,   8,
                         EGL_DEPTH_SIZE,  8,
#ifdef GLES_20
                         EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
#endif
                         EGL_NONE };

#ifdef X11
    if (initX11(&disp_w, &disp_h))
        return -1;

    disp_type = (EGLNativeDisplayType)x11Display;
    window = (EGLNativeWindowType)x11Window;
#else
    if (get_disp_resolution(&disp_w, &disp_h)) {
        printf("ERROR: get display resolution failed\n");
        return -1;
    }

    printf("\n\nliuxu, 04/21/2014, get_disp_resolution, disp_w=%d, disp_h=%d\n\n", disp_w, disp_h);

    disp_type = (EGLNativeDisplayType)EGL_DEFAULT_DISPLAY;
    window  = 0;
#endif

    dpy = eglGetDisplay(disp_type);

    if (eglInitialize(dpy, NULL, NULL) != EGL_TRUE) {
        print_err("eglInitialize");
        return -1;
    }

    if (eglGetConfigs(dpy, cfgs, 2, &n_cfgs) != EGL_TRUE) {
        print_err("eglGetConfigs");
        goto cleanup;
    }
    
    if (eglChooseConfig(dpy, egl_attr, cfgs, 2, &n_cfgs) != EGL_TRUE) {
        print_err("eglChooseConfig");
        goto cleanup;
    }

    surface = eglCreateWindowSurface(dpy, cfgs[0], window, NULL);
    if (surface == EGL_NO_SURFACE) {
        print_err("eglCreateWindowSurface");
        goto cleanup;
    }

#ifdef GLES_20
    context = eglCreateContext(dpy, cfgs[0], EGL_NO_CONTEXT, context_attr);
#else
    context = eglCreateContext(dpy, cfgs[0], EGL_NO_CONTEXT, NULL);
#endif
    if (context == EGL_NO_CONTEXT) {
        print_err("eglCreateContext");
        goto cleanup;
    }

    if (eglMakeCurrent(dpy, surface, surface, context) != EGL_TRUE) {
        print_err("eglMakeCurrent");
        goto cleanup;
    }
  
    /* 0 - do not sync with video frame */
    if (profiling == TRUE) {
        if (eglSwapInterval(dpy, 0) != EGL_TRUE) {
            print_err("eglSwapInterval");
            goto cleanup;
        }
    }

#ifndef GLES_20
    glShadeModel(GL_FLAT);
    glTexParameterf(GL_TEXTURE_STREAM_IMG, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameterf(GL_TEXTURE_STREAM_IMG, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

    glFrontFace(GL_CW);
    glCullFace(GL_FRONT);
    glEnable(GL_CULL_FACE);

    glEnable(GL_NORMALIZE);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    glOrthof(-CUBE_V_LEN * disp_w / disp_h, CUBE_V_LEN * disp_w / disp_h,
             -CUBE_V_LEN, CUBE_V_LEN, -CUBE_V_LEN * 2, CUBE_V_LEN * 2);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
#endif

    return 0;

cleanup:
    deInitEGL(n_buf);
#ifdef X11
    deInitX11();
#endif
    return -1;
}