• 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 #include "avcodec_dfx_component.h"
17 #include <algorithm>
18 #include "instance_info.h"
19 #include "meta/meta.h"
20 
21 using namespace OHOS::Media;
22 namespace OHOS {
23 namespace MediaAVCodec {
CreateVideoLogTag(const Meta & callerInfo)24 std::string CreateVideoLogTag(const Meta &callerInfo)
25 {
26     int32_t instanceId = 0;
27     std::string codecName = "";
28     std::string type = "";
29     bool ret = callerInfo.GetData(EventInfoExtentedKey::INSTANCE_ID.data(), instanceId) &&
30                callerInfo.GetData(Tag::MEDIA_CODEC_NAME, codecName);
31     if (!ret || instanceId == INVALID_INSTANCE_ID) {
32         return "";
33     }
34     std::transform(codecName.begin(), codecName.end(), codecName.begin(), ::tolower);
35     type += codecName.find("omx") != std::string::npos ? "h." : "s.";
36     if (codecName.find("decode") != std::string::npos) {
37         type += "vdec";
38     } else if (codecName.find("encode") != std::string::npos) {
39         type += "venc";
40     } else {
41         return "";
42     }
43     return std::string("[") + std::to_string(instanceId) + "][" + type + "]";
44 }
45 
AVCodecDfxComponent()46 AVCodecDfxComponent::AVCodecDfxComponent()
47 {
48     tag_.store("");
49 }
50 
~AVCodecDfxComponent()51 AVCodecDfxComponent::~AVCodecDfxComponent() {}
52 
SetTag(const std::string & str)53 void AVCodecDfxComponent::SetTag(const std::string &str)
54 {
55     if (str == "") {
56         return;
57     }
58     tagContent_ = str;
59     tag_.store(tagContent_.c_str());
60 }
61 
GetTag()62 const std::string &AVCodecDfxComponent::GetTag()
63 {
64     return tagContent_;
65 }
66 } // namespace MediaAVCodec
67 } // namespace OHOS
68