• 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 AUDIO_SOURCE_CLOCK_H
17 #define AUDIO_SOURCE_CLOCK_H
18 
19 #include <mutex>
20 #include <vector>
21 #include "audio_info.h"
22 
23 namespace OHOS {
24 namespace AudioStandard {
25 
26 class AudioSourceClock {
27 public:
AudioSourceClock()28     AudioSourceClock() {}
~AudioSourceClock()29     virtual ~AudioSourceClock() {}
30 
31     void Init(uint32_t sampleRate, AudioSampleFormat format, uint32_t channel);
32     void Renew(uint32_t posIncSize);
33     void UpdateSessionId(const std::vector<int32_t> &sessionIdList);
34 
35     // can be override for differ method
36     virtual uint64_t GetTimestamp(uint32_t __attribute__((unused)) positionInc);
37 protected:
38     uint32_t sizePerPos_;
39     uint32_t sampleRate_ = 0;
40     AudioSampleFormat format_ = AudioSampleFormat::INVALID_WIDTH;
41     uint32_t channel_ = 0;
42 
43     std::vector<int32_t> sessionIdList_;
44     std::mutex clockMtx_;
45 };
46 
47 // AudioCapturerSourceTsRecorder is a RAII tool to help audio source renew the timestamp.
48 class AudioCapturerSourceTsRecorder {
49 public:
AudioCapturerSourceTsRecorder(uint64_t & replyBytes,std::shared_ptr<AudioSourceClock> clock)50     AudioCapturerSourceTsRecorder(uint64_t &replyBytes, std::shared_ptr<AudioSourceClock> clock)
51         : replyBytes_(replyBytes), clock_(clock) {}
52 
53     ~AudioCapturerSourceTsRecorder();
54 private:
55     uint64_t &replyBytes_;
56     std::shared_ptr<AudioSourceClock> clock_;
57 };
58 
59 } // namespace AudioStandard
60 } // namespace OHOS
61 
62 #endif // CAPTURER_CLOCK_H
63