1 /*
2 * Copyright (c) 2021-2022, 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_mpeg2_mem_compression.cpp
25 //! \brief    Defines the common interface for Mpeg2 decode mmc
26 //! \details  The mmc is to handle mmc operations,
27 //! including compression and decompressin of Mpeg2 decode
28 //!
29 
30 #include "mos_defs.h"
31 #include "decode_mpeg2_mem_compression.h"
32 #include "decode_utils.h"
33 
34 namespace decode
35 {
36 
Mpeg2DecodeMemComp(CodechalHwInterfaceNext * hwInterface)37 Mpeg2DecodeMemComp::Mpeg2DecodeMemComp(CodechalHwInterfaceNext *hwInterface)
38 {
39     m_osInterface = hwInterface->GetOsInterface();
40 }
41 
CheckReferenceList(Mpeg2BasicFeature & mpeg2BasicFeature,MOS_MEMCOMP_STATE & preDeblockSurfMmcState,MOS_MEMCOMP_STATE & postDeblockSurfMmcState)42 MOS_STATUS Mpeg2DecodeMemComp::CheckReferenceList(
43     Mpeg2BasicFeature &mpeg2BasicFeature, MOS_MEMCOMP_STATE &preDeblockSurfMmcState, MOS_MEMCOMP_STATE &postDeblockSurfMmcState)
44 {
45     MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
46     DECODE_FUNC_CALL();
47     DECODE_CHK_NULL(m_osInterface);
48 
49     if (((postDeblockSurfMmcState != MOS_MEMCOMP_DISABLED) ||
50         (preDeblockSurfMmcState != MOS_MEMCOMP_DISABLED)) &&
51         (mpeg2BasicFeature.m_mpeg2PicParams->m_pictureCodingType != I_TYPE))
52     {
53         bool selfReference = false;
54         if ((mpeg2BasicFeature.m_mpeg2PicParams->m_currPic.FrameIdx == mpeg2BasicFeature.m_mpeg2PicParams->m_forwardRefIdx) ||
55             (mpeg2BasicFeature.m_mpeg2PicParams->m_currPic.FrameIdx == mpeg2BasicFeature.m_mpeg2PicParams->m_backwardRefIdx))
56         {
57             selfReference = true;
58         }
59 
60         if (selfReference)
61         {
62             postDeblockSurfMmcState = MOS_MEMCOMP_DISABLED;
63             preDeblockSurfMmcState  = MOS_MEMCOMP_DISABLED;
64             DECODE_ASSERTMESSAGE("Self-reference is detected for P/B frames!");
65 
66             //Decompress current frame to avoid green corruption in this error handling case
67             MOS_MEMCOMP_STATE mmcMode;
68             DECODE_CHK_STATUS(m_osInterface->pfnGetMemoryCompressionMode(m_osInterface,
69                 &mpeg2BasicFeature.m_destSurface.OsResource,
70                 &mmcMode));
71 
72             if (mmcMode != MOS_MEMCOMP_DISABLED)
73             {
74                 DECODE_CHK_STATUS(m_osInterface->pfnDecompResource(
75                     m_osInterface,
76                     &mpeg2BasicFeature.m_destSurface.OsResource));
77             }
78         }
79     }
80     return eStatus;
81 }
82 
83 }
84