h264: move MMCO handlers out of the loop (cosmetics).

This change only splits each individual MMCO handler into several functions
dedicated for each operation. This is needed to perform further work later
on.
This commit is contained in:
Gwenole Beauchesne 2012-10-22 10:50:29 +02:00
parent a39a709d2d
commit 04bbd8cc11

View file

@ -1671,6 +1671,84 @@ exec_ref_pic_marking_sliding_window(GstVaapiDecoderH264 *decoder)
return TRUE; return TRUE;
} }
static inline gint32
get_picNumX(GstVaapiPictureH264 *picture, GstH264RefPicMarking *ref_pic_marking)
{
gint32 pic_num;
if (!picture->field_pic_flag)
pic_num = picture->frame_num_wrap;
else
pic_num = 2 * picture->frame_num_wrap + 1;
pic_num -= ref_pic_marking->difference_of_pic_nums_minus1 + 1;
return pic_num;
}
/* 8.2.5.4.1. Mark-term reference picture as "unused for reference" */
static void
exec_ref_pic_marking_adaptive_mmco_1(
GstVaapiDecoderH264 *decoder,
GstVaapiPictureH264 *picture,
GstH264RefPicMarking *ref_pic_marking
)
{
GstVaapiDecoderH264Private * const priv = decoder->priv;
gint32 i, picNumX;
picNumX = get_picNumX(picture, ref_pic_marking);
i = find_short_term_reference(decoder, picNumX);
if (i < 0)
return;
remove_reference_at(decoder, priv->short_ref, &priv->short_ref_count, i);
}
/* 8.2.5.4.2. Mark long-term reference picture as "unused for reference" */
static void
exec_ref_pic_marking_adaptive_mmco_2(
GstVaapiDecoderH264 *decoder,
GstVaapiPictureH264 *picture,
GstH264RefPicMarking *ref_pic_marking
)
{
GstVaapiDecoderH264Private * const priv = decoder->priv;
gint32 i;
i = find_long_term_reference(decoder, picture->long_term_pic_num);
if (i < 0)
return;
remove_reference_at(decoder, priv->long_ref, &priv->long_ref_count, i);
}
/* 8.2.5.4.3. Assign LongTermFrameIdx to a short-term reference picture */
static void
exec_ref_pic_marking_adaptive_mmco_3(
GstVaapiDecoderH264 *decoder,
GstVaapiPictureH264 *picture,
GstH264RefPicMarking *ref_pic_marking
)
{
gint32 i, picNumX;
picNumX = get_picNumX(picture, ref_pic_marking);
i = find_short_term_reference(decoder, picNumX);
if (i < 0)
return;
}
/* 8.2.5.4.5. Mark all reference pictures as "unused for reference" */
static void
exec_ref_pic_marking_adaptive_mmco_5(
GstVaapiDecoderH264 *decoder,
GstVaapiPictureH264 *picture,
GstH264RefPicMarking *ref_pic_marking
)
{
GstVaapiDecoderH264Private * const priv = decoder->priv;
clear_references(decoder, priv->short_ref, &priv->short_ref_count);
clear_references(decoder, priv->long_ref, &priv->long_ref_count );
}
/* 8.2.5.4. Adaptive memory control decoded reference picture marking process */ /* 8.2.5.4. Adaptive memory control decoded reference picture marking process */
static gboolean static gboolean
exec_ref_pic_marking_adaptive( exec_ref_pic_marking_adaptive(
@ -1679,64 +1757,35 @@ exec_ref_pic_marking_adaptive(
GstH264DecRefPicMarking *dec_ref_pic_marking GstH264DecRefPicMarking *dec_ref_pic_marking
) )
{ {
GstVaapiDecoderH264Private * const priv = decoder->priv;
gint32 pic_num, ref_idx;
guint i; guint i;
GST_DEBUG("reference picture marking process (adaptive memory control)"); GST_DEBUG("reference picture marking process (adaptive memory control)");
typedef void (*exec_ref_pic_marking_adaptive_mmco_func)(
GstVaapiDecoderH264 *decoder,
GstVaapiPictureH264 *picture,
GstH264RefPicMarking *ref_pic_marking
);
static const exec_ref_pic_marking_adaptive_mmco_func mmco_funcs[] = {
NULL,
exec_ref_pic_marking_adaptive_mmco_1,
exec_ref_pic_marking_adaptive_mmco_2,
exec_ref_pic_marking_adaptive_mmco_3,
NULL,
exec_ref_pic_marking_adaptive_mmco_5,
};
for (i = 0; i < dec_ref_pic_marking->n_ref_pic_marking; i++) { for (i = 0; i < dec_ref_pic_marking->n_ref_pic_marking; i++) {
GstH264RefPicMarking * const ref_pic_marking = GstH264RefPicMarking * const ref_pic_marking =
&dec_ref_pic_marking->ref_pic_marking[i]; &dec_ref_pic_marking->ref_pic_marking[i];
switch (ref_pic_marking->memory_management_control_operation) { const guint mmco = ref_pic_marking->memory_management_control_operation;
case 1: if (mmco < G_N_ELEMENTS(mmco_funcs) && mmco_funcs[mmco])
// Mark short-term reference picture as "unused for reference" mmco_funcs[mmco](decoder, picture, ref_pic_marking);
if (!picture->field_pic_flag) else {
pic_num = picture->frame_num_wrap; GST_ERROR("unhandled MMCO %u", mmco);
else return FALSE;
pic_num = 2 * picture->frame_num_wrap + 1;
pic_num -= ref_pic_marking->difference_of_pic_nums_minus1 + 1;
ref_idx = find_short_term_reference(decoder, pic_num);
if (ref_idx < 0)
break;
remove_reference_at(
decoder,
priv->short_ref, &priv->short_ref_count,
ref_idx
);
break;
case 2:
// Mark long-term reference picture as "unused for reference"
pic_num = picture->long_term_pic_num;
ref_idx = find_long_term_reference(decoder, pic_num);
if (ref_idx < 0)
break;
remove_reference_at(
decoder,
priv->long_ref, &priv->long_ref_count,
ref_idx
);
break;
case 3:
// Assign LongTermFrameIdx to a short-term reference picture
if (!picture->field_pic_flag)
pic_num = picture->frame_num_wrap;
else
pic_num = 2 * picture->frame_num_wrap + 1;
pic_num -= ref_pic_marking->difference_of_pic_nums_minus1 + 1;
ref_idx = find_short_term_reference(decoder, pic_num);
if (ref_idx < 0)
break;
break;
case 5:
// Mark all reference pictures as "unused for reference"
clear_references(decoder, priv->short_ref, &priv->short_ref_count);
clear_references(decoder, priv->long_ref, &priv->long_ref_count );
break;
default:
g_assert(0 && "unhandled MMCO");
break;
} }
} }
return TRUE; return TRUE;