1 /*
2 * Copyright (c) 2018, 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_vdenc_roi.h
24 //! \brief    implementation of ROI feature of HEVC VDENC
25 
26 #include "mos_defs.h"
27 #include "encode_hevc_vdenc_roi_native.h"
28 namespace encode
29 {
PrepareParams(SeqParams * hevcSeqParams,PicParams * hevcPicParams,SlcParams * hevcSlcParams)30 MOS_STATUS NativeROI::PrepareParams(
31     SeqParams *hevcSeqParams,
32     PicParams *hevcPicParams,
33     SlcParams *hevcSlcParams)
34 {
35     ENCODE_CHK_NULL_RETURN(hevcSeqParams);
36     ENCODE_CHK_NULL_RETURN(hevcPicParams);
37     ENCODE_CHK_NULL_RETURN(hevcSlcParams);
38 
39     ENCODE_CHK_STATUS_RETURN(
40         RoiStrategy::PrepareParams(hevcSeqParams, hevcPicParams, hevcSlcParams));
41 
42     m_numDistinctDeltaQp =
43         sizeof(hevcPicParams->ROIDistinctDeltaQp) / sizeof(int8_t);
44     m_roiDistinctDeltaQp = hevcPicParams->ROIDistinctDeltaQp;
45     ENCODE_CHK_NULL_RETURN(m_roiDistinctDeltaQp);
46 
47     return MOS_STATUS_SUCCESS;
48 }
49 
SetQpRoiCtrlPerLcu(StreamInParams * streaminParams,HevcVdencStreamInState * data)50 void NativeROI::SetQpRoiCtrlPerLcu(
51     StreamInParams *streaminParams,
52     HevcVdencStreamInState *data)
53 {
54     if (streaminParams->setQpRoiCtrl != true)
55     {
56         return;
57     }
58     data->DW0.RoiCtrl = streaminParams->roiCtrl;
59 }
60 
SetRoiCtrlMode(uint32_t lcuIndex,uint32_t regionIndex,StreamInParams & streaminParams)61 void NativeROI::SetRoiCtrlMode(
62     uint32_t lcuIndex,
63     uint32_t regionIndex,
64     StreamInParams &streaminParams)
65 {
66     if (regionIndex > m_numRoi || streaminParams.setQpRoiCtrl != true)
67     {
68         return;
69     }
70     // For native ROI, determine Region ID based on distinct
71     // delta Qps and set ROI control
72     uint8_t roiCtrl = 0;
73     for (auto j = 0; j < m_maxNumNativeRoi; j++)
74     {
75         if (m_roiDistinctDeltaQp[j] ==
76                 m_roiRegions[regionIndex].PriorityLevelOrDQp)
77         {
78             // All four 16x16 blocks within the 32x32 blocks
79             // should share the same region ID j
80             roiCtrl = j + 1;
81             for (auto k = 0; k < 3; k++)
82             {
83                 roiCtrl = roiCtrl << 2;
84                 roiCtrl = roiCtrl + j + 1;
85             }
86             break;
87         }
88     }
89 
90     streaminParams.roiCtrl = roiCtrl;
91 }
92 
93 }  // namespace encode