1 /*
2 * Copyright (c) 2021, 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     decode_vp8_mem_compression.cpp
25 //! \brief    Defines the common interface for Vp8 decode mmc
26 //! \details  The mmc is to handle mmc operations,
27 //! including compression and decompressin of Vp8 decode
28 //!
29 
30 #include "mos_defs.h"
31 #include "decode_utils.h"
32 #include "decode_vp8_mem_compression.h"
33 
34 #ifdef _MMC_SUPPORTED
35 
36 namespace decode
37 {
Vp8DecodeMemComp(CodechalHwInterfaceNext * hwInterface)38 Vp8DecodeMemComp::Vp8DecodeMemComp(CodechalHwInterfaceNext *hwInterface)
39 {
40     m_osInterface = hwInterface->GetOsInterface();
41 }
42 
CheckReferenceList(Vp8BasicFeature & vp8BasicFeature,MOS_MEMCOMP_STATE & PostDeblockSurfMmcState,MOS_MEMCOMP_STATE & PreDeblockSurfMmcState)43 MOS_STATUS Vp8DecodeMemComp::CheckReferenceList(Vp8BasicFeature &vp8BasicFeature,
44                                                 MOS_MEMCOMP_STATE &PostDeblockSurfMmcState,
45                                                 MOS_MEMCOMP_STATE &PreDeblockSurfMmcState)
46 {
47     DECODE_FUNC_CALL();
48     DECODE_CHK_NULL(m_osInterface);
49 
50     MOS_MEMCOMP_STATE mmcMode;
51 
52     DECODE_ASSERT(vp8BasicFeature.m_vp8PicParams);
53     auto &vp8PicParams = *(vp8BasicFeature.m_vp8PicParams);
54 
55     //Disable MMC if self-reference is detected (mainly for error concealment)
56     if ((PostDeblockSurfMmcState != MOS_MEMCOMP_DISABLED) ||
57         (PreDeblockSurfMmcState != MOS_MEMCOMP_DISABLED) &&
58         (vp8PicParams.key_frame != I_TYPE))
59     {
60         bool selfReference = false;
61         if ((vp8PicParams.ucCurrPicIndex == vp8PicParams.ucLastRefPicIndex) ||
62             (vp8PicParams.ucCurrPicIndex == vp8PicParams.ucGoldenRefPicIndex) ||
63             (vp8PicParams.ucCurrPicIndex ==vp8PicParams.ucAltRefPicIndex))
64         {
65             selfReference = true;
66         }
67 
68         if (selfReference)
69         {
70             PostDeblockSurfMmcState = MOS_MEMCOMP_DISABLED;
71             PreDeblockSurfMmcState  = MOS_MEMCOMP_DISABLED;
72             DECODE_NORMALMESSAGE("Self-reference is detected for P/B frames!");
73 
74             // Decompress current frame to avoid green corruptions in this error handling case
75             MOS_SURFACE &destSurface = vp8BasicFeature.m_destSurface;
76             DECODE_CHK_STATUS(m_osInterface->pfnGetMemoryCompressionMode(
77                                 m_osInterface,
78                                 &destSurface.OsResource,
79                                 &mmcMode));
80             if (mmcMode != MOS_MEMCOMP_DISABLED)
81             {
82                 DECODE_CHK_STATUS(m_osInterface->pfnDecompResource(
83                                 m_osInterface,
84                                 &destSurface.OsResource));
85             }
86         }
87 
88     }
89 
90     return MOS_STATUS_SUCCESS;
91 }
92 
SetPipeBufAddr(Vp8BasicFeature & vp8BasicFeature,MOS_MEMCOMP_STATE & PostDeblockSurfMmcState,MOS_MEMCOMP_STATE & PreDeblockSurfMmcState)93 MOS_STATUS Vp8DecodeMemComp::SetPipeBufAddr(Vp8BasicFeature &vp8BasicFeature,
94                                             MOS_MEMCOMP_STATE &PostDeblockSurfMmcState,
95                                             MOS_MEMCOMP_STATE &PreDeblockSurfMmcState)
96 {
97     DECODE_FUNC_CALL();
98     MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
99 
100     if (m_mmcEnabled)
101     {
102         DECODE_CHK_STATUS(m_osInterface->pfnGetMemoryCompressionMode(m_osInterface,
103             &vp8BasicFeature.m_destSurface.OsResource,
104             &PreDeblockSurfMmcState));
105     }
106     else
107     {
108         PreDeblockSurfMmcState = MOS_MEMCOMP_DISABLED;
109     }
110     PostDeblockSurfMmcState = PreDeblockSurfMmcState;
111 
112     vp8BasicFeature.m_destSurface.MmcState = vp8BasicFeature.m_deblockingEnabled ? PostDeblockSurfMmcState : PreDeblockSurfMmcState;
113 
114     return eStatus;
115 }
116 
117 }  // namespace decode
118 #endif
119