Add mbtk_loopbuff and rtp support.

Change-Id: Idc80af4efb8ff76c4afc59fdf1d3896b453e6ff4
diff --git a/mbtk/test/libmbtk_lib/mbtk_loopbuff_test.c b/mbtk/test/libmbtk_lib/mbtk_loopbuff_test.c
new file mode 100755
index 0000000..4ae6684
--- /dev/null
+++ b/mbtk/test/libmbtk_lib/mbtk_loopbuff_test.c
@@ -0,0 +1,107 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <errno.h>
+#include <unistd.h>
+#include <time.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <pthread.h>
+
+#include "mbtk_loop_buffer.h"
+#include "mbtk_log.h"
+#include "mbtk_utils.h"
+
+
+static void* read_run(void* arg)
+{
+    mbtk_loop_buff_handle *handle = (mbtk_loop_buff_handle*)arg;
+    int fd = open("/data/voip_playback.wav", O_RDONLY);
+    int read_count = 0;
+    int buff_count = 0;
+    if(fd > 0) {
+        char buff[1569];
+        int len;
+        int temp_len;
+        while((len = read(fd, buff, sizeof(buff))) > 0) {
+            read_count += len;
+
+            temp_len = mbtk_loopbuff_writen(handle, buff, len);
+            if(temp_len > 0) {
+                if(temp_len != len) {
+                    printf("mbtk_loopbuff_writen() fail : %d/%d\n", temp_len, len);
+                }
+                buff_count += temp_len;
+            } else {
+                printf("mbtk_loopbuff_writen() fail.\n");
+            }
+        }
+        close(fd);
+    }
+    printf("read complete : %d / %d\n", read_count, buff_count);
+
+    return NULL;
+}
+
+static void* write_run(void* arg)
+{
+    mbtk_loop_buff_handle *handle = (mbtk_loop_buff_handle*)arg;
+    int write_count = 0;
+    int buff_count = 0;
+    int fd = open("/data/voip_playback_copy.wav", O_WRONLY | O_CREAT | O_TRUNC, 0644);
+    if(fd > 0) {
+        char buff[999];
+        int len;
+        while((len = mbtk_loopbuff_readn(handle, buff, sizeof(buff))) > 0) {
+            buff_count += len;
+            len = write(fd, buff, len);
+            if(len > 0)
+                write_count += len;
+            else
+                printf("mbtk_write() fail.\n");
+        }
+        close(fd);
+    }
+
+    printf("write complete : %d / %d\n", write_count, buff_count);
+    return NULL;
+}
+
+int main(int argc, char *argv[])
+{
+    mbtk_log_init("radio", "LOOPBUFF");
+    mbtk_loop_buff_handle *handle = mbtk_loopbuff_get(7 * 1001);
+    if(handle) {
+        pthread_t read_pid, write_pid;
+        if(pthread_create(&read_pid, NULL, read_run, handle))
+        {
+            LOGE("pthread_create() fail.");
+            return -1;
+        }
+
+        if(pthread_create(&write_pid, NULL, write_run, handle))
+        {
+            LOGE("pthread_create() fail.");
+            return -1;
+        }
+
+        sleep(1);
+
+        if (pthread_join(read_pid, NULL)){
+            printf("error join thread!\n");
+            abort();
+        }
+
+        if (pthread_join(write_pid, NULL)){
+            printf("error join thread!\n");
+            abort();
+        }
+
+        mbtk_loopbuff_free(handle);
+    }
+    return 0;
+}
+
+
diff --git a/mbtk/test/libmbtk_lib/mbtk_rtp_test.c b/mbtk/test/libmbtk_lib/mbtk_rtp_test.c
new file mode 100755
index 0000000..2140e25
--- /dev/null
+++ b/mbtk/test/libmbtk_lib/mbtk_rtp_test.c
@@ -0,0 +1,155 @@
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "mbtk_rtp.h"
+#include "mbtk_log.h"
+
+
+static void help()
+{
+    printf("rtp_mode <0/1>: Disable/Enable RTP.\n");
+    printf("volume <0-7>: Set volume.\n");
+    printf("remote_ip <xxx:xxx:xxx:xxx>: Set remote ip.\n");
+    printf("client_port <port>: Set client(local) port.\n");
+    printf("server_port <port>: Set server(remote) port.\n");
+    printf("sample_rate <8000/16000>: Set sample rate.\n");
+    printf("channel <1>: Set channel.\n");
+}
+
+
+static void sig_handler(int sig)
+{
+    if(mbtk_rtp_deinit()) {
+        printf("mbtk_rtp_deinit() fail.\n");
+    }
+
+    printf("Success exit by signal...\n");
+    exit(0);
+}
+
+int main(int argc, char *argv[])
+{
+    mbtk_log_init("radio", "RTP_CLI");
+
+    if(mbtk_rtp_init()) {
+        printf("mbtk_rtp_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("0 : Disable    1 : Enable    Other : Exit\n");
+        help();
+        if(fgets(cmd, 100, stdin))
+        {
+            if(cmd[0] == '\r' || cmd[0] == '\n')
+                continue;
+            char *ptr = cmd + strlen(cmd) - 1;
+            while(ptr >= cmd && (*ptr == '\r' || *ptr == '\n'))
+            {
+                *ptr-- = '\0';
+            }
+
+            if(!strncasecmp(cmd, "rtp_mode", 8))
+            {
+                int temp;
+                if(1 == sscanf(cmd, "rtp_mode %d", &temp)) {
+                    if(mbtk_rtp_enable((bool)temp)) {
+                        printf("Error\n");
+                    } else {
+                        printf("Success\n");
+                    }
+                }
+            }
+            else if(!strncasecmp(cmd, "volume", 6)){
+                int temp;
+                if(1 == sscanf(cmd, "volume %d", &temp)) {
+                    if(mbtk_rtp_volume_set(temp)) {
+                        printf("Error\n");
+                    } else {
+                        printf("Success\n");
+                    }
+                }
+            }
+            else if(!strncasecmp(cmd, "remote_ip", 9)){
+                char ipv4[20] = {0};
+                if(1 == sscanf(cmd, "remote_ip %s", ipv4)) {
+                    if(mbtk_rtp_remote_ip_set(ipv4)) {
+                        printf("Error\n");
+                    } else {
+                        printf("Success\n");
+                    }
+                }
+            }
+            else if(!strncasecmp(cmd, "client_port", 11)){
+                int temp;
+                if(1 == sscanf(cmd, "client_port %d", &temp)) {
+                    if(mbtk_rtp_client_port_set(temp)) {
+                        printf("Error\n");
+                    } else {
+                        printf("Success\n");
+                    }
+                }
+            }
+            else if(!strncasecmp(cmd, "server_port", 11)){
+                int temp;
+                if(1 == sscanf(cmd, "server_port %d", &temp)) {
+                    if(mbtk_rtp_server_port_set(temp)) {
+                        printf("Error\n");
+                    } else {
+                        printf("Success\n");
+                    }
+                }
+            }
+            else if(!strncasecmp(cmd, "sample_rate", 11)){
+                int temp;
+                if(1 == sscanf(cmd, "sample_rate %d", &temp)) {
+                    if(mbtk_rtp_sample_rate_set(temp)) {
+                        printf("Error\n");
+                    } else {
+                        printf("Success\n");
+                    }
+                }
+            }
+            else if(!strncasecmp(cmd, "channel", 7)){
+                int temp;
+                if(1 == sscanf(cmd, "channel %d", &temp)) {
+                    if(mbtk_rtp_channel_set(temp)) {
+                        printf("Error\n");
+                    } else {
+                        printf("Success\n");
+                    }
+                }
+            }
+
+            else if(!strcasecmp(cmd, "h") || !strcasecmp(cmd, "help")) {
+                help();
+            } else if(!strcasecmp(cmd, "q")) {
+                break;
+            } else {
+                printf("\n");
+            }
+        }
+    }
+
+//exit:
+    if(mbtk_rtp_deinit()) {
+        printf("mbtk_rtp_deinit() fail.\n");
+        return -1;
+    }
+
+    printf("Success exit.\n");
+    return 0;
+}