diff --git a/frameworks/innerkitsimpl/audioadapter/include/pulse_audio_service_adapter_impl.h b/frameworks/innerkitsimpl/audioadapter/include/pulse_audio_service_adapter_impl.h index 5d98492c4daccdcfa765827832773ac5bcc7e9f9..a0055de0f72822950d131d9c879afdf2372491a9 100644 --- a/frameworks/innerkitsimpl/audioadapter/include/pulse_audio_service_adapter_impl.h +++ b/frameworks/innerkitsimpl/audioadapter/include/pulse_audio_service_adapter_impl.h @@ -16,24 +16,19 @@ #ifndef ST_PULSEAUDIO_AUDIO_SERVICE_ADAPTER_H #define ST_PULSEAUDIO_AUDIO_SERVICE_ADAPTER_H -#ifdef __cplusplus -extern "C" { -#endif #include -#ifdef __cplusplus -} -#endif + #include "audio_service_adapter.h" namespace OHOS { namespace AudioStandard { class PulseAudioServiceAdapterImpl : public AudioServiceAdapter { public: - PulseAudioServiceAdapterImpl(AudioServiceAdapterCallback *cb); + PulseAudioServiceAdapterImpl(std::unique_ptr &cb); ~PulseAudioServiceAdapterImpl(); bool Connect() override; - int32_t OpenAudioPort(char *audioPortName, std::string moduleArgs) override; + int32_t OpenAudioPort(std::string audioPortName, std::string moduleArgs) override; int32_t CloseAudioPort(int32_t audioHandleIndex) override; int32_t SetDefaultSink(std::string name) override; int32_t SetDefaultSource(std::string name) override; diff --git a/frameworks/innerkitsimpl/audioadapter/src/pulse_audio_service_adapter_impl.cpp b/frameworks/innerkitsimpl/audioadapter/src/pulse_audio_service_adapter_impl.cpp index 0ba7feac0b7f9bea3861d94a01343c759cffa7ba..b415e5fde527355b7bb2ad3ae466b03d8932213c 100644 --- a/frameworks/innerkitsimpl/audioadapter/src/pulse_audio_service_adapter_impl.cpp +++ b/frameworks/innerkitsimpl/audioadapter/src/pulse_audio_service_adapter_impl.cpp @@ -22,21 +22,23 @@ #include "audio_errors.h" #include "media_log.h" +using namespace std; + namespace OHOS { namespace AudioStandard { -static AudioServiceAdapterCallback *mAudioServiceAdapterCallback; +static unique_ptr mAudioServiceAdapterCallback; AudioServiceAdapter::~AudioServiceAdapter() = default; PulseAudioServiceAdapterImpl::~PulseAudioServiceAdapterImpl() = default; -std::unique_ptr AudioServiceAdapter::CreateAudioAdapter(AudioServiceAdapterCallback *cb) +unique_ptr AudioServiceAdapter::CreateAudioAdapter(unique_ptr cb) { - return std::make_unique(cb); + return make_unique(cb); } -PulseAudioServiceAdapterImpl::PulseAudioServiceAdapterImpl(AudioServiceAdapterCallback *cb) +PulseAudioServiceAdapterImpl::PulseAudioServiceAdapterImpl(unique_ptr &cb) { - mAudioServiceAdapterCallback = cb; + mAudioServiceAdapterCallback = move(cb); } bool PulseAudioServiceAdapterImpl::Connect() @@ -84,11 +86,11 @@ bool PulseAudioServiceAdapterImpl::Connect() bool PulseAudioServiceAdapterImpl::ConnectToPulseAudio() { - std::unique_ptr userData = std::make_unique(); + unique_ptr userData = make_unique(); userData->thiz = this; if (mContext != NULL) { - pa_context_disconnect (mContext); + pa_context_disconnect(mContext); pa_context_set_state_callback(mContext, NULL, NULL); pa_context_set_subscribe_callback(mContext, NULL, NULL); pa_context_unref(mContext); @@ -124,14 +126,14 @@ Fail: return false; } -int32_t PulseAudioServiceAdapterImpl::OpenAudioPort(char *audioPortName, std::string moduleArgs) +int32_t PulseAudioServiceAdapterImpl::OpenAudioPort(string audioPortName, string moduleArgs) { - std::unique_ptr userData = std::make_unique(); + unique_ptr userData = make_unique(); userData->thiz = this; pa_threaded_mainloop_lock(mMainLoop); - pa_operation *operation = pa_context_load_module(mContext, audioPortName, moduleArgs.c_str(), PaModuleLoadCb, - reinterpret_cast(userData.get())); + pa_operation *operation = pa_context_load_module(mContext, audioPortName.c_str(), moduleArgs.c_str(), + PaModuleLoadCb, reinterpret_cast(userData.get())); if (operation == NULL) { MEDIA_ERR_LOG("[PulseAudioServiceAdapterImpl] pa_context_load_module returned nullptr"); pa_threaded_mainloop_unlock(mMainLoop); @@ -164,7 +166,7 @@ int32_t PulseAudioServiceAdapterImpl::CloseAudioPort(int32_t audioHandleIndex) return SUCCESS; } -int32_t PulseAudioServiceAdapterImpl::SetDefaultSink(std::string name) +int32_t PulseAudioServiceAdapterImpl::SetDefaultSink(string name) { pa_threaded_mainloop_lock(mMainLoop); pa_operation *operation = pa_context_set_default_sink(mContext, name.c_str(), NULL, NULL); @@ -180,7 +182,7 @@ int32_t PulseAudioServiceAdapterImpl::SetDefaultSink(std::string name) } -int32_t PulseAudioServiceAdapterImpl::SetDefaultSource(std::string name) +int32_t PulseAudioServiceAdapterImpl::SetDefaultSource(string name) { pa_threaded_mainloop_lock(mMainLoop); pa_operation *operation = pa_context_set_default_source(mContext, name.c_str(), NULL, NULL); @@ -197,7 +199,7 @@ int32_t PulseAudioServiceAdapterImpl::SetDefaultSource(std::string name) int32_t PulseAudioServiceAdapterImpl::SetVolume(AudioStreamType streamType, float volume) { - std::unique_ptr userData = std::make_unique(); + unique_ptr userData = make_unique(); userData->thiz = this; userData->volume = volume; userData->streamType = streamType; @@ -226,7 +228,7 @@ int32_t PulseAudioServiceAdapterImpl::SetVolume(AudioStreamType streamType, floa int32_t PulseAudioServiceAdapterImpl::SetMute(AudioStreamType streamType, bool mute) { - std::unique_ptr userData = std::make_unique(); + unique_ptr userData = make_unique(); userData->thiz = this; userData->mute = mute; userData->streamType = streamType; @@ -257,7 +259,7 @@ int32_t PulseAudioServiceAdapterImpl::SetMute(AudioStreamType streamType, bool m bool PulseAudioServiceAdapterImpl::IsMute(AudioStreamType streamType) { - std::unique_ptr userData = std::make_unique(); + unique_ptr userData = make_unique(); userData->thiz = this; userData->streamType = streamType; userData->mute = false; @@ -289,7 +291,7 @@ bool PulseAudioServiceAdapterImpl::IsMute(AudioStreamType streamType) bool PulseAudioServiceAdapterImpl::IsStreamActive(AudioStreamType streamType) { - std::unique_ptr userData = std::make_unique(); + unique_ptr userData = make_unique(); userData->thiz = this; userData->streamType = streamType; userData->isCorked = true; @@ -340,7 +342,7 @@ void PulseAudioServiceAdapterImpl::Disconnect() return; } -std::string PulseAudioServiceAdapterImpl::GetNameByStreamType(AudioStreamType streamType) +string PulseAudioServiceAdapterImpl::GetNameByStreamType(AudioStreamType streamType) { switch (streamType) { case STREAM_MUSIC: @@ -360,19 +362,19 @@ std::string PulseAudioServiceAdapterImpl::GetNameByStreamType(AudioStreamType st } } -AudioStreamType PulseAudioServiceAdapterImpl::GetIdByStreamType(std::string streamType) +AudioStreamType PulseAudioServiceAdapterImpl::GetIdByStreamType(string streamType) { AudioStreamType stream = STREAM_MUSIC; - if (!streamType.compare(std::string("music"))) + if (!streamType.compare(string("music"))) stream = STREAM_MUSIC; - else if (!streamType.compare(std::string("ring"))) + else if (!streamType.compare(string("ring"))) stream = STREAM_RING; - else if (!streamType.compare(std::string("system"))) + else if (!streamType.compare(string("system"))) stream = STREAM_SYSTEM; - else if (!streamType.compare(std::string("notification"))) + else if (!streamType.compare(string("notification"))) stream = STREAM_NOTIFICATION; - else if (!streamType.compare(std::string("alarm"))) + else if (!streamType.compare(string("alarm"))) stream = STREAM_ALARM; return stream; @@ -385,7 +387,7 @@ void PulseAudioServiceAdapterImpl::PaGetSinkInputInfoMuteStatusCb(pa_context *c, PulseAudioServiceAdapterImpl *thiz = userData->thiz; if (eol < 0) { - MEDIA_ERR_LOG("[PulseAudioServiceAdapterImpl] Failed to get sink input information: %s", + MEDIA_ERR_LOG("[PulseAudioServiceAdapterImpl] Failed to get sink input information: %{public}s", pa_strerror(pa_context_errno(c))); return; } @@ -406,7 +408,7 @@ void PulseAudioServiceAdapterImpl::PaGetSinkInputInfoMuteStatusCb(pa_context *c, return; } - std::string streamType(streamtype); + string streamType(streamtype); if (!streamType.compare(thiz->GetNameByStreamType(userData->streamType))) { userData->mute = i->mute; MEDIA_INFO_LOG("[PulseAudioServiceAdapterImpl] Mute : %{public}d for stream : %{public}s", @@ -423,7 +425,7 @@ void PulseAudioServiceAdapterImpl::PaGetSinkInputInfoMuteCb(pa_context *c, const PulseAudioServiceAdapterImpl *thiz = userData->thiz; if (eol < 0) { - MEDIA_ERR_LOG("[PulseAudioServiceAdapterImpl] Failed to get sink input information: %s", + MEDIA_ERR_LOG("[PulseAudioServiceAdapterImpl] Failed to get sink input information: %{public}s", pa_strerror(pa_context_errno(c))); return; } @@ -444,7 +446,7 @@ void PulseAudioServiceAdapterImpl::PaGetSinkInputInfoMuteCb(pa_context *c, const return; } - std::string streamType(streamtype); + string streamType(streamtype); if (!streamType.compare(thiz->GetNameByStreamType(userData->streamType))) { pa_operation_unref(pa_context_set_sink_input_mute(c, i->index, (userData->mute) ? 1 : 0, NULL, NULL)); MEDIA_INFO_LOG("[PulseAudioServiceAdapterImpl] Applied Mute : %{public}d for stream : %{public}s", @@ -495,7 +497,7 @@ void PulseAudioServiceAdapterImpl::PaModuleLoadCb(pa_context *c, uint32_t idx, v { UserData *userData = reinterpret_cast(userdata); if (idx == PA_INVALID_INDEX) { - MEDIA_ERR_LOG("[PulseAudioServiceAdapterImpl] Failure: %s", pa_strerror(pa_context_errno(c))); + MEDIA_ERR_LOG("[PulseAudioServiceAdapterImpl] Failure: %{public}s", pa_strerror(pa_context_errno(c))); userData->idx = PA_INVALID_INDEX; } else { userData->idx = idx; @@ -514,7 +516,7 @@ void PulseAudioServiceAdapterImpl::PaGetSinkInputInfoVolumeCb(pa_context *c, con MEDIA_ERR_LOG("[PulseAudioServiceAdapterImpl] GetSinkInputInfoVolumeCb"); if (eol < 0) { delete userData; - MEDIA_ERR_LOG("[PulseAudioServiceAdapterImpl] Failed to get sink input information: %s", + MEDIA_ERR_LOG("[PulseAudioServiceAdapterImpl] Failed to get sink input information: %{public}s", pa_strerror(pa_context_errno(c))); return; } @@ -537,8 +539,8 @@ void PulseAudioServiceAdapterImpl::PaGetSinkInputInfoVolumeCb(pa_context *c, con return; } - std::string streamType(streamtype); - float volumeFactor = std::atof(streamVolume); + string streamType(streamtype); + float volumeFactor = atof(streamVolume); AudioStreamType streamID = thiz->GetIdByStreamType(streamType); float volumeCb = mAudioServiceAdapterCallback->OnGetVolumeCb(streamtype); float vol = volumeCb * volumeFactor; @@ -566,7 +568,7 @@ void PulseAudioServiceAdapterImpl::PaGetSinkInputInfoCorkStatusCb(pa_context *c, PulseAudioServiceAdapterImpl *thiz = userData->thiz; if (eol < 0) { - MEDIA_ERR_LOG("[PulseAudioServiceAdapterImpl] Failed to get sink input information: %s", + MEDIA_ERR_LOG("[PulseAudioServiceAdapterImpl] Failed to get sink input information: %{public}s", pa_strerror(pa_context_errno(c))); return; } @@ -587,7 +589,7 @@ void PulseAudioServiceAdapterImpl::PaGetSinkInputInfoCorkStatusCb(pa_context *c, return; } - std::string streamType(streamtype); + string streamType(streamtype); if (!streamType.compare(thiz->GetNameByStreamType(userData->streamType))) { userData->isCorked = i->corked; MEDIA_INFO_LOG("[PulseAudioServiceAdapterImpl] corked : %{public}d for stream : %{public}s", @@ -600,7 +602,7 @@ void PulseAudioServiceAdapterImpl::PaGetSinkInputInfoCorkStatusCb(pa_context *c, void PulseAudioServiceAdapterImpl::PaSubscribeCb(pa_context *c, pa_subscription_event_type_t t, uint32_t idx, void *userdata) { - std::unique_ptr userData = std::make_unique(); + unique_ptr userData = make_unique(); PulseAudioServiceAdapterImpl *thiz = reinterpret_cast(userdata); userData->thiz = thiz; switch (t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) { diff --git a/frameworks/innerkitsimpl/audiorenderer/include/audio_renderer_sink_intf.h b/frameworks/innerkitsimpl/audiorenderer/include/audio_renderer_sink_intf.h index 6219e31c01d434f185db1352e3ce26f34d30c203..90500d15753f6bc36876461d53d3c4215088daa7 100644 --- a/frameworks/innerkitsimpl/audiorenderer/include/audio_renderer_sink_intf.h +++ b/frameworks/innerkitsimpl/audiorenderer/include/audio_renderer_sink_intf.h @@ -27,13 +27,13 @@ typedef struct { float volume; } AudioSinkAttr; -int32_t AudioRendererSinkInit(AudioSinkAttr *); +int32_t AudioRendererSinkInit(AudioSinkAttr *attr); void AudioRendererSinkDeInit(void); int32_t AudioRendererSinkStart(void); int32_t AudioRendererSinkStop(void); -int32_t AudioRendererRenderFrame(char*, uint64_t, uint64_t*); +int32_t AudioRendererRenderFrame(char *data, uint64_t len, uint64_t *writeLen); int32_t AudioRendererSinkSetVolume(float, float); -int32_t AudioRendererSinkGetLatency(uint32_t *); +int32_t AudioRendererSinkGetLatency(uint32_t *latency); #ifdef __cplusplus } #endif diff --git a/frameworks/innerkitsimpl/audiorenderer/src/audio_renderer_sink.cpp b/frameworks/innerkitsimpl/audiorenderer/src/audio_renderer_sink.cpp index 340cb3952c5d3688efc43f5714a981bfe1fb0246..3c9b89fc5679dee0249448fb4c1173654e1236b5 100644 --- a/frameworks/innerkitsimpl/audiorenderer/src/audio_renderer_sink.cpp +++ b/frameworks/innerkitsimpl/audiorenderer/src/audio_renderer_sink.cpp @@ -55,7 +55,7 @@ AudioRendererSink::~AudioRendererSink() DeInit(); } -AudioRendererSink* AudioRendererSink::GetInstance() +AudioRendererSink *AudioRendererSink::GetInstance() { static AudioRendererSink audioRenderer_; @@ -119,7 +119,7 @@ static int32_t SwitchAdapter(struct AudioAdapterDescriptor *descs, const char *a continue; } if (!strcmp(desc->adapterName, adapterNameCase)) { - for (uint32_t port = 0; ((desc != nullptr) && (port < desc->portNum)); port++) { + for (uint32_t port = 0; port < desc->portNum; port++) { // Only find out the port of out in the sound card if (desc->ports[port].dir == portFlag) { *renderPort = desc->ports[port]; @@ -465,7 +465,7 @@ extern "C" { using namespace OHOS::AudioStandard; -AudioRendererSink* g_audioRendrSinkInstance = AudioRendererSink::GetInstance(); +AudioRendererSink *g_audioRendrSinkInstance = AudioRendererSink::GetInstance(); int32_t AudioRendererSinkInit(AudioSinkAttr *attr) { diff --git a/frameworks/innerkitsimpl/common/include/media_info.h b/frameworks/innerkitsimpl/common/include/media_info.h deleted file mode 100755 index 55193c649b6b3ad83c72ddbf0b7be250f05de10b..0000000000000000000000000000000000000000 --- a/frameworks/innerkitsimpl/common/include/media_info.h +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @addtogroup MultiMedia_MediaCommon - * @{ - * - * @brief Provides data types and media formats required for recording and playing audio and videos. - * - * - * @since 1.0 - * @version 1.0 - */ - -/** - * @file media_info.h - * - * @brief Declares the media_info class and provides various audio, video, and codec types. - * - * - * @since 1.0 - * @version 1.0 - */ - -#ifndef MEDIA_INFO_H -#define MEDIA_INFO_H -#include - -/** - * Indicates the constant quality mode. In this mode, the bit rate is not limited to guarantee the image quality to - * the largest extent. - */ -const int BITRATE_MODE_CQ = 0; - -/** - * Indicates the variable bit rate mode. In this mode, the codec dynamically adjusts the output bit rate based on - * the image complexity. The codec increases the bit rate if the image is complex and decreases the bit rate if the - * image is simple. - */ -const int BITRATE_MODE_VBR = 1; - -/** Indicates the constant bit rate mode. In this mode, the codec keeps the output bit rate as constant as possible. */ -const int BITRATE_MODE_CBR = 2; - -/** Indicates the ARGB8888 color format. */ -const int32_t COLOR_FORMAT_ARGB8888_32BIT = 16; - -/** Indicates the YUV420SP color format. */ -const int32_t COLOR_FORMAT_YUV420SP = 21; - -/** Indicates that the current frame is an Instantaneous Decoder Refresh (IDR) frame. */ -const std::string KEY_IS_SYNC_FRAME = "is-sync-frame"; - -/** Indicates the frame timestamp. */ -const std::string KEY_TIME_US = "timeUs"; - -/** - * @brief Enumerates audio source types. - * - * @since 1.0 - * @version 1.0 - */ -typedef enum { - /** Invalid audio source */ - AUDIO_SOURCE_INVALID = -1, - /** Default audio source */ - AUDIO_SOURCE_DEFAULT = 0, - /** Microphone */ - AUDIO_MIC = 1, - /** Uplink voice */ - AUDIO_VOICE_UPLINK = 2, - /** Downlink voice */ - AUDIO_VOICE_DOWNLINK = 3, - /** Voice call */ - AUDIO_VOICE_CALL = 4, - /** Camcorder */ - AUDIO_CAMCORDER = 5, - /** Voice recognition */ - AUDIO_VOICE_RECOGNITION = 6, - /** Voice communication */ - AUDIO_VOICE_COMMUNICATION = 7, - /** Remote submix */ - AUDIO_REMOTE_SUBMIX = 8, - /** Unprocessed audio */ - AUDIO_UNPROCESSED = 9, - /** Voice performance */ - AUDIO_VOICE_PERFORMANCE = 10, - /** Echo reference */ - AUDIO_ECHO_REFERENCE = 1997, - /** Radio tuner */ - AUDIO_RADIO_TUNER = 1998, - /** Hotword */ - AUDIO_HOTWORD = 1999, - /** Extended remote submix */ - AUDIO_REMOTE_SUBMIX_EXTEND = 10007, -} AudioSourceType; - -/** - * @brief Defines the audio Device Descriptor. - * - * @since 1.0 - * @version 1.0 - */ -typedef struct { - /** Device name */ - std::string deviceName; - /** Type of the audio input source */ - AudioSourceType inputSourceType; - /** Bits 31-24: reserved bits; bits 23-16: mode ID; bits 15-8: device ID; bits 7-0: channel ID */ - uint32_t deviceId; -} AudioDeviceDesc; - -/** - * @brief Enumerates audio stream types. - * - * @since 1.0 - * @version 1.0 - */ -typedef enum { - /** Default audio stream type */ - TYPE_DEFAULT = -1, - /** Media */ - TYPE_MEDIA = 0, - /** Voice call */ - TYPE_VOICE_COMMUNICATION = 1, - /** System sound */ - TYPE_SYSTEM = 2, - /** Ringtone */ - TYPE_RING = 3, - /** Music */ - TYPE_MUSIC = 4, - /** Alarm */ - TYPE_ALARM = 5, - /** Notification */ - TYPE_NOTIFICATION = 6, - /** Bluetooth Synchronous Connection-Oriented (SCO) */ - TYPE_BLUETOOTH_SCO = 7, - /** Enforced audible */ - TYPE_ENFORCED_AUDIBLE = 8, - /** Dual-tone multi-frequency (DTMF) */ - TYPE_DTMF = 9, - /** Text-To-Speech (TTS) */ - TYPE_TTS = 10, - /** Accessibility */ - TYPE_ACCESSIBILITY = 11, -} AudioStreamType; - -/** - * @brief Enumerates video codec formats. - * - * @since 1.0 - * @version 1.0 - */ -typedef enum { - /** Default format */ - VIDEO_DEFAULT = 0, - /** H.264 */ - H264 = 2, - /** High Efficiency Video Coding (HEVC) */ - HEVC = 5, -} VideoCodecFormat; - -/** - * @brief Enumerates audio codec formats. - * - * @since 1.0 - * @version 1.0 - */ -typedef enum { - /** Default format */ - AUDIO_DEFAULT = 0, - /** Advanced Audio Coding Low Complexity (AAC-LC) */ - AAC_LC = 1, - /** High-Efficiency Advanced Audio Coding (AAC-HE), previously known as AAC+ or aacPlus v1 */ - AAC_HE_V1 = 2, - /** AAC++ or aacPlus v2 */ - AAC_HE_V2 = 3, - /** Advanced Audio Coding Low Delay (AAC-LD) */ - AAC_LD = 4, - /** Advanced Audio Coding Enhanced Low Delay (AAC-ELD) */ - AAC_ELD = 5, - /** Invalid value */ - FORMAT_BUTT, -} AudioCodecFormat; - -/** - * @brief Enumerates audio bit widths. - * - * @since 1.0 - * @version 1.0 - */ -typedef enum { - /** 8-bit width */ - BIT_WIDTH_8 = 8, - /** 16-bit width */ - BIT_WIDTH_16 = 16, - /** 24-bit width */ - BIT_WIDTH_24 = 24, - /** Invalid value */ - BIT_WIDTH_BUTT, -} AudioBitWidth; -#endif // MEDIA_INFO_H diff --git a/frameworks/innerkitsimpl/pulseaudio/include/ltdl.h b/frameworks/innerkitsimpl/pulseaudio/include/ltdl.h index 9ce4b7d3ea355c1df5f3a3581c70c5a515f2ff23..e77d6958f0fb0ec5b693b148a1256935652a4cea 100644 --- a/frameworks/innerkitsimpl/pulseaudio/include/ltdl.h +++ b/frameworks/innerkitsimpl/pulseaudio/include/ltdl.h @@ -19,10 +19,10 @@ #include -typedef void* lt_dlhandle; +typedef void *lt_dlhandle; const char *lt_dlerror(void); -const char* lt_dlgetsearchpath(); +const char *lt_dlgetsearchpath(); int lt_dlclose(lt_dlhandle handle); lt_dlhandle lt_dlopenext(const char *filename); -void* lt_dlsym(lt_dlhandle handle, const char *symbol); +void *lt_dlsym(lt_dlhandle handle, const char *symbol); diff --git a/frameworks/innerkitsimpl/pulseaudio/src/modules/hdi/hdi_source.c b/frameworks/innerkitsimpl/pulseaudio/src/modules/hdi/hdi_source.c index 30b3eeef3c198c599cac2a31497383774c7df410..83286f80b4e69f74381b0b6c5db684c3f99a91a3 100644 --- a/frameworks/innerkitsimpl/pulseaudio/src/modules/hdi/hdi_source.c +++ b/frameworks/innerkitsimpl/pulseaudio/src/modules/hdi/hdi_source.c @@ -335,7 +335,7 @@ static int pa_set_source_properties(pa_module *m, pa_modargs *ma, pa_sample_spec return 0; } -pa_source *pa_hdi_source_new(pa_module *m, pa_modargs *ma, const char*driver) { +pa_source *pa_hdi_source_new(pa_module *m, pa_modargs *ma, const char *driver) { struct userdata *u = NULL; pa_sample_spec ss; char *thread_name = NULL; diff --git a/frameworks/innerkitsimpl/pulseaudio/src/modules/hdi/module_hdi_sink.c b/frameworks/innerkitsimpl/pulseaudio/src/modules/hdi/module_hdi_sink.c index f47aa9ed2fa57d4186563edcf4f75a1bed39db3a..8ffca663c40aef25ba3cc0b0578fc956a23e72b4 100644 --- a/frameworks/innerkitsimpl/pulseaudio/src/modules/hdi/module_hdi_sink.c +++ b/frameworks/innerkitsimpl/pulseaudio/src/modules/hdi/module_hdi_sink.c @@ -21,7 +21,7 @@ #include #include -pa_sink* PaHdiSinkNew(pa_module *m, pa_modargs *ma, const char *driver); +pa_sink *PaHdiSinkNew(pa_module *m, pa_modargs *ma, const char *driver); void PaHdiSinkFree(pa_sink *s); PA_MODULE_AUTHOR("OpenHarmony"); diff --git a/frameworks/innerkitsimpl/pulseaudio/src/modules/hdi/module_hdi_source.c b/frameworks/innerkitsimpl/pulseaudio/src/modules/hdi/module_hdi_source.c index 4e8760c937f138f9ad2e11f8f5130fffe858de00..b77a74ff061cd4ace224aaa2e395c6da03861895 100644 --- a/frameworks/innerkitsimpl/pulseaudio/src/modules/hdi/module_hdi_source.c +++ b/frameworks/innerkitsimpl/pulseaudio/src/modules/hdi/module_hdi_source.c @@ -17,14 +17,12 @@ #include #endif -#include - #include #include #include #include -pa_source* pa_hdi_source_new(pa_module *m, pa_modargs *ma, const char*driver); +pa_source *pa_hdi_source_new(pa_module *m, pa_modargs *ma, const char *driver); void pa_hdi_source_free(pa_source *s); @@ -91,7 +89,7 @@ int pa__get_n_used(pa_module *m) return pa_source_linked_by(source); } -void pa__done(pa_module*m) +void pa__done(pa_module *m) { pa_source *source = NULL; diff --git a/frameworks/innerkitsimpl/pulseaudio/src/pulsecore/ltdl-stub.c b/frameworks/innerkitsimpl/pulseaudio/src/pulsecore/ltdl-stub.c index ce239ab9b8ef4a8b822326f58214da872cc3ab67..d21ea3f6a1c9cbcfca0ebe1e690dfa4f38121f87 100644 --- a/frameworks/innerkitsimpl/pulseaudio/src/pulsecore/ltdl-stub.c +++ b/frameworks/innerkitsimpl/pulseaudio/src/pulsecore/ltdl-stub.c @@ -20,28 +20,33 @@ #define SYSTEM_LIB_PATH "/system/lib/" -lt_dlhandle lt_dlopenext(const char *filename) { +lt_dlhandle lt_dlopenext(const char *filename) +{ pa_assert(filename); return (dlopen(filename, RTLD_NOW)); } -void* lt_dlsym(lt_dlhandle handle, const char *symbol) { +void *lt_dlsym(lt_dlhandle handle, const char *symbol) +{ pa_assert(handle); pa_assert(symbol); return (dlsym(handle, symbol)); } -int lt_dlclose(lt_dlhandle handle) { +int lt_dlclose(lt_dlhandle handle) +{ pa_assert(handle); return (dlclose(handle)); } -const char *lt_dlerror(void) { +const char *lt_dlerror(void) +{ return dlerror(); } -const char* lt_dlgetsearchpath() { - const char* path = SYSTEM_LIB_PATH; +const char *lt_dlgetsearchpath(void) +{ + const char *path = SYSTEM_LIB_PATH; return path; } diff --git a/interfaces/innerkits/native/audioadapter/include/audio_service_adapter.h b/interfaces/innerkits/native/audioadapter/include/audio_service_adapter.h index e1ae1b1dee018b0703e0a8c8d9c01e2520d86aa8..8a11dc7b9a6f3d008287de7ddccd47df208db399 100644 --- a/interfaces/innerkits/native/audioadapter/include/audio_service_adapter.h +++ b/interfaces/innerkits/native/audioadapter/include/audio_service_adapter.h @@ -33,6 +33,8 @@ public: * @return Returns volume level in float */ virtual float OnGetVolumeCb(std::string streamType) = 0; + + virtual ~AudioServiceAdapterCallback() {}; }; class AudioServiceAdapter { @@ -43,7 +45,7 @@ public: * @param cb callback reference for AudioServiceAdapterCallback class * @return Returns instance of class that extends AudioServiceAdapter */ - static std::unique_ptr CreateAudioAdapter(AudioServiceAdapterCallback *cb); + static std::unique_ptr CreateAudioAdapter(std::unique_ptr cb); /** * @brief Connect to underlining audio server @@ -62,7 +64,7 @@ public: * @return Returns module index if module loaded sucessfully; returns an error code * defined in {@link audio_errors.h} otherwise. */ - virtual int32_t OpenAudioPort(char *audioPortName, std::string moduleArgs) = 0; + virtual int32_t OpenAudioPort(std::string audioPortName, std::string moduleArgs) = 0; /** * @brief closes/unloads the audio modules loaded. diff --git a/interfaces/innerkits/native/audiomanager/include/audio_system_manager.h b/interfaces/innerkits/native/audiomanager/include/audio_system_manager.h index 13ca025ad1109b05d65d66ab08544af2db3023a5..7cc47e7991416016e1930befaac7cdcffbeb93c5 100644 --- a/interfaces/innerkits/native/audiomanager/include/audio_system_manager.h +++ b/interfaces/innerkits/native/audiomanager/include/audio_system_manager.h @@ -34,7 +34,7 @@ public: AudioDeviceDescriptor(); virtual ~AudioDeviceDescriptor(); bool Marshalling(Parcel &parcel) const override; - static AudioDeviceDescriptor* Unmarshalling(Parcel &parcel); + static AudioDeviceDescriptor *Unmarshalling(Parcel &parcel); }; /** @@ -102,7 +102,8 @@ public: */ STREAM_ACCESSIBILITY = 12 }; - static AudioSystemManager* GetInstance(); + + static AudioSystemManager *GetInstance(); static float MapVolumeToHDI(int32_t volume); static int32_t MapVolumeFromHDI(float volume); int32_t SetVolume(AudioSystemManager::AudioVolumeType volumeType, int32_t volume) const; diff --git a/interfaces/innerkits/native/audiosession/include/audio_session.h b/interfaces/innerkits/native/audiosession/include/audio_session.h index 08b32e9b00bc9e41dce56bd702203cc2e8064326..50c9c58e998841d88723b01a7653033191ce4711 100644 --- a/interfaces/innerkits/native/audiosession/include/audio_session.h +++ b/interfaces/innerkits/native/audiosession/include/audio_session.h @@ -33,18 +33,18 @@ class AudioSession : public AudioServiceClient { public: uint32_t GetSessionID(); - AudioDevDescriptor* GetActiveAudioSinkDevice(uint32_t sessionID); - AudioDevDescriptor* GetActiveAudioSourceDevice(uint32_t sessionID); + AudioDevDescriptor *GetActiveAudioSinkDevice(uint32_t sessionID); + AudioDevDescriptor *GetActiveAudioSourceDevice(uint32_t sessionID); - bool SetActiveAudioSinkDevice(uint32_t sessionID, const AudioDevDescriptor& audioDesc); - bool SetActiveAudioSourceDevice(uint32_t sessionID, const AudioDevDescriptor& audioDesc); + bool SetActiveAudioSinkDevice(uint32_t sessionID, const AudioDevDescriptor &audioDesc); + bool SetActiveAudioSourceDevice(uint32_t sessionID, const AudioDevDescriptor &audioDesc); float GetAudioStreamVolume(uint32_t sessionID); float GetAudioDeviceVolume(uint32_t sessionID); bool SetAudioStreamVolume(uint32_t sessionID, float volume); bool SetAudioDeviceVolume(uint32_t sessionID, float volume); private: - AudioSession* CreateSession(SessionType eSession); + AudioSession *CreateSession(SessionType eSession); }; } // namespace AudioStandard } // namespace OHOS diff --git a/services/include/client/audio_service_client.h b/services/include/client/audio_service_client.h index 1159a53d9d161d626ac45d6ab19f246cc9e00ce1..c51e13b79ae97a4a9d93e6f02343ace086d53cef 100644 --- a/services/include/client/audio_service_client.h +++ b/services/include/client/audio_service_client.h @@ -210,7 +210,7 @@ public: * @param audioParams will be filled up with stream audio parameters * @return Returns {@code 0} if success; returns {@code -1} otherwise. */ - int32_t GetAudioStreamParams(AudioStreamParams& audioParams); + int32_t GetAudioStreamParams(AudioStreamParams &audioParams); /** * Provides the minimum buffer size required for this audio stream @@ -298,7 +298,7 @@ private: std::mutex mtx; AudioCache acache; - const void* internalReadBuffer; + const void *internalReadBuffer; size_t internalRdBufLen; size_t internalRdBufIndex; int32_t streamCmdStatus; diff --git a/services/src/audio_policy/server/service/include/audio_policy_service.h b/services/src/audio_policy/server/service/include/audio_policy_service.h index dca6eb8a02955f126137b3a98bed9f59efba2efa..fb85c6db063effaf1ed7dc94de5e6e565f56c6b5 100644 --- a/services/src/audio_policy/server/service/include/audio_policy_service.h +++ b/services/src/audio_policy/server/service/include/audio_policy_service.h @@ -64,9 +64,9 @@ public: AudioRingerMode GetRingerMode() const; // Parser callbacks - void OnAudioPortAvailable(std::shared_ptr portInfo); + void OnAudioPortAvailable(std::unique_ptr portInfo); - void OnAudioPortPinAvailable(std::shared_ptr portInfo); + void OnAudioPortPinAvailable(std::unique_ptr portInfo); void OnDefaultOutputPortPin(InternalDeviceType device); diff --git a/services/src/audio_policy/server/service/include/common/audio_config.h b/services/src/audio_policy/server/service/include/common/audio_config.h index 64660be35c6d546c1567129f670004322f9c730b..fca11ce95d88420d55b0902447fdf6768e1f4126 100644 --- a/services/src/audio_policy/server/service/include/common/audio_config.h +++ b/services/src/audio_policy/server/service/include/common/audio_config.h @@ -47,12 +47,12 @@ enum PortType { class PortInfo { public: PortType type; - char* name; - char* role; - char* rate; - char* channels; - char* buffer_size; - char* fileName; + char *name; + char *role; + char *rate; + char *channels; + char *buffer_size; + char *fileName; PortInfo() : type(TYPE_AUDIO_PORT_INVALID), @@ -91,7 +91,7 @@ public: struct AudioPortPinInfo : public PortInfo { public: - char* pinType; + char *pinType; AudioPortPinInfo() : pinType(nullptr) { diff --git a/services/src/audio_policy/server/service/include/config/xml_parser.h b/services/src/audio_policy/server/service/include/config/xml_parser.h index 5ac727d5ebbee46091bf19555926f58eb1506710..82395c6bb1a9e1d3add53e667fda04b3acb17d22 100644 --- a/services/src/audio_policy/server/service/include/config/xml_parser.h +++ b/services/src/audio_policy/server/service/include/config/xml_parser.h @@ -16,14 +16,8 @@ #ifndef ST_XML_PARSER_H #define ST_XML_PARSER_H -#ifdef __cplusplus -extern "C" { -#endif #include #include -#ifdef __cplusplus -} -#endif #include "audio_config.h" #include "iport_observer.h" @@ -39,7 +33,7 @@ public: bool Parse() final; void Destroy() final; - explicit XMLParser(IPortObserver& observer) + explicit XMLParser(IPortObserver &observer) : mPortObserver(observer), mDoc(nullptr) { @@ -50,17 +44,17 @@ public: Destroy(); } private: - bool ParseInternal(xmlNode* node); - NodeName GetNodeNameAsInt(xmlNode* node); - void ParseBuiltInDevices(xmlNode* node); - void ParseDefaultOutputDevice(xmlNode* node); - void ParseDefaultInputDevice(xmlNode* node); - void ParseAudioPorts(xmlNode* node); - void ParseAudioPortPins(xmlNode* node); - InternalDeviceType GetDeviceType(xmlChar *device); - - IPortObserver& mPortObserver; - xmlDoc* mDoc; + bool ParseInternal(xmlNode &node); + NodeName GetNodeNameAsInt(xmlNode &node); + void ParseBuiltInDevices(xmlNode &node); + void ParseDefaultOutputDevice(xmlNode &node); + void ParseDefaultInputDevice(xmlNode &node); + void ParseAudioPorts(xmlNode &node); + void ParseAudioPortPins(xmlNode &node); + InternalDeviceType GetDeviceType(xmlChar &device); + + IPortObserver &mPortObserver; + xmlDoc *mDoc; }; } // namespace AudioStandard } // namespace OHOS diff --git a/services/src/audio_policy/server/service/include/interface/iaudio_policy_interface.h b/services/src/audio_policy/server/service/include/interface/iaudio_policy_interface.h index 51f36771d4d23fad446ca1dfa674cae5ac54f0ff..9a1dcbc1b3c79bef075f6986c92e22442574f62c 100644 --- a/services/src/audio_policy/server/service/include/interface/iaudio_policy_interface.h +++ b/services/src/audio_policy/server/service/include/interface/iaudio_policy_interface.h @@ -42,7 +42,7 @@ public: virtual bool IsStreamActive(AudioStreamType streamType) = 0; - virtual AudioIOHandle OpenAudioPort(std::shared_ptr audioPortInfo) = 0; + virtual AudioIOHandle OpenAudioPort(std::unique_ptr &audioPortInfo) = 0; virtual int32_t CloseAudioPort(AudioIOHandle ioHandle) = 0; diff --git a/services/src/audio_policy/server/service/include/interface/iport_observer.h b/services/src/audio_policy/server/service/include/interface/iport_observer.h index 8e53159172ca006fa0ae6c495b88ca6f0bf8d869..f6b98fdf48a68aa0ae3654ef475c2ea57d201f09 100644 --- a/services/src/audio_policy/server/service/include/interface/iport_observer.h +++ b/services/src/audio_policy/server/service/include/interface/iport_observer.h @@ -23,8 +23,8 @@ namespace OHOS { namespace AudioStandard { class IPortObserver { public: - virtual void OnAudioPortAvailable(std::shared_ptr portInfo) = 0; - virtual void OnAudioPortPinAvailable(std::shared_ptr portInfo) = 0; + virtual void OnAudioPortAvailable(std::unique_ptr portInfo) = 0; + virtual void OnAudioPortPinAvailable(std::unique_ptr portInfo) = 0; virtual void OnDefaultOutputPortPin(InternalDeviceType device) = 0; virtual void OnDefaultInputPortPin(InternalDeviceType device) = 0; }; diff --git a/services/src/audio_policy/server/service/include/manager/audio_adapter_manager.h b/services/src/audio_policy/server/service/include/manager/audio_adapter_manager.h index 97cb41663c1e7a39a874e545c7c2a3bed6a6451f..09bd731981b491024daee17696c8c19fefec4a53 100644 --- a/services/src/audio_policy/server/service/include/manager/audio_adapter_manager.h +++ b/services/src/audio_policy/server/service/include/manager/audio_adapter_manager.h @@ -58,7 +58,7 @@ public: bool IsStreamActive(AudioStreamType streamType); - AudioIOHandle OpenAudioPort(std::shared_ptr audioPortInfo); + AudioIOHandle OpenAudioPort(std::unique_ptr &audioPortInfo); int32_t CloseAudioPort(AudioIOHandle ioHandle); @@ -68,6 +68,8 @@ public: AudioRingerMode GetRingerMode(void); + virtual ~AudioAdapterManager() {} + private: struct UserData { AudioAdapterManager *thiz; @@ -86,10 +88,8 @@ private: mVolumeMap[STREAM_RING] = MAX_VOLUME; } - virtual ~AudioAdapterManager() {} - bool ConnectToPulseAudio(void); - std::string GetModuleArgs(std::shared_ptr audioPortInfo); + std::string GetModuleArgs(std::unique_ptr &audioPortInfo); std::string GetStreamNameByStreamType(AudioStreamType streamType); AudioStreamType GetStreamIDByType(std::string streamType); bool InitAudioPolicyKvStore(bool& isFirstBoot); @@ -107,6 +107,32 @@ private: std::unique_ptr mAudioPolicyKvStore; friend class PolicyCallbackImpl; }; + +class PolicyCallbackImpl : public AudioServiceAdapterCallback { +public: + explicit PolicyCallbackImpl(std::unique_ptr &audioAdapterManager) + { + audioAdapterManager_ = std::move(audioAdapterManager); + } + + ~PolicyCallbackImpl() + { + audioAdapterManager_ = nullptr; + } + + float OnGetVolumeCb(std::string streamType) + { + if (audioAdapterManager_->mRingerMode != RINGER_MODE_NORMAL) { + if (!streamType.compare("ring")) { + return AudioAdapterManager::MIN_VOLUME; + } + } + AudioStreamType streamID = audioAdapterManager_->GetStreamIDByType(streamType); + return audioAdapterManager_->mVolumeMap[streamID]; + } +private: + std::unique_ptr audioAdapterManager_; +}; } // namespace AudioStandard } // namespace OHOS #endif // ST_PULSEAUDIO_ADAPTER_MANAGER_H diff --git a/services/src/audio_policy/server/service/src/audio_policy_service.cpp b/services/src/audio_policy/server/service/src/audio_policy_service.cpp index 642443c457f51c51bc68af171c089df201500533..af320de2468f0dbefeaef73d303d8998f69dc061 100644 --- a/services/src/audio_policy/server/service/src/audio_policy_service.cpp +++ b/services/src/audio_policy/server/service/src/audio_policy_service.cpp @@ -179,14 +179,14 @@ AudioRingerMode AudioPolicyService::GetRingerMode() const // Parser callbacks -void AudioPolicyService::OnAudioPortAvailable(shared_ptr portInfo) +void AudioPolicyService::OnAudioPortAvailable(unique_ptr portInfo) { AudioIOHandle ioHandle = mAudioPolicyManager.OpenAudioPort(portInfo); mIOHandles[portInfo->name] = ioHandle; return; } -void AudioPolicyService::OnAudioPortPinAvailable(shared_ptr portInfo) +void AudioPolicyService::OnAudioPortPinAvailable(unique_ptr portInfo) { return; } diff --git a/services/src/audio_policy/server/service/src/config/xml_parser.cpp b/services/src/audio_policy/server/service/src/config/xml_parser.cpp index 57995920ba10763a14883887b5a430d0877bc1dd..477fa7baf318268faab312c59c59005d1d6de7fc 100644 --- a/services/src/audio_policy/server/service/src/config/xml_parser.cpp +++ b/services/src/audio_policy/server/service/src/config/xml_parser.cpp @@ -32,13 +32,13 @@ bool XMLParser::LoadConfiguration() bool XMLParser::Parse() { - xmlNode* root = xmlDocGetRootElement(mDoc); + xmlNode *root = xmlDocGetRootElement(mDoc); if (root == NULL) { MEDIA_ERR_LOG("xmlDocGetRootElement Failed"); return false; } - if (!ParseInternal(root)) + if (!ParseInternal(*root)) return false; return true; @@ -52,29 +52,29 @@ void XMLParser::Destroy() return; } -bool XMLParser::ParseInternal(xmlNode* node) +bool XMLParser::ParseInternal(xmlNode &node) { - xmlNode* currNode = node; + xmlNode *currNode = &node; for (; currNode; currNode = currNode->next) { if (XML_ELEMENT_NODE == currNode->type) { - switch (GetNodeNameAsInt(currNode)) { + switch (GetNodeNameAsInt(*currNode)) { case BUILT_IN_DEVICES: - ParseBuiltInDevices(currNode); + ParseBuiltInDevices(*currNode); break; case DEFAULT_OUTPUT_DEVICE: - ParseDefaultOutputDevice(currNode); + ParseDefaultOutputDevice(*currNode); break; case DEFAULT_INPUT_DEVICE: - ParseDefaultInputDevice(currNode); + ParseDefaultInputDevice(*currNode); break; case AUDIO_PORTS: - ParseAudioPorts(currNode); + ParseAudioPorts(*currNode); break; case AUDIO_PORT_PINS: - ParseAudioPortPins(currNode); + ParseAudioPortPins(*currNode); break; default: - ParseInternal(currNode->children); + ParseInternal(*(currNode->children)); break; } } @@ -83,74 +83,75 @@ bool XMLParser::ParseInternal(xmlNode* node) return true; } -NodeName XMLParser::GetNodeNameAsInt(xmlNode* node) +NodeName XMLParser::GetNodeNameAsInt(xmlNode &node) { - if (!xmlStrcmp(node->name, reinterpret_cast("BuiltInDevices"))) + if (!xmlStrcmp(node.name, reinterpret_cast("BuiltInDevices"))) return BUILT_IN_DEVICES; - if (!xmlStrcmp(node->name, reinterpret_cast("DefaultOutputDevice"))) + if (!xmlStrcmp(node.name, reinterpret_cast("DefaultOutputDevice"))) return DEFAULT_OUTPUT_DEVICE; - if (!xmlStrcmp(node->name, reinterpret_cast("DefaultInputDevice"))) + if (!xmlStrcmp(node.name, reinterpret_cast("DefaultInputDevice"))) return DEFAULT_INPUT_DEVICE; - if (!xmlStrcmp(node->name, reinterpret_cast("AudioPorts"))) + if (!xmlStrcmp(node.name, reinterpret_cast("AudioPorts"))) return AUDIO_PORTS; - if (!xmlStrcmp(node->name, reinterpret_cast("AudioPort"))) + if (!xmlStrcmp(node.name, reinterpret_cast("AudioPort"))) return AUDIO_PORT; - if (!xmlStrcmp(node->name, reinterpret_cast("AudioPortPins"))) + if (!xmlStrcmp(node.name, reinterpret_cast("AudioPortPins"))) return AUDIO_PORT_PINS; - if (!xmlStrcmp(node->name, reinterpret_cast("AudioPortPin"))) + if (!xmlStrcmp(node.name, reinterpret_cast("AudioPortPin"))) return AUDIO_PORT_PIN; return UNKNOWN; } -void XMLParser::ParseBuiltInDevices(xmlNode* node) +void XMLParser::ParseBuiltInDevices(xmlNode &node) { - while (node) { - xmlNode* child = node->children; - xmlChar* device = xmlNodeGetContent(child); + xmlNode *currNode = &node; + while (currNode) { + xmlNode *child = currNode->children; + xmlChar *device = xmlNodeGetContent(child); if (device != NULL) { MEDIA_DEBUG_LOG("Trigger Cb"); } - node = node->next; + currNode = currNode->next; } return; } -void XMLParser::ParseDefaultOutputDevice(xmlNode* node) +void XMLParser::ParseDefaultOutputDevice(xmlNode &node) { - xmlNode* child = node->children; - xmlChar* device = xmlNodeGetContent(child); + xmlNode *child = node.children; + xmlChar *device = xmlNodeGetContent(child); if (device != NULL) { MEDIA_DEBUG_LOG("DefaultOutputDevice %{public}s", device); - mPortObserver.OnDefaultOutputPortPin(GetDeviceType(device)); + mPortObserver.OnDefaultOutputPortPin(GetDeviceType(*device)); } return; } -void XMLParser::ParseDefaultInputDevice(xmlNode* node) +void XMLParser::ParseDefaultInputDevice(xmlNode &node) { - xmlNode* child = node->children; - xmlChar* device = xmlNodeGetContent(child); + xmlNode *child = node.children; + xmlChar *device = xmlNodeGetContent(child); MEDIA_DEBUG_LOG("DefaultInputDevice"); if (device != NULL) { MEDIA_DEBUG_LOG("DefaultInputDevice %{public}s", device); - mPortObserver.OnDefaultInputPortPin(GetDeviceType(device)); + mPortObserver.OnDefaultInputPortPin(GetDeviceType(*device)); } return; } -void XMLParser::ParseAudioPorts(xmlNode* node) +void XMLParser::ParseAudioPorts(xmlNode &node) { - xmlNode* child = node->xmlChildrenNode; + xmlNode *child = node.xmlChildrenNode; for (; child; child = child->next) { if (!xmlStrcmp(child->name, reinterpret_cast("AudioPort"))) { - std::shared_ptr portInfo = std::make_shared(); + std::unique_ptr portInfo = std::make_unique(); portInfo->type = TYPE_AUDIO_PORT; if (xmlHasProp(child, reinterpret_cast(const_cast("role")))) { @@ -189,20 +190,20 @@ void XMLParser::ParseAudioPorts(xmlNode* node) reinterpret_cast(const_cast("file")))); } - mPortObserver.OnAudioPortAvailable(portInfo); + mPortObserver.OnAudioPortAvailable(std::move(portInfo)); } } return; } -void XMLParser::ParseAudioPortPins(xmlNode* node) +void XMLParser::ParseAudioPortPins(xmlNode &node) { - xmlNode* child = node->xmlChildrenNode; + xmlNode *child = node.xmlChildrenNode; for (; child; child = child->next) { if (!xmlStrcmp(child->name, reinterpret_cast("AudioPortPin"))) { - std::shared_ptr portInfo = std::make_shared(); + std::unique_ptr portInfo = std::make_unique(); portInfo->type = TYPE_AUDIO_PORT_PIN; if (xmlHasProp(child, reinterpret_cast(const_cast("role")))) @@ -220,18 +221,18 @@ void XMLParser::ParseAudioPortPins(xmlNode* node) MEDIA_INFO_LOG("AudioPort:Role: %s, Name: %s, Type: %s", portInfo->role, portInfo->name, portInfo->pinType); - mPortObserver.OnAudioPortPinAvailable(portInfo); + mPortObserver.OnAudioPortPinAvailable(std::move(portInfo)); } } return; } -InternalDeviceType XMLParser::GetDeviceType(xmlChar *device) +InternalDeviceType XMLParser::GetDeviceType(xmlChar &device) { - if (!xmlStrcmp(device, reinterpret_cast("Speaker"))) + if (!xmlStrcmp(&device, reinterpret_cast("Speaker"))) return InternalDeviceType::DEVICE_TYPE_SPEAKER; - if (!xmlStrcmp(device, reinterpret_cast("Built-In Mic"))) + if (!xmlStrcmp(&device, reinterpret_cast("Built-In Mic"))) return InternalDeviceType::DEVICE_TYPE_MIC; return InternalDeviceType::DEVICE_TYPE_NONE; diff --git a/services/src/audio_policy/server/service/src/manager/audio_adapter_manager.cpp b/services/src/audio_policy/server/service/src/manager/audio_adapter_manager.cpp index b6f930834d7e6a3f91264ed3a876d4342e72569f..1f26add40e85e4ab4afb0d5a7b4acad2b8c381ec 100644 --- a/services/src/audio_policy/server/service/src/manager/audio_adapter_manager.cpp +++ b/services/src/audio_policy/server/service/src/manager/audio_adapter_manager.cpp @@ -22,31 +22,11 @@ namespace OHOS { namespace AudioStandard { -class PolicyCallbackImpl : public AudioServiceAdapterCallback { -public: - explicit PolicyCallbackImpl(AudioAdapterManager *audioAdapterManager) - { - audioAdapterManager_ = audioAdapterManager; - } - - float OnGetVolumeCb(std::string streamType) - { - if (audioAdapterManager_->mRingerMode != RINGER_MODE_NORMAL) { - if (!streamType.compare("ring")) { - return AudioAdapterManager::MIN_VOLUME; - } - } - AudioStreamType streamID = audioAdapterManager_->GetStreamIDByType(streamType); - return audioAdapterManager_->mVolumeMap[streamID]; - } -private: - AudioAdapterManager *audioAdapterManager_; -}; - bool AudioAdapterManager::Init() { - PolicyCallbackImpl *policyCallbackImpl = new PolicyCallbackImpl(this); - mAudioServiceAdapter = AudioServiceAdapter::CreateAudioAdapter(policyCallbackImpl); + std::unique_ptr audioAdapterManager(this); + std::unique_ptr policyCallbackImpl = std::make_unique(audioAdapterManager); + mAudioServiceAdapter = AudioServiceAdapter::CreateAudioAdapter(std::move(policyCallbackImpl)); bool result = mAudioServiceAdapter->Connect(); if (!result) { MEDIA_ERR_LOG("[AudioAdapterManager] Error in connecting audio adapter"); @@ -100,6 +80,7 @@ bool AudioAdapterManager::IsStreamActive(AudioStreamType streamType) bool result = mAudioServiceAdapter->IsStreamActive(streamType); return result; } + int32_t AudioAdapterManager::SetDeviceActive(AudioIOHandle ioHandle, InternalDeviceType deviceType, std::string name, bool active) { @@ -136,7 +117,7 @@ AudioRingerMode AudioAdapterManager::GetRingerMode() return mRingerMode; } -AudioIOHandle AudioAdapterManager::OpenAudioPort(std::shared_ptr audioPortInfo) +AudioIOHandle AudioAdapterManager::OpenAudioPort(std::unique_ptr &audioPortInfo) { std::string moduleArgs = GetModuleArgs(audioPortInfo); MEDIA_INFO_LOG("[AudioAdapterManager] load-module %{public}s %{public}s", audioPortInfo->name, moduleArgs.c_str()); @@ -161,7 +142,7 @@ int32_t AudioAdapterManager::CloseAudioPort(AudioIOHandle ioHandle) } // Private Members -std::string AudioAdapterManager::GetModuleArgs(std::shared_ptr audioPortInfo) +std::string AudioAdapterManager::GetModuleArgs(std::unique_ptr &audioPortInfo) { std::string args; diff --git a/services/src/client/audio_service_client.cpp b/services/src/client/audio_service_client.cpp index ff5a02675279b1bd423f5b73c23013232f1bd9be..4780d7eac2c5a41b9156c6b5caefd24a821e0b2a 100644 --- a/services/src/client/audio_service_client.cpp +++ b/services/src/client/audio_service_client.cpp @@ -29,24 +29,30 @@ AudioCapturerCallbacks::~AudioCapturerCallbacks() = default; const uint64_t LATENCY_IN_MSEC = 200UL; #define CHECK_AND_RETURN_IFINVALID(expr) \ +do { \ if (!(expr)) { \ return AUDIO_CLIENT_ERR; \ - } + } \ +} while (false) #define CHECK_PA_STATUS_RET_IF_FAIL(mainLoop, context, paStream, error) \ +do { \ if (!context || !paStream || !mainLoop \ - || !PA_CONTEXT_IS_GOOD(pa_context_get_state(context)) \ - || !PA_STREAM_IS_GOOD(pa_stream_get_state(paStream))) { \ - return error; \ - } + || !PA_CONTEXT_IS_GOOD(pa_context_get_state(context)) \ + || !PA_STREAM_IS_GOOD(pa_stream_get_state(paStream))) { \ + return error; \ + } \ +} while (false) #define CHECK_PA_STATUS_FOR_WRITE(mainLoop, context, paStream, pError, retVal) \ +do { \ if (!context || !paStream || !mainLoop \ - || !PA_CONTEXT_IS_GOOD(pa_context_get_state(context)) \ - || !PA_STREAM_IS_GOOD(pa_stream_get_state(paStream))) { \ - pError = pa_context_errno(context); \ - return retVal; \ - } + || !PA_CONTEXT_IS_GOOD(pa_context_get_state(context)) \ + || !PA_STREAM_IS_GOOD(pa_stream_get_state(paStream))) { \ + pError = pa_context_errno(context); \ + return retVal; \ + } \ +} while (false) AudioStreamParams AudioServiceClient::ConvertFromPAAudioParams(pa_sample_spec paSampleSpec) { @@ -142,7 +148,6 @@ void AudioServiceClient::PAStreamUnderFlowCb(pa_stream *stream, void *userdata) void AudioServiceClient::PAStreamLatencyUpdateCb(pa_stream *stream, void *userdata) { pa_threaded_mainloop *mainLoop = (pa_threaded_mainloop *)userdata; - MEDIA_INFO_LOG("Inside latency update callback"); pa_threaded_mainloop_signal(mainLoop, 0); } @@ -906,7 +911,7 @@ int32_t AudioServiceClient::UpdateReadBuffer(uint8_t *buffer, size_t &length, si internalRdBufLen = 0; internalRdBufIndex = 0; if (retVal < 0) { - MEDIA_ERR_LOG("pa_stream_drop failed, retVal: %d", retVal); + MEDIA_ERR_LOG("pa_stream_drop failed, retVal: %{public}d", retVal); return AUDIO_CLIENT_READ_STREAM_ERR; } } @@ -927,7 +932,7 @@ int32_t AudioServiceClient::ReadStream(StreamBuffer &stream, bool isBlocking) while (!internalReadBuffer) { int retVal = pa_stream_peek(paStream, &internalReadBuffer, &internalRdBufLen); if (retVal < 0) { - MEDIA_ERR_LOG("pa_stream_peek failed, retVal: %d", retVal); + MEDIA_ERR_LOG("pa_stream_peek failed, retVal: %{public}d", retVal); pa_threaded_mainloop_unlock(mainLoop); return AUDIO_CLIENT_READ_STREAM_ERR; } @@ -942,7 +947,7 @@ int32_t AudioServiceClient::ReadStream(StreamBuffer &stream, bool isBlocking) } else if (!internalReadBuffer) { retVal = pa_stream_drop(paStream); if (retVal < 0) { - MEDIA_ERR_LOG("pa_stream_drop failed, retVal: %d", retVal); + MEDIA_ERR_LOG("pa_stream_drop failed, retVal: %{public}d", retVal); pa_threaded_mainloop_unlock(mainLoop); return AUDIO_CLIENT_READ_STREAM_ERR; } @@ -1191,7 +1196,7 @@ void AudioServiceClient::GetSinkInputInfoVolumeCb(pa_context *c, const pa_sink_i AudioServiceClient *thiz = reinterpret_cast(userdata); if (eol < 0) { - MEDIA_ERR_LOG("Failed to get sink input information: %s", pa_strerror(pa_context_errno(c))); + MEDIA_ERR_LOG("Failed to get sink input information: %{public}s", pa_strerror(pa_context_errno(c))); return; } @@ -1225,7 +1230,7 @@ void AudioServiceClient::GetSinkInputInfoVolumeCb(pa_context *c, const pa_sink_i pa_cvolume_set(&cv, i->channel_map.channels, volume); pa_operation_unref(pa_context_set_sink_input_volume(c, i->index, &cv, NULL, NULL)); - MEDIA_INFO_LOG("Applied volume : %{public}f for stream : %{public}s, volumeInt%{public}d", + MEDIA_INFO_LOG("Applied volume : %{public}f for stream : %{public}s, pa volume: %{public}d", vol, i->name, volume); return; diff --git a/services/src/server/audio_server.cpp b/services/src/server/audio_server.cpp index 2688a8675cd408514e4b72e00e0c9b2d3afaee18..364b3d61ede2ee5635b2686878b832339f58d631 100644 --- a/services/src/server/audio_server.cpp +++ b/services/src/server/audio_server.cpp @@ -35,7 +35,7 @@ REGISTER_SYSTEM_ABILITY_BY_ID(AudioServer, AUDIO_DISTRIBUTED_SERVICE_ID, true) #ifdef PA constexpr int PA_ARG_COUNT = 1; -void* AudioServer::paDaemonThread(void* arg) +void *AudioServer::paDaemonThread(void *arg) { /* Load the mandatory pulseaudio modules at start */ char *argv[] = { diff --git a/services/test/audio_capturer_test.cpp b/services/test/audio_capturer_test.cpp index cc6c2d27c1db65d11eb6ef2a7af8049e94c3af56..37f56c36c82f8d66432f6dbe1ae820c0983b7c55 100644 --- a/services/test/audio_capturer_test.cpp +++ b/services/test/audio_capturer_test.cpp @@ -96,7 +96,7 @@ public: return false; } - uint8_t* buffer = (uint8_t *)malloc(bufferLen); + auto buffer = std::make_unique(bufferLen); if (buffer == nullptr) { MEDIA_ERR_LOG("AudioCapturerTest: Failed to allocate buffer"); return false; @@ -107,7 +107,7 @@ public: while (numBuffersToCapture) { size_t bytesRead = 0; while (bytesRead < bufferLen) { - int32_t len = audioCapturer->Read(*(buffer + bytesRead), bufferLen - bytesRead, isBlocking); + int32_t len = audioCapturer->Read(*(buffer.get() + bytesRead), bufferLen - bytesRead, isBlocking); if (len >= 0) { bytesRead += len; } else { @@ -122,7 +122,7 @@ public: continue; } - if (fwrite(buffer, size, bytesRead, pFile) != bytesRead) { + if (fwrite(buffer.get(), size, bytesRead, pFile) != bytesRead) { MEDIA_ERR_LOG("error occured in fwrite"); } numBuffersToCapture--; @@ -138,7 +138,6 @@ public: } } } - free(buffer); return true; } diff --git a/services/test/audio_policy_test.cpp b/services/test/audio_policy_test.cpp index 3805af2e8d28ba3b1c4d9147780c64c8c8385f7d..fd46475fada53c7a6dca4db02fb87ef3687da401 100644 --- a/services/test/audio_policy_test.cpp +++ b/services/test/audio_policy_test.cpp @@ -66,8 +66,9 @@ static void PrintUsage(void) cout << "\tWritten by Sajeesh Sidharthan and Anurup M" << endl << endl; } -static void HandleVolume(const AudioSystemManager *audioSystemMgr, int streamType, char option) +static void HandleVolume(int streamType, char option) { + AudioSystemManager *audioSystemMgr = AudioSystemManager::GetInstance(); if (option == 'v') { float volume = audioSystemMgr->GetVolume(static_cast(streamType)); cout << "Get Volume : " << volume << endl; @@ -80,8 +81,9 @@ static void HandleVolume(const AudioSystemManager *audioSystemMgr, int streamTyp } } -static void HandleMute(const AudioSystemManager *audioSystemMgr, int streamType, char option) +static void HandleMute(int streamType, char option) { + AudioSystemManager *audioSystemMgr = AudioSystemManager::GetInstance(); if (option == 'm') { bool muteStatus = audioSystemMgr->IsStreamMute(static_cast(streamType)); cout << "Get Mute : " << muteStatus << endl; @@ -94,8 +96,9 @@ static void HandleMute(const AudioSystemManager *audioSystemMgr, int streamType, } } -static void HandleMicMute(const AudioSystemManager *audioSystemMgr, char option) +static void HandleMicMute(char option) { + AudioSystemManager *audioSystemMgr = AudioSystemManager::GetInstance(); if (option == 'u') { bool muteStatus = audioSystemMgr->IsMicrophoneMute(); cout << "Is Mic Mute : " << muteStatus << endl; @@ -113,15 +116,17 @@ static void SetStreamType(int &streamType) cout << "Set Stream : " << streamType << endl; } -static void IsStreamActive(const AudioSystemManager *audioSystemMgr) +static void IsStreamActive() { + AudioSystemManager *audioSystemMgr = AudioSystemManager::GetInstance(); int streamType = strtol(optarg, nullptr, AudioPolicyTest::OPT_ARG_BASE); cout << "Stream Active: " << audioSystemMgr->IsStreamActive( static_cast(streamType)) << endl; } -static void SetDeviceActive(const AudioSystemManager *audioSystemMgr, int argc, char* argv[]) +static void SetDeviceActive(int argc, char *argv[]) { + AudioSystemManager *audioSystemMgr = AudioSystemManager::GetInstance(); int active = -1; int device = strtol(optarg, nullptr, AudioPolicyTest::OPT_ARG_BASE); cout << "Set Device : " << device << endl; @@ -137,15 +142,17 @@ static void SetDeviceActive(const AudioSystemManager *audioSystemMgr, int argc, cout << "Set DeviceActive Result: " << result << endl; } -static void IsDeviceActive(const AudioSystemManager *audioSystemMgr) +static void IsDeviceActive() { + AudioSystemManager *audioSystemMgr = AudioSystemManager::GetInstance(); int device = strtol(optarg, nullptr, AudioPolicyTest::OPT_ARG_BASE); bool devActiveStatus = audioSystemMgr->IsDeviceActive(ActiveDeviceType(device)); cout << "GetDevice Active : " << devActiveStatus << endl; } -static void HandleRingerMode(const AudioSystemManager *audioSystemMgr, char option) +static void HandleRingerMode(char option) { + AudioSystemManager *audioSystemMgr = AudioSystemManager::GetInstance(); if (option == 'r') { int ringMode = static_cast(audioSystemMgr->GetRingerMode()); cout << "Get Ringer Mode : " << ringMode << endl; @@ -183,36 +190,35 @@ int main(int argc, char* argv[]) } int streamType = static_cast(AudioSystemManager::AudioVolumeType::STREAM_MUSIC); - AudioSystemManager *audioSystemMgr = AudioSystemManager::GetInstance(); while ((opt = getopt(argc, argv, ":V:U:S:D:M:R:d:s:vmru")) != -1) { switch (opt) { case 'V': case 'v': - HandleVolume(audioSystemMgr, streamType, opt); + HandleVolume(streamType, opt); break; case 'M': case 'm': - HandleMute(audioSystemMgr, streamType, opt); + HandleMute(streamType, opt); break; case 'U': case 'u': - HandleMicMute(audioSystemMgr, opt); + HandleMicMute(opt); break; case 'S': SetStreamType(streamType); break; case 's': - IsStreamActive(audioSystemMgr); + IsStreamActive(); break; case 'D': - SetDeviceActive(audioSystemMgr, argc, argv); + SetDeviceActive(argc, argv); break; case 'd': - IsDeviceActive(audioSystemMgr); + IsDeviceActive(); break; case 'R': case 'r': - HandleRingerMode(audioSystemMgr, opt); + HandleRingerMode(opt); break; case ':': NoValueError(); diff --git a/services/test/audio_renderer_test.cpp b/services/test/audio_renderer_test.cpp index 26aea417bcb6987013a55b7d9065eec61dc91266..812746ee69b7cbe304b6d2f4dd908299749008df 100644 --- a/services/test/audio_renderer_test.cpp +++ b/services/test/audio_renderer_test.cpp @@ -102,9 +102,9 @@ public: } bool TestPauseStop(const unique_ptr &audioRenderer, bool &pauseTested, bool &stopTested, - FILE *wavFile) const + FILE &wavFile) const { - uint64_t currFilePos = ftell(wavFile); + uint64_t currFilePos = ftell(&wavFile); if (!stopTested && (currFilePos > AudioTestConstants::STOP_BUFFER_POSITION) && audioRenderer->Stop()) { stopTested = true; sleep(AudioTestConstants::STOP_RENDER_TIME_SECONDS); @@ -167,7 +167,7 @@ public: } int32_t n = 2; - uint8_t *buffer = (uint8_t *) malloc(n * bufferLen); + auto buffer = std::make_unique(n * bufferLen); if (buffer == nullptr) { MEDIA_ERR_LOG("AudioRendererTest: Failed to allocate buffer"); return false; @@ -181,11 +181,11 @@ public: bool pauseTested = false; while (!feof(wavFile)) { - bytesToWrite = fread(buffer, 1, bufferLen, wavFile); + bytesToWrite = fread(buffer.get(), 1, bufferLen, wavFile); bytesWritten = 0; MEDIA_INFO_LOG("AudioRendererTest: Bytes to write: %{public}zu", bytesToWrite); - if (!TestPauseStop(audioRenderer, pauseTested, stopTested, wavFile)) { + if (!TestPauseStop(audioRenderer, pauseTested, stopTested, *wavFile)) { break; } @@ -195,7 +195,7 @@ public: } while ((bytesWritten < bytesToWrite) && ((bytesToWrite - bytesWritten) > minBytes)) { - bytesWritten += audioRenderer->Write(buffer + bytesWritten, + bytesWritten += audioRenderer->Write(buffer.get() + bytesWritten, bytesToWrite - bytesWritten); MEDIA_INFO_LOG("AudioRendererTest: Bytes written: %{public}zu", bytesWritten); if (bytesWritten < 0) { @@ -210,8 +210,6 @@ public: MEDIA_ERR_LOG("AudioRendererTest: Drain failed"); } - free(buffer); - return true; }