1 /*
2 * Copyright (c) 2020, 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_avc_downsampling_feature.cpp
25 //! \brief    Defines the interface for avc decode downsampling feature
26 //! \details  The avc decode downsampling feature interface is maintaining the down sampling context.
27 //!
28 #include "decode_avc_downsampling_feature.h"
29 #include "decode_avc_basic_feature.h"
30 #include "decode_utils.h"
31 
32 #ifdef _DECODE_PROCESSING_SUPPORTED
33 
34 namespace decode
35 {
AvcDownSamplingFeature(MediaFeatureManager * featureManager,DecodeAllocator * allocator,PMOS_INTERFACE osInterface)36 AvcDownSamplingFeature::AvcDownSamplingFeature(
37     MediaFeatureManager *featureManager, DecodeAllocator *allocator, PMOS_INTERFACE osInterface) :
38     DecodeDownSamplingFeature(featureManager, allocator, osInterface)
39 {
40 }
41 
~AvcDownSamplingFeature()42 AvcDownSamplingFeature::~AvcDownSamplingFeature()
43 {
44 }
45 
GetRefFrameList(std::vector<uint32_t> & refFrameList)46 MOS_STATUS AvcDownSamplingFeature::GetRefFrameList(std::vector<uint32_t> &refFrameList)
47 {
48     AvcBasicFeature *avcBasicFeature = dynamic_cast<AvcBasicFeature *>(m_basicFeature);
49     DECODE_CHK_NULL(avcBasicFeature);
50 
51     const std::vector<uint8_t> & activeRefList =
52         avcBasicFeature->m_refFrames.GetActiveReferenceList(*avcBasicFeature->m_avcPicParams);
53 
54     refFrameList.clear();
55 
56     for (uint8_t frameIdx : activeRefList)
57     {
58         refFrameList.push_back(frameIdx);
59     }
60 
61     return MOS_STATUS_SUCCESS;
62 }
63 
UpdateInternalTargets(DecodeBasicFeature & basicFeature)64 MOS_STATUS AvcDownSamplingFeature::UpdateInternalTargets(DecodeBasicFeature &basicFeature)
65 {
66     DECODE_FUNC_CALL();
67 
68     AvcBasicFeature *avcBasicFeature = dynamic_cast<AvcBasicFeature *>(m_basicFeature);
69     DECODE_CHK_NULL(avcBasicFeature);
70 
71     uint32_t curFrameIdx = avcBasicFeature->m_curRenderPic.FrameIdx;
72     std::vector<uint32_t> refFrameList;
73     DECODE_CHK_STATUS(GetRefFrameList(refFrameList));
74     DECODE_CHK_STATUS(m_internalTargets.UpdateRefList(curFrameIdx, refFrameList, avcBasicFeature->m_fixedFrameIdx));
75 
76     MOS_SURFACE surface;
77     MOS_ZeroMemory(&surface, sizeof(surface));
78     DECODE_CHK_STATUS(GetDecodeTargetSize(surface.dwWidth, surface.dwHeight));
79     DECODE_CHK_STATUS(GetDecodeTargetFormat(surface.Format));
80     DECODE_CHK_STATUS(m_internalTargets.ActiveCurSurf(
81         curFrameIdx, &surface, basicFeature.IsMmcEnabled(), resourceOutputPicture));
82 
83     return MOS_STATUS_SUCCESS;
84 }
85 
GetDecodeTargetSize(SurfaceWidthT & width,SurfaceHeightT & height)86 MOS_STATUS AvcDownSamplingFeature::GetDecodeTargetSize(SurfaceWidthT &width, SurfaceHeightT &height)
87 {
88     width  = m_basicFeature->m_width;
89     height = m_basicFeature->m_height;
90     return MOS_STATUS_SUCCESS;
91 }
92 
GetDecodeTargetFormat(MOS_FORMAT & format)93 MOS_STATUS AvcDownSamplingFeature::GetDecodeTargetFormat(MOS_FORMAT &format)
94 {
95     AvcBasicFeature *avcBasicFeature = dynamic_cast<AvcBasicFeature *>(m_basicFeature);
96     DECODE_CHK_NULL(avcBasicFeature);
97     PCODEC_AVC_PIC_PARAMS avcPicParams = avcBasicFeature->m_avcPicParams;
98     DECODE_CHK_NULL(avcPicParams);
99 
100     if (avcPicParams->seq_fields.chroma_format_idc == avcChromaFormat420)
101     {
102         format = Format_NV12;
103     }
104     else if (avcPicParams->seq_fields.chroma_format_idc == avcChromaFormatMono)
105     {
106         format = Format_400P;
107     }
108     else
109     {
110         DECODE_ASSERTMESSAGE("Unsupported subsampling format!");
111     }
112 
113     return MOS_STATUS_SUCCESS;
114 }
115 
UpdateDecodeTarget(MOS_SURFACE & surface)116 MOS_STATUS AvcDownSamplingFeature::UpdateDecodeTarget(MOS_SURFACE &surface)
117 {
118     AvcBasicFeature *avcBasicFeature = dynamic_cast<AvcBasicFeature *>(m_basicFeature);
119     DECODE_CHK_NULL(avcBasicFeature);
120 
121     DECODE_CHK_STATUS(avcBasicFeature->UpdateDestSurface(surface));
122 
123     DECODE_CHK_NULL(avcBasicFeature->m_avcPicParams);
124     AvcReferenceFrames &refFrames = avcBasicFeature->m_refFrames;
125     DECODE_CHK_STATUS(refFrames.UpdateCurResource(*avcBasicFeature->m_avcPicParams));
126 
127     return MOS_STATUS_SUCCESS;
128 }
129 
130 }
131 
132 #endif
133