1 /* 2 * Copyright (C) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef AVCODEC_INSTANCE_INFO_H 17 #define AVCODEC_INSTANCE_INFO_H 18 19 #include <sys/types.h> 20 #include <string> 21 #include "avcodec_log.h" 22 #include "avcodec_info.h" 23 #include "meta.h" 24 #include "meta/meta_key.h" 25 26 namespace OHOS { 27 namespace MediaAVCodec { 28 constexpr pid_t INVALID_PID = -1; 29 constexpr int32_t INVALID_INSTANCE_ID = -1; 30 31 class EventInfoExtentedKey { 32 public: 33 static constexpr std::string_view INSTANCE_ID = "av_codec_event_info_instance_id"; 34 static constexpr std::string_view CODEC_TYPE = "av_codec_event_info_codec_type"; 35 static constexpr std::string_view IS_HARDWARE = "IS_VENDOR"; 36 static constexpr std::string_view BIT_DEPTH = "av_codec_event_info_bit_depth"; 37 static constexpr std::string_view ENABLE_POST_PROCESSING = "av_codec_event_info_enable_post_processing"; 38 static constexpr std::string_view PIXEL_FORMAT_STRING = "pixel_format_string"; 39 GetInstanceIdFromMeta(const Media::Meta & meta)40 static int32_t GetInstanceIdFromMeta(const Media::Meta &meta) 41 { 42 auto instanceId = INVALID_INSTANCE_ID; 43 meta.GetData(EventInfoExtentedKey::INSTANCE_ID.data(), instanceId); 44 return instanceId; 45 } 46 }; 47 48 struct CallerInfo { 49 pid_t pid = -1; 50 uid_t uid = 0; 51 std::string processName = ""; 52 }; 53 54 struct InstanceInfo { 55 int32_t instanceId = INVALID_INSTANCE_ID; 56 CallerInfo caller; 57 CallerInfo forwardCaller; 58 AVCodecType codecType; 59 uint32_t memoryUsage = 0; 60 PrintInstanceInfo61 void Print() 62 { 63 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_FRAMEWORK, "InstanceInfo"}; 64 AVCODEC_LOGI("InstanceId: %{public}d, Caller: [%{public}d, %{public}s], ForwardCaller: [%{public}d, %{public}s]" 65 ", CodecType: %{public}d, MemoryUsage: %{public}u", instanceId, caller.pid, caller.processName.c_str(), 66 forwardCaller.pid, forwardCaller.processName.c_str(), codecType, memoryUsage); 67 } 68 }; 69 } // namespace MediaAVCodec 70 } // namespace OHOS 71 #endif // AVCODEC_INSTANCE_INFO_H