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 //! \file     decode_downsampling_feature.h
24 //! \brief    Defines the common interface for decode downsampling feature
25 //! \details  The decode downsampling feature interface is further sub-divided by codec standard,
26 //!           this file is for the base interface which is shared by all codecs.
27 //!
28 #ifndef __DECODE_DOWNSAMPLING_FEATURE_H__
29 #define __DECODE_DOWNSAMPLING_FEATURE_H__
30 
31 #include "codec_def_decode.h"
32 #include "decode_allocator.h"
33 #include "media_feature.h"
34 #include "codechal_hw.h"
35 #include "codechal_setting.h"
36 #include "decode_internal_target.h"
37 
38 #ifdef _DECODE_PROCESSING_SUPPORTED
39 
40 namespace decode
41 {
42 class DecodeDownSamplingFeature: public MediaFeature
43 {
44 public:
45     using SurfaceWidthT  = decltype(MOS_SURFACE::dwWidth);
46     using SurfaceHeightT = decltype(MOS_SURFACE::dwHeight);
47 
48     DecodeDownSamplingFeature(MediaFeatureManager *featureManager, DecodeAllocator *allocator, CodechalHwInterface *hwInterface);
49     virtual ~DecodeDownSamplingFeature();
50 
51     //!
52     //! \brief  Init decode basic parameter
53     //! \param  [in] setting
54     //!         Pointer to CodechalSetting
55     //! \return MOS_STATUS
56     //!         MOS_STATUS_SUCCESS if success, else fail reason
57     //!
58     virtual MOS_STATUS Init(void *setting);
59 
60     //!
61     //! \brief  Update decode basic feature
62     //! \param  [in] params
63     //!         Pointer to DecoderParams
64     //! \return MOS_STATUS
65     //!         MOS_STATUS_SUCCESS if success, else fail reason
66     //!
67     virtual MOS_STATUS Update(void *params);
68 
69     virtual MOS_STATUS DumpSfcOutputs(CodechalDebugInterface* debugInterface);
70 
71     // Downsampling input
72     PMOS_SURFACE   m_inputSurface = nullptr;
73     CodecRectangle m_inputSurfaceRegion = {};
74     uint32_t       m_chromaSitingType = 0;
75 
76     // Downsampling output
77     MOS_SURFACE    m_outputSurface;
78     CodecRectangle m_outputSurfaceRegion = {};
79 
80     // Downsampling parameters
81     uint32_t       m_rotationState = 0;
82     uint32_t       m_blendState = 0;
83     uint32_t       m_mirrorState = 0;
84     bool           m_isInputSurfAllocated = false;
85     bool           m_isReferenceOnlyPattern = false;
86 
87     CODECHAL_SCALING_MODE  m_scalingMode = CODECHAL_SCALING_NEAREST;
88 
89     // Histogram
90     PMOS_BUFFER    m_histogramBuffer   = nullptr;  // SFC histogram internal buffer for current frame
91     PMOS_SURFACE   m_histogramDestSurf = nullptr;  // SFC histogram dest surface
92     bool           m_histogramDebug    = false;
93     const uint32_t m_histogramBinWidth = 4;
94 
95 #if (_DEBUG || _RELEASE_INTERNAL)
96     MOS_SURFACE    m_outputSurfaceList[DecodeBasicFeature::m_maxFrameIndex] = {}; //! \brief Downsampled surfaces
97 #endif
98 
99 protected:
100     virtual MOS_STATUS UpdateInternalTargets(DecodeBasicFeature &basicFeature);
101 
102     virtual MOS_STATUS GetRefFrameList(std::vector<uint32_t> &refFrameList) = 0;
103     virtual MOS_STATUS GetDecodeTargetSize(SurfaceWidthT &width, SurfaceHeightT &height) = 0;
104     virtual MOS_STATUS GetDecodeTargetFormat(MOS_FORMAT &format) = 0;
105     virtual MOS_STATUS UpdateDecodeTarget(MOS_SURFACE &surface) = 0;
106     PMOS_BUFFER        AllocateHistogramBuffer(uint8_t frameIndex);
107 
108     CodechalHwInterface *m_hwInterface  = nullptr;
109     DecodeAllocator     *m_allocator    = nullptr;
110     DecodeBasicFeature  *m_basicFeature = nullptr;
111 
112     InternalTargets      m_internalTargets; //!< Internal targets for downsampling input if application dosen't prepare
113     PMOS_BUFFER          m_histogramBufferList[DecodeBasicFeature::m_maxFrameIndex] = {};  //! \brief Internal histogram output buffer list
114 
115 MEDIA_CLASS_DEFINE_END(DecodeDownSamplingFeature)
116 };
117 }//decode
118 
119 #endif // !_DECODE_PROCESSING_SUPPORTED
120 
121 #endif // !__DECODE_DOWNSAMPLING_FEATURE_H__
122