From 46c01de05dbb50c74aca137298da5b3d16918034 Mon Sep 17 00:00:00 2001 From: Cong Zhong Date: Thu, 31 Jan 2013 16:13:22 +0800 Subject: [PATCH] codecparsers: mpeg2: store quantization matrices in zigzag scan order. Quantizer matrices are encoded in zigzag scan order in the bitstream, but they are stored in raster scan order when they are parsed. However, default matrices were also prepared in zigzag scan order, hence the mismatch. i.e. the matrices were presented either in raster scan order if they are explicitly present in the bitstream, or they were presented in zigzag scan order if the default definitions were to be used instead. One way to solve this problem is to always expose the quantization matrices in zigzag scan order, since this is the role of the parser to not build up stories from the source bitstream and just present what is in there. Utility functions will be provided to convert quantization matrices in either scan order. https://bugzilla.gnome.org/show_bug.cgi?id=693000 Signed-off-by: Cong Zhong Signed-off-by: Gwenole Beauchesne --- gst-libs/gst/codecparsers/gstmpegvideoparser.c | 16 ++++++---------- gst-libs/gst/codecparsers/gstmpegvideoparser.h | 8 +++++--- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/gst-libs/gst/codecparsers/gstmpegvideoparser.c b/gst-libs/gst/codecparsers/gstmpegvideoparser.c index 94726c7385..c841139ad7 100644 --- a/gst-libs/gst/codecparsers/gstmpegvideoparser.c +++ b/gst-libs/gst/codecparsers/gstmpegvideoparser.c @@ -322,7 +322,7 @@ gst_mpeg_video_parse_sequence_header (GstMpegVideoSequenceHdr * seqhdr, if (load_intra_flag) { gint i; for (i = 0; i < 64; i++) - READ_UINT8 (&br, seqhdr->intra_quantizer_matrix[mpeg_zigzag_8x8[i]], 8); + READ_UINT8 (&br, seqhdr->intra_quantizer_matrix[i], 8); } else memcpy (seqhdr->intra_quantizer_matrix, default_intra_quantizer_matrix, 64); @@ -331,8 +331,7 @@ gst_mpeg_video_parse_sequence_header (GstMpegVideoSequenceHdr * seqhdr, if (load_non_intra_flag) { gint i; for (i = 0; i < 64; i++) - READ_UINT8 (&br, seqhdr->non_intra_quantizer_matrix[mpeg_zigzag_8x8[i]], - 8); + READ_UINT8 (&br, seqhdr->non_intra_quantizer_matrix[i], 8); } else memset (seqhdr->non_intra_quantizer_matrix, 16, 64); @@ -564,31 +563,28 @@ gst_mpeg_video_parse_quant_matrix_extension (GstMpegVideoQuantMatrixExt * quant, READ_UINT8 (&br, quant->load_intra_quantiser_matrix, 1); if (quant->load_intra_quantiser_matrix) { for (i = 0; i < 64; i++) { - READ_UINT8 (&br, quant->intra_quantiser_matrix[mpeg_zigzag_8x8[i]], 8); + READ_UINT8 (&br, quant->intra_quantiser_matrix[i], 8); } } READ_UINT8 (&br, quant->load_non_intra_quantiser_matrix, 1); if (quant->load_non_intra_quantiser_matrix) { for (i = 0; i < 64; i++) { - READ_UINT8 (&br, quant->non_intra_quantiser_matrix[mpeg_zigzag_8x8[i]], - 8); + READ_UINT8 (&br, quant->non_intra_quantiser_matrix[i], 8); } } READ_UINT8 (&br, quant->load_chroma_intra_quantiser_matrix, 1); if (quant->load_chroma_intra_quantiser_matrix) { for (i = 0; i < 64; i++) { - READ_UINT8 (&br, quant->chroma_intra_quantiser_matrix[mpeg_zigzag_8x8[i]], - 8); + READ_UINT8 (&br, quant->chroma_intra_quantiser_matrix[i], 8); } } READ_UINT8 (&br, quant->load_chroma_non_intra_quantiser_matrix, 1); if (quant->load_chroma_non_intra_quantiser_matrix) { for (i = 0; i < 64; i++) { - READ_UINT8 (&br, - quant->chroma_non_intra_quantiser_matrix[mpeg_zigzag_8x8[i]], 8); + READ_UINT8 (&br, quant->chroma_non_intra_quantiser_matrix[i], 8); } } diff --git a/gst-libs/gst/codecparsers/gstmpegvideoparser.h b/gst-libs/gst/codecparsers/gstmpegvideoparser.h index 88ab3933bd..5685433836 100644 --- a/gst-libs/gst/codecparsers/gstmpegvideoparser.h +++ b/gst-libs/gst/codecparsers/gstmpegvideoparser.h @@ -193,8 +193,8 @@ typedef struct _GstMpegVideoPacket GstMpegVideoPacket; * @bitrate_value: Value of the bitrate as is in the stream (400bps unit) * @bitrate: the real bitrate of the Mpeg video stream in bits per second, 0 if VBR stream * @constrained_parameters_flag: %TRUE if this stream uses contrained parameters. - * @intra_quantizer_matrix: intra-quantization table - * @non_intra_quantizer_matrix: non-intra quantization table + * @intra_quantizer_matrix: intra-quantization table, in zigzag scan order + * @non_intra_quantizer_matrix: non-intra quantization table, in zigzag scan order * * The Mpeg2 Video Sequence Header structure. */ @@ -283,7 +283,9 @@ struct _GstMpegVideoSequenceDisplayExt * @load_chroma_non_intra_quantiser_matrix: * @chroma_non_intra_quantiser_matrix: * - * The Quant Matrix Extension structure + * The Quant Matrix Extension structure that exposes quantization + * matrices in zigzag scan order. i.e. the original encoded scan + * order. */ struct _GstMpegVideoQuantMatrixExt {