1 /*
2 * Copyright (c) 2023, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 //!
23 //! \file     encode_hevc_basic_feature_rsvd.cpp
24 //! \brief    Defines the common interface for encode hevc basic feature rsvd
25 //!
26 #include "encode_hevc_basic_feature_422.h"
27 
28 namespace encode
29 {
Init(PCODEC_HEVC_ENCODE_SEQUENCE_PARAMS hevcSeqParams,PCODEC_HEVC_ENCODE_PICTURE_PARAMS hevcPicParams)30     MOS_STATUS HevcBasicFeature422::Init(PCODEC_HEVC_ENCODE_SEQUENCE_PARAMS hevcSeqParams, PCODEC_HEVC_ENCODE_PICTURE_PARAMS hevcPicParams)
31     {
32         ENCODE_FUNC_CALL();
33 
34         ENCODE_CHK_NULL_RETURN(hevcSeqParams);
35         ENCODE_CHK_NULL_RETURN(hevcPicParams);
36         if (hevcSeqParams->chroma_format_idc == HCP_CHROMA_FORMAT_YUV422)
37         {
38             m_is422 = true;
39         }
40 
41         if (m_is422 && hevcPicParams->tiles_enabled_flag )
42         {
43             ENCODE_ASSERTMESSAGE(" 422 with multi tiles is not supported.");
44             return MOS_STATUS_INVALID_PARAMETER;
45         }
46 
47         return MOS_STATUS_SUCCESS;
48     }
49 
RegisterMbCodeBuffer(TrackedBuffer * trackedBuf,bool & isRegistered,uint32_t mbCodeSize)50     MOS_STATUS HevcBasicFeature422::RegisterMbCodeBuffer(TrackedBuffer *trackedBuf, bool &isRegistered, uint32_t mbCodeSize)
51     {
52         ENCODE_FUNC_CALL();
53 
54         ENCODE_CHK_NULL_RETURN(trackedBuf);
55 
56         MOS_ALLOC_GFXRES_PARAMS allocParamsForLinear;
57         MOS_ZeroMemory(&allocParamsForLinear, sizeof(MOS_ALLOC_GFXRES_PARAMS));
58         allocParamsForLinear.Type = MOS_GFXRES_BUFFER;
59         allocParamsForLinear.TileType = MOS_TILE_LINEAR;
60         allocParamsForLinear.Format   = Format_Buffer;
61         allocParamsForLinear.dwMemType        = MOS_MEMPOOL_SYSTEMMEMORY;
62         allocParamsForLinear.Flags.bCacheable = true;
63         // set the ResUsageType to enable coherency in gmm
64         allocParamsForLinear.ResUsageType     = MOS_HW_RESOURCE_USAGE_ENCODE_OUTPUT_BITSTREAM;
65 
66         if (mbCodeSize > 0)
67         {
68             allocParamsForLinear.pBufName = "mbCodeBuffer";
69             allocParamsForLinear.dwBytes = mbCodeSize + 8 * CODECHAL_CACHELINE_SIZE;
70             ENCODE_CHK_STATUS_RETURN(trackedBuf->RegisterParam(encode::BufferType::mbCodedBuffer, allocParamsForLinear));
71             isRegistered = true;
72         }
73 
74         return MOS_STATUS_SUCCESS;
75     }
76 
Update422Format(PCODEC_HEVC_ENCODE_SEQUENCE_PARAMS hevcSeqParams,uint8_t & outputChromaFormat,MOS_FORMAT & reconFormat,bool is10Bit)77     MOS_STATUS HevcBasicFeature422::Update422Format(PCODEC_HEVC_ENCODE_SEQUENCE_PARAMS hevcSeqParams, uint8_t &outputChromaFormat, MOS_FORMAT &reconFormat, bool is10Bit)
78     {
79         ENCODE_FUNC_CALL();
80 
81         ENCODE_CHK_NULL_RETURN(hevcSeqParams);
82         hevcSeqParams->chroma_format_idc =
83             outputChromaFormat = HCP_CHROMA_FORMAT_YUV420;
84         reconFormat            = is10Bit ? Format_P010 : Format_NV12;
85 
86         return MOS_STATUS_SUCCESS;
87     }
88 
Revert422Format(PCODEC_HEVC_ENCODE_SEQUENCE_PARAMS hevcSeqParams,uint8_t & outputChromaFormat,MOS_FORMAT & reconFormat,bool is10Bit)89     MOS_STATUS HevcBasicFeature422::Revert422Format(PCODEC_HEVC_ENCODE_SEQUENCE_PARAMS hevcSeqParams, uint8_t &outputChromaFormat, MOS_FORMAT &reconFormat, bool is10Bit)
90     {
91         ENCODE_FUNC_CALL();
92 
93         ENCODE_CHK_NULL_RETURN(hevcSeqParams);
94         hevcSeqParams->chroma_format_idc =
95             outputChromaFormat = HCP_CHROMA_FORMAT_YUV422;
96         reconFormat            = is10Bit ? Format_Y216 : Format_YUY2;
97 
98         return MOS_STATUS_SUCCESS;
99     }
100 
101 }
102