/* Reconfigures the encoder with the new properties */ static GstVaapiEncoderStatus gst_vaapi_encoder_reconfigure_internal (GstVaapiEncoder * encoder) { GstVaapiEncoderClass *const klass = GST_VAAPI_ENCODER_GET_CLASS (encoder); GstVideoInfo *const vip = GST_VAAPI_ENCODER_VIDEO_INFO (encoder); GstVaapiEncoderStatus status; GstVaapiVideoPool *pool; guint codedbuf_size; /* Generate a keyframe every second */ if (!encoder->keyframe_period) encoder->keyframe_period = (vip->fps_n + vip->fps_d - 1) / vip->fps_d; status = klass->reconfigure (encoder); if (status != GST_VAAPI_ENCODER_STATUS_SUCCESS) return status; if (!gst_vaapi_encoder_ensure_context (encoder)) goto error_reset_context; codedbuf_size = encoder->codedbuf_pool ? gst_vaapi_coded_buffer_pool_get_buffer_size (GST_VAAPI_CODED_BUFFER_POOL (encoder)) : 0; if (codedbuf_size != encoder->codedbuf_size) { pool = gst_vaapi_coded_buffer_pool_new (encoder, encoder->codedbuf_size); if (!pool) goto error_alloc_codedbuf_pool; gst_vaapi_video_pool_set_capacity (pool, 5); gst_vaapi_video_pool_replace (&encoder->codedbuf_pool, pool); gst_vaapi_video_pool_unref (pool); } return GST_VAAPI_ENCODER_STATUS_SUCCESS; /* ERRORS */ error_alloc_codedbuf_pool: { GST_ERROR ("failed to initialize coded buffer pool"); return GST_VAAPI_ENCODER_STATUS_ERROR_ALLOCATION_FAILED; } error_reset_context: { GST_ERROR ("failed to update VA context"); return GST_VAAPI_ENCODER_STATUS_ERROR_OPERATION_FAILED; } }
int main (int argc, char *argv[]) { GstVaapiDisplay *display; GstVaapiSurface *surface; GstVaapiID surface_id; GstVaapiSurface *surfaces[MAX_SURFACES]; GstVaapiVideoPool *pool; gint i; static const GstVaapiChromaType chroma_type = GST_VAAPI_CHROMA_TYPE_YUV420; static const guint width = 320; static const guint height = 240; if (!video_output_init (&argc, argv, NULL)) g_error ("failed to initialize video output subsystem"); display = video_output_create_display (NULL); if (!display) g_error ("could not create Gst/VA display"); surface = gst_vaapi_surface_new (display, chroma_type, width, height); if (!surface) g_error ("could not create Gst/VA surface"); surface_id = gst_vaapi_surface_get_id (surface); g_print ("created surface %" GST_VAAPI_ID_FORMAT "\n", GST_VAAPI_ID_ARGS (surface_id)); gst_vaapi_object_unref (surface); pool = gst_vaapi_surface_pool_new (display, GST_VIDEO_FORMAT_ENCODED, width, height); if (!pool) g_error ("could not create Gst/VA surface pool"); for (i = 0; i < MAX_SURFACES; i++) { surface = gst_vaapi_video_pool_get_object (pool); if (!surface) g_error ("could not allocate Gst/VA surface from pool"); g_print ("created surface %" GST_VAAPI_ID_FORMAT " from pool\n", GST_VAAPI_ID_ARGS (gst_vaapi_surface_get_id (surface))); surfaces[i] = surface; } /* Check the pool doesn't return the last free'd surface */ surface = gst_vaapi_object_ref (surfaces[1]); for (i = 0; i < 2; i++) gst_vaapi_video_pool_put_object (pool, surfaces[i]); for (i = 0; i < 2; i++) { surfaces[i] = gst_vaapi_video_pool_get_object (pool); if (!surfaces[i]) g_error ("could not re-allocate Gst/VA surface%d from pool", i); g_print ("created surface %" GST_VAAPI_ID_FORMAT " from pool (realloc)\n", GST_VAAPI_ID_ARGS (gst_vaapi_surface_get_id (surfaces[i]))); } if (surface == surfaces[0]) g_error ("Gst/VA pool doesn't queue free surfaces"); for (i = MAX_SURFACES - 1; i >= 0; i--) { if (!surfaces[i]) continue; gst_vaapi_video_pool_put_object (pool, surfaces[i]); surfaces[i] = NULL; } /* Unref in random order to check objects are correctly refcounted */ gst_vaapi_display_unref (display); gst_vaapi_video_pool_unref (pool); gst_vaapi_object_unref (surface); video_output_exit (); return 0; }