Loading camera/ndk/impl/ACameraManager.cpp +43 −20 Original line number Diff line number Diff line Loading @@ -76,6 +76,10 @@ static bool isCameraServiceDisabled() { sp<hardware::ICameraService> CameraManagerGlobal::getCameraService() { Mutex::Autolock _l(mLock); return getCameraServiceLocked(); } sp<hardware::ICameraService> CameraManagerGlobal::getCameraServiceLocked() { if (mCameraService.get() == nullptr) { if (isCameraServiceDisabled()) { return mCameraService; Loading Loading @@ -216,8 +220,12 @@ void CameraManagerGlobal::registerAvailabilityCallback( if (pair.second) { for (auto& pair : mDeviceStatusMap) { const String8& cameraId = pair.first; int32_t status = pair.second; int32_t status = pair.second.status; // Don't send initial callbacks for camera ids which don't support // camera2 if (!pair.second.supportsHAL3) { continue; } sp<AMessage> msg = new AMessage(kWhatSendSingleCallback, mHandler); ACameraManager_AvailabilityCallback cb = isStatusAvailable(status) ? callback->onCameraAvailable : callback->onCameraUnavailable; Loading @@ -236,20 +244,32 @@ void CameraManagerGlobal::unregisterAvailabilityCallback( mCallbacks.erase(cb); } bool CameraManagerGlobal::supportsCamera2ApiLocked(const String8 &cameraId) { bool camera2Support = false; auto cs = getCameraServiceLocked(); binder::Status serviceRet = cs->supportsCameraApi(String16(cameraId), hardware::ICameraService::API_VERSION_2, &camera2Support); if (!serviceRet.isOk()) { ALOGE("%s: supportsCameraApi2Locked() call failed for cameraId %s", __FUNCTION__, cameraId.c_str()); return false; } return camera2Support; } void CameraManagerGlobal::getCameraIdList(std::vector<String8>* cameraIds) { // Ensure that we have initialized/refreshed the list of available devices auto cs = getCameraService(); Mutex::Autolock _l(mLock); // Needed to make sure we're connected to cameraservice getCameraServiceLocked(); for(auto& deviceStatus : mDeviceStatusMap) { if (deviceStatus.second == hardware::ICameraServiceListener::STATUS_NOT_PRESENT || deviceStatus.second == hardware::ICameraServiceListener::STATUS_ENUMERATING) { if (deviceStatus.second.status == hardware::ICameraServiceListener::STATUS_NOT_PRESENT || deviceStatus.second.status == hardware::ICameraServiceListener::STATUS_ENUMERATING) { continue; } bool camera2Support = false; binder::Status serviceRet = cs->supportsCameraApi(String16(deviceStatus.first), hardware::ICameraService::API_VERSION_2, &camera2Support); if (!serviceRet.isOk() || !camera2Support) { if (!deviceStatus.second.supportsHAL3) { continue; } cameraIds->push_back(deviceStatus.first); Loading Loading @@ -377,7 +397,7 @@ void CameraManagerGlobal::onStatusChangedLocked( bool firstStatus = (mDeviceStatusMap.count(cameraId) == 0); int32_t oldStatus = firstStatus ? status : // first status mDeviceStatusMap[cameraId]; mDeviceStatusMap[cameraId].status; if (!firstStatus && isStatusAvailable(status) == isStatusAvailable(oldStatus)) { Loading @@ -385,8 +405,10 @@ void CameraManagerGlobal::onStatusChangedLocked( return; } bool supportsHAL3 = supportsCamera2ApiLocked(cameraId); // Iterate through all registered callbacks mDeviceStatusMap[cameraId] = status; mDeviceStatusMap[cameraId] = StatusAndHAL3Support(status, supportsHAL3); if (supportsHAL3) { for (auto cb : mCallbacks) { sp<AMessage> msg = new AMessage(kWhatSendSingleCallback, mHandler); ACameraManager_AvailabilityCallback cbFp = isStatusAvailable(status) ? Loading @@ -396,6 +418,7 @@ void CameraManagerGlobal::onStatusChangedLocked( msg->setString(kCameraIdKey, AString(cameraId)); msg->post(); } } if (status == hardware::ICameraServiceListener::STATUS_NOT_PRESENT) { mDeviceStatusMap.erase(cameraId); } Loading camera/ndk/impl/ACameraManager.h +14 −4 Original line number Diff line number Diff line Loading @@ -156,12 +156,14 @@ class CameraManagerGlobal final : public RefBase { sp<CallbackHandler> mHandler; sp<ALooper> mCbLooper; // Looper thread where callbacks actually happen on sp<hardware::ICameraService> getCameraServiceLocked(); void onCameraAccessPrioritiesChanged(); void onStatusChanged(int32_t status, const String8& cameraId); void onStatusChangedLocked(int32_t status, const String8& cameraId); // Utils for status static bool validStatus(int32_t status); static bool isStatusAvailable(int32_t status); bool supportsCamera2ApiLocked(const String8 &cameraId); // The sort logic must match the logic in // libcameraservice/common/CameraProviderManager.cpp::getAPI1CompatibleCameraDeviceIds Loading @@ -184,8 +186,16 @@ class CameraManagerGlobal final : public RefBase { } }; struct StatusAndHAL3Support { int32_t status = hardware::ICameraServiceListener::STATUS_NOT_PRESENT; bool supportsHAL3 = false; StatusAndHAL3Support(int32_t st, bool HAL3support): status(st), supportsHAL3(HAL3support) { }; StatusAndHAL3Support() = default; }; // Map camera_id -> status std::map<String8, int32_t, CameraIdComparator> mDeviceStatusMap; std::map<String8, StatusAndHAL3Support, CameraIdComparator> mDeviceStatusMap; // For the singleton instance static Mutex sLock; Loading drm/libmediadrm/Android.bp +22 −4 Original line number Diff line number Diff line Loading @@ -95,8 +95,6 @@ cc_library_shared { "android.hardware.drm@1.0", "android.hardware.drm@1.1", "android.hardware.drm@1.2", "libbinder", "libhidlbase", "liblog", "libmediametrics", "libprotobuf-cpp-lite", Loading Loading @@ -134,8 +132,6 @@ cc_library_shared { "android.hardware.drm@1.1", "android.hardware.drm@1.2", "libbase", "libbinder", "libhidlbase", "liblog", "libmediametrics", "libprotobuf-cpp-full", Loading @@ -149,3 +145,25 @@ cc_library_shared { ], } cc_library_shared { name: "libmediadrmmetrics_consumer", srcs: [ "DrmMetricsConsumer.cpp", ], include_dirs: [ "frameworks/av/media/libmedia/include" ], shared_libs: [ "android.hardware.drm@1.0", "android.hardware.drm@1.1", "android.hardware.drm@1.2", "libbinder", "libhidlbase", "liblog", "libmediadrm", "libmediadrmmetrics_full", "libutils", ], } drm/libmediadrm/DrmHal.cpp +5 −8 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ #include <mediadrm/DrmHal.h> #include <mediadrm/DrmSessionClientInterface.h> #include <mediadrm/DrmSessionManager.h> #include <mediadrm/IDrmMetricsConsumer.h> #include <vector> Loading Loading @@ -1362,11 +1363,11 @@ status_t DrmHal::setPropertyByteArray(String8 const &name, return status.isOk() ? toStatusT(status) : DEAD_OBJECT; } status_t DrmHal::getMetrics(PersistableBundle* metrics) { if (metrics == nullptr) { status_t DrmHal::getMetrics(const sp<IDrmMetricsConsumer> &consumer) { if (consumer == nullptr) { return UNEXPECTED_NULL; } mMetrics.Export(metrics); consumer->consumeFrameworkMetrics(mMetrics); // Append vendor metrics if they are supported. if (mPluginV1_1 != NULL) { Loading @@ -1393,11 +1394,7 @@ status_t DrmHal::getMetrics(PersistableBundle* metrics) { if (status != Status::OK) { ALOGV("Error getting plugin metrics: %d", status); } else { PersistableBundle pluginBundle; if (MediaDrmMetrics::HidlMetricsToBundle( pluginMetrics, &pluginBundle) == OK) { metrics->putPersistableBundle(String16(vendor), pluginBundle); } consumer->consumeHidlMetrics(vendor, pluginMetrics); } err = toStatusT(status); }); Loading drm/libmediadrm/DrmMetrics.cpp +4 −225 Original line number Diff line number Diff line Loading @@ -29,143 +29,12 @@ using ::android::String16; using ::android::String8; using ::android::drm_metrics::DrmFrameworkMetrics; using ::android::hardware::hidl_string; using ::android::hardware::hidl_vec; using ::android::hardware::drm::V1_0::EventType; using ::android::hardware::drm::V1_2::KeyStatusType; using ::android::hardware::drm::V1_1::DrmMetricGroup; using ::android::os::PersistableBundle; namespace { template <typename T> std::string GetAttributeName(T type); template <> std::string GetAttributeName<KeyStatusType>(KeyStatusType type) { static const char *type_names[] = {"USABLE", "EXPIRED", "OUTPUT_NOT_ALLOWED", "STATUS_PENDING", "INTERNAL_ERROR"}; if (((size_t)type) > arraysize(type_names)) { return "UNKNOWN_TYPE"; } return type_names[(size_t)type]; } template <> std::string GetAttributeName<EventType>(EventType type) { static const char *type_names[] = {"PROVISION_REQUIRED", "KEY_NEEDED", "KEY_EXPIRED", "VENDOR_DEFINED", "SESSION_RECLAIMED"}; if (((size_t)type) > arraysize(type_names)) { return "UNKNOWN_TYPE"; } return type_names[(size_t)type]; } template <typename T> void ExportCounterMetric(const android::CounterMetric<T> &counter, PersistableBundle *metrics) { if (!metrics) { ALOGE("metrics was unexpectedly null."); return; } std::string success_count_name = counter.metric_name() + ".ok.count"; std::string error_count_name = counter.metric_name() + ".error.count"; std::vector<int64_t> status_values; counter.ExportValues( [&](const android::status_t status, const int64_t value) { if (status == android::OK) { metrics->putLong(android::String16(success_count_name.c_str()), value); } else { int64_t total_errors(0); metrics->getLong(android::String16(error_count_name.c_str()), &total_errors); metrics->putLong(android::String16(error_count_name.c_str()), total_errors + value); status_values.push_back(status); } }); if (!status_values.empty()) { std::string error_list_name = counter.metric_name() + ".error.list"; metrics->putLongVector(android::String16(error_list_name.c_str()), status_values); } } template <typename T> void ExportCounterMetricWithAttributeNames( const android::CounterMetric<T> &counter, PersistableBundle *metrics) { if (!metrics) { ALOGE("metrics was unexpectedly null."); return; } counter.ExportValues([&](const T &attribute, const int64_t value) { std::string name = counter.metric_name() + "." + GetAttributeName(attribute) + ".count"; metrics->putLong(android::String16(name.c_str()), value); }); } template <typename T> void ExportEventMetric(const android::EventMetric<T> &event, PersistableBundle *metrics) { if (!metrics) { ALOGE("metrics was unexpectedly null."); return; } std::string success_count_name = event.metric_name() + ".ok.count"; std::string error_count_name = event.metric_name() + ".error.count"; std::string timing_name = event.metric_name() + ".ok.average_time_micros"; std::vector<int64_t> status_values; event.ExportValues([&](const android::status_t &status, const android::EventStatistics &value) { if (status == android::OK) { metrics->putLong(android::String16(success_count_name.c_str()), value.count); metrics->putLong(android::String16(timing_name.c_str()), value.mean); } else { int64_t total_errors(0); metrics->getLong(android::String16(error_count_name.c_str()), &total_errors); metrics->putLong(android::String16(error_count_name.c_str()), total_errors + value.count); status_values.push_back(status); } }); if (!status_values.empty()) { std::string error_list_name = event.metric_name() + ".error.list"; metrics->putLongVector(android::String16(error_list_name.c_str()), status_values); } } void ExportSessionLifespans( const std::map<std::string, std::pair<int64_t, int64_t>> &mSessionLifespans, PersistableBundle *metrics) { if (!metrics) { ALOGE("metrics was unexpectedly null."); return; } if (mSessionLifespans.empty()) { return; } PersistableBundle startTimesBundle; PersistableBundle endTimesBundle; for (auto it = mSessionLifespans.begin(); it != mSessionLifespans.end(); it++) { String16 key(it->first.c_str(), it->first.size()); startTimesBundle.putLong(key, it->second.first); endTimesBundle.putLong(key, it->second.second); } metrics->putPersistableBundle( android::String16("drm.mediadrm.session_start_times_ms"), startTimesBundle); metrics->putPersistableBundle( android::String16("drm.mediadrm.session_end_times_ms"), endTimesBundle); } std::string ToHexString(const android::Vector<uint8_t> &sessionId) { std::ostringstream out; out << std::hex << std::setfill('0'); Loading @@ -175,31 +44,6 @@ std::string ToHexString(const android::Vector<uint8_t> &sessionId) { return out.str(); } template <typename CT> void SetValue(const String16 &name, DrmMetricGroup::ValueType type, const CT &value, PersistableBundle *bundle) { switch (type) { case DrmMetricGroup::ValueType::INT64_TYPE: bundle->putLong(name, value.int64Value); break; case DrmMetricGroup::ValueType::DOUBLE_TYPE: bundle->putDouble(name, value.doubleValue); break; case DrmMetricGroup::ValueType::STRING_TYPE: bundle->putString(name, String16(value.stringValue.c_str())); break; default: ALOGE("Unexpected value type: %hhu", type); } } inline String16 MakeIndexString(unsigned int index) { std::string str("["); str.append(std::to_string(index)); str.append("]"); return String16(str.c_str()); } } // namespace namespace android { Loading Loading @@ -237,23 +81,6 @@ void MediaDrmMetrics::SetSessionEnd(const android::Vector<uint8_t> &sessionId) { } } void MediaDrmMetrics::Export(PersistableBundle *metrics) { if (!metrics) { ALOGE("metrics was unexpectedly null."); return; } ExportCounterMetric(mOpenSessionCounter, metrics); ExportCounterMetric(mCloseSessionCounter, metrics); ExportEventMetric(mGetKeyRequestTimeUs, metrics); ExportEventMetric(mProvideKeyResponseTimeUs, metrics); ExportCounterMetric(mGetProvisionRequestCounter, metrics); ExportCounterMetric(mProvideProvisionResponseCounter, metrics); ExportCounterMetricWithAttributeNames(mKeyStatusChangeCounter, metrics); ExportCounterMetricWithAttributeNames(mEventCounter, metrics); ExportCounterMetric(mGetDeviceUniqueIdCounter, metrics); ExportSessionLifespans(mSessionLifespans, metrics); } status_t MediaDrmMetrics::GetSerializedMetrics(std::string *serializedMetrics) { if (!serializedMetrics) { Loading Loading @@ -361,62 +188,14 @@ status_t MediaDrmMetrics::GetSerializedMetrics(std::string *serializedMetrics) { return OK; } std::map<std::string, std::pair<int64_t, int64_t>> MediaDrmMetrics::GetSessionLifespans() const { return mSessionLifespans; } int64_t MediaDrmMetrics::GetCurrentTimeMs() { struct timeval tv; gettimeofday(&tv, NULL); return ((int64_t)tv.tv_sec * 1000) + ((int64_t)tv.tv_usec / 1000); } status_t MediaDrmMetrics::HidlMetricsToBundle( const hidl_vec<DrmMetricGroup> &hidlMetricGroups, PersistableBundle *bundleMetricGroups) { if (bundleMetricGroups == nullptr) { return UNEXPECTED_NULL; } if (hidlMetricGroups.size() == 0) { return OK; } int groupIndex = 0; std::map<String16, int> indexMap; for (const auto &hidlMetricGroup : hidlMetricGroups) { PersistableBundle bundleMetricGroup; for (const auto &hidlMetric : hidlMetricGroup.metrics) { String16 metricName(hidlMetric.name.c_str()); PersistableBundle bundleMetric; // Add metric component values. for (const auto &value : hidlMetric.values) { SetValue(String16(value.componentName.c_str()), value.type, value, &bundleMetric); } // Set metric attributes. PersistableBundle bundleMetricAttributes; for (const auto &attribute : hidlMetric.attributes) { SetValue(String16(attribute.name.c_str()), attribute.type, attribute, &bundleMetricAttributes); } // Add attributes to the bundle metric. bundleMetric.putPersistableBundle(String16("attributes"), bundleMetricAttributes); // Add one layer of indirection, allowing for repeated metric names. PersistableBundle repeatedMetrics; bundleMetricGroup.getPersistableBundle(metricName, &repeatedMetrics); int index = indexMap[metricName]; repeatedMetrics.putPersistableBundle(MakeIndexString(index), bundleMetric); indexMap[metricName] = ++index; // Add the bundle metric to the group of metrics. bundleMetricGroup.putPersistableBundle(metricName, repeatedMetrics); } // Add the bundle metric group to the collection of groups. bundleMetricGroups->putPersistableBundle(MakeIndexString(groupIndex++), bundleMetricGroup); } return OK; } } // namespace android Loading
camera/ndk/impl/ACameraManager.cpp +43 −20 Original line number Diff line number Diff line Loading @@ -76,6 +76,10 @@ static bool isCameraServiceDisabled() { sp<hardware::ICameraService> CameraManagerGlobal::getCameraService() { Mutex::Autolock _l(mLock); return getCameraServiceLocked(); } sp<hardware::ICameraService> CameraManagerGlobal::getCameraServiceLocked() { if (mCameraService.get() == nullptr) { if (isCameraServiceDisabled()) { return mCameraService; Loading Loading @@ -216,8 +220,12 @@ void CameraManagerGlobal::registerAvailabilityCallback( if (pair.second) { for (auto& pair : mDeviceStatusMap) { const String8& cameraId = pair.first; int32_t status = pair.second; int32_t status = pair.second.status; // Don't send initial callbacks for camera ids which don't support // camera2 if (!pair.second.supportsHAL3) { continue; } sp<AMessage> msg = new AMessage(kWhatSendSingleCallback, mHandler); ACameraManager_AvailabilityCallback cb = isStatusAvailable(status) ? callback->onCameraAvailable : callback->onCameraUnavailable; Loading @@ -236,20 +244,32 @@ void CameraManagerGlobal::unregisterAvailabilityCallback( mCallbacks.erase(cb); } bool CameraManagerGlobal::supportsCamera2ApiLocked(const String8 &cameraId) { bool camera2Support = false; auto cs = getCameraServiceLocked(); binder::Status serviceRet = cs->supportsCameraApi(String16(cameraId), hardware::ICameraService::API_VERSION_2, &camera2Support); if (!serviceRet.isOk()) { ALOGE("%s: supportsCameraApi2Locked() call failed for cameraId %s", __FUNCTION__, cameraId.c_str()); return false; } return camera2Support; } void CameraManagerGlobal::getCameraIdList(std::vector<String8>* cameraIds) { // Ensure that we have initialized/refreshed the list of available devices auto cs = getCameraService(); Mutex::Autolock _l(mLock); // Needed to make sure we're connected to cameraservice getCameraServiceLocked(); for(auto& deviceStatus : mDeviceStatusMap) { if (deviceStatus.second == hardware::ICameraServiceListener::STATUS_NOT_PRESENT || deviceStatus.second == hardware::ICameraServiceListener::STATUS_ENUMERATING) { if (deviceStatus.second.status == hardware::ICameraServiceListener::STATUS_NOT_PRESENT || deviceStatus.second.status == hardware::ICameraServiceListener::STATUS_ENUMERATING) { continue; } bool camera2Support = false; binder::Status serviceRet = cs->supportsCameraApi(String16(deviceStatus.first), hardware::ICameraService::API_VERSION_2, &camera2Support); if (!serviceRet.isOk() || !camera2Support) { if (!deviceStatus.second.supportsHAL3) { continue; } cameraIds->push_back(deviceStatus.first); Loading Loading @@ -377,7 +397,7 @@ void CameraManagerGlobal::onStatusChangedLocked( bool firstStatus = (mDeviceStatusMap.count(cameraId) == 0); int32_t oldStatus = firstStatus ? status : // first status mDeviceStatusMap[cameraId]; mDeviceStatusMap[cameraId].status; if (!firstStatus && isStatusAvailable(status) == isStatusAvailable(oldStatus)) { Loading @@ -385,8 +405,10 @@ void CameraManagerGlobal::onStatusChangedLocked( return; } bool supportsHAL3 = supportsCamera2ApiLocked(cameraId); // Iterate through all registered callbacks mDeviceStatusMap[cameraId] = status; mDeviceStatusMap[cameraId] = StatusAndHAL3Support(status, supportsHAL3); if (supportsHAL3) { for (auto cb : mCallbacks) { sp<AMessage> msg = new AMessage(kWhatSendSingleCallback, mHandler); ACameraManager_AvailabilityCallback cbFp = isStatusAvailable(status) ? Loading @@ -396,6 +418,7 @@ void CameraManagerGlobal::onStatusChangedLocked( msg->setString(kCameraIdKey, AString(cameraId)); msg->post(); } } if (status == hardware::ICameraServiceListener::STATUS_NOT_PRESENT) { mDeviceStatusMap.erase(cameraId); } Loading
camera/ndk/impl/ACameraManager.h +14 −4 Original line number Diff line number Diff line Loading @@ -156,12 +156,14 @@ class CameraManagerGlobal final : public RefBase { sp<CallbackHandler> mHandler; sp<ALooper> mCbLooper; // Looper thread where callbacks actually happen on sp<hardware::ICameraService> getCameraServiceLocked(); void onCameraAccessPrioritiesChanged(); void onStatusChanged(int32_t status, const String8& cameraId); void onStatusChangedLocked(int32_t status, const String8& cameraId); // Utils for status static bool validStatus(int32_t status); static bool isStatusAvailable(int32_t status); bool supportsCamera2ApiLocked(const String8 &cameraId); // The sort logic must match the logic in // libcameraservice/common/CameraProviderManager.cpp::getAPI1CompatibleCameraDeviceIds Loading @@ -184,8 +186,16 @@ class CameraManagerGlobal final : public RefBase { } }; struct StatusAndHAL3Support { int32_t status = hardware::ICameraServiceListener::STATUS_NOT_PRESENT; bool supportsHAL3 = false; StatusAndHAL3Support(int32_t st, bool HAL3support): status(st), supportsHAL3(HAL3support) { }; StatusAndHAL3Support() = default; }; // Map camera_id -> status std::map<String8, int32_t, CameraIdComparator> mDeviceStatusMap; std::map<String8, StatusAndHAL3Support, CameraIdComparator> mDeviceStatusMap; // For the singleton instance static Mutex sLock; Loading
drm/libmediadrm/Android.bp +22 −4 Original line number Diff line number Diff line Loading @@ -95,8 +95,6 @@ cc_library_shared { "android.hardware.drm@1.0", "android.hardware.drm@1.1", "android.hardware.drm@1.2", "libbinder", "libhidlbase", "liblog", "libmediametrics", "libprotobuf-cpp-lite", Loading Loading @@ -134,8 +132,6 @@ cc_library_shared { "android.hardware.drm@1.1", "android.hardware.drm@1.2", "libbase", "libbinder", "libhidlbase", "liblog", "libmediametrics", "libprotobuf-cpp-full", Loading @@ -149,3 +145,25 @@ cc_library_shared { ], } cc_library_shared { name: "libmediadrmmetrics_consumer", srcs: [ "DrmMetricsConsumer.cpp", ], include_dirs: [ "frameworks/av/media/libmedia/include" ], shared_libs: [ "android.hardware.drm@1.0", "android.hardware.drm@1.1", "android.hardware.drm@1.2", "libbinder", "libhidlbase", "liblog", "libmediadrm", "libmediadrmmetrics_full", "libutils", ], }
drm/libmediadrm/DrmHal.cpp +5 −8 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ #include <mediadrm/DrmHal.h> #include <mediadrm/DrmSessionClientInterface.h> #include <mediadrm/DrmSessionManager.h> #include <mediadrm/IDrmMetricsConsumer.h> #include <vector> Loading Loading @@ -1362,11 +1363,11 @@ status_t DrmHal::setPropertyByteArray(String8 const &name, return status.isOk() ? toStatusT(status) : DEAD_OBJECT; } status_t DrmHal::getMetrics(PersistableBundle* metrics) { if (metrics == nullptr) { status_t DrmHal::getMetrics(const sp<IDrmMetricsConsumer> &consumer) { if (consumer == nullptr) { return UNEXPECTED_NULL; } mMetrics.Export(metrics); consumer->consumeFrameworkMetrics(mMetrics); // Append vendor metrics if they are supported. if (mPluginV1_1 != NULL) { Loading @@ -1393,11 +1394,7 @@ status_t DrmHal::getMetrics(PersistableBundle* metrics) { if (status != Status::OK) { ALOGV("Error getting plugin metrics: %d", status); } else { PersistableBundle pluginBundle; if (MediaDrmMetrics::HidlMetricsToBundle( pluginMetrics, &pluginBundle) == OK) { metrics->putPersistableBundle(String16(vendor), pluginBundle); } consumer->consumeHidlMetrics(vendor, pluginMetrics); } err = toStatusT(status); }); Loading
drm/libmediadrm/DrmMetrics.cpp +4 −225 Original line number Diff line number Diff line Loading @@ -29,143 +29,12 @@ using ::android::String16; using ::android::String8; using ::android::drm_metrics::DrmFrameworkMetrics; using ::android::hardware::hidl_string; using ::android::hardware::hidl_vec; using ::android::hardware::drm::V1_0::EventType; using ::android::hardware::drm::V1_2::KeyStatusType; using ::android::hardware::drm::V1_1::DrmMetricGroup; using ::android::os::PersistableBundle; namespace { template <typename T> std::string GetAttributeName(T type); template <> std::string GetAttributeName<KeyStatusType>(KeyStatusType type) { static const char *type_names[] = {"USABLE", "EXPIRED", "OUTPUT_NOT_ALLOWED", "STATUS_PENDING", "INTERNAL_ERROR"}; if (((size_t)type) > arraysize(type_names)) { return "UNKNOWN_TYPE"; } return type_names[(size_t)type]; } template <> std::string GetAttributeName<EventType>(EventType type) { static const char *type_names[] = {"PROVISION_REQUIRED", "KEY_NEEDED", "KEY_EXPIRED", "VENDOR_DEFINED", "SESSION_RECLAIMED"}; if (((size_t)type) > arraysize(type_names)) { return "UNKNOWN_TYPE"; } return type_names[(size_t)type]; } template <typename T> void ExportCounterMetric(const android::CounterMetric<T> &counter, PersistableBundle *metrics) { if (!metrics) { ALOGE("metrics was unexpectedly null."); return; } std::string success_count_name = counter.metric_name() + ".ok.count"; std::string error_count_name = counter.metric_name() + ".error.count"; std::vector<int64_t> status_values; counter.ExportValues( [&](const android::status_t status, const int64_t value) { if (status == android::OK) { metrics->putLong(android::String16(success_count_name.c_str()), value); } else { int64_t total_errors(0); metrics->getLong(android::String16(error_count_name.c_str()), &total_errors); metrics->putLong(android::String16(error_count_name.c_str()), total_errors + value); status_values.push_back(status); } }); if (!status_values.empty()) { std::string error_list_name = counter.metric_name() + ".error.list"; metrics->putLongVector(android::String16(error_list_name.c_str()), status_values); } } template <typename T> void ExportCounterMetricWithAttributeNames( const android::CounterMetric<T> &counter, PersistableBundle *metrics) { if (!metrics) { ALOGE("metrics was unexpectedly null."); return; } counter.ExportValues([&](const T &attribute, const int64_t value) { std::string name = counter.metric_name() + "." + GetAttributeName(attribute) + ".count"; metrics->putLong(android::String16(name.c_str()), value); }); } template <typename T> void ExportEventMetric(const android::EventMetric<T> &event, PersistableBundle *metrics) { if (!metrics) { ALOGE("metrics was unexpectedly null."); return; } std::string success_count_name = event.metric_name() + ".ok.count"; std::string error_count_name = event.metric_name() + ".error.count"; std::string timing_name = event.metric_name() + ".ok.average_time_micros"; std::vector<int64_t> status_values; event.ExportValues([&](const android::status_t &status, const android::EventStatistics &value) { if (status == android::OK) { metrics->putLong(android::String16(success_count_name.c_str()), value.count); metrics->putLong(android::String16(timing_name.c_str()), value.mean); } else { int64_t total_errors(0); metrics->getLong(android::String16(error_count_name.c_str()), &total_errors); metrics->putLong(android::String16(error_count_name.c_str()), total_errors + value.count); status_values.push_back(status); } }); if (!status_values.empty()) { std::string error_list_name = event.metric_name() + ".error.list"; metrics->putLongVector(android::String16(error_list_name.c_str()), status_values); } } void ExportSessionLifespans( const std::map<std::string, std::pair<int64_t, int64_t>> &mSessionLifespans, PersistableBundle *metrics) { if (!metrics) { ALOGE("metrics was unexpectedly null."); return; } if (mSessionLifespans.empty()) { return; } PersistableBundle startTimesBundle; PersistableBundle endTimesBundle; for (auto it = mSessionLifespans.begin(); it != mSessionLifespans.end(); it++) { String16 key(it->first.c_str(), it->first.size()); startTimesBundle.putLong(key, it->second.first); endTimesBundle.putLong(key, it->second.second); } metrics->putPersistableBundle( android::String16("drm.mediadrm.session_start_times_ms"), startTimesBundle); metrics->putPersistableBundle( android::String16("drm.mediadrm.session_end_times_ms"), endTimesBundle); } std::string ToHexString(const android::Vector<uint8_t> &sessionId) { std::ostringstream out; out << std::hex << std::setfill('0'); Loading @@ -175,31 +44,6 @@ std::string ToHexString(const android::Vector<uint8_t> &sessionId) { return out.str(); } template <typename CT> void SetValue(const String16 &name, DrmMetricGroup::ValueType type, const CT &value, PersistableBundle *bundle) { switch (type) { case DrmMetricGroup::ValueType::INT64_TYPE: bundle->putLong(name, value.int64Value); break; case DrmMetricGroup::ValueType::DOUBLE_TYPE: bundle->putDouble(name, value.doubleValue); break; case DrmMetricGroup::ValueType::STRING_TYPE: bundle->putString(name, String16(value.stringValue.c_str())); break; default: ALOGE("Unexpected value type: %hhu", type); } } inline String16 MakeIndexString(unsigned int index) { std::string str("["); str.append(std::to_string(index)); str.append("]"); return String16(str.c_str()); } } // namespace namespace android { Loading Loading @@ -237,23 +81,6 @@ void MediaDrmMetrics::SetSessionEnd(const android::Vector<uint8_t> &sessionId) { } } void MediaDrmMetrics::Export(PersistableBundle *metrics) { if (!metrics) { ALOGE("metrics was unexpectedly null."); return; } ExportCounterMetric(mOpenSessionCounter, metrics); ExportCounterMetric(mCloseSessionCounter, metrics); ExportEventMetric(mGetKeyRequestTimeUs, metrics); ExportEventMetric(mProvideKeyResponseTimeUs, metrics); ExportCounterMetric(mGetProvisionRequestCounter, metrics); ExportCounterMetric(mProvideProvisionResponseCounter, metrics); ExportCounterMetricWithAttributeNames(mKeyStatusChangeCounter, metrics); ExportCounterMetricWithAttributeNames(mEventCounter, metrics); ExportCounterMetric(mGetDeviceUniqueIdCounter, metrics); ExportSessionLifespans(mSessionLifespans, metrics); } status_t MediaDrmMetrics::GetSerializedMetrics(std::string *serializedMetrics) { if (!serializedMetrics) { Loading Loading @@ -361,62 +188,14 @@ status_t MediaDrmMetrics::GetSerializedMetrics(std::string *serializedMetrics) { return OK; } std::map<std::string, std::pair<int64_t, int64_t>> MediaDrmMetrics::GetSessionLifespans() const { return mSessionLifespans; } int64_t MediaDrmMetrics::GetCurrentTimeMs() { struct timeval tv; gettimeofday(&tv, NULL); return ((int64_t)tv.tv_sec * 1000) + ((int64_t)tv.tv_usec / 1000); } status_t MediaDrmMetrics::HidlMetricsToBundle( const hidl_vec<DrmMetricGroup> &hidlMetricGroups, PersistableBundle *bundleMetricGroups) { if (bundleMetricGroups == nullptr) { return UNEXPECTED_NULL; } if (hidlMetricGroups.size() == 0) { return OK; } int groupIndex = 0; std::map<String16, int> indexMap; for (const auto &hidlMetricGroup : hidlMetricGroups) { PersistableBundle bundleMetricGroup; for (const auto &hidlMetric : hidlMetricGroup.metrics) { String16 metricName(hidlMetric.name.c_str()); PersistableBundle bundleMetric; // Add metric component values. for (const auto &value : hidlMetric.values) { SetValue(String16(value.componentName.c_str()), value.type, value, &bundleMetric); } // Set metric attributes. PersistableBundle bundleMetricAttributes; for (const auto &attribute : hidlMetric.attributes) { SetValue(String16(attribute.name.c_str()), attribute.type, attribute, &bundleMetricAttributes); } // Add attributes to the bundle metric. bundleMetric.putPersistableBundle(String16("attributes"), bundleMetricAttributes); // Add one layer of indirection, allowing for repeated metric names. PersistableBundle repeatedMetrics; bundleMetricGroup.getPersistableBundle(metricName, &repeatedMetrics); int index = indexMap[metricName]; repeatedMetrics.putPersistableBundle(MakeIndexString(index), bundleMetric); indexMap[metricName] = ++index; // Add the bundle metric to the group of metrics. bundleMetricGroup.putPersistableBundle(metricName, repeatedMetrics); } // Add the bundle metric group to the collection of groups. bundleMetricGroups->putPersistableBundle(MakeIndexString(groupIndex++), bundleMetricGroup); } return OK; } } // namespace android