• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #ifndef LOG_TAG
16 #define LOG_TAG "AudioLogUtils"
17 #endif
18 
19 #include "audio_log_utils.h"
20 
21 #include <cinttypes>
22 #include "audio_capturer_log.h"
23 
24 namespace OHOS {
25 namespace AudioStandard {
26 namespace {
27 static const uint32_t MEDIUM_FREQ_PRINT_LOG = 100;
28 static const uint32_t LOW_FREQ_PRINT_LOG = 1000;
29 }
ProcessVolumeData(const std::string & logTag,const ChannelVolumes & vols,int64_t & count)30 void AudioLogUtils::ProcessVolumeData(const std::string &logTag, const ChannelVolumes &vols, int64_t &count)
31 {
32     bool isDataSilent = true;
33     for (int32_t i = 0; i < vols.channel; i++) {
34         if (vols.volStart[i] != 0) {
35             isDataSilent = false;
36             break;
37         }
38     }
39     if (isDataSilent) {
40         if (count > 0) {
41             AUDIO_INFO_LOG("[%{public}s] not slient %{public}" PRId64 "frames change to slient",
42                 logTag.c_str(), count);
43             count = 0;
44         }
45         count--;
46         IncSilentData(logTag, vols, -count);
47     } else {
48         if (count < 0) {
49             AUDIO_INFO_LOG("[%{public}s] slient %{public}" PRId64 "frames change to not slient",
50                 logTag.c_str(), -count);
51             count = 0;
52         }
53         count++;
54         IncSoundData(logTag, vols, count);
55     }
56 }
57 
IncSilentData(const std::string & logTag,const ChannelVolumes & vols,int64_t count)58 void AudioLogUtils::IncSilentData(const std::string &logTag, const ChannelVolumes &vols, int64_t count)
59 {
60     if ((count < LOW_FREQ_PRINT_LOG && count % MEDIUM_FREQ_PRINT_LOG == 0) ||
61         (count >= LOW_FREQ_PRINT_LOG && count % LOW_FREQ_PRINT_LOG == 0)) {
62         AUDIO_INFO_LOG("[%{public}s], channel: %{public}d, counts: %{public}" PRId64 "",
63             logTag.c_str(), vols.channel, count);
64     }
65 }
66 
IncSoundData(const std::string & logTag,const ChannelVolumes & vols,int64_t count)67 void AudioLogUtils::IncSoundData(const std::string &logTag, const ChannelVolumes &vols, int64_t count)
68 {
69     if ((count < LOW_FREQ_PRINT_LOG && count % MEDIUM_FREQ_PRINT_LOG == 0) ||
70         (count >= LOW_FREQ_PRINT_LOG && count % LOW_FREQ_PRINT_LOG == 0)) {
71         if (vols.channel == MONO) {
72             AUDIO_INFO_LOG("[%{public}s] MONO = %{public}d, counts: %{public}" PRId64 "",
73                 logTag.c_str(), vols.volStart[0], count);
74         } else {
75             AUDIO_INFO_LOG("[%{public}s] channel: %{public}d, L=%{public}d, R=%{public}d, counts: %{public}" PRId64 "",
76                 logTag.c_str(), vols.channel, vols.volStart[0], vols.volStart[1], count);
77         }
78     }
79 }
80 } // namespace AudioStandard
81 } // namespace OHOS
82