Skip to content

Commit

Permalink
format code with amazon rules
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Li <zhiqinli@amazon.com>
  • Loading branch information
codingspirit committed Jan 6, 2023
1 parent 0042716 commit 696ab36
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 121 deletions.
94 changes: 47 additions & 47 deletions source/C302/C302AudioCapturer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
80 changes: 40 additions & 40 deletions source/C302/C302AudioPlayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions source/C302/C302Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
}
51 changes: 25 additions & 26 deletions source/C302/C302VideoCapturer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 696ab36

Please sign in to comment.