diff --git a/model/audio/common/include/audio_platform_base.h b/model/audio/common/include/audio_platform_base.h index 2b605e4f..a8f150a2 100644 --- a/model/audio/common/include/audio_platform_base.h +++ b/model/audio/common/include/audio_platform_base.h @@ -60,49 +60,12 @@ struct CircleBufInfo { uint32_t curTrafSize; /* The size of each actual transmission of PCM data */ }; -/* head file: pnp_message_report */ -enum PnpReportType { - DEVICE_PULG, - EVENT_REPORT, - REPORT_TYPE_INVALID -}; +#define HDF_AUDIO_CAPTURE_THRESHOLD (0x9) +#define HDF_AUDIO_PRIMARY_DEVICE (0x80) -enum PnpEventID { - THRESHOLD_REPORT, - LOAD_ADAPTER, - SERVICE_STATUS, - EVENT_ID_INVALID -}; - -enum PnpDeviceType { - PRIMARY_DEVICE, - USB_DEVICE, - A2DP_DEVICE, - DEVICE_TYPE_INVALID -}; - -struct PnpReportDevPlugMsg { - uint8_t eventType; - uint8_t state; - uint8_t deviceType; - uint8_t deviceCap; - uint8_t id; -}; - -struct PnpReportEventMsg { - uint8_t eventType; - uint8_t eventId; - uint8_t eventValue; - uint8_t deviceType; - uint8_t reserve; /* Reserved fields are not used for the time being */ -}; - -struct PnpReportMsg { - enum PnpReportType reportType; - union { - struct PnpReportDevPlugMsg devPlugMsg; - struct PnpReportEventMsg eventMsg; - }; +struct AudioEvent { + uint32_t eventType; + uint32_t deviceType; }; unsigned int SysReadl(unsigned long addr); @@ -129,7 +92,7 @@ int32_t AudioRenderPrepare(const struct AudioCard *card); int32_t AudioCapturePrepare(const struct AudioCard *card); int32_t AudioRenderTrigger(struct AudioCard *card, int cmd); int32_t AudioCaptureTrigger(struct AudioCard *card, int cmd); -int32_t AudioCapSilenceThresholdEvent(struct HdfDeviceObject *device, const struct PnpReportMsg *reportMsg); +int32_t AudioCapSilenceThresholdEvent(struct HdfDeviceObject *device, const struct AudioEvent *reportMsg); #ifdef __cplusplus #if __cplusplus diff --git a/model/audio/common/src/audio_platform_base.c b/model/audio/common/src/audio_platform_base.c index b509996d..504507d8 100755 --- a/model/audio/common/src/audio_platform_base.c +++ b/model/audio/common/src/audio_platform_base.c @@ -23,7 +23,7 @@ const int RENDER_TRAF_BUF_SIZE = 1024; const int MIN_BUFF_SIZE = 16 * 1024; const int TIME_OUT_CONST = 50; const int SLEEP_TIME = 5; -#define PNP_REPORT_MSG_LEN 32 +#define AUDIO_PNP_MSG_LEN 256 #define INTERLEAVED 1 const int MIN_PERIOD_SILENCE_THRESHOLD = (4 * 1024); const int MAX_PERIOD_SILENCE_THRESHOLD = (16 * 1024); @@ -1194,84 +1194,33 @@ int32_t AudioPcmPointer(const struct AudioCard *card, uint32_t *pointer, enum Au return HDF_SUCCESS; } -static int32_t PnpReportMsgConvert(const struct PnpReportMsg *pnpReportMsg, char *msgBuf, const uint32_t bufLen) +int32_t AudioCapSilenceThresholdEvent(struct HdfDeviceObject *device, const struct AudioEvent *reportMsg) { int ret; - if (pnpReportMsg == NULL || msgBuf == NULL || bufLen < PNP_REPORT_MSG_LEN) { - AUDIO_DRIVER_LOG_ERR("Parameter error!"); - return HDF_FAILURE; - } - - switch (pnpReportMsg->reportType) { - case DEVICE_PULG: - ret = snprintf_s(msgBuf, bufLen, bufLen - 1, "%d;%d;%d;%d;%d", - pnpReportMsg->devPlugMsg.eventType, pnpReportMsg->devPlugMsg.state, - pnpReportMsg->devPlugMsg.deviceType, pnpReportMsg->devPlugMsg.deviceCap, - pnpReportMsg->devPlugMsg.id); - if (ret < 0) { - AUDIO_DRIVER_LOG_ERR("snprintf_s failed"); - return HDF_ERR_IO; - } - break; - case EVENT_REPORT: - ret = snprintf_s(msgBuf, bufLen, bufLen - 1, "%d;%d;%d;%d;%d", - pnpReportMsg->eventMsg.eventType, pnpReportMsg->eventMsg.eventId, - pnpReportMsg->eventMsg.eventValue, pnpReportMsg->eventMsg.deviceType, - pnpReportMsg->eventMsg.reserve); - if (ret < 0) { - AUDIO_DRIVER_LOG_ERR("snprintf_s failed"); - return HDF_ERR_IO; - } - break; - default: - AUDIO_DRIVER_LOG_ERR("Unknown message type!"); - return HDF_FAILURE; - } - - return HDF_SUCCESS; -} - -int32_t AudioCapSilenceThresholdEvent(struct HdfDeviceObject *device, const struct PnpReportMsg *reportMsg) -{ - int ret; - char *msgBuf = NULL; + char msgBuf[AUDIO_PNP_MSG_LEN] = {0}; if (device == NULL || reportMsg == NULL) { ADM_LOG_ERR("device is NULL!"); return HDF_ERR_INVALID_PARAM; } - if (!HdfDeviceSetClass(device, DEVICE_CLASS_AUDIO)) { - ADM_LOG_ERR("set audio class failed."); + + ret = snprintf_s(msgBuf, AUDIO_PNP_MSG_LEN, AUDIO_PNP_MSG_LEN - 1, + "EVENT_TYPE=0x%x;DEVICE_TYPE=0x%x", reportMsg->eventType, reportMsg->deviceType); + if (ret < 0) { + ADM_LOG_ERR("snprintf_s fail"); return HDF_FAILURE; } - - msgBuf = (char *)OsalMemCalloc(PNP_REPORT_MSG_LEN); - if (msgBuf == NULL) { - ADM_LOG_ERR("Malloc memory failed!"); - return HDF_FAILURE; - } - - ret = PnpReportMsgConvert(reportMsg, msgBuf, PNP_REPORT_MSG_LEN); - if (ret != HDF_SUCCESS) { - ADM_LOG_ERR("PnpReportMsgConvert fail"); - OsalMemFree(msgBuf); - return HDF_FAILURE; - } - if (HdfDeviceObjectSetServInfo(device, msgBuf) != HDF_SUCCESS) { ADM_LOG_ERR("HdfDeviceObjectSetServInfo fail!"); - OsalMemFree(msgBuf); return HDF_FAILURE; } ret = HdfDeviceObjectUpdate(device); if (ret != HDF_SUCCESS) { ADM_LOG_ERR("HdfDeviceObjectUpdate fail\n"); - OsalMemFree(msgBuf); return HDF_FAILURE; } - OsalMemFree(msgBuf); return HDF_SUCCESS; } diff --git a/model/audio/core/src/audio_host.c b/model/audio/core/src/audio_host.c index 59f09a2e..89ceaa0a 100644 --- a/model/audio/core/src/audio_host.c +++ b/model/audio/core/src/audio_host.c @@ -355,20 +355,12 @@ static int32_t AudioDriverBind(struct HdfDeviceObject *device) return HDF_SUCCESS; } -static int32_t AudioDriverInit(struct HdfDeviceObject *device) +static int32_t AudioCardInit(struct HdfDeviceObject *device, struct AudioHost *audioHost) { - struct AudioCard *audioCard = NULL; - struct AudioHost *audioHost = NULL; int32_t ret; - - ADM_LOG_DEBUG("entry."); - if (device == NULL) { - ADM_LOG_ERR("device is NULL."); - return HDF_ERR_INVALID_OBJECT; - } - audioHost = (struct AudioHost *)device->service; - if (audioHost == NULL) { - ADM_LOG_ERR("audioHost is NULL."); + struct AudioCard *audioCard = NULL; + if (device == NULL || audioHost == NULL) { + ADM_LOG_ERR("device or audioHost is NULL."); return HDF_FAILURE; } @@ -414,6 +406,27 @@ static int32_t AudioDriverInit(struct HdfDeviceObject *device) /* sound card added to list */ DListInsertHead(&audioCard->list, &cardManager); + return HDF_SUCCESS; +} + +static int32_t AudioDriverInit(struct HdfDeviceObject *device) +{ + struct AudioHost *audioHost = NULL; + + ADM_LOG_DEBUG("entry."); + if (device == NULL) { + ADM_LOG_ERR("device is NULL."); + return HDF_ERR_INVALID_OBJECT; + } + if (!HdfDeviceSetClass(device, DEVICE_CLASS_AUDIO)) { + ADM_LOG_ERR("set audio class failed."); + return HDF_FAILURE; + } + audioHost = (struct AudioHost *)device->service; + if (AudioCardInit(device, audioHost) != HDF_SUCCESS) { + ADM_LOG_ERR("set audio class failed."); + return HDF_FAILURE; + } ADM_LOG_INFO("success."); return HDF_SUCCESS; }