• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 BLUETOOTH_RENDERER_SINK_H
17 #define BLUETOOTH_RENDERER_SINK_H
18 
19 #include "audio_info.h"
20 #include "audio_proxy_manager.h"
21 #include "running_lock.h"
22 
23 #include <cstdio>
24 #include <list>
25 
26 namespace OHOS {
27 namespace AudioStandard {
28 typedef struct {
29     HDI::Audio_Bluetooth::AudioFormat format;
30     uint32_t sampleFmt;
31     uint32_t sampleRate;
32     uint32_t channel;
33     float volume;
34 } BluetoothSinkAttr;
35 
36 class BluetoothRendererSink {
37 public:
38     int32_t Init(const BluetoothSinkAttr &attr);
39     void DeInit(void);
40     int32_t Start(void);
41     int32_t Stop(void);
42     int32_t Flush(void);
43     int32_t Reset(void);
44     int32_t Pause(void);
45     int32_t Resume(void);
46     int32_t RenderFrame(char &data, uint64_t len, uint64_t &writeLen);
47     int32_t SetVolume(float left, float right);
48     int32_t GetVolume(float &left, float &right);
49     int32_t GetLatency(uint32_t *latency);
50     int32_t GetTransactionId(uint64_t *transactionId);
51     static BluetoothRendererSink *GetInstance(void);
52     bool GetAudioMonoState();
53     float GetAudioBalanceValue();
54     void SetAudioMonoState(bool audioMono);
55     void SetAudioBalanceValue(float audioBalance);
56     bool rendererInited_;
57 
58 private:
59     BluetoothRendererSink();
60     ~BluetoothRendererSink();
61     BluetoothSinkAttr attr_;
62     bool started_;
63     bool paused_;
64     float leftVolume_;
65     float rightVolume_;
66     struct HDI::Audio_Bluetooth::AudioProxyManager *audioManager_;
67     struct HDI::Audio_Bluetooth::AudioAdapter *audioAdapter_;
68     struct HDI::Audio_Bluetooth::AudioRender *audioRender_;
69     struct HDI::Audio_Bluetooth::AudioPort audioPort = {};
70     void *handle_;
71     bool audioMonoState_ = false;
72     bool audioBalanceState_ = false;
73     float audioBalanceValue_ = 0.0f;
74     float leftBalanceCoef_ = 1.0f;
75     float rightBalanceCoef_ = 1.0f;
76 
77     std::shared_ptr<PowerMgr::RunningLock> mKeepRunningLock;
78 
79     int32_t CreateRender(struct HDI::Audio_Bluetooth::AudioPort &renderPort);
80     int32_t InitAudioManager();
81     void AdjustStereoToMono(char *data, uint64_t len);
82     void AdjustAudioBalance(char *data, uint64_t len);
83 #ifdef BT_DUMPFILE
84     FILE *pfd;
85 #endif // DUMPFILE
86 };
87 }  // namespace AudioStandard
88 }  // namespace OHOS
89 #endif // BLUETOOTH_RENDERER_SINK_H
90