• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "meta.h"
23 #include "meta/meta_key.h"
24 
25 namespace OHOS {
26 namespace MediaAVCodec {
27 constexpr pid_t INVALID_PID = -1;
28 constexpr int32_t INVALID_INSTANCE_ID = -1;
29 
30 class EventInfoExtentedKey {
31 public:
32     static constexpr std::string_view INSTANCE_ID = "av_codec_event_info_instance_id";
33     static constexpr std::string_view CODEC_TYPE = "av_codec_event_info_codec_type";
34     static constexpr std::string_view IS_HARDWARE = "IS_VENDOR";
35     static constexpr std::string_view BIT_DEPTH = "av_codec_event_info_bit_depth";
36     static constexpr std::string_view ENABLE_POST_PROCESSING = "av_codec_event_info_enable_post_processing";
37     static constexpr std::string_view PIXEL_FORMAT_STRING = "pixel_format_string";
38 
GetInstanceIdFromMeta(const Media::Meta & meta)39     static int32_t GetInstanceIdFromMeta(const Media::Meta &meta)
40     {
41         auto instanceId = INVALID_INSTANCE_ID;
42         meta.GetData(EventInfoExtentedKey::INSTANCE_ID.data(), instanceId);
43         return instanceId;
44     }
45 };
46 
47 struct CallerInfo {
48     pid_t pid = -1;
49     uid_t uid = 0;
50     std::string processName = "";
51 };
52 
53 struct InstanceInfo {
54     int32_t instanceId = INVALID_INSTANCE_ID;
55     CallerInfo caller;
56     CallerInfo forwardCaller;
57     uint32_t memoryUsage = 0;
58 
PrintInstanceInfo59     void Print()
60     {
61         constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_FRAMEWORK, "InstanceInfo"};
62         AVCODEC_LOGI("InstanceId: %{public}d, Caller: [%{public}d, %{public}s], ForwardCaller: [%{public}d, %{public}s]"
63             ", MemoryUsage: %{public}u", instanceId, caller.pid, caller.processName.c_str(), forwardCaller.pid,
64             forwardCaller.processName.c_str(), memoryUsage);
65     }
66 };
67 } // namespace MediaAVCodec
68 } // namespace OHOS
69 #endif // AVCODEC_INSTANCE_INFO_H