| 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 | //! |
| 24 | //! \file media_status_report.cpp |
| 25 | //! \brief Defines the common interface for media status reporter |
| 26 | //! \details |
| 27 | //! |
| 28 | #include <algorithm> |
| 29 | #include "media_status_report.h" |
| 30 | #include "mos_os.h" |
| 31 | |
| 32 | MediaStatusReport::MediaStatusReport(PMOS_INTERFACE osInterface) |
| 33 | { |
| 34 | if (osInterface && osInterface->pfnGetUserSettingInstance) |
| 35 | { |
| 36 | m_userSettingPtr = osInterface->pfnGetUserSettingInstance(osInterface); |
| 37 | } |
| 38 | #if (_DEBUG || _RELEASE_INTERNAL) |
| 39 | ReadUserSettingForDebug( |
| 40 | m_userSettingPtr, |
| 41 | m_enableVdboxIdReport, |
| 42 | __MEDIA_USER_FEATURE_VALUE_ENABLE_VDBOX_ID_REPORT, |
| 43 | MediaUserSetting::Group::Device); |
| 44 | #endif |
| 45 | } |
| 46 | |
| 47 | MOS_STATUS MediaStatusReport::GetAddress(uint32_t statusReportType, PMOS_RESOURCE &osResource, uint32_t &offset) |
| 48 | { |
| 49 | MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 50 | |
| 51 | if (m_statusBufAddr == nullptr) |
| 52 | return MOS_STATUS_NULL_POINTER; |
| 53 | |
| 54 | osResource = m_statusBufAddr[statusReportType].osResource; |
| 55 | |
| 56 | if (statusReportType == STATUS_REPORT_GLOBAL_COUNT) |
| 57 | { |
| 58 | offset = m_statusBufAddr[statusReportType].offset; |
| 59 | } |
| 60 | else |
| 61 | { |
| 62 | offset = m_statusBufAddr[statusReportType].offset + m_statusBufAddr[statusReportType].bufSize * CounterToIndex(m_submittedCount); |
| 63 | } |
| 64 | |
| 65 | return eStatus; |
| 66 | } |
| 67 | |
| 68 | MOS_STATUS MediaStatusReport::GetReport(uint16_t requireNum, void *status) |
| 69 | |
| 70 | { |
| 71 | MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 72 | |
| 73 | Lock(); |
| 74 | uint32_t completedCount = *m_completedCount; |
| 75 | uint32_t reportedCount = m_reportedCount; |
| 76 | uint32_t reportedCountOrigin = m_reportedCount; |
| 77 | uint32_t availableCount = m_submittedCount - reportedCount; |
| 78 | uint32_t generatedReportCount = 0; |
| 79 | uint32_t reportIndex = 0; |
| 80 | bool reverseOrder = (requireNum > 1); |
| 81 | |
| 82 | while (reportedCount != completedCount && generatedReportCount < requireNum){ |
| 83 | |
| 84 | // Get reverse order index to temporally fix application get status report size bigger than 2 case. |
| 85 | reportIndex = reverseOrder ? CounterToIndex(completedCount + reportedCountOrigin - reportedCount -1) : |
| 86 | CounterToIndex(reportedCount); |
| 87 | // m_reportedCount is used by component. Need to assign actual index before call ParseStatus |
| 88 | m_reportedCount = reportIndex; |
| 89 | eStatus = ParseStatus(((uint8_t*)status + m_sizeOfReport * generatedReportCount), reportIndex); |
| 90 | |
| 91 | reportedCount++; |
| 92 | generatedReportCount++; |
| 93 | } |
| 94 | |
| 95 | // update incomplete/unavailable status |
| 96 | uint32_t updatedCount = reportedCount; |
| 97 | if (generatedReportCount < requireNum) |
| 98 | { |
| 99 | for (auto i = generatedReportCount; i < requireNum; i++) |
| 100 | { |
| 101 | eStatus = SetStatus(((uint8_t *)status + m_sizeOfReport * i), |
| 102 | CounterToIndex(updatedCount), |
| 103 | i >= availableCount); |
| 104 | updatedCount++; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | m_reportedCount = reportedCount; |
| 109 | UnLock(); |
| 110 | |
| 111 | return eStatus; |
| 112 | } |
| 113 | |
| 114 | MOS_STATUS MediaStatusReport::RegistObserver(MediaStatusReportObserver *observer) |
| 115 | { |
| 116 | MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 117 | std::vector<MediaStatusReportObserver *>::iterator it; |
| 118 | |
| 119 | it = std::find(m_completeObservers.begin(), m_completeObservers.end(), observer); |
| 120 | if (it != m_completeObservers.end()) |
| 121 | { |
| 122 | // the observer already in the vector |
| 123 | return MOS_STATUS_SUCCESS; |
| 124 | } |
| 125 | |
| 126 | Lock(); |
| 127 | m_completeObservers.push_back(observer); |
| 128 | UnLock(); |
| 129 | |
| 130 | return eStatus; |
| 131 | } |
| 132 | |
| 133 | MOS_STATUS MediaStatusReport::UnregistObserver(MediaStatusReportObserver *observer) |
| 134 | { |
| 135 | MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 136 | std::vector<MediaStatusReportObserver *>::iterator it; |
| 137 | |
| 138 | it = std::find(m_completeObservers.begin(), m_completeObservers.end(), observer); |
| 139 | if (it == m_completeObservers.end()) |
| 140 | { |
| 141 | // the observer not in the vector |
| 142 | return MOS_STATUS_INVALID_PARAMETER; |
| 143 | } |
| 144 | |
| 145 | Lock(); |
| 146 | m_completeObservers.erase(it); |
| 147 | UnLock(); |
| 148 | |
| 149 | return eStatus; |
| 150 | } |
| 151 | |
| 152 | MOS_STATUS MediaStatusReport::NotifyObservers(void *mfxStatus, void *rcsStatus, void *statusReport) |
| 153 | { |
| 154 | MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 155 | std::vector<MediaStatusReportObserver *>::iterator it; |
| 156 | |
| 157 | for (it = m_completeObservers.begin(); it != m_completeObservers.end(); it++) |
| 158 | { |
| 159 | eStatus = (*it)->Completed(mfxStatus, rcsStatus, statusReport); |
| 160 | } |
| 161 | |
| 162 | return eStatus; |
| 163 | } |
| 164 | |
| 165 | #if (_DEBUG || _RELEASE_INTERNAL) |
| 166 | void MediaStatusReport::ParseVdboxIdsFromBuf(const uint32_t *csEngineIdRegBuf) |
| 167 | { |
| 168 | for (auto i = 0; i < csInstanceIdMax; i++) |
| 169 | { |
| 170 | CsEngineId csEngineId; |
| 171 | csEngineId.value = csEngineIdRegBuf[i]; |
| 172 | if (csEngineId.fields.classId == classIdVideoEngine) |
| 173 | { |
| 174 | m_usedVdboxIds |= 1 << ((csEngineId.fields.instanceId) << 2); |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | MOS_STATUS MediaStatusReport::ReportUsedVdboxIds() |
| 180 | { |
| 181 | if (m_enableVdboxIdReport) |
| 182 | { |
| 183 | uint32_t reportedUsedID = 0; |
| 184 | ReadUserSettingForDebug( |
| 185 | m_userSettingPtr, |
| 186 | reportedUsedID, |
| 187 | __MEDIA_USER_FEATURE_VALUE_USED_VDBOX_ID, |
| 188 | MediaUserSetting::Group::Device, |
| 189 | 0, |
| 190 | false, |
| 191 | MEDIA_USER_SETTING_INTERNAL_REPORT); |
| 192 | ReportUserSettingForDebug( |
| 193 | m_userSettingPtr, |
| 194 | __MEDIA_USER_FEATURE_VALUE_USED_VDBOX_ID, |
| 195 | reportedUsedID | m_usedVdboxIds, |
| 196 | MediaUserSetting::Group::Device); |
| 197 | } |
| 198 | return MOS_STATUS_SUCCESS; |
| 199 | } |
| 200 | #endif |