st/va: delay decoder creation until max_references is known
[mesa.git] / src / gallium / state_trackers / va / picture_h264.c
1 /**************************************************************************
2 *
3 * Copyright 2010 Thomas Balling Sørensen & Orasanu Lucian.
4 * Copyright 2014 Advanced Micro Devices, Inc.
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
27 **************************************************************************/
28
29 #include "util/u_video.h"
30 #include "va_private.h"
31
32 void vlVaHandlePictureParameterBufferH264(vlVaDriver *drv, vlVaContext *context, vlVaBuffer *buf)
33 {
34 VAPictureParameterBufferH264 *h264 = buf->data;
35
36 assert(buf->size >= sizeof(VAPictureParameterBufferH264) && buf->num_elements == 1);
37 /*CurrPic*/
38 context->desc.h264.field_order_cnt[0] = h264->CurrPic.TopFieldOrderCnt;
39 context->desc.h264.field_order_cnt[1] = h264->CurrPic.BottomFieldOrderCnt;
40 /*ReferenceFrames[16]*/
41 /*picture_width_in_mbs_minus1*/
42 /*picture_height_in_mbs_minus1*/
43 /*bit_depth_luma_minus8*/
44 /*bit_depth_chroma_minus8*/
45 context->desc.h264.num_ref_frames = h264->num_ref_frames;
46 /*chroma_format_idc*/
47 /*residual_colour_transform_flag*/
48 /*gaps_in_frame_num_value_allowed_flag*/
49 context->desc.h264.pps->sps->frame_mbs_only_flag =
50 h264->seq_fields.bits.frame_mbs_only_flag;
51 context->desc.h264.pps->sps->mb_adaptive_frame_field_flag =
52 h264->seq_fields.bits.mb_adaptive_frame_field_flag;
53 context->desc.h264.pps->sps->direct_8x8_inference_flag =
54 h264->seq_fields.bits.direct_8x8_inference_flag;
55 /*MinLumaBiPredSize8x8*/
56 context->desc.h264.pps->sps->log2_max_frame_num_minus4 =
57 h264->seq_fields.bits.log2_max_frame_num_minus4;
58 context->desc.h264.pps->sps->pic_order_cnt_type =
59 h264->seq_fields.bits.pic_order_cnt_type;
60 context->desc.h264.pps->sps->log2_max_pic_order_cnt_lsb_minus4 =
61 h264->seq_fields.bits.log2_max_pic_order_cnt_lsb_minus4;
62 context->desc.h264.pps->sps->delta_pic_order_always_zero_flag =
63 h264->seq_fields.bits.delta_pic_order_always_zero_flag;
64 /*num_slice_groups_minus1*/
65 /*slice_group_map_type*/
66 /*slice_group_change_rate_minus1*/
67 context->desc.h264.pps->pic_init_qp_minus26 =
68 h264->pic_init_qp_minus26;
69 /*pic_init_qs_minus26*/
70 context->desc.h264.pps->chroma_qp_index_offset =
71 h264->chroma_qp_index_offset;
72 context->desc.h264.pps->second_chroma_qp_index_offset =
73 h264->second_chroma_qp_index_offset;
74 context->desc.h264.pps->entropy_coding_mode_flag =
75 h264->pic_fields.bits.entropy_coding_mode_flag;
76 context->desc.h264.pps->weighted_pred_flag =
77 h264->pic_fields.bits.weighted_pred_flag;
78 context->desc.h264.pps->weighted_bipred_idc =
79 h264->pic_fields.bits.weighted_bipred_idc;
80 context->desc.h264.pps->transform_8x8_mode_flag =
81 h264->pic_fields.bits.transform_8x8_mode_flag;
82 context->desc.h264.field_pic_flag =
83 h264->pic_fields.bits.field_pic_flag;
84 context->desc.h264.pps->constrained_intra_pred_flag =
85 h264->pic_fields.bits.constrained_intra_pred_flag;
86 context->desc.h264.pps->bottom_field_pic_order_in_frame_present_flag =
87 h264->pic_fields.bits.pic_order_present_flag;
88 context->desc.h264.pps->deblocking_filter_control_present_flag =
89 h264->pic_fields.bits.deblocking_filter_control_present_flag;
90 context->desc.h264.pps->redundant_pic_cnt_present_flag =
91 h264->pic_fields.bits.redundant_pic_cnt_present_flag;
92 /*reference_pic_flag*/
93 context->desc.h264.frame_num = h264->frame_num;
94
95 if (!context->decoder && context->desc.h264.num_ref_frames > 0)
96 context->templat.max_references = MIN2(context->desc.h264.num_ref_frames, 16);
97 }
98
99 void vlVaHandleIQMatrixBufferH264(vlVaContext *context, vlVaBuffer *buf)
100 {
101 VAIQMatrixBufferH264 *h264 = buf->data;
102
103 assert(buf->size >= sizeof(VAIQMatrixBufferH264) && buf->num_elements == 1);
104 memcpy(&context->desc.h264.pps->ScalingList4x4, h264->ScalingList4x4, 6 * 16);
105 memcpy(&context->desc.h264.pps->ScalingList8x8, h264->ScalingList8x8, 2 * 64);
106 }
107
108 void vlVaHandleSliceParameterBufferH264(vlVaContext *context, vlVaBuffer *buf)
109 {
110 VASliceParameterBufferH264 *h264 = buf->data;
111
112 assert(buf->size >= sizeof(VASliceParameterBufferH264) && buf->num_elements == 1);
113 context->desc.h264.num_ref_idx_l0_active_minus1 =
114 h264->num_ref_idx_l0_active_minus1;
115 context->desc.h264.num_ref_idx_l1_active_minus1 =
116 h264->num_ref_idx_l1_active_minus1;
117 }