Beispiel #1
0
static gboolean vid_area_render_handler(	GtkGLArea *area,
						GdkGLContext *context,
						gpointer data )
{
	gmpv_handle *ctx = data;
	int width;
	int height;
	int fbo;

	if(!ctx->opengl_ready)
	{
		mpv_check_error(mpv_opengl_cb_init_gl(	ctx->opengl_ctx,
							NULL,
							get_proc_address,
							NULL ));

		ctx->opengl_ready = TRUE;
	}

	width = gtk_widget_get_allocated_width(GTK_WIDGET(area));
	height = (-1)*gtk_widget_get_allocated_height(GTK_WIDGET(area));
	fbo = -1;

	glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fbo);
	mpv_opengl_cb_draw(ctx->opengl_ctx, fbo, width, height);

	return TRUE;
}
Beispiel #2
0
static gboolean
render_cb(GtkGLArea* area,
          GdkGLContext* ctxt,
          gpointer udata)
{
    GtPlayerMpv* self = GT_PLAYER_MPV(udata);
    GtPlayerMpvPrivate* priv = gt_player_mpv_get_instance_private(self);

    int width;
    int height;
    int fbo;

    if (!priv->opengl_ready)
    {
        check_mpv_error(mpv_opengl_cb_init_gl(priv->mpv_opengl, NULL,
                                              get_proc_address, NULL));
        priv->opengl_ready = TRUE;
    }

    width = gtk_widget_get_allocated_height(priv->opengl_area);
    height = (-1)*gtk_widget_get_allocated_width(priv->opengl_area);
    fbo = -1;

    glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fbo);
    mpv_opengl_cb_draw(priv->mpv_opengl, fbo, width, height);

    return TRUE;
}
void PlayerRenderer::render()
{
  int fbo = m_window->renderTargetId();

  m_window->resetOpenGLState();

  // The negative height signals to mpv that the video should be flipped
  // (according to the flipped OpenGL coordinate system).
  mpv_opengl_cb_draw(m_mpvGL, fbo, m_size.width(), -m_size.height());

  m_window->resetOpenGLState();
}
void PlayerRenderer::render()
{
  GLint fbo = 0;
  QOpenGLContext::currentContext()->functions()->glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fbo);

  m_window->resetOpenGLState();

  // The negative height signals to mpv that the video should be flipped
  // (according to the flipped OpenGL coordinate system).
  mpv_opengl_cb_draw(m_mpvGL, fbo, m_size.width(), -m_size.height());

  m_window->resetOpenGLState();
}
static gboolean
render_cb(GtkGLArea* area,
          GdkGLContext* ctxt,
          gpointer udata)
{
    GtPlayerBackendMpvOpenGL* self = GT_PLAYER_BACKEND_MPV_OPENGL(udata);
    GtPlayerBackendMpvOpenGLPrivate* priv = gt_player_backend_mpv_opengl_get_instance_private(self);

    int width;
    int height;
    int fbo;

    width = gtk_widget_get_allocated_width(GTK_WIDGET(area));
    height = (-1)*gtk_widget_get_allocated_height(GTK_WIDGET(area));
    fbo = -1;

    glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fbo);
    mpv_opengl_cb_draw(priv->mpv_opengl, fbo, width, height);

    return GDK_EVENT_STOP;
}
void VideoPlayer::paintGL()
{
    mpv_opengl_cb_draw(mpv_gl, defaultFramebufferObject(), width(), -height());
}
Beispiel #7
0
static void *render_thread_run(void *data) {
    struct render_thread *render_thread = data;

    EGLDisplay egl_display = NULL;
    EGLSurface egl_surface = NULL;
    EGLContext egl_context = NULL;
    // Gather egl params and bind to mpv opengl_cb
    {
        pthread_mutex_lock(&render_thread->lock);

        egl_display = render_thread->egl_display;
        egl_surface = render_thread->egl_surface;
        egl_context = render_thread->egl_context;

        eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context);
        eglSwapInterval(egl_display, 0);

        int res = mpv_opengl_cb_init_gl(render_thread->opengl_cb_context, NULL,
                                        mpv_get_proc_address, NULL);
        if (res < 0) {
            log_mpv_error("mpv_opengl_cb_init_gl failed", res);
        }

        mpv_opengl_cb_set_update_callback(render_thread->opengl_cb_context,
                                          update_callback, render_thread);

        // TODO: after the first uninit the video track is reset to 0 (none)
        // Setting this to 1 restarts the playback though and messes up the time the video
        // was playing at.
        uint64_t on = 1;
        mpv_set_property(render_thread->mpv, "vid", MPV_FORMAT_INT64, &on);

        render_thread->running = 1;
        pthread_cond_broadcast(&render_thread->ready);

        pthread_mutex_unlock(&render_thread->lock);
    }

    int64_t last_time = mpv_get_time_us(render_thread->mpv);
    int frames = 0;

    while (1) {
        // Wait for available frames
        {
            pthread_mutex_lock(&render_thread->frame_wait_lock);
            while (!render_thread->frame_available) {
                pthread_cond_wait(&render_thread->frame_wait, &render_thread->frame_wait_lock);
            }
            render_thread->frame_available = 0;
            pthread_mutex_unlock(&render_thread->frame_wait_lock);
        }

        // Check if still running
        int run, width, height;
        {
            pthread_mutex_lock(&render_thread->lock);
            run = render_thread->running;
            width = render_thread->width;
            height = render_thread->height;
            pthread_mutex_unlock(&render_thread->lock);
        }
        if (!run) {
            break;
        }

//        int64_t draw_start = mpv_get_time_us(render_thread->mpv);
        mpv_opengl_cb_draw(render_thread->opengl_cb_context, 0, width, -height);
//        LOGI("Render time %ld", (mpv_get_time_us(render_thread->mpv) - draw_start));
        if (!eglSwapBuffers(egl_display, egl_surface)) {
            LOGE("eglSwapBuffers failed %d", eglGetError());
        }
//        mpv_opengl_cb_report_flip(render_thread->opengl_cb_context, 0);

        frames++;

        int64_t now = mpv_get_time_us(render_thread->mpv);
        if (now - last_time >= 1000 * 1000) {
            // last_time += 1000 * 1000;
            last_time = now; // Don't play catch-up
            LOGI("Render fps %d", frames);
            frames = 0;
        }
    }

    // Release egl params and unbind from mpv opengl_cb
    {
        pthread_mutex_lock(&render_thread->lock);

        int res = mpv_opengl_cb_uninit_gl(render_thread->opengl_cb_context);
        if (res < 0) {
            log_mpv_error("mpv_opengl_cb_uninit_gl failed", res);
        }

        eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);

        pthread_mutex_unlock(&render_thread->lock);
    }

    return NULL;
}
Beispiel #8
0
void MpvWidget::paintGL()
{
    mpv_opengl_cb_draw(mpv_gl, defaultFramebufferObject(), width(), -height());
}