• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 "test_utils.h"
17 #include "hcodec_api.h"
18 
19 using namespace std;
20 using namespace std::chrono;
21 using namespace OHOS::MediaAVCodec;
22 
GetCodecName(bool isEncoder,const string & mime)23 string GetCodecName(bool isEncoder, const string& mime)
24 {
25     vector<CapabilityData> caps;
26     int32_t ret = GetHCodecCapabilityList(caps);
27     if (ret != 0) {
28         return {};
29     }
30     AVCodecType targetType = isEncoder ? AVCODEC_TYPE_VIDEO_ENCODER : AVCODEC_TYPE_VIDEO_DECODER;
31     auto it = find_if(caps.begin(), caps.end(), [&mime, targetType](const CapabilityData& cap) {
32         return cap.mimeType == mime && cap.codecType == targetType;
33     });
34     if (it != caps.end()) {
35         return it->codecName;
36     }
37     return {};
38 }
39 
Instance()40 CostRecorder& CostRecorder::Instance()
41 {
42     static CostRecorder inst;
43     return inst;
44 }
45 
Clear()46 void CostRecorder::Clear()
47 {
48     records_.clear();
49 }
50 
Update(steady_clock::time_point begin,const string & apiName)51 void CostRecorder::Update(steady_clock::time_point begin, const string& apiName)
52 {
53     auto cost = duration_cast<microseconds>(steady_clock::now() - begin).count();
54     records_[apiName].totalCost += cost;
55     records_[apiName].totalCnt++;
56 }
57 
Print() const58 void CostRecorder::Print() const
59 {
60     for (const auto& one : records_) {
61         printf("%s everage cost %u us\n", one.first.c_str(),
62             static_cast<uint32_t>(one.second.totalCost / one.second.totalCnt));
63     }
64 }