[Feature] add GA346 baseline version

Change-Id: Ic62933698569507dcf98240cdf5d9931ae34348f
diff --git a/src/lynq/lib/liblynq-media/LICENSE b/src/lynq/lib/liblynq-media/LICENSE
new file mode 100644
index 0000000..77f59ed
--- /dev/null
+++ b/src/lynq/lib/liblynq-media/LICENSE
@@ -0,0 +1,31 @@
+Copyright Statement:
+
+This software/firmware and related documentation ("MediaTek Software") are
+protected under relevant copyright laws. The information contained herein is
+confidential and proprietary to MediaTek Inc. and/or its licensors. Without
+the prior written permission of MediaTek inc. and/or its licensors, any
+reproduction, modification, use or disclosure of MediaTek Software, and
+information contained herein, in whole or in part, shall be strictly
+prohibited.
+
+MediaTek Inc. (C) 2015. All rights reserved.
+
+BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
+RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ON AN "AS-IS" BASIS ONLY. MEDIATEK 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 MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH
+RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK 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 MEDIATEK
+SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE
+RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S
+ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE
+RELEASED HEREUNDER WILL BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE
+MEDIATEK SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+CHARGE PAID BY RECEIVER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
diff --git a/src/lynq/lib/liblynq-media/MODULE_LICENSE_APACHE2 b/src/lynq/lib/liblynq-media/MODULE_LICENSE_APACHE2
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/lynq/lib/liblynq-media/MODULE_LICENSE_APACHE2
diff --git a/src/lynq/lib/liblynq-media/Makefile b/src/lynq/lib/liblynq-media/Makefile
new file mode 100644
index 0000000..e1e1c50
--- /dev/null
+++ b/src/lynq/lib/liblynq-media/Makefile
@@ -0,0 +1,63 @@
+PREFIX   = ../install
+CROSS    = arm-none-linux-
+ROOT     = $(PREFIX)/$(CROSS:%-=%)
+
+#For Yocto use
+
+RFX_TEST_CLIENT = false
+RFX_TEST_AOSP = false
+
+$(warning ########## libvendor_ril BB_TELEFWK_OPTION $(BB_TELEFWK_OPTION) ##########)
+
+		   
+
+SUBDIRS +=  liblynq-media
+
+
+
+
+
+$(warning ########## lynq-rilcmd SUBDIRS  $(SUBDIRS) ##########)
+export SIM_COUNT?=1
+
+.PHONY: all build clean pack_rootfs
+
+all: build
+
+build: clean
+
+clean:
+	$(warning ########## clean ril ##########)
+	for i in $(SUBDIRS); do			\
+		(cd $$i && make clean);			\
+		if [ $$? != 0 ]; then		\
+			exit 1;					\
+		fi							\
+	done
+
+build:
+	$(warning ########## build ril ##########)
+	for i in $(SUBDIRS); do			\
+		(cd $$i && make);			\
+		if [ $$? != 0 ]; then		\
+			exit 1;					\
+		fi							\
+	done
+
+install:
+	$(warning ########## install ril ##########)
+	for i in $(SUBDIRS); do			\
+		(cd $$i && make install);			\
+		if [ $$? != 0 ]; then		\
+			exit 1;					\
+		fi							\
+	done
+
+pack_rootfs:
+	$(warning ########## pack_rootfs ril ##########)
+	for i in $(SUBDIRS); do			\
+		(cd $$i && make pack_rootfs);			\
+		if [ $$? != 0 ]; then		\
+			exit 1;					\
+		fi							\
+	done
diff --git a/src/lynq/lib/liblynq-media/NOTICE b/src/lynq/lib/liblynq-media/NOTICE
new file mode 100644
index 0000000..c5b1efa
--- /dev/null
+++ b/src/lynq/lib/liblynq-media/NOTICE
@@ -0,0 +1,190 @@
+
+   Copyright (c) 2005-2008, The Android Open Source Project
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
diff --git a/src/lynq/lib/liblynq-media/README b/src/lynq/lib/liblynq-media/README
new file mode 100644
index 0000000..9a7e82f
--- /dev/null
+++ b/src/lynq/lib/liblynq-media/README
@@ -0,0 +1,13 @@
+WHAT IT DOES?
+=============
+MTK ril proxy core library
+
+HOW IT WAS BUILT?
+==================
+This module is source code released.
+
+HOW TO USE IT?
+==============
+MTK ril proxy daemon will use this library to communicate with GSM and C2K RILD.
+
+All the source code of this folder were written by MediaTek co..
diff --git a/src/lynq/lib/liblynq-media/include/liblynq-media/lynq_medial.h b/src/lynq/lib/liblynq-media/include/liblynq-media/lynq_medial.h
new file mode 100644
index 0000000..bca19a8
--- /dev/null
+++ b/src/lynq/lib/liblynq-media/include/liblynq-media/lynq_medial.h
@@ -0,0 +1,35 @@
+#ifndef __LYNQ_MEDIA_H__
+#define __LYNQ_MEDIA_H__
+typedef enum {
+     VOLUME_LEVEL1= 1,
+     VOLUME_LEVEL2,
+     VOLUME_LEVEL3,
+     VOLUME_LEVEL4,
+     VOLUME_LEVEL5,
+     VOLUME_LEVEL6,
+     VOLUME_LEVEL7,
+}volume_level_t;
+typedef enum {
+     MIC_VOLUME_LEVEL1= 1,
+     MIC_VOLUME_LEVEL2,
+     MIC_VOLUME_LEVEL3,
+     MIC_VOLUME_LEVEL4,
+     MIC_VOLUME_LEVEL5,
+     MIC_VOLUME_LEVEL6,
+     MIC_VOLUME_LEVEL7,
+}mic_volume_level_t;
+typedef void *MEDIA_HANDLE;
+
+#define VOLUME_MAX 7
+#define VOLUME_MIN 1
+
+int lynq_spk_volume_up();
+int lynq_spk_volume_down();
+int lynq_get_spk_volume();
+int lynq_set_spk_volume(int volume);
+int lynq_set_mic_volume(int volume);
+int lynq_get_mic_volume();
+
+MEDIA_HANDLE lynq_media_play_audio(char *path);
+int lynq_media_stop_audio(MEDIA_HANDLE handle);
+#endif  //__LYNQ_MEDIA_H__
diff --git a/src/lynq/lib/liblynq-media/include/liblynq-media/lynq_modem_voice.h b/src/lynq/lib/liblynq-media/include/liblynq-media/lynq_modem_voice.h
new file mode 100644
index 0000000..dcf301e
--- /dev/null
+++ b/src/lynq/lib/liblynq-media/include/liblynq-media/lynq_modem_voice.h
@@ -0,0 +1,12 @@
+#ifndef __LYNQ_MODEM_VOICE_H__
+#define __LYNQ_MODEM_VOICE_H__
+int lynq_audio_init();//mixer_init
+int lynq_audio_set(int value );//mixer_set
+int lynq_set_modem_volume(int value);//mixer_set_volume
+int lynq_get_modem_volume();//mixer_get_volume
+int lynq_incall_record(char* file_path);
+int lynq_stop_record();
+int lynq_set_call_mute(int mute);//setCallMute
+int lynq_get_call_mute();//getCallMute
+void lynq_reset_mute();//resetMute
+#endif  //__LYNQ_MODEM_VOICE_H__
\ No newline at end of file
diff --git a/src/lynq/lib/liblynq-media/liblynq-media/makefile b/src/lynq/lib/liblynq-media/liblynq-media/makefile
new file mode 100644
index 0000000..100006f
--- /dev/null
+++ b/src/lynq/lib/liblynq-media/liblynq-media/makefile
@@ -0,0 +1,83 @@
+SHELL = /bin/sh
+RM = rm -f
+
+LOCAL_CFLAGS := -Wall \
+                -g -Os \
+                -flto \
+                -fPIC \
+                -DRIL_SHLIB \
+                -DATCI_PARSE \
+                -DKEEP_ALIVE \
+                -DECALL_SUPPORT \
+
+$(warning ################# RITA ROOT: $(ROOT),includedir:$(includedir))
+LOCAL_PATH   = .
+
+LOCAL_C_INCLUDES = \
+  -I. \
+  -I$(ROOT)$(includedir)/logger \
+  -I$(LOCAL_PATH)/../include/liblynq-media \
+  -I$(ROOT)$(includedir)/glib-2.0 \
+  -I$(ROOT)$(libdir)/glib-2.0/include \
+  -I$(ROOT)$(includedir)/gstreamer-1.0 \
+  -I$(ROOT)$(libdir)/gstreamer-1.0/include\
+
+
+
+LOCAL_LIBS := \
+    -L. \
+    -lmtk_audio_mixer_ctrl \
+    -luciwrapper \
+    -ldl \
+    -lstdc++ \
+    -llog \
+    -lcutils \
+    -lutils \
+    -lasound \
+    -lpal \
+    -lpthread \
+    -lgstreamer-1.0 \
+    -lglib-2.0 \
+    -lgstbase-1.0 \
+    -lgstreamer-1.0 \
+    -lgobject-2.0 \
+    -lgio-2.0 \
+    -ldtmf \
+    -lapn \
+
+
+
+SOURCES = $(wildcard *.c wildcard *.h)
+
+EXECUTABLE = liblynq-media.so
+
+OBJECTS=$(SOURCES:.c=.o)
+
+
+.PHONY: build clean install pack_rootfs 
+
+all: build
+$(EXECUTABLE): $(OBJECTS)
+	$(CXX) -shared -Wl,--no-undefined $(OBJECTS) $(LOCAL_LIBS) $(LOCAL_CFLAGS) $(LOCAL_C_INCLUDES) -o $@
+
+%.o : %.c
+	$(CC) $(LOCAL_C_INCLUDES) $(LOCAL_CFLAGS) $(LOCAL_LIBS) -o $@ -c $< 
+
+build:  $(EXECUTABLE)
+	$(warning ########## build $(EXECUTABLE)  ##########)
+
+install:
+	mkdir -p $(ROOT)$(base_libdir)/
+	install $(EXECUTABLE) $(ROOT)$(base_libdir)/
+	mkdir -p $(ROOT)$(includedir)/$(NAME)/sdk
+
+pack_rootfs:
+	mkdir -p $(PACK_INITRAMFS_TO)$(base_libdir)/
+	cp -af $(EXECUTABLE) $(PACK_INITRAMFS_TO)$(base_libdir)/
+	$(CROSS)strip $(PACK_INITRAMFS_TO)$(base_libdir)/$(EXECUTABLE)
+	mkdir -p $(PACK_TO)$(base_libdir)/
+	cp -af $(EXECUTABLE) $(PACK_TO)$(base_libdir)/
+	$(CROSS)strip $(PACK_TO)$(base_libdir)/$(EXECUTABLE)
+.PHONY: clean
+clean:
+	$(RM) $(OBJECTS) $(EXECUTABLE)
diff --git a/src/lynq/lib/liblynq-media/liblynq-media/media_control.c b/src/lynq/lib/liblynq-media/liblynq-media/media_control.c
new file mode 100644
index 0000000..b60ec95
--- /dev/null
+++ b/src/lynq/lib/liblynq-media/liblynq-media/media_control.c
@@ -0,0 +1,373 @@
+#include <stdio.h>

+#include <stdlib.h>

+#include "lynq_medial.h"

+#include <syslog.h>

+#include <gst/gst.h>

+#include <pthread.h>

+#include <cutils/properties.h>

+//#include "modem_afe_ctrl.h"

+#include <log/log.h>

+#define LOG_TAG "MEDIA_API"

+#define NV_VOLUME_NAME    "ro.spk.volume.level"

+#define NV_MIC_VOLUME_NAME    "ro.mic.volume.level"

+//static char *volume_rcv = "/tmp/libmodem-afe-ctrl/server_rcv";

+static const int VOLUME_LEVEL_1 = 0;

+static const int VOLUME_LEVEL_2 = 200;

+static const int VOLUME_LEVEL_3 = 209;

+static const int VOLUME_LEVEL_4 = 220;

+static const int VOLUME_LEVEL_5 = 234;

+static const int VOLUME_LEVEL_6 = 245;

+static const int VOLUME_LEVEL_7 = 255;

+

+static const int MIC_VOLUME_LEVEL_1 = 9;

+static const int MIC_VOLUME_LEVEL_2 = 19;

+static const int MIC_VOLUME_LEVEL_3 = 28;

+static const int MIC_VOLUME_LEVEL_4 = 37;

+static const int MIC_VOLUME_LEVEL_5 = 46;

+static const int MIC_VOLUME_LEVEL_6 = 55;

+static const int MIC_VOLUME_LEVEL_7 = 63;

+

+typedef struct {

+  MEDIA_HANDLE handle;

+  gint mute;		

+  gdouble volume;

+  pthread_t thread;

+  GMainLoop *loop;

+  GstElement *playbin;

+  guint bus_watch_id;

+  GstState gst_cur_state;

+} MEDIA_PARAM_T;

+

+

+static gboolean

+  bus_call (GstBus * bus, GstMessage * msg, gpointer datas)

+  {

+    GstState oldstate, newstate, pending;

+    MEDIA_PARAM_T *param = (MEDIA_PARAM_T *)datas;

+    GMainLoop *loop = param->loop;

+    switch (GST_MESSAGE_TYPE (msg)) {

+      case GST_MESSAGE_EOS:{

+        RLOGD ("End-of-stream\n");

+        g_main_loop_quit (loop);

+        break;

+      }

+      case GST_MESSAGE_STATE_CHANGED:

+        gst_message_parse_state_changed (msg, &oldstate, &newstate, &pending);

+        param->gst_cur_state = newstate;

+        break;

+      case GST_MESSAGE_ERROR:{

+        gchar *debug;

+        GError *err;

+        gst_message_parse_error (msg, &err, &debug);

+        g_printerr ("Debugging info: %s\n", (debug) ? debug : "none");

+        g_free (debug);

+        RLOGD ("Error: %s\n", err->message);

+        g_error_free (err);

+  

+        g_main_loop_quit (loop);

+  

+        break;

+      }

+      default:

+        break;

+    }

+    return TRUE;

+  }

+int lynq_get_mic_current_volume()

+{

+    char  cvolume_levle[5];

+    property_get(NV_MIC_VOLUME_NAME, cvolume_levle, "5");

+	printf("lynq_media_get_current_volume end :%s\n" ,cvolume_levle);

+    return atoi(cvolume_levle);

+	 

+}

+static void lynq_set_mic_volume_to_nvram(int volume_levle )

+{

+    char buf[5];

+    sprintf(buf, "%d", volume_levle);

+    property_set(NV_MIC_VOLUME_NAME, buf);

+

+}

+static int lynq_set_mic_real_volume(int real_volume)

+{

+    char cmd[256];

+    RLOGD("mic real volume: %d \n", real_volume);

+    sprintf(cmd, "amixer -c0 cset name=\"PGA Volume\" %d", real_volume);

+    system(cmd);

+    return 1;

+}

+static int get_mic_real_volume(int volume_levle)

+{

+    int real_volume;

+    switch (volume_levle) {

+    case MIC_VOLUME_LEVEL1:

+        real_volume = MIC_VOLUME_LEVEL_1;

+        break;

+    case MIC_VOLUME_LEVEL2:

+        real_volume = MIC_VOLUME_LEVEL_2;

+        break;

+    case MIC_VOLUME_LEVEL3:

+        real_volume = MIC_VOLUME_LEVEL_3;

+        break;

+    case MIC_VOLUME_LEVEL4:

+        real_volume = MIC_VOLUME_LEVEL_4;

+        break;

+    case MIC_VOLUME_LEVEL5:

+        real_volume = MIC_VOLUME_LEVEL_5;

+        break;

+    case MIC_VOLUME_LEVEL6:

+        real_volume = MIC_VOLUME_LEVEL_6;

+        break;

+    case MIC_VOLUME_LEVEL7:

+        real_volume = MIC_VOLUME_LEVEL_7;

+        break;

+    default:

+        syslog(LOG_ERR, "Not the correct parameter");

+        return 0;

+    } 

+    return real_volume;

+}

+ int lynq_set_mic_volume(int volume) {

+    char cmd[256];

+    int real_volume;

+    if((volume>MIC_VOLUME_LEVEL7)||(volume<MIC_VOLUME_LEVEL1))

+    return 0;

+    lynq_set_mic_volume_to_nvram(volume);

+    real_volume = get_mic_real_volume(volume);

+    lynq_set_mic_real_volume(real_volume);

+    return 1;

+}

+

+int lynq_get_mic_volume() {

+    int mic_cur;

+    mic_cur = lynq_get_mic_current_volume();

+    return mic_cur;

+}

+int lynq_get_spk_current_volume()

+{

+    char  cvolume_levle[5] = {0};

+    property_get(NV_VOLUME_NAME, cvolume_levle, "5");

+    printf("lynq_media_get_current_volume end :%s\n" ,cvolume_levle);

+    return atoi(cvolume_levle);

+	 

+}

+static void lynq_set_spk_volume_to_nvram(int volume_levle )

+{

+    char buf[5] = {0};

+    sprintf(buf, "%d", volume_levle);

+    property_set(NV_VOLUME_NAME, buf);

+}

+static int lynq_set_spk_real_volume(int volume)

+{

+    char cmd[256];

+    RLOGD("spk real volume: %d \n", volume);

+    sprintf(cmd, "amixer -c0 cset name=\"Playback Volume\" %d", volume);

+    system(cmd);

+    return 1;

+}

+static int get_spk_real_volume(int volume_levle)

+{

+    int real_volume;

+    switch (volume_levle) {

+    case VOLUME_LEVEL1:

+        real_volume = VOLUME_LEVEL_1;

+        break;

+    case VOLUME_LEVEL2:

+        real_volume = VOLUME_LEVEL_2;

+        break;

+    case VOLUME_LEVEL3:

+        real_volume = VOLUME_LEVEL_3;

+        break;

+    case VOLUME_LEVEL4:

+        real_volume = VOLUME_LEVEL_4;

+        break;

+    case VOLUME_LEVEL5:

+        real_volume = VOLUME_LEVEL_5;

+        break;

+    case VOLUME_LEVEL6:

+        real_volume = VOLUME_LEVEL_6;

+        break;

+    case VOLUME_LEVEL7:

+        real_volume = VOLUME_LEVEL_7;

+        break;

+    default:

+        syslog(LOG_ERR, "Not the correct parameter");

+        return 0;

+    } 

+    return real_volume;

+}

+int lynq_spk_volume_up()

+{ 

+    int real_volume,current_volume;

+    current_volume = lynq_get_spk_current_volume();

+    if(VOLUME_LEVEL7 == current_volume)

+    {

+        return 1;

+    }

+    else

+    {

+        lynq_set_spk_volume_to_nvram(current_volume+1);

+        real_volume = get_spk_real_volume(current_volume+1);

+        lynq_set_spk_real_volume(real_volume);

+    }

+	

+}

+int lynq_spk_volume_down()

+{   

+    int real_volume,current_volume;

+    current_volume = lynq_get_spk_current_volume();

+	

+    if(VOLUME_LEVEL1 == current_volume)

+    {

+        return 1;

+    }

+    else

+    {

+        lynq_set_spk_volume_to_nvram(current_volume-1);

+        real_volume = get_spk_real_volume(current_volume-1);

+        lynq_set_spk_real_volume(real_volume);

+    }

+	

+}

+

+int lynq_set_spk_volume(int volume)

+{

+    if((volume>VOLUME_LEVEL7)||(volume<VOLUME_LEVEL1))

+    return 0;

+    lynq_set_spk_volume_to_nvram(volume);

+    int real_volume = get_spk_real_volume(volume);

+    lynq_set_spk_real_volume(real_volume);

+    return 1;

+}

+int lynq_get_spk_volume() {

+    int spk_cur;

+    spk_cur = lynq_get_spk_current_volume();

+    return spk_cur;

+}

+

+static int media_stop_full(MEDIA_PARAM_T *param)

+{

+  GMainLoop *loop = param->loop;

+  GstElement *playbin = param->playbin;

+  guint bus_watch_id = param->bus_watch_id;

+  GstEvent *event_stop = NULL;

+  if (param != param->handle) {

+      RLOGE("invalid handle: %p \n", param->handle);

+      return 1;

+  }

+  gst_element_set_state (playbin, GST_STATE_NULL);

+  gst_object_unref (GST_OBJECT (playbin));

+  g_source_remove (bus_watch_id);

+  g_main_loop_unref (loop);

+  param->handle = NULL;	

+  free(param);

+  param = NULL;

+

+}

+

+void* media_thread_func(void *arg)

+{

+    MEDIA_PARAM_T *param = (MEDIA_PARAM_T *)arg;

+    RLOGD("%s start \n", __FUNCTION__);

+    g_main_loop_run (param->loop);

+    RLOGD("g_main_loop_run end \n");

+

+    media_stop_full(param);

+    return ((void *)0);

+}

+ static void start_main_loop(const MEDIA_PARAM_T *param)

+{

+    pthread_attr_t attr; 

+    pthread_attr_init( &attr ); 

+    pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED); 

+    pthread_create(&(param->thread), &attr, (void *)media_thread_func, param);

+}

+

+MEDIA_HANDLE lynq_media_play_audio(char *path)

+{

+

+  GstBus *bus;

+  GstMessage *msg;

+  GMainLoop *loop;

+  GstElement *pipeline,*playbin;

+  gchar *uri;

+  guint bus_watch_id;

+  int ret;

+  pthread_t thread;

+  MEDIA_HANDLE handle = NULL;

+  MEDIA_PARAM_T *param = malloc(sizeof(MEDIA_PARAM_T));

+  if (param == NULL) {

+    RLOGE ("malloc MEDIA_PARAM_T fail \n");;

+  }

+  memset(param, 0, sizeof(MEDIA_PARAM_T));

+  handle = (MEDIA_HANDLE)param;

+  param->mute = 0;

+  param->volume = 1.0;

+  gst_init (NULL, NULL);

+  loop = g_main_loop_new (NULL, FALSE);

+  playbin = gst_element_factory_make ("playbin", "playbin");

+  RLOGD ("main start.\n");

+  pipeline = gst_pipeline_new ("test-pipeline");

+  if (!pipeline || !playbin) {

+    g_printerr ("Not all elements could be created.\n");

+    return -1;

+  }

+

+  if (gst_uri_is_valid (path))

+    uri = g_strdup (path);

+  else

+    uri = gst_filename_to_uri (path, NULL);

+    g_object_set (playbin, "uri", uri, NULL);

+    g_object_set (playbin, "flags",0x42,NULL);

+    g_object_set (playbin, "volume",param->volume,NULL);

+    g_object_set (playbin, "mute",param->mute,NULL);

+    ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);

+    if (ret == GST_STATE_CHANGE_FAILURE) {

+      g_printerr ("Unable to set the pipeline to the playing state.\n");

+      gst_object_unref (pipeline);

+      return -1;

+  }

+  bus = gst_element_get_bus (playbin);

+  bus_watch_id = gst_bus_add_watch (bus, bus_call, (gpointer)param);

+  g_object_unref (bus);

+  param->playbin = playbin;

+  param->bus_watch_id = bus_watch_id;

+  param->thread = thread;

+  param->loop = loop;

+  start_main_loop(param);

+  RLOGD ("gst_bus_add_watch.\n");

+  gst_element_set_state (playbin, GST_STATE_PLAYING);

+  do {

+      if (param->gst_cur_state == GST_STATE_PLAYING)

+      {

+          break;

+      }

+      else

+      {

+         usleep(5000);

+      }

+    } while (1);

+  param->handle = handle;

+  return handle;

+}

+int lynq_media_stop_audio(MEDIA_HANDLE handle)

+{

+    if (handle == NULL) {

+        RLOGE ("%s, handle is NULL\n", __FUNCTION__);

+        return -1;

+    }

+    MEDIA_PARAM_T *param = (MEDIA_PARAM_T *)handle;

+

+    if (handle != param->handle) {

+        RLOGE("invalid handle: %p \n", handle);

+        return 1;

+    }

+

+    g_main_loop_quit (param->loop);

+    pthread_join(param->thread, NULL);

+

+    return 1;

+}

+

+

+

diff --git a/src/lynq/lib/liblynq-media/liblynq-media/modem_voice_control.c b/src/lynq/lib/liblynq-media/liblynq-media/modem_voice_control.c
new file mode 100644
index 0000000..9cedd2e
--- /dev/null
+++ b/src/lynq/lib/liblynq-media/liblynq-media/modem_voice_control.c
@@ -0,0 +1,255 @@
+#include <stdio.h>

+#include <stdlib.h>

+#include "lynq_modem_voice.h"

+#include <syslog.h>

+#include <log/log.h>

+#define LOG_TAG "MEDIA_API"

+#include <dtmf.h>

+#include "mixer_ctrl.h"

+

+const char g_card_name[] = "mtk_phonecall";

+/*for speech on*/

+const char g_mixer_name[] = "Speech_on";

+const char g_mixer_name_volume[] = "DL Call Playback Volume";

+const char g_DL_mute_name[] = "Speech_DL_mute";

+const char g_UL_mute_name[] = "Speech_UL_mute";

+GstElement *pipeline_element;

+static int inCallRecordMode = 0;

+static int gst_status = 0;

+

+ int lynq_audio_init() //mixer_init

+{

+    int ret;

+

+    // only need to set card name once

+    ret = set_card_name(g_card_name);

+    if (ret)

+        RLOGE("set_card_name err: %d", ret);

+    return ret;

+}

+

+ int lynq_audio_set(int value )//mixer_set

+{

+    int ret;

+

+     //set mixer ctl to om:1 or off:0

+    ret = set_mixer_ctrl_value_int(g_mixer_name, value);

+    if (ret)

+        RLOGE("set_mixer_ctrl_value_int g_mixer_name err: %d", ret);

+    return ret;

+}

+/*

+int mixer_reset_set(int value )

+{

+    int ret;

+

+    // set mixer  to reset:1

+    ret = set_mixer_ctrl_value_int(g_mixer_reset_name, value);

+    if (ret)

+        RLOGE("set_mixer_ctrl_value_int g_mixer_reset_name err: %d", ret);

+    return ret;

+}*/

+

+

+

+

+

+int lynq_set_spk_modem_volume(int value)//mixer_set_volume

+{

+    int ret;

+  //  if (get_audio_path() == 0) {

+        ret = set_mixer_ctrl_volume_value(g_mixer_name_volume, value);

+   // } else {

+   //     ret = set_mixer_ctrl_volume_value(g_mixer_name_volume_bt, value);

+   // }

+    if (ret)

+        RLOGE("set_mixer_ctrl_volume_value_int err: %d", ret);

+    return ret;

+}

+

+

+ int lynq_get_spk_modem_volume()//mixer_get_volume

+{

+    long int vol_value;

+  //  if (get_audio_path() == 0) {

+        vol_value = get_mixer_ctrl_volume_value(g_mixer_name_volume);

+   // } else {

+   //     vol_value = get_mixer_ctrl_volume_value(g_mixer_name_volume_bt);

+   // }

+    RLOGD("The ctrl \"%s\" is set to %d", g_mixer_name_volume, vol_value);

+    return vol_value;

+}

+

+static int GSM_Init(char* filepath){

+    GstElement *pipeline, *source, *mux, *encoder, *sink;

+    RLOGD("[GSM]GSM Init Start!");

+    /* Initialisation */

+    gst_init (NULL, NULL);

+

+    pipeline = gst_pipeline_new ("3gppmux-test");

+    source   = gst_element_factory_make ("pulsesrc",       "file-source");

+    encoder  = gst_element_factory_make ("faac",           "encoder");

+    mux      = gst_element_factory_make ("3gppmux",        "muxer");

+    sink     = gst_element_factory_make ("filesink",       "output");

+

+    g_object_set(mux, "fragment-duration", 100, NULL);

+    g_object_set(sink, "location", filepath, NULL);

+

+    if (!pipeline || !source || !encoder || !mux || !sink) {

+        if(pipeline) {

+            gst_object_unref (GST_OBJECT (pipeline));

+            pipeline = NULL;

+        }

+        if(source) {

+            gst_object_unref (GST_OBJECT (source));

+            source = NULL;

+        }

+        if(encoder) {

+            gst_object_unref (GST_OBJECT (encoder));

+            encoder = NULL;

+        }

+        if(mux) {

+            gst_object_unref (GST_OBJECT (mux));

+            mux = NULL;

+        }

+        if(sink) {

+            gst_object_unref (GST_OBJECT (sink));

+            sink = NULL;

+        }

+        RLOGE ("[GSM]One element could not be created. Exiting");

+        return -1;

+    }

+

+    gst_bin_add_many (GST_BIN (pipeline), source, encoder, mux, sink, NULL);

+    gst_element_link_many (source, encoder, mux, sink, NULL);

+

+    pipeline_element = pipeline;

+    gst_status = 1; //initial done

+    RLOGD("[GSM]GSM Init Done!");

+    return 0;

+}

+static int GSM_Start(void)

+{

+    RLOGD("[GSM]GSM Start start!");

+    if(gst_status == 2)

+        return 0;

+

+    if(gst_status == 1 || gst_status ==3) {

+        GstStateChangeReturn ret = gst_element_set_state (pipeline_element, GST_STATE_PLAYING);

+

+        RLOGD("[GSM]Running... return: %d", ret);

+        //g_main_loop_run (gst_loop);

+        gst_status = 2; //start done

+    } else {

+        return -1;

+    }

+    RLOGD("[GSM]GSM Start End!");

+    return 0;

+}

+

+static int GSM_Stop()

+{

+    RLOGD("[GSM]GSM Stop Start!");

+    if (gst_status == 4)

+        return 0;

+

+    if(gst_status == 2 || gst_status == 3) {

+    /* Out of the main loop, clean up nicely */

+        gboolean isSend = gst_element_send_event (pipeline_element, gst_event_new_eos ());

+        GstStateChangeReturn ret = gst_element_set_state (pipeline_element, GST_STATE_NULL);

+        RLOGD("[GSM]Returned, stopping playback. ret: %d, isSend: %d", ret, isSend);

+        gst_status = 4;

+    } else {

+        return -1;

+    }

+    RLOGD("[GSM]GSM Stop End!");

+    return 0;

+}

+static int GSM_Close()

+{

+    RLOGD("[GSM]Deleting pipeline");

+    gst_object_unref (GST_OBJECT (pipeline_element));

+    gst_deinit ();

+    gst_status = 0;

+    RLOGD("[GSM]GSM Close Done!");

+    return 0;

+}

+int lynq_incall_record(char* file_path)

+{

+	RLOGD("start GSM!");

+	if(-1 != GSM_Init(file_path) && -1 != GSM_Start()) {

+		inCallRecordMode = 1;

+		RLOGW("inCallRecord Start OK!");

+	}else{

+		inCallRecordMode = 0;

+		return 1;

+		RLOGW("[error],inCallRecord Start fail!");

+	}

+

+    return 0;

+}

+int lynq_stop_record()

+{

+    RLOGD("After Handup, stop record! Before Record is %s",inCallRecordMode ? "Enable" : "Disable");

+    if (inCallRecordMode == 1) {

+         if(!(-1 != GSM_Stop() && -1 != GSM_Close()))

+            RLOGW("[error],inCallRecord fail!");

+

+         inCallRecordMode = 0;

+        /*From GSM report stop_record to PulseAudio send record_off  need 15ms. so after stop record delay 30ms*/

+         usleep(30*1000);

+         return 1;

+    }

+    return 0;

+}

+

+static int mixer_set_mute(int path, int value)

+{

+    RLOGD("mixer_set_mute path: %d , value: %d", path, value);

+    int ret;

+    /* DL:0 UL:1 */

+    if (path == 0) {

+        ret = set_mixer_ctrl_value_int(g_DL_mute_name, value);

+    } else {

+        ret = set_mixer_ctrl_value_int(g_UL_mute_name, value);

+    }

+    if (ret) {

+        RLOGE("set_mixer_ctrl_volume_value_int err: %d", ret);

+    }

+    return ret;

+}

+

+static long int mixer_get_mute(int path)

+{

+    long int is_mute;

+

+    /* DL:0 UL:1 */

+    if (path == 0) {

+        is_mute = get_mixer_ctrl_value_int(g_DL_mute_name);

+        RLOGD("The ctrl \"%s\" is set to %d", g_DL_mute_name, is_mute);

+    } else {

+        is_mute = get_mixer_ctrl_value_int(g_UL_mute_name);

+        RLOGD("The ctrl \"%s\" is set to %d", g_UL_mute_name, is_mute);

+    }

+

+    return is_mute;

+}

+ int lynq_set_call_mute(int mute) {

+    RLOGD("setCallMute: %d", mute);

+    return mixer_set_mute(1, (mute ? 1: 0));

+}

+

+int lynq_get_call_mute() {

+    long int cc_mute = mixer_get_mute(1);

+    RLOGD("getCallMute: %d", cc_mute);

+    return cc_mute;

+}

+

+

+void lynq_reset_mute() {

+    if (lynq_get_call_mute() > 0) {

+        lynq_set_call_mute(0);

+    }

+}

+

+