libs: humongous code style fix

As part of the upstreaming process of gstreamer-vaapi into the GStreamer
umbrella, we need to comply with the project's code style. This meant to
change a lot of code.

It was decided to use a single massive patch to update the code style.

I would like to apologize with the original developers of this code because of
the history breakage.

Signed-off-by: Víctor Manuel Jáquez Leal <victorx.jaquez@intel.com>
This commit is contained in:
Víctor Manuel Jáquez Leal 2016-02-03 11:50:13 +01:00
parent 4b5be5973e
commit ac730d0a62
13 changed files with 8565 additions and 8730 deletions

View file

@ -37,14 +37,15 @@
* *
* A decoded picture buffer (DPB) object. * A decoded picture buffer (DPB) object.
*/ */
struct _GstVaapiDpb { struct _GstVaapiDpb
/*< private >*/ {
GstVaapiMiniObject parent_instance; /*< private > */
GstVaapiMiniObject parent_instance;
/*< protected >*/ /*< protected > */
GstVaapiPicture **pictures; GstVaapiPicture **pictures;
guint num_pictures; guint num_pictures;
guint max_pictures; guint max_pictures;
}; };
/** /**
@ -52,124 +53,123 @@ struct _GstVaapiDpb {
* *
* The #GstVaapiDpb base class. * The #GstVaapiDpb base class.
*/ */
struct _GstVaapiDpbClass { struct _GstVaapiDpbClass
/*< private >*/ {
GstVaapiMiniObjectClass parent_class; /*< private > */
GstVaapiMiniObjectClass parent_class;
/*< protected >*/ /*< protected > */
void (*flush) (GstVaapiDpb *dpb); void (*flush) (GstVaapiDpb * dpb);
gboolean (*add) (GstVaapiDpb *dpb, GstVaapiPicture *picture); gboolean (*add) (GstVaapiDpb * dpb, GstVaapiPicture * picture);
void (*get_neighbours) (GstVaapiDpb *dpb, GstVaapiPicture *picture, void (*get_neighbours) (GstVaapiDpb * dpb, GstVaapiPicture * picture,
GstVaapiPicture **prev_picture_ptr, GstVaapiPicture **next_picture_ptr); GstVaapiPicture ** prev_picture_ptr, GstVaapiPicture ** next_picture_ptr);
}; };
static const GstVaapiMiniObjectClass * static const GstVaapiMiniObjectClass *gst_vaapi_dpb_class (void);
gst_vaapi_dpb_class(void);
static const GstVaapiMiniObjectClass * static const GstVaapiMiniObjectClass *gst_vaapi_dpb2_class (void);
gst_vaapi_dpb2_class(void);
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
/* --- Common utilities --- */ /* --- Common utilities --- */
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
static inline GstVaapiDpb * static inline GstVaapiDpb *
dpb_new(guint max_pictures) dpb_new (guint max_pictures)
{ {
GstVaapiDpb *dpb; GstVaapiDpb *dpb;
g_return_val_if_fail(max_pictures > 0, NULL); g_return_val_if_fail (max_pictures > 0, NULL);
dpb = (GstVaapiDpb *)gst_vaapi_mini_object_new( dpb =
max_pictures == 2 ? gst_vaapi_dpb2_class() : gst_vaapi_dpb_class()); (GstVaapiDpb *) gst_vaapi_mini_object_new (max_pictures ==
if (!dpb) 2 ? gst_vaapi_dpb2_class () : gst_vaapi_dpb_class ());
return NULL; if (!dpb)
return NULL;
dpb->num_pictures = 0; dpb->num_pictures = 0;
dpb->max_pictures = max_pictures; dpb->max_pictures = max_pictures;
dpb->pictures = g_new0(GstVaapiPicture *, max_pictures); dpb->pictures = g_new0 (GstVaapiPicture *, max_pictures);
if (!dpb->pictures) if (!dpb->pictures)
goto error; goto error;
return dpb; return dpb;
error: error:
gst_vaapi_dpb_unref(dpb); gst_vaapi_dpb_unref (dpb);
return NULL; return NULL;
} }
static gint static gint
dpb_get_oldest(GstVaapiDpb *dpb, gboolean output) dpb_get_oldest (GstVaapiDpb * dpb, gboolean output)
{ {
gint i, lowest_pts_index; gint i, lowest_pts_index;
for (i = 0; i < dpb->num_pictures; i++) { for (i = 0; i < dpb->num_pictures; i++) {
if ((GST_VAAPI_PICTURE_IS_OUTPUT(dpb->pictures[i]) ^ output) == 0) if ((GST_VAAPI_PICTURE_IS_OUTPUT (dpb->pictures[i]) ^ output) == 0)
break; break;
} }
if (i == dpb->num_pictures) if (i == dpb->num_pictures)
return -1; return -1;
lowest_pts_index = i++; lowest_pts_index = i++;
for (; i < dpb->num_pictures; i++) { for (; i < dpb->num_pictures; i++) {
GstVaapiPicture * const picture = dpb->pictures[i]; GstVaapiPicture *const picture = dpb->pictures[i];
if ((GST_VAAPI_PICTURE_IS_OUTPUT(picture) ^ output) != 0) if ((GST_VAAPI_PICTURE_IS_OUTPUT (picture) ^ output) != 0)
continue; continue;
if (picture->poc < dpb->pictures[lowest_pts_index]->poc) if (picture->poc < dpb->pictures[lowest_pts_index]->poc)
lowest_pts_index = i; lowest_pts_index = i;
} }
return lowest_pts_index; return lowest_pts_index;
} }
static void static void
dpb_remove_index(GstVaapiDpb *dpb, guint index) dpb_remove_index (GstVaapiDpb * dpb, guint index)
{ {
GstVaapiPicture ** const pictures = dpb->pictures; GstVaapiPicture **const pictures = dpb->pictures;
guint num_pictures = --dpb->num_pictures; guint num_pictures = --dpb->num_pictures;
if (index != num_pictures) if (index != num_pictures)
gst_vaapi_picture_replace(&pictures[index], pictures[num_pictures]); gst_vaapi_picture_replace (&pictures[index], pictures[num_pictures]);
gst_vaapi_picture_replace(&pictures[num_pictures], NULL); gst_vaapi_picture_replace (&pictures[num_pictures], NULL);
} }
static inline gboolean static inline gboolean
dpb_output(GstVaapiDpb *dpb, GstVaapiPicture *picture) dpb_output (GstVaapiDpb * dpb, GstVaapiPicture * picture)
{ {
return gst_vaapi_picture_output(picture); return gst_vaapi_picture_output (picture);
} }
static gboolean static gboolean
dpb_bump(GstVaapiDpb *dpb) dpb_bump (GstVaapiDpb * dpb)
{ {
gint index; gint index;
gboolean success; gboolean success;
index = dpb_get_oldest(dpb, FALSE); index = dpb_get_oldest (dpb, FALSE);
if (index < 0) if (index < 0)
return FALSE; return FALSE;
success = dpb_output(dpb, dpb->pictures[index]); success = dpb_output (dpb, dpb->pictures[index]);
if (!GST_VAAPI_PICTURE_IS_REFERENCE(dpb->pictures[index])) if (!GST_VAAPI_PICTURE_IS_REFERENCE (dpb->pictures[index]))
dpb_remove_index(dpb, index); dpb_remove_index (dpb, index);
return success; return success;
} }
static void static void
dpb_clear(GstVaapiDpb *dpb) dpb_clear (GstVaapiDpb * dpb)
{ {
guint i; guint i;
for (i = 0; i < dpb->num_pictures; i++) for (i = 0; i < dpb->num_pictures; i++)
gst_vaapi_picture_replace(&dpb->pictures[i], NULL); gst_vaapi_picture_replace (&dpb->pictures[i], NULL);
dpb->num_pictures = 0; dpb->num_pictures = 0;
} }
static void static void
dpb_flush(GstVaapiDpb *dpb) dpb_flush (GstVaapiDpb * dpb)
{ {
while (dpb_bump(dpb)) while (dpb_bump (dpb));
; dpb_clear (dpb);
dpb_clear(dpb);
} }
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
@ -177,82 +177,80 @@ dpb_flush(GstVaapiDpb *dpb)
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
static gboolean static gboolean
dpb_add(GstVaapiDpb *dpb, GstVaapiPicture *picture) dpb_add (GstVaapiDpb * dpb, GstVaapiPicture * picture)
{ {
guint i; guint i;
// Remove all unused pictures // Remove all unused pictures
i = 0; i = 0;
while (i < dpb->num_pictures) { while (i < dpb->num_pictures) {
GstVaapiPicture * const picture = dpb->pictures[i]; GstVaapiPicture *const picture = dpb->pictures[i];
if (GST_VAAPI_PICTURE_IS_OUTPUT(picture) && if (GST_VAAPI_PICTURE_IS_OUTPUT (picture) &&
!GST_VAAPI_PICTURE_IS_REFERENCE(picture)) !GST_VAAPI_PICTURE_IS_REFERENCE (picture))
dpb_remove_index(dpb, i); dpb_remove_index (dpb, i);
else else
i++; i++;
} }
// Store reference decoded picture into the DPB // Store reference decoded picture into the DPB
if (GST_VAAPI_PICTURE_IS_REFERENCE(picture)) { if (GST_VAAPI_PICTURE_IS_REFERENCE (picture)) {
while (dpb->num_pictures == dpb->max_pictures) { while (dpb->num_pictures == dpb->max_pictures) {
if (!dpb_bump(dpb)) if (!dpb_bump (dpb))
return FALSE; return FALSE;
}
} }
}
// Store non-reference decoded picture into the DPB // Store non-reference decoded picture into the DPB
else { else {
if (GST_VAAPI_PICTURE_IS_SKIPPED(picture)) if (GST_VAAPI_PICTURE_IS_SKIPPED (picture))
return TRUE; return TRUE;
while (dpb->num_pictures == dpb->max_pictures) { while (dpb->num_pictures == dpb->max_pictures) {
for (i = 0; i < dpb->num_pictures; i++) { for (i = 0; i < dpb->num_pictures; i++) {
if (!GST_VAAPI_PICTURE_IS_OUTPUT(picture) && if (!GST_VAAPI_PICTURE_IS_OUTPUT (picture) &&
dpb->pictures[i]->poc < picture->poc) dpb->pictures[i]->poc < picture->poc)
break; break;
} }
if (i == dpb->num_pictures) if (i == dpb->num_pictures)
return dpb_output(dpb, picture); return dpb_output (dpb, picture);
if (!dpb_bump(dpb)) if (!dpb_bump (dpb))
return FALSE; return FALSE;
}
} }
gst_vaapi_picture_replace(&dpb->pictures[dpb->num_pictures++], picture); }
return TRUE; gst_vaapi_picture_replace (&dpb->pictures[dpb->num_pictures++], picture);
return TRUE;
} }
static void static void
dpb_get_neighbours(GstVaapiDpb *dpb, GstVaapiPicture *picture, dpb_get_neighbours (GstVaapiDpb * dpb, GstVaapiPicture * picture,
GstVaapiPicture **prev_picture_ptr, GstVaapiPicture **next_picture_ptr) GstVaapiPicture ** prev_picture_ptr, GstVaapiPicture ** next_picture_ptr)
{ {
GstVaapiPicture *prev_picture = NULL; GstVaapiPicture *prev_picture = NULL;
GstVaapiPicture *next_picture = NULL; GstVaapiPicture *next_picture = NULL;
guint i; guint i;
/* Find the first picture with POC > specified picture POC */ /* Find the first picture with POC > specified picture POC */
for (i = 0; i < dpb->num_pictures; i++) { for (i = 0; i < dpb->num_pictures; i++) {
GstVaapiPicture * const ref_picture = dpb->pictures[i]; GstVaapiPicture *const ref_picture = dpb->pictures[i];
if (ref_picture->poc == picture->poc) { if (ref_picture->poc == picture->poc) {
if (i > 0) if (i > 0)
prev_picture = dpb->pictures[i - 1]; prev_picture = dpb->pictures[i - 1];
if (i + 1 < dpb->num_pictures) if (i + 1 < dpb->num_pictures)
next_picture = dpb->pictures[i + 1]; next_picture = dpb->pictures[i + 1];
break; break;
} } else if (ref_picture->poc > picture->poc) {
else if (ref_picture->poc > picture->poc) { next_picture = ref_picture;
next_picture = ref_picture; if (i > 0)
if (i > 0) prev_picture = dpb->pictures[i - 1];
prev_picture = dpb->pictures[i - 1]; break;
break;
}
} }
}
g_assert(next_picture ? next_picture->poc > picture->poc : TRUE); g_assert (next_picture ? next_picture->poc > picture->poc : TRUE);
g_assert(prev_picture ? prev_picture->poc < picture->poc : TRUE); g_assert (prev_picture ? prev_picture->poc < picture->poc : TRUE);
if (prev_picture_ptr) if (prev_picture_ptr)
*prev_picture_ptr = prev_picture; *prev_picture_ptr = prev_picture;
if (next_picture_ptr) if (next_picture_ptr)
*next_picture_ptr = next_picture; *next_picture_ptr = next_picture;
} }
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
@ -260,66 +258,66 @@ dpb_get_neighbours(GstVaapiDpb *dpb, GstVaapiPicture *picture,
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
static gboolean static gboolean
dpb2_add(GstVaapiDpb *dpb, GstVaapiPicture *picture) dpb2_add (GstVaapiDpb * dpb, GstVaapiPicture * picture)
{ {
GstVaapiPicture *ref_picture; GstVaapiPicture *ref_picture;
gint index = -1; gint index = -1;
g_return_val_if_fail(GST_VAAPI_IS_DPB(dpb), FALSE); g_return_val_if_fail (GST_VAAPI_IS_DPB (dpb), FALSE);
g_return_val_if_fail(dpb->max_pictures == 2, FALSE); g_return_val_if_fail (dpb->max_pictures == 2, FALSE);
/* /*
* Purpose: only store reference decoded pictures into the DPB * Purpose: only store reference decoded pictures into the DPB
* *
* This means: * This means:
* - non-reference decoded pictures are output immediately * - non-reference decoded pictures are output immediately
* - ... thus causing older reference pictures to be output, if not already * - ... thus causing older reference pictures to be output, if not already
* - the oldest reference picture is replaced with the new reference picture * - the oldest reference picture is replaced with the new reference picture
*/ */
if (G_LIKELY(dpb->num_pictures == 2)) { if (G_LIKELY (dpb->num_pictures == 2)) {
index = (dpb->pictures[0]->poc > dpb->pictures[1]->poc); index = (dpb->pictures[0]->poc > dpb->pictures[1]->poc);
ref_picture = dpb->pictures[index]; ref_picture = dpb->pictures[index];
if (!GST_VAAPI_PICTURE_IS_OUTPUT(ref_picture)) { if (!GST_VAAPI_PICTURE_IS_OUTPUT (ref_picture)) {
if (!dpb_output(dpb, ref_picture)) if (!dpb_output (dpb, ref_picture))
return FALSE; return FALSE;
}
} }
}
if (!GST_VAAPI_PICTURE_IS_REFERENCE(picture)) if (!GST_VAAPI_PICTURE_IS_REFERENCE (picture))
return dpb_output(dpb, picture); return dpb_output (dpb, picture);
if (index < 0) if (index < 0)
index = dpb->num_pictures++; index = dpb->num_pictures++;
gst_vaapi_picture_replace(&dpb->pictures[index], picture); gst_vaapi_picture_replace (&dpb->pictures[index], picture);
return TRUE; return TRUE;
} }
static void static void
dpb2_get_neighbours(GstVaapiDpb *dpb, GstVaapiPicture *picture, dpb2_get_neighbours (GstVaapiDpb * dpb, GstVaapiPicture * picture,
GstVaapiPicture **prev_picture_ptr, GstVaapiPicture **next_picture_ptr) GstVaapiPicture ** prev_picture_ptr, GstVaapiPicture ** next_picture_ptr)
{ {
GstVaapiPicture *ref_picture, *ref_pictures[2]; GstVaapiPicture *ref_picture, *ref_pictures[2];
GstVaapiPicture **picture_ptr; GstVaapiPicture **picture_ptr;
guint i, index; guint i, index;
g_return_if_fail(GST_VAAPI_IS_DPB(dpb)); g_return_if_fail (GST_VAAPI_IS_DPB (dpb));
g_return_if_fail(dpb->max_pictures == 2); g_return_if_fail (dpb->max_pictures == 2);
g_return_if_fail(GST_VAAPI_IS_PICTURE(picture)); g_return_if_fail (GST_VAAPI_IS_PICTURE (picture));
ref_pictures[0] = NULL; ref_pictures[0] = NULL;
ref_pictures[1] = NULL; ref_pictures[1] = NULL;
for (i = 0; i < dpb->num_pictures; i++) { for (i = 0; i < dpb->num_pictures; i++) {
ref_picture = dpb->pictures[i]; ref_picture = dpb->pictures[i];
index = ref_picture->poc > picture->poc; index = ref_picture->poc > picture->poc;
picture_ptr = &ref_pictures[index]; picture_ptr = &ref_pictures[index];
if (!*picture_ptr || ((*picture_ptr)->poc > ref_picture->poc) == index) if (!*picture_ptr || ((*picture_ptr)->poc > ref_picture->poc) == index)
*picture_ptr = ref_picture; *picture_ptr = ref_picture;
} }
if (prev_picture_ptr) if (prev_picture_ptr)
*prev_picture_ptr = ref_pictures[0]; *prev_picture_ptr = ref_pictures[0];
if (next_picture_ptr) if (next_picture_ptr)
*next_picture_ptr = ref_pictures[1]; *next_picture_ptr = ref_pictures[1];
} }
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
@ -327,92 +325,94 @@ dpb2_get_neighbours(GstVaapiDpb *dpb, GstVaapiPicture *picture,
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
static void static void
gst_vaapi_dpb_finalize(GstVaapiDpb *dpb) gst_vaapi_dpb_finalize (GstVaapiDpb * dpb)
{ {
dpb_clear(dpb); dpb_clear (dpb);
g_free(dpb->pictures); g_free (dpb->pictures);
} }
static const GstVaapiMiniObjectClass * static const GstVaapiMiniObjectClass *
gst_vaapi_dpb_class(void) gst_vaapi_dpb_class (void)
{ {
static const GstVaapiDpbClass GstVaapiDpbClass = { static const GstVaapiDpbClass GstVaapiDpbClass = {
{ sizeof(GstVaapiDpb), {sizeof (GstVaapiDpb),
(GDestroyNotify)gst_vaapi_dpb_finalize }, (GDestroyNotify) gst_vaapi_dpb_finalize}
,
dpb_flush, dpb_flush,
dpb_add, dpb_add,
dpb_get_neighbours dpb_get_neighbours
}; };
return &GstVaapiDpbClass.parent_class; return &GstVaapiDpbClass.parent_class;
} }
static const GstVaapiMiniObjectClass * static const GstVaapiMiniObjectClass *
gst_vaapi_dpb2_class(void) gst_vaapi_dpb2_class (void)
{ {
static const GstVaapiDpbClass GstVaapiDpb2Class = { static const GstVaapiDpbClass GstVaapiDpb2Class = {
{ sizeof(GstVaapiDpb), {sizeof (GstVaapiDpb),
(GDestroyNotify)gst_vaapi_dpb_finalize }, (GDestroyNotify) gst_vaapi_dpb_finalize}
,
dpb_flush, dpb_flush,
dpb2_add, dpb2_add,
dpb2_get_neighbours dpb2_get_neighbours
}; };
return &GstVaapiDpb2Class.parent_class; return &GstVaapiDpb2Class.parent_class;
} }
GstVaapiDpb * GstVaapiDpb *
gst_vaapi_dpb_new(guint max_pictures) gst_vaapi_dpb_new (guint max_pictures)
{ {
return dpb_new(max_pictures); return dpb_new (max_pictures);
} }
void void
gst_vaapi_dpb_flush(GstVaapiDpb *dpb) gst_vaapi_dpb_flush (GstVaapiDpb * dpb)
{ {
const GstVaapiDpbClass *klass; const GstVaapiDpbClass *klass;
g_return_if_fail(GST_VAAPI_IS_DPB(dpb)); g_return_if_fail (GST_VAAPI_IS_DPB (dpb));
klass = GST_VAAPI_DPB_GET_CLASS(dpb); klass = GST_VAAPI_DPB_GET_CLASS (dpb);
if (G_UNLIKELY(!klass || !klass->add)) if (G_UNLIKELY (!klass || !klass->add))
return; return;
klass->flush(dpb); klass->flush (dpb);
} }
gboolean gboolean
gst_vaapi_dpb_add(GstVaapiDpb *dpb, GstVaapiPicture *picture) gst_vaapi_dpb_add (GstVaapiDpb * dpb, GstVaapiPicture * picture)
{ {
const GstVaapiDpbClass *klass; const GstVaapiDpbClass *klass;
g_return_val_if_fail(GST_VAAPI_IS_DPB(dpb), FALSE); g_return_val_if_fail (GST_VAAPI_IS_DPB (dpb), FALSE);
g_return_val_if_fail(GST_VAAPI_IS_PICTURE(picture), FALSE); g_return_val_if_fail (GST_VAAPI_IS_PICTURE (picture), FALSE);
klass = GST_VAAPI_DPB_GET_CLASS(dpb); klass = GST_VAAPI_DPB_GET_CLASS (dpb);
if (G_UNLIKELY(!klass || !klass->add)) if (G_UNLIKELY (!klass || !klass->add))
return FALSE; return FALSE;
return klass->add(dpb, picture); return klass->add (dpb, picture);
} }
guint guint
gst_vaapi_dpb_size(GstVaapiDpb *dpb) gst_vaapi_dpb_size (GstVaapiDpb * dpb)
{ {
g_return_val_if_fail(GST_VAAPI_IS_DPB(dpb), 0); g_return_val_if_fail (GST_VAAPI_IS_DPB (dpb), 0);
return dpb->num_pictures; return dpb->num_pictures;
} }
void void
gst_vaapi_dpb_get_neighbours(GstVaapiDpb *dpb, GstVaapiPicture *picture, gst_vaapi_dpb_get_neighbours (GstVaapiDpb * dpb, GstVaapiPicture * picture,
GstVaapiPicture **prev_picture_ptr, GstVaapiPicture **next_picture_ptr) GstVaapiPicture ** prev_picture_ptr, GstVaapiPicture ** next_picture_ptr)
{ {
const GstVaapiDpbClass *klass; const GstVaapiDpbClass *klass;
g_return_if_fail(GST_VAAPI_IS_DPB(dpb)); g_return_if_fail (GST_VAAPI_IS_DPB (dpb));
g_return_if_fail(GST_VAAPI_IS_PICTURE(picture)); g_return_if_fail (GST_VAAPI_IS_PICTURE (picture));
klass = GST_VAAPI_DPB_GET_CLASS(dpb); klass = GST_VAAPI_DPB_GET_CLASS (dpb);
if (G_UNLIKELY(!klass || !klass->get_neighbours)) if (G_UNLIKELY (!klass || !klass->get_neighbours))
return; return;
klass->get_neighbours(dpb, picture, prev_picture_ptr, next_picture_ptr); klass->get_neighbours (dpb, picture, prev_picture_ptr, next_picture_ptr);
} }

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -38,14 +38,14 @@
* sub-classes. * sub-classes.
*/ */
void void
gst_vaapi_decoder_unit_init(GstVaapiDecoderUnit *unit) gst_vaapi_decoder_unit_init (GstVaapiDecoderUnit * unit)
{ {
unit->flags = 0; unit->flags = 0;
unit->size = 0; unit->size = 0;
unit->offset = 0; unit->offset = 0;
unit->parsed_info = NULL; unit->parsed_info = NULL;
unit->parsed_info_destroy_notify = NULL; unit->parsed_info_destroy_notify = NULL;
} }
/** /**
@ -59,9 +59,9 @@ gst_vaapi_decoder_unit_init(GstVaapiDecoderUnit *unit)
* sub-classes. * sub-classes.
*/ */
void void
gst_vaapi_decoder_unit_clear(GstVaapiDecoderUnit *unit) gst_vaapi_decoder_unit_clear (GstVaapiDecoderUnit * unit)
{ {
gst_vaapi_decoder_unit_set_parsed_info(unit, NULL, NULL); gst_vaapi_decoder_unit_set_parsed_info (unit, NULL, NULL);
} }
/** /**
@ -77,13 +77,13 @@ gst_vaapi_decoder_unit_clear(GstVaapiDecoderUnit *unit)
* function will be called before the @parsed_info is replaced. * function will be called before the @parsed_info is replaced.
*/ */
void void
gst_vaapi_decoder_unit_set_parsed_info(GstVaapiDecoderUnit *unit, gst_vaapi_decoder_unit_set_parsed_info (GstVaapiDecoderUnit * unit,
gpointer parsed_info, GDestroyNotify destroy_notify) gpointer parsed_info, GDestroyNotify destroy_notify)
{ {
g_return_if_fail(GST_VAAPI_IS_DECODER_UNIT(unit)); g_return_if_fail (GST_VAAPI_IS_DECODER_UNIT (unit));
if (unit->parsed_info && unit->parsed_info_destroy_notify) if (unit->parsed_info && unit->parsed_info_destroy_notify)
unit->parsed_info_destroy_notify(unit->parsed_info); unit->parsed_info_destroy_notify (unit->parsed_info);
unit->parsed_info = parsed_info; unit->parsed_info = parsed_info;
unit->parsed_info_destroy_notify = destroy_notify; unit->parsed_info_destroy_notify = destroy_notify;
} }

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -29,40 +29,40 @@
#include "gstvaapiparser_frame.h" #include "gstvaapiparser_frame.h"
static inline const GstVaapiMiniObjectClass * static inline const GstVaapiMiniObjectClass *
gst_vaapi_parser_frame_class(void) gst_vaapi_parser_frame_class (void)
{ {
static const GstVaapiMiniObjectClass GstVaapiParserFrameClass = { static const GstVaapiMiniObjectClass GstVaapiParserFrameClass = {
sizeof(GstVaapiParserFrame), sizeof (GstVaapiParserFrame),
(GDestroyNotify)gst_vaapi_parser_frame_free (GDestroyNotify) gst_vaapi_parser_frame_free
}; };
return &GstVaapiParserFrameClass; return &GstVaapiParserFrameClass;
} }
static inline gboolean static inline gboolean
alloc_units(GArray **units_ptr, guint size) alloc_units (GArray ** units_ptr, guint size)
{ {
GArray *units; GArray *units;
units = g_array_sized_new(FALSE, FALSE, sizeof(GstVaapiDecoderUnit), size); units = g_array_sized_new (FALSE, FALSE, sizeof (GstVaapiDecoderUnit), size);
*units_ptr = units; *units_ptr = units;
return units != NULL; return units != NULL;
} }
static inline void static inline void
free_units(GArray **units_ptr) free_units (GArray ** units_ptr)
{ {
GArray * const units = *units_ptr; GArray *const units = *units_ptr;
guint i; guint i;
if (units) { if (units) {
for (i = 0; i < units->len; i++) { for (i = 0; i < units->len; i++) {
GstVaapiDecoderUnit * const unit = GstVaapiDecoderUnit *const unit =
&g_array_index(units, GstVaapiDecoderUnit, i); &g_array_index (units, GstVaapiDecoderUnit, i);
gst_vaapi_decoder_unit_clear(unit); gst_vaapi_decoder_unit_clear (unit);
}
g_array_free(units, TRUE);
*units_ptr = NULL;
} }
g_array_free (units, TRUE);
*units_ptr = NULL;
}
} }
/** /**
@ -75,32 +75,32 @@ free_units(GArray **units_ptr)
* Returns: The newly allocated #GstVaapiParserFrame * Returns: The newly allocated #GstVaapiParserFrame
*/ */
GstVaapiParserFrame * GstVaapiParserFrame *
gst_vaapi_parser_frame_new(guint width, guint height) gst_vaapi_parser_frame_new (guint width, guint height)
{ {
GstVaapiParserFrame *frame; GstVaapiParserFrame *frame;
guint num_slices; guint num_slices;
frame = (GstVaapiParserFrame *) frame = (GstVaapiParserFrame *)
gst_vaapi_mini_object_new(gst_vaapi_parser_frame_class()); gst_vaapi_mini_object_new (gst_vaapi_parser_frame_class ());
if (!frame) if (!frame)
return NULL; return NULL;
if (!height) if (!height)
height = 1088; height = 1088;
num_slices = (height + 15) / 16; num_slices = (height + 15) / 16;
if (!alloc_units(&frame->pre_units, 16)) if (!alloc_units (&frame->pre_units, 16))
goto error; goto error;
if (!alloc_units(&frame->units, num_slices)) if (!alloc_units (&frame->units, num_slices))
goto error; goto error;
if (!alloc_units(&frame->post_units, 1)) if (!alloc_units (&frame->post_units, 1))
goto error; goto error;
frame->output_offset = 0; frame->output_offset = 0;
return frame; return frame;
error: error:
gst_vaapi_parser_frame_unref(frame); gst_vaapi_parser_frame_unref (frame);
return NULL; return NULL;
} }
/** /**
@ -114,11 +114,11 @@ error:
* sub-classes. * sub-classes.
*/ */
void void
gst_vaapi_parser_frame_free(GstVaapiParserFrame *frame) gst_vaapi_parser_frame_free (GstVaapiParserFrame * frame)
{ {
free_units(&frame->units); free_units (&frame->units);
free_units(&frame->pre_units); free_units (&frame->pre_units);
free_units(&frame->post_units); free_units (&frame->post_units);
} }
/** /**
@ -129,19 +129,19 @@ gst_vaapi_parser_frame_free(GstVaapiParserFrame *frame)
* Appends unit to the @frame. * Appends unit to the @frame.
*/ */
void void
gst_vaapi_parser_frame_append_unit(GstVaapiParserFrame *frame, gst_vaapi_parser_frame_append_unit (GstVaapiParserFrame * frame,
GstVaapiDecoderUnit *unit) GstVaapiDecoderUnit * unit)
{ {
GArray **unit_array_ptr; GArray **unit_array_ptr;
unit->offset = frame->output_offset; unit->offset = frame->output_offset;
frame->output_offset += unit->size; frame->output_offset += unit->size;
if (GST_VAAPI_DECODER_UNIT_IS_SLICE(unit)) if (GST_VAAPI_DECODER_UNIT_IS_SLICE (unit))
unit_array_ptr = &frame->units; unit_array_ptr = &frame->units;
else if (GST_VAAPI_DECODER_UNIT_IS_FRAME_END(unit)) else if (GST_VAAPI_DECODER_UNIT_IS_FRAME_END (unit))
unit_array_ptr = &frame->post_units; unit_array_ptr = &frame->post_units;
else else
unit_array_ptr = &frame->pre_units; unit_array_ptr = &frame->pre_units;
g_array_append_val(*unit_array_ptr, *unit); g_array_append_val (*unit_array_ptr, *unit);
} }

View file

@ -39,61 +39,61 @@
#undef gst_vaapi_pixmap_replace #undef gst_vaapi_pixmap_replace
static inline GstVaapiPixmap * static inline GstVaapiPixmap *
gst_vaapi_pixmap_new_internal(const GstVaapiPixmapClass *pixmap_class, gst_vaapi_pixmap_new_internal (const GstVaapiPixmapClass * pixmap_class,
GstVaapiDisplay *display) GstVaapiDisplay * display)
{ {
g_assert(pixmap_class->create != NULL); g_assert (pixmap_class->create != NULL);
g_assert(pixmap_class->render != NULL); g_assert (pixmap_class->render != NULL);
return gst_vaapi_object_new(GST_VAAPI_OBJECT_CLASS(pixmap_class), display); return gst_vaapi_object_new (GST_VAAPI_OBJECT_CLASS (pixmap_class), display);
} }
GstVaapiPixmap * GstVaapiPixmap *
gst_vaapi_pixmap_new(const GstVaapiPixmapClass *pixmap_class, gst_vaapi_pixmap_new (const GstVaapiPixmapClass * pixmap_class,
GstVaapiDisplay *display, GstVideoFormat format, guint width, guint height) GstVaapiDisplay * display, GstVideoFormat format, guint width, guint height)
{ {
GstVaapiPixmap *pixmap; GstVaapiPixmap *pixmap;
g_return_val_if_fail(format != GST_VIDEO_FORMAT_UNKNOWN && g_return_val_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN &&
format != GST_VIDEO_FORMAT_ENCODED, NULL); format != GST_VIDEO_FORMAT_ENCODED, NULL);
g_return_val_if_fail(width > 0, NULL); g_return_val_if_fail (width > 0, NULL);
g_return_val_if_fail(height > 0, NULL); g_return_val_if_fail (height > 0, NULL);
pixmap = gst_vaapi_pixmap_new_internal(pixmap_class, display); pixmap = gst_vaapi_pixmap_new_internal (pixmap_class, display);
if (!pixmap) if (!pixmap)
return NULL; return NULL;
pixmap->format = format; pixmap->format = format;
pixmap->width = width; pixmap->width = width;
pixmap->height = height; pixmap->height = height;
if (!pixmap_class->create(pixmap)) if (!pixmap_class->create (pixmap))
goto error; goto error;
return pixmap; return pixmap;
error: error:
gst_vaapi_pixmap_unref_internal(pixmap); gst_vaapi_pixmap_unref_internal (pixmap);
return NULL; return NULL;
} }
GstVaapiPixmap * GstVaapiPixmap *
gst_vaapi_pixmap_new_from_native(const GstVaapiPixmapClass *pixmap_class, gst_vaapi_pixmap_new_from_native (const GstVaapiPixmapClass * pixmap_class,
GstVaapiDisplay *display, gpointer native_pixmap) GstVaapiDisplay * display, gpointer native_pixmap)
{ {
GstVaapiPixmap *pixmap; GstVaapiPixmap *pixmap;
pixmap = gst_vaapi_pixmap_new_internal(pixmap_class, display); pixmap = gst_vaapi_pixmap_new_internal (pixmap_class, display);
if (!pixmap) if (!pixmap)
return NULL; return NULL;
GST_VAAPI_OBJECT_ID(pixmap) = GPOINTER_TO_SIZE(native_pixmap); GST_VAAPI_OBJECT_ID (pixmap) = GPOINTER_TO_SIZE (native_pixmap);
pixmap->use_foreign_pixmap = TRUE; pixmap->use_foreign_pixmap = TRUE;
if (!pixmap_class->create(pixmap)) if (!pixmap_class->create (pixmap))
goto error; goto error;
return pixmap; return pixmap;
error: error:
gst_vaapi_pixmap_unref_internal(pixmap); gst_vaapi_pixmap_unref_internal (pixmap);
return NULL; return NULL;
} }
/** /**
@ -105,9 +105,9 @@ error:
* Returns: The same @pixmap argument * Returns: The same @pixmap argument
*/ */
GstVaapiPixmap * GstVaapiPixmap *
gst_vaapi_pixmap_ref(GstVaapiPixmap *pixmap) gst_vaapi_pixmap_ref (GstVaapiPixmap * pixmap)
{ {
return gst_vaapi_pixmap_ref_internal(pixmap); return gst_vaapi_pixmap_ref_internal (pixmap);
} }
/** /**
@ -118,9 +118,9 @@ gst_vaapi_pixmap_ref(GstVaapiPixmap *pixmap)
* the reference count reaches zero, the pixmap will be free'd. * the reference count reaches zero, the pixmap will be free'd.
*/ */
void void
gst_vaapi_pixmap_unref(GstVaapiPixmap *pixmap) gst_vaapi_pixmap_unref (GstVaapiPixmap * pixmap)
{ {
gst_vaapi_pixmap_unref_internal(pixmap); gst_vaapi_pixmap_unref_internal (pixmap);
} }
/** /**
@ -133,10 +133,10 @@ gst_vaapi_pixmap_unref(GstVaapiPixmap *pixmap)
* valid pixmap. However, @new_pixmap can be NULL. * valid pixmap. However, @new_pixmap can be NULL.
*/ */
void void
gst_vaapi_pixmap_replace(GstVaapiPixmap **old_pixmap_ptr, gst_vaapi_pixmap_replace (GstVaapiPixmap ** old_pixmap_ptr,
GstVaapiPixmap *new_pixmap) GstVaapiPixmap * new_pixmap)
{ {
gst_vaapi_pixmap_replace_internal(old_pixmap_ptr, new_pixmap); gst_vaapi_pixmap_replace_internal (old_pixmap_ptr, new_pixmap);
} }
/** /**
@ -148,11 +148,11 @@ gst_vaapi_pixmap_replace(GstVaapiPixmap **old_pixmap_ptr,
* Return value: the parent #GstVaapiDisplay object * Return value: the parent #GstVaapiDisplay object
*/ */
GstVaapiDisplay * GstVaapiDisplay *
gst_vaapi_pixmap_get_display(GstVaapiPixmap *pixmap) gst_vaapi_pixmap_get_display (GstVaapiPixmap * pixmap)
{ {
g_return_val_if_fail(pixmap != NULL, NULL); g_return_val_if_fail (pixmap != NULL, NULL);
return GST_VAAPI_OBJECT_DISPLAY(pixmap); return GST_VAAPI_OBJECT_DISPLAY (pixmap);
} }
/** /**
@ -164,11 +164,11 @@ gst_vaapi_pixmap_get_display(GstVaapiPixmap *pixmap)
* Return value: the format of the @pixmap * Return value: the format of the @pixmap
*/ */
GstVideoFormat GstVideoFormat
gst_vaapi_pixmap_get_format(GstVaapiPixmap *pixmap) gst_vaapi_pixmap_get_format (GstVaapiPixmap * pixmap)
{ {
g_return_val_if_fail(pixmap != NULL, GST_VIDEO_FORMAT_UNKNOWN); g_return_val_if_fail (pixmap != NULL, GST_VIDEO_FORMAT_UNKNOWN);
return GST_VAAPI_PIXMAP_FORMAT(pixmap); return GST_VAAPI_PIXMAP_FORMAT (pixmap);
} }
/** /**
@ -180,11 +180,11 @@ gst_vaapi_pixmap_get_format(GstVaapiPixmap *pixmap)
* Return value: the width of the @pixmap, in pixels * Return value: the width of the @pixmap, in pixels
*/ */
guint guint
gst_vaapi_pixmap_get_width(GstVaapiPixmap *pixmap) gst_vaapi_pixmap_get_width (GstVaapiPixmap * pixmap)
{ {
g_return_val_if_fail(pixmap != NULL, 0); g_return_val_if_fail (pixmap != NULL, 0);
return GST_VAAPI_PIXMAP_WIDTH(pixmap); return GST_VAAPI_PIXMAP_WIDTH (pixmap);
} }
/** /**
@ -196,11 +196,11 @@ gst_vaapi_pixmap_get_width(GstVaapiPixmap *pixmap)
* Return value: the height of the @pixmap, in pixels * Return value: the height of the @pixmap, in pixels
*/ */
guint guint
gst_vaapi_pixmap_get_height(GstVaapiPixmap *pixmap) gst_vaapi_pixmap_get_height (GstVaapiPixmap * pixmap)
{ {
g_return_val_if_fail(pixmap != NULL, 0); g_return_val_if_fail (pixmap != NULL, 0);
return GST_VAAPI_PIXMAP_HEIGHT(pixmap); return GST_VAAPI_PIXMAP_HEIGHT (pixmap);
} }
/** /**
@ -212,15 +212,16 @@ gst_vaapi_pixmap_get_height(GstVaapiPixmap *pixmap)
* Retrieves the dimensions of a #GstVaapiPixmap. * Retrieves the dimensions of a #GstVaapiPixmap.
*/ */
void void
gst_vaapi_pixmap_get_size(GstVaapiPixmap *pixmap, guint *width, guint *height) gst_vaapi_pixmap_get_size (GstVaapiPixmap * pixmap, guint * width,
guint * height)
{ {
g_return_if_fail(pixmap != NULL); g_return_if_fail (pixmap != NULL);
if (width) if (width)
*width = GST_VAAPI_PIXMAP_WIDTH(pixmap); *width = GST_VAAPI_PIXMAP_WIDTH (pixmap);
if (height) if (height)
*height = GST_VAAPI_PIXMAP_HEIGHT(pixmap); *height = GST_VAAPI_PIXMAP_HEIGHT (pixmap);
} }
/** /**
@ -240,21 +241,21 @@ gst_vaapi_pixmap_get_size(GstVaapiPixmap *pixmap, guint *width, guint *height)
* Return value: %TRUE on success * Return value: %TRUE on success
*/ */
gboolean gboolean
gst_vaapi_pixmap_put_surface(GstVaapiPixmap *pixmap, GstVaapiSurface *surface, gst_vaapi_pixmap_put_surface (GstVaapiPixmap * pixmap,
const GstVaapiRectangle *crop_rect, guint flags) GstVaapiSurface * surface, const GstVaapiRectangle * crop_rect, guint flags)
{ {
GstVaapiRectangle src_rect; GstVaapiRectangle src_rect;
g_return_val_if_fail(pixmap != NULL, FALSE); g_return_val_if_fail (pixmap != NULL, FALSE);
g_return_val_if_fail(surface != NULL, FALSE); g_return_val_if_fail (surface != NULL, FALSE);
if (!crop_rect) { if (!crop_rect) {
src_rect.x = 0; src_rect.x = 0;
src_rect.y = 0; src_rect.y = 0;
src_rect.width = GST_VAAPI_SURFACE_WIDTH(surface); src_rect.width = GST_VAAPI_SURFACE_WIDTH (surface);
src_rect.height = GST_VAAPI_SURFACE_HEIGHT(surface); src_rect.height = GST_VAAPI_SURFACE_HEIGHT (surface);
crop_rect = &src_rect; crop_rect = &src_rect;
} }
return GST_VAAPI_PIXMAP_GET_CLASS(pixmap)->render(pixmap, surface, return GST_VAAPI_PIXMAP_GET_CLASS (pixmap)->render (pixmap, surface,
crop_rect, flags); crop_rect, flags);
} }

View file

@ -38,134 +38,131 @@
#define DEBUG 1 #define DEBUG 1
#include "gstvaapidebug.h" #include "gstvaapidebug.h"
typedef struct _GstVaapiPixmapX11Class GstVaapiPixmapX11Class; typedef struct _GstVaapiPixmapX11Class GstVaapiPixmapX11Class;
struct _GstVaapiPixmapX11 { struct _GstVaapiPixmapX11
GstVaapiPixmap parent_instance; {
GstVaapiPixmap parent_instance;
}; };
struct _GstVaapiPixmapX11Class { struct _GstVaapiPixmapX11Class
GstVaapiPixmapClass parent_class; {
GstVaapiPixmapClass parent_class;
}; };
static gboolean static gboolean
gst_vaapi_pixmap_x11_create_from_xid(GstVaapiPixmap *pixmap, Pixmap xid) gst_vaapi_pixmap_x11_create_from_xid (GstVaapiPixmap * pixmap, Pixmap xid)
{ {
guint depth; guint depth;
gboolean success; gboolean success;
if (!xid) if (!xid)
return FALSE; return FALSE;
GST_VAAPI_OBJECT_LOCK_DISPLAY(pixmap); GST_VAAPI_OBJECT_LOCK_DISPLAY (pixmap);
success = x11_get_geometry(GST_VAAPI_OBJECT_NATIVE_DISPLAY(pixmap), xid, success = x11_get_geometry (GST_VAAPI_OBJECT_NATIVE_DISPLAY (pixmap), xid,
NULL, NULL, &pixmap->width, &pixmap->height, &depth); NULL, NULL, &pixmap->width, &pixmap->height, &depth);
GST_VAAPI_OBJECT_UNLOCK_DISPLAY(pixmap); GST_VAAPI_OBJECT_UNLOCK_DISPLAY (pixmap);
if (!success) if (!success)
return FALSE; return FALSE;
pixmap->format = gst_vaapi_display_x11_get_pixmap_format( pixmap->format =
GST_VAAPI_OBJECT_DISPLAY_X11(pixmap), depth); gst_vaapi_display_x11_get_pixmap_format (GST_VAAPI_OBJECT_DISPLAY_X11
if (pixmap->format == GST_VIDEO_FORMAT_UNKNOWN) (pixmap), depth);
return FALSE; if (pixmap->format == GST_VIDEO_FORMAT_UNKNOWN)
return TRUE; return FALSE;
return TRUE;
} }
static gboolean static gboolean
gst_vaapi_pixmap_x11_create(GstVaapiPixmap *pixmap) gst_vaapi_pixmap_x11_create (GstVaapiPixmap * pixmap)
{ {
GstVaapiDisplayX11 * const display = GstVaapiDisplayX11 *const display =
GST_VAAPI_DISPLAY_X11(GST_VAAPI_OBJECT_DISPLAY(pixmap)); GST_VAAPI_DISPLAY_X11 (GST_VAAPI_OBJECT_DISPLAY (pixmap));
Display * const dpy = GST_VAAPI_OBJECT_NATIVE_DISPLAY(display); Display *const dpy = GST_VAAPI_OBJECT_NATIVE_DISPLAY (display);
Window rootwin; Window rootwin;
Pixmap xid; Pixmap xid;
guint depth; guint depth;
if (pixmap->use_foreign_pixmap) if (pixmap->use_foreign_pixmap)
return gst_vaapi_pixmap_x11_create_from_xid(pixmap, return gst_vaapi_pixmap_x11_create_from_xid (pixmap,
GST_VAAPI_OBJECT_ID(pixmap)); GST_VAAPI_OBJECT_ID (pixmap));
depth = gst_vaapi_display_x11_get_pixmap_depth(display, pixmap->format); depth = gst_vaapi_display_x11_get_pixmap_depth (display, pixmap->format);
if (!depth) if (!depth)
return FALSE; return FALSE;
GST_VAAPI_OBJECT_LOCK_DISPLAY(pixmap); GST_VAAPI_OBJECT_LOCK_DISPLAY (pixmap);
rootwin = RootWindow(dpy, DefaultScreen(dpy)); rootwin = RootWindow (dpy, DefaultScreen (dpy));
xid = XCreatePixmap(dpy, rootwin, pixmap->width, pixmap->height, depth); xid = XCreatePixmap (dpy, rootwin, pixmap->width, pixmap->height, depth);
GST_VAAPI_OBJECT_UNLOCK_DISPLAY(pixmap); GST_VAAPI_OBJECT_UNLOCK_DISPLAY (pixmap);
GST_DEBUG("xid %" GST_VAAPI_ID_FORMAT, GST_VAAPI_ID_ARGS(xid)); GST_DEBUG ("xid %" GST_VAAPI_ID_FORMAT, GST_VAAPI_ID_ARGS (xid));
GST_VAAPI_OBJECT_ID(pixmap) = xid; GST_VAAPI_OBJECT_ID (pixmap) = xid;
return xid != None; return xid != None;
} }
static void static void
gst_vaapi_pixmap_x11_destroy(GstVaapiPixmap *pixmap) gst_vaapi_pixmap_x11_destroy (GstVaapiPixmap * pixmap)
{ {
const Pixmap xid = GST_VAAPI_OBJECT_ID(pixmap); const Pixmap xid = GST_VAAPI_OBJECT_ID (pixmap);
if (xid) { if (xid) {
if (!pixmap->use_foreign_pixmap) { if (!pixmap->use_foreign_pixmap) {
GST_VAAPI_OBJECT_LOCK_DISPLAY(pixmap); GST_VAAPI_OBJECT_LOCK_DISPLAY (pixmap);
XFreePixmap(GST_VAAPI_OBJECT_NATIVE_DISPLAY(pixmap), xid); XFreePixmap (GST_VAAPI_OBJECT_NATIVE_DISPLAY (pixmap), xid);
GST_VAAPI_OBJECT_UNLOCK_DISPLAY(pixmap); GST_VAAPI_OBJECT_UNLOCK_DISPLAY (pixmap);
}
GST_VAAPI_OBJECT_ID(pixmap) = None;
} }
GST_VAAPI_OBJECT_ID (pixmap) = None;
}
} }
static gboolean static gboolean
gst_vaapi_pixmap_x11_render(GstVaapiPixmap *pixmap, GstVaapiSurface *surface, gst_vaapi_pixmap_x11_render (GstVaapiPixmap * pixmap, GstVaapiSurface * surface,
const GstVaapiRectangle *crop_rect, guint flags) const GstVaapiRectangle * crop_rect, guint flags)
{ {
VASurfaceID surface_id; VASurfaceID surface_id;
VAStatus status; VAStatus status;
surface_id = GST_VAAPI_OBJECT_ID(surface); surface_id = GST_VAAPI_OBJECT_ID (surface);
if (surface_id == VA_INVALID_ID) if (surface_id == VA_INVALID_ID)
return FALSE; return FALSE;
GST_VAAPI_OBJECT_LOCK_DISPLAY(pixmap); GST_VAAPI_OBJECT_LOCK_DISPLAY (pixmap);
status = vaPutSurface( status = vaPutSurface (GST_VAAPI_OBJECT_VADISPLAY (pixmap),
GST_VAAPI_OBJECT_VADISPLAY(pixmap), surface_id,
surface_id, GST_VAAPI_OBJECT_ID (pixmap),
GST_VAAPI_OBJECT_ID(pixmap), crop_rect->x, crop_rect->y,
crop_rect->x, crop_rect->y, crop_rect->width, crop_rect->height,
crop_rect->width, crop_rect->height, 0, 0,
0, 0, GST_VAAPI_PIXMAP_WIDTH (pixmap),
GST_VAAPI_PIXMAP_WIDTH(pixmap), GST_VAAPI_PIXMAP_HEIGHT (pixmap),
GST_VAAPI_PIXMAP_HEIGHT(pixmap), NULL, 0, from_GstVaapiSurfaceRenderFlags (flags)
NULL, 0, );
from_GstVaapiSurfaceRenderFlags(flags) GST_VAAPI_OBJECT_UNLOCK_DISPLAY (pixmap);
); if (!vaapi_check_status (status, "vaPutSurface() [pixmap]"))
GST_VAAPI_OBJECT_UNLOCK_DISPLAY(pixmap); return FALSE;
if (!vaapi_check_status(status, "vaPutSurface() [pixmap]")) return TRUE;
return FALSE;
return TRUE;
} }
void void
gst_vaapi_pixmap_x11_class_init(GstVaapiPixmapX11Class *klass) gst_vaapi_pixmap_x11_class_init (GstVaapiPixmapX11Class * klass)
{ {
GstVaapiObjectClass * const object_class = GstVaapiObjectClass *const object_class = GST_VAAPI_OBJECT_CLASS (klass);
GST_VAAPI_OBJECT_CLASS(klass); GstVaapiPixmapClass *const pixmap_class = GST_VAAPI_PIXMAP_CLASS (klass);
GstVaapiPixmapClass * const pixmap_class =
GST_VAAPI_PIXMAP_CLASS(klass);
object_class->finalize = (GstVaapiObjectFinalizeFunc) object_class->finalize = (GstVaapiObjectFinalizeFunc)
gst_vaapi_pixmap_x11_destroy; gst_vaapi_pixmap_x11_destroy;
pixmap_class->create = gst_vaapi_pixmap_x11_create; pixmap_class->create = gst_vaapi_pixmap_x11_create;
pixmap_class->render = gst_vaapi_pixmap_x11_render; pixmap_class->render = gst_vaapi_pixmap_x11_render;
} }
#define gst_vaapi_pixmap_x11_finalize \ #define gst_vaapi_pixmap_x11_finalize \
gst_vaapi_pixmap_x11_destroy gst_vaapi_pixmap_x11_destroy
GST_VAAPI_OBJECT_DEFINE_CLASS_WITH_CODE( GST_VAAPI_OBJECT_DEFINE_CLASS_WITH_CODE (GstVaapiPixmapX11,
GstVaapiPixmapX11, gst_vaapi_pixmap_x11, gst_vaapi_pixmap_x11_class_init (&g_class))
gst_vaapi_pixmap_x11,
gst_vaapi_pixmap_x11_class_init(&g_class))
/** /**
* gst_vaapi_pixmap_x11_new: * gst_vaapi_pixmap_x11_new:
@ -179,17 +176,17 @@ GST_VAAPI_OBJECT_DEFINE_CLASS_WITH_CODE(
* *
* Return value: the newly allocated #GstVaapiPixmap object * Return value: the newly allocated #GstVaapiPixmap object
*/ */
GstVaapiPixmap * GstVaapiPixmap *gst_vaapi_pixmap_x11_new (GstVaapiDisplay * display,
gst_vaapi_pixmap_x11_new(GstVaapiDisplay *display, GstVideoFormat format, GstVideoFormat format, guint width, guint height)
guint width, guint height)
{ {
GST_DEBUG("new pixmap, format %s, size %ux%u", GST_DEBUG ("new pixmap, format %s, size %ux%u",
gst_vaapi_video_format_to_string(format), width, height); gst_vaapi_video_format_to_string (format), width, height);
g_return_val_if_fail(GST_VAAPI_IS_DISPLAY_X11(display), NULL); g_return_val_if_fail (GST_VAAPI_IS_DISPLAY_X11 (display), NULL);
return gst_vaapi_pixmap_new(GST_VAAPI_PIXMAP_CLASS( return
gst_vaapi_pixmap_x11_class()), display, format, width, height); gst_vaapi_pixmap_new (GST_VAAPI_PIXMAP_CLASS (gst_vaapi_pixmap_x11_class
()), display, format, width, height);
} }
/** /**
@ -205,15 +202,16 @@ gst_vaapi_pixmap_x11_new(GstVaapiDisplay *display, GstVideoFormat format,
* Return value: the newly allocated #GstVaapiPixmap object * Return value: the newly allocated #GstVaapiPixmap object
*/ */
GstVaapiPixmap * GstVaapiPixmap *
gst_vaapi_pixmap_x11_new_with_xid(GstVaapiDisplay *display, Pixmap xid) gst_vaapi_pixmap_x11_new_with_xid (GstVaapiDisplay * display, Pixmap xid)
{ {
GST_DEBUG("new pixmap from xid 0x%08x", (guint)xid); GST_DEBUG ("new pixmap from xid 0x%08x", (guint) xid);
g_return_val_if_fail(GST_VAAPI_IS_DISPLAY_X11(display), NULL); g_return_val_if_fail (GST_VAAPI_IS_DISPLAY_X11 (display), NULL);
g_return_val_if_fail(xid != None, NULL); g_return_val_if_fail (xid != None, NULL);
return gst_vaapi_pixmap_new_from_native(GST_VAAPI_PIXMAP_CLASS( return
gst_vaapi_pixmap_x11_class()), display, GSIZE_TO_POINTER(xid)); gst_vaapi_pixmap_new_from_native (GST_VAAPI_PIXMAP_CLASS
(gst_vaapi_pixmap_x11_class ()), display, GSIZE_TO_POINTER (xid));
} }
/** /**
@ -227,11 +225,11 @@ gst_vaapi_pixmap_x11_new_with_xid(GstVaapiDisplay *display, Pixmap xid)
* Return value: the underlying X11 Pixmap bound to @pixmap. * Return value: the underlying X11 Pixmap bound to @pixmap.
*/ */
Pixmap Pixmap
gst_vaapi_pixmap_x11_get_xid(GstVaapiPixmapX11 *pixmap) gst_vaapi_pixmap_x11_get_xid (GstVaapiPixmapX11 * pixmap)
{ {
g_return_val_if_fail(pixmap != NULL, None); g_return_val_if_fail (pixmap != NULL, None);
return GST_VAAPI_OBJECT_ID(pixmap); return GST_VAAPI_OBJECT_ID (pixmap);
} }
/** /**
@ -245,9 +243,9 @@ gst_vaapi_pixmap_x11_get_xid(GstVaapiPixmapX11 *pixmap)
* caller (foreign pixmap) * caller (foreign pixmap)
*/ */
gboolean gboolean
gst_vaapi_pixmap_x11_is_foreign_xid(GstVaapiPixmapX11 *pixmap) gst_vaapi_pixmap_x11_is_foreign_xid (GstVaapiPixmapX11 * pixmap)
{ {
g_return_val_if_fail(pixmap != NULL, FALSE); g_return_val_if_fail (pixmap != NULL, FALSE);
return GST_VAAPI_PIXMAP(pixmap)->use_foreign_pixmap; return GST_VAAPI_PIXMAP (pixmap)->use_foreign_pixmap;
} }

View file

@ -34,172 +34,153 @@
#include "gstvaapiprofile.h" #include "gstvaapiprofile.h"
#include "gstvaapiworkarounds.h" #include "gstvaapiworkarounds.h"
typedef struct _GstVaapiCodecMap GstVaapiCodecMap; typedef struct _GstVaapiCodecMap GstVaapiCodecMap;
typedef struct _GstVaapiProfileMap GstVaapiProfileMap; typedef struct _GstVaapiProfileMap GstVaapiProfileMap;
typedef struct _GstVaapiEntrypointMap GstVaapiEntrypointMap; typedef struct _GstVaapiEntrypointMap GstVaapiEntrypointMap;
struct _GstVaapiCodecMap { struct _GstVaapiCodecMap
GstVaapiCodec codec; {
const gchar *name; GstVaapiCodec codec;
const gchar *name;
}; };
struct _GstVaapiProfileMap { struct _GstVaapiProfileMap
GstVaapiProfile profile; {
VAProfile va_profile; GstVaapiProfile profile;
const char *media_str; VAProfile va_profile;
const gchar *profile_str; const char *media_str;
const gchar *profile_str;
}; };
struct _GstVaapiEntrypointMap { struct _GstVaapiEntrypointMap
GstVaapiEntrypoint entrypoint; {
VAEntrypoint va_entrypoint; GstVaapiEntrypoint entrypoint;
VAEntrypoint va_entrypoint;
}; };
/* Codecs */ /* Codecs */
static const GstVaapiCodecMap gst_vaapi_codecs[] = { static const GstVaapiCodecMap gst_vaapi_codecs[] = {
{ GST_VAAPI_CODEC_MPEG1, "mpeg1" }, {GST_VAAPI_CODEC_MPEG1, "mpeg1"},
{ GST_VAAPI_CODEC_MPEG2, "mpeg2" }, {GST_VAAPI_CODEC_MPEG2, "mpeg2"},
{ GST_VAAPI_CODEC_MPEG4, "mpeg4" }, {GST_VAAPI_CODEC_MPEG4, "mpeg4"},
{ GST_VAAPI_CODEC_H263, "h263" }, {GST_VAAPI_CODEC_H263, "h263"},
{ GST_VAAPI_CODEC_H264, "h264" }, {GST_VAAPI_CODEC_H264, "h264"},
{ GST_VAAPI_CODEC_WMV3, "wmv3" }, {GST_VAAPI_CODEC_WMV3, "wmv3"},
{ GST_VAAPI_CODEC_VC1, "vc1" }, {GST_VAAPI_CODEC_VC1, "vc1"},
{ GST_VAAPI_CODEC_JPEG, "jpeg" }, {GST_VAAPI_CODEC_JPEG, "jpeg"},
{ GST_VAAPI_CODEC_VP8, "vp8" }, {GST_VAAPI_CODEC_VP8, "vp8"},
{ GST_VAAPI_CODEC_H265, "h265" }, {GST_VAAPI_CODEC_H265, "h265"},
{ GST_VAAPI_CODEC_VP9, "vp9" }, {GST_VAAPI_CODEC_VP9, "vp9"},
{ 0, } {0,}
}; };
/* Profiles */ /* Profiles */
static const GstVaapiProfileMap gst_vaapi_profiles[] = { static const GstVaapiProfileMap gst_vaapi_profiles[] = {
{ GST_VAAPI_PROFILE_MPEG2_SIMPLE, VAProfileMPEG2Simple, {GST_VAAPI_PROFILE_MPEG2_SIMPLE, VAProfileMPEG2Simple,
"video/mpeg, mpegversion=2", "simple" "video/mpeg, mpegversion=2", "simple"},
}, {GST_VAAPI_PROFILE_MPEG2_MAIN, VAProfileMPEG2Main,
{ GST_VAAPI_PROFILE_MPEG2_MAIN, VAProfileMPEG2Main, "video/mpeg, mpegversion=2", "main"},
"video/mpeg, mpegversion=2", "main" {GST_VAAPI_PROFILE_MPEG4_SIMPLE, VAProfileMPEG4Simple,
}, "video/mpeg, mpegversion=4", "simple"},
{ GST_VAAPI_PROFILE_MPEG4_SIMPLE, VAProfileMPEG4Simple, {GST_VAAPI_PROFILE_MPEG4_ADVANCED_SIMPLE, VAProfileMPEG4AdvancedSimple,
"video/mpeg, mpegversion=4", "simple" "video/mpeg, mpegversion=4", "advanced-simple"},
}, {GST_VAAPI_PROFILE_MPEG4_MAIN, VAProfileMPEG4Main,
{ GST_VAAPI_PROFILE_MPEG4_ADVANCED_SIMPLE, VAProfileMPEG4AdvancedSimple, "video/mpeg, mpegversion=4", "main"},
"video/mpeg, mpegversion=4", "advanced-simple" {GST_VAAPI_PROFILE_MPEG4_ADVANCED_SIMPLE, VAProfileMPEG4AdvancedSimple,
}, "video/x-divx, divxversion=5", "advanced-simple"},
{ GST_VAAPI_PROFILE_MPEG4_MAIN, VAProfileMPEG4Main, {GST_VAAPI_PROFILE_MPEG4_ADVANCED_SIMPLE, VAProfileMPEG4AdvancedSimple,
"video/mpeg, mpegversion=4", "main" "video/x-xvid", "advanced-simple"},
},
{ GST_VAAPI_PROFILE_MPEG4_ADVANCED_SIMPLE, VAProfileMPEG4AdvancedSimple,
"video/x-divx, divxversion=5", "advanced-simple"
},
{ GST_VAAPI_PROFILE_MPEG4_ADVANCED_SIMPLE, VAProfileMPEG4AdvancedSimple,
"video/x-xvid", "advanced-simple"
},
#if VA_CHECK_VERSION(0,30,0) #if VA_CHECK_VERSION(0,30,0)
{ GST_VAAPI_PROFILE_H263_BASELINE, VAProfileH263Baseline, {GST_VAAPI_PROFILE_H263_BASELINE, VAProfileH263Baseline,
"video/x-h263, variant=itu, h263version=h263", "baseline" "video/x-h263, variant=itu, h263version=h263", "baseline"},
},
#endif #endif
{ GST_VAAPI_PROFILE_H264_BASELINE, VAProfileH264Baseline, {GST_VAAPI_PROFILE_H264_BASELINE, VAProfileH264Baseline,
"video/x-h264", "baseline" "video/x-h264", "baseline"},
},
#if VA_CHECK_VERSION(0,31,1) #if VA_CHECK_VERSION(0,31,1)
{ GST_VAAPI_PROFILE_H264_CONSTRAINED_BASELINE, {GST_VAAPI_PROFILE_H264_CONSTRAINED_BASELINE,
VAProfileH264ConstrainedBaseline, VAProfileH264ConstrainedBaseline,
"video/x-h264", "constrained-baseline" "video/x-h264", "constrained-baseline"},
},
#endif #endif
{ GST_VAAPI_PROFILE_H264_MAIN, VAProfileH264Main, {GST_VAAPI_PROFILE_H264_MAIN, VAProfileH264Main,
"video/x-h264", "main" "video/x-h264", "main"},
}, {GST_VAAPI_PROFILE_H264_HIGH, VAProfileH264High,
{ GST_VAAPI_PROFILE_H264_HIGH, VAProfileH264High, "video/x-h264", "high"},
"video/x-h264", "high"
},
#if VA_CHECK_VERSION(0,35,2) #if VA_CHECK_VERSION(0,35,2)
{ GST_VAAPI_PROFILE_H264_MULTIVIEW_HIGH, VAProfileH264MultiviewHigh, {GST_VAAPI_PROFILE_H264_MULTIVIEW_HIGH, VAProfileH264MultiviewHigh,
"video/x-h264", "multiview-high" "video/x-h264", "multiview-high"},
}, {GST_VAAPI_PROFILE_H264_STEREO_HIGH, VAProfileH264StereoHigh,
{ GST_VAAPI_PROFILE_H264_STEREO_HIGH, VAProfileH264StereoHigh, "video/x-h264", "stereo-high"},
"video/x-h264", "stereo-high"
},
#endif #endif
{ GST_VAAPI_PROFILE_VC1_SIMPLE, VAProfileVC1Simple, {GST_VAAPI_PROFILE_VC1_SIMPLE, VAProfileVC1Simple,
"video/x-wmv, wmvversion=3", "simple" "video/x-wmv, wmvversion=3", "simple"},
}, {GST_VAAPI_PROFILE_VC1_MAIN, VAProfileVC1Main,
{ GST_VAAPI_PROFILE_VC1_MAIN, VAProfileVC1Main, "video/x-wmv, wmvversion=3", "main"},
"video/x-wmv, wmvversion=3", "main" {GST_VAAPI_PROFILE_VC1_ADVANCED, VAProfileVC1Advanced,
}, "video/x-wmv, wmvversion=3, format=(string)WVC1", "advanced"},
{ GST_VAAPI_PROFILE_VC1_ADVANCED, VAProfileVC1Advanced,
"video/x-wmv, wmvversion=3, format=(string)WVC1", "advanced"
},
#if VA_CHECK_VERSION(0,32,0) #if VA_CHECK_VERSION(0,32,0)
{ GST_VAAPI_PROFILE_JPEG_BASELINE, VAProfileJPEGBaseline, {GST_VAAPI_PROFILE_JPEG_BASELINE, VAProfileJPEGBaseline,
"image/jpeg", NULL "image/jpeg", NULL},
},
#endif #endif
#if VA_CHECK_VERSION(0,35,0) #if VA_CHECK_VERSION(0,35,0)
{ GST_VAAPI_PROFILE_VP8, VAProfileVP8Version0_3, {GST_VAAPI_PROFILE_VP8, VAProfileVP8Version0_3,
"video/x-vp8", NULL "video/x-vp8", NULL},
},
#endif #endif
#if VA_CHECK_VERSION(0,37,0) #if VA_CHECK_VERSION(0,37,0)
{ GST_VAAPI_PROFILE_H265_MAIN, VAProfileHEVCMain, {GST_VAAPI_PROFILE_H265_MAIN, VAProfileHEVCMain,
"video/x-h265", "main" "video/x-h265", "main"},
}, {GST_VAAPI_PROFILE_H265_MAIN10, VAProfileHEVCMain10,
{ GST_VAAPI_PROFILE_H265_MAIN10, VAProfileHEVCMain10, "video/x-h265", "main-10"},
"video/x-h265", "main-10"
},
#endif #endif
#if VA_CHECK_VERSION(0,38,0) #if VA_CHECK_VERSION(0,38,0)
{ GST_VAAPI_PROFILE_VP9, VAProfileVP9Profile0, {GST_VAAPI_PROFILE_VP9, VAProfileVP9Profile0,
"video/x-vp9", NULL "video/x-vp9", NULL},
},
#endif #endif
{ 0, } {0,}
}; };
/* Entry-points */ /* Entry-points */
static const GstVaapiEntrypointMap gst_vaapi_entrypoints[] = { static const GstVaapiEntrypointMap gst_vaapi_entrypoints[] = {
{ GST_VAAPI_ENTRYPOINT_VLD, VAEntrypointVLD }, {GST_VAAPI_ENTRYPOINT_VLD, VAEntrypointVLD},
{ GST_VAAPI_ENTRYPOINT_IDCT, VAEntrypointIDCT }, {GST_VAAPI_ENTRYPOINT_IDCT, VAEntrypointIDCT},
{ GST_VAAPI_ENTRYPOINT_MOCO, VAEntrypointMoComp }, {GST_VAAPI_ENTRYPOINT_MOCO, VAEntrypointMoComp},
#if VA_CHECK_VERSION(0,30,0) #if VA_CHECK_VERSION(0,30,0)
{ GST_VAAPI_ENTRYPOINT_SLICE_ENCODE, VAEntrypointEncSlice }, {GST_VAAPI_ENTRYPOINT_SLICE_ENCODE, VAEntrypointEncSlice},
{ GST_VAAPI_ENTRYPOINT_PICTURE_ENCODE, VAEntrypointEncPicture }, {GST_VAAPI_ENTRYPOINT_PICTURE_ENCODE, VAEntrypointEncPicture},
#endif #endif
{ 0, } {0,}
}; };
static const GstVaapiCodecMap * static const GstVaapiCodecMap *
get_codecs_map(GstVaapiCodec codec) get_codecs_map (GstVaapiCodec codec)
{ {
const GstVaapiCodecMap *m; const GstVaapiCodecMap *m;
for (m = gst_vaapi_codecs; m->codec; m++) for (m = gst_vaapi_codecs; m->codec; m++)
if (m->codec == codec) if (m->codec == codec)
return m; return m;
return NULL; return NULL;
} }
static const GstVaapiProfileMap * static const GstVaapiProfileMap *
get_profiles_map(GstVaapiProfile profile) get_profiles_map (GstVaapiProfile profile)
{ {
const GstVaapiProfileMap *m; const GstVaapiProfileMap *m;
for (m = gst_vaapi_profiles; m->profile; m++) for (m = gst_vaapi_profiles; m->profile; m++)
if (m->profile == profile) if (m->profile == profile)
return m; return m;
return NULL; return NULL;
} }
static const GstVaapiEntrypointMap * static const GstVaapiEntrypointMap *
get_entrypoints_map(GstVaapiEntrypoint entrypoint) get_entrypoints_map (GstVaapiEntrypoint entrypoint)
{ {
const GstVaapiEntrypointMap *m; const GstVaapiEntrypointMap *m;
for (m = gst_vaapi_entrypoints; m->entrypoint; m++) for (m = gst_vaapi_entrypoints; m->entrypoint; m++)
if (m->entrypoint == entrypoint) if (m->entrypoint == entrypoint)
return m; return m;
return NULL; return NULL;
} }
/** /**
@ -211,11 +192,11 @@ get_entrypoints_map(GstVaapiEntrypoint entrypoint)
* Return value: the statically allocated string representation of @codec * Return value: the statically allocated string representation of @codec
*/ */
const gchar * const gchar *
gst_vaapi_codec_get_name(GstVaapiCodec codec) gst_vaapi_codec_get_name (GstVaapiCodec codec)
{ {
const GstVaapiCodecMap * const m = get_codecs_map(codec); const GstVaapiCodecMap *const m = get_codecs_map (codec);
return m ? m->name : NULL; return m ? m->name : NULL;
} }
/** /**
@ -229,14 +210,14 @@ gst_vaapi_codec_get_name(GstVaapiCodec codec)
* Return value: the #GstVaapiProfile describing the @profile * Return value: the #GstVaapiProfile describing the @profile
*/ */
GstVaapiProfile GstVaapiProfile
gst_vaapi_profile(VAProfile profile) gst_vaapi_profile (VAProfile profile)
{ {
const GstVaapiProfileMap *m; const GstVaapiProfileMap *m;
for (m = gst_vaapi_profiles; m->profile; m++) for (m = gst_vaapi_profiles; m->profile; m++)
if (m->va_profile == profile) if (m->va_profile == profile)
return m->profile; return m->profile;
return 0; return 0;
} }
/** /**
@ -248,11 +229,11 @@ gst_vaapi_profile(VAProfile profile)
* Return value: the statically allocated string representation of @profile * Return value: the statically allocated string representation of @profile
*/ */
const gchar * const gchar *
gst_vaapi_profile_get_name(GstVaapiProfile profile) gst_vaapi_profile_get_name (GstVaapiProfile profile)
{ {
const GstVaapiProfileMap * const m = get_profiles_map(profile); const GstVaapiProfileMap *const m = get_profiles_map (profile);
return m ? m->profile_str : NULL; return m ? m->profile_str : NULL;
} }
/** /**
@ -266,11 +247,11 @@ gst_vaapi_profile_get_name(GstVaapiProfile profile)
* @profile media type * @profile media type
*/ */
const gchar * const gchar *
gst_vaapi_profile_get_media_type_name(GstVaapiProfile profile) gst_vaapi_profile_get_media_type_name (GstVaapiProfile profile)
{ {
const GstVaapiProfileMap * const m = get_profiles_map(profile); const GstVaapiProfileMap *const m = get_profiles_map (profile);
return m ? m->media_str : NULL; return m ? m->media_str : NULL;
} }
/** /**
@ -283,73 +264,81 @@ gst_vaapi_profile_get_media_type_name(GstVaapiProfile profile)
* Return value: the #GstVaapiProfile described in @buffer * Return value: the #GstVaapiProfile described in @buffer
*/ */
static GstVaapiProfile static GstVaapiProfile
gst_vaapi_profile_from_codec_data_h264(GstBuffer *buffer) gst_vaapi_profile_from_codec_data_h264 (GstBuffer * buffer)
{ {
/* MPEG-4 Part 15: Advanced Video Coding (AVC) file format */ /* MPEG-4 Part 15: Advanced Video Coding (AVC) file format */
guchar buf[3]; guchar buf[3];
if (gst_buffer_extract(buffer, 0, buf, sizeof(buf)) != sizeof(buf)) if (gst_buffer_extract (buffer, 0, buf, sizeof (buf)) != sizeof (buf))
return 0;
if (buf[0] != 1) /* configurationVersion = 1 */
return 0;
switch (buf[1]) { /* AVCProfileIndication */
case 66: return ((buf[2] & 0x40) ?
GST_VAAPI_PROFILE_H264_CONSTRAINED_BASELINE :
GST_VAAPI_PROFILE_H264_BASELINE);
case 77: return GST_VAAPI_PROFILE_H264_MAIN;
case 100: return GST_VAAPI_PROFILE_H264_HIGH;
case 118: return GST_VAAPI_PROFILE_H264_MULTIVIEW_HIGH;
case 128: return GST_VAAPI_PROFILE_H264_STEREO_HIGH;
}
return 0; return 0;
if (buf[0] != 1) /* configurationVersion = 1 */
return 0;
switch (buf[1]) { /* AVCProfileIndication */
case 66:
return ((buf[2] & 0x40) ?
GST_VAAPI_PROFILE_H264_CONSTRAINED_BASELINE :
GST_VAAPI_PROFILE_H264_BASELINE);
case 77:
return GST_VAAPI_PROFILE_H264_MAIN;
case 100:
return GST_VAAPI_PROFILE_H264_HIGH;
case 118:
return GST_VAAPI_PROFILE_H264_MULTIVIEW_HIGH;
case 128:
return GST_VAAPI_PROFILE_H264_STEREO_HIGH;
}
return 0;
} }
static GstVaapiProfile static GstVaapiProfile
gst_vaapi_profile_from_codec_data_h265(GstBuffer *buffer) gst_vaapi_profile_from_codec_data_h265 (GstBuffer * buffer)
{ {
/* ISO/IEC 14496-15: HEVC file format */ /* ISO/IEC 14496-15: HEVC file format */
guchar buf[3]; guchar buf[3];
if (gst_buffer_extract(buffer, 0, buf, sizeof(buf)) != sizeof(buf)) if (gst_buffer_extract (buffer, 0, buf, sizeof (buf)) != sizeof (buf))
return 0;
if (buf[0] != 1) /* configurationVersion = 1 */
return 0;
if (buf[1] & 0xc0) /* general_profile_space = 0 */
return 0;
switch (buf[1] & 0x1f) { /* HEVCProfileIndication */
case 1: return GST_VAAPI_PROFILE_H265_MAIN;
case 2: return GST_VAAPI_PROFILE_H265_MAIN10;
case 3: return GST_VAAPI_PROFILE_H265_MAIN_STILL_PICTURE;
}
return 0; return 0;
if (buf[0] != 1) /* configurationVersion = 1 */
return 0;
if (buf[1] & 0xc0) /* general_profile_space = 0 */
return 0;
switch (buf[1] & 0x1f) { /* HEVCProfileIndication */
case 1:
return GST_VAAPI_PROFILE_H265_MAIN;
case 2:
return GST_VAAPI_PROFILE_H265_MAIN10;
case 3:
return GST_VAAPI_PROFILE_H265_MAIN_STILL_PICTURE;
}
return 0;
} }
static GstVaapiProfile static GstVaapiProfile
gst_vaapi_profile_from_codec_data(GstVaapiCodec codec, GstBuffer *buffer) gst_vaapi_profile_from_codec_data (GstVaapiCodec codec, GstBuffer * buffer)
{ {
GstVaapiProfile profile; GstVaapiProfile profile;
if (!codec || !buffer) if (!codec || !buffer)
return 0; return 0;
switch (codec) { switch (codec) {
case GST_VAAPI_CODEC_H264: case GST_VAAPI_CODEC_H264:
profile = gst_vaapi_profile_from_codec_data_h264(buffer); profile = gst_vaapi_profile_from_codec_data_h264 (buffer);
break; break;
case GST_VAAPI_CODEC_H265: case GST_VAAPI_CODEC_H265:
profile = gst_vaapi_profile_from_codec_data_h265(buffer); profile = gst_vaapi_profile_from_codec_data_h265 (buffer);
break; break;
default: default:
profile = 0; profile = 0;
break; break;
} }
return profile; return profile;
} }
/** /**
@ -363,62 +352,60 @@ gst_vaapi_profile_from_codec_data(GstVaapiCodec codec, GstBuffer *buffer)
* Return value: the #GstVaapiProfile describing the @caps * Return value: the #GstVaapiProfile describing the @caps
*/ */
GstVaapiProfile GstVaapiProfile
gst_vaapi_profile_from_caps(const GstCaps *caps) gst_vaapi_profile_from_caps (const GstCaps * caps)
{ {
const GstVaapiProfileMap *m; const GstVaapiProfileMap *m;
GstCaps *caps_test; GstCaps *caps_test;
GstStructure *structure; GstStructure *structure;
const gchar *profile_str; const gchar *profile_str;
GstVaapiProfile profile, best_profile; GstVaapiProfile profile, best_profile;
GstBuffer *codec_data = NULL; GstBuffer *codec_data = NULL;
const gchar *name; const gchar *name;
gsize namelen; gsize namelen;
if (!caps) if (!caps)
return 0; return 0;
structure = gst_caps_get_structure(caps, 0); structure = gst_caps_get_structure (caps, 0);
if (!structure) if (!structure)
return 0; return 0;
name = gst_structure_get_name(structure); name = gst_structure_get_name (structure);
namelen = strlen(name); namelen = strlen (name);
profile_str = gst_structure_get_string(structure, "profile"); profile_str = gst_structure_get_string (structure, "profile");
if (!profile_str) { if (!profile_str) {
const GValue *v_codec_data; const GValue *v_codec_data;
v_codec_data = gst_structure_get_value(structure, "codec_data"); v_codec_data = gst_structure_get_value (structure, "codec_data");
if (v_codec_data) if (v_codec_data)
codec_data = gst_value_get_buffer(v_codec_data); codec_data = gst_value_get_buffer (v_codec_data);
}
profile = 0;
best_profile = 0;
for (m = gst_vaapi_profiles; !profile && m->profile; m++) {
if (strncmp (name, m->media_str, namelen) != 0)
continue;
caps_test = gst_caps_from_string (m->media_str);
if (gst_caps_is_always_compatible (caps, caps_test)) {
best_profile = m->profile;
if (profile_str && m->profile_str &&
strcmp (profile_str, m->profile_str) == 0)
profile = best_profile;
} }
if (!profile) {
profile = 0; profile =
best_profile = 0; gst_vaapi_profile_from_codec_data (gst_vaapi_profile_get_codec
for (m = gst_vaapi_profiles; !profile && m->profile; m++) { (m->profile), codec_data);
if (strncmp(name, m->media_str, namelen) != 0) if (!profile && WORKAROUND_QTDEMUX_NO_H263_PROFILES
continue; && strncmp (name, "video/x-h263", namelen) == 0) {
caps_test = gst_caps_from_string(m->media_str); /* HACK: qtdemux does not report profiles for h263 */
if (gst_caps_is_always_compatible(caps, caps_test)) { profile = m->profile;
best_profile = m->profile; }
if (profile_str && m->profile_str &&
strcmp(profile_str, m->profile_str) == 0)
profile = best_profile;
}
if (!profile) {
profile = gst_vaapi_profile_from_codec_data(
gst_vaapi_profile_get_codec(m->profile),
codec_data
);
if (!profile &&
WORKAROUND_QTDEMUX_NO_H263_PROFILES &&
strncmp(name, "video/x-h263", namelen) == 0) {
/* HACK: qtdemux does not report profiles for h263 */
profile = m->profile;
}
}
gst_caps_unref(caps_test);
} }
return profile ? profile : best_profile; gst_caps_unref (caps_test);
}
return profile ? profile : best_profile;
} }
/** /**
@ -432,11 +419,11 @@ gst_vaapi_profile_from_caps(const GstCaps *caps)
* Return value: the VA profile, or -1 if none was found * Return value: the VA profile, or -1 if none was found
*/ */
VAProfile VAProfile
gst_vaapi_profile_get_va_profile(GstVaapiProfile profile) gst_vaapi_profile_get_va_profile (GstVaapiProfile profile)
{ {
const GstVaapiProfileMap * const m = get_profiles_map(profile); const GstVaapiProfileMap *const m = get_profiles_map (profile);
return m ? m->va_profile : (VAProfile)-1; return m ? m->va_profile : (VAProfile) - 1;
} }
/** /**
@ -449,29 +436,25 @@ gst_vaapi_profile_get_va_profile(GstVaapiProfile profile)
* Return value: the newly allocated #GstCaps, or %NULL if none was found * Return value: the newly allocated #GstCaps, or %NULL if none was found
*/ */
GstCaps * GstCaps *
gst_vaapi_profile_get_caps(GstVaapiProfile profile) gst_vaapi_profile_get_caps (GstVaapiProfile profile)
{ {
const GstVaapiProfileMap *m; const GstVaapiProfileMap *m;
GstCaps *out_caps, *caps; GstCaps *out_caps, *caps;
out_caps = gst_caps_new_empty(); out_caps = gst_caps_new_empty ();
if (!out_caps) if (!out_caps)
return NULL; return NULL;
for (m = gst_vaapi_profiles; m->profile; m++) { for (m = gst_vaapi_profiles; m->profile; m++) {
if (m->profile != profile) if (m->profile != profile)
continue; continue;
caps = gst_caps_from_string(m->media_str); caps = gst_caps_from_string (m->media_str);
if (!caps) if (!caps)
continue; continue;
gst_caps_set_simple( gst_caps_set_simple (caps, "profile", G_TYPE_STRING, m->profile_str, NULL);
caps, out_caps = gst_caps_merge (out_caps, caps);
"profile", G_TYPE_STRING, m->profile_str, }
NULL return out_caps;
);
out_caps = gst_caps_merge(out_caps, caps);
}
return out_caps;
} }
/** /**
@ -483,26 +466,26 @@ gst_vaapi_profile_get_caps(GstVaapiProfile profile)
* Return value: the #GstVaapiCodec from @profile * Return value: the #GstVaapiCodec from @profile
*/ */
GstVaapiCodec GstVaapiCodec
gst_vaapi_profile_get_codec(GstVaapiProfile profile) gst_vaapi_profile_get_codec (GstVaapiProfile profile)
{ {
GstVaapiCodec codec; GstVaapiCodec codec;
switch (profile) { switch (profile) {
case GST_VAAPI_PROFILE_VC1_SIMPLE: case GST_VAAPI_PROFILE_VC1_SIMPLE:
case GST_VAAPI_PROFILE_VC1_MAIN: case GST_VAAPI_PROFILE_VC1_MAIN:
codec = GST_VAAPI_CODEC_WMV3; codec = GST_VAAPI_CODEC_WMV3;
break; break;
case GST_VAAPI_PROFILE_VC1_ADVANCED: case GST_VAAPI_PROFILE_VC1_ADVANCED:
codec = GST_VAAPI_CODEC_VC1; codec = GST_VAAPI_CODEC_VC1;
break; break;
case GST_VAAPI_PROFILE_JPEG_BASELINE: case GST_VAAPI_PROFILE_JPEG_BASELINE:
codec = GST_VAAPI_CODEC_JPEG; codec = GST_VAAPI_CODEC_JPEG;
break; break;
default: default:
codec = (guint32)profile & GST_MAKE_FOURCC(0xff,0xff,0xff,0); codec = (guint32) profile & GST_MAKE_FOURCC (0xff, 0xff, 0xff, 0);
break; break;
} }
return codec; return codec;
} }
/** /**
@ -516,14 +499,14 @@ gst_vaapi_profile_get_codec(GstVaapiProfile profile)
* Return value: the #GstVaapiEntrypoint describing the @entrypoint * Return value: the #GstVaapiEntrypoint describing the @entrypoint
*/ */
GstVaapiEntrypoint GstVaapiEntrypoint
gst_vaapi_entrypoint(VAEntrypoint entrypoint) gst_vaapi_entrypoint (VAEntrypoint entrypoint)
{ {
const GstVaapiEntrypointMap *m; const GstVaapiEntrypointMap *m;
for (m = gst_vaapi_entrypoints; m->entrypoint; m++) for (m = gst_vaapi_entrypoints; m->entrypoint; m++)
if (m->va_entrypoint == entrypoint) if (m->va_entrypoint == entrypoint)
return m->entrypoint; return m->entrypoint;
return 0; return 0;
} }
/** /**
@ -537,9 +520,9 @@ gst_vaapi_entrypoint(VAEntrypoint entrypoint)
* Return value: the VA entry-point, or -1 if none was found * Return value: the VA entry-point, or -1 if none was found
*/ */
VAEntrypoint VAEntrypoint
gst_vaapi_entrypoint_get_va_entrypoint(GstVaapiEntrypoint entrypoint) gst_vaapi_entrypoint_get_va_entrypoint (GstVaapiEntrypoint entrypoint)
{ {
const GstVaapiEntrypointMap * const m = get_entrypoints_map(entrypoint); const GstVaapiEntrypointMap *const m = get_entrypoints_map (entrypoint);
return m ? m->va_entrypoint : (VAEntrypoint)-1; return m ? m->va_entrypoint : (VAEntrypoint) - 1;
} }

View file

@ -38,20 +38,21 @@
#define DEBUG 1 #define DEBUG 1
#include "gstvaapidebug.h" #include "gstvaapidebug.h"
typedef struct _GstVaapiSubpictureClass GstVaapiSubpictureClass; typedef struct _GstVaapiSubpictureClass GstVaapiSubpictureClass;
/** /**
* GstVaapiSubpicture: * GstVaapiSubpicture:
* *
* A VA subpicture wrapper * A VA subpicture wrapper
*/ */
struct _GstVaapiSubpicture { struct _GstVaapiSubpicture
/*< private >*/ {
GstVaapiObject parent_instance; /*< private > */
GstVaapiObject parent_instance;
GstVaapiImage *image; GstVaapiImage *image;
guint flags; guint flags;
gfloat global_alpha; gfloat global_alpha;
}; };
/** /**
@ -59,66 +60,62 @@ struct _GstVaapiSubpicture {
* *
* A VA subpicture wrapper class * A VA subpicture wrapper class
*/ */
struct _GstVaapiSubpictureClass { struct _GstVaapiSubpictureClass
/*< private >*/ {
GstVaapiObjectClass parent_class; /*< private > */
GstVaapiObjectClass parent_class;
}; };
static void static void
gst_vaapi_subpicture_destroy(GstVaapiSubpicture *subpicture) gst_vaapi_subpicture_destroy (GstVaapiSubpicture * subpicture)
{ {
GstVaapiDisplay * const display = GST_VAAPI_OBJECT_DISPLAY(subpicture); GstVaapiDisplay *const display = GST_VAAPI_OBJECT_DISPLAY (subpicture);
VASubpictureID subpicture_id; VASubpictureID subpicture_id;
VAStatus status; VAStatus status;
subpicture_id = GST_VAAPI_OBJECT_ID(subpicture); subpicture_id = GST_VAAPI_OBJECT_ID (subpicture);
GST_DEBUG("subpicture %" GST_VAAPI_ID_FORMAT, GST_DEBUG ("subpicture %" GST_VAAPI_ID_FORMAT,
GST_VAAPI_ID_ARGS(subpicture_id)); GST_VAAPI_ID_ARGS (subpicture_id));
if (subpicture_id != VA_INVALID_ID) { if (subpicture_id != VA_INVALID_ID) {
if (display) { if (display) {
GST_VAAPI_DISPLAY_LOCK(display); GST_VAAPI_DISPLAY_LOCK (display);
status = vaDestroySubpicture( status = vaDestroySubpicture (GST_VAAPI_DISPLAY_VADISPLAY (display),
GST_VAAPI_DISPLAY_VADISPLAY(display), subpicture_id);
subpicture_id GST_VAAPI_DISPLAY_UNLOCK (display);
); if (!vaapi_check_status (status, "vaDestroySubpicture()"))
GST_VAAPI_DISPLAY_UNLOCK(display); g_warning ("failed to destroy subpicture %" GST_VAAPI_ID_FORMAT,
if (!vaapi_check_status(status, "vaDestroySubpicture()")) GST_VAAPI_ID_ARGS (subpicture_id));
g_warning("failed to destroy subpicture %" GST_VAAPI_ID_FORMAT,
GST_VAAPI_ID_ARGS(subpicture_id));
}
GST_VAAPI_OBJECT_ID(subpicture) = VA_INVALID_ID;
} }
gst_vaapi_object_replace(&subpicture->image, NULL); GST_VAAPI_OBJECT_ID (subpicture) = VA_INVALID_ID;
}
gst_vaapi_object_replace (&subpicture->image, NULL);
} }
static gboolean static gboolean
gst_vaapi_subpicture_create(GstVaapiSubpicture *subpicture, gst_vaapi_subpicture_create (GstVaapiSubpicture * subpicture,
GstVaapiImage *image) GstVaapiImage * image)
{ {
GstVaapiDisplay * const display = GST_VAAPI_OBJECT_DISPLAY(subpicture); GstVaapiDisplay *const display = GST_VAAPI_OBJECT_DISPLAY (subpicture);
VASubpictureID subpicture_id; VASubpictureID subpicture_id;
VAStatus status; VAStatus status;
GST_VAAPI_DISPLAY_LOCK(display); GST_VAAPI_DISPLAY_LOCK (display);
status = vaCreateSubpicture( status = vaCreateSubpicture (GST_VAAPI_DISPLAY_VADISPLAY (display),
GST_VAAPI_DISPLAY_VADISPLAY(display), GST_VAAPI_OBJECT_ID (image), &subpicture_id);
GST_VAAPI_OBJECT_ID(image), GST_VAAPI_DISPLAY_UNLOCK (display);
&subpicture_id if (!vaapi_check_status (status, "vaCreateSubpicture()"))
); return FALSE;
GST_VAAPI_DISPLAY_UNLOCK(display);
if (!vaapi_check_status(status, "vaCreateSubpicture()"))
return FALSE;
GST_DEBUG("subpicture %" GST_VAAPI_ID_FORMAT, GST_DEBUG ("subpicture %" GST_VAAPI_ID_FORMAT,
GST_VAAPI_ID_ARGS(subpicture_id)); GST_VAAPI_ID_ARGS (subpicture_id));
GST_VAAPI_OBJECT_ID(subpicture) = subpicture_id; GST_VAAPI_OBJECT_ID (subpicture) = subpicture_id;
subpicture->image = gst_vaapi_object_ref(image); subpicture->image = gst_vaapi_object_ref (image);
return TRUE; return TRUE;
} }
#define gst_vaapi_subpicture_finalize gst_vaapi_subpicture_destroy #define gst_vaapi_subpicture_finalize gst_vaapi_subpicture_destroy
GST_VAAPI_OBJECT_DEFINE_CLASS(GstVaapiSubpicture, gst_vaapi_subpicture) GST_VAAPI_OBJECT_DEFINE_CLASS (GstVaapiSubpicture, gst_vaapi_subpicture)
/** /**
* gst_vaapi_subpicture_new: * gst_vaapi_subpicture_new:
@ -130,38 +127,38 @@ GST_VAAPI_OBJECT_DEFINE_CLASS(GstVaapiSubpicture, gst_vaapi_subpicture)
* *
* Return value: the newly allocated #GstVaapiSubpicture object * Return value: the newly allocated #GstVaapiSubpicture object
*/ */
GstVaapiSubpicture * GstVaapiSubpicture *gst_vaapi_subpicture_new (GstVaapiImage * image,
gst_vaapi_subpicture_new(GstVaapiImage *image, guint flags) guint flags)
{ {
GstVaapiSubpicture *subpicture; GstVaapiSubpicture *subpicture;
GstVaapiDisplay *display; GstVaapiDisplay *display;
GstVideoFormat format; GstVideoFormat format;
guint va_flags; guint va_flags;
g_return_val_if_fail(image != NULL, NULL); g_return_val_if_fail (image != NULL, NULL);
GST_DEBUG("create from image %" GST_VAAPI_ID_FORMAT, GST_DEBUG ("create from image %" GST_VAAPI_ID_FORMAT,
GST_VAAPI_ID_ARGS(GST_VAAPI_OBJECT_ID(image))); GST_VAAPI_ID_ARGS (GST_VAAPI_OBJECT_ID (image)));
display = GST_VAAPI_OBJECT_DISPLAY(image); display = GST_VAAPI_OBJECT_DISPLAY (image);
format = GST_VAAPI_IMAGE_FORMAT(image); format = GST_VAAPI_IMAGE_FORMAT (image);
if (!gst_vaapi_display_has_subpicture_format(display, format, &va_flags)) if (!gst_vaapi_display_has_subpicture_format (display, format, &va_flags))
return NULL; return NULL;
if (flags & ~va_flags) if (flags & ~va_flags)
return NULL; return NULL;
subpicture = gst_vaapi_object_new(gst_vaapi_subpicture_class(), display); subpicture = gst_vaapi_object_new (gst_vaapi_subpicture_class (), display);
if (!subpicture) if (!subpicture)
return NULL; return NULL;
subpicture->global_alpha = 1.0f; subpicture->global_alpha = 1.0f;
if (!gst_vaapi_subpicture_set_image(subpicture, image)) if (!gst_vaapi_subpicture_set_image (subpicture, image))
goto error; goto error;
return subpicture; return subpicture;
error: error:
gst_vaapi_object_unref(subpicture); gst_vaapi_object_unref (subpicture);
return NULL; return NULL;
} }
/** /**
@ -177,80 +174,80 @@ error:
* Return value: the newly allocated #GstVaapiSubpicture object * Return value: the newly allocated #GstVaapiSubpicture object
*/ */
GstVaapiSubpicture * GstVaapiSubpicture *
gst_vaapi_subpicture_new_from_overlay_rectangle( gst_vaapi_subpicture_new_from_overlay_rectangle (GstVaapiDisplay * display,
GstVaapiDisplay *display, GstVideoOverlayRectangle * rect)
GstVideoOverlayRectangle *rect
)
{ {
GstVaapiSubpicture *subpicture; GstVaapiSubpicture *subpicture;
GstVideoFormat format; GstVideoFormat format;
GstVaapiImage *image; GstVaapiImage *image;
GstVaapiImageRaw raw_image; GstVaapiImageRaw raw_image;
GstBuffer *buffer; GstBuffer *buffer;
guint8 *data; guint8 *data;
gfloat global_alpha; gfloat global_alpha;
guint width, height, stride; guint width, height, stride;
guint hw_flags, flags; guint hw_flags, flags;
GstVideoMeta *vmeta; GstVideoMeta *vmeta;
GstMapInfo map_info; GstMapInfo map_info;
g_return_val_if_fail(GST_IS_VIDEO_OVERLAY_RECTANGLE(rect), NULL); g_return_val_if_fail (GST_IS_VIDEO_OVERLAY_RECTANGLE (rect), NULL);
/* XXX: use gst_vaapi_image_format_from_video() */ /* XXX: use gst_vaapi_image_format_from_video() */
#if G_BYTE_ORDER == G_LITTLE_ENDIAN #if G_BYTE_ORDER == G_LITTLE_ENDIAN
format = GST_VIDEO_FORMAT_BGRA; format = GST_VIDEO_FORMAT_BGRA;
#else #else
format = GST_VIDEO_FORMAT_ARGB; format = GST_VIDEO_FORMAT_ARGB;
#endif #endif
if (!gst_vaapi_display_has_subpicture_format(display, format, &hw_flags)) if (!gst_vaapi_display_has_subpicture_format (display, format, &hw_flags))
return NULL; return NULL;
flags = hw_flags & from_GstVideoOverlayFormatFlags( flags =
gst_video_overlay_rectangle_get_flags(rect)); hw_flags &
from_GstVideoOverlayFormatFlags (gst_video_overlay_rectangle_get_flags
(rect));
buffer = gst_video_overlay_rectangle_get_pixels_unscaled_argb(rect, buffer = gst_video_overlay_rectangle_get_pixels_unscaled_argb (rect,
to_GstVideoOverlayFormatFlags(flags)); to_GstVideoOverlayFormatFlags (flags));
if (!buffer) if (!buffer)
return NULL; return NULL;
vmeta = gst_buffer_get_video_meta(buffer); vmeta = gst_buffer_get_video_meta (buffer);
if (!vmeta) if (!vmeta)
return NULL; return NULL;
width = vmeta->width; width = vmeta->width;
height = vmeta->height; height = vmeta->height;
if (!gst_video_meta_map(vmeta, 0, &map_info, (gpointer *)&data, if (!gst_video_meta_map (vmeta, 0, &map_info, (gpointer *) & data,
(gint *)&stride, GST_MAP_READ)) (gint *) & stride, GST_MAP_READ))
return NULL; return NULL;
image = gst_vaapi_image_new(display, format, width, height); image = gst_vaapi_image_new (display, format, width, height);
if (!image) if (!image)
return NULL; return NULL;
raw_image.format = format; raw_image.format = format;
raw_image.width = width; raw_image.width = width;
raw_image.height = height; raw_image.height = height;
raw_image.num_planes = 1; raw_image.num_planes = 1;
raw_image.pixels[0] = data; raw_image.pixels[0] = data;
raw_image.stride[0] = stride; raw_image.stride[0] = stride;
if (!gst_vaapi_image_update_from_raw(image, &raw_image, NULL)) { if (!gst_vaapi_image_update_from_raw (image, &raw_image, NULL)) {
GST_WARNING("could not update VA image with subtitle data"); GST_WARNING ("could not update VA image with subtitle data");
gst_vaapi_object_unref(image); gst_vaapi_object_unref (image);
return NULL; return NULL;
} }
subpicture = gst_vaapi_subpicture_new(image, flags); subpicture = gst_vaapi_subpicture_new (image, flags);
gst_vaapi_object_unref(image); gst_vaapi_object_unref (image);
gst_video_meta_unmap(vmeta, 0, &map_info); gst_video_meta_unmap (vmeta, 0, &map_info);
if (!subpicture) if (!subpicture)
return NULL; return NULL;
if (flags & GST_VAAPI_SUBPICTURE_FLAG_GLOBAL_ALPHA) { if (flags & GST_VAAPI_SUBPICTURE_FLAG_GLOBAL_ALPHA) {
global_alpha = gst_video_overlay_rectangle_get_global_alpha(rect); global_alpha = gst_video_overlay_rectangle_get_global_alpha (rect);
if (!gst_vaapi_subpicture_set_global_alpha(subpicture, global_alpha)) if (!gst_vaapi_subpicture_set_global_alpha (subpicture, global_alpha))
return NULL; return NULL;
} }
return subpicture; return subpicture;
} }
/** /**
@ -262,11 +259,11 @@ gst_vaapi_subpicture_new_from_overlay_rectangle(
* Return value: the underlying VA subpicture id * Return value: the underlying VA subpicture id
*/ */
GstVaapiID GstVaapiID
gst_vaapi_subpicture_get_id(GstVaapiSubpicture *subpicture) gst_vaapi_subpicture_get_id (GstVaapiSubpicture * subpicture)
{ {
g_return_val_if_fail(subpicture != NULL, VA_INVALID_ID); g_return_val_if_fail (subpicture != NULL, VA_INVALID_ID);
return GST_VAAPI_OBJECT_ID(subpicture); return GST_VAAPI_OBJECT_ID (subpicture);
} }
/** /**
@ -278,11 +275,11 @@ gst_vaapi_subpicture_get_id(GstVaapiSubpicture *subpicture)
* Return value: the @subpicture flags * Return value: the @subpicture flags
*/ */
guint guint
gst_vaapi_subpicture_get_flags(GstVaapiSubpicture *subpicture) gst_vaapi_subpicture_get_flags (GstVaapiSubpicture * subpicture)
{ {
g_return_val_if_fail(subpicture != NULL, 0); g_return_val_if_fail (subpicture != NULL, 0);
return subpicture->flags; return subpicture->flags;
} }
/** /**
@ -294,11 +291,11 @@ gst_vaapi_subpicture_get_flags(GstVaapiSubpicture *subpicture)
* Return value: the #GstVaapiImage this @subpicture is bound to * Return value: the #GstVaapiImage this @subpicture is bound to
*/ */
GstVaapiImage * GstVaapiImage *
gst_vaapi_subpicture_get_image(GstVaapiSubpicture *subpicture) gst_vaapi_subpicture_get_image (GstVaapiSubpicture * subpicture)
{ {
g_return_val_if_fail(subpicture != NULL, NULL); g_return_val_if_fail (subpicture != NULL, NULL);
return subpicture->image; return subpicture->image;
} }
/** /**
@ -312,14 +309,14 @@ gst_vaapi_subpicture_get_image(GstVaapiSubpicture *subpicture)
* Return value: %TRUE on success * Return value: %TRUE on success
*/ */
gboolean gboolean
gst_vaapi_subpicture_set_image(GstVaapiSubpicture *subpicture, gst_vaapi_subpicture_set_image (GstVaapiSubpicture * subpicture,
GstVaapiImage *image) GstVaapiImage * image)
{ {
g_return_val_if_fail(subpicture != NULL, FALSE); g_return_val_if_fail (subpicture != NULL, FALSE);
g_return_val_if_fail(image != NULL, FALSE); g_return_val_if_fail (image != NULL, FALSE);
gst_vaapi_subpicture_destroy(subpicture); gst_vaapi_subpicture_destroy (subpicture);
return gst_vaapi_subpicture_create(subpicture, image); return gst_vaapi_subpicture_create (subpicture, image);
} }
/** /**
@ -331,11 +328,11 @@ gst_vaapi_subpicture_set_image(GstVaapiSubpicture *subpicture,
* Return value: the global_alpha value of this @subpicture * Return value: the global_alpha value of this @subpicture
*/ */
gfloat gfloat
gst_vaapi_subpicture_get_global_alpha(GstVaapiSubpicture *subpicture) gst_vaapi_subpicture_get_global_alpha (GstVaapiSubpicture * subpicture)
{ {
g_return_val_if_fail(subpicture != NULL, 1.0); g_return_val_if_fail (subpicture != NULL, 1.0);
return subpicture->global_alpha; return subpicture->global_alpha;
} }
/** /**
@ -350,32 +347,29 @@ gst_vaapi_subpicture_get_global_alpha(GstVaapiSubpicture *subpicture)
* Return value: %TRUE if global_alpha could be set, %FALSE otherwise * Return value: %TRUE if global_alpha could be set, %FALSE otherwise
*/ */
gboolean gboolean
gst_vaapi_subpicture_set_global_alpha(GstVaapiSubpicture *subpicture, gst_vaapi_subpicture_set_global_alpha (GstVaapiSubpicture * subpicture,
gfloat global_alpha) gfloat global_alpha)
{ {
GstVaapiDisplay *display; GstVaapiDisplay *display;
VAStatus status; VAStatus status;
g_return_val_if_fail(subpicture != NULL, FALSE); g_return_val_if_fail (subpicture != NULL, FALSE);
if (!(subpicture->flags & GST_VAAPI_SUBPICTURE_FLAG_GLOBAL_ALPHA)) if (!(subpicture->flags & GST_VAAPI_SUBPICTURE_FLAG_GLOBAL_ALPHA))
return FALSE; return FALSE;
if (subpicture->global_alpha == global_alpha) if (subpicture->global_alpha == global_alpha)
return TRUE;
display = GST_VAAPI_OBJECT_DISPLAY(subpicture);
GST_VAAPI_DISPLAY_LOCK(display);
status = vaSetSubpictureGlobalAlpha(
GST_VAAPI_DISPLAY_VADISPLAY(display),
GST_VAAPI_OBJECT_ID(subpicture),
global_alpha
);
GST_VAAPI_DISPLAY_UNLOCK(display);
if (!vaapi_check_status(status, "vaSetSubpictureGlobalAlpha()"))
return FALSE;
subpicture->global_alpha = global_alpha;
return TRUE; return TRUE;
display = GST_VAAPI_OBJECT_DISPLAY (subpicture);
GST_VAAPI_DISPLAY_LOCK (display);
status = vaSetSubpictureGlobalAlpha (GST_VAAPI_DISPLAY_VADISPLAY (display),
GST_VAAPI_OBJECT_ID (subpicture), global_alpha);
GST_VAAPI_DISPLAY_UNLOCK (display);
if (!vaapi_check_status (status, "vaSetSubpictureGlobalAlpha()"))
return FALSE;
subpicture->global_alpha = global_alpha;
return TRUE;
} }