1 /*
2 * Copyright (c) 2019-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_status_report.h
24 //! \brief    Defines the class for decode status report
25 //! \details
26 //!
27 #ifndef __DECODE_STATUS_REPORT_H__
28 #define __DECODE_STATUS_REPORT_H__
29 
30 #include "media_status_report.h"
31 #include "decode_utils.h"
32 #include "decode_allocator.h"
33 #include "decode_status_report_defs.h"
34 
35 namespace decode {
36 
37     //!
38     //! \struct DecodeStatusReportData
39     //! \brief  Decode status report structure
40     //!
41     struct DecodeStatusReportData
42     {
43         //! \brief Status for the picture associated with this status report
44         CODECHAL_STATUS         codecStatus = CODECHAL_STATUS_SUCCESSFUL;
45         //! \brief Status report number associated with the picture in this status report provided in Execute()
46         uint32_t                statusReportNumber = 0;
47         //! \brief Uncompressed frame information for the picture associated with this status report
48         CODEC_PICTURE           currDecodedPic = { 0 };
49         //! \brief Applies for VC1 and MPEG2 only, uncompressed frame information for the out of loop deblock destination
50         CODEC_PICTURE           currDeblockedPic = { 0 };
51         //! \brief Pointer to the resource for the decode render target for the picture associated with this status report
52         MOS_RESOURCE            currDecodedPicRes = { 0 };
53         //! \brief Applies when debug dumps are enabled for VC1 only, resource of deblocked picture
54         MOS_RESOURCE            deblockedPicResOlp = { 0 };
55         //! \brief number of MBs decoded or if unused set to 0xFFFF
56         uint16_t                numMbsAffected = 0;
57         //! \brief Crc of frame from MMIO
58         uint32_t                frameCrc = 0;
59 
60 #if (_DEBUG || _RELEASE_INTERNAL)
61         //! \brief Applies when debug dumps are enabled, pointer to SFC output resource for the picture associated with this status report
62         PMOS_RESOURCE           currSfcOutputPicRes = nullptr;
63         //! \brief Applies when debug dumps are enabled, pointer to histogram output resource for the picture associated with this status report
64         PMOS_RESOURCE           currHistogramOutBuf = nullptr;
65         //! \brief Applies when debug dumps are enabled, pointer to AV1 film grain output resource for the picture associated with this status report
66         PMOS_RESOURCE           currFgOutputPicRes = nullptr;
67         //! \brief Applies when debug dumps are enabled, stream out buffer
68         PMOS_RESOURCE           streamOutBuf = nullptr;
69         //! \brief Applies when debug dumps are enabled, index of the streamout buffer
70         uint32_t                streamoutIdx = 0;
71         //! \brief Applies when debug dumps are enabled, indicates whether or not this is the final field in the frame.
72         bool                    secondField = false;
73         //! \brief Applies to VC1 only, indicates whether or not the frame required OLP.
74         bool                    olpNeeded = false;
75         //! \brief Applies when debug dumps are enabled, frame type (I/P/B)
76         uint16_t                frameType = 0;
77 #endif // (_DEBUG || _RELEASE_INTERNAL)
78     };
79 
80     class DecodeStatusReport : public MediaStatusReport
81     {
82     public:
83         DecodeStatusReport(DecodeAllocator *alloc, bool enableRcs);
84         virtual ~DecodeStatusReport();
85 
86         //!
87         //! \brief  Create resources for status report and do initialization
88         //! \return MOS_STATUS
89         //!         MOS_STATUS_SUCCESS if success, else fail reason
90         //!
91         virtual MOS_STATUS Create() override;
92         //!
93         //! \brief  Destroy resources for status report
94         //! \return MOS_STATUS
95         //!         MOS_STATUS_SUCCESS if success, else fail reason
96         //!
97         virtual MOS_STATUS Destroy();
98         //!
99         //! \brief  Initialize the status in report for each item
100         //!
101         //! \details Called per frame for normal usages.
102         //!          It can be called per tilerow if enable tile replay mode.
103         //!
104         //! \param  [in] inputPar
105         //!         Pointer to parameters pass to status report.
106         //! \return MOS_STATUS
107         //!         MOS_STATUS_SUCCESS if success, else fail reason
108         //!
109         virtual MOS_STATUS Init(void *inputPar) override;
110         //!
111         //! \brief  Reset Status
112         //!
113         //! \details Called per frame for normal usages.
114         //!          It can be called per tilerow if enable tile replay mode.
115         //!
116         //! \return MOS_STATUS
117         //!         MOS_STATUS_SUCCESS if success, else fail reason
118         //!
119         virtual MOS_STATUS Reset() override;
120 
121         //!
122         //! \brief  Get Mfx status for frame specified by counter
123         //! \param  [in] counter
124         //!         The decode counter of requesting frame
125         //! \return DecodeStatusMfx
126         //!         The Mfx status specified by counter
127         //!
128         const DecodeStatusMfx& GetMfxStatus(uint32_t counter);
129 
130         //!
131         //! \brief  Get report data for frame specified by counter
132         //! \param  [in] counter
133         //!         The decode counter of requesting frame
134         //! \return DecodeStatusReportData
135         //!         The report data specified by counter
136         //!
137         const DecodeStatusReportData& GetReportData(uint32_t counter);
138 
139     protected:
140         //!
141         //! \brief  Collect the status report information into report buffer.
142         //! \param  [in] report
143         //!         The report buffer address provided by DDI.
144         //! \param  [in] index
145         //!         The index of current requesting report.
146         //! \return MOS_STATUS
147         //!         MOS_STATUS_SUCCESS if success, else fail reason
148         //!
149         virtual MOS_STATUS ParseStatus(void *report, uint32_t index) override;
150 
151         virtual MOS_STATUS SetStatus(void *report, uint32_t index, bool outOfRange = false) override;
152 
153         //!
154         //! \brief  Set offsets for Mfx status buffer.
155         //! \return void
156         //!
157         void SetOffsetsForStatusBuf();
158 
159         //!
160         //! \brief  Update the status result of current report.
161         //! \param  [in] statusReportData
162         //!         The pointer to DecodeStatusReportData.
163         //! \param  [in] decodeStatus
164         //!         The RCS status report buffer.
165         //! \param  [in] completed
166         //!         Whether the request frame completed.
167         //! \return MOS_STATUS
168         //!         MOS_STATUS_SUCCESS if success, else fail reason
169         //!
170         virtual MOS_STATUS UpdateCodecStatus(
171             DecodeStatusReportData* statusReportData,
172             DecodeStatusMfx* decodeStatus,
173             bool completed);
174 
175     protected:
176 
177         bool                   m_enableRcs = false;
178         DecodeAllocator*       m_allocator = nullptr;  //!< Decode allocator
179 
180         DecodeStatusReportData m_statusReportData[m_statusNum] = {};
181 
182         const uint32_t         m_completedCountSize = sizeof(uint32_t) * 2;
183         const uint32_t         m_statusBufSizeMfx   = MOS_ALIGN_CEIL(sizeof(DecodeStatusMfx), sizeof(uint64_t));
184         const uint32_t         m_statusBufSizeRcs   = MOS_ALIGN_CEIL(sizeof(DecodeStatusRcs), sizeof(uint64_t));
185 
186         PMOS_BUFFER            m_statusBufMfx = nullptr;
187         PMOS_BUFFER            m_statusBufRcs = nullptr;
188         uint8_t               *m_dataStatusMfx = nullptr;
189         uint8_t               *m_dataStatusRcs = nullptr;
190 
191     MEDIA_CLASS_DEFINE_END(DecodeStatusReport)
192     };
193 }
194 
195 #endif // !__DECODE_STATUS_REPORT_H__
196