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 16 #ifndef MULTIMEDIA_AUDIO_RENDERER_IMPL_H 17 #define MULTIMEDIA_AUDIO_RENDERER_IMPL_H 18 #include "audio_renderer.h" 19 #include "audio_stream_manager.h" 20 #include "cj_common_ffi.h" 21 #include "multimedia_audio_ffi.h" 22 #include "multimedia_audio_renderer_callback.h" 23 #include "native/ffi_remote_data.h" 24 25 namespace OHOS { 26 namespace AudioStandard { 27 class MMAAudioRendererImpl : public OHOS::FFI::FFIData { 28 DECL_TYPE(MMAAudioRendererImpl, OHOS::FFI::FFIData) 29 public: 30 MMAAudioRendererImpl(); 31 32 ~MMAAudioRendererImpl(); 33 34 int32_t CreateAudioRenderer(CAudioRendererOptions options); 35 36 int32_t GetState(); 37 38 int64_t GetAudioTime(int32_t* errorCode); 39 40 uint32_t GetBufferSize(int32_t* errorCode); 41 42 int32_t Flush(); 43 44 int32_t Drain(); 45 46 int32_t Pause(); 47 48 CArrDeviceDescriptor GetCurrentOutputDevices(int32_t* errorCode); 49 50 double GetSpeed(int32_t* errorCode); 51 52 bool GetSilentModeAndMixWithOthers(int32_t* errorCode); 53 54 double GetVolume(int32_t* errorCode); 55 56 uint32_t GetUnderflowCount(int32_t* errorCode); 57 58 void SetVolumeWithRamp(double volume, int32_t duration, int32_t* errorCode); 59 60 void SetSpeed(double speed, int32_t* errorCode); 61 62 void SetVolume(double volume, int32_t* errorCode); 63 64 void SetSilentModeAndMixWithOthers(bool on, int32_t* errorCode); 65 66 void SetInterruptMode(int32_t mode, int32_t* errorCode); 67 68 void SetChannelBlendMode(int32_t mode, int32_t* errorCode); 69 70 void SetDefaultOutputDevice(int32_t type, int32_t* errorCode); 71 72 void RegisterCallback(int32_t callbackType, void (*callback)(), int32_t* errorCode); 73 74 void RegisterCallbackWithFrame(int32_t callbackType, void (*callback)(), int64_t frame, int32_t* errorCode); 75 76 int32_t GetAudioEffectMode(int32_t* errorCode); 77 78 void SetAudioEffectMode(int32_t mode, int32_t* errorCode); 79 80 double GetMinStreamVolume(int32_t* errorCode); 81 82 double GetMaxStreamVolume(int32_t* errorCode); 83 84 void Release(int32_t* errorCode); 85 86 uint32_t GetStreamId(int32_t* errorCode); 87 88 void Stop(int32_t* errorCode); 89 90 void Start(int32_t* errorCode); 91 92 CAudioStreamInfo GetStreamInfo(int32_t* errorCode); 93 94 CAudioRendererInfo GetRendererInfo(int32_t* errorCode); 95 96 private: 97 static constexpr double MIN_VOLUME_IN_DOUBLE = 0.0; 98 static constexpr double MAX_VOLUME_IN_DOUBLE = 1.0; 99 void RegisterOutputDeviceCallback(int32_t callbackType, void (*callback)(), int32_t* errorCode); 100 std::shared_ptr<AudioRenderer> audioRenderer_ {}; 101 std::shared_ptr<CjAudioRendererCallback> callback_ {}; 102 std::shared_ptr<CjRendererPositionCallback> positionCb_ {}; 103 std::shared_ptr<CjRendererPeriodPositionCallback> periodPositionCb_ {}; 104 std::shared_ptr<CjAudioRendererWriteCallback> rendererWriteDataCallback_ {}; 105 std::shared_ptr<CjAudioRendererOutputDeviceChangeCallback> rendererDeviceChangeCallback_ {}; 106 std::shared_ptr<CjAudioRendererOutputDeviceChangeWithInfoCallback> rendererOutputDeviceChangeWithInfoCallback_ {}; 107 }; 108 } // namespace AudioStandard 109 } // namespace OHOS 110 #endif // MULTIMEDIA_AUDIO_RENDERER_IMPL_H 111