/** * gst_vaapi_encoder_get_buffer_with_timeout: * @encoder: a #GstVaapiEncoder * @out_codedbuf_proxy_ptr: the next coded buffer as a #GstVaapiCodedBufferProxy * @timeout: the number of microseconds to wait for the coded buffer, at most * * Upon successful return, *@out_codedbuf_proxy_ptr contains the next * coded buffer as a #GstVaapiCodedBufferProxy. The caller owns this * object, so gst_vaapi_coded_buffer_proxy_unref() shall be called * after usage. Otherwise, @GST_VAAPI_DECODER_STATUS_ERROR_NO_BUFFER * is returned if no coded buffer is available so far (timeout). * * The parent frame is available as a #GstVideoCodecFrame attached to * the user-data anchor of the output coded buffer. Ownership of the * frame is transferred to the coded buffer. * * Return value: a #GstVaapiEncoderStatus */ GstVaapiEncoderStatus gst_vaapi_encoder_get_buffer_with_timeout (GstVaapiEncoder * encoder, GstVaapiCodedBufferProxy ** out_codedbuf_proxy_ptr, guint64 timeout) { GstVaapiEncPicture *picture; GstVaapiCodedBufferProxy *codedbuf_proxy; codedbuf_proxy = g_async_queue_timeout_pop (encoder->codedbuf_queue, timeout); if (!codedbuf_proxy) return GST_VAAPI_ENCODER_STATUS_NO_BUFFER; /* Wait for completion of all operations and report any error that occurred */ picture = gst_vaapi_coded_buffer_proxy_get_user_data (codedbuf_proxy); if (!gst_vaapi_surface_sync (picture->surface)) goto error_invalid_buffer; gst_vaapi_coded_buffer_proxy_set_user_data (codedbuf_proxy, gst_video_codec_frame_ref (picture->frame), (GDestroyNotify) gst_video_codec_frame_unref); if (out_codedbuf_proxy_ptr) *out_codedbuf_proxy_ptr = gst_vaapi_coded_buffer_proxy_ref (codedbuf_proxy); gst_vaapi_coded_buffer_proxy_unref (codedbuf_proxy); return GST_VAAPI_ENCODER_STATUS_SUCCESS; /* ERRORS */ error_invalid_buffer: { GST_ERROR ("failed to encode the frame"); gst_vaapi_coded_buffer_proxy_unref (codedbuf_proxy); return GST_VAAPI_ENCODER_STATUS_ERROR_INVALID_SURFACE; } }
static gboolean renderer_process (App * app, RenderFrame * rfp) { GError *error = NULL; GstVaapiSurface *surface; const GstVaapiRectangle *crop_rect; #define SEND_ERROR(...) \ do { \ error = g_error_new(APP_ERROR, APP_ERROR_RENDERER, __VA_ARGS__); \ goto send_error; \ } while (0) surface = gst_vaapi_surface_proxy_get_surface (rfp->proxy); if (!surface) SEND_ERROR ("failed to get decoded surface from render frame"); ensure_window_size (app, surface); crop_rect = gst_vaapi_surface_proxy_get_crop_rect (rfp->proxy); if (g_use_pixmap && !ensure_pixmaps (app, surface, crop_rect)) SEND_ERROR ("failed to create intermediate pixmaps"); if (!gst_vaapi_surface_sync (surface)) SEND_ERROR ("failed to sync decoded surface"); if (G_LIKELY (!g_benchmark)) renderer_wait_until (app, rfp->pts); if (G_UNLIKELY (g_use_pixmap)) { GstVaapiPixmap *const pixmap = app->pixmaps[app->pixmap_id]; if (!gst_vaapi_pixmap_put_surface (pixmap, surface, crop_rect, GST_VAAPI_PICTURE_STRUCTURE_FRAME)) SEND_ERROR ("failed to render to pixmap"); if (!gst_vaapi_window_put_pixmap (app->window, pixmap, NULL, NULL)) SEND_ERROR ("failed to render surface %" GST_VAAPI_ID_FORMAT, GST_VAAPI_ID_ARGS (pixmap)); app->pixmap_id = (app->pixmap_id + 1) % G_N_ELEMENTS (app->pixmaps); } else if (!gst_vaapi_window_put_surface (app->window, surface, crop_rect, NULL, GST_VAAPI_PICTURE_STRUCTURE_FRAME)) SEND_ERROR ("failed to render surface %" GST_VAAPI_ID_FORMAT, GST_VAAPI_ID_ARGS (gst_vaapi_surface_get_id (surface))); app->num_frames++; render_frame_replace (&app->last_frame, rfp); return TRUE; #undef SEND_ERROR send_error: app_send_error (app, error); return FALSE; }
/** * gst_vaapi_texture_put_surface: * @texture: a #GstVaapiTexture * @surface: a #GstVaapiSurface * @flags: postprocessing flags. See #GstVaapiTextureRenderFlags * * Renders the @surface into the àtexture. The @flags specify how * de-interlacing (if needed), color space conversion, scaling and * other postprocessing transformations are performed. * * Return value: %TRUE on success */ static gboolean gst_vaapi_texture_glx_put_surface_unlocked (GstVaapiTexture * base_texture, GstVaapiSurface * surface, const GstVaapiRectangle * crop_rect, guint flags) { GstVaapiTextureGLX *const texture = GST_VAAPI_TEXTURE_GLX (base_texture); VAStatus status; GLContextState old_cs; gboolean success = FALSE; const GLfloat *txc, *tyc; static const GLfloat g_texcoords[2][2] = { {0.0f, 1.0f}, {1.0f, 0.0f}, }; status = vaPutSurface (GST_VAAPI_OBJECT_VADISPLAY (texture), GST_VAAPI_OBJECT_ID (surface), texture->pixo->pixmap, crop_rect->x, crop_rect->y, crop_rect->width, crop_rect->height, 0, 0, base_texture->width, base_texture->height, NULL, 0, from_GstVaapiSurfaceRenderFlags (flags)); if (!vaapi_check_status (status, "vaPutSurface() [TFP]")) return FALSE; if (texture->gl_context && !gl_set_current_context (texture->gl_context, &old_cs)) return FALSE; if (!gl_bind_framebuffer_object (texture->fbo)) { GST_ERROR ("failed to bind FBO"); goto out_reset_context; } if (!gst_vaapi_surface_sync (surface)) { GST_ERROR ("failed to render surface to pixmap"); goto out_unbind_fbo; } if (!gl_bind_pixmap_object (texture->pixo)) { GST_ERROR ("could not bind GLX pixmap"); goto out_unbind_fbo; } flags = GST_VAAPI_TEXTURE_FLAGS (texture); txc = g_texcoords[! !(flags & GST_VAAPI_TEXTURE_ORIENTATION_FLAG_X_INVERTED)]; tyc = g_texcoords[! !(flags & GST_VAAPI_TEXTURE_ORIENTATION_FLAG_Y_INVERTED)]; glColor4f (1.0f, 1.0f, 1.0f, 1.0f); glBegin (GL_QUADS); { glTexCoord2f (txc[0], tyc[0]); glVertex2i (0, 0); glTexCoord2f (txc[0], tyc[1]); glVertex2i (0, base_texture->height); glTexCoord2f (txc[1], tyc[1]); glVertex2i (base_texture->width, base_texture->height); glTexCoord2f (txc[1], tyc[0]); glVertex2i (base_texture->width, 0); } glEnd (); if (!gl_unbind_pixmap_object (texture->pixo)) { GST_ERROR ("failed to release GLX pixmap"); goto out_unbind_fbo; } success = TRUE; out_unbind_fbo: if (!gl_unbind_framebuffer_object (texture->fbo)) success = FALSE; out_reset_context: if (texture->gl_context && !gl_set_current_context (&old_cs, NULL)) success = FALSE; return success; }