diff --git a/audio/BUILD.gn b/audio/BUILD.gn index 685cc9b7a4d8236b4a2bc0ed3e937d7d3ef97cf9..ecbbed3f01c519b50c393ce07410c3380ba79c43 100644 --- a/audio/BUILD.gn +++ b/audio/BUILD.gn @@ -28,9 +28,9 @@ group("hdi_audio") { deps += [ "hal/hdi_binder/proxy:hdi_audio_client", "hal/hdi_binder/server:hdi_audio_a2dp_server", - "hal/hdi_binder/server:hdi_audio_pnp_server", "hal/hdi_binder/server:hdi_audio_primary_server", "hal/hdi_binder/server:hdi_audio_usb_server", + "hdi_service/event:hdi_audio_pnp_server", ] } deps += [ "hdi_service:idl_audio" ] diff --git a/audio/hal/hdi_binder/server/BUILD.gn b/audio/hal/hdi_binder/server/BUILD.gn index 49ab49adb1d731eed0888194700c31177717ea05..e6c0f5977fd1ec1f6a5eac7862dbf1252616a714 100644 --- a/audio/hal/hdi_binder/server/BUILD.gn +++ b/audio/hal/hdi_binder/server/BUILD.gn @@ -132,42 +132,4 @@ if (drivers_peripheral_audio_feature_hdf_proxy_stub == true) { subsystem_name = "hdf" part_name = "drivers_peripheral_audio" } - - ohos_shared_library("hdi_audio_pnp_server") { - include_dirs = [ - "include", - "$hdf_hal_path/hdi_passthrough/include", - "$hdf_audio_path/interfaces/include", - "//third_party/bounds_checking_function/include", - ] - - sources = [ - "src/hdf_audio_input_event.c", - "src/hdf_audio_pnp_server.c", - "src/hdf_audio_pnp_uevent.c", - "src/hdf_audio_pnp_uevent_hdmi.c", - ] - - if (is_standard_system) { - external_deps = [ - "c_utils:utils", - "hdf_core:libhdf_host", - "hdf_core:libhdf_ipc_adapter", - "hdf_core:libhdf_utils", - "hdf_core:libhdi", - "hiviewdfx_hilog_native:libhilog", - ] - } else { - external_deps = [ "hilog:libhilog" ] - } - defines = [] - if (enable_audio_hal_hdf_log) { - defines += [ "AUDIO_HDF_LOG" ] - } - - shlib_type = "hdi" - install_images = [ chipset_base_dir ] - subsystem_name = "hdf" - part_name = "drivers_peripheral_audio" - } } diff --git a/audio/hal/hdi_binder/server/include/hdf_audio_pnp_server.h b/audio/hal/hdi_binder/server/include/hdf_audio_pnp_server.h index e4f2dcefd535b2978d149c8399b6d8f9f4e49b08..5eee573d136705d09b684ae9cb44ac016c30c21e 100644 --- a/audio/hal/hdi_binder/server/include/hdf_audio_pnp_server.h +++ b/audio/hal/hdi_binder/server/include/hdf_audio_pnp_server.h @@ -16,19 +16,16 @@ #ifndef HDF_AUDIO_PNP_SERVER_H #define HDF_AUDIO_PNP_SERVER_H -#include "audio_events.h" +#include "v1_0/audio_types.h" #include "hdf_types.h" #ifdef __cplusplus extern "C" { #endif -int32_t AudioPnpStatusSend(const char *serverName, - const char *tokenServerName, const char *pnpInfo, const int cmd); /* statusInfo is update new info */ int32_t AudioPnpUpdateInfo(const char *statusInfo); int32_t AudioPnpUpdateInfoOnly(struct AudioEvent audioEvent); -int32_t AudioPnpUpdateAndSend(struct AudioEvent audioEvent); int32_t AudioUhdfUnloadDriver(const char *driverName); int32_t AudioUhdfLoadDriver(const char *driverName); diff --git a/audio/hal/hdi_binder/server/src/hdf_audio_input_event.c b/audio/hal/hdi_binder/server/src/hdf_audio_input_event.c index 6a46aa937b69861c458d231eaa6a531ed43ddd73..d9528546e6ade9b0ad0a9107ed89c4fbe9f578ad 100644 --- a/audio/hal/hdi_binder/server/src/hdf_audio_input_event.c +++ b/audio/hal/hdi_binder/server/src/hdf_audio_input_event.c @@ -36,17 +36,17 @@ static int32_t AudioAnalogHeadsetDeviceCheck(struct input_event evt) struct AudioEvent audioEvent; AUDIO_FUNC_LOGI("enter."); - audioEvent.eventType = (evt.value == 0) ? HDF_AUDIO_DEVICE_REMOVE : HDF_AUDIO_DEVICE_ADD; - audioEvent.deviceType = HDF_AUDIO_DEVICE_UNKOWN; + audioEvent.eventType = (evt.value == 0) ? AUDIO_DEVICE_REMOVE : AUDIO_DEVICE_ADD; + audioEvent.deviceType = AUDIO_DEVICE_UNKNOWN; switch (evt.code) { case SW_HEADPHONE_INSERT: - audioEvent.deviceType = HDF_AUDIO_HEADPHONE; + audioEvent.deviceType = AUDIO_HEADPHONE; break; case SW_MICROPHONE_INSERT: - audioEvent.deviceType = HDF_AUDIO_HEADSET; + audioEvent.deviceType = AUDIO_HEADSET; break; case SW_LINEOUT_INSERT: - audioEvent.deviceType = HDF_AUDIO_LINEOUT; + audioEvent.deviceType = AUDIO_LINEOUT; break; default: // SW_JACK_PHYSICAL_INSERT = 0x7, SW_LINEIN_INSERT = 0xd and other. AUDIO_FUNC_LOGE("n't surpport code =0x%{public}x\n", evt.code); diff --git a/audio/hal/hdi_binder/server/src/hdf_audio_pnp_server.c b/audio/hal/hdi_binder/server/src/hdf_audio_pnp_server.c index bde1dca184d55dd2db67135aa4a8aa559c1271c5..68e17d83505bbdf672bb28acdbf99a83ca5297a6 100644 --- a/audio/hal/hdi_binder/server/src/hdf_audio_pnp_server.c +++ b/audio/hal/hdi_binder/server/src/hdf_audio_pnp_server.c @@ -18,7 +18,6 @@ #include "hdf_audio_input_event.h" #include "hdf_audio_pnp_uevent.h" #include "hdf_audio_pnp_uevent_hdmi.h" -#include "hdf_audio_server.h" #include "hdf_device_desc.h" #include "hdf_device_object.h" #include "hdf_io_service_if.h" @@ -37,60 +36,6 @@ static struct HdfDeviceObject *g_audioPnpDevice = NULL; -int32_t AudioPnpStatusSend(const char *serverName, const char *tokenServerName, const char *pnpInfo, const int cmd) -{ - if (serverName == NULL || tokenServerName == NULL || pnpInfo == NULL) { - AUDIO_FUNC_LOGE("serverName is null!"); - return HDF_ERR_INVALID_PARAM; - } - - struct HDIServiceManager *servmgr = HDIServiceManagerGet(); - if (servmgr == NULL) { - AUDIO_FUNC_LOGE("get all service failed!"); - return HDF_FAILURE; - } - - struct HdfRemoteService *hdiAudioService = servmgr->GetService(servmgr, serverName); - HDIServiceManagerRelease(servmgr); - if (hdiAudioService == NULL || hdiAudioService->dispatcher == NULL) { - AUDIO_FUNC_LOGE("get %{public}s not exist!", serverName); - return HDF_FAILURE; - } - - if (!HdfRemoteServiceSetInterfaceDesc(hdiAudioService, tokenServerName)) { - AUDIO_FUNC_LOGE("SetInterfaceDesc %{public}s failed! ", tokenServerName); - HdfRemoteServiceRecycle(hdiAudioService); - return HDF_FAILURE; - } - - struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC); - if (data == NULL) { - AUDIO_FUNC_LOGE("sbuf data malloc failed!"); - return HDF_FAILURE; - } - - if (!HdfRemoteServiceWriteInterfaceToken(hdiAudioService, data)) { - AUDIO_FUNC_LOGE("write token failed!"); - HdfSbufRecycle(data); - return HDF_FAILURE; - } - - if (!HdfSbufWriteString(data, pnpInfo)) { - HdfSbufRecycle(data); - AUDIO_FUNC_LOGE("sbuf write failed!"); - return HDF_FAILURE; - } - - int ret = hdiAudioService->dispatcher->Dispatch(hdiAudioService, cmd, data, NULL); - HdfSbufRecycle(data); - if (ret != HDF_SUCCESS) { - AUDIO_FUNC_LOGE("%{public}s cmd(%{public}d) dispatch failed! ret = %{public}d", serverName, cmd, ret); - return HDF_FAILURE; - } - - return HDF_SUCCESS; -} - int32_t AudioPnpUpdateInfo(const char *statusInfo) { if (g_audioPnpDevice == NULL) { @@ -136,33 +81,6 @@ int32_t AudioPnpUpdateInfoOnly(struct AudioEvent audioEvent) return HDF_SUCCESS; } -int32_t AudioPnpUpdateAndSend(struct AudioEvent audioEvent) -{ - int32_t ret; - char pnpInfo[AUDIO_PNP_INFO_LEN_MAX] = {0}; - - ret = snprintf_s(pnpInfo, AUDIO_PNP_INFO_LEN_MAX, AUDIO_PNP_INFO_LEN_MAX - 1, "EVENT_TYPE=%u;DEVICE_TYPE=%u", - audioEvent.eventType, audioEvent.deviceType); - if (ret < 0) { - AUDIO_FUNC_LOGE("snprintf_s fail!"); - return HDF_FAILURE; - } - - ret = AudioPnpUpdateInfo(pnpInfo); - if (ret != HDF_SUCCESS) { - AUDIO_FUNC_LOGE("update info fail! ret = %{public}d", ret); - return HDF_FAILURE; - } - - ret = AudioPnpStatusSend(AUDIO_HDI_SERVICE_NAME, AUDIO_TOKEN_SERVER_NAME, pnpInfo, AUDIO_HDI_PNP_DEV_STATUS); - if (ret != HDF_SUCCESS) { - return HDF_FAILURE; - } - AUDIO_FUNC_LOGD("Audio uevent:%{public}s", pnpInfo); - - return HDF_SUCCESS; -} - static int32_t HdfAudioPnpBind(struct HdfDeviceObject *device) { AUDIO_FUNC_LOGI("enter."); diff --git a/audio/hal/hdi_binder/server/src/hdf_audio_pnp_uevent.c b/audio/hal/hdi_binder/server/src/hdf_audio_pnp_uevent.c index edaeda547d3d6877d1393a9f04755b13c2e08a42..5ae0f15b2e15fe066d55dad4f0a4b3372bff6282 100644 --- a/audio/hal/hdi_binder/server/src/hdf_audio_pnp_uevent.c +++ b/audio/hal/hdi_binder/server/src/hdf_audio_pnp_uevent.c @@ -103,8 +103,8 @@ struct AudioPnpUevent { }; struct AudioEvent g_audioPnpDeviceState = { - .eventType = HDF_AUDIO_EVENT_UNKOWN, - .deviceType = HDF_AUDIO_DEVICE_UNKOWN, + .eventType = AUDIO_EVENT_UNKNOWN, + .deviceType = AUDIO_DEVICE_UNKNOWN, }; static bool IsUpdatePnpDeviceState(struct AudioEvent *pnpDeviceEvent) @@ -230,11 +230,11 @@ static int32_t DetectAnalogHeadsetState(struct AudioEvent *audioEvent) AUDIO_FUNC_LOGI("audio switch state = %{public}c", state); if (state == '0') { - audioEvent->eventType = HDF_AUDIO_DEVICE_REMOVE; - audioEvent->deviceType = HDF_AUDIO_HEADSET; + audioEvent->eventType = AUDIO_DEVICE_REMOVE; + audioEvent->deviceType = AUDIO_HEADSET; } else { - audioEvent->eventType = HDF_AUDIO_DEVICE_ADD; - audioEvent->deviceType = HDF_AUDIO_HEADSET; + audioEvent->eventType = AUDIO_DEVICE_ADD; + audioEvent->deviceType = AUDIO_HEADSET; } (void)fclose(fp); @@ -419,8 +419,8 @@ static int32_t DetectUsbHeadsetState(struct AudioEvent *audioEvent) state = ScanUsbBusSubDir(subDir); if (state == AUDIO_DEVICE_ONLINE) { - audioEvent->eventType = HDF_AUDIO_DEVICE_ADD; - audioEvent->deviceType = HDF_AUDIO_USB_HEADSET; + audioEvent->eventType = AUDIO_DEVICE_ADD; + audioEvent->deviceType = AUDIO_USB_HEADSET; closedir(busDir); return HDF_SUCCESS; } @@ -456,19 +456,19 @@ static int32_t AudioUsbHeadsetDetectDevice(struct AudioPnpUevent *audioPnpUevent AUDIO_FUNC_LOGW("check audio usb device not exist, not add"); return HDF_ERR_INVALID_PARAM; } - audioEvent.eventType = HDF_AUDIO_DEVICE_ADD; + audioEvent.eventType = AUDIO_DEVICE_ADD; } else if (strcmp(audioPnpUevent->action, UEVENT_ACTION_REMOVE) == 0) { if (!DeleteAudioUsbDevice(audioPnpUevent->devName)) { AUDIO_FUNC_LOGW("check audio usb device[%{public}s] not exist, not delete", audioPnpUevent->devName); return HDF_ERR_INVALID_PARAM; } - audioEvent.eventType = HDF_AUDIO_DEVICE_REMOVE; + audioEvent.eventType = AUDIO_DEVICE_REMOVE; } else { return HDF_FAILURE; } - audioEvent.deviceType = HDF_AUDIO_USB_HEADSET; - AUDIO_FUNC_LOGI("audio usb headset [%{public}s]", audioEvent.eventType == HDF_AUDIO_DEVICE_ADD ? "add" : "removed"); + audioEvent.deviceType = AUDIO_USB_HEADSET; + AUDIO_FUNC_LOGI("audio usb headset [%{public}s]", audioEvent.eventType == AUDIO_DEVICE_ADD ? "add" : "removed"); if (!IsUpdatePnpDeviceState(&audioEvent)) { AUDIO_FUNC_LOGI("audio usb device[%{public}u] state[%{public}u] not need flush !", audioEvent.deviceType, @@ -489,20 +489,23 @@ static int32_t AudioAnalogHeadsetDetectDevice(struct AudioPnpUevent *audioPnpUev } if (strncmp(audioPnpUevent->subSystem, UEVENT_SUBSYSTEM_SWITCH, strlen(UEVENT_SUBSYSTEM_SWITCH)) == 0) { - static uint32_t h2wTypeLast = HDF_AUDIO_HEADSET; + static uint32_t h2wTypeLast = AUDIO_HEADSET; if (strncmp(audioPnpUevent->switchName, UEVENT_SWITCH_NAME_H2W, strlen(UEVENT_SWITCH_NAME_H2W)) != 0) { AUDIO_FUNC_LOGE("the switch name of 'h2w' not found!"); return HDF_FAILURE; } if (audioPnpUevent->switchState[0] == '0') { - audioEvent.eventType = HDF_AUDIO_DEVICE_REMOVE; + audioEvent.eventType = AUDIO_DEVICE_REMOVE; audioEvent.deviceType = h2wTypeLast; } else if ((audioPnpUevent->switchState[0] == '1') || (audioPnpUevent->switchState[0] == '2')) { - audioEvent.eventType = HDF_AUDIO_DEVICE_ADD; - audioEvent.deviceType = HDF_AUDIO_HEADSET; + audioEvent.eventType = AUDIO_DEVICE_ADD; + audioEvent.deviceType = AUDIO_HEADSET; + } else if (audioPnpUevent->switchState[0] == '4'){ + audioEvent.eventType = AUDIO_DEVICE_ADD; + audioEvent.deviceType = AUDIO_ADAPTER_DEVICE; } else { - audioEvent.eventType = HDF_AUDIO_DEVICE_ADD; - audioEvent.deviceType = HDF_AUDIO_DEVICE_UNKOWN; + audioEvent.eventType = AUDIO_DEVICE_ADD; + audioEvent.deviceType = AUDIO_DEVICE_UNKNOWN; } h2wTypeLast = audioEvent.deviceType; } else { @@ -516,18 +519,18 @@ static int32_t AudioAnalogHeadsetDetectDevice(struct AudioPnpUevent *audioPnpUev return HDF_FAILURE; } if (strstr(audioPnpUevent->state, UEVENT_STATE_ANALOG_HS0) != NULL) { - audioEvent.eventType = HDF_AUDIO_DEVICE_REMOVE; + audioEvent.eventType = AUDIO_DEVICE_REMOVE; } else if (strstr(audioPnpUevent->state, UEVENT_STATE_ANALOG_HS1) != NULL) { - audioEvent.eventType = HDF_AUDIO_DEVICE_ADD; + audioEvent.eventType = AUDIO_DEVICE_ADD; } else { return HDF_FAILURE; } - audioEvent.deviceType = HDF_AUDIO_HEADSET; + audioEvent.deviceType = AUDIO_HEADSET; } AUDIO_FUNC_LOGI("audio analog [%{public}s][%{public}s]", - audioEvent.deviceType == HDF_AUDIO_HEADSET ? "headset" : "headphone", - audioEvent.eventType == HDF_AUDIO_DEVICE_ADD ? "add" : "removed"); + audioEvent.deviceType == AUDIO_HEADSET ? "headset" : "headphone", + audioEvent.eventType == AUDIO_DEVICE_ADD ? "add" : "removed"); if (!IsUpdatePnpDeviceState(&audioEvent)) { AUDIO_FUNC_LOGI("audio analog device[%{public}u] state[%{public}u] not need flush !", audioEvent.deviceType, @@ -683,15 +686,15 @@ void DetectAudioDevice(struct HdfDeviceObject *device) OsalMSleep(AUDIO_DEVICE_WAIT_USB_ONLINE); // Wait until the usb node is successfully created ret = DetectAnalogHeadsetState(&audioEvent); - if ((ret == HDF_SUCCESS) && (audioEvent.eventType == HDF_AUDIO_DEVICE_ADD)) { + if ((ret == HDF_SUCCESS) && (audioEvent.eventType == AUDIO_DEVICE_ADD)) { AUDIO_FUNC_LOGI("audio detect analog headset"); goto FINISH; } - audioEvent.eventType = HDF_AUDIO_EVENT_UNKOWN; - audioEvent.deviceType = HDF_AUDIO_DEVICE_UNKOWN; + audioEvent.eventType = AUDIO_EVENT_UNKNOWN; + audioEvent.deviceType = AUDIO_DEVICE_UNKNOWN; ret = DetectUsbHeadsetState(&audioEvent); - if ((ret == HDF_SUCCESS) && (audioEvent.eventType == HDF_AUDIO_DEVICE_ADD)) { + if ((ret == HDF_SUCCESS) && (audioEvent.eventType == AUDIO_DEVICE_ADD)) { AUDIO_FUNC_LOGI("audio detect usb headset"); goto FINISH; } diff --git a/audio/hal/hdi_binder/server/src/hdf_audio_pnp_uevent_hdmi.c b/audio/hal/hdi_binder/server/src/hdf_audio_pnp_uevent_hdmi.c index 9a4576d14a4f4c0f718b371da7b71044097428c1..ed1eb2a6d0a9e3b986b476cf677e0d35b6a5df9b 100644 --- a/audio/hal/hdi_binder/server/src/hdf_audio_pnp_uevent_hdmi.c +++ b/audio/hal/hdi_binder/server/src/hdf_audio_pnp_uevent_hdmi.c @@ -27,7 +27,6 @@ #include #include "audio_uhdf_log.h" #include "hdf_audio_pnp_server.h" -#include "hdf_audio_server_common.h" #include "hdf_base.h" #include "hdf_io_service.h" #include "osal_time.h" @@ -60,13 +59,13 @@ static int32_t AudioHdmiPnpUeventStatus(const char *statusStr, bool isPnp) struct AudioEvent audioEvent; if (strncmp(statusStr, UEVENT_HDMI_STATE_PLUG, strlen(UEVENT_HDMI_STATE_PLUG)) == 0) { - audioEvent.eventType = HDF_AUDIO_DEVICE_ADD; + audioEvent.eventType = AUDIO_DEVICE_ADD; if (AudioUhdfLoadDriver(AUDIO_HDMI_CARD_NAME) != HDF_SUCCESS) { AUDIO_FUNC_LOGW("AudioUhdfLoadDriver Failed"); } AUDIO_FUNC_LOGI("An HDMI device is plugged in"); } else if (strncmp(statusStr, UEVENT_HDMI_STATE_REMV, strlen(UEVENT_HDMI_STATE_REMV)) == 0) { - audioEvent.eventType = HDF_AUDIO_DEVICE_REMOVE; + audioEvent.eventType = AUDIO_DEVICE_REMOVE; if (AudioUhdfUnloadDriver(AUDIO_HDMI_CARD_NAME) != HDF_SUCCESS) { AUDIO_FUNC_LOGW("AudioUhdfUnloadDriver Failed"); } @@ -76,7 +75,7 @@ static int32_t AudioHdmiPnpUeventStatus(const char *statusStr, bool isPnp) return HDF_FAILURE; } - audioEvent.deviceType = HDF_AUDIO_HDMI_DEVICE; + audioEvent.deviceType = AUDIO_HDMI_DEVICE; if (isPnp) { return AudioPnpUpdateInfoOnly(audioEvent); } diff --git a/audio/hdi_service/event/BUILD.gn b/audio/hdi_service/event/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..cf3ed9deb6cc141e5d6f80439718cafcd400ad89 --- /dev/null +++ b/audio/hdi_service/event/BUILD.gn @@ -0,0 +1,59 @@ +# Copyright (c) 2023 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. + +hdf_audio_path = "./../.." +hdf_hdi_service_path = "./.." +import("//build/ohos.gni") +import("$hdf_audio_path/audio.gni") + +if (drivers_peripheral_audio_feature_hdf_proxy_stub == true) { + ohos_shared_library("hdi_audio_pnp_server") { + sources = [ + "$hdf_audio_path/hal/hdi_binder/server/src/hdf_audio_input_event.c", + "$hdf_audio_path/hal/hdi_binder/server/src/hdf_audio_pnp_server.c", + "$hdf_audio_path/hal/hdi_binder/server/src/hdf_audio_pnp_uevent.c", + "$hdf_audio_path/hal/hdi_binder/server/src/hdf_audio_pnp_uevent_hdmi.c", + ] + + include_dirs = [ + "$hdf_audio_path/hal/hdi_binder/server/include", + "$hdf_hdi_service_path/primary_impl/include", + "$hdf_hdi_service_path/vendor_interface/utils", + "//third_party/bounds_checking_function/include", + ] + + defines = [] + if (enable_audio_hal_hdf_log) { + defines += [ "AUDIO_HDF_LOG" ] + } + + if (is_standard_system) { + external_deps = [ + "c_utils:utils", + "drivers_interface_audio:audio_idl_headers", + "hdf_core:libhdf_host", + "hdf_core:libhdf_ipc_adapter", + "hdf_core:libhdf_utils", + "hdf_core:libhdi", + "hiviewdfx_hilog_native:libhilog", + ] + } else { + external_deps = [ "hilog:libhilog" ] + } + + shlib_type = "hdi" + install_images = [ chipset_base_dir ] + subsystem_name = "hdf" + part_name = "drivers_peripheral_audio" + } +}