1 /*
2 * Copyright (c) 2018-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 //! \file     media_status_report.h
24 //! \brief    Defines the class for media status report
25 //! \details
26 //!
27 #ifndef __MEDIA_STATUS_REPORT_H__
28 #define __MEDIA_STATUS_REPORT_H__
29 
30 #include "mos_os_specific.h"
31 #include "media_status_report_observer.h"
32 
33 #define STATUS_REPORT_GLOBAL_COUNT 0
34 
35 class MediaStatusReport
36 {
37 public:
38 
39     typedef enum
40     {
41         querySkipped = 0x00,
42         queryStart   = 0x01,
43         queryEnd     = 0xFF
44     } ExecutingStatus;
45 
46     struct StatusBufAddr
47     {
48         MOS_RESOURCE *osResource;
49         uint32_t     offset;
50         uint32_t     bufSize;
51     };
52 
53     //!
54     //! \brief  Constructor
55     //!
MediaStatusReport()56     MediaStatusReport() {};
~MediaStatusReport()57     virtual ~MediaStatusReport() {};
58 
59     //!
60     //! \brief  Create resources for status report and do initialization
61     //! \return MOS_STATUS
62     //!         MOS_STATUS_SUCCESS if success, else fail reason
63     //!
64     virtual MOS_STATUS Create() = 0;
65     //!
66     //! \brief  Initialize the status in report for each item
67     //!
68     //! \details Called per frame for normal usages.
69     //!          It can be called per tilerow if needed.
70     //!
71     //! \param  [in] inputPar
72     //!         Pointer to parameters pass to status report.
73     //! \return MOS_STATUS
74     //!         MOS_STATUS_SUCCESS if success, else fail reason
75     //!
76     virtual MOS_STATUS Init(void *inputPar) = 0;
77     //!
78     //! \brief  Reset Status
79     //!
80     //! \details Called per frame for normal usages.
81     //!          It can be called per tilerow if needed.
82     //!
83     //! \return MOS_STATUS
84     //!         MOS_STATUS_SUCCESS if success, else fail reason
85     //!
86     virtual MOS_STATUS Reset() = 0;
87     //!
88     //! \brief  The entry to get status report.
89     //! \param  [in] numStatus
90     //!         The requested number of status reports
91     //! \param  [out] status
92     //!         The point to encode status
93     //! \return MOS_STATUS
94     //!         MOS_STATUS_SUCCESS if success, else fail reason
95     //!
96     //!
97     MOS_STATUS GetReport(uint16_t numStatus, void *status);
98     //!
99     //! \brief  Get address of status report.
100     //! \param  [in] statusReportType
101     //!         status report item type
102     //! \param  [out] pOsResource
103     //!         The point to PMOS_RESOURCE of each item
104     //! \param  [out] offset
105     //!         Offset of each item
106     //! \return MOS_STATUS
107     //!         MOS_STATUS_SUCCESS if success, else fail reason
108     //!
109     //!
110     MOS_STATUS GetAddress(uint32_t statusReportType, PMOS_RESOURCE &osResource, uint32_t &offset);
111     //!
112     //! \brief  Get submitted count of status report.
113     //! \return m_submittedCount
114     //!
GetSubmittedCount()115     uint32_t GetSubmittedCount() const { return m_submittedCount; }
116 
117     //!
118     //! \brief  Get completed count of status report.
119     //! \return The content of m_completedCount
120     //!
GetCompletedCount()121     uint32_t GetCompletedCount() const
122     {
123         if (m_completedCount == nullptr)
124         {
125             return 0;
126         }
127         return (*m_completedCount);
128     }
129 
130     //!
131     //! \brief  Get reported count of status report.
132     //! \return m_reportedCount
133     //!
GetReportedCount()134     uint32_t GetReportedCount() const { return m_reportedCount; }
135 
GetIndex(uint32_t count)136     uint32_t GetIndex(uint32_t count) { return CounterToIndex(count); }
137     //!
138     //! \brief  Regist observer of complete event.
139     //! \param  [in] observer
140     //!         The point to StatusReportObserver who will observe the complete event
141     //! \return MOS_STATUS
142     //!         MOS_STATUS_SUCCESS if success, else fail reason
143     //!
144     MOS_STATUS RegistObserver(MediaStatusReportObserver *observer);
145 
146     //!
147     //! \brief  Unregist observer of complete event.
148     //! \param  [in] observer
149     //!         The point to StatusReportObserver
150     //! \return MOS_STATUS
151     //!         MOS_STATUS_SUCCESS if success, else fail reason
152     //!
153     MOS_STATUS UnregistObserver(MediaStatusReportObserver *observer);
154 
155 protected:
156     //!
157     //! \brief  Collect the status report information into report buffer.
158     //! \param  [in] report
159     //!         The report buffer address provided by DDI.
160     //! \param  [in] index
161     //!         The index of current requesting report.
162     //! \return MOS_STATUS
163     //!         MOS_STATUS_SUCCESS if success, else fail reason
164     //!
165     virtual MOS_STATUS ParseStatus(void *report, uint32_t index) = 0;
166 
167     //!
168     //! \brief  Set unavailable status report information into report buffer.
169     //! \param  [in] report
170     //!         The report buffer address provided by DDI.
171     //! \return MOS_STATUS
172     //!         MOS_STATUS_SUCCESS if success, else fail reason
173     //!
174     virtual MOS_STATUS SetStatus(void *report, uint32_t index, bool outOfRange = false) = 0;
175     //!
176     //! \brief  Notify observers that the frame has been completed.
177     //! \param  [in] statusBuffer
178     //!         The point to status buffer
179     //! \param  [in,out] statusReport
180     //!         The point to status report
181     //! \return MOS_STATUS
182     //!         MOS_STATUS_SUCCESS if success, else fail reason
183     //!
184     MOS_STATUS NotifyObservers(void *mfxStatus, void *rcsStatus, void *statusReport);
185 
Lock()186     void Lock(){m_lock.lock();};
UnLock()187     void UnLock(){m_lock.unlock();};
188 
CounterToIndex(uint32_t counter)189     inline uint32_t CounterToIndex(uint32_t counter)
190     {
191         return counter & (m_statusNum - 1);
192     }
193 
194     static const uint32_t m_statusNum        = 512;
195 
196     PMOS_RESOURCE    m_completedCountBuf     = nullptr;
197     uint32_t         *m_completedCount       = nullptr;
198     uint32_t         m_submittedCount        = 0;
199     uint32_t         m_reportedCount         = 0;
200     uint32_t         m_sizeOfReport          = 0;
201 
202     StatusBufAddr    *m_statusBufAddr        = nullptr;
203 
204     std::recursive_mutex                      m_lock;
205     std::vector<MediaStatusReportObserver *>  m_completeObservers;
206 MEDIA_CLASS_DEFINE_END(MediaStatusReport)
207 };
208 
209 #endif // !__MEDIA_STATUS_REPORT_H__
210