Change test makefile.
Change-Id: I27eef2cdb86b220dd03e9be79d5bef7f9303258b
diff --git a/mbtk/test/libmbtk_audio/Makefile b/mbtk/test/libmbtk_audio/Makefile
new file mode 100755
index 0000000..1045e71
--- /dev/null
+++ b/mbtk/test/libmbtk_audio/Makefile
@@ -0,0 +1,34 @@
+ROOT = $(shell pwd)/../../..
+include $(ROOT)/mbtk/Make.defines
+
+INC_DIR +=
+
+LIB_DIR +=
+
+LIBS += -lmbtk_lib -lmbtk_net -lmbtk_audio
+
+CFLAGS +=
+
+DEFINE +=
+
+LOCAL_SRC_FILES = $(wildcard *.c) $(wildcard *.cpp)
+
+$(info LOCAL_SRC_FILES = $(LOCAL_SRC_FILES))
+
+OBJS = $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(LOCAL_SRC_FILES)))
+BINS = $(patsubst %.o,%,$(OBJS))
+
+all: $(BINS)
+
+$(BINS):$(OBJS)
+ @echo " BIN $@"
+ $(CC) $(CFLAGS) $(LIB_DIR) $(LIBS) $@.o -o $(OUT_DIR)/bin/$@
+
+%.o:%.c
+ $(CC) $(CFLAGS) $(INC_DIR) $(DEFINE) -c $< -o $@
+
+%.o:%.cpp
+ $(CC) $(CFLAGS) $(INC_DIR) $(DEFINE) -c $< -o $@
+
+clean:
+ rm -f $(OBJS)
diff --git a/mbtk/test/libmbtk_audio/mbtk_pcm_play_test.c b/mbtk/test/libmbtk_audio/mbtk_pcm_play_test.c
new file mode 100755
index 0000000..c11e06a
--- /dev/null
+++ b/mbtk/test/libmbtk_audio/mbtk_pcm_play_test.c
@@ -0,0 +1,139 @@
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <fcntl.h>
+
+#include "audio_if_api.h"
+#include "mbtk_audio2.h"
+
+#define BUFF_SIZE 4096
+
+int main(int argc, char *argv[])
+{
+ if(argc != 3) {
+ printf("mbtk_pcm_play_test <wav_file> <pack_size>\n");
+ return -1;
+ }
+
+ mbtk_log_init("radio", "MBTK_AUDIO");
+
+ if(mbtk_audio_pcm_init()) {
+ printf("mbtk_audio_pcm_init() fail.\n");
+ return -1;
+ }
+
+ int pack_size = atoi(argv[2]);
+ if(pack_size <= 0) {
+ pack_size = 1024;
+ }
+
+ int rc, len, fd, frames = 0;
+ //char buf[MBTK_PCM_WB_BUF_SIZE];
+ char buf[BUFF_SIZE];
+ char *path = (char*)argv[1];
+ struct stat st;
+ struct riff_wave_header riff_wave_header;
+ struct chunk_header chunk_header;
+ struct chunk_fmt chunk_fmt = {0};
+ unsigned int more_chunks = 1;
+
+ /* Check and open source file */
+ if (access(path, F_OK) || stat(path, &st)) {
+ printf("%s: error reading from file %s\n", __FUNCTION__, path);
+ return -1;
+ }
+
+ if (!st.st_size) {
+ printf("%s: empty file %s\n", __FUNCTION__, path);
+ return -1;
+ }
+
+ fd = open(path, O_RDONLY);
+ if (fd < 0) {
+ printf("%s: error opening file %s\n", __FUNCTION__, path);
+ return -1;
+ }
+
+ read(fd, &riff_wave_header, sizeof(riff_wave_header));
+ if ((riff_wave_header.riff_id != ID_RIFF) || (riff_wave_header.wave_id != ID_WAVE)) {
+ printf("Error: '%s' is not a riff/wave file\n", path);
+ close(fd);
+ return -1;
+ }
+
+ do {
+ read(fd, &chunk_header, sizeof(chunk_header));
+
+ switch (chunk_header.id) {
+ case ID_FMT:
+ read(fd, &chunk_fmt, sizeof(chunk_fmt));
+ /* If the format header is larger, skip the rest */
+ if (chunk_header.sz > sizeof(chunk_fmt))
+ lseek(fd, chunk_header.sz - sizeof(chunk_fmt), SEEK_CUR);
+ break;
+ case ID_DATA:
+ /* Stop looking for chunks */
+ more_chunks = 0;
+ break;
+ default:
+ /* Unknown chunk, skip bytes */
+ lseek(fd, chunk_header.sz, SEEK_CUR);
+ }
+ } while (more_chunks);
+
+ //Support 8k/16k & mono wave file
+ if (((chunk_fmt.sample_rate != 8000) && (chunk_fmt.sample_rate != 16000))
+ || (chunk_fmt.num_channels != 1) ) {
+ printf("%s: error wave file:sample_rate = %d, num_channels = %d!! \n",
+ __FUNCTION__,chunk_fmt.sample_rate, chunk_fmt.num_channels);
+ close(fd);
+ return -1;
+ }
+
+ printf("%s: success open wave file:%s, sample_rate = %d, num_channels = %d.\n",
+ __FUNCTION__, path, chunk_fmt.sample_rate, chunk_fmt.num_channels);
+
+ if ((8000 == chunk_fmt.sample_rate) && (1 == chunk_fmt.num_channels)) {
+ mbtk_audio_pcm_sample_rate_set(MBTK_AUDIO_SAMPLE_RATE_8000);
+ } else if ((16000 == chunk_fmt.sample_rate) && (1 == chunk_fmt.num_channels)) {
+ mbtk_audio_pcm_sample_rate_set(MBTK_AUDIO_SAMPLE_RATE_16000);
+ }
+
+ if(mbtk_audio_pcm_play_start()) {
+ printf("mbtk_audio_pcm_play_start() fail.\n");
+ return -1;
+ }
+
+ printf("%s: starting playback %d bytes every 20ms.\n", __FUNCTION__, pack_size);
+
+ while (TRUE) {
+ /* Playback loop */
+ memset(buf, 0x00, sizeof(buf));
+ len = read(fd, buf, pack_size);
+ if (len == -1) {
+ printf("%s: error reading from file\n", __FUNCTION__);
+ break;
+ }
+
+ if (len == 0) {
+ /* reached EOF */
+ printf("%s: nothing to read\n", __FUNCTION__);
+ break;
+ }
+
+ if((rc = mbtk_audio_pcm_play_data_send(buf, len)) < len) {
+ printf("Send data %d/%d\n", rc, len);
+ break;
+ }
+
+ printf("%s: No.%d frame playback[len - %d]\n", __FUNCTION__, ++frames, len);
+ }
+
+ if(mbtk_audio_pcm_deinit()) {
+ printf("mbtk_audio_pcm_deinit() fail.\n");
+ return -1;
+ }
+
+ return 0;
+}
+
diff --git a/mbtk/test/libmbtk_audio/mbtk_pcm_recorder_test.c b/mbtk/test/libmbtk_audio/mbtk_pcm_recorder_test.c
new file mode 100755
index 0000000..748e599
--- /dev/null
+++ b/mbtk/test/libmbtk_audio/mbtk_pcm_recorder_test.c
@@ -0,0 +1,116 @@
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <signal.h>
+
+#include "mbtk_audio2.h"
+#include "mbtk_log.h"
+
+static void sig_handler(int sig)
+{
+ if(mbtk_audio_pcm_recorder_stop()) {
+ printf("mbtk_audio_pcm_recorder_stop() fail.\n");
+ //goto exit;
+ }
+
+ if(mbtk_audio_pcm_deinit()) {
+ printf("mbtk_audio_pcm_deinit() fail.\n");
+ }
+
+ printf("Success exit by signal...\n");
+ exit(0);
+}
+
+static void recorder_cb(void *data, uint32 data_len)
+{
+ if(data_len > 0) {
+ LOGD("Recorver data:%d", data_len);
+ } else {
+ LOGD("Recorver data end.");
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ if(argc != 1) {
+ printf("mbtk_pcm_recorder_test\n");
+ return -1;
+ }
+
+ mbtk_log_init("radio", "MBTK_AUDIO");
+
+ if(mbtk_audio_pcm_init()) {
+ printf("mbtk_audio_pcm_init() fail.\n");
+ return -1;
+ }
+
+ signal(SIGINT, sig_handler);
+ signal(SIGTERM, sig_handler);
+
+ char cmd[100];
+ bool running = TRUE;
+ while(running)
+ {
+ memset(cmd, 0, 100);
+ int err;
+ printf("1 : Recorder 2 : Pause 3 : Resume 4 : Stop Other : Exit\n");
+ if(fgets(cmd, 100, stdin))
+ {
+ if(cmd[0] == '\r' || cmd[0] == '\n')
+ continue;
+ int state = atoi(cmd);
+ switch(state){
+ case 1:
+ {
+ if(mbtk_audio_pcm_recorder_start(recorder_cb)) {
+ printf("mbtk_audio_pcm_recorder_start() fail.\n");
+ //goto exit;
+ }
+ break;
+ }
+ case 2:
+ {
+ if(mbtk_audio_pcm_recorder_pause()) {
+ printf("mbtk_audio_pcm_recorder_pause() fail.\n");
+ //goto exit;
+ }
+ break;
+ }
+ case 3:
+ {
+ if(mbtk_audio_pcm_recorder_resume()) {
+ printf("mbtk_audio_pcm_recorder_resume() fail.\n");
+ //goto exit;
+ }
+ break;
+ }
+ case 4:
+ {
+ if(mbtk_audio_pcm_recorder_stop()) {
+ printf("mbtk_audio_pcm_recorder_stop() fail.\n");
+ //goto exit;
+ }
+ break;
+ }
+ default:
+ {
+ running = FALSE;
+ break;
+ }
+ }
+ }
+ }
+
+exit:
+ if(mbtk_audio_pcm_deinit()) {
+ printf("mbtk_audio_pcm_deinit() fail.\n");
+ return -1;
+ }
+
+ printf("Success exit.\n");
+ return 0;
+}
+
+
+
diff --git a/mbtk/test/libmbtk_audio/mbtk_wav_play_test.c b/mbtk/test/libmbtk_audio/mbtk_wav_play_test.c
new file mode 100755
index 0000000..deaaa97
--- /dev/null
+++ b/mbtk/test/libmbtk_audio/mbtk_wav_play_test.c
@@ -0,0 +1,106 @@
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <signal.h>
+
+#include "mbtk_audio2.h"
+
+static void sig_handler(int sig)
+{
+ if(mbtk_audio_wav_play_stop()) {
+ printf("mbtk_audio_wav_play_stop() fail.\n");
+ //goto exit;
+ }
+
+ if(mbtk_audio_wav_deinit()) {
+ printf("mbtk_audio_wav_deinit() fail.\n");
+ }
+
+ printf("Success exit by signal...\n");
+ exit(0);
+}
+
+
+int main(int argc, char *argv[])
+{
+ if(argc != 2) {
+ printf("mbtk_wav_play_test <wav_file>\n");
+ return -1;
+ }
+
+ mbtk_log_init("radio", "MBTK_AUDIO");
+
+ if(mbtk_audio_wav_init()) {
+ printf("mbtk_audio_wav_init() fail.\n");
+ return -1;
+ }
+
+ signal(SIGINT, sig_handler);
+ signal(SIGTERM, sig_handler);
+
+ char cmd[100];
+ bool running = TRUE;
+ while(running)
+ {
+ memset(cmd, 0, 100);
+ int err;
+ printf("1 : Play 2 : Pause 3 : Resume 4 : Stop Other : Exit\n");
+ if(fgets(cmd, 100, stdin))
+ {
+ if(cmd[0] == '\r' || cmd[0] == '\n')
+ continue;
+ int state = atoi(cmd);
+ switch(state){
+ case 1:
+ {
+ if(mbtk_audio_wav_play_start(argv[1])) {
+ printf("mbtk_audio_wav_play_start() fail.\n");
+ //goto exit;
+ }
+ break;
+ }
+ case 2:
+ {
+ if(mbtk_audio_wav_play_pause()) {
+ printf("mbtk_audio_wav_play_pause() fail.\n");
+ //goto exit;
+ }
+ break;
+ }
+ case 3:
+ {
+ if(mbtk_audio_wav_play_resume()) {
+ printf("mbtk_audio_wav_play_resume() fail.\n");
+ //goto exit;
+ }
+ break;
+ }
+ case 4:
+ {
+ if(mbtk_audio_wav_play_stop()) {
+ printf("mbtk_audio_wav_play_stop() fail.\n");
+ //goto exit;
+ }
+ break;
+ }
+ default:
+ {
+ running = FALSE;
+ break;
+ }
+ }
+ }
+ }
+
+exit:
+ if(mbtk_audio_wav_deinit()) {
+ printf("mbtk_audio_wav_deinit() fail.\n");
+ return -1;
+ }
+
+ printf("Success exit.\n");
+ return 0;
+}
+
+
diff --git a/mbtk/test/libmbtk_audio/mbtk_wav_recorder_test.c b/mbtk/test/libmbtk_audio/mbtk_wav_recorder_test.c
new file mode 100755
index 0000000..2f9a1a2
--- /dev/null
+++ b/mbtk/test/libmbtk_audio/mbtk_wav_recorder_test.c
@@ -0,0 +1,105 @@
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <signal.h>
+
+#include "mbtk_audio2.h"
+
+static void sig_handler(int sig)
+{
+ if(mbtk_audio_wav_recorder_stop()) {
+ printf("mbtk_audio_wav_recorder_stop() fail.\n");
+ //goto exit;
+ }
+
+ if(mbtk_audio_wav_deinit()) {
+ printf("mbtk_audio_wav_deinit() fail.\n");
+ }
+
+ printf("Success exit by signal...\n");
+ exit(0);
+}
+
+
+int main(int argc, char *argv[])
+{
+ if(argc != 2) {
+ printf("mbtk_wav_recorder_test <wav_file>\n");
+ return -1;
+ }
+
+ mbtk_log_init("radio", "MBTK_AUDIO");
+
+ if(mbtk_audio_wav_init()) {
+ printf("mbtk_audio_wav_init() fail.\n");
+ return -1;
+ }
+
+ signal(SIGINT, sig_handler);
+ signal(SIGTERM, sig_handler);
+
+ char cmd[100];
+ bool running = TRUE;
+ while(running)
+ {
+ memset(cmd, 0, 100);
+ int err;
+ printf("1 : Recorder 2 : Pause 3 : Resume 4 : Stop Other : Exit\n");
+ if(fgets(cmd, 100, stdin))
+ {
+ if(cmd[0] == '\r' || cmd[0] == '\n')
+ continue;
+ int state = atoi(cmd);
+ switch(state){
+ case 1:
+ {
+ if(mbtk_audio_wav_recorder_start(argv[1], MBTK_AUDIO_SAMPLE_RATE_8000)) {
+ printf("mbtk_audio_wav_recorder_start() fail.\n");
+ //goto exit;
+ }
+ break;
+ }
+ case 2:
+ {
+ if(mbtk_audio_wav_recorder_pause()) {
+ printf("mbtk_audio_wav_recorder_pause() fail.\n");
+ //goto exit;
+ }
+ break;
+ }
+ case 3:
+ {
+ if(mbtk_audio_wav_recorder_resume()) {
+ printf("mbtk_audio_wav_recorder_resume() fail.\n");
+ //goto exit;
+ }
+ break;
+ }
+ case 4:
+ {
+ if(mbtk_audio_wav_recorder_stop()) {
+ printf("mbtk_audio_wav_recorder_stop() fail.\n");
+ //goto exit;
+ }
+ break;
+ }
+ default:
+ {
+ running = FALSE;
+ break;
+ }
+ }
+ }
+ }
+
+exit:
+ if(mbtk_audio_wav_deinit()) {
+ printf("mbtk_audio_wav_deinit() fail.\n");
+ return -1;
+ }
+
+ printf("Success exit.\n");
+ return 0;
+}
+