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 //!
24 //! \file     encode_scalability_option.cpp
25 //! \brief    Defines the common interface for encode scalability option.
26 //!
27 
28 #include "encode_scalability_option.h"
29 #include <stdint.h>
30 #include "encode_scalability_defs.h"
31 #include "media_scalability_defs.h"
32 #include "mhw_vdbox.h"
33 
34 namespace encode
35 {
EncodeScalabilityOption(const EncodeScalabilityOption & pOption)36 EncodeScalabilityOption::EncodeScalabilityOption(const EncodeScalabilityOption &pOption)
37 {
38     m_numPipe = pOption.m_numPipe;
39     m_enabledVdenc = pOption.m_enabledVdenc;
40 }
41 
SetScalabilityOption(ScalabilityPars * params)42 MOS_STATUS EncodeScalabilityOption::SetScalabilityOption(ScalabilityPars *params)
43 {
44     SCALABILITY_CHK_NULL_RETURN(params);
45 
46     EncodeScalabilityPars *encPars = (EncodeScalabilityPars *)params;
47 
48     if (encPars->enableVE == false)
49     {
50         m_numPipe = 1;
51         return MOS_STATUS_SUCCESS;
52     }
53 
54     m_numPipe = encPars->numVdbox;
55     if (encPars->numTileColumns != m_numPipe && !encPars->allowSwArbitarySplit)
56     {
57         m_numPipe = 1;// switch back to the single VDBOX mode if invalid tile column test cases.
58         //only set it when tile colums number less than vdbox number.
59         if (encPars->numTileColumns < encPars->numVdbox && encPars->numTileColumns >= 1 && encPars->numTileColumns <= 4)
60         {
61             m_numPipe = static_cast<uint8_t>(encPars->numTileColumns);
62         }
63     }
64 
65     if (!encPars->forceMultiPipe && !encPars->enableTileReplay)
66     {
67         uint32_t frameWidthTh  = m_4KFrameWdithTh;
68         uint32_t frameHeightTh = m_4KFrameHeightTh;
69         if (encPars->outputChromaFormat == (uint8_t)HCP_CHROMA_FORMAT_YUV420)
70         {
71             frameWidthTh = m_5KFrameWdithTh;
72             frameHeightTh = m_5KFrameWdithTh;
73         }
74         if (encPars->frameWidth < frameWidthTh && encPars->frameHeight <frameHeightTh)
75         {
76             m_numPipe = 1;
77         }
78     }
79     SCALABILITY_VERBOSEMESSAGE("Tile Column = %d, System VDBOX Num = %d, Decided Pipe Num = %d.", encPars->numTileColumns, encPars->numVdbox, m_numPipe);
80 
81     m_enabledVdenc = encPars->enableVDEnc;
82     m_raMode = encPars->raMode;
83     m_protectMode = encPars->protectMode;
84 
85     return MOS_STATUS_SUCCESS;
86 }
87 
IsScalabilityOptionMatched(ScalabilityPars * params)88 bool EncodeScalabilityOption::IsScalabilityOptionMatched(ScalabilityPars *params)
89 {
90     if (params == nullptr)
91     {
92         return false;
93     }
94 
95     bool                   matched  = false;
96     EncodeScalabilityPars *encPars = (EncodeScalabilityPars *)params;
97 
98     EncodeScalabilityOption newOption;
99     newOption.SetScalabilityOption(params);
100 
101     if (m_numPipe != newOption.GetNumPipe() ||
102         m_enabledVdenc != newOption.IsVdencEnabled()||
103         m_raMode != newOption.GetRAMode() ||
104         m_protectMode != newOption.GetProtectMode())
105     {
106         matched = false;
107     }
108     else
109     {
110         matched = true;
111     }
112     return matched;
113 }
114 }
115