context: clean-ups. Strip down APIs.

Improve documentation and debug messages. Clean-up APIs, i.e. strip
them down to the minimal set of interfaces. They are private, so no
need expose getters for instance.
This commit is contained in:
Gwenole Beauchesne 2014-01-23 09:41:07 +01:00
parent 1ffdc010ad
commit c85b080688
4 changed files with 121 additions and 305 deletions

View file

@ -28,9 +28,9 @@
*/ */
#include "sysdeps.h" #include "sysdeps.h"
#include <assert.h>
#include "gstvaapicompat.h" #include "gstvaapicompat.h"
#include "gstvaapicontext.h" #include "gstvaapicontext.h"
#include "gstvaapidisplay_priv.h"
#include "gstvaapiobject_priv.h" #include "gstvaapiobject_priv.h"
#include "gstvaapisurface.h" #include "gstvaapisurface.h"
#include "gstvaapisurface_priv.h" #include "gstvaapisurface_priv.h"
@ -44,37 +44,6 @@
#define DEBUG 1 #define DEBUG 1
#include "gstvaapidebug.h" #include "gstvaapidebug.h"
typedef struct _GstVaapiContextClass GstVaapiContextClass;
/**
* GstVaapiContext:
*
* A VA context wrapper.
*/
struct _GstVaapiContext
{
/*< private >*/
GstVaapiObject parent_instance;
GstVaapiContextInfo info;
VAConfigID config_id;
GPtrArray *surfaces;
GstVaapiVideoPool *surfaces_pool;
GPtrArray *overlays[2];
guint overlay_id;
};
/**
* GstVaapiContextClass:
*
* A VA context wrapper class.
*/
struct _GstVaapiContextClass
{
/*< private >*/
GstVaapiObjectClass parent_class;
};
typedef struct _GstVaapiOverlayRectangle GstVaapiOverlayRectangle; typedef struct _GstVaapiOverlayRectangle GstVaapiOverlayRectangle;
struct _GstVaapiOverlayRectangle struct _GstVaapiOverlayRectangle
{ {
@ -88,25 +57,6 @@ struct _GstVaapiOverlayRectangle
guint is_associated:1; guint is_associated:1;
}; };
static guint
get_max_ref_frames (GstVaapiProfile profile)
{
guint ref_frames;
switch (gst_vaapi_profile_get_codec (profile)) {
case GST_VAAPI_CODEC_H264:
ref_frames = 16;
break;
case GST_VAAPI_CODEC_JPEG:
ref_frames = 0;
break;
default:
ref_frames = 2;
break;
}
return ref_frames;
}
static inline void static inline void
gst_video_overlay_rectangle_replace (GstVideoOverlayRectangle ** old_rect_ptr, gst_video_overlay_rectangle_replace (GstVideoOverlayRectangle ** old_rect_ptr,
GstVideoOverlayRectangle * new_rect) GstVideoOverlayRectangle * new_rect)
@ -392,7 +342,7 @@ overlay_reassociate (GPtrArray * overlays)
} }
static void static void
gst_vaapi_context_clear_overlay (GstVaapiContext * context) context_clear_overlay (GstVaapiContext * context)
{ {
overlay_clear (context->overlays[0]); overlay_clear (context->overlays[0]);
overlay_clear (context->overlays[1]); overlay_clear (context->overlays[1]);
@ -400,42 +350,39 @@ gst_vaapi_context_clear_overlay (GstVaapiContext * context)
} }
static inline void static inline void
gst_vaapi_context_destroy_overlay (GstVaapiContext * context) context_destroy_overlay (GstVaapiContext * context)
{ {
gst_vaapi_context_clear_overlay (context); context_clear_overlay (context);
} }
static void static void
unref_surface_cb (gpointer data, gpointer user_data) unref_surface_cb (GstVaapiSurface * surface)
{ {
GstVaapiSurface *const surface = GST_VAAPI_SURFACE (data);
gst_vaapi_surface_set_parent_context (surface, NULL); gst_vaapi_surface_set_parent_context (surface, NULL);
gst_vaapi_object_unref (surface); gst_vaapi_object_unref (surface);
} }
static void static void
gst_vaapi_context_destroy_surfaces (GstVaapiContext * context) context_destroy_surfaces (GstVaapiContext * context)
{ {
gst_vaapi_context_destroy_overlay (context); context_destroy_overlay (context);
if (context->surfaces) { if (context->surfaces) {
g_ptr_array_foreach (context->surfaces, unref_surface_cb, NULL); g_ptr_array_unref (context->surfaces);
g_ptr_array_free (context->surfaces, TRUE);
context->surfaces = NULL; context->surfaces = NULL;
} }
gst_vaapi_video_pool_replace (&context->surfaces_pool, NULL); gst_vaapi_video_pool_replace (&context->surfaces_pool, NULL);
} }
static void static void
gst_vaapi_context_destroy (GstVaapiContext * context) context_destroy (GstVaapiContext * context)
{ {
GstVaapiDisplay *const display = GST_VAAPI_OBJECT_DISPLAY (context); GstVaapiDisplay *const display = GST_VAAPI_OBJECT_DISPLAY (context);
VAContextID context_id; VAContextID context_id;
VAStatus status; VAStatus status;
context_id = GST_VAAPI_OBJECT_ID (context); context_id = GST_VAAPI_OBJECT_ID (context);
GST_DEBUG ("context %" GST_VAAPI_ID_FORMAT, GST_VAAPI_ID_ARGS (context_id)); GST_DEBUG ("context 0x%08x", context_id);
if (context_id != VA_INVALID_ID) { if (context_id != VA_INVALID_ID) {
GST_VAAPI_DISPLAY_LOCK (display); GST_VAAPI_DISPLAY_LOCK (display);
@ -443,35 +390,33 @@ gst_vaapi_context_destroy (GstVaapiContext * context)
context_id); context_id);
GST_VAAPI_DISPLAY_UNLOCK (display); GST_VAAPI_DISPLAY_UNLOCK (display);
if (!vaapi_check_status (status, "vaDestroyContext()")) if (!vaapi_check_status (status, "vaDestroyContext()"))
g_warning ("failed to destroy context %" GST_VAAPI_ID_FORMAT, GST_WARNING ("failed to destroy context 0x%08x", context_id);
GST_VAAPI_ID_ARGS (context_id));
GST_VAAPI_OBJECT_ID (context) = VA_INVALID_ID; GST_VAAPI_OBJECT_ID (context) = VA_INVALID_ID;
} }
if (context->config_id != VA_INVALID_ID) { if (context->va_config != VA_INVALID_ID) {
GST_VAAPI_DISPLAY_LOCK (display); GST_VAAPI_DISPLAY_LOCK (display);
status = vaDestroyConfig (GST_VAAPI_DISPLAY_VADISPLAY (display), status = vaDestroyConfig (GST_VAAPI_DISPLAY_VADISPLAY (display),
context->config_id); context->va_config);
GST_VAAPI_DISPLAY_UNLOCK (display); GST_VAAPI_DISPLAY_UNLOCK (display);
if (!vaapi_check_status (status, "vaDestroyConfig()")) if (!vaapi_check_status (status, "vaDestroyConfig()"))
g_warning ("failed to destroy config %" GST_VAAPI_ID_FORMAT, GST_WARNING ("failed to destroy config 0x%08x", context->va_config);
GST_VAAPI_ID_ARGS (context->config_id)); context->va_config = VA_INVALID_ID;
context->config_id = VA_INVALID_ID;
} }
} }
static gboolean static gboolean
gst_vaapi_context_create_overlay (GstVaapiContext * context) context_create_overlay (GstVaapiContext * context)
{ {
if (!context->overlays[0] || !context->overlays[1]) if (!context->overlays[0] || !context->overlays[1])
return FALSE; return FALSE;
gst_vaapi_context_clear_overlay (context); context_clear_overlay (context);
return TRUE; return TRUE;
} }
static gboolean static gboolean
gst_vaapi_context_create_surfaces (GstVaapiContext * context) context_create_surfaces (GstVaapiContext * context)
{ {
const GstVaapiContextInfo *const cip = &context->info; const GstVaapiContextInfo *const cip = &context->info;
GstVideoInfo vi; GstVideoInfo vi;
@ -481,11 +426,13 @@ gst_vaapi_context_create_surfaces (GstVaapiContext * context)
/* Number of scratch surfaces beyond those used as reference */ /* Number of scratch surfaces beyond those used as reference */
const guint SCRATCH_SURFACES_COUNT = 4; const guint SCRATCH_SURFACES_COUNT = 4;
if (!gst_vaapi_context_create_overlay (context)) if (!context_create_overlay (context))
return FALSE; return FALSE;
num_surfaces = cip->ref_frames + SCRATCH_SURFACES_COUNT;
if (!context->surfaces) { if (!context->surfaces) {
context->surfaces = g_ptr_array_new (); context->surfaces = g_ptr_array_new_full (num_surfaces,
(GDestroyNotify) unref_surface_cb);
if (!context->surfaces) if (!context->surfaces)
return FALSE; return FALSE;
} }
@ -498,8 +445,6 @@ gst_vaapi_context_create_surfaces (GstVaapiContext * context)
if (!context->surfaces_pool) if (!context->surfaces_pool)
return FALSE; return FALSE;
} }
num_surfaces = cip->ref_frames + SCRATCH_SURFACES_COUNT;
gst_vaapi_video_pool_set_capacity (context->surfaces_pool, num_surfaces); gst_vaapi_video_pool_set_capacity (context->surfaces_pool, num_surfaces);
for (i = context->surfaces->len; i < num_surfaces; i++) { for (i = context->surfaces->len; i < num_surfaces; i++) {
@ -516,12 +461,10 @@ gst_vaapi_context_create_surfaces (GstVaapiContext * context)
} }
static gboolean static gboolean
gst_vaapi_context_create (GstVaapiContext * context) context_create (GstVaapiContext * context)
{ {
const GstVaapiContextInfo *const cip = &context->info; const GstVaapiContextInfo *const cip = &context->info;
GstVaapiDisplay *const display = GST_VAAPI_OBJECT_DISPLAY (context); GstVaapiDisplay *const display = GST_VAAPI_OBJECT_DISPLAY (context);
VAProfile va_profile;
VAEntrypoint va_entrypoint;
guint va_rate_control; guint va_rate_control;
VAConfigAttrib attribs[2]; VAConfigAttrib attribs[2];
guint num_attribs; guint num_attribs;
@ -532,27 +475,28 @@ gst_vaapi_context_create (GstVaapiContext * context)
gboolean success = FALSE; gboolean success = FALSE;
guint i; guint i;
if (!context->surfaces && !gst_vaapi_context_create_surfaces (context)) if (!context->surfaces && !context_create_surfaces (context))
goto end; goto cleanup;
surfaces = g_array_sized_new (FALSE, surfaces = g_array_sized_new (FALSE,
FALSE, sizeof (VASurfaceID), context->surfaces->len); FALSE, sizeof (VASurfaceID), context->surfaces->len);
if (!surfaces) if (!surfaces)
goto end; goto cleanup;
for (i = 0; i < context->surfaces->len; i++) { for (i = 0; i < context->surfaces->len; i++) {
GstVaapiSurface *const surface = g_ptr_array_index (context->surfaces, i); GstVaapiSurface *const surface = g_ptr_array_index (context->surfaces, i);
if (!surface) if (!surface)
goto end; goto cleanup;
surface_id = GST_VAAPI_OBJECT_ID (surface); surface_id = GST_VAAPI_OBJECT_ID (surface);
g_array_append_val (surfaces, surface_id); g_array_append_val (surfaces, surface_id);
} }
assert (surfaces->len == context->surfaces->len); g_assert (surfaces->len == context->surfaces->len);
if (!cip->profile || !cip->entrypoint) if (!cip->profile || !cip->entrypoint)
goto end; goto cleanup;
va_profile = gst_vaapi_profile_get_va_profile (cip->profile); context->va_profile = gst_vaapi_profile_get_va_profile (cip->profile);
va_entrypoint = gst_vaapi_entrypoint_get_va_entrypoint (cip->entrypoint); context->va_entrypoint =
gst_vaapi_entrypoint_get_va_entrypoint (cip->entrypoint);
num_attribs = 0; num_attribs = 0;
attribs[num_attribs++].type = VAConfigAttribRTFormat; attribs[num_attribs++].type = VAConfigAttribRTFormat;
@ -561,12 +505,12 @@ gst_vaapi_context_create (GstVaapiContext * context)
GST_VAAPI_DISPLAY_LOCK (display); GST_VAAPI_DISPLAY_LOCK (display);
status = vaGetConfigAttributes (GST_VAAPI_DISPLAY_VADISPLAY (display), status = vaGetConfigAttributes (GST_VAAPI_DISPLAY_VADISPLAY (display),
va_profile, va_entrypoint, attribs, num_attribs); context->va_profile, context->va_entrypoint, attribs, num_attribs);
GST_VAAPI_DISPLAY_UNLOCK (display); GST_VAAPI_DISPLAY_UNLOCK (display);
if (!vaapi_check_status (status, "vaGetConfigAttributes()")) if (!vaapi_check_status (status, "vaGetConfigAttributes()"))
goto end; goto cleanup;
if (!(attribs[0].value & VA_RT_FORMAT_YUV420)) if (!(attribs[0].value & VA_RT_FORMAT_YUV420))
goto end; goto cleanup;
if (cip->entrypoint == GST_VAAPI_ENTRYPOINT_SLICE_ENCODE) { if (cip->entrypoint == GST_VAAPI_ENTRYPOINT_SLICE_ENCODE) {
va_rate_control = from_GstVaapiRateControl (cip->rc_mode); va_rate_control = from_GstVaapiRateControl (cip->rc_mode);
@ -575,32 +519,32 @@ gst_vaapi_context_create (GstVaapiContext * context)
if ((attribs[1].value & va_rate_control) != va_rate_control) { if ((attribs[1].value & va_rate_control) != va_rate_control) {
GST_ERROR ("unsupported %s rate control", GST_ERROR ("unsupported %s rate control",
string_of_VARateControl (va_rate_control)); string_of_VARateControl (va_rate_control));
goto end; goto cleanup;
} }
attribs[1].value = va_rate_control; attribs[1].value = va_rate_control;
} }
GST_VAAPI_DISPLAY_LOCK (display); GST_VAAPI_DISPLAY_LOCK (display);
status = vaCreateConfig (GST_VAAPI_DISPLAY_VADISPLAY (display), status = vaCreateConfig (GST_VAAPI_DISPLAY_VADISPLAY (display),
va_profile, va_entrypoint, attribs, num_attribs, &context->config_id); context->va_profile, context->va_entrypoint, attribs, num_attribs,
&context->va_config);
GST_VAAPI_DISPLAY_UNLOCK (display); GST_VAAPI_DISPLAY_UNLOCK (display);
if (!vaapi_check_status (status, "vaCreateConfig()")) if (!vaapi_check_status (status, "vaCreateConfig()"))
goto end; goto cleanup;
GST_VAAPI_DISPLAY_LOCK (display); GST_VAAPI_DISPLAY_LOCK (display);
status = vaCreateContext (GST_VAAPI_DISPLAY_VADISPLAY (display), status = vaCreateContext (GST_VAAPI_DISPLAY_VADISPLAY (display),
context->config_id, context->va_config, cip->width, cip->height, VA_PROGRESSIVE,
cip->width, cip->height,
VA_PROGRESSIVE,
(VASurfaceID *) surfaces->data, surfaces->len, &context_id); (VASurfaceID *) surfaces->data, surfaces->len, &context_id);
GST_VAAPI_DISPLAY_UNLOCK (display); GST_VAAPI_DISPLAY_UNLOCK (display);
if (!vaapi_check_status (status, "vaCreateContext()")) if (!vaapi_check_status (status, "vaCreateContext()"))
goto end; goto cleanup;
GST_DEBUG ("context %" GST_VAAPI_ID_FORMAT, GST_VAAPI_ID_ARGS (context_id)); GST_DEBUG ("context 0x%08x", context_id);
GST_VAAPI_OBJECT_ID (context) = context_id; GST_VAAPI_OBJECT_ID (context) = context_id;
success = TRUE; success = TRUE;
end:
cleanup:
if (surfaces) if (surfaces)
g_array_free (surfaces, TRUE); g_array_free (surfaces, TRUE);
return success; return success;
@ -611,7 +555,7 @@ gst_vaapi_context_init (GstVaapiContext * context,
const GstVaapiContextInfo * cip) const GstVaapiContextInfo * cip)
{ {
context->info = *cip; context->info = *cip;
context->config_id = VA_INVALID_ID; context->va_config = VA_INVALID_ID;
context->overlays[0] = overlay_new (); context->overlays[0] = overlay_new ();
context->overlays[1] = overlay_new (); context->overlays[1] = overlay_new ();
} }
@ -621,43 +565,15 @@ gst_vaapi_context_finalize (GstVaapiContext * context)
{ {
overlay_destroy (&context->overlays[0]); overlay_destroy (&context->overlays[0]);
overlay_destroy (&context->overlays[1]); overlay_destroy (&context->overlays[1]);
gst_vaapi_context_destroy (context); context_destroy (context);
gst_vaapi_context_destroy_surfaces (context); context_destroy_surfaces (context);
} }
GST_VAAPI_OBJECT_DEFINE_CLASS (GstVaapiContext, gst_vaapi_context) GST_VAAPI_OBJECT_DEFINE_CLASS (GstVaapiContext, gst_vaapi_context);
/** /**
* gst_vaapi_context_new: * gst_vaapi_context_new:
* @display: a #GstVaapiDisplay * @display: a #GstVaapiDisplay
* @profile: a #GstVaapiProfile
* @entrypoint: a #GstVaapiEntrypoint
* @width: coded width from the bitstream
* @height: coded height from the bitstream
*
* Creates a new #GstVaapiContext with the specified codec @profile
* and @entrypoint.
*
* Return value: the newly allocated #GstVaapiContext object
*/
GstVaapiContext *gst_vaapi_context_new (GstVaapiDisplay * display,
GstVaapiProfile profile,
GstVaapiEntrypoint entrypoint, guint width, guint height)
{
GstVaapiContextInfo info;
info.profile = profile;
info.entrypoint = entrypoint;
info.rc_mode = GST_VAAPI_RATECONTROL_NONE;
info.width = width;
info.height = height;
info.ref_frames = get_max_ref_frames (profile);
return gst_vaapi_context_new_full (display, &info);
}
/**
* gst_vaapi_context_new_full:
* @display: a #GstVaapiDisplay
* @cip: a pointer to the #GstVaapiContextInfo * @cip: a pointer to the #GstVaapiContextInfo
* *
* Creates a new #GstVaapiContext with the configuration specified by * Creates a new #GstVaapiContext with the configuration specified by
@ -667,7 +583,7 @@ GST_VAAPI_OBJECT_DEFINE_CLASS (GstVaapiContext, gst_vaapi_context)
* Return value: the newly allocated #GstVaapiContext object * Return value: the newly allocated #GstVaapiContext object
*/ */
GstVaapiContext * GstVaapiContext *
gst_vaapi_context_new_full (GstVaapiDisplay * display, gst_vaapi_context_new (GstVaapiDisplay * display,
const GstVaapiContextInfo * cip) const GstVaapiContextInfo * cip)
{ {
GstVaapiContext *context; GstVaapiContext *context;
@ -682,7 +598,7 @@ gst_vaapi_context_new_full (GstVaapiDisplay * display,
return NULL; return NULL;
gst_vaapi_context_init (context, cip); gst_vaapi_context_init (context, cip);
if (!gst_vaapi_context_create (context)) if (!context_create (context))
goto error; goto error;
return context; return context;
@ -694,36 +610,6 @@ error:
/** /**
* gst_vaapi_context_reset: * gst_vaapi_context_reset:
* @context: a #GstVaapiContext * @context: a #GstVaapiContext
* @profile: a #GstVaapiProfile
* @entrypoint: a #GstVaapiEntrypoint
* @width: coded width from the bitstream
* @height: coded height from the bitstream
*
* Resets @context to the specified codec @profile and @entrypoint.
* The surfaces will be reallocated if the coded size changed.
*
* Return value: %TRUE on success
*/
gboolean
gst_vaapi_context_reset (GstVaapiContext * context,
GstVaapiProfile profile,
GstVaapiEntrypoint entrypoint, unsigned int width, unsigned int height)
{
GstVaapiContextInfo info;
info.profile = profile;
info.entrypoint = entrypoint;
info.rc_mode = GST_VAAPI_RATECONTROL_NONE;
info.width = width;
info.height = height;
info.ref_frames = context->info.ref_frames;
return gst_vaapi_context_reset_full (context, &info);
}
/**
* gst_vaapi_context_reset_full:
* @context: a #GstVaapiContext
* @new_cip: a pointer to the new #GstVaapiContextInfo details * @new_cip: a pointer to the new #GstVaapiContextInfo details
* *
* Resets @context to the configuration specified by @new_cip, thus * Resets @context to the configuration specified by @new_cip, thus
@ -733,41 +619,45 @@ gst_vaapi_context_reset (GstVaapiContext * context,
* Return value: %TRUE on success * Return value: %TRUE on success
*/ */
gboolean gboolean
gst_vaapi_context_reset_full (GstVaapiContext * context, gst_vaapi_context_reset (GstVaapiContext * context,
const GstVaapiContextInfo * new_cip) const GstVaapiContextInfo * new_cip)
{ {
GstVaapiContextInfo *const cip = &context->info; GstVaapiContextInfo *const cip = &context->info;
gboolean size_changed, codec_changed, rc_mode_changed; gboolean size_changed, config_changed;
size_changed = cip->width != new_cip->width || cip->height != new_cip->height; size_changed = cip->width != new_cip->width || cip->height != new_cip->height;
if (size_changed) { if (size_changed) {
gst_vaapi_context_destroy_surfaces (context);
cip->width = new_cip->width; cip->width = new_cip->width;
cip->height = new_cip->height; cip->height = new_cip->height;
} }
codec_changed = cip->profile != new_cip->profile || config_changed = cip->profile != new_cip->profile ||
cip->entrypoint != new_cip->entrypoint; cip->entrypoint != new_cip->entrypoint;
if (codec_changed) { if (config_changed) {
gst_vaapi_context_destroy (context);
cip->profile = new_cip->profile; cip->profile = new_cip->profile;
cip->entrypoint = new_cip->entrypoint; cip->entrypoint = new_cip->entrypoint;
} }
if (new_cip->entrypoint == GST_VAAPI_ENTRYPOINT_SLICE_ENCODE) { switch (new_cip->entrypoint) {
rc_mode_changed = cip->rc_mode != cip->rc_mode; case GST_VAAPI_ENTRYPOINT_SLICE_ENCODE:
if (rc_mode_changed) { if (cip->rc_mode != new_cip->rc_mode) {
gst_vaapi_context_destroy (context); cip->rc_mode = new_cip->rc_mode;
cip->rc_mode = new_cip->rc_mode; config_changed = TRUE;
} }
break;
default:
break;
} }
if (size_changed && !gst_vaapi_context_create_surfaces (context)) if (size_changed)
return FALSE; context_destroy_surfaces (context);
if (config_changed)
context_destroy (context);
if (codec_changed && !gst_vaapi_context_create (context)) if (size_changed && !context_create_surfaces (context))
return FALSE;
if (config_changed && !context_create (context))
return FALSE; return FALSE;
return TRUE; return TRUE;
} }
@ -787,83 +677,6 @@ gst_vaapi_context_get_id (GstVaapiContext * context)
return GST_VAAPI_OBJECT_ID (context); return GST_VAAPI_OBJECT_ID (context);
} }
/**
* gst_vaapi_context_get_profile:
* @context: a #GstVaapiContext
*
* Returns the VA profile used by the @context.
*
* Return value: the VA profile used by the @context
*/
GstVaapiProfile
gst_vaapi_context_get_profile (GstVaapiContext * context)
{
g_return_val_if_fail (context != NULL, 0);
return context->info.profile;
}
/**
* gst_vaapi_context_set_profile:
* @context: a #GstVaapiContext
* @profile: the new #GstVaapiProfile to use
*
* Sets the new @profile to use with the @context. If @profile matches
* the previous profile, this call has no effect. Otherwise, the
* underlying VA context is recreated, while keeping the previously
* allocated surfaces.
*
* Return value: %TRUE on success
*/
gboolean
gst_vaapi_context_set_profile (GstVaapiContext * context,
GstVaapiProfile profile)
{
g_return_val_if_fail (context != NULL, FALSE);
g_return_val_if_fail (profile, FALSE);
return gst_vaapi_context_reset (context,
profile,
context->info.entrypoint, context->info.width, context->info.height);
}
/**
* gst_vaapi_context_get_entrypoint:
* @context: a #GstVaapiContext
*
* Returns the VA entrypoint used by the @context
*
* Return value: the VA entrypoint used by the @context
*/
GstVaapiEntrypoint
gst_vaapi_context_get_entrypoint (GstVaapiContext * context)
{
g_return_val_if_fail (context != NULL, 0);
return context->info.entrypoint;
}
/**
* gst_vaapi_context_get_size:
* @context: a #GstVaapiContext
* @pwidth: return location for the width, or %NULL
* @pheight: return location for the height, or %NULL
*
* Retrieves the size of the surfaces attached to @context.
*/
void
gst_vaapi_context_get_size (GstVaapiContext * context,
guint * pwidth, guint * pheight)
{
g_return_if_fail (context != NULL);
if (pwidth)
*pwidth = context->info.width;
if (pheight)
*pheight = context->info.height;
}
/** /**
* gst_vaapi_context_get_surface_proxy: * gst_vaapi_context_get_surface_proxy:
* @context: a #GstVaapiContext * @context: a #GstVaapiContext
@ -885,8 +698,8 @@ gst_vaapi_context_get_surface_proxy (GstVaapiContext * context)
g_return_val_if_fail (context != NULL, NULL); g_return_val_if_fail (context != NULL, NULL);
return return
gst_vaapi_surface_proxy_new_from_pool (GST_VAAPI_SURFACE_POOL (context-> gst_vaapi_surface_proxy_new_from_pool (GST_VAAPI_SURFACE_POOL
surfaces_pool)); (context->surfaces_pool));
} }
/** /**
@ -932,7 +745,7 @@ gst_vaapi_context_apply_composition (GstVaapiContext * context,
return FALSE; return FALSE;
if (!composition) { if (!composition) {
gst_vaapi_context_clear_overlay (context); context_clear_overlay (context);
return TRUE; return TRUE;
} }
@ -970,11 +783,10 @@ gst_vaapi_context_apply_composition (GstVaapiContext * context,
return TRUE; return TRUE;
error: error:
gst_vaapi_context_clear_overlay (context); context_clear_overlay (context);
return FALSE; return FALSE;
} }
/** /**
* gst_vaapi_context_get_attribute: * gst_vaapi_context_get_attribute:
* @context: a #GstVaapiContext * @context: a #GstVaapiContext
@ -1002,11 +814,9 @@ gst_vaapi_context_get_attribute (GstVaapiContext * context,
GST_VAAPI_OBJECT_LOCK_DISPLAY (context); GST_VAAPI_OBJECT_LOCK_DISPLAY (context);
attrib.type = type; attrib.type = type;
status = vaGetConfigAttributes (GST_VAAPI_OBJECT_VADISPLAY (context), status = vaGetConfigAttributes (GST_VAAPI_OBJECT_VADISPLAY (context),
gst_vaapi_profile_get_va_profile (context->info.profile), context->va_profile, context->va_entrypoint, &attrib, 1);
gst_vaapi_entrypoint_get_va_entrypoint (context->info.entrypoint),
&attrib, 1);
GST_VAAPI_OBJECT_UNLOCK_DISPLAY (context); GST_VAAPI_OBJECT_UNLOCK_DISPLAY (context);
if (!vaapi_check_status (status, "vaGetConfiAttributes()")) if (!vaapi_check_status (status, "vaGetConfigAttributes()"))
return FALSE; return FALSE;
if (out_value_ptr) if (out_value_ptr)

View file

@ -1,5 +1,5 @@
/* /*
* gstvaapicontext.h - VA context abstraction * gstvaapicontext.h - VA context abstraction (private)
* *
* Copyright (C) 2010-2011 Splitted-Desktop Systems * Copyright (C) 2010-2011 Splitted-Desktop Systems
* Author: Gwenole Beauchesne <gwenole.beauchesne@splitted-desktop.com> * Author: Gwenole Beauchesne <gwenole.beauchesne@splitted-desktop.com>
@ -25,19 +25,22 @@
#ifndef GST_VAAPI_CONTEXT_H #ifndef GST_VAAPI_CONTEXT_H
#define GST_VAAPI_CONTEXT_H #define GST_VAAPI_CONTEXT_H
#include <gst/vaapi/gstvaapiobject.h>
#include <gst/vaapi/gstvaapiprofile.h>
#include <gst/vaapi/gstvaapidisplay.h>
#include <gst/vaapi/gstvaapisurface.h>
#include <gst/video/video-overlay-composition.h> #include <gst/video/video-overlay-composition.h>
#include "gstvaapiobject.h"
#include "gstvaapiobject_priv.h"
#include "gstvaapiprofile.h"
#include "gstvaapidisplay.h"
#include "gstvaapisurface.h"
#include "gstvaapivideopool.h"
G_BEGIN_DECLS G_BEGIN_DECLS
#define GST_VAAPI_CONTEXT(obj) \ #define GST_VAAPI_CONTEXT(obj) \
((GstVaapiContext *) (obj)) ((GstVaapiContext *) (obj))
typedef struct _GstVaapiContext GstVaapiContext;
typedef struct _GstVaapiContextInfo GstVaapiContextInfo; typedef struct _GstVaapiContextInfo GstVaapiContextInfo;
typedef struct _GstVaapiContext GstVaapiContext;
typedef struct _GstVaapiContextClass GstVaapiContextClass;
/** /**
* GstVaapiContextInfo: * GstVaapiContextInfo:
@ -59,48 +62,51 @@ struct _GstVaapiContextInfo
guint ref_frames; guint ref_frames;
}; };
G_GNUC_INTERNAL /**
GstVaapiContext * * GstVaapiContext:
gst_vaapi_context_new (GstVaapiDisplay * display, GstVaapiProfile profile, *
GstVaapiEntrypoint entrypoint, guint width, guint height); * A VA context wrapper.
*/
struct _GstVaapiContext
{
/*< private >*/
GstVaapiObject parent_instance;
GstVaapiContextInfo info;
VAProfile va_profile;
VAEntrypoint va_entrypoint;
VAConfigID va_config;
GPtrArray *surfaces;
GstVaapiVideoPool *surfaces_pool;
GPtrArray *overlays[2];
guint overlay_id;
};
/**
* GstVaapiContextClass:
*
* A VA context wrapper class.
*/
struct _GstVaapiContextClass
{
/*< private >*/
GstVaapiObjectClass parent_class;
};
G_GNUC_INTERNAL G_GNUC_INTERNAL
GstVaapiContext * GstVaapiContext *
gst_vaapi_context_new_full (GstVaapiDisplay * display, gst_vaapi_context_new (GstVaapiDisplay * display,
const GstVaapiContextInfo * cip); const GstVaapiContextInfo * cip);
G_GNUC_INTERNAL G_GNUC_INTERNAL
gboolean gboolean
gst_vaapi_context_reset (GstVaapiContext * context, GstVaapiProfile profile, gst_vaapi_context_reset (GstVaapiContext * context,
GstVaapiEntrypoint entrypoint, guint width, guint height);
G_GNUC_INTERNAL
gboolean
gst_vaapi_context_reset_full (GstVaapiContext * context,
const GstVaapiContextInfo * new_cip); const GstVaapiContextInfo * new_cip);
G_GNUC_INTERNAL G_GNUC_INTERNAL
GstVaapiID GstVaapiID
gst_vaapi_context_get_id (GstVaapiContext * context); gst_vaapi_context_get_id (GstVaapiContext * context);
G_GNUC_INTERNAL
GstVaapiProfile
gst_vaapi_context_get_profile (GstVaapiContext * context);
G_GNUC_INTERNAL
gboolean
gst_vaapi_context_set_profile (GstVaapiContext * context,
GstVaapiProfile profile);
G_GNUC_INTERNAL
GstVaapiEntrypoint
gst_vaapi_context_get_entrypoint (GstVaapiContext * context);
G_GNUC_INTERNAL
void
gst_vaapi_context_get_size (GstVaapiContext * context,
guint * pwidth, guint * pheight);
G_GNUC_INTERNAL G_GNUC_INTERNAL
GstVaapiSurfaceProxy * GstVaapiSurfaceProxy *
gst_vaapi_context_get_surface_proxy (GstVaapiContext * context); gst_vaapi_context_get_surface_proxy (GstVaapiContext * context);

View file

@ -953,11 +953,11 @@ gst_vaapi_decoder_ensure_context(
gst_vaapi_decoder_set_picture_size(decoder, cip->width, cip->height); gst_vaapi_decoder_set_picture_size(decoder, cip->width, cip->height);
if (decoder->context) { if (decoder->context) {
if (!gst_vaapi_context_reset_full(decoder->context, cip)) if (!gst_vaapi_context_reset(decoder->context, cip))
return FALSE; return FALSE;
} }
else { else {
decoder->context = gst_vaapi_context_new_full(decoder->display, cip); decoder->context = gst_vaapi_context_new(decoder->display, cip);
if (!decoder->context) if (!decoder->context)
return FALSE; return FALSE;
} }

View file

@ -501,10 +501,10 @@ gst_vaapi_encoder_ensure_context (GstVaapiEncoder * encoder)
set_context_info (encoder); set_context_info (encoder);
if (encoder->context) { if (encoder->context) {
if (!gst_vaapi_context_reset_full (encoder->context, cip)) if (!gst_vaapi_context_reset (encoder->context, cip))
return FALSE; return FALSE;
} else { } else {
encoder->context = gst_vaapi_context_new_full (encoder->display, cip); encoder->context = gst_vaapi_context_new (encoder->display, cip);
if (!encoder->context) if (!encoder->context)
return FALSE; return FALSE;
} }