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