h264: minor clean-ups.

Drop explicit initialization of most fields that are implicitly set to
zero. Drop helper macros for casting to GstVaapiPictureH264 or
GstVaapiFrameStore. Also remove some useless checks for NULL pointers.
This commit is contained in:
Gwenole Beauchesne 2012-12-13 11:48:06 +01:00
parent 4992e7c60f
commit 0b2e399235

View file

@ -86,15 +86,6 @@ gst_vaapi_decoder_unit_h264_new(guint size)
/* --- H.264 Pictures --- */ /* --- H.264 Pictures --- */
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
#define GST_VAAPI_PICTURE_H264_CAST(obj) \
((GstVaapiPictureH264 *)(obj))
#define GST_VAAPI_PICTURE_H264(obj) \
GST_VAAPI_PICTURE_H264_CAST(obj)
#define GST_VAAPI_IS_PICTURE_H264(obj) \
(GST_VAAPI_PICTURE_H264(obj) != NULL)
/* /*
* Extended picture flags: * Extended picture flags:
* *
@ -173,20 +164,12 @@ gst_vaapi_picture_h264_create(
static inline GstVaapiPictureH264 * static inline GstVaapiPictureH264 *
gst_vaapi_picture_h264_new(GstVaapiDecoderH264 *decoder) gst_vaapi_picture_h264_new(GstVaapiDecoderH264 *decoder)
{ {
GstVaapiCodecObject *object; return (GstVaapiPictureH264 *)gst_vaapi_codec_object_new(
g_return_val_if_fail(GST_VAAPI_IS_DECODER(decoder), NULL);
object = gst_vaapi_codec_object_new(
&GstVaapiPictureH264Class, &GstVaapiPictureH264Class,
GST_VAAPI_CODEC_BASE(decoder), GST_VAAPI_CODEC_BASE(decoder),
NULL, sizeof(VAPictureParameterBufferH264), NULL, sizeof(VAPictureParameterBufferH264),
NULL, 0, NULL, 0,
0 0);
);
if (!object)
return NULL;
return GST_VAAPI_PICTURE_H264_CAST(object);
} }
static inline void static inline void
@ -196,8 +179,8 @@ gst_vaapi_picture_h264_set_reference(
gboolean other_field gboolean other_field
) )
{ {
g_return_if_fail(GST_VAAPI_IS_PICTURE_H264(picture)); if (!picture)
return;
GST_VAAPI_PICTURE_FLAG_UNSET(picture, GST_VAAPI_PICTURE_FLAGS_REFERENCE); GST_VAAPI_PICTURE_FLAG_UNSET(picture, GST_VAAPI_PICTURE_FLAGS_REFERENCE);
GST_VAAPI_PICTURE_FLAG_SET(picture, reference_flags); GST_VAAPI_PICTURE_FLAG_SET(picture, reference_flags);
@ -210,29 +193,15 @@ gst_vaapi_picture_h264_set_reference(
static inline GstVaapiPictureH264 * static inline GstVaapiPictureH264 *
gst_vaapi_picture_h264_new_field(GstVaapiPictureH264 *picture) gst_vaapi_picture_h264_new_field(GstVaapiPictureH264 *picture)
{ {
GstVaapiPicture *base_picture; g_return_val_if_fail(picture, NULL);
g_return_val_if_fail(GST_VAAPI_IS_PICTURE_H264(picture), NULL); return (GstVaapiPictureH264 *)gst_vaapi_picture_new_field(&picture->base);
base_picture = gst_vaapi_picture_new_field(&picture->base);
if (!base_picture)
return NULL;
return GST_VAAPI_PICTURE_H264_CAST(base_picture);
} }
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
/* --- Frame Buffers (DPB) --- */ /* --- Frame Buffers (DPB) --- */
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
#define GST_VAAPI_FRAME_STORE_CAST(obj) \
((GstVaapiFrameStore *)(obj))
#define GST_VAAPI_FRAME_STORE(obj) \
GST_VAAPI_FRAME_STORE_CAST(obj)
#define GST_VAAPI_IS_FRAME_STORE(obj) \
(GST_VAAPI_MINI_OBJECT(obj) != NULL)
struct _GstVaapiFrameStore { struct _GstVaapiFrameStore {
/*< private >*/ /*< private >*/
GstVaapiMiniObject parent_instance; GstVaapiMiniObject parent_instance;
@ -263,8 +232,6 @@ gst_vaapi_frame_store_new(GstVaapiPictureH264 *picture)
gst_vaapi_frame_store_finalize gst_vaapi_frame_store_finalize
}; };
g_return_val_if_fail(GST_VAAPI_IS_PICTURE_H264(picture), NULL);
fs = (GstVaapiFrameStore *) fs = (GstVaapiFrameStore *)
gst_vaapi_mini_object_new(&GstVaapiFrameStoreClass); gst_vaapi_mini_object_new(&GstVaapiFrameStoreClass);
if (!fs) if (!fs)
@ -283,10 +250,9 @@ gst_vaapi_frame_store_add(GstVaapiFrameStore *fs, GstVaapiPictureH264 *picture)
{ {
guint field; guint field;
g_return_val_if_fail(GST_VAAPI_IS_FRAME_STORE(fs), FALSE);
g_return_val_if_fail(fs->num_buffers == 1, FALSE); g_return_val_if_fail(fs->num_buffers == 1, FALSE);
g_return_val_if_fail(GST_VAAPI_IS_PICTURE_H264(picture), FALSE);
g_return_val_if_fail(!GST_VAAPI_PICTURE_IS_FRAME(picture), FALSE); g_return_val_if_fail(!GST_VAAPI_PICTURE_IS_FRAME(picture), FALSE);
g_return_val_if_fail(!GST_VAAPI_PICTURE_IS_FIRST_FIELD(picture), FALSE);
gst_vaapi_picture_replace(&fs->buffers[fs->num_buffers++], picture); gst_vaapi_picture_replace(&fs->buffers[fs->num_buffers++], picture);
if (picture->output_flag) { if (picture->output_flag) {
@ -369,6 +335,9 @@ G_DEFINE_TYPE(GstVaapiDecoderH264,
gst_vaapi_decoder_h264, gst_vaapi_decoder_h264,
GST_VAAPI_TYPE_DECODER) GST_VAAPI_TYPE_DECODER)
#define GST_VAAPI_DECODER_H264_CAST(decoder) \
((GstVaapiDecoderH264 *)(decoder))
#define GST_VAAPI_DECODER_H264_GET_PRIVATE(obj) \ #define GST_VAAPI_DECODER_H264_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), \ (G_TYPE_INSTANCE_GET_PRIVATE((obj), \
GST_VAAPI_TYPE_DECODER_H264, \ GST_VAAPI_TYPE_DECODER_H264, \
@ -408,7 +377,7 @@ struct _GstVaapiDecoderH264Private {
gboolean prev_pic_structure; // previous picture structure gboolean prev_pic_structure; // previous picture structure
guint is_constructed : 1; guint is_constructed : 1;
guint is_opened : 1; guint is_opened : 1;
guint is_avc : 1; guint is_avcC : 1;
guint got_sps : 1; guint got_sps : 1;
guint got_pps : 1; guint got_pps : 1;
guint has_context : 1; guint has_context : 1;
@ -631,12 +600,8 @@ dpb_add(GstVaapiDecoderH264 *decoder, GstVaapiPictureH264 *picture)
// Check if picture is the second field and the first field is still in DPB // Check if picture is the second field and the first field is still in DPB
fs = priv->prev_frame; fs = priv->prev_frame;
if (fs && !gst_vaapi_frame_store_has_frame(fs)) { if (fs && !gst_vaapi_frame_store_has_frame(fs))
g_return_val_if_fail(fs->num_buffers == 1, FALSE);
g_return_val_if_fail(!GST_VAAPI_PICTURE_IS_FRAME(picture), FALSE);
g_return_val_if_fail(!GST_VAAPI_PICTURE_IS_FIRST_FIELD(picture), FALSE);
return gst_vaapi_frame_store_add(fs, picture); return gst_vaapi_frame_store_add(fs, picture);
}
// Create new frame store, and split fields if necessary // Create new frame store, and split fields if necessary
fs = gst_vaapi_frame_store_new(picture); fs = gst_vaapi_frame_store_new(picture);
@ -2831,7 +2796,7 @@ decode_codec_data(GstVaapiDecoderH264 *decoder, GstBuffer *buffer)
ofs = unit.nalu.offset + unit.nalu.size; ofs = unit.nalu.offset + unit.nalu.size;
} }
priv->is_avc = TRUE; priv->is_avcC = TRUE;
return GST_VAAPI_DECODER_STATUS_SUCCESS; return GST_VAAPI_DECODER_STATUS_SUCCESS;
} }
@ -2864,7 +2829,8 @@ static GstVaapiDecoderStatus
gst_vaapi_decoder_h264_parse(GstVaapiDecoder *base_decoder, gst_vaapi_decoder_h264_parse(GstVaapiDecoder *base_decoder,
GstAdapter *adapter, gboolean at_eos, GstVaapiDecoderUnit **unit_ptr) GstAdapter *adapter, gboolean at_eos, GstVaapiDecoderUnit **unit_ptr)
{ {
GstVaapiDecoderH264 * const decoder = GST_VAAPI_DECODER_H264(base_decoder); GstVaapiDecoderH264 * const decoder =
GST_VAAPI_DECODER_H264_CAST(base_decoder);
GstVaapiDecoderH264Private * const priv = decoder->priv; GstVaapiDecoderH264Private * const priv = decoder->priv;
GstVaapiParserState * const ps = GST_VAAPI_PARSER_STATE(base_decoder); GstVaapiParserState * const ps = GST_VAAPI_PARSER_STATE(base_decoder);
GstVaapiDecoderUnitH264 *unit; GstVaapiDecoderUnitH264 *unit;
@ -2881,7 +2847,7 @@ gst_vaapi_decoder_h264_parse(GstVaapiDecoder *base_decoder,
size = gst_adapter_available(adapter); size = gst_adapter_available(adapter);
if (priv->is_avc) { if (priv->is_avcC) {
if (size < priv->nal_length_size) if (size < priv->nal_length_size)
return GST_VAAPI_DECODER_STATUS_ERROR_NO_DATA; return GST_VAAPI_DECODER_STATUS_ERROR_NO_DATA;
@ -2936,7 +2902,7 @@ gst_vaapi_decoder_h264_parse(GstVaapiDecoder *base_decoder,
if (!unit) if (!unit)
return GST_VAAPI_DECODER_STATUS_ERROR_ALLOCATION_FAILED; return GST_VAAPI_DECODER_STATUS_ERROR_ALLOCATION_FAILED;
if (priv->is_avc) if (priv->is_avcC)
result = gst_h264_parser_identify_nalu_avc(priv->parser, result = gst_h264_parser_identify_nalu_avc(priv->parser,
buf, 0, buf_size, priv->nal_length_size, &unit->nalu); buf, 0, buf_size, priv->nal_length_size, &unit->nalu);
else else
@ -3013,7 +2979,8 @@ static GstVaapiDecoderStatus
gst_vaapi_decoder_h264_decode(GstVaapiDecoder *base_decoder, gst_vaapi_decoder_h264_decode(GstVaapiDecoder *base_decoder,
GstVaapiDecoderUnit *unit) GstVaapiDecoderUnit *unit)
{ {
GstVaapiDecoderH264 * const decoder = GST_VAAPI_DECODER_H264(base_decoder); GstVaapiDecoderH264 * const decoder =
GST_VAAPI_DECODER_H264_CAST(base_decoder);
GstVaapiDecoderStatus status; GstVaapiDecoderStatus status;
status = ensure_decoder(decoder); status = ensure_decoder(decoder);
@ -3026,7 +2993,8 @@ static GstVaapiDecoderStatus
gst_vaapi_decoder_h264_start_frame(GstVaapiDecoder *base_decoder, gst_vaapi_decoder_h264_start_frame(GstVaapiDecoder *base_decoder,
GstVaapiDecoderUnit *base_unit) GstVaapiDecoderUnit *base_unit)
{ {
GstVaapiDecoderH264 * const decoder = GST_VAAPI_DECODER_H264(base_decoder); GstVaapiDecoderH264 * const decoder =
GST_VAAPI_DECODER_H264_CAST(base_decoder);
GstVaapiDecoderUnitH264 * const unit = (GstVaapiDecoderUnitH264 *)base_unit; GstVaapiDecoderUnitH264 * const unit = (GstVaapiDecoderUnitH264 *)base_unit;
return decode_picture(decoder, unit); return decode_picture(decoder, unit);
@ -3035,7 +3003,8 @@ gst_vaapi_decoder_h264_start_frame(GstVaapiDecoder *base_decoder,
static GstVaapiDecoderStatus static GstVaapiDecoderStatus
gst_vaapi_decoder_h264_end_frame(GstVaapiDecoder *base_decoder) gst_vaapi_decoder_h264_end_frame(GstVaapiDecoder *base_decoder)
{ {
GstVaapiDecoderH264 * const decoder = GST_VAAPI_DECODER_H264(base_decoder); GstVaapiDecoderH264 * const decoder =
GST_VAAPI_DECODER_H264_CAST(base_decoder);
return decode_current_picture(decoder); return decode_current_picture(decoder);
} }
@ -3043,7 +3012,7 @@ gst_vaapi_decoder_h264_end_frame(GstVaapiDecoder *base_decoder)
static void static void
gst_vaapi_decoder_h264_finalize(GObject *object) gst_vaapi_decoder_h264_finalize(GObject *object)
{ {
GstVaapiDecoderH264 * const decoder = GST_VAAPI_DECODER_H264(object); GstVaapiDecoderH264 * const decoder = GST_VAAPI_DECODER_H264_CAST(object);
gst_vaapi_decoder_h264_destroy(decoder); gst_vaapi_decoder_h264_destroy(decoder);
@ -3053,7 +3022,7 @@ gst_vaapi_decoder_h264_finalize(GObject *object)
static void static void
gst_vaapi_decoder_h264_constructed(GObject *object) gst_vaapi_decoder_h264_constructed(GObject *object)
{ {
GstVaapiDecoderH264 * const decoder = GST_VAAPI_DECODER_H264(object); GstVaapiDecoderH264 * const decoder = GST_VAAPI_DECODER_H264_CAST(object);
GstVaapiDecoderH264Private * const priv = decoder->priv; GstVaapiDecoderH264Private * const priv = decoder->priv;
GObjectClass *parent_class; GObjectClass *parent_class;
@ -3088,40 +3057,11 @@ gst_vaapi_decoder_h264_init(GstVaapiDecoderH264 *decoder)
priv = GST_VAAPI_DECODER_H264_GET_PRIVATE(decoder); priv = GST_VAAPI_DECODER_H264_GET_PRIVATE(decoder);
decoder->priv = priv; decoder->priv = priv;
priv->parser = NULL;
priv->current_picture = NULL;
priv->dpb_count = 0;
priv->dpb_size = 0;
priv->profile = GST_VAAPI_PROFILE_UNKNOWN; priv->profile = GST_VAAPI_PROFILE_UNKNOWN;
priv->entrypoint = GST_VAAPI_ENTRYPOINT_VLD; priv->entrypoint = GST_VAAPI_ENTRYPOINT_VLD;
priv->chroma_type = GST_VAAPI_CHROMA_TYPE_YUV420; priv->chroma_type = GST_VAAPI_CHROMA_TYPE_YUV420;
priv->short_ref_count = 0;
priv->long_ref_count = 0;
priv->RefPicList0_count = 0;
priv->RefPicList1_count = 0;
priv->nal_length_size = 0;
priv->field_poc[0] = 0;
priv->field_poc[1] = 0;
priv->poc_msb = 0;
priv->poc_lsb = 0;
priv->prev_poc_msb = 0;
priv->prev_poc_lsb = 0;
priv->frame_num_offset = 0;
priv->frame_num = 0;
priv->prev_frame_num = 0;
priv->prev_pic_has_mmco5 = FALSE;
priv->prev_pic_structure = GST_VAAPI_PICTURE_STRUCTURE_FRAME; priv->prev_pic_structure = GST_VAAPI_PICTURE_STRUCTURE_FRAME;
priv->is_constructed = FALSE;
priv->is_opened = FALSE;
priv->is_avc = FALSE;
priv->has_context = FALSE;
priv->progressive_sequence = TRUE; priv->progressive_sequence = TRUE;
memset(priv->dpb, 0, sizeof(priv->dpb));
memset(priv->short_ref, 0, sizeof(priv->short_ref));
memset(priv->long_ref, 0, sizeof(priv->long_ref));
memset(priv->RefPicList0, 0, sizeof(priv->RefPicList0));
memset(priv->RefPicList1, 0, sizeof(priv->RefPicList1));
} }
/** /**