mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-23 14:36:24 +00:00
dpb: cosmetics (clean-ups).
This commit is contained in:
parent
e44d8ee6e3
commit
9372f14f94
1 changed files with 105 additions and 125 deletions
|
@ -70,20 +70,18 @@ static const GstVaapiMiniObjectClass *
|
||||||
gst_vaapi_dpb2_class(void);
|
gst_vaapi_dpb2_class(void);
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
/* --- Common Decoded Picture Buffer utilities --- */
|
/* --- Common utilities --- */
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static GstVaapiDpb *
|
static inline GstVaapiDpb *
|
||||||
dpb_new(guint max_pictures)
|
dpb_new(guint max_pictures)
|
||||||
{
|
{
|
||||||
const GstVaapiMiniObjectClass *klass;
|
|
||||||
GstVaapiDpb *dpb;
|
GstVaapiDpb *dpb;
|
||||||
|
|
||||||
g_return_val_if_fail(max_pictures > 0, NULL);
|
g_return_val_if_fail(max_pictures > 0, NULL);
|
||||||
|
|
||||||
klass = max_pictures == 2 ? gst_vaapi_dpb2_class() : gst_vaapi_dpb_class();
|
dpb = (GstVaapiDpb *)gst_vaapi_mini_object_new(
|
||||||
|
max_pictures == 2 ? gst_vaapi_dpb2_class() : gst_vaapi_dpb_class());
|
||||||
dpb = (GstVaapiDpb *)gst_vaapi_mini_object_new(klass);
|
|
||||||
if (!dpb)
|
if (!dpb)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -166,20 +164,20 @@ dpb_clear(GstVaapiDpb *dpb)
|
||||||
dpb->num_pictures = 0;
|
dpb->num_pictures = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
|
||||||
/* --- Base Decoded Picture Buffer --- */
|
|
||||||
/* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_vaapi_dpb_base_flush(GstVaapiDpb *dpb)
|
dpb_flush(GstVaapiDpb *dpb)
|
||||||
{
|
{
|
||||||
while (dpb_bump(dpb))
|
while (dpb_bump(dpb))
|
||||||
;
|
;
|
||||||
dpb_clear(dpb);
|
dpb_clear(dpb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
/* --- Generic implementation --- */
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_vaapi_dpb_base_add(GstVaapiDpb *dpb, GstVaapiPicture *picture)
|
dpb_add(GstVaapiDpb *dpb, GstVaapiPicture *picture)
|
||||||
{
|
{
|
||||||
guint i;
|
guint i;
|
||||||
|
|
||||||
|
@ -222,13 +220,9 @@ gst_vaapi_dpb_base_add(GstVaapiDpb *dpb, GstVaapiPicture *picture)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
gst_vaapi_dpb_base_get_neighbours(
|
dpb_get_neighbours(GstVaapiDpb *dpb, GstVaapiPicture *picture,
|
||||||
GstVaapiDpb *dpb,
|
GstVaapiPicture **prev_picture_ptr, GstVaapiPicture **next_picture_ptr)
|
||||||
GstVaapiPicture *picture,
|
|
||||||
GstVaapiPicture **prev_picture_ptr,
|
|
||||||
GstVaapiPicture **next_picture_ptr
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
GstVaapiPicture *prev_picture = NULL;
|
GstVaapiPicture *prev_picture = NULL;
|
||||||
GstVaapiPicture *next_picture = NULL;
|
GstVaapiPicture *next_picture = NULL;
|
||||||
|
@ -261,13 +255,82 @@ gst_vaapi_dpb_base_get_neighbours(
|
||||||
*next_picture_ptr = next_picture;
|
*next_picture_ptr = next_picture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
/* --- Optimized implementation for 2 reference pictures --- */
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
dpb2_add(GstVaapiDpb *dpb, GstVaapiPicture *picture)
|
||||||
|
{
|
||||||
|
GstVaapiPicture *ref_picture;
|
||||||
|
gint index = -1;
|
||||||
|
|
||||||
|
g_return_val_if_fail(GST_VAAPI_IS_DPB(dpb), FALSE);
|
||||||
|
g_return_val_if_fail(dpb->max_pictures == 2, FALSE);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Purpose: only store reference decoded pictures into the DPB
|
||||||
|
*
|
||||||
|
* This means:
|
||||||
|
* - non-reference decoded pictures are output immediately
|
||||||
|
* - ... thus causing older reference pictures to be output, if not already
|
||||||
|
* - the oldest reference picture is replaced with the new reference picture
|
||||||
|
*/
|
||||||
|
if (G_LIKELY(dpb->num_pictures == 2)) {
|
||||||
|
index = (dpb->pictures[0]->poc > dpb->pictures[1]->poc);
|
||||||
|
ref_picture = dpb->pictures[index];
|
||||||
|
if (!GST_VAAPI_PICTURE_IS_OUTPUT(ref_picture)) {
|
||||||
|
if (!dpb_output(dpb, ref_picture))
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!GST_VAAPI_PICTURE_IS_REFERENCE(picture))
|
||||||
|
return dpb_output(dpb, picture);
|
||||||
|
|
||||||
|
if (index < 0)
|
||||||
|
index = dpb->num_pictures++;
|
||||||
|
gst_vaapi_picture_replace(&dpb->pictures[index], picture);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
dpb2_get_neighbours(GstVaapiDpb *dpb, GstVaapiPicture *picture,
|
||||||
|
GstVaapiPicture **prev_picture_ptr, GstVaapiPicture **next_picture_ptr)
|
||||||
|
{
|
||||||
|
GstVaapiPicture *ref_picture, *ref_pictures[2];
|
||||||
|
GstVaapiPicture **picture_ptr;
|
||||||
|
guint i, index;
|
||||||
|
|
||||||
|
g_return_if_fail(GST_VAAPI_IS_DPB(dpb));
|
||||||
|
g_return_if_fail(dpb->max_pictures == 2);
|
||||||
|
g_return_if_fail(GST_VAAPI_IS_PICTURE(picture));
|
||||||
|
|
||||||
|
ref_pictures[0] = NULL;
|
||||||
|
ref_pictures[1] = NULL;
|
||||||
|
for (i = 0; i < dpb->num_pictures; i++) {
|
||||||
|
ref_picture = dpb->pictures[i];
|
||||||
|
index = ref_picture->poc > picture->poc;
|
||||||
|
picture_ptr = &ref_pictures[index];
|
||||||
|
if (!*picture_ptr || ((*picture_ptr)->poc > ref_picture->poc) == index)
|
||||||
|
*picture_ptr = ref_picture;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prev_picture_ptr)
|
||||||
|
*prev_picture_ptr = ref_pictures[0];
|
||||||
|
if (next_picture_ptr)
|
||||||
|
*next_picture_ptr = ref_pictures[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
/* --- Interface --- */
|
||||||
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_vaapi_dpb_finalize(GstVaapiDpb *dpb)
|
gst_vaapi_dpb_finalize(GstVaapiDpb *dpb)
|
||||||
{
|
{
|
||||||
if (dpb->pictures) {
|
dpb_clear(dpb);
|
||||||
dpb_clear(dpb);
|
g_free(dpb->pictures);
|
||||||
g_free(dpb->pictures);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const GstVaapiMiniObjectClass *
|
static const GstVaapiMiniObjectClass *
|
||||||
|
@ -277,13 +340,27 @@ gst_vaapi_dpb_class(void)
|
||||||
{ sizeof(GstVaapiDpb),
|
{ sizeof(GstVaapiDpb),
|
||||||
(GDestroyNotify)gst_vaapi_dpb_finalize },
|
(GDestroyNotify)gst_vaapi_dpb_finalize },
|
||||||
|
|
||||||
gst_vaapi_dpb_base_flush,
|
dpb_flush,
|
||||||
gst_vaapi_dpb_base_add,
|
dpb_add,
|
||||||
gst_vaapi_dpb_base_get_neighbours
|
dpb_get_neighbours
|
||||||
};
|
};
|
||||||
return &GstVaapiDpbClass.parent_class;
|
return &GstVaapiDpbClass.parent_class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const GstVaapiMiniObjectClass *
|
||||||
|
gst_vaapi_dpb2_class(void)
|
||||||
|
{
|
||||||
|
static const GstVaapiDpbClass GstVaapiDpb2Class = {
|
||||||
|
{ sizeof(GstVaapiDpb),
|
||||||
|
(GDestroyNotify)gst_vaapi_dpb_finalize },
|
||||||
|
|
||||||
|
dpb_flush,
|
||||||
|
dpb2_add,
|
||||||
|
dpb2_get_neighbours
|
||||||
|
};
|
||||||
|
return &GstVaapiDpb2Class.parent_class;
|
||||||
|
}
|
||||||
|
|
||||||
GstVaapiDpb *
|
GstVaapiDpb *
|
||||||
gst_vaapi_dpb_new(guint max_pictures)
|
gst_vaapi_dpb_new(guint max_pictures)
|
||||||
{
|
{
|
||||||
|
@ -326,12 +403,8 @@ gst_vaapi_dpb_size(GstVaapiDpb *dpb)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gst_vaapi_dpb_get_neighbours(
|
gst_vaapi_dpb_get_neighbours(GstVaapiDpb *dpb, GstVaapiPicture *picture,
|
||||||
GstVaapiDpb *dpb,
|
GstVaapiPicture **prev_picture_ptr, GstVaapiPicture **next_picture_ptr)
|
||||||
GstVaapiPicture *picture,
|
|
||||||
GstVaapiPicture **prev_picture_ptr,
|
|
||||||
GstVaapiPicture **next_picture_ptr
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
const GstVaapiDpbClass *klass;
|
const GstVaapiDpbClass *klass;
|
||||||
|
|
||||||
|
@ -343,96 +416,3 @@ gst_vaapi_dpb_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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
|
||||||
/* --- Decoded Picture Buffer (optimized for 2 reference pictures) --- */
|
|
||||||
/* ------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_vaapi_dpb2_get_neighbours(
|
|
||||||
GstVaapiDpb *dpb,
|
|
||||||
GstVaapiPicture *picture,
|
|
||||||
GstVaapiPicture **prev_picture_ptr,
|
|
||||||
GstVaapiPicture **next_picture_ptr
|
|
||||||
);
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
gst_vaapi_dpb2_add(GstVaapiDpb *dpb, GstVaapiPicture *picture)
|
|
||||||
{
|
|
||||||
GstVaapiPicture *ref_picture;
|
|
||||||
gint index = -1;
|
|
||||||
|
|
||||||
g_return_val_if_fail(GST_VAAPI_IS_DPB(dpb), FALSE);
|
|
||||||
g_return_val_if_fail(dpb->max_pictures == 2, FALSE);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Purpose: only store reference decoded pictures into the DPB
|
|
||||||
*
|
|
||||||
* This means:
|
|
||||||
* - non-reference decoded pictures are output immediately
|
|
||||||
* - ... thus causing older reference pictures to be output, if not already
|
|
||||||
* - the oldest reference picture is replaced with the new reference picture
|
|
||||||
*/
|
|
||||||
if (G_LIKELY(dpb->num_pictures == 2)) {
|
|
||||||
index = (dpb->pictures[0]->poc > dpb->pictures[1]->poc);
|
|
||||||
ref_picture = dpb->pictures[index];
|
|
||||||
if (!GST_VAAPI_PICTURE_IS_OUTPUT(ref_picture)) {
|
|
||||||
if (!dpb_output(dpb, ref_picture))
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!GST_VAAPI_PICTURE_IS_REFERENCE(picture))
|
|
||||||
return dpb_output(dpb, picture);
|
|
||||||
|
|
||||||
if (index < 0)
|
|
||||||
index = dpb->num_pictures++;
|
|
||||||
gst_vaapi_picture_replace(&dpb->pictures[index], picture);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const GstVaapiMiniObjectClass *
|
|
||||||
gst_vaapi_dpb2_class(void)
|
|
||||||
{
|
|
||||||
static const GstVaapiDpbClass GstVaapiDpb2Class = {
|
|
||||||
{ sizeof(GstVaapiDpb),
|
|
||||||
(GDestroyNotify)gst_vaapi_dpb_finalize },
|
|
||||||
|
|
||||||
gst_vaapi_dpb_base_flush,
|
|
||||||
gst_vaapi_dpb2_add,
|
|
||||||
gst_vaapi_dpb2_get_neighbours
|
|
||||||
};
|
|
||||||
return &GstVaapiDpb2Class.parent_class;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
gst_vaapi_dpb2_get_neighbours(
|
|
||||||
GstVaapiDpb *dpb,
|
|
||||||
GstVaapiPicture *picture,
|
|
||||||
GstVaapiPicture **prev_picture_ptr,
|
|
||||||
GstVaapiPicture **next_picture_ptr
|
|
||||||
)
|
|
||||||
{
|
|
||||||
GstVaapiPicture *ref_picture, *ref_pictures[2];
|
|
||||||
GstVaapiPicture **picture_ptr;
|
|
||||||
guint i, index;
|
|
||||||
|
|
||||||
g_return_if_fail(GST_VAAPI_IS_DPB(dpb));
|
|
||||||
g_return_if_fail(dpb->max_pictures == 2);
|
|
||||||
g_return_if_fail(GST_VAAPI_IS_PICTURE(picture));
|
|
||||||
|
|
||||||
ref_pictures[0] = NULL;
|
|
||||||
ref_pictures[1] = NULL;
|
|
||||||
for (i = 0; i < dpb->num_pictures; i++) {
|
|
||||||
ref_picture = dpb->pictures[i];
|
|
||||||
index = ref_picture->poc > picture->poc;
|
|
||||||
picture_ptr = &ref_pictures[index];
|
|
||||||
if (!*picture_ptr || ((*picture_ptr)->poc > ref_picture->poc) == index)
|
|
||||||
*picture_ptr = ref_picture;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prev_picture_ptr)
|
|
||||||
*prev_picture_ptr = ref_pictures[0];
|
|
||||||
if (next_picture_ptr)
|
|
||||||
*next_picture_ptr = ref_pictures[1];
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue