From 696ab363733fdadafd09406857f49a7947b55035 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Thu, 5 Jan 2023 09:14:59 +0800 Subject: [PATCH] format code with amazon rules Signed-off-by: Alex Li --- source/C302/C302AudioCapturer.c | 94 ++++++++++++++++----------------- source/C302/C302AudioPlayer.c | 80 ++++++++++++++-------------- source/C302/C302Common.h | 16 +++--- source/C302/C302VideoCapturer.c | 51 +++++++++--------- 4 files changed, 120 insertions(+), 121 deletions(-) diff --git a/source/C302/C302AudioCapturer.c b/source/C302/C302AudioCapturer.c index 866ba70..ca9d60e 100644 --- a/source/C302/C302AudioCapturer.c +++ b/source/C302/C302AudioCapturer.c @@ -21,7 +21,7 @@ #define USING_HARD_STREAM_AUDIO -#define DEFAULT_VOLUME 50 +#define DEFAULT_VOLUME 50 #define C302_HANDLE_GET(x) C302AudioCapturer* audioHandle = (C302AudioCapturer*) ((x)) @@ -32,7 +32,7 @@ typedef struct { AudioChannel channel; AudioBitDepth bitDepth; AudioSampleRate sampleRate; - IPC_AUDIO_FRAME *aframe; + IPC_AUDIO_FRAME* aframe; } C302AudioCapturer; static int setStatus(AudioCapturerHandle handle, const AudioCapturerStatus newStatus) @@ -115,57 +115,57 @@ int audioCapturerSetFormat(AudioCapturerHandle handle, const AudioFormat format, unsigned int bit_width; switch (format) { - case AUD_FMT_G711A: - enc_type = CODEC_G711A; - break; - case AUD_FMT_G711U: - enc_type = CODEC_G711U; - break; - case AUD_FMT_AAC: - enc_type = CODEC_AAC; - break; - default: - KVS_LOG("Unsupported format %d", format); - return -EINVAL; + case AUD_FMT_G711A: + enc_type = CODEC_G711A; + break; + case AUD_FMT_G711U: + enc_type = CODEC_G711U; + break; + case AUD_FMT_AAC: + enc_type = CODEC_AAC; + break; + default: + KVS_LOG("Unsupported format %d", format); + return -EINVAL; } switch (channel) { - case AUD_CHN_MONO: - channels = 1; - break; - case AUD_CHN_STEREO: - channels = 2; - break; - default: - KVS_LOG("Unsupported channel num %d", channel); - return -EINVAL; + case AUD_CHN_MONO: + channels = 1; + break; + case AUD_CHN_STEREO: + channels = 2; + break; + default: + KVS_LOG("Unsupported channel num %d", channel); + return -EINVAL; } switch (sampleRate) { - case AUD_SAM_8K: - sample_rate = AUDIO_SAMPLERATE_8K; - break; - case AUD_SAM_16K: - sample_rate = AUDIO_SAMPLERATE_16K; - break; - case AUD_SAM_32K: - sample_rate = AUDIO_SAMPLERATE_32K; - break; - case AUD_SAM_48K: - sample_rate = AUDIO_SAMPLERATE_48K; - break; - default: - KVS_LOG("Unsupported sample rate %d", sampleRate); - return -EINVAL; + case AUD_SAM_8K: + sample_rate = AUDIO_SAMPLERATE_8K; + break; + case AUD_SAM_16K: + sample_rate = AUDIO_SAMPLERATE_16K; + break; + case AUD_SAM_32K: + sample_rate = AUDIO_SAMPLERATE_32K; + break; + case AUD_SAM_48K: + sample_rate = AUDIO_SAMPLERATE_48K; + break; + default: + KVS_LOG("Unsupported sample rate %d", sampleRate); + return -EINVAL; } switch (bitDepth) { - case AUD_BIT_16: - bit_width = AUDIO_BITWIDTH_16; - break; - default: - KVS_LOG("Unsupported bit depth %d", bitDepth); - return -EINVAL; + case AUD_BIT_16: + bit_width = AUDIO_BITWIDTH_16; + break; + default: + KVS_LOG("Unsupported bit depth %d", bitDepth); + return -EINVAL; } int ret = IPC_AUDIO_SetConfig(CFG_AI_FLAG, enc_type, channels, sample_rate, bit_width, DEFAULT_VOLUME); @@ -217,7 +217,7 @@ int audioCapturerAcquireStream(AudioCapturerHandle handle) IPC_CFG_UnInit(CFG_AI_FLAG); return -EAGAIN; } - audioHandle->aframe = (IPC_AUDIO_FRAME *)malloc(sizeof(IPC_AUDIO_FRAME)); + audioHandle->aframe = (IPC_AUDIO_FRAME*) malloc(sizeof(IPC_AUDIO_FRAME)); if (!audioHandle->aframe) { KVS_LOG("AI device alloc aframe failed"); IPC_AUDIO_UnInit(CFG_AI_FLAG); @@ -247,10 +247,10 @@ int audioCapturerGetFrame(AudioCapturerHandle handle, void* pFrameDataBuffer, co ret = IPC_AUDIO_GetFrame(audioHandle->aframe); if (ret <= 0) { - //KVS_LOG("IPC_AUDIO_GetFrame failed"); + // KVS_LOG("IPC_AUDIO_GetFrame failed"); return -EAGAIN; } - memcpy(pFrameDataBuffer, (void*)audioHandle->aframe->u8data, audioHandle->aframe->u32len); + memcpy(pFrameDataBuffer, (void*) audioHandle->aframe->u8data, audioHandle->aframe->u32len); *pFrameSize = audioHandle->aframe->u32len; *pTimestamp = audioHandle->aframe->u64pts; #endif diff --git a/source/C302/C302AudioPlayer.c b/source/C302/C302AudioPlayer.c index b857e03..96d7333 100644 --- a/source/C302/C302AudioPlayer.c +++ b/source/C302/C302AudioPlayer.c @@ -23,7 +23,7 @@ #define C302_HANDLE_GET(x) C302AudioPlayer* audioHandle = (C302AudioPlayer*) ((x)) -#define DEFAULT_VOLUME 50 +#define DEFAULT_VOLUME 50 typedef struct { AudioPlayerStatus status; @@ -114,54 +114,54 @@ int audioPlayerSetFormat(AudioPlayerHandle handle, const AudioFormat format, con unsigned int bit_width; switch (format) { - case AUD_FMT_G711A: - enc_type = CODEC_G711A; - break; - case AUD_FMT_G711U: - enc_type = CODEC_G711U; - break; - default: - KVS_LOG("Unsupported format %d", format); - return -EINVAL; + case AUD_FMT_G711A: + enc_type = CODEC_G711A; + break; + case AUD_FMT_G711U: + enc_type = CODEC_G711U; + break; + default: + KVS_LOG("Unsupported format %d", format); + return -EINVAL; } switch (channel) { - case AUD_CHN_MONO: - channels = 1; - break; - case AUD_CHN_STEREO: - channels = 2; - break; - default: - KVS_LOG("Unsupported channel num %d", channel); - return -EINVAL; + case AUD_CHN_MONO: + channels = 1; + break; + case AUD_CHN_STEREO: + channels = 2; + break; + default: + KVS_LOG("Unsupported channel num %d", channel); + return -EINVAL; } switch (sampleRate) { - case AUD_SAM_8K: - sample_rate = AUDIO_SAMPLERATE_8K; - break; - case AUD_SAM_16K: - sample_rate = AUDIO_SAMPLERATE_16K; - break; - case AUD_SAM_32K: - sample_rate = AUDIO_SAMPLERATE_32K; - break; - case AUD_SAM_48K: - sample_rate = AUDIO_SAMPLERATE_48K; - break; - default: - KVS_LOG("Unsupported sample rate %d", sampleRate); - return -EINVAL; + case AUD_SAM_8K: + sample_rate = AUDIO_SAMPLERATE_8K; + break; + case AUD_SAM_16K: + sample_rate = AUDIO_SAMPLERATE_16K; + break; + case AUD_SAM_32K: + sample_rate = AUDIO_SAMPLERATE_32K; + break; + case AUD_SAM_48K: + sample_rate = AUDIO_SAMPLERATE_48K; + break; + default: + KVS_LOG("Unsupported sample rate %d", sampleRate); + return -EINVAL; } switch (bitDepth) { - case AUD_BIT_16: - bit_width = AUDIO_BITWIDTH_16; - break; - default: - KVS_LOG("Unsupported bit depth %d", bitDepth); - return -EINVAL; + case AUD_BIT_16: + bit_width = AUDIO_BITWIDTH_16; + break; + default: + KVS_LOG("Unsupported bit depth %d", bitDepth); + return -EINVAL; } int ret = IPC_AUDIO_SetConfig(CFG_AO_FLAG, enc_type, channels, sample_rate, bit_width, DEFAULT_VOLUME); diff --git a/source/C302/C302Common.h b/source/C302/C302Common.h index 541b8a4..92a9a08 100644 --- a/source/C302/C302Common.h +++ b/source/C302/C302Common.h @@ -44,13 +44,13 @@ #define KVS_LOG(format, args...) printf("[kvs %s:%d] " format, __func__, __LINE__, ##args) #endif -#define HANDLE_NULL_CHECK(x) \ - if (!(x)) { \ - KVS_LOG("HANDLE_STATUS_CHECK err\n"); \ - return -EINVAL; \ +#define HANDLE_NULL_CHECK(x) \ + if (!(x)) { \ + KVS_LOG("HANDLE_STATUS_CHECK err\n"); \ + return -EINVAL; \ } -#define HANDLE_STATUS_CHECK(C302Handle, expectedStatus) \ - if ((C302Handle)->status != (expectedStatus)) { \ - KVS_LOG("HANDLE_STATUS_CHECK err\n"); \ - return -EAGAIN; \ +#define HANDLE_STATUS_CHECK(C302Handle, expectedStatus) \ + if ((C302Handle)->status != (expectedStatus)) { \ + KVS_LOG("HANDLE_STATUS_CHECK err\n"); \ + return -EAGAIN; \ } diff --git a/source/C302/C302VideoCapturer.c b/source/C302/C302VideoCapturer.c index 52231ec..821aa48 100644 --- a/source/C302/C302VideoCapturer.c +++ b/source/C302/C302VideoCapturer.c @@ -24,9 +24,9 @@ #define USING_HARD_STREAM_VIDEO -#define DEFAULT_STREAM_CHN 0 -#define DEFAULT_STREAM_FPS 30 -#define DEFAULT_STREAM_PRO 1 +#define DEFAULT_STREAM_CHN 0 +#define DEFAULT_STREAM_FPS 30 +#define DEFAULT_STREAM_PRO 1 #define C302_HANDLE_GET(x) C302VideoCapturer* videoHandle = (C302VideoCapturer*) ((x)) @@ -151,29 +151,29 @@ int videoCapturerSetFormat(VideoCapturerHandle handle, const VideoFormat format, IPC_VCODEC_TYPE vcodec; switch (format) { - case VID_FMT_H264: - vcodec = CODEC_H264; - break; - case VID_FMT_H265: - vcodec = CODEC_H265; - break; - default: - KVS_LOG("Unsupported format %d", format); - return -EINVAL; + case VID_FMT_H264: + vcodec = CODEC_H264; + break; + case VID_FMT_H265: + vcodec = CODEC_H265; + break; + default: + KVS_LOG("Unsupported format %d", format); + return -EINVAL; } switch (resolution) { - case VID_RES_1080P: - vresolution.u32Width = 1920; - vresolution.u32Height = 1080; - break; - case VID_RES_720P: - vresolution.u32Width = 1280; - vresolution.u32Height = 720; - break; - default: - KVS_LOG("Unsupported resolution %d", resolution); - return -EINVAL; + case VID_RES_1080P: + vresolution.u32Width = 1920; + vresolution.u32Height = 1080; + break; + case VID_RES_720P: + vresolution.u32Width = 1280; + vresolution.u32Height = 720; + break; + default: + KVS_LOG("Unsupported resolution %d", resolution); + return -EINVAL; } int ret = IPC_VIDEO_SetStreamConfig(DEFAULT_STREAM_CHN, FORMAT_NONE, &vresolution, vcodec, DEFAULT_STREAM_FPS, DEFAULT_STREAM_PRO); @@ -232,12 +232,11 @@ int videoCapturerGetFrame(VideoCapturerHandle handle, void* pFrameDataBuffer, co if (videoHandle->format == VID_FMT_H264) { ret = IPC_VIDEO_GetFrame(&videoHandle->vframe, DEFAULT_STREAM_CHN, 0); if (ret > 0) { - //KVS_LOG("IPC_VIDEO_GetFrame:%u\n", videoHandle->vframe.u32len); + // KVS_LOG("IPC_VIDEO_GetFrame:%u\n", videoHandle->vframe.u32len); memcpy(pFrameDataBuffer, videoHandle->vframe.u8data, videoHandle->vframe.u32len); *pFrameSize = videoHandle->vframe.u32len; *pTimestamp = videoHandle->vframe.u64pts; - } - else { + } else { return -EINVAL; } } else {