diff --git a/frameworks/js/napi/audio_manager/src/audio_volume_key_event_napi.cpp b/frameworks/js/napi/audio_manager/src/audio_volume_key_event_napi.cpp index 7bc9f09..decd165 100644 --- a/frameworks/js/napi/audio_manager/src/audio_volume_key_event_napi.cpp +++ b/frameworks/js/napi/audio_manager/src/audio_volume_key_event_napi.cpp @@ -121,7 +121,7 @@ static void NativeVolumeEventToJsObj(const napi_env& env, napi_value& jsObj, void AudioVolumeKeyEventNapi::OnJsCallbackVolumeEvent(std::unique_ptr &jsCb) { - MEDIA_ERR_LOG("AudioVolumeKeyEventNapi:OnJsCallbackVolumeEvent"); + MEDIA_INFO_LOG("AudioVolumeKeyEventNapi:OnJsCallbackVolumeEvent"); uv_loop_s *loop = nullptr; napi_get_uv_event_loop(env_, &loop); if (loop == nullptr) { diff --git a/frameworks/js/napi/ringtone_manager/src/audio_renderer_info_napi.cpp b/frameworks/js/napi/ringtone_manager/src/audio_renderer_info_napi.cpp index cc4030c..9922111 100644 --- a/frameworks/js/napi/ringtone_manager/src/audio_renderer_info_napi.cpp +++ b/frameworks/js/napi/ringtone_manager/src/audio_renderer_info_napi.cpp @@ -320,5 +320,5 @@ napi_value AudioRendererInfoNapi::SetRendererFlags(napi_env env, napi_callback_i return jsResult; } -} -} \ No newline at end of file +} // namespace AudioStandard +} // namespace OHOS diff --git a/frameworks/js/napi/ringtone_manager/src/ringtone_options_napi.cpp b/frameworks/js/napi/ringtone_manager/src/ringtone_options_napi.cpp index f2ee388..92eb9b5 100644 --- a/frameworks/js/napi/ringtone_manager/src/ringtone_options_napi.cpp +++ b/frameworks/js/napi/ringtone_manager/src/ringtone_options_napi.cpp @@ -252,5 +252,5 @@ napi_value RingtoneOptionsNapi::SetLoop(napi_env env, napi_callback_info info) return jsResult; } -} -} \ No newline at end of file +} // namespace AudioStandard +} // namespace OHOS diff --git a/frameworks/native/audioadapter/include/audio_service_adapter.h b/frameworks/native/audioadapter/include/audio_service_adapter.h index 86fb5d0..160a316 100644 --- a/frameworks/native/audioadapter/include/audio_service_adapter.h +++ b/frameworks/native/audioadapter/include/audio_service_adapter.h @@ -36,7 +36,7 @@ public: virtual void OnSessionRemoved(const uint32_t sessionID) = 0; - virtual ~AudioServiceAdapterCallback() {}; + virtual ~AudioServiceAdapterCallback() {} }; class AudioServiceAdapter { diff --git a/frameworks/native/audioadapter/include/pulse_audio_service_adapter_impl.h b/frameworks/native/audioadapter/include/pulse_audio_service_adapter_impl.h index 97739e1..9000580 100644 --- a/frameworks/native/audioadapter/include/pulse_audio_service_adapter_impl.h +++ b/frameworks/native/audioadapter/include/pulse_audio_service_adapter_impl.h @@ -25,7 +25,7 @@ namespace OHOS { namespace AudioStandard { class PulseAudioServiceAdapterImpl : public AudioServiceAdapter { public: - PulseAudioServiceAdapterImpl(std::unique_ptr &cb); + explicit PulseAudioServiceAdapterImpl(std::unique_ptr &cb); ~PulseAudioServiceAdapterImpl(); bool Connect() override; diff --git a/frameworks/native/audioadapter/src/pulse_audio_service_adapter_impl.cpp b/frameworks/native/audioadapter/src/pulse_audio_service_adapter_impl.cpp index 796bfc9..4a1aa66 100644 --- a/frameworks/native/audioadapter/src/pulse_audio_service_adapter_impl.cpp +++ b/frameworks/native/audioadapter/src/pulse_audio_service_adapter_impl.cpp @@ -90,14 +90,6 @@ bool PulseAudioServiceAdapterImpl::Connect() bool PulseAudioServiceAdapterImpl::ConnectToPulseAudio() { - unique_ptr userData = make_unique(); - if (userData == nullptr) { - MEDIA_ERR_LOG("[PulseAudioServiceAdapterImpl] UserData memory alloc failed"); - return false; - } - - userData->thiz = this; - if (mContext != nullptr) { pa_context_disconnect(mContext); pa_context_set_state_callback(mContext, nullptr, nullptr); @@ -560,7 +552,7 @@ void PulseAudioServiceAdapterImpl::PaGetSinkInputInfoVolumeCb(pa_context *c, con UserData *userData = reinterpret_cast(userdata); PulseAudioServiceAdapterImpl *thiz = userData->thiz; - MEDIA_ERR_LOG("[PulseAudioServiceAdapterImpl] GetSinkInputInfoVolumeCb"); + MEDIA_INFO_LOG("[PulseAudioServiceAdapterImpl] GetSinkInputInfoVolumeCb"); if (eol < 0) { delete userData; MEDIA_ERR_LOG("[PulseAudioServiceAdapterImpl] Failed to get sink input information: %{public}s", diff --git a/frameworks/native/audiorenderer/src/audio_renderer_sink.cpp b/frameworks/native/audiorenderer/src/audio_renderer_sink.cpp index fca6284..5901c02 100644 --- a/frameworks/native/audiorenderer/src/audio_renderer_sink.cpp +++ b/frameworks/native/audiorenderer/src/audio_renderer_sink.cpp @@ -92,7 +92,7 @@ void AudioRendererSink::DeInit() #endif // DUMPFILE } -int32_t InitAttrs(struct AudioSampleAttributes &attrs) +void InitAttrs(struct AudioSampleAttributes &attrs) { /* Initialization of audio parameters for playback */ #ifdef PRODUCT_M40 @@ -113,8 +113,6 @@ int32_t InitAttrs(struct AudioSampleAttributes &attrs) attrs.startThreshold = DEEP_BUFFER_RENDER_PERIOD_SIZE / (attrs.frameSize); attrs.stopThreshold = INT_32_MAX; attrs.silenceThreshold = 0; - - return SUCCESS; } static int32_t SwitchAdapterRender(struct AudioAdapterDescriptor *descs, string adapterNameCase, @@ -169,7 +167,7 @@ uint32_t PcmFormatToBits(enum AudioFormat format) return PCM_32_BIT; default: return PCM_24_BIT; - }; + } } int32_t AudioRendererSink::CreateRender(struct AudioPort &renderPort) @@ -182,7 +180,7 @@ int32_t AudioRendererSink::CreateRender(struct AudioPort &renderPort) param.format = attr_.format; param.frameSize = PcmFormatToBits(param.format) * param.channelCount / PCM_8_BIT; param.startThreshold = DEEP_BUFFER_RENDER_PERIOD_SIZE / (param.frameSize); - MEDIA_ERR_LOG("AudioRendererSink Create render format: %{public}d", param.format); + MEDIA_INFO_LOG("AudioRendererSink Create render format: %{public}d", param.format); struct AudioDeviceDescriptor deviceDesc; deviceDesc.portId = renderPort.portId; deviceDesc.pins = PIN_OUT_SPEAKER; diff --git a/frameworks/native/audiorenderer/src/bluetooth_renderer_sink.cpp b/frameworks/native/audiorenderer/src/bluetooth_renderer_sink.cpp index 61c8b59..01f8d61 100644 --- a/frameworks/native/audiorenderer/src/bluetooth_renderer_sink.cpp +++ b/frameworks/native/audiorenderer/src/bluetooth_renderer_sink.cpp @@ -94,7 +94,7 @@ void BluetoothRendererSink::DeInit() #endif // BT_DUMPFILE } -int32_t InitAttrs(struct AudioSampleAttributes &attrs) +void InitAttrs(struct AudioSampleAttributes &attrs) { /* Initialization of audio parameters for playback */ attrs.format = AUDIO_FORMAT_PCM_16_BIT; @@ -109,8 +109,6 @@ int32_t InitAttrs(struct AudioSampleAttributes &attrs) attrs.startThreshold = DEEP_BUFFER_RENDER_PERIOD_SIZE / (attrs.frameSize); attrs.stopThreshold = INT_32_MAX; attrs.silenceThreshold = 0; - - return SUCCESS; } static int32_t SwitchAdapter(struct AudioAdapterDescriptor *descs, string adapterNameCase, @@ -199,7 +197,7 @@ int32_t BluetoothRendererSink::CreateRender(struct AudioPort &renderPort) param.format = attr_.format; param.frameSize = PcmFormatToBits(param.format) * param.channelCount / PCM_8_BIT; param.startThreshold = DEEP_BUFFER_RENDER_PERIOD_SIZE / (param.frameSize); - MEDIA_ERR_LOG("BluetoothRendererSink Create render format: %{public}d", param.format); + MEDIA_INFO_LOG("BluetoothRendererSink Create render format: %{public}d", param.format); struct AudioDeviceDescriptor deviceDesc; deviceDesc.portId = renderPort.portId; deviceDesc.pins = PIN_OUT_SPEAKER; diff --git a/frameworks/native/pulseaudio/src/modules/hdi/hdi_sink.c b/frameworks/native/pulseaudio/src/modules/hdi/hdi_sink.c index da88e16..1ec17a5 100644 --- a/frameworks/native/pulseaudio/src/modules/hdi/hdi_sink.c +++ b/frameworks/native/pulseaudio/src/modules/hdi/hdi_sink.c @@ -238,6 +238,7 @@ static int SinkProcessMsg(pa_msgobject *o, int code, void *data, int64_t offset, pa_memchunk *chunk) { struct Userdata *u = PA_SINK(o)->userdata; + pa_assert(u); switch (code) { case PA_SINK_MESSAGE_GET_LATENCY: { uint64_t latency; @@ -342,7 +343,7 @@ static int32_t PrepareDevice(struct Userdata *u) enum AudioFormat format = ConvertToHDIAudioFormat(u->ss.format); sample_attrs.format = format; sample_attrs.sampleFmt = format; - MEDIA_ERR_LOG("audiorenderer format: %d", sample_attrs.format); + MEDIA_INFO_LOG("audiorenderer format: %d", sample_attrs.format); sample_attrs.sampleRate = u->ss.rate; sample_attrs.channel = u->ss.channels; @@ -420,6 +421,7 @@ pa_sink *PaHdiSinkNew(pa_module *m, pa_modargs *ma, const char *driver) pa_assert(ma); u = pa_xnew0(struct Userdata, 1); + pa_assert(u); u->core = m->core; u->module = m; diff --git a/frameworks/native/pulseaudio/src/modules/hdi/hdi_source.c b/frameworks/native/pulseaudio/src/modules/hdi/hdi_source.c index 6251dee..5baf62e 100644 --- a/frameworks/native/pulseaudio/src/modules/hdi/hdi_source.c +++ b/frameworks/native/pulseaudio/src/modules/hdi/hdi_source.c @@ -97,6 +97,7 @@ static void userdata_free(struct Userdata *u) static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t offset, pa_memchunk *chunk) { struct Userdata *u = PA_SOURCE(o)->userdata; + pa_assert(u); switch (code) { case PA_SOURCE_MESSAGE_GET_LATENCY: { diff --git a/interfaces/inner_api/native/audioringtone/include/iringtone_player.h b/interfaces/inner_api/native/audioringtone/include/iringtone_player.h index c28e130..23d16ce 100644 --- a/interfaces/inner_api/native/audioringtone/include/iringtone_player.h +++ b/interfaces/inner_api/native/audioringtone/include/iringtone_player.h @@ -116,6 +116,6 @@ public: */ virtual int32_t Release() = 0; }; -} // AudioStandard -} // OHOS +} // namespace AudioStandard +} // namespace OHOS #endif // IRINGTONE_PLAYER_H diff --git a/interfaces/kits/js/audio_capturer/include/audio_capturer_napi.h b/interfaces/kits/js/audio_capturer/include/audio_capturer_napi.h index cc829da..7b4fcf4 100644 --- a/interfaces/kits/js/audio_capturer/include/audio_capturer_napi.h +++ b/interfaces/kits/js/audio_capturer/include/audio_capturer_napi.h @@ -132,6 +132,6 @@ private: std::shared_ptr periodPositionCBNapi_ = nullptr; std::shared_ptr callbackNapi_ = nullptr; }; -} -} +} // namespace AudioStandard +} // namespace OHOS #endif /* AUDIO_CAPTURER_NAPI_H_ */ diff --git a/interfaces/kits/js/audio_renderer/include/audio_renderer_napi.h b/interfaces/kits/js/audio_renderer/include/audio_renderer_napi.h index 6a4e5c8..9171b32 100644 --- a/interfaces/kits/js/audio_renderer/include/audio_renderer_napi.h +++ b/interfaces/kits/js/audio_renderer/include/audio_renderer_napi.h @@ -190,6 +190,6 @@ static const std::map audioStateMap = { {"STATE_RELEASED", RENDERER_RELEASED}, {"STATE_PAUSED", RENDERER_PAUSED} }; -} -} +} // namespace AudioStandard +} // namespace OHOS #endif /* AUDIO_RENDERER_NAPI_H_ */ diff --git a/services/include/audio_policy/client/audio_policy_base.h b/services/include/audio_policy/client/audio_policy_base.h index 8a74db7..8cced1e 100644 --- a/services/include/audio_policy/client/audio_policy_base.h +++ b/services/include/audio_policy/client/audio_policy_base.h @@ -78,6 +78,6 @@ public: public: DECLARE_INTERFACE_DESCRIPTOR(u"IAudioPolicy"); }; -} // AudioStandard +} // namespace AudioStandard } // namespace OHOS #endif // I_AUDIO_POLICY_BASE_H diff --git a/services/include/audio_policy/client/audio_policy_manager_stub.h b/services/include/audio_policy/client/audio_policy_manager_stub.h index 2b82522..55a3f64 100644 --- a/services/include/audio_policy/client/audio_policy_manager_stub.h +++ b/services/include/audio_policy/client/audio_policy_manager_stub.h @@ -53,6 +53,6 @@ private: void GetDevicesInternal(MessageParcel &data, MessageParcel &reply); void SetDeviceChangeCallbackInternal(MessageParcel &data, MessageParcel &reply); }; -} // AudioStandard +} // namespace AudioStandard } // namespace OHOS #endif // AUDIO_POLICY_MANAGER_STUB_H diff --git a/services/include/audio_policy/server/audio_service_dump.h b/services/include/audio_policy/server/audio_service_dump.h index 50edd53..cead248 100644 --- a/services/include/audio_policy/server/audio_service_dump.h +++ b/services/include/audio_policy/server/audio_service_dump.h @@ -35,7 +35,7 @@ template void AppendFormat(std::string& out, const char* fmt, Args&& ... args) { char buf[STRING_BUFFER_SIZE] = {0}; - int len = ::snprintf_s(buf, sizeof(buf), sizeof(buf)-1, fmt, args...); + int len = ::sprintf_s(buf, sizeof(buf), fmt, args...); if (len <= 0) { MEDIA_ERR_LOG("snprintf_s error : buffer allocation fails"); return; @@ -103,14 +103,14 @@ private: pa_mainloop_api *api; pa_context *context; std::mutex ctrlMutex; - + bool isMainLoopStarted; bool isContextConnected; AudioData audioData_; - + int32_t ConnectStreamToPA(); void ResetPAAudioDump(); - + void PlaybackStreamDump(std::string &dumpString); void RecordStreamDump(std::string &dumpString); void HDFModulesDump(std::string &dumpString); @@ -126,7 +126,7 @@ private: static const std::string GetDeviceTypeName(DeviceType deviceType); static bool IsEndWith(const std::string &mainStr, const std::string &toMatch); static bool IsValidModule (const std::string moduleName); - + // Callbacks static void PAContextStateCb(pa_context *context, void *userdata); static void PASinkInfoCallback(pa_context *c, const pa_sink_info *i, int eol, void *userdata); diff --git a/services/include/audio_service/client/audio_server_death_recipient.h b/services/include/audio_service/client/audio_server_death_recipient.h index 6930af8..aa90b83 100644 --- a/services/include/audio_service/client/audio_server_death_recipient.h +++ b/services/include/audio_service/client/audio_server_death_recipient.h @@ -23,7 +23,7 @@ namespace OHOS { namespace AudioStandard { class AudioServerDeathRecipient : public IRemoteObject::DeathRecipient { public: - explicit AudioServerDeathRecipient(pid_t pid) : pid_(pid) {}; + explicit AudioServerDeathRecipient(pid_t pid) : pid_(pid) {} virtual ~AudioServerDeathRecipient() = default; DISALLOW_COPY_AND_MOVE(AudioServerDeathRecipient); void OnRemoteDied(const wptr &remote) diff --git a/services/src/audio_policy/client/audio_policy_manager.cpp b/services/src/audio_policy/client/audio_policy_manager.cpp index 70ba93f..56f714a 100644 --- a/services/src/audio_policy/client/audio_policy_manager.cpp +++ b/services/src/audio_policy/client/audio_policy_manager.cpp @@ -161,7 +161,7 @@ int32_t AudioPolicyManager::UnsetRingerModeCallback(const int32_t clientId) int32_t AudioPolicyManager::SetDeviceChangeCallback(const std::shared_ptr &callback) { - MEDIA_ERR_LOG("Entered %{public}s", __func__); + MEDIA_INFO_LOG("Entered %{public}s", __func__); if (callback == nullptr) { MEDIA_ERR_LOG("AudioPolicyManager: callback is nullptr"); return ERR_INVALID_PARAM; diff --git a/services/src/audio_policy/server/audio_service_dump.cpp b/services/src/audio_policy/server/audio_service_dump.cpp index 2ff9045..598f52b 100644 --- a/services/src/audio_policy/server/audio_service_dump.cpp +++ b/services/src/audio_policy/server/audio_service_dump.cpp @@ -718,5 +718,5 @@ void AudioServiceDump::PASourceOutputInfoCallback(pa_context *c, const pa_source } asDump->audioData_.streamData.sourceOutputs.push_back(sourceOutputInfo); } -} // namespace AudoStandard +} // namespace AudioStandard } // namespace OHOS diff --git a/services/src/audio_policy/server/service/audio_policy_service.cpp b/services/src/audio_policy/server/service/audio_policy_service.cpp index b67c978..a35cec5 100644 --- a/services/src/audio_policy/server/service/audio_policy_service.cpp +++ b/services/src/audio_policy/server/service/audio_policy_service.cpp @@ -618,5 +618,5 @@ DeviceRole AudioPolicyService::GetDeviceRole(const std::string &role) return DeviceRole::DEVICE_ROLE_NONE; } } -} -} +} // namespace AudioStandard +} // namespace OHOS diff --git a/services/src/audio_policy/server/service/config/audio_focus_parser.cpp b/services/src/audio_policy/server/service/config/audio_focus_parser.cpp index 4c09aa6..5373a9a 100644 --- a/services/src/audio_policy/server/service/config/audio_focus_parser.cpp +++ b/services/src/audio_policy/server/service/config/audio_focus_parser.cpp @@ -210,5 +210,5 @@ void AudioFocusParser::ParseAllowedStreams(xmlNode *node, char *curStream) currNode = currNode->next; } } -} -} +} // namespace AudioStandard +} // namespace OHOS diff --git a/services/src/audio_policy/server/service/manager/audio_adapter_manager.cpp b/services/src/audio_policy/server/service/manager/audio_adapter_manager.cpp index f99fd30..3743bb2 100644 --- a/services/src/audio_policy/server/service/manager/audio_adapter_manager.cpp +++ b/services/src/audio_policy/server/service/manager/audio_adapter_manager.cpp @@ -33,6 +33,11 @@ bool AudioAdapterManager::ConnectServiceAdapter() std::unique_ptr audioAdapterManager(this); std::unique_ptr policyCallbackImpl = std::make_unique(audioAdapterManager); mAudioServiceAdapter = AudioServiceAdapter::CreateAudioAdapter(std::move(policyCallbackImpl)); + if (!mAudioServiceAdapter) { + MEDIA_ERR_LOG("[AudioAdapterManager] Error in audio adapter initialization"); + return false; + } + bool result = mAudioServiceAdapter->Connect(); if (!result) { MEDIA_ERR_LOG("[AudioAdapterManager] Error in connecting audio adapter"); @@ -53,6 +58,11 @@ void AudioAdapterManager::InitKVStore() void AudioAdapterManager::Deinit(void) { + if (!mAudioServiceAdapter) { + MEDIA_ERR_LOG("[AudioAdapterManager] audio adapter null"); + return; + } + return mAudioServiceAdapter->Disconnect(); } @@ -69,6 +79,11 @@ int32_t AudioAdapterManager::SetAudioSessionCallback(AudioSessionCallback *callb int32_t AudioAdapterManager::SetStreamVolume(AudioStreamType streamType, float volume) { + if (!mAudioServiceAdapter) { + MEDIA_ERR_LOG("[AudioAdapterManager] audio adapter null"); + return ERR_OPERATION_FAILED; + } + // Incase if KvStore didnot connect during bootup if (mAudioPolicyKvStore == nullptr) { bool isFirstBoot = false; @@ -91,27 +106,52 @@ float AudioAdapterManager::GetStreamVolume(AudioStreamType streamType) int32_t AudioAdapterManager::SetStreamMute(AudioStreamType streamType, bool mute) { + if (!mAudioServiceAdapter) { + MEDIA_ERR_LOG("[AudioAdapterManager] audio adapter null"); + return ERR_OPERATION_FAILED; + } + return mAudioServiceAdapter->SetMute(streamType, mute); } bool AudioAdapterManager::GetStreamMute(AudioStreamType streamType) const { - return mAudioServiceAdapter->IsMute(streamType); + if (!mAudioServiceAdapter) { + MEDIA_ERR_LOG("[AudioAdapterManager] audio adapter null"); + return false; + } + + return mAudioServiceAdapter->IsMute(streamType); } bool AudioAdapterManager::IsStreamActive(AudioStreamType streamType) { + if (!mAudioServiceAdapter) { + MEDIA_ERR_LOG("[AudioAdapterManager] audio adapter null"); + return false; + } + return mAudioServiceAdapter->IsStreamActive(streamType); } int32_t AudioAdapterManager::SuspendAudioDevice(std::string &portName, bool isSuspend) { + if (!mAudioServiceAdapter) { + MEDIA_ERR_LOG("[AudioAdapterManager] audio adapter null"); + return ERR_OPERATION_FAILED; + } + return mAudioServiceAdapter->SuspendAudioDevice(portName, isSuspend); } int32_t AudioAdapterManager::SetDeviceActive(AudioIOHandle ioHandle, InternalDeviceType deviceType, std::string name, bool active) { + if (!mAudioServiceAdapter) { + MEDIA_ERR_LOG("[AudioAdapterManager] audio adapter null"); + return ERR_OPERATION_FAILED; + } + switch (deviceType) { case InternalDeviceType::DEVICE_TYPE_SPEAKER: case InternalDeviceType::DEVICE_TYPE_WIRED_HEADSET: diff --git a/services/src/audio_service/client/audio_manager_proxy.cpp b/services/src/audio_service/client/audio_manager_proxy.cpp index 1a1adcd..51e6c80 100644 --- a/services/src/audio_service/client/audio_manager_proxy.cpp +++ b/services/src/audio_service/client/audio_manager_proxy.cpp @@ -65,7 +65,7 @@ int32_t AudioManagerProxy::GetMinVolume(AudioSystemManager::AudioVolumeType volu return error; } - float volume = reply.ReadInt32(); + int32_t volume = reply.ReadInt32(); return volume; } diff --git a/services/src/audio_service/client/audio_ringtone_manager.cpp b/services/src/audio_service/client/audio_ringtone_manager.cpp index 1155d28..58068ee 100644 --- a/services/src/audio_service/client/audio_ringtone_manager.cpp +++ b/services/src/audio_service/client/audio_ringtone_manager.cpp @@ -187,6 +187,7 @@ void RingtonePlayer::InitialisePlayer() int32_t RingtonePlayer::PrepareRingtonePlayer(bool isReInitNeeded) { MEDIA_INFO_LOG("RingtonePlayer::%{public}s", __func__); + CHECK_AND_RETURN_RET_LOG(player_ != nullptr, ERR_INVALID_PARAM, "Ringtone player instance is null"); // fetch uri from kvstore auto kvstoreUri = audioRingtoneMgr_.GetSystemRingtoneUri(context_, type_); @@ -299,6 +300,8 @@ RingtoneState RingtonePlayer::GetRingtoneState() void RingtonePlayer::SetPlayerState(RingtoneState ringtoneState) { + CHECK_AND_RETURN_LOG(player_ != nullptr, "Ringtone player instance is null"); + if (ringtoneState_ != RingtoneState::STATE_RELEASED) { ringtoneState_ = ringtoneState; } @@ -380,37 +383,37 @@ void RingtonePlayerCallback::OnError(PlayerErrorType errorType, int32_t errorCod void RingtonePlayerCallback::OnInfo(PlayerOnInfoType type, int32_t extra, const Format &infoBody) { - if (type == INFO_TYPE_STATE_CHANGE) { - state_ = static_cast(extra); - - switch (state_) { - case PLAYER_STATE_ERROR: - ringtoneState_ = STATE_INVALID; - break; - case PLAYER_IDLE: - case PLAYER_INITIALIZED: - case PLAYER_PREPARING: - ringtoneState_ = STATE_NEW; - break; - case PLAYER_PREPARED: - ringtoneState_ = STATE_PREPARED; - break; - case PLAYER_STARTED: - ringtoneState_ = STATE_RUNNING; - break; - case PLAYER_PAUSED: - ringtoneState_ = STATE_PAUSED; - break; - case PLAYER_STOPPED: - case PLAYER_PLAYBACK_COMPLETE: - ringtoneState_ = STATE_STOPPED; - break; - default: - break; - } - - ringtonePlayer_.SetPlayerState(ringtoneState_); + if (type != INFO_TYPE_STATE_CHANGE) { + return; } + state_ = static_cast(extra); + + switch (state_) { + case PLAYER_STATE_ERROR: + ringtoneState_ = STATE_INVALID; + break; + case PLAYER_IDLE: + case PLAYER_INITIALIZED: + case PLAYER_PREPARING: + ringtoneState_ = STATE_NEW; + break; + case PLAYER_PREPARED: + ringtoneState_ = STATE_PREPARED; + break; + case PLAYER_STARTED: + ringtoneState_ = STATE_RUNNING; + break; + case PLAYER_PAUSED: + ringtoneState_ = STATE_PAUSED; + break; + case PLAYER_STOPPED: + case PLAYER_PLAYBACK_COMPLETE: + ringtoneState_ = STATE_STOPPED; + break; + default: + break; + } + ringtonePlayer_.SetPlayerState(ringtoneState_); } -} // AudioStandard -} // OHOS +} // namesapce AudioStandard +} // namespace OHOS diff --git a/services/src/audio_service/client/audio_service_client.cpp b/services/src/audio_service/client/audio_service_client.cpp index 002a25f..121b6e0 100644 --- a/services/src/audio_service/client/audio_service_client.cpp +++ b/services/src/audio_service/client/audio_service_client.cpp @@ -135,9 +135,7 @@ pa_sample_spec AudioServiceClient::ConvertToPAAudioParams(AudioStreamParams audi static size_t AlignToAudioFrameSize(size_t l, const pa_sample_spec &ss) { - size_t fs; - - fs = pa_frame_size(&ss); + size_t fs = pa_frame_size(&ss); if (fs == 0) { MEDIA_ERR_LOG(" Error: pa_frame_size returned 0"); return 0; @@ -148,10 +146,11 @@ static size_t AlignToAudioFrameSize(size_t l, const pa_sample_spec &ss) void AudioServiceClient::PAStreamStartSuccessCb(pa_stream *stream, int32_t success, void *userdata) { - if (userdata == nullptr) { - MEDIA_ERR_LOG(" Error: userData is null!"); + if (!userdata) { + MEDIA_ERR_LOG("AudioServiceClient::PAStreamStartSuccessCb: userdata is null"); return; } + AudioServiceClient *asClient = static_cast(userdata); pa_threaded_mainloop *mainLoop = static_cast(asClient->mainLoop); @@ -166,6 +165,11 @@ void AudioServiceClient::PAStreamStartSuccessCb(pa_stream *stream, int32_t succe void AudioServiceClient::PAStreamStopSuccessCb(pa_stream *stream, int32_t success, void *userdata) { + if (!userdata) { + MEDIA_ERR_LOG("AudioServiceClient::PAStreamStopSuccessCb: userdata is null"); + return; + } + AudioServiceClient *asClient = static_cast(userdata); pa_threaded_mainloop *mainLoop = static_cast(asClient->mainLoop); @@ -180,6 +184,11 @@ void AudioServiceClient::PAStreamStopSuccessCb(pa_stream *stream, int32_t succes void AudioServiceClient::PAStreamPauseSuccessCb(pa_stream *stream, int32_t success, void *userdata) { + if (!userdata) { + MEDIA_ERR_LOG("AudioServiceClient::PAStreamPauseSuccessCb: userdata is null"); + return; + } + AudioServiceClient *asClient = static_cast(userdata); pa_threaded_mainloop *mainLoop = static_cast(asClient->mainLoop); @@ -194,6 +203,11 @@ void AudioServiceClient::PAStreamPauseSuccessCb(pa_stream *stream, int32_t succe void AudioServiceClient::PAStreamDrainSuccessCb(pa_stream *stream, int32_t success, void *userdata) { + if (!userdata) { + MEDIA_ERR_LOG("AudioServiceClient::PAStreamDrainSuccessCb: userdata is null"); + return; + } + AudioServiceClient *asClient = (AudioServiceClient *)userdata; pa_threaded_mainloop *mainLoop = (pa_threaded_mainloop *)asClient->mainLoop; @@ -203,6 +217,10 @@ void AudioServiceClient::PAStreamDrainSuccessCb(pa_stream *stream, int32_t succe void AudioServiceClient::PAStreamFlushSuccessCb(pa_stream *stream, int32_t success, void *userdata) { + if (!userdata) { + MEDIA_ERR_LOG("AudioServiceClient::PAStreamFlushSuccessCb: userdata is null"); + return; + } AudioServiceClient *asClient = (AudioServiceClient *)userdata; pa_threaded_mainloop *mainLoop = (pa_threaded_mainloop *)asClient->mainLoop; @@ -218,6 +236,10 @@ void AudioServiceClient::PAStreamReadCb(pa_stream *stream, size_t length, void * void AudioServiceClient::PAStreamSetBufAttrSuccessCb(pa_stream *stream, int32_t success, void *userdata) { + if (!userdata) { + MEDIA_ERR_LOG("AudioServiceClient::PAStreamSetBufAttrSuccessCb: userdata is null"); + return; + } AudioServiceClient *asClient = (AudioServiceClient *)userdata; pa_threaded_mainloop *mainLoop = (pa_threaded_mainloop *)asClient->mainLoop; @@ -282,6 +304,11 @@ int32_t AudioServiceClient::SaveWriteCallback(const std::weak_ptr(userdata); auto mainLoop = static_cast(asClient->mainLoop); pa_threaded_mainloop_signal(mainLoop, 0); @@ -304,6 +331,11 @@ void AudioServiceClient::PAStreamWriteCb(pa_stream *stream, size_t length, void void AudioServiceClient::PAStreamUnderFlowCb(pa_stream *stream, void *userdata) { + if (!userdata) { + MEDIA_ERR_LOG("AudioServiceClient::PAStreamUnderFlowCb: userdata is null"); + return; + } + AudioServiceClient *asClient = (AudioServiceClient *)userdata; asClient->underFlowCount++; } @@ -316,6 +348,11 @@ void AudioServiceClient::PAStreamLatencyUpdateCb(pa_stream *stream, void *userda void AudioServiceClient::PAStreamStateCb(pa_stream *stream, void *userdata) { + if (!userdata) { + MEDIA_ERR_LOG("AudioServiceClient::PAStreamStateCb: userdata is null"); + return; + } + AudioServiceClient *asClient = (AudioServiceClient *)userdata; pa_threaded_mainloop *mainLoop = (pa_threaded_mainloop *)asClient->mainLoop; diff --git a/services/src/audio_service/client/audio_stream.cpp b/services/src/audio_service/client/audio_stream.cpp index 94bbf74..945e21b 100644 --- a/services/src/audio_service/client/audio_stream.cpp +++ b/services/src/audio_service/client/audio_stream.cpp @@ -688,5 +688,5 @@ void AudioStream::WriteBuffers() } MEDIA_INFO_LOG("AudioStream::WriteBuffers thread end"); } -} // namspace AudioStandard +} // namespace AudioStandard } // namespace OHOS diff --git a/services/src/audio_service/client/audio_system_manager.cpp b/services/src/audio_service/client/audio_system_manager.cpp index 72095d9..3e82f33 100644 --- a/services/src/audio_service/client/audio_system_manager.cpp +++ b/services/src/audio_service/client/audio_system_manager.cpp @@ -273,7 +273,7 @@ bool AudioSystemManager::IsStreamMute(AudioSystemManager::AudioVolumeType volume int32_t AudioSystemManager::SetDeviceChangeCallback(const std::shared_ptr &callback) { - MEDIA_ERR_LOG("Entered AudioSystemManager::%{public}s", __func__); + MEDIA_INFO_LOG("Entered AudioSystemManager::%{public}s", __func__); if (callback == nullptr) { MEDIA_ERR_LOG("SetDeviceChangeCallback: callback is nullptr"); return ERR_INVALID_PARAM; diff --git a/services/src/audio_service/server/audio_manager_stub.cpp b/services/src/audio_service/server/audio_manager_stub.cpp index 1813cc6..cfc59a4 100644 --- a/services/src/audio_service/server/audio_manager_stub.cpp +++ b/services/src/audio_service/server/audio_manager_stub.cpp @@ -82,6 +82,8 @@ int AudioManagerStub::OnRemoteRequest( if (size > 0) { MEDIA_DEBUG_LOG("cookie received from server"); reply.WriteRawData(static_cast(cookieInfo), size); + free((void *)cookieInfo); + cookieInfo = nullptr; } return MEDIA_OK; diff --git a/services/src/audio_service/server/audio_server.cpp b/services/src/audio_service/server/audio_server.cpp index 83bc848..73d0a7a 100644 --- a/services/src/audio_service/server/audio_server.cpp +++ b/services/src/audio_service/server/audio_server.cpp @@ -99,8 +99,7 @@ const std::string AudioServer::GetAudioParameter(const std::string &key) if (AudioServer::audioParameters.count(key)) { return AudioServer::audioParameters[key]; } else { - const std::string value = ""; - return value; + return ""; } } @@ -109,19 +108,25 @@ const char *AudioServer::RetrieveCookie(int32_t &size) char *cookieInfo = nullptr; size = 0; std::ifstream cookieFile(DEFAULT_COOKIE_PATH, std::ifstream::binary); - if (cookieFile) { - cookieFile.seekg (0, cookieFile.end); - size = cookieFile.tellg(); - cookieFile.seekg (0, cookieFile.beg); - - if ((size > 0) && (size < PATH_MAX)) { - cookieInfo = (char *)malloc(size * sizeof(char)); - MEDIA_DEBUG_LOG("Reading: %{public}d characters...", size); - cookieFile.read(cookieInfo, size); - } - cookieFile.close(); + if (!cookieFile) { + return cookieInfo; } + cookieFile.seekg (0, cookieFile.end); + size = cookieFile.tellg(); + cookieFile.seekg (0, cookieFile.beg); + + if ((size > 0) && (size < PATH_MAX)) { + cookieInfo = (char *)malloc(size * sizeof(char)); + if (cookieInfo == nullptr) { + MEDIA_ERR_LOG("AudioServer::RetrieveCookie: No memory"); + cookieFile.close(); + return cookieInfo; + } + MEDIA_DEBUG_LOG("Reading: %{public}d characters...", size); + cookieFile.read(cookieInfo, size); + } + cookieFile.close(); return cookieInfo; } diff --git a/services/test/audio_interrupt_test.cpp b/services/test/audio_interrupt_test.cpp index 38b8563..708eebd 100644 --- a/services/test/audio_interrupt_test.cpp +++ b/services/test/audio_interrupt_test.cpp @@ -260,8 +260,8 @@ void AudioInterruptTest::SaveStreamInfo(ContentType contentType, StreamUsage str contentType_ = contentType; streamUsage_ = streamUsage; } -} // AudioStandard -} // OHOS +} // namespace AudioStandard +} // namespace OHOS using namespace OHOS; using namespace OHOS::AudioStandard; diff --git a/services/test/audio_interrupt_test.h b/services/test/audio_interrupt_test.h index ac1f5d9..5ece5fe 100644 --- a/services/test/audio_interrupt_test.h +++ b/services/test/audio_interrupt_test.h @@ -50,6 +50,6 @@ private: ContentType contentType_ = ContentType::CONTENT_TYPE_MUSIC; StreamUsage streamUsage_ = StreamUsage::STREAM_USAGE_MEDIA; }; -} // AudioStandard -} // OHOS +} // namespace AudioStandard +} // namespace OHOS #endif // AUDIO_INTERRUPT_TEST_H \ No newline at end of file diff --git a/services/test/interrupt_multi_renderer_test.cpp b/services/test/interrupt_multi_renderer_test.cpp index 9df589d..6295c11 100644 --- a/services/test/interrupt_multi_renderer_test.cpp +++ b/services/test/interrupt_multi_renderer_test.cpp @@ -286,8 +286,8 @@ int32_t InterruptMultiRendererTest::TestPlayback(int argc, char *argv[]) const return 0; } -} // AudioStandard -} // OHOS +} // namespace AudioStandard +} // namespace OHOS using namespace OHOS; using namespace OHOS::AudioStandard; diff --git a/services/test/interrupt_multi_renderer_test.h b/services/test/interrupt_multi_renderer_test.h index 79dbbda..9731b4f 100644 --- a/services/test/interrupt_multi_renderer_test.h +++ b/services/test/interrupt_multi_renderer_test.h @@ -39,6 +39,6 @@ private: const std::shared_ptr &cb) const; int32_t ValidateFile(char *filePath, char path[]) const; }; -} // AudioStandard -} // OHOS +} // namespace AudioStandard +} // namespace OHOS #endif // INTERRUPT_MULTI_RENDERER_TEST_H diff --git a/test/moduletest/audiopolicy/1.0/include/audio_policy_test.h b/test/moduletest/audiopolicy/1.0/include/audio_policy_test.h index a7ab2a1..4199689 100644 --- a/test/moduletest/audiopolicy/1.0/include/audio_policy_test.h +++ b/test/moduletest/audiopolicy/1.0/include/audio_policy_test.h @@ -62,7 +62,7 @@ public: // TearDown: Called after each test cases void TearDown(void) override; }; -} -} -} +} // namespace V1_0 +} // namespace AudioStandard +} // namespace OHOS #endif // AUDIO_POLICY_TEST_H diff --git a/test/moduletest/audiopolicy/1.0/src/audio_policy_test.cpp b/test/moduletest/audiopolicy/1.0/src/audio_policy_test.cpp index af2722e..7726289 100644 --- a/test/moduletest/audiopolicy/1.0/src/audio_policy_test.cpp +++ b/test/moduletest/audiopolicy/1.0/src/audio_policy_test.cpp @@ -563,6 +563,6 @@ INSTANTIATE_TEST_CASE_P( GetAudioScene, AudioPolicyGetAudioSceneTest, ValuesIn(AUDIO_SCENE_PARAMS)); -} // V1_0 -} // AudioStandard -} // OHOS +} // namespace V1_0 +} // namespace AudioStandard +} // namespace OHOS