mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-29 18:48:44 +00:00
vdpaumpegdec: use READ_UINT[8|16|32] macros
This commit is contained in:
parent
6933d12a9b
commit
a9687846f6
1 changed files with 110 additions and 112 deletions
|
@ -54,6 +54,34 @@ guint8 mpeg2_scan[64] = {
|
|||
53, 60, 61, 54, 47, 55, 62, 63
|
||||
};
|
||||
|
||||
#define READ_UINT8(reader, val, nbits) { \
|
||||
if (!gst_bit_reader_get_bits_uint8 (reader, &val, nbits)) { \
|
||||
GST_WARNING ("failed to read uint8, nbits: %d", nbits); \
|
||||
goto error; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define READ_UINT16(reader, val, nbits) { \
|
||||
if (!gst_bit_reader_get_bits_uint16 (reader, &val, nbits)) { \
|
||||
GST_WARNING ("failed to read uint16, nbits: %d", nbits); \
|
||||
goto error; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define READ_UINT32(reader, val, nbits) { \
|
||||
if (!gst_bit_reader_get_bits_uint32 (reader, &val, nbits)) { \
|
||||
GST_WARNING ("failed to read uint32, nbits: %d", nbits); \
|
||||
goto error; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define READ_UINT64(reader, val, nbits) { \
|
||||
if (!gst_bit_reader_get_bits_uint64 (reader, &val, nbits)) { \
|
||||
GST_WARNING ("failed to read uint32, nbits: %d", nbits); \
|
||||
goto error; \
|
||||
} \
|
||||
}
|
||||
|
||||
static void
|
||||
set_fps_from_code (MPEGSeqHdr * hdr, guint8 fps_code)
|
||||
{
|
||||
|
@ -116,39 +144,34 @@ mpeg_util_parse_sequence_extension (MPEGSeqExtHdr * hdr, GstBuffer * buffer)
|
|||
if (!gst_bit_reader_skip (&reader, 1))
|
||||
return FALSE;
|
||||
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &hdr->profile, 3))
|
||||
return FALSE;
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &hdr->level, 4))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, hdr->profile, 3);
|
||||
READ_UINT8 (&reader, hdr->level, 4);
|
||||
|
||||
/* progressive */
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &hdr->progressive, 1))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, hdr->progressive, 1);
|
||||
|
||||
/* chroma format */
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &hdr->chroma_format, 2))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, hdr->chroma_format, 2);
|
||||
|
||||
/* resolution extension */
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &hdr->horiz_size_ext, 2))
|
||||
return FALSE;
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &hdr->vert_size_ext, 2))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, hdr->horiz_size_ext, 2);
|
||||
READ_UINT8 (&reader, hdr->vert_size_ext, 2);
|
||||
|
||||
if (!gst_bit_reader_get_bits_uint16 (&reader, &hdr->bitrate_ext, 12))
|
||||
return FALSE;
|
||||
READ_UINT16 (&reader, hdr->bitrate_ext, 12);
|
||||
|
||||
/* skip to framerate extension */
|
||||
if (!gst_bit_reader_skip (&reader, 9))
|
||||
return FALSE;
|
||||
|
||||
/* framerate extension */
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &hdr->fps_n_ext, 2))
|
||||
return FALSE;
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &hdr->fps_d_ext, 2))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, hdr->fps_n_ext, 2);
|
||||
READ_UINT8 (&reader, hdr->fps_d_ext, 2);
|
||||
|
||||
return TRUE;
|
||||
|
||||
error:
|
||||
GST_WARNING ("error parsing \"Sequence Extension\"");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
@ -163,64 +186,52 @@ mpeg_util_parse_sequence_hdr (MPEGSeqHdr * hdr, GstBuffer * buffer)
|
|||
return FALSE;
|
||||
|
||||
/* resolution */
|
||||
if (!gst_bit_reader_get_bits_uint16 (&reader, &hdr->width, 12))
|
||||
return FALSE;
|
||||
if (!gst_bit_reader_get_bits_uint16 (&reader, &hdr->height, 12))
|
||||
return FALSE;
|
||||
READ_UINT16 (&reader, hdr->width, 12);
|
||||
READ_UINT16 (&reader, hdr->height, 12);
|
||||
|
||||
/* aspect ratio */
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &dar_idx, 4))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, dar_idx, 4);
|
||||
set_par_from_dar (hdr, dar_idx);
|
||||
|
||||
/* framerate */
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &par_idx, 4))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, par_idx, 4);
|
||||
set_fps_from_code (hdr, par_idx);
|
||||
|
||||
/* bitrate */
|
||||
if (!gst_bit_reader_get_bits_uint32 (&reader, &hdr->bitrate, 18))
|
||||
return FALSE;
|
||||
READ_UINT32 (&reader, hdr->bitrate, 18);
|
||||
|
||||
if (!gst_bit_reader_skip (&reader, 1))
|
||||
return FALSE;
|
||||
|
||||
/* VBV buffer size */
|
||||
if (!gst_bit_reader_get_bits_uint16 (&reader, &hdr->vbv_buffer, 10))
|
||||
return FALSE;
|
||||
READ_UINT16 (&reader, hdr->vbv_buffer, 10);
|
||||
|
||||
/* constrained parameters flag */
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader,
|
||||
&hdr->constrained_parameters_flag, 1))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, hdr->constrained_parameters_flag, 1);
|
||||
|
||||
/* intra quantizer matrix */
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &load_intra_flag, 1))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, load_intra_flag, 1);
|
||||
if (load_intra_flag) {
|
||||
gint i;
|
||||
for (i = 0; i < 64; i++) {
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader,
|
||||
&hdr->intra_quantizer_matrix[mpeg2_scan[i]], 8))
|
||||
return FALSE;
|
||||
}
|
||||
for (i = 0; i < 64; i++)
|
||||
READ_UINT8 (&reader, hdr->intra_quantizer_matrix[mpeg2_scan[i]], 8);
|
||||
} else
|
||||
memcpy (hdr->intra_quantizer_matrix, default_intra_quantizer_matrix, 64);
|
||||
|
||||
/* non intra quantizer matrix */
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &load_non_intra_flag, 1))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, load_non_intra_flag, 1);
|
||||
if (load_non_intra_flag) {
|
||||
gint i;
|
||||
for (i = 0; i < 64; i++) {
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader,
|
||||
&hdr->non_intra_quantizer_matrix[mpeg2_scan[i]], 8))
|
||||
return FALSE;
|
||||
}
|
||||
for (i = 0; i < 64; i++)
|
||||
READ_UINT8 (&reader, hdr->non_intra_quantizer_matrix[mpeg2_scan[i]], 8);
|
||||
} else
|
||||
memset (hdr->non_intra_quantizer_matrix, 16, 64);
|
||||
|
||||
return TRUE;
|
||||
|
||||
error:
|
||||
GST_WARNING ("error parsing \"Sequence Header\"");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
@ -249,12 +260,9 @@ mpeg_util_parse_picture_hdr (MPEGPictureHdr * hdr, GstBuffer * buffer)
|
|||
|
||||
if (hdr->pic_type == P_FRAME || hdr->pic_type == B_FRAME) {
|
||||
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &hdr->full_pel_forward_vector,
|
||||
1))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, hdr->full_pel_forward_vector, 1);
|
||||
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &hdr->f_code[0][0], 3))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, hdr->f_code[0][0], 3);
|
||||
hdr->f_code[0][1] = hdr->f_code[0][0];
|
||||
} else {
|
||||
hdr->full_pel_forward_vector = 0;
|
||||
|
@ -262,12 +270,9 @@ mpeg_util_parse_picture_hdr (MPEGPictureHdr * hdr, GstBuffer * buffer)
|
|||
}
|
||||
|
||||
if (hdr->pic_type == B_FRAME) {
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader,
|
||||
&hdr->full_pel_backward_vector, 1))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, hdr->full_pel_backward_vector, 1);
|
||||
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &hdr->f_code[1][0], 3))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, hdr->f_code[1][0], 3);
|
||||
hdr->f_code[1][1] = hdr->f_code[1][0];
|
||||
} else {
|
||||
hdr->full_pel_backward_vector = 0;
|
||||
|
@ -275,6 +280,10 @@ mpeg_util_parse_picture_hdr (MPEGPictureHdr * hdr, GstBuffer * buffer)
|
|||
}
|
||||
|
||||
return TRUE;
|
||||
|
||||
error:
|
||||
GST_WARNING ("error parsing \"Picture Header\"");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
@ -292,61 +301,49 @@ mpeg_util_parse_picture_coding_extension (MPEGPictureExt * ext,
|
|||
return FALSE;
|
||||
|
||||
/* f_code */
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &ext->f_code[0][0], 4))
|
||||
return FALSE;
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &ext->f_code[0][1], 4))
|
||||
return FALSE;
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &ext->f_code[1][0], 4))
|
||||
return FALSE;
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &ext->f_code[1][1], 4))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, ext->f_code[0][0], 4);
|
||||
READ_UINT8 (&reader, ext->f_code[0][1], 4);
|
||||
READ_UINT8 (&reader, ext->f_code[1][0], 4);
|
||||
READ_UINT8 (&reader, ext->f_code[1][1], 4);
|
||||
|
||||
/* intra DC precision */
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &ext->intra_dc_precision, 2))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, ext->intra_dc_precision, 2);
|
||||
|
||||
/* picture structure */
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &ext->picture_structure, 2))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, ext->picture_structure, 2);
|
||||
|
||||
/* top field first */
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &ext->top_field_first, 1))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, ext->top_field_first, 1);
|
||||
|
||||
/* frame pred frame dct */
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &ext->frame_pred_frame_dct, 1))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, ext->frame_pred_frame_dct, 1);
|
||||
|
||||
/* concealment motion vectors */
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &ext->concealment_motion_vectors,
|
||||
1))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, ext->concealment_motion_vectors, 1);
|
||||
|
||||
/* q scale type */
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &ext->q_scale_type, 1))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, ext->q_scale_type, 1);
|
||||
|
||||
/* intra vlc format */
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &ext->intra_vlc_format, 1))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, ext->intra_vlc_format, 1);
|
||||
|
||||
/* alternate scan */
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &ext->alternate_scan, 1))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, ext->alternate_scan, 1);
|
||||
|
||||
/* repeat first field */
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &ext->repeat_first_field, 1))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, ext->repeat_first_field, 1);
|
||||
|
||||
/* chroma_420_type */
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &ext->chroma_420_type, 1))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, ext->chroma_420_type, 1);
|
||||
|
||||
/* progressive_frame */
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &ext->progressive_frame, 1))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, ext->progressive_frame, 1);
|
||||
|
||||
return TRUE;
|
||||
|
||||
error:
|
||||
GST_WARNING ("error parsing \"Picture Coding Extension\"");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
@ -358,32 +355,29 @@ mpeg_util_parse_gop (MPEGGop * gop, GstBuffer * buffer)
|
|||
if (!gst_bit_reader_skip (&reader, 8 * 4))
|
||||
return FALSE;
|
||||
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &gop->drop_frame_flag, 1))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, gop->drop_frame_flag, 1);
|
||||
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &gop->hour, 5))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, gop->hour, 5);
|
||||
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &gop->minute, 6))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, gop->minute, 6);
|
||||
|
||||
/* skip unused bit */
|
||||
if (!gst_bit_reader_skip (&reader, 1))
|
||||
return FALSE;
|
||||
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &gop->second, 6))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, gop->second, 6);
|
||||
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &gop->frame, 6))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, gop->frame, 6);
|
||||
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &gop->closed_gop, 1))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, gop->closed_gop, 1);
|
||||
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &gop->broken_gop, 1))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, gop->broken_gop, 1);
|
||||
|
||||
return TRUE;
|
||||
|
||||
error:
|
||||
GST_WARNING ("error parsing \"GOP\"");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
@ -401,30 +395,34 @@ mpeg_util_parse_quant_matrix (MPEGQuantMatrix * qm, GstBuffer * buffer)
|
|||
return FALSE;
|
||||
|
||||
/* intra quantizer matrix */
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &load_intra_flag, 1))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, load_intra_flag, 1);
|
||||
if (load_intra_flag) {
|
||||
gint i;
|
||||
for (i = 0; i < 64; i++) {
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader,
|
||||
&qm->intra_quantizer_matrix[mpeg2_scan[i]], 8))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, qm->intra_quantizer_matrix[mpeg2_scan[i]], 8);
|
||||
}
|
||||
} else
|
||||
memcpy (qm->intra_quantizer_matrix, default_intra_quantizer_matrix, 64);
|
||||
|
||||
/* non intra quantizer matrix */
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader, &load_non_intra_flag, 1))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, load_non_intra_flag, 1);
|
||||
if (load_non_intra_flag) {
|
||||
gint i;
|
||||
for (i = 0; i < 64; i++) {
|
||||
if (!gst_bit_reader_get_bits_uint8 (&reader,
|
||||
&qm->non_intra_quantizer_matrix[mpeg2_scan[i]], 8))
|
||||
return FALSE;
|
||||
READ_UINT8 (&reader, qm->non_intra_quantizer_matrix[mpeg2_scan[i]], 8);
|
||||
}
|
||||
} else
|
||||
memset (qm->non_intra_quantizer_matrix, 16, 64);
|
||||
|
||||
return TRUE;
|
||||
|
||||
error:
|
||||
GST_WARNING ("error parsing \"Quant Matrix Extension\"");
|
||||
return FALSE;
|
||||
|
||||
}
|
||||
|
||||
#undef READ_UINT8
|
||||
#undef READ_UINT16
|
||||
#undef READ_UINT32
|
||||
#undef READ_UINT64
|
||||
|
|
Loading…
Reference in a new issue