[Feature]Add liblynq-rtp

Change-Id: Ie5c3166d0bf56156a90ada278236c206affe0e6c
diff --git a/src/lynq/lib/liblynq-rtp/Makefile b/src/lynq/lib/liblynq-rtp/Makefile
new file mode 100755
index 0000000..a96d783
--- /dev/null
+++ b/src/lynq/lib/liblynq-rtp/Makefile
@@ -0,0 +1,61 @@
+SHELL = /bin/sh
+RM = rm -f
+
+
+LOCAL_CFLAGS := \
+	-Wall \
+    -g \
+    -Wall \
+    -fPIC \
+    -shared \
+    -D__COMPILE_OPTION__ \
+    -D__LINUX_OS__ \
+
+CPPFLAGS=\
+  -std=c++11 \
+
+LOCAL_PATH = .
+$(warning ################# Typethree LOCAL_PATH:$(LOCAL_PATH),ROOT: $(ROOT),includedir:$(includedir),libdir:$(libdir))
+
+LOCAL_C_INCLUDES = \
+    -I$(LOCAL_PATH)/include \
+	-I$(ROOT)$(includedir)/liblog \
+	-I$(ROOT)$(includedir)/logger \
+	-I$(ROOT)$(includedir)/include \
+
+LOCAL_LIBS := \
+    -L. \
+	-ldl \
+    -lrt \
+	-llog \
+	-lutils \
+	-lcutils \
+	-llynq-log \
+#    -llynq-log \
+
+$(warning libs=$(LOCAL_LIBS))
+
+CXXSRC=\
+
+SOURCES = $(wildcard *.c wildcard src/*.c)
+
+EXECUTABLE = liblynq-rtp.so
+
+COBJS=$(SOURCES:.c=.o)
+$(warning test)
+all: $(EXECUTABLE)
+$(EXECUTABLE): $(COBJS)
+	$(CXX) -shared -Wl,--no-undefined $(COBJS) $(LOCAL_LIBS) $(LOCAL_CFLAGS) $(LOCAL_C_INCLUDES) -o $@
+
+%.o: %.c
+	$(warning ----->build $<)
+	$(CC) $(LOCAL_C_INCLUDES) $(LOCAL_CFLAGS) $(LOCAL_LIBS) -o $@ -c $<
+
+.PHONY: install clean
+install:
+	mkdir -p $(ROOT)$(base_libdir)/
+	install $(EXECUTABLE) $(ROOT)$(base_libdir)/
+
+clean:
+	rm -f $(EXECUTABLE) rm -rf *.o
+	find ./ -name *.o | xargs rm -rf
\ No newline at end of file
diff --git a/src/lynq/lib/liblynq-rtp/include/lynq_rtp.h b/src/lynq/lib/liblynq-rtp/include/lynq_rtp.h
new file mode 100755
index 0000000..01cbe51
--- /dev/null
+++ b/src/lynq/lib/liblynq-rtp/include/lynq_rtp.h
@@ -0,0 +1,34 @@
+#ifndef LYNQ_RTP_H
+#define LYNQ_RTP_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define  MAX_IP_LENGTH 128
+#define  MAX_EN_CODING_NAME_LENGTH 32
+#define  MAX_CMD_SIZE 512
+
+typedef enum{
+    RTP_CLIENT = 0,     
+    RTP_SERVER =1,
+}LYNQ_Rtp_Mode;
+
+int lynq_set_rtp_mode_media_play(const LYNQ_Rtp_Mode rtp_mode);
+int lynq_set_rtp_ip_media_play(LYNQ_Rtp_Mode rtp_mode,const char* ip,const int ip_length);
+int lynq_set_rtp_port_media_play(LYNQ_Rtp_Mode rtp_mode,const int port);
+int lynq_set_rtp_param_media_play(LYNQ_Rtp_Mode rtp_mode,char *file_address,const int clock_rate,const int channels,const int latency);
+
+int lynq_get_rtp_ip_media_play(const LYNQ_Rtp_Mode rtp_mode, char* ip, const int ip_length);
+int lynq_get_rtp_port_media_play(LYNQ_Rtp_Mode rtp_mode,int* port);
+int lynq_get_rtp_param_media_play(LYNQ_Rtp_Mode rtp_mode,char *file_address,int* clock_rate,int* channels,int* latency);
+
+int lynq_start_rtp_server_media_play();
+int lynq_stop_rtp_server_media_play();
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
\ No newline at end of file
diff --git a/src/lynq/lib/liblynq-rtp/src/lynq_rtp.c b/src/lynq/lib/liblynq-rtp/src/lynq_rtp.c
new file mode 100755
index 0000000..76de919
--- /dev/null
+++ b/src/lynq/lib/liblynq-rtp/src/lynq_rtp.c
@@ -0,0 +1,223 @@
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <log/log.h>
+#include <unistd.h>
+
+#include "lynq_rtp.h"
+#include "liblog/lynq_deflog.h"
+
+#define USER_LOG_TAG "LYNQ_RTP"
+
+char server_cmd[MAX_CMD_SIZE];
+
+char client_cmd[MAX_CMD_SIZE];
+
+typedef struct
+{
+    LYNQ_Rtp_Mode mode;
+    char ip[128];
+    int port;
+    int clockrate;
+    char address[128];
+    int latency;
+    int channels;
+}lynq_rtp_info;
+
+lynq_rtp_info lynq_rtp_client_info;
+lynq_rtp_info lynq_rtp_server_info;
+
+int g_lynq_rtp_mode;
+
+int g_lynq_rtp_pid;
+
+int get_pid(char *name) 
+{
+    char buf[256] = "";
+    char cmd[30] = ""; 
+    int  pid = -1;
+    sprintf(cmd, "pidof %s", name);
+ 
+    FILE *pFd = popen(cmd, "r");
+    if (pFd != NULL) 
+    {
+        while (fgets(buf, sizeof(buf), pFd)) 
+        {
+            pid = atoi(buf);
+            break;
+        }
+        pclose(pFd);
+    }
+    return pid;
+}
+
+int lynq_set_rtp_mode_media_play(const LYNQ_Rtp_Mode rtp_mode)
+{
+    if (rtp_mode == 0)
+    {
+        lynq_rtp_client_info.mode = 0;
+    }
+    else if (rtp_mode == 1)
+    {
+        lynq_rtp_server_info.mode = 1;
+    }
+    g_lynq_rtp_mode = rtp_mode;
+
+    LYLOGSET(LOG_INFO);
+    LYLOGEINIT(USER_LOG_TAG);
+    return 0;
+}
+
+int lynq_set_rtp_ip_media_play(LYNQ_Rtp_Mode rtp_mode,const char* ip,const int ip_length)
+{
+    if (NULL == ip)
+    {
+        LYERRLOG("ip is NULL!!!");
+        return -1;
+    }
+    if (ip_length != strlen(ip))
+    {
+        LYERRLOG("incoming ip length error");
+        return -1;
+    }
+
+    if (rtp_mode == 1)
+    {
+        bzero(lynq_rtp_server_info.ip,MAX_IP_LENGTH);
+        strcpy(lynq_rtp_server_info.ip,ip);
+    }
+    else if (rtp_mode == 0)
+    {
+        bzero(lynq_rtp_client_info.ip,MAX_IP_LENGTH);
+        strcpy(lynq_rtp_client_info.ip,ip);
+    }
+    return 0;
+}
+
+int lynq_set_rtp_port_media_play(LYNQ_Rtp_Mode rtp_mode,const int port)
+{
+    if (port < 0)
+    {
+        LYERRLOG("invalid port number");
+        return -1;
+    }
+    if (rtp_mode == 0)
+    {
+        lynq_rtp_client_info.port = port;
+    }
+    else if (rtp_mode == 1)
+    {
+        lynq_rtp_server_info.port = port;
+    }
+    return 0;
+}
+
+int lynq_set_rtp_param_media_play(LYNQ_Rtp_Mode rtp_mode,char *file_address,const int clock_rate,const int channels,const int latency)
+{
+    if (NULL == file_address)
+    {
+        LYERRLOG("file address is NULL");
+        return -1;
+    }
+    if (rtp_mode == 0)
+    {
+        lynq_rtp_client_info.clockrate = clock_rate;
+        lynq_rtp_client_info.channels = channels;
+        lynq_rtp_client_info.latency = latency;
+    }
+    if (rtp_mode == 1)
+    {
+        strcpy(lynq_rtp_server_info.address,file_address);
+    }
+    return 0;
+}
+
+int lynq_start_rtp_server_media_play()
+{
+    if (g_lynq_rtp_mode == 0)
+    {
+        bzero(client_cmd,MAX_CMD_SIZE);
+
+        sprintf(client_cmd,"gst-launch-1.0 udpsrc port=%d caps=\'application/x-rtp, media=(string)audio, clock-rate=(int)%d, channel=(int)%d\' ! rtpjitterbuffer latency=%d ! rtppcmadepay ! pulsesink",   \
+        lynq_rtp_client_info.port,lynq_rtp_client_info.clockrate,lynq_rtp_client_info.channels,lynq_rtp_client_info.latency);
+        
+        printf("typethree test :%s\r\n",client_cmd);
+        system(client_cmd);
+    }
+    else if (g_lynq_rtp_mode == 1)
+    {
+        bzero(server_cmd,MAX_CMD_SIZE);
+        
+        sprintf(server_cmd,"gst-launch-1.0 -v filesrc location=\"%s\" ! decodebin ! audioconvert ! audioresample ! alawenc ! rtppcmapay ! udpsink host=%s auto-multicast=true port=%d", \
+        lynq_rtp_server_info.address, lynq_rtp_server_info.ip,lynq_rtp_server_info.port);
+
+        printf("typethree test :%s\r\n",server_cmd);
+        system(server_cmd);
+    }
+    g_lynq_rtp_pid = get_pid(client_cmd);
+    return 0;
+}
+
+int lynq_stop_rtp_server_media_play()
+{
+    char kill_buf[512] = "";
+    sprintf(kill_buf,"kill -9 %d",g_lynq_rtp_pid);
+    system(kill_buf);
+    return 0;
+}
+
+
+/*query part*/
+int lynq_get_rtp_ip_media_play(const LYNQ_Rtp_Mode rtp_mode, char* ip, const int ip_length)
+{
+    if (NULL == ip)
+    {
+        LYERRLOG("incoming ip is NULL!!!");
+        return -1;
+    }
+    if (rtp_mode == 0)
+    {
+        bzero(ip,ip_length);
+        strcpy(ip,lynq_rtp_client_info.ip);
+    }
+    else if (rtp_mode == 1)
+    {
+        bzero(ip,ip_length);
+        strcpy(ip,lynq_rtp_server_info.ip);
+    }
+    return 0;
+}
+
+int lynq_get_rtp_port_media_play(LYNQ_Rtp_Mode rtp_mode,int* port)
+{
+    if (rtp_mode == 0)
+    {
+        *port = lynq_rtp_client_info.port;
+    }
+    else if (rtp_mode == 1)
+    {
+        *port = lynq_rtp_server_info.port;
+    }
+    return 0;
+}
+
+int lynq_get_rtp_param_media_play(LYNQ_Rtp_Mode rtp_mode,char *file_address,int* clock_rate,int* channels,int* latency)
+{
+    if (NULL == file_address)
+    {
+        LYERRLOG("file address is NULL");
+        return -1;
+    }
+    if (rtp_mode == 0)
+    {
+        *clock_rate = lynq_rtp_client_info.clockrate;
+        *channels = lynq_rtp_client_info.channels ;
+        *latency = lynq_rtp_client_info.latency;
+    }
+    if (rtp_mode == 1)
+    {
+        strcpy(file_address,lynq_rtp_server_info.address);
+    }
+    return 0;
+}
\ No newline at end of file