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_vp9_downsampling_feature.cpp
25 //! \brief    Defines the interface for Vp9 decode downsampling feature
26 //! \details  The Vp9 decode downsampling feature interface is maintaining the down sampling context.
27 //!
28 #include "decode_vp9_downsampling_feature.h"
29 #include "decode_vp9_basic_feature.h"
30 #include "decode_utils.h"
31 
32 #ifdef _DECODE_PROCESSING_SUPPORTED
33 
34 namespace decode
35 {
Vp9DownSamplingFeature(MediaFeatureManager * featureManager,DecodeAllocator * allocator,PMOS_INTERFACE osInterface)36 Vp9DownSamplingFeature::Vp9DownSamplingFeature(
37     MediaFeatureManager *featureManager, DecodeAllocator *allocator, PMOS_INTERFACE osInterface) :
38     DecodeDownSamplingFeature(featureManager, allocator, osInterface)
39 {
40 }
41 
~Vp9DownSamplingFeature()42 Vp9DownSamplingFeature::~Vp9DownSamplingFeature()
43 {
44 }
45 
GetRefFrameList(std::vector<uint32_t> & refFrameList)46 MOS_STATUS Vp9DownSamplingFeature::GetRefFrameList(std::vector<uint32_t> &refFrameList)
47 {
48     Vp9BasicFeature *vp9BasicFeature = dynamic_cast<Vp9BasicFeature *>(m_basicFeature);
49     DECODE_CHK_NULL(vp9BasicFeature);
50 
51     uint8_t curFrameIdx = vp9BasicFeature->m_vp9PicParams->CurrPic.FrameIdx;
52     DECODE_CHK_COND(curFrameIdx >= vp9BasicFeature->m_maxFrameIndex, "Frame Index of current frame out of range!");
53     PCODEC_REF_LIST destEntry = vp9BasicFeature->m_refFrames.m_vp9RefList[curFrameIdx];
54     DECODE_CHK_NULL(destEntry);
55 
56     refFrameList.clear();
57     for (auto i = 0; i < CODECHAL_DECODE_VP9_MAX_NUM_REF_FRAME; i++)
58     {
59         uint8_t refFrameIdx = destEntry->RefList[i].FrameIdx;
60         if (refFrameIdx < vp9BasicFeature->m_maxFrameIndex)
61         {
62             refFrameList.push_back(refFrameIdx);
63         }
64     }
65     return MOS_STATUS_SUCCESS;
66 }
67 
GetDecodeTargetFormat(MOS_FORMAT & format)68 MOS_STATUS Vp9DownSamplingFeature::GetDecodeTargetFormat(MOS_FORMAT &format)
69 {
70     Vp9BasicFeature *vp9BasicFeature = dynamic_cast<Vp9BasicFeature *>(m_basicFeature);
71     DECODE_CHK_NULL(vp9BasicFeature);
72     PCODEC_VP9_PIC_PARAMS vp9PicParams = vp9BasicFeature->m_vp9PicParams;
73     DECODE_CHK_NULL(vp9PicParams);
74     if (vp9PicParams->subsampling_x == 1 && vp9PicParams->subsampling_y == 1) //HCP_CHROMA_FORMAT_YUV420
75     {
76         if (vp9PicParams->BitDepthMinus8 > 2)
77         {
78             format = Format_P016;
79         }
80         else if (vp9PicParams->BitDepthMinus8 > 0)
81         {
82             format = Format_P010;
83         }
84         else
85         {
86             format = Format_NV12;
87         }
88     }
89     else if (vp9PicParams->subsampling_x == 0 && vp9PicParams->subsampling_y == 0)  //HCP_CHROMA_FORMAT_YUV444
90     {
91         if (vp9PicParams->BitDepthMinus8 > 2)
92         {
93             format = Format_Y416;
94         }
95         else if (vp9PicParams->BitDepthMinus8 > 0)
96         {
97             format = Format_Y410;
98         }
99         else
100         {
101             format = Format_AYUV;
102         }
103     }
104     else
105     {
106         DECODE_ASSERTMESSAGE("Invalid Chroma sampling format!");
107         return MOS_STATUS_INVALID_PARAMETER;
108     }
109     return MOS_STATUS_SUCCESS;
110 }
111 
UpdateDecodeTarget(MOS_SURFACE & surface)112 MOS_STATUS Vp9DownSamplingFeature::UpdateDecodeTarget(MOS_SURFACE &surface)
113 {
114     Vp9BasicFeature *vp9BasicFeature = dynamic_cast<Vp9BasicFeature *>(m_basicFeature);
115     DECODE_CHK_NULL(vp9BasicFeature);
116 
117     DECODE_CHK_STATUS(vp9BasicFeature->UpdateDestSurface(surface));
118     DECODE_CHK_NULL(vp9BasicFeature->m_vp9PicParams);
119     Vp9ReferenceFrames &refFrames = vp9BasicFeature->m_refFrames;
120     DECODE_CHK_STATUS(refFrames.UpdateCurResource(
121         *vp9BasicFeature->m_vp9PicParams));
122 
123     return MOS_STATUS_SUCCESS;
124 }
125 
GetDecodeTargetSize(SurfaceWidthT & width,SurfaceHeightT & height)126 MOS_STATUS Vp9DownSamplingFeature::GetDecodeTargetSize(SurfaceWidthT &width, SurfaceHeightT &height)
127 {
128     Vp9BasicFeature *vp9BasicFeature = dynamic_cast<Vp9BasicFeature *>(m_basicFeature);
129     DECODE_CHK_NULL(vp9BasicFeature);
130     width  = (uint32_t)vp9BasicFeature->m_vp9PicParams->FrameWidthMinus1 + 1;
131     height = (uint32_t)vp9BasicFeature->m_vp9PicParams->FrameHeightMinus1 + 1;
132     return MOS_STATUS_SUCCESS;
133 }
134 
135 }
136 
137 #endif
138 
139