1 /* 2 * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 LOOP_BACK_DEMO_H 17 #define LOOP_BACK_DEMO_H 18 19 #include "access_token.h" 20 #include "accesstoken_kit.h" 21 #include "audio_capturer.h" 22 #include "audio_renderer.h" 23 #include "nativetoken_kit.h" 24 #include "token_setproc.h" 25 26 namespace OHOS { 27 namespace AudioStandard { 28 class LoopBackDemo { 29 public: 30 LoopBackDemo(); 31 ~LoopBackDemo(); 32 33 void InitializeRenderOptions(AudioRendererParams &rendererParams); 34 void InitializeCapturerOptions(AudioCapturerOptions &capturerOptions); 35 36 int32_t StartRender(); 37 int32_t InitAudioRenderer(); 38 39 int32_t StartCapture(); 40 int32_t InitAudioCapturer(); 41 42 void RendererThread(); 43 void CaptureThreadWorker(); 44 45 void loopback(); 46 bool GetPermission(); 47 48 private: 49 bool isBlockingRead_ = true; 50 bool isRunningRender_ = false; 51 bool isRunningCapture_ = false; 52 53 size_t bufferLen_ = 0; 54 55 std::unique_ptr<AudioCapturer> audioCapturer_ = nullptr; 56 std::unique_ptr<AudioRenderer> audioRenderer_ = nullptr; 57 58 AudioRendererParams rendererParams_; 59 AudioCapturerOptions capturerOptions_; 60 }; 61 } // namespace AudioStandard 62 } // namespace OHOS 63 #endif // AUDIO_CAPTURER_UNIT_TEST_H 64