context: re-indent all GstVaapiContext related source code.

This commit is contained in:
Gwenole Beauchesne 2014-01-23 09:27:38 +01:00
parent c5bdeb6980
commit 1ffdc010ad
2 changed files with 584 additions and 629 deletions

View file

@ -51,7 +51,8 @@ typedef struct _GstVaapiContextClass GstVaapiContextClass;
* *
* A VA context wrapper. * A VA context wrapper.
*/ */
struct _GstVaapiContext { struct _GstVaapiContext
{
/*< private >*/ /*< private >*/
GstVaapiObject parent_instance; GstVaapiObject parent_instance;
@ -68,13 +69,15 @@ struct _GstVaapiContext {
* *
* A VA context wrapper class. * A VA context wrapper class.
*/ */
struct _GstVaapiContextClass { struct _GstVaapiContextClass
{
/*< private >*/ /*< private >*/
GstVaapiObjectClass parent_class; GstVaapiObjectClass parent_class;
}; };
typedef struct _GstVaapiOverlayRectangle GstVaapiOverlayRectangle; typedef struct _GstVaapiOverlayRectangle GstVaapiOverlayRectangle;
struct _GstVaapiOverlayRectangle { struct _GstVaapiOverlayRectangle
{
GstVaapiContext *context; GstVaapiContext *context;
GstVaapiSubpicture *subpicture; GstVaapiSubpicture *subpicture;
GstVaapiRectangle render_rect; GstVaapiRectangle render_rect;
@ -91,9 +94,15 @@ get_max_ref_frames(GstVaapiProfile profile)
guint ref_frames; guint ref_frames;
switch (gst_vaapi_profile_get_codec (profile)) { switch (gst_vaapi_profile_get_codec (profile)) {
case GST_VAAPI_CODEC_H264: ref_frames = 16; break; case GST_VAAPI_CODEC_H264:
case GST_VAAPI_CODEC_JPEG: ref_frames = 0; break; ref_frames = 16;
default: ref_frames = 2; break; break;
case GST_VAAPI_CODEC_JPEG:
ref_frames = 0;
break;
default:
ref_frames = 2;
break;
} }
return ref_frames; return ref_frames;
} }
@ -116,8 +125,7 @@ gst_video_overlay_rectangle_replace(GstVideoOverlayRectangle **old_rect_ptr,
gst_vaapi_mini_object_replace((GstVaapiMiniObject **)(old_overlay_ptr), \ gst_vaapi_mini_object_replace((GstVaapiMiniObject **)(old_overlay_ptr), \
(GstVaapiMiniObject *)(new_overlay)) (GstVaapiMiniObject *)(new_overlay))
static void static void overlay_rectangle_finalize (GstVaapiOverlayRectangle * overlay);
overlay_rectangle_finalize(GstVaapiOverlayRectangle *overlay);
static gboolean static gboolean
overlay_rectangle_associate (GstVaapiOverlayRectangle * overlay); overlay_rectangle_associate (GstVaapiOverlayRectangle * overlay);
@ -136,8 +144,8 @@ overlay_rectangle_class(void)
} }
static GstVaapiOverlayRectangle * static GstVaapiOverlayRectangle *
overlay_rectangle_new(GstVideoOverlayRectangle *rect, GstVaapiContext *context, overlay_rectangle_new (GstVideoOverlayRectangle * rect,
guint layer_id) GstVaapiContext * context, guint layer_id)
{ {
GstVaapiOverlayRectangle *overlay; GstVaapiOverlayRectangle *overlay;
GstVaapiRectangle *render_rect; GstVaapiRectangle *render_rect;
@ -160,8 +168,9 @@ overlay_rectangle_new(GstVideoOverlayRectangle *rect, GstVaapiContext *context,
if (!overlay->rect_buffer) if (!overlay->rect_buffer)
goto error; goto error;
overlay->subpicture = gst_vaapi_subpicture_new_from_overlay_rectangle( overlay->subpicture =
GST_VAAPI_OBJECT_DISPLAY(context), rect); gst_vaapi_subpicture_new_from_overlay_rectangle (GST_VAAPI_OBJECT_DISPLAY
(context), rect);
if (!overlay->subpicture) if (!overlay->subpicture)
goto error; goto error;
@ -245,8 +254,9 @@ overlay_rectangle_changed_pixels(GstVaapiOverlayRectangle *overlay,
if (overlay->seq_num == gst_video_overlay_rectangle_get_seqnum (rect)) if (overlay->seq_num == gst_video_overlay_rectangle_get_seqnum (rect))
return FALSE; return FALSE;
flags = to_GstVideoOverlayFormatFlags( flags =
gst_vaapi_subpicture_get_flags(overlay->subpicture)); to_GstVideoOverlayFormatFlags (gst_vaapi_subpicture_get_flags
(overlay->subpicture));
buffer = gst_video_overlay_rectangle_get_pixels_unscaled_raw (rect, flags); buffer = gst_video_overlay_rectangle_get_pixels_unscaled_raw (rect, flags);
if (!buffer) if (!buffer)
@ -265,8 +275,7 @@ overlay_rectangle_changed_pixels(GstVaapiOverlayRectangle *overlay,
for (i = 0; i < n_blocks; i++) { for (i = 0; i < n_blocks; i++) {
GstMemory *const mem1 = gst_buffer_peek_memory (buffer, i); GstMemory *const mem1 = gst_buffer_peek_memory (buffer, i);
GstMemory * const mem2 = GstMemory *const mem2 = gst_buffer_peek_memory (overlay->rect_buffer, i);
gst_buffer_peek_memory(overlay->rect_buffer, i);
if (!gst_memory_is_span (mem1, mem2, &ofs)) if (!gst_memory_is_span (mem1, mem2, &ofs))
return FALSE; return FALSE;
} }
@ -291,8 +300,7 @@ overlay_rectangle_changed_render_rect(GstVaapiOverlayRectangle *overlay,
if (x == render_rect->x && if (x == render_rect->x &&
y == render_rect->y && y == render_rect->y &&
width == render_rect->width && width == render_rect->width && height == render_rect->height)
height == render_rect->height)
return FALSE; return FALSE;
render_rect->x = x; render_rect->x = x;
@ -360,8 +368,7 @@ overlay_lookup(GPtrArray *overlays, GstVideoOverlayRectangle *rect)
guint i; guint i;
for (i = 0; i < overlays->len; i++) { for (i = 0; i < overlays->len; i++) {
GstVaapiOverlayRectangle * const overlay = GstVaapiOverlayRectangle *const overlay = g_ptr_array_index (overlays, i);
g_ptr_array_index(overlays, i);
if (overlay->rect == rect) if (overlay->rect == rect)
return overlay; return overlay;
@ -432,10 +439,8 @@ gst_vaapi_context_destroy(GstVaapiContext *context)
if (context_id != VA_INVALID_ID) { if (context_id != VA_INVALID_ID) {
GST_VAAPI_DISPLAY_LOCK (display); GST_VAAPI_DISPLAY_LOCK (display);
status = vaDestroyContext( status = vaDestroyContext (GST_VAAPI_DISPLAY_VADISPLAY (display),
GST_VAAPI_DISPLAY_VADISPLAY(display), 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, g_warning ("failed to destroy context %" GST_VAAPI_ID_FORMAT,
@ -445,10 +450,8 @@ gst_vaapi_context_destroy(GstVaapiContext *context)
if (context->config_id != VA_INVALID_ID) { if (context->config_id != VA_INVALID_ID) {
GST_VAAPI_DISPLAY_LOCK (display); GST_VAAPI_DISPLAY_LOCK (display);
status = vaDestroyConfig( status = vaDestroyConfig (GST_VAAPI_DISPLAY_VADISPLAY (display),
GST_VAAPI_DISPLAY_VADISPLAY(display), context->config_id);
context->config_id
);
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, g_warning ("failed to destroy config %" GST_VAAPI_ID_FORMAT,
@ -490,8 +493,8 @@ gst_vaapi_context_create_surfaces(GstVaapiContext *context)
if (!context->surfaces_pool) { if (!context->surfaces_pool) {
gst_video_info_set_format (&vi, GST_VIDEO_FORMAT_ENCODED, gst_video_info_set_format (&vi, GST_VIDEO_FORMAT_ENCODED,
cip->width, cip->height); cip->width, cip->height);
context->surfaces_pool = gst_vaapi_surface_pool_new( context->surfaces_pool =
GST_VAAPI_OBJECT_DISPLAY(context), &vi); gst_vaapi_surface_pool_new (GST_VAAPI_OBJECT_DISPLAY (context), &vi);
if (!context->surfaces_pool) if (!context->surfaces_pool)
return FALSE; return FALSE;
} }
@ -500,11 +503,8 @@ gst_vaapi_context_create_surfaces(GstVaapiContext *context)
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++) {
surface = gst_vaapi_surface_new( surface = gst_vaapi_surface_new (GST_VAAPI_OBJECT_DISPLAY (context),
GST_VAAPI_OBJECT_DISPLAY(context), GST_VAAPI_CHROMA_TYPE_YUV420, cip->width, cip->height);
GST_VAAPI_CHROMA_TYPE_YUV420,
cip->width, cip->height
);
if (!surface) if (!surface)
return FALSE; return FALSE;
gst_vaapi_surface_set_parent_context (surface, context); gst_vaapi_surface_set_parent_context (surface, context);
@ -535,18 +535,13 @@ gst_vaapi_context_create(GstVaapiContext *context)
if (!context->surfaces && !gst_vaapi_context_create_surfaces (context)) if (!context->surfaces && !gst_vaapi_context_create_surfaces (context))
goto end; goto end;
surfaces = g_array_sized_new( surfaces = g_array_sized_new (FALSE,
FALSE, FALSE, sizeof (VASurfaceID), context->surfaces->len);
FALSE,
sizeof(VASurfaceID),
context->surfaces->len
);
if (!surfaces) if (!surfaces)
goto end; goto end;
for (i = 0; i < context->surfaces->len; i++) { for (i = 0; i < context->surfaces->len; i++) {
GstVaapiSurface * const surface = GstVaapiSurface *const surface = g_ptr_array_index (context->surfaces, i);
g_ptr_array_index(context->surfaces, i);
if (!surface) if (!surface)
goto end; goto end;
surface_id = GST_VAAPI_OBJECT_ID (surface); surface_id = GST_VAAPI_OBJECT_ID (surface);
@ -565,12 +560,8 @@ gst_vaapi_context_create(GstVaapiContext *context)
attribs[num_attribs++].type = VAConfigAttribRateControl; attribs[num_attribs++].type = VAConfigAttribRateControl;
GST_VAAPI_DISPLAY_LOCK (display); GST_VAAPI_DISPLAY_LOCK (display);
status = vaGetConfigAttributes( status = vaGetConfigAttributes (GST_VAAPI_DISPLAY_VADISPLAY (display),
GST_VAAPI_DISPLAY_VADISPLAY(display), va_profile, va_entrypoint, attribs, num_attribs);
va_profile,
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 end;
@ -590,26 +581,18 @@ gst_vaapi_context_create(GstVaapiContext *context)
} }
GST_VAAPI_DISPLAY_LOCK (display); GST_VAAPI_DISPLAY_LOCK (display);
status = vaCreateConfig( status = vaCreateConfig (GST_VAAPI_DISPLAY_VADISPLAY (display),
GST_VAAPI_DISPLAY_VADISPLAY(display), va_profile, va_entrypoint, attribs, num_attribs, &context->config_id);
va_profile,
va_entrypoint,
attribs, num_attribs,
&context->config_id
);
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 end;
GST_VAAPI_DISPLAY_LOCK (display); GST_VAAPI_DISPLAY_LOCK (display);
status = vaCreateContext( status = vaCreateContext (GST_VAAPI_DISPLAY_VADISPLAY (display),
GST_VAAPI_DISPLAY_VADISPLAY(display),
context->config_id, context->config_id,
cip->width, cip->height, cip->width, cip->height,
VA_PROGRESSIVE, VA_PROGRESSIVE,
(VASurfaceID *)surfaces->data, surfaces->len, (VASurfaceID *) surfaces->data, surfaces->len, &context_id);
&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 end;
@ -624,7 +607,8 @@ end:
} }
static inline void static inline void
gst_vaapi_context_init(GstVaapiContext *context, const GstVaapiContextInfo *cip) gst_vaapi_context_init (GstVaapiContext * context,
const GstVaapiContextInfo * cip)
{ {
context->info = *cip; context->info = *cip;
context->config_id = VA_INVALID_ID; context->config_id = VA_INVALID_ID;
@ -656,14 +640,9 @@ 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 (GstVaapiDisplay * display,
gst_vaapi_context_new(
GstVaapiDisplay *display,
GstVaapiProfile profile, GstVaapiProfile profile,
GstVaapiEntrypoint entrypoint, GstVaapiEntrypoint entrypoint, guint width, guint height)
guint width,
guint height
)
{ {
GstVaapiContextInfo info; GstVaapiContextInfo info;
@ -726,13 +705,9 @@ error:
* Return value: %TRUE on success * Return value: %TRUE on success
*/ */
gboolean gboolean
gst_vaapi_context_reset( gst_vaapi_context_reset (GstVaapiContext * context,
GstVaapiContext *context,
GstVaapiProfile profile, GstVaapiProfile profile,
GstVaapiEntrypoint entrypoint, GstVaapiEntrypoint entrypoint, unsigned int width, unsigned int height)
unsigned int width,
unsigned int height
)
{ {
GstVaapiContextInfo info; GstVaapiContextInfo info;
@ -764,8 +739,7 @@ gst_vaapi_context_reset_full(GstVaapiContext *context,
GstVaapiContextInfo *const cip = &context->info; GstVaapiContextInfo *const cip = &context->info;
gboolean size_changed, codec_changed, rc_mode_changed; gboolean size_changed, codec_changed, rc_mode_changed;
size_changed = cip->width != new_cip->width || size_changed = cip->width != new_cip->width || cip->height != new_cip->height;
cip->height != new_cip->height;
if (size_changed) { if (size_changed) {
gst_vaapi_context_destroy_surfaces (context); gst_vaapi_context_destroy_surfaces (context);
cip->width = new_cip->width; cip->width = new_cip->width;
@ -842,16 +816,15 @@ gst_vaapi_context_get_profile(GstVaapiContext *context)
* Return value: %TRUE on success * Return value: %TRUE on success
*/ */
gboolean gboolean
gst_vaapi_context_set_profile(GstVaapiContext *context, GstVaapiProfile profile) gst_vaapi_context_set_profile (GstVaapiContext * context,
GstVaapiProfile profile)
{ {
g_return_val_if_fail (context != NULL, FALSE); g_return_val_if_fail (context != NULL, FALSE);
g_return_val_if_fail (profile, FALSE); g_return_val_if_fail (profile, FALSE);
return gst_vaapi_context_reset (context, return gst_vaapi_context_reset (context,
profile, profile,
context->info.entrypoint, context->info.entrypoint, context->info.width, context->info.height);
context->info.width,
context->info.height);
} }
/** /**
@ -879,11 +852,8 @@ gst_vaapi_context_get_entrypoint(GstVaapiContext *context)
* Retrieves the size of the surfaces attached to @context. * Retrieves the size of the surfaces attached to @context.
*/ */
void void
gst_vaapi_context_get_size( gst_vaapi_context_get_size (GstVaapiContext * context,
GstVaapiContext *context, guint * pwidth, guint * pheight)
guint *pwidth,
guint *pheight
)
{ {
g_return_if_fail (context != NULL); g_return_if_fail (context != NULL);
@ -914,8 +884,9 @@ 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 gst_vaapi_surface_proxy_new_from_pool( return
GST_VAAPI_SURFACE_POOL(context->surfaces_pool)); gst_vaapi_surface_proxy_new_from_pool (GST_VAAPI_SURFACE_POOL (context->
surfaces_pool));
} }
/** /**
@ -948,10 +919,8 @@ gst_vaapi_context_get_surface_count(GstVaapiContext *context)
* %FALSE otherwise * %FALSE otherwise
*/ */
gboolean gboolean
gst_vaapi_context_apply_composition( gst_vaapi_context_apply_composition (GstVaapiContext * context,
GstVaapiContext *context, GstVideoOverlayComposition * composition)
GstVideoOverlayComposition *composition
)
{ {
GPtrArray *curr_overlay, *next_overlay; GPtrArray *curr_overlay, *next_overlay;
guint i, n_rectangles; guint i, n_rectangles;
@ -982,8 +951,7 @@ gst_vaapi_context_apply_composition(
overlay_rectangle_ref (overlay); overlay_rectangle_ref (overlay);
if (overlay->layer_id != i) if (overlay->layer_id != i)
reassociate = TRUE; reassociate = TRUE;
} } else {
else {
overlay = overlay_rectangle_new (rect, context, i); overlay = overlay_rectangle_new (rect, context, i);
if (!overlay) { if (!overlay) {
GST_WARNING ("could not create VA overlay rectangle"); GST_WARNING ("could not create VA overlay rectangle");

View file

@ -49,7 +49,8 @@ typedef struct _GstVaapiContextInfo GstVaapiContextInfo;
* Note: @rc_mode is only valid for VA context used for encoding, * Note: @rc_mode is only valid for VA context used for encoding,
* i.e. if @entrypoint is set to @GST_VAAPI_ENTRYPOINT_SLICE_ENCODE. * i.e. if @entrypoint is set to @GST_VAAPI_ENTRYPOINT_SLICE_ENCODE.
*/ */
struct _GstVaapiContextInfo { struct _GstVaapiContextInfo
{
GstVaapiProfile profile; GstVaapiProfile profile;
GstVaapiEntrypoint entrypoint; GstVaapiEntrypoint entrypoint;
GstVaapiRateControl rc_mode; GstVaapiRateControl rc_mode;
@ -60,13 +61,8 @@ struct _GstVaapiContextInfo {
G_GNUC_INTERNAL G_GNUC_INTERNAL
GstVaapiContext * GstVaapiContext *
gst_vaapi_context_new( gst_vaapi_context_new (GstVaapiDisplay * display, GstVaapiProfile profile,
GstVaapiDisplay *display, GstVaapiEntrypoint entrypoint, guint width, guint height);
GstVaapiProfile profile,
GstVaapiEntrypoint entrypoint,
guint width,
guint height
);
G_GNUC_INTERNAL G_GNUC_INTERNAL
GstVaapiContext * GstVaapiContext *
@ -75,13 +71,8 @@ gst_vaapi_context_new_full(GstVaapiDisplay *display,
G_GNUC_INTERNAL G_GNUC_INTERNAL
gboolean gboolean
gst_vaapi_context_reset( gst_vaapi_context_reset (GstVaapiContext * context, GstVaapiProfile profile,
GstVaapiContext *context, GstVaapiEntrypoint entrypoint, guint width, guint height);
GstVaapiProfile profile,
GstVaapiEntrypoint entrypoint,
guint width,
guint height
);
G_GNUC_INTERNAL G_GNUC_INTERNAL
gboolean gboolean
@ -98,7 +89,8 @@ gst_vaapi_context_get_profile(GstVaapiContext *context);
G_GNUC_INTERNAL G_GNUC_INTERNAL
gboolean gboolean
gst_vaapi_context_set_profile(GstVaapiContext *context, GstVaapiProfile profile); gst_vaapi_context_set_profile (GstVaapiContext * context,
GstVaapiProfile profile);
G_GNUC_INTERNAL G_GNUC_INTERNAL
GstVaapiEntrypoint GstVaapiEntrypoint
@ -106,11 +98,8 @@ gst_vaapi_context_get_entrypoint(GstVaapiContext *context);
G_GNUC_INTERNAL G_GNUC_INTERNAL
void void
gst_vaapi_context_get_size( gst_vaapi_context_get_size (GstVaapiContext * context,
GstVaapiContext *context, guint * pwidth, guint * pheight);
guint *pwidth,
guint *pheight
);
G_GNUC_INTERNAL G_GNUC_INTERNAL
GstVaapiSurfaceProxy * GstVaapiSurfaceProxy *
@ -122,10 +111,8 @@ gst_vaapi_context_get_surface_count(GstVaapiContext *context);
G_GNUC_INTERNAL G_GNUC_INTERNAL
gboolean gboolean
gst_vaapi_context_apply_composition( gst_vaapi_context_apply_composition (GstVaapiContext * context,
GstVaapiContext *context, GstVideoOverlayComposition * composition);
GstVideoOverlayComposition *composition
);
G_GNUC_INTERNAL G_GNUC_INTERNAL
gboolean gboolean