Merge "[Feature][ZXW-180]Add API to open sample rate channel and other parameters"
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
index eb557f6..dcf37a9 100755
--- 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
@@ -4,8 +4,6 @@
 #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)
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-audio/include/lynq-qser-audio.h b/cap/zx297520v3/src/lynq/lib/liblynq-qser-audio/include/lynq-qser-audio.h
index cc37b2e..d963767 100644
--- a/cap/zx297520v3/src/lynq/lib/liblynq-qser-audio/include/lynq-qser-audio.h
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-audio/include/lynq-qser-audio.h
@@ -17,8 +17,8 @@
 
 #include "sc_audio.h"
 
-sc_audio_handle_t playback_handle = SC_AUDIO_INVALID_HANDLE;
-sc_audio_handle_t capture_handle = SC_AUDIO_INVALID_HANDLE;
+extern sc_audio_handle_t playback_handle;
+extern sc_audio_handle_t capture_handle;
 
 typedef void (*_cb_onPlayer)(int);
 
@@ -31,6 +31,8 @@
 
 int qser_AudRecorder_Open(char* device, _cb_onPlayer cb_fun);
 int qser_AudRecorder_StartRecord(int hdl, const char *fd, int offset);
+int qser_AudRecorder_StartRecord_Custom(char *file, int period_size, \
+                 int period_count, int num_channels, int sample_rate);
 int qser_AudRecorder_Pause(void);
 int qser_AudRecorder_Resume(void);
 void qser_AudRecorder_Stop(void);
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-audio/lynq-qser-audio.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-qser-audio/lynq-qser-audio.cpp
index 70b4e43..63ce463 100644
--- a/cap/zx297520v3/src/lynq/lib/liblynq-qser-audio/lynq-qser-audio.cpp
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-audio/lynq-qser-audio.cpp
@@ -16,6 +16,9 @@
 #define SC_AUDIO_BE_DAI_MIN -1
 #define SC_AUDIO_STREAM_FORMAT_INVALID 0
 
+sc_audio_handle_t playback_handle = SC_AUDIO_INVALID_HANDLE;
+sc_audio_handle_t capture_handle = SC_AUDIO_INVALID_HANDLE;
+
 /********************************************************************
 * @brief: _cb_onPlayer, typedef for a callback function that is called
           when an audio operation is performed
@@ -204,6 +207,83 @@
 }
 
 /********************************************************************
+* @brief: qser_AudRecorder_StartRecord_Custom, used to capture audio from a file and play it
+* @param file [IN]: char*, the path of the audio file
+* @param period_size [IN]: int, the period size of the PCM buffer
+* @param period_count [IN]: int, the period count of the PCM buffer
+* @param num_channels [IN]: int, the number of channels in the audio
+* @param sample_rate [IN]: int, the sample rate of the audio
+* @return : int, returns 0 if successful, returns -1 if failed
+* @todo: NA
+* @see: NA
+* @warning: NA
+*********************************************************************/
+int qser_AudRecorder_StartRecord_Custom(char *file, int period_size, int period_count, \
+                        int num_channels, int sample_rate)
+{
+    int error_line;
+    sc_audio_pcm_config_t pcm_config;
+    int ret = 0;
+
+    if(NULL == file || 0 == strlen(file))
+    {
+        error_line = __LINE__;
+        goto exit;
+    }
+
+    capture_handle = sc_audio_capture_open(SC_AUDIO_FE_PCM_DEV_MULTIMEDIA1, SC_AUDIO_BE_DAI_MIN);
+
+    if (SC_AUDIO_INVALID_HANDLE == capture_handle)
+    {
+        error_line = __LINE__;
+        goto exit;
+    }
+
+    memset(&pcm_config, 0, sizeof(sc_audio_pcm_config_t));
+
+    if(-1 == period_size || -1 == period_count || -1 == num_channels || -1 == sample_rate)
+    {
+        ret = sc_audio_capture_file_prepare(capture_handle, file, SC_AUDIO_STREAM_FORMAT_INVALID, \
+                        NULL, capture_state_cb, NULL);
+    }
+    else
+    {
+        pcm_config.period_size = period_size;
+        pcm_config.period_count = period_count;
+        pcm_config.flags = 0;
+        pcm_config.num_channels = num_channels;
+        pcm_config.sample_rate = sample_rate;
+        pcm_config.pcm_format = 2;
+        ret = sc_audio_capture_file_prepare(capture_handle, file, SC_AUDIO_STREAM_FORMAT_INVALID, \
+                        &pcm_config, capture_state_cb, NULL);
+    }
+
+    if (SC_ERR_SUCCESS != ret)
+    {
+        error_line = __LINE__;
+        goto exit;
+    }
+
+    ret = sc_audio_capture_record(capture_handle);
+
+    if (SC_ERR_SUCCESS != ret)
+    {
+        error_line = __LINE__;
+        goto exit;
+    }
+
+    return 0;
+
+exit:
+    if (SC_AUDIO_INVALID_HANDLE != capture_handle)
+    {
+        sc_audio_capture_close(capture_handle);
+    }
+    LYINFLOG("player_capture_play_file error_line=%d\n", error_line);
+    return -1;
+}
+
+/********************************************************************
 * @brief: qser_AudPlayer_Pause, pause the audio playback
 * @param hdl [IN]: int, handle for the audio device or stream
 * @return : success 0, failed -1