Path: blob/21.2-virgl/src/gallium/frontends/va/picture_mpeg12.c
4561 views
/**************************************************************************1*2* Copyright 2014 Advanced Micro Devices, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS18* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.20* IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR21* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,22* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE23* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/2627#include "va_private.h"2829const int reverse_inverse_zscan[] =30{31/* Reverse inverse z scan pattern */320, 2, 3, 9, 10, 20, 21, 35,331, 4, 8, 11, 19, 22, 34, 36,345, 7, 12, 18, 23, 33, 37, 48,356, 13, 17, 24, 32, 38, 47, 49,3614, 16, 25, 31, 39, 46, 50, 57,3715, 26, 30, 40, 45, 51, 56, 58,3827, 29, 41, 44, 52, 55, 59, 62,3928, 42, 43, 53, 54, 60, 61, 63,40};4142void vlVaHandlePictureParameterBufferMPEG12(vlVaDriver *drv, vlVaContext *context, vlVaBuffer *buf)43{44VAPictureParameterBufferMPEG2 *mpeg2 = buf->data;4546assert(buf->size >= sizeof(VAPictureParameterBufferMPEG2) && buf->num_elements == 1);47context->desc.mpeg12.num_slices = 0;48/*horizontal_size;*/49/*vertical_size;*/50vlVaGetReferenceFrame(drv, mpeg2->forward_reference_picture, &context->desc.mpeg12.ref[0]);51vlVaGetReferenceFrame(drv, mpeg2->backward_reference_picture, &context->desc.mpeg12.ref[1]);52context->desc.mpeg12.picture_coding_type = mpeg2->picture_coding_type;53context->desc.mpeg12.f_code[0][0] = ((mpeg2->f_code >> 12) & 0xf) - 1;54context->desc.mpeg12.f_code[0][1] = ((mpeg2->f_code >> 8) & 0xf) - 1;55context->desc.mpeg12.f_code[1][0] = ((mpeg2->f_code >> 4) & 0xf) - 1;56context->desc.mpeg12.f_code[1][1] = (mpeg2->f_code & 0xf) - 1;57context->desc.mpeg12.intra_dc_precision =58mpeg2->picture_coding_extension.bits.intra_dc_precision;59context->desc.mpeg12.picture_structure =60mpeg2->picture_coding_extension.bits.picture_structure;61context->desc.mpeg12.top_field_first =62mpeg2->picture_coding_extension.bits.top_field_first;63context->desc.mpeg12.frame_pred_frame_dct =64mpeg2->picture_coding_extension.bits.frame_pred_frame_dct;65context->desc.mpeg12.concealment_motion_vectors =66mpeg2->picture_coding_extension.bits.concealment_motion_vectors;67context->desc.mpeg12.q_scale_type =68mpeg2->picture_coding_extension.bits.q_scale_type;69context->desc.mpeg12.intra_vlc_format =70mpeg2->picture_coding_extension.bits.intra_vlc_format;71context->desc.mpeg12.alternate_scan =72mpeg2->picture_coding_extension.bits.alternate_scan;73/*repeat_first_field*/74/*progressive_frame*/75/*is_first_field*/76}7778void vlVaHandleIQMatrixBufferMPEG12(vlVaContext *context, vlVaBuffer *buf)79{80VAIQMatrixBufferMPEG2 *mpeg2 = buf->data;81static uint8_t temp_intra_matrix[64];82static uint8_t temp_nonintra_matrix[64];8384assert(buf->size >= sizeof(VAIQMatrixBufferMPEG2) && buf->num_elements == 1);85if (mpeg2->load_intra_quantiser_matrix) {86/* The quantiser matrix that VAAPI provides has been applied87with inverse z-scan. However, what we expect in MPEG288picture description is the original order. Therefore,89we need to reverse it back to its original order.90*/91for (int i = 0; i < 64; i++)92temp_intra_matrix[i] =93mpeg2->intra_quantiser_matrix[reverse_inverse_zscan[i]];94context->desc.mpeg12.intra_matrix = temp_intra_matrix;95} else96context->desc.mpeg12.intra_matrix = NULL;9798if (mpeg2->load_non_intra_quantiser_matrix) {99for (int i = 0; i < 64; i++)100temp_nonintra_matrix[i] =101mpeg2->non_intra_quantiser_matrix[reverse_inverse_zscan[i]];102context->desc.mpeg12.non_intra_matrix = temp_nonintra_matrix;103} else104context->desc.mpeg12.non_intra_matrix = NULL;105}106107void vlVaHandleSliceParameterBufferMPEG12(vlVaContext *context, vlVaBuffer *buf)108{109assert(buf->size >= sizeof(VASliceParameterBufferMPEG2));110context->desc.mpeg12.num_slices += buf->num_elements;111}112113114