[Feature][ZXW-134][audio]Add codec demo to play and record

Only Configure:No
Affected branch:master
Affected module:audio
Is it affected on both ZXIC and MTK: only ZXIC
Self-test: Yes
Doc Update:Yes

Change-Id: I8330fa6d19e076df42d441b07b71e93091d4cdc2
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/conf/distro/vehicle_dc_ref.conf b/cap/zx297520v3/sources/meta-zxic-custom/conf/distro/vehicle_dc_ref.conf
index 9a284ea..44be59c 100755
--- a/cap/zx297520v3/sources/meta-zxic-custom/conf/distro/vehicle_dc_ref.conf
+++ b/cap/zx297520v3/sources/meta-zxic-custom/conf/distro/vehicle_dc_ref.conf
@@ -276,6 +276,7 @@
         lynq-gpio-demo \
         lynq-irq-demo \
         lynq-gnss-update \
+        lynq-audio-demo \
         "
 
 zxic_app_open += "${@bb.utils.contains('CONFIG_TEL_API_SUPPORT', 'RIL', 'rild', '', d)}"
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-audio-demo/files/LICENSE b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-audio-demo/files/LICENSE
new file mode 100755
index 0000000..cb88533
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-audio-demo/files/LICENSE
@@ -0,0 +1,31 @@
+Copyright Statement:
+
+This software/firmware and related documentation ("Mobiletek Software") are
+protected under relevant copyright laws. The information contained herein is
+confidential and proprietary to Mobiletek Inc. and/or its licensors. Without
+the prior written permission of Mobiletek inc. and/or its licensors, any
+reproduction, modification, use or disclosure of Mobiletek Software, and
+information contained herein, in whole or in part, shall be strictly
+prohibited.
+
+Mobiletek Inc. (C) 2015. All rights reserved.
+
+BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("Mobiletek SOFTWARE")
+RECEIVED FROM Mobiletek AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ON AN "AS-IS" BASIS ONLY. Mobiletek EXPRESSLY DISCLAIMS ANY AND ALL
+WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+NONINFRINGEMENT. NEITHER DOES Mobiletek PROVIDE ANY WARRANTY WHATSOEVER WITH
+RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+INCORPORATED IN, OR SUPPLIED WITH THE Mobiletek SOFTWARE, AND RECEIVER AGREES
+TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN Mobiletek
+SOFTWARE. Mobiletek SHALL ALSO NOT BE RESPONSIBLE FOR ANY Mobiletek SOFTWARE
+RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND Mobiletek'S
+ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE Mobiletek SOFTWARE
+RELEASED HEREUNDER WILL BE, AT Mobiletek'S OPTION, TO REVISE OR REPLACE THE
+Mobiletek SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+CHARGE PAID BY RECEIVER TO Mobiletek FOR SUCH Mobiletek SOFTWARE AT ISSUE.
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-audio-demo/files/lynq-audio-demo.cpp b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-audio-demo/files/lynq-audio-demo.cpp
new file mode 100755
index 0000000..eb557f6
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-audio-demo/files/lynq-audio-demo.cpp
@@ -0,0 +1,138 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <include/lynq-qser-audio.h>
+
+extern sc_audio_handle_t playback_handle;
+
+void player_cmd_proc(char *cmdstr)
+{
+    if (strcmp(cmdstr, "P\n") == 0)
+    {
+        qser_AudPlayer_Pause(playback_handle);
+    }
+    else if (strcmp(cmdstr, "R\n") == 0)
+    {
+        qser_AudPlayer_Resume(playback_handle);
+    }
+    else if (strcmp(cmdstr, "T\n") == 0)
+    {
+        qser_AudPlayer_Stop(playback_handle);
+    }
+    else
+    {
+        printf("Unknown command: %s", cmdstr);
+    }
+}
+
+void capture_cmd_proc(char *cmdstr)
+{
+    if (strcmp(cmdstr, "P\n") == 0)
+    {
+        qser_AudRecorder_Pause();
+    }
+    else if (strcmp(cmdstr, "R\n") == 0)
+    {
+        qser_AudRecorder_Resume();
+    }
+    else if (strcmp(cmdstr, "T\n") == 0)
+    {
+        qser_AudRecorder_Stop();
+    }
+    else
+    {
+        printf("Unknown command: %s", cmdstr);
+    }
+}
+
+int main(int argc, char *argv[])
+{
+    if (argc < 3)
+    {
+        printf("Usage: %s <play|recd> <file>\n", argv[0]);
+        return 1;
+    }
+
+    const char *action = argv[1];
+    const char *file = argv[2];
+
+    int g_audio_owner_id = 0;
+    char player_device[] = "device1";
+    char recorder_device[] = "device2";
+    char cmdstr[256];
+
+    _cb_onPlayer cb_fun = [](int result)
+    {
+        if (result == 0)
+        {
+            printf("Audio recorder opened successfully.\n");
+        }
+        else
+        {
+            printf("Failed to open audio recorder, error code: %d\n", result);
+        }
+    };
+
+    if (strcmp(action, "play") == 0)
+    {
+        int player_open_result = qser_AudPlayer_Open(player_device, cb_fun);
+        if (player_open_result != 0)
+        {
+            printf("Failed to open audio player.\n");
+            return 1;
+        }
+
+        qser_AudPlayer_PlayFrmFile(g_audio_owner_id, file, 0);
+
+        while (1)
+        {
+            printf("Please input a player command (P/R/T/exit) :\n");
+            if (fgets(cmdstr, sizeof(cmdstr), stdin) != NULL)
+            {
+                if (strcmp(cmdstr, "exit\n") == 0)
+                {
+                    qser_AudPlayer_Close(playback_handle);
+                    break;
+                }
+                player_cmd_proc(cmdstr);
+            }
+        }
+
+        qser_AudPlayer_Close(playback_handle);
+    }
+    else if (strcmp(action, "recd") == 0)
+    {
+        int recorder_open_result = qser_AudRecorder_Open(recorder_device, cb_fun);
+        if (recorder_open_result != 0) {
+            printf("Failed to open audio recorder.\n");
+            return 1;
+        }
+
+        qser_AudRecorder_StartRecord(g_audio_owner_id, file, 0);
+
+        while (1)
+        {
+            printf("Please input a player command (P/R/T/exit) :\n");
+            if (fgets(cmdstr, sizeof(cmdstr), stdin) != NULL)
+            {
+                if (strcmp(cmdstr, "exit\n") == 0)
+                {
+                    qser_AudRecorder_Close();
+                    break;
+                }
+                capture_cmd_proc(cmdstr);
+            }
+        }
+        qser_AudRecorder_Close();
+    }
+    else
+    {
+        printf("Unknown action: %s\n", action);
+        return 1;
+    }
+
+    qser_Audio_Deinit();
+
+    return 0;
+}
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-audio-demo/files/makefile b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-audio-demo/files/makefile
new file mode 100755
index 0000000..c37eeaa
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-audio-demo/files/makefile
@@ -0,0 +1,51 @@
+SHELL = /bin/sh
+RM = rm -f
+
+LOCAL_CFLAGS := -Wall \
+                -std=gnu++14 \
+                -g -Os \
+                -flto \
+                -fpermissive \
+
+ifeq ($(strip $(TARGET_PLATFORM)), T106)
+LOCAL_CFLAGS += -DBINDER_IPC_32BIT=1 -DHAVE_ENDIAN_H -DHAVE_PTHREADS -DHAVE_SYS_UIO_H -DHAVE_POSIX_FILEMAP -DHAVE_STRLCPY -DHAVE_PRCTL -DHAVE_MEMSET16 -DHAVE_MEMSET32 -DANDROID_SMP=0
+endif
+
+LOCAL_CFLAGS += -Werror=format-security
+
+$(warning ################# rock ROOT: $(ROOT),includedir:$(includedir),)
+
+LOCAL_PATH   = .
+
+LOCAL_C_INCLUDES = \
+  -I. \
+  -I$(LOCAL_PATH)/include/ \
+  -I$(ROOT)$(includedir)/ \
+
+
+LOCAL_LIBS := \
+    -L. \
+    -ldl \
+    -lstdc++ \
+    -lpthread \
+    -llynq-qser-audio \
+
+SOURCES = lynq-audio-demo.cpp
+
+EXECUTABLE = lynq-audio-demo
+
+OBJECTS=$(SOURCES:.cpp=.o)
+
+all: $(EXECUTABLE) 
+
+$(EXECUTABLE): $(OBJECTS)
+	$(CXX) $(OBJECTS) $(LOCAL_LIBS) $(LOCAL_CFLAGS) $(LOCAL_C_INCLUDES) -o $@
+
+%.o : %.cpp
+	$(CXX) $(LOCAL_C_INCLUDES) $(LOCAL_CFLAGS) $(LOCAL_LIBS) -o $@ -c $<
+
+.PHONY: clean
+clean:
+	$(RM) $(OBJECTS) $(EXECUTABLE)
+	$(RM) $(OBJECTS_TOOL) $(EXECUTABLE)
+
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-audio-demo/lynq-audio-demo.bb b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-audio-demo/lynq-audio-demo.bb
new file mode 100644
index 0000000..2260b19
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-audio-demo/lynq-audio-demo.bb
@@ -0,0 +1,31 @@
+#inherit externalsrc package
+#inherit externalsrc package systemd
+DESCRIPTION = "lynq-audio-demo"
+LICENSE = "CLOSED"
+LICENSE = "CLOSED"
+LIC_FILES_CHKSUM = "file://LICENSE;md5=b1e07e8d88e26263e71d3a9e2aa9a2ff"
+SRC_URI = "file://lynq-audio-demo.cpp \
+           file://makefile \
+"
+DEPENDS += "liblynq-qser-audio"
+
+SRC-DIR = "${S}/../lynq-audio-demo"
+FILES_${PN} += "${bindir}/"
+TARGET_CC_ARCH += "${LDFLAGS}"
+SYSTEMD_PACKAGES = "${PN}"
+S = "${WORKDIR}"
+#INHIBIT_PACKAGE_STRIP = "1"
+do_compile () {
+	if test "${PACKAGE_ARCH}" = "cortexa7hf-vfp-vfpv4-neon" || test "${PACKAGE_ARCH}" = "cortexa7hf-neon-vfpv4"; then
+		oe_runmake all ROOT=${STAGING_DIR_HOST} OFLAGS="--sysroot=${STAGING_DIR_HOST} -mhard-float"
+	else
+		oe_runmake all ROOT=${STAGING_DIR_HOST} OFLAGS="--sysroot=${STAGING_DIR_HOST}"
+	fi
+}
+
+
+do_install() {
+
+	install -d ${D}${bindir}/
+	install -m 0755 ${S}/lynq-audio-demo ${D}${bindir}/
+}