update realtek patch: 20161222_TV_ANDROID_7.x_COEX_8723BS-B664a_8723BU-B664a
authorhwg <hwg@rock-chips.com>
Wed, 4 Jan 2017 08:04:52 +0000 (16:04 +0800)
committerhwg <hwg@rock-chips.com>
Wed, 4 Jan 2017 08:05:28 +0000 (16:05 +0800)
Change-Id: I19585acc8056559607d7cb2005fad6622fff1184

41 files changed:
rtkbt/addon/bee1/addon.mk
rtkbt/addon/bee1/system/usr/keylayout/Vendor_005d_Product_0001.kl [new file with mode: 0755]
rtkbt/addon/rtkbtAutoPairUIDemo/AndroidManifest.xml [new file with mode: 0755]
rtkbt/addon/rtkbtAutoPairUIDemo/res/drawable-hdpi/ic_launcher.png [new file with mode: 0755]
rtkbt/addon/rtkbtAutoPairUIDemo/res/drawable-ldpi/ic_launcher.png [new file with mode: 0755]
rtkbt/addon/rtkbtAutoPairUIDemo/res/drawable-mdpi/ic_launcher.png [new file with mode: 0755]
rtkbt/addon/rtkbtAutoPairUIDemo/res/drawable-xhdpi/ic_launcher.png [new file with mode: 0755]
rtkbt/addon/rtkbtAutoPairUIDemo/res/values-v11/styles.xml [new file with mode: 0755]
rtkbt/addon/rtkbtAutoPairUIDemo/res/values-v14/styles.xml [new file with mode: 0755]
rtkbt/addon/rtkbtAutoPairUIDemo/res/values-zh-rCN/strings.xml [new file with mode: 0755]
rtkbt/addon/rtkbtAutoPairUIDemo/res/values-zh-rCN/styles.xml [new file with mode: 0755]
rtkbt/addon/rtkbtAutoPairUIDemo/res/values/strings.xml [new file with mode: 0755]
rtkbt/addon/rtkbtAutoPairUIDemo/res/values/styles.xml [new file with mode: 0755]
rtkbt/addon/rtkbtAutoPairUIDemo/src/com/android/rtkbtAutoPairUIDemo/rtkbtAutoPairUIDemoReceiver.java [new file with mode: 0755]
rtkbt/addon/vr_bee1_hidraw_daemon/hidraw/bee_settings.h
rtkbt/addon/vr_bee1_hidraw_daemon/hidraw/config.c
rtkbt/addon/vr_bee1_hidraw_daemon/hidraw/config.h
rtkbt/addon/vr_bee1_hidraw_daemon/hidraw/get_voice_app.c
rtkbt/addon/vr_bee1_hidraw_daemon/hidraw/get_voice_app.h
rtkbt/addon/vr_bee1_hidraw_daemon/hidraw/voice_hidraw.c
rtkbt/addon/vr_bee1_hidraw_daemon/hidraw/voice_hidraw.h
rtkbt/addon/vr_bee1_hidraw_daemon/system/etc/hidraw_setting
rtkbt/addon/vr_bee2_hidraw_daemon/hidraw/bee_settings.h
rtkbt/addon/vr_bee2_hidraw_daemon/hidraw/config.c
rtkbt/addon/vr_bee2_hidraw_daemon/hidraw/config.h
rtkbt/addon/vr_bee2_hidraw_daemon/hidraw/get_voice_app.c
rtkbt/addon/vr_bee2_hidraw_daemon/hidraw/get_voice_app.h
rtkbt/addon/vr_bee2_hidraw_daemon/hidraw/voice_hidraw.c
rtkbt/addon/vr_bee2_hidraw_daemon/hidraw/voice_hidraw.h
rtkbt/addon/vr_bee2_hidraw_daemon/system/etc/hidraw_setting
rtkbt/code/bt/realtek/src/rtkbt_api.c
rtkbt/code/libbt-vendor/uart/src/bt_vendor_rtk.c
rtkbt/rtkbt.mk
rtkbt/system/etc/bluetooth/rtkbt.conf
rtkbt/system/etc/firmware/rtl8723d_config
rtkbt/system/etc/firmware/rtl8723d_fw
rtkbt/system/etc/firmware/rtl8723ds_fw
rtkbt/system/etc/firmware/rtl8821c_config
rtkbt/system/etc/firmware/rtl8821cs_config
rtkbt/system/etc/firmware/rtl8822b_config
rtkbt/system/etc/firmware/rtl8822bs_config

index f98f886e040acd20e834038b88151eb579677c73..91e0b0aca6b4dcfa7ec9c1b9da9a9786e2273f10 100755 (executable)
@@ -2,6 +2,6 @@ PRODUCT_COPY_FILES += \
     $(LOCAL_PATH)/system/etc/bluetooth/rtkbt_plugins.conf:system/etc/bluetooth/rtkbt_plugins.conf \
     $(LOCAL_PATH)/system/etc/bluetooth/rtkbt_autopair_config.xml:system/etc/bluetooth/rtkbt_autopair_config.xml \
     $(LOCAL_PATH)/system/etc/bluetooth/rtkbt_plugin_autopair_stack.conf:system/etc/bluetooth/rtkbt_plugin_autopair_stack.conf \
-    $(LOCAL_PATH)/system/usr/keylayout/rtkbt_vhid_Vid_005d_Pid_0001.kl:system/usr/keylayout/rtkbt_vhid_Vid_005d_Pid_0001.kl \
+    $(LOCAL_PATH)/system/usr/keylayout/Vendor_005d_Product_0001.kl:system/usr/keylayout/Vendor_005d_Product_0001.kl \
     $(LOCAL_PATH)/system/etc/bluetooth/rtkbt_plugin_vr_bee1_hidraw.conf:system/etc/bluetooth/rtkbt_plugin_vr_bee1_hidraw.conf \
 
diff --git a/rtkbt/addon/bee1/system/usr/keylayout/Vendor_005d_Product_0001.kl b/rtkbt/addon/bee1/system/usr/keylayout/Vendor_005d_Product_0001.kl
new file mode 100755 (executable)
index 0000000..c76e12f
--- /dev/null
@@ -0,0 +1,34 @@
+# Copyright (C) 2010 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.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# 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.
+
+#
+# Generic key layout file for full alphabetic US English PC style external keyboards.
+#
+# This file is intentionally very generic and is intended to support a broad rang of keyboards.
+# Do not edit the generic key layout to support a specific keyboard; instead, create
+# a new key layout file with the required keyboard configuration.
+#
+
+key 1     ESCAPE
+key 28    ENTER
+key 63    F5
+key 102   HOME
+key 103   DPAD_UP
+key 105   DPAD_LEFT
+key 106   DPAD_RIGHT
+key 108   DPAD_DOWN
+key 114   VOLUME_DOWN
+key 115   VOLUME_UP
+key 116   POWER
+key 130   MENU
diff --git a/rtkbt/addon/rtkbtAutoPairUIDemo/AndroidManifest.xml b/rtkbt/addon/rtkbtAutoPairUIDemo/AndroidManifest.xml
new file mode 100755 (executable)
index 0000000..293b2ff
--- /dev/null
@@ -0,0 +1,24 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.realtek.rtkbt.AutoPairUIDemo"
+    android:versionCode="1"
+    android:versionName="1.0">
+
+    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />
+    <uses-permission android:name="android.permission.BLUETOOTH"/>
+       <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
+       <uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED"/>
+       <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
+
+    <application android:label="@string/app_name"
+        android:icon="@drawable/ic_launcher"
+        android:theme="@style/AppTheme">
+
+        <receiver android:name="rtkbtAutoPairUIDemoReceiver">
+            <intent-filter>
+                <action android:name="com.realtek.autopair.message" />
+            </intent-filter>
+        </receiver>
+
+    </application>
+
+</manifest>
diff --git a/rtkbt/addon/rtkbtAutoPairUIDemo/res/drawable-hdpi/ic_launcher.png b/rtkbt/addon/rtkbtAutoPairUIDemo/res/drawable-hdpi/ic_launcher.png
new file mode 100755 (executable)
index 0000000..a301d57
Binary files /dev/null and b/rtkbt/addon/rtkbtAutoPairUIDemo/res/drawable-hdpi/ic_launcher.png differ
diff --git a/rtkbt/addon/rtkbtAutoPairUIDemo/res/drawable-ldpi/ic_launcher.png b/rtkbt/addon/rtkbtAutoPairUIDemo/res/drawable-ldpi/ic_launcher.png
new file mode 100755 (executable)
index 0000000..2c2a58b
Binary files /dev/null and b/rtkbt/addon/rtkbtAutoPairUIDemo/res/drawable-ldpi/ic_launcher.png differ
diff --git a/rtkbt/addon/rtkbtAutoPairUIDemo/res/drawable-mdpi/ic_launcher.png b/rtkbt/addon/rtkbtAutoPairUIDemo/res/drawable-mdpi/ic_launcher.png
new file mode 100755 (executable)
index 0000000..f91f736
Binary files /dev/null and b/rtkbt/addon/rtkbtAutoPairUIDemo/res/drawable-mdpi/ic_launcher.png differ
diff --git a/rtkbt/addon/rtkbtAutoPairUIDemo/res/drawable-xhdpi/ic_launcher.png b/rtkbt/addon/rtkbtAutoPairUIDemo/res/drawable-xhdpi/ic_launcher.png
new file mode 100755 (executable)
index 0000000..96095ec
Binary files /dev/null and b/rtkbt/addon/rtkbtAutoPairUIDemo/res/drawable-xhdpi/ic_launcher.png differ
diff --git a/rtkbt/addon/rtkbtAutoPairUIDemo/res/values-v11/styles.xml b/rtkbt/addon/rtkbtAutoPairUIDemo/res/values-v11/styles.xml
new file mode 100755 (executable)
index 0000000..d408cbc
--- /dev/null
@@ -0,0 +1,5 @@
+<resources>
+
+    <style name="AppTheme" parent="android:Theme.Holo.Light" />
+
+</resources>
\ No newline at end of file
diff --git a/rtkbt/addon/rtkbtAutoPairUIDemo/res/values-v14/styles.xml b/rtkbt/addon/rtkbtAutoPairUIDemo/res/values-v14/styles.xml
new file mode 100755 (executable)
index 0000000..1c089a7
--- /dev/null
@@ -0,0 +1,5 @@
+<resources>
+
+    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar" />
+
+</resources>
\ No newline at end of file
diff --git a/rtkbt/addon/rtkbtAutoPairUIDemo/res/values-zh-rCN/strings.xml b/rtkbt/addon/rtkbtAutoPairUIDemo/res/values-zh-rCN/strings.xml
new file mode 100755 (executable)
index 0000000..729693d
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<resources>
+    <string name="app_name">"BluetoothRTKAutoPairService"</string>
+    <string name="found">"找到遥控器设备,开始自动配对,请勿操作遥控器"</string>
+    <string name="removebond_timeout">"删除之前配对信息操作超时,失败!"</string>
+    <string name="ble_pair_success">"LE模式遥控器配对成功"</string>
+    <string name="ble_pair_fail">"LE模式遥控器配对失败"</string>
+    <string name="ble_pair_timeout">"LE模式遥控器配对超时,失败!"</string>
+    <string name="ble_sdp_success">"LE模式遥控器搜索服务(SDP)成功"</string>
+    <string name="ble_sdp_fail">"LE模式遥控器搜索服务(SDP)失败"</string>
+    <string name="classic_pair_success">"BR/EDR模式遥控器配对成功"</string>
+    <string name="classic_pair_fail">"BR/EDR模式遥控器配对失败"</string>
+    <string name="classic_pair_timeout">"BR/EDR模式遥控器配对超时,失败!"</string>
+    <string name="classic_sdp_success">"BR/EDR模式遥控器搜索服务(SDP)成功"</string>
+    <string name="classic_sdp_fail">"BR/EDR模式遥控器搜索服务(SDP)失败"</string>
+    <string name="over">"遥控器可以开始使用了!"</string>
+    <string name="connect_to_device">"遥控器配对已完成,正在连接遥控器,请勿操作遥控器"</string>
+    <string name="error_weak_signal">"请将遥控器靠近电视,等待自动配对!"</string>
+    <string name="remove_bond">解除遥控器配对</string>
+    <string name="auto_pair_stop">自动配对超时结束!</string>
+</resources>
diff --git a/rtkbt/addon/rtkbtAutoPairUIDemo/res/values-zh-rCN/styles.xml b/rtkbt/addon/rtkbtAutoPairUIDemo/res/values-zh-rCN/styles.xml
new file mode 100755 (executable)
index 0000000..4dba0d0
--- /dev/null
@@ -0,0 +1,5 @@
+<resources>
+
+    <style name="AppTheme" parent="android:Theme.Light" />
+
+</resources>
\ No newline at end of file
diff --git a/rtkbt/addon/rtkbtAutoPairUIDemo/res/values/strings.xml b/rtkbt/addon/rtkbtAutoPairUIDemo/res/values/strings.xml
new file mode 100755 (executable)
index 0000000..8898ccc
--- /dev/null
@@ -0,0 +1,24 @@
+<resources>
+    <string name="app_name">BluetoothRTKAutoPairService</string>
+    <string name="found">Found Remote Controller,Start BLE Pair Process. Please Do not operate remoter!</string>
+
+    <string name="removebond_timeout">Remove Old Pair Data Timeout</string>
+
+    <string name="ble_pair_success">BLE Pair Success</string>
+    <string name="ble_pair_fail">BLE Pair Fail</string>
+    <string name="ble_pair_timeout">BLE Pair Timeout</string>
+    <string name="ble_sdp_success">BLE SDP Success</string>
+    <string name="ble_sdp_fail">BLE SDP Fail</string>
+
+    <string name="classic_pair_success">Classic Pair Success</string>
+    <string name="classic_pair_fail">Classic Pair Fail</string>
+    <string name="classic_pair_timeout">Classic Pair Timeout</string>
+    <string name="classic_sdp_success">Classic SDP Success</string>
+    <string name="classic_sdp_fail">Classic SDP Fail</string>
+
+    <string name="connect_to_device">Remote Controller is paired, please wait to connect!</string>
+    <string name="over">Remote Controller can be used</string>
+    <string name="error_weak_signal">Please keep Remote Controller close to the TV, wait for autopair!</string>
+    <string name="remove_bond">remove the bond of the remoter</string>
+    <string name="auto_pair_stop">Auto pair stop!</string>
+</resources>
diff --git a/rtkbt/addon/rtkbtAutoPairUIDemo/res/values/styles.xml b/rtkbt/addon/rtkbtAutoPairUIDemo/res/values/styles.xml
new file mode 100755 (executable)
index 0000000..4dba0d0
--- /dev/null
@@ -0,0 +1,5 @@
+<resources>
+
+    <style name="AppTheme" parent="android:Theme.Light" />
+
+</resources>
\ No newline at end of file
diff --git a/rtkbt/addon/rtkbtAutoPairUIDemo/src/com/android/rtkbtAutoPairUIDemo/rtkbtAutoPairUIDemoReceiver.java b/rtkbt/addon/rtkbtAutoPairUIDemo/src/com/android/rtkbtAutoPairUIDemo/rtkbtAutoPairUIDemoReceiver.java
new file mode 100755 (executable)
index 0000000..f936030
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2015 The Realtek Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+
+package com.realtek.rtkbt.AutoPairUIDemo;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothRtkbt;
+import android.bluetooth.BluetoothDevice;
+import android.util.Log;
+import android.widget.Toast;
+import android.util.Log;
+import java.util.HashMap;
+
+
+/*
+ *BluetoothRTKAutoPairBroadcastReceiver sync state with bluetooth,
+ *STATE_ON start BluetoothRTKAutoPairService
+ *STATE_TURNING_OFF stop BluetoothRTKAutoPairService
+ */
+
+
+public class rtkbtAutoPairUIDemoReceiver extends BroadcastReceiver {
+    private static final String TAG = "<===AutoPairUIDemoReceiver===>";
+    private static final boolean RTK_DBG = true;
+    private static final String RTKBT_AUTOPAIR_MESSAGE = "com.realtek.autopair.message";
+    private static final String RTKBT_AUTOPAIR_MESSAGE_FIELD_RCUADDR = "com.realtek.autopair.message.rcuaddr";
+    private static final String RTKBT_AUTOPAIR_MESSAGE_FIELD_MESSAGE_ID = "com.realtek.autopair.message.id";
+    private static final String RTKBT_AUTOPAIR_MESSAGE_FIELD_DATA = "com.realtek.autopair.message.data";
+
+    private static final int RTKBT_AUTOPAIR_State_Idle                     = 0;
+    private static final int RTKBT_AUTOPAIR_State_Found                    = 1;
+    private static final int RTKBT_AUTOPAIR_State_RemoveBond               = 2;
+    private static final int RTKBT_AUTOPAIR_State_BLEBond                  = 3;
+    private static final int RTKBT_AUTOPAIR_State_ClassicBond              = 4;
+    private static final int RTKBT_AUTOPAIR_State_SaveNewRCU               = 5;
+    private static final int RTKBT_AUTOPAIR_State_PairSuccess_to_connect   = 6;
+    private static final int RTKBT_AUTOPAIR_State_ConnectSuccess           = 7;
+
+    private static final int RTKBT_AUTOPAIR_State_PairFail                 = 0x101;
+    private static final int RTKBT_AUTOPAIR_State_PairTimeout              = 0x102;
+    private static final int RTKBT_AUTOPAIR_State_ConnectFail              = 0x103;
+
+    @Override
+    public void onReceive(Context context, Intent intent) {
+        Log.i(TAG, "receive intent:" + intent.getAction());
+
+        if(intent.getAction().equals(RTKBT_AUTOPAIR_MESSAGE)) {
+            Log.d(TAG, "RTKBT_AUTOPAIR_MESSAGE: ID:"+intent.getIntExtra(RTKBT_AUTOPAIR_MESSAGE_FIELD_MESSAGE_ID, 0)+" ADDR:"+intent.getStringExtra(RTKBT_AUTOPAIR_MESSAGE_FIELD_RCUADDR)+" DATA:"+intent.getByteArrayExtra(RTKBT_AUTOPAIR_MESSAGE_FIELD_DATA));
+            ShowMessage(context, intent);
+        }
+    }
+    private void ShowMessage(Context context, Intent intent)
+    {
+        int message_id = intent.getIntExtra(RTKBT_AUTOPAIR_MESSAGE_FIELD_MESSAGE_ID, 0);
+        String rcuaddr = intent.getStringExtra(RTKBT_AUTOPAIR_MESSAGE_FIELD_RCUADDR);
+        byte[] data =intent.getByteArrayExtra(RTKBT_AUTOPAIR_MESSAGE_FIELD_DATA);
+        switch(message_id)
+        {
+            case RTKBT_AUTOPAIR_State_Found:
+                Toast.makeText(context,"Found RCU("+rcuaddr+")",Toast.LENGTH_LONG).show();
+                break;
+            case RTKBT_AUTOPAIR_State_RemoveBond:
+                Toast.makeText(context,"RCU("+rcuaddr+") Remove Old RCU Bonding Info",Toast.LENGTH_LONG).show();
+                break;
+            case RTKBT_AUTOPAIR_State_BLEBond:
+                Toast.makeText(context,"RCU("+rcuaddr+") Start BLE Bonding",Toast.LENGTH_LONG).show();
+                break;
+            case RTKBT_AUTOPAIR_State_ClassicBond:
+                Toast.makeText(context,"RCU("+rcuaddr+") Start BREDR Bonding",Toast.LENGTH_LONG).show();
+                break;
+            case RTKBT_AUTOPAIR_State_SaveNewRCU:
+                Toast.makeText(context,"RCU("+rcuaddr+") Save New RCU Bonding Info",Toast.LENGTH_LONG).show();
+                break;
+            case RTKBT_AUTOPAIR_State_PairSuccess_to_connect:
+                Toast.makeText(context,"RCU("+rcuaddr+") Connecting to RCU",Toast.LENGTH_LONG).show();
+                break;
+            case RTKBT_AUTOPAIR_State_ConnectSuccess:
+                Toast.makeText(context,"RCU("+rcuaddr+") Connected to RCU, Pair success",Toast.LENGTH_LONG).show();
+                break;
+            case RTKBT_AUTOPAIR_State_PairFail:
+                Toast.makeText(context,"RCU("+rcuaddr+") Pair Failed",Toast.LENGTH_LONG).show();
+                break;
+            case RTKBT_AUTOPAIR_State_PairTimeout:
+                Toast.makeText(context,"RCU("+rcuaddr+") Pair Timeout",Toast.LENGTH_LONG).show();
+                break;
+            case RTKBT_AUTOPAIR_State_ConnectFail:
+                Toast.makeText(context,"RCU("+rcuaddr+") Connect Fail",Toast.LENGTH_LONG).show();
+                break;
+        }
+    }
+}
index 9135f8378b27eec4b2f21dc92f6f2c5360a1938d..ea2d44890e449eab561365e56f12180b2a96491b 100755 (executable)
@@ -1,35 +1,35 @@
-#ifndef BEE_SETTINGS_H
-#define BEE_SETTINGS_H
-
-#define BEE_RCU_VID (0x005D)
-#define BEE_RCU_PID (0x0001)
-#define BEE_RCU_VERSION (0x0000)
-
-#define BEE_VOICEKEY_LEN 8
-
-#define BEE_VOICEKEY_REPORTID (0x01)
-
-unsigned char BEE_VOICE_KEYDOWN_DATA[BEE_VOICEKEY_LEN] = {0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00};
-unsigned char BEE_VOICE_KEYUP_DATA[BEE_VOICEKEY_LEN] = {0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
-
-//msbc
-#define BEE_MSBC_VOICEDATA_REPORTID     (0x5A)
-#define BEE_MSBC_VOICECMD_REPORTID      (0x5A)
-
-
-#define BEE_MSBC_ATT_FRAME_SIZE         120
-#define BEE_MSBC_FRAME_SIZE             60
-#define BEE_MSBC_DECODE_INPUT_SIZE      58
-#define BEE_MSBC_DECODE_OUTPUT_SIZE     240
-
-//sbc
-#define BEE_SBC_VOICEDATA_REPORTID      (0x5B)
-#define BEE_SBC_VOICECMD_REPORTID       (0x5B)
-
-#define BEE_SBC_ATT_FRAME_SIZE          72
-#define BEE_SBC_FRAME_SIZE              36
-
-#define BEE_SBC_DECODE_INPUT_SIZE      36
-#define BEE_SBC_DECODE_OUTPUT_SIZE     256
-
-#endif
+#ifndef BEE_SETTINGS_H\r
+#define BEE_SETTINGS_H\r
+\r
+#define BEE_RCU_VID (0x005D)\r
+#define BEE_RCU_PID (0x0001)\r
+#define BEE_RCU_VERSION (0x0000)\r
+\r
+#define BEE_VOICEKEY_LEN 8\r
+\r
+#define BEE_VOICEKEY_REPORTID (0x01)\r
+\r
+unsigned char BEE_VOICE_KEYDOWN_DATA[BEE_VOICEKEY_LEN] = {0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00};\r
+unsigned char BEE_VOICE_KEYUP_DATA[BEE_VOICEKEY_LEN] = {0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};\r
+\r
+//msbc\r
+#define BEE_MSBC_VOICEDATA_REPORTID     (0x5A)\r
+#define BEE_MSBC_VOICECMD_REPORTID      (0x5A)\r
+\r
+\r
+#define BEE_MSBC_ATT_FRAME_SIZE         120\r
+#define BEE_MSBC_FRAME_SIZE             60\r
+#define BEE_MSBC_DECODE_INPUT_SIZE      58\r
+#define BEE_MSBC_DECODE_OUTPUT_SIZE     240\r
+\r
+//sbc\r
+#define BEE_SBC_VOICEDATA_REPORTID      (0x5B)\r
+#define BEE_SBC_VOICECMD_REPORTID       (0x5B)\r
+\r
+#define BEE_SBC_ATT_FRAME_SIZE          72\r
+#define BEE_SBC_FRAME_SIZE              36\r
+\r
+#define BEE_SBC_DECODE_INPUT_SIZE      36\r
+#define BEE_SBC_DECODE_OUTPUT_SIZE     256\r
+\r
+#endif
\ No newline at end of file
index e56e8c5ba740e0e712e716dad98ac3fdd348c6cc..17e5e177d92647c72048e3d6e083ee769f501024 100755 (executable)
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <cutils/log.h>
-
-#include "config.h"
-
-
-tVoice_Hidraw_Settings *gConfig = NULL;
-static char * gContent = NULL;
-
-
-static char * voice_conf_getline(char * head, char ** left)
-{
-    char * next;
-    if(*head == 0)
-        return NULL;
-    while((*head == '\r')||(*head == '\n'))
-        head++;
-    if(*head == 0)
-        return NULL;
-    next = head;
-    while((*next != '\r')&&(*next != '\n')&&(*next != 0))
-        next++;
-    if(*next != 0)
-        *next++ = 0;
-    *left = next;
-    return head;
-}
-
-static void voice_conf_parse_config(tVoice_Hidraw_Settings **items, char *content)
-{
-    char * group = NULL;
-    char * item = NULL;
-    char * val = NULL;
-    char * line = NULL;
-    int id = -1;
-    tVoice_Hidraw_Settings* entry, * head, *end;
-
-    char * p;
-    int i = 0;
-
-    head = NULL;
-    end = NULL;
-
-    ALOGD("voice_conf_parse_config\n");
-    while((line = voice_conf_getline(content, &content)) != NULL)
-    {
-        ALOGD("voice_conf_parse_config line:%s\n", line);
-        switch(line[0])
-        {
-            case '[':
-            {
-                p = strstr(line,"]");
-                if(p)
-                {
-                    *p = 0;
-                    group = &(line[1]);
-                    ALOGI("voice_conf_parse_config Find Group[%s]\n", group);
-                }else{
-                    ALOGW("voice_conf_parse_config Expected ']' end of Group(%s)!\n", line);
-                }
-                break;
-            }
-            case '#':
-            {
-                break;
-            }
-            default:
-            {
-                p = strstr(line,"=");
-                if(p)
-                {
-                    *p++ = 0;
-                    item = line;
-                    val = p;
-                    if((item[0]==0)||(val[0]==0))
-                    {
-                        ALOGI("voice_conf_parse_config ignore(item:%s val:%s)\n", item[0]?item:"(null)", val[0]?val:"(null)");
-                        break;
-                    }
-                    ALOGI("voice_conf_parse_config Find Item[%s:%s=%s]\n", group, item, val);
-                    entry = malloc(sizeof(tVoice_Hidraw_Settings));
-                    if(entry)
-                    {
-                        entry->next = NULL;
-                        entry->group = group;
-                        entry->item = item;
-                        entry->val = val;
-                        if(end)
-                        {
-                            end->next = entry;
-                            end = entry;
-                        }else
-                            end = entry;
-                        if(head == NULL)
-                            head = entry;
-                    }
-                }
-            }
-        }
-    }
-    *items = head;
-}
-
-
-int voice_loadconfig(char * path)
-{
-    int i,res,fd;
-    struct stat st;
-    char * content = NULL;
-    struct tVoice_Hidraw_Settings* config = NULL;
-
-    ALOGI("voice_loadconfig(%s) load!\n", path);
-    fd = open(path, O_RDONLY);
-    if(fd < 0)
-    {
-        ALOGW("voice_loadconfig(%s) open fail!\n", path);
-        return -1;
-    }
-    res = fstat(fd, &st);
-    if(res)
-    {
-        ALOGW("voice_loadconfig(%s) stat fail! reason=%d\n", path, res);
-        return -1;
-    }
-    if(st.st_size <= 0)
-    {
-        ALOGW("voice_loadconfig(%s) size fail! size=%d\n", path, (int)st.st_size);
-        close(fd);
-        return -1;
-    }
-    ALOGI("voice_loadconfig(%s) size=%d!\n", path, (int)st.st_size);
-    content = malloc(st.st_size+1);
-    if(content == NULL)
-    {
-        ALOGW("voice_loadconfig(%s) malloc fail!\n", path);
-        close(fd);
-        return -1;
-    }
-    res = read(fd, content, st.st_size);
-    if(res <= 0)
-    {
-        ALOGW("voice_loadconfig(%s) read fail! res=%d\n", path, res);
-        close(fd);
-        return -1;
-    }
-    content[res] = 0;
-    voice_conf_parse_config(&config, content);
-    close(fd);
-
-    gConfig = config;
-    return 0;
-}
-
-
-
-
-static char * voice_api_GetConfig(char * group, char * item)
-{
-    int i;
-    tVoice_Hidraw_Settings * entry;
-
-    if(item == NULL)
-        return NULL;
-    entry = gConfig;
-    while(entry)
-    {
-        if(group&&(entry->group)&&(strcmp(entry->group, group)==0)&&(strcmp(entry->item, item)==0))
-            return entry->val;
-        if((group==NULL)&&(entry->group==NULL)&&(strcmp(entry->item, item)==0))
-            return entry->val;
-
-        entry = entry->next;
-    }
-    return NULL;
-}
-
-int voice_get_int_config(char *group, char *item) {
-    char *str;
-    int value = -1;
-
-    str = voice_api_GetConfig(group, item);
-    if(str == NULL) {
-        ALOGE("failed to get int value: %s-%s", group, item);
-        goto result;
-    }
-
-    value = strtol(str, NULL, 16);
-
-result:
-    return value;
-}
-
-int voice_get_byte_array_config(char *group, char *item, char* arr, int len) {
-    char *str, *front, *tail;
-    int ret = -1;
-    int i = 0;
-
-    str = voice_api_GetConfig(group, item);
-    if(str == NULL) {
-        goto retval;
-    }
-
-    front = str;
-
-    while(i < len) {
-        tail = strstr(front, ",");
-        if(tail == NULL) {
-            tail = strstr(front, ";");
-        }
-
-        if(tail == NULL) {
-            ALOGE("failed to get byte-array value: %s-%s-No%d", group, item, i + 1);
-            goto retval;
-        }
-
-        *tail++ = 0;
-        *(arr+i) = (strtol(front, NULL, 16)) & 0xff;
-        front = tail;
-        i++;
-    }
-
-    if(i == len)ret = i;
-
-retval:
-    return ret;
-}
-
-int voice_conf_exit()
-{
-    struct tVoice_Hidraw_Settings *item, *p;
-    int i;
-
-    item = gConfig;
-    while(item)
-    {
-        p = item;
-        item = item->next;
-        free(p);
-    }
-
-    if(gContent)
-        free(gContent);
-    return 0;
-}
-
-
+#include <string.h>\r
+#include <sys/types.h>\r
+#include <sys/stat.h>\r
+#include <unistd.h>\r
+#include <fcntl.h>\r
+#include <stdlib.h>\r
+#include <cutils/log.h>\r
+\r
+#include "config.h"\r
+\r
+\r
+tVoice_Hidraw_Settings *gConfig = NULL;\r
+static char * gContent = NULL;\r
+\r
+\r
+static char * voice_conf_getline(char * head, char ** left)\r
+{\r
+    char * next;\r
+    if(*head == 0)\r
+        return NULL;\r
+    while((*head == '\r')||(*head == '\n'))\r
+        head++;\r
+    if(*head == 0)\r
+        return NULL;\r
+    next = head;\r
+    while((*next != '\r')&&(*next != '\n')&&(*next != 0))\r
+        next++;\r
+    if(*next != 0)\r
+        *next++ = 0;\r
+    *left = next;\r
+    return head;\r
+}\r
+\r
+static void voice_conf_parse_config(tVoice_Hidraw_Settings **items, char *content)\r
+{\r
+    char * group = NULL;\r
+    char * item = NULL;\r
+    char * val = NULL;\r
+    char * line = NULL;\r
+    int id = -1;\r
+    tVoice_Hidraw_Settings* entry, * head, *end;\r
+\r
+    char * p;\r
+    int i = 0;\r
+\r
+    head = NULL;\r
+    end = NULL;\r
+\r
+    ALOGD("voice_conf_parse_config\n");\r
+    while((line = voice_conf_getline(content, &content)) != NULL)\r
+    {\r
+        ALOGD("voice_conf_parse_config line:%s\n", line);\r
+        switch(line[0])\r
+        {\r
+            case '[':\r
+            {\r
+                p = strstr(line,"]");\r
+                if(p)\r
+                {\r
+                    *p = 0;\r
+                    group = &(line[1]);\r
+                    ALOGI("voice_conf_parse_config Find Group[%s]\n", group);\r
+                }else{\r
+                    ALOGW("voice_conf_parse_config Expected ']' end of Group(%s)!\n", line);\r
+                }\r
+                break;\r
+            }\r
+            case '#':\r
+            {\r
+                break;\r
+            }\r
+            default:\r
+            {\r
+                p = strstr(line,"=");\r
+                if(p)\r
+                {\r
+                    *p++ = 0;\r
+                    item = line;\r
+                    val = p;\r
+                    if((item[0]==0)||(val[0]==0))\r
+                    {\r
+                        ALOGI("voice_conf_parse_config ignore(item:%s val:%s)\n", item[0]?item:"(null)", val[0]?val:"(null)");\r
+                        break;\r
+                    }\r
+                    ALOGI("voice_conf_parse_config Find Item[%s:%s=%s]\n", group, item, val);\r
+                    entry = malloc(sizeof(tVoice_Hidraw_Settings));\r
+                    if(entry)\r
+                    {\r
+                        entry->next = NULL;\r
+                        entry->group = group;\r
+                        entry->item = item;\r
+                        entry->val = val;\r
+                        if(end)\r
+                        {\r
+                            end->next = entry;\r
+                            end = entry;\r
+                        }else\r
+                            end = entry;\r
+                        if(head == NULL)\r
+                            head = entry;\r
+                    }\r
+                }\r
+            }\r
+        }\r
+    }\r
+    *items = head;\r
+}\r
+\r
+\r
+int voice_loadconfig(char * path)\r
+{\r
+    int i,res,fd;\r
+    struct stat st;\r
+    char * content = NULL;\r
+    struct tVoice_Hidraw_Settings* config = NULL;\r
+\r
+    ALOGI("voice_loadconfig(%s) load!\n", path);\r
+    fd = open(path, O_RDONLY);\r
+    if(fd < 0)\r
+    {\r
+        ALOGW("voice_loadconfig(%s) open fail!\n", path);\r
+        return -1;\r
+    }\r
+    res = fstat(fd, &st);\r
+    if(res)\r
+    {\r
+        ALOGW("voice_loadconfig(%s) stat fail! reason=%d\n", path, res);\r
+        return -1;\r
+    }\r
+    if(st.st_size <= 0)\r
+    {\r
+        ALOGW("voice_loadconfig(%s) size fail! size=%d\n", path, (int)st.st_size);\r
+        close(fd);\r
+        return -1;\r
+    }\r
+    ALOGI("voice_loadconfig(%s) size=%d!\n", path, (int)st.st_size);\r
+    content = malloc(st.st_size+1);\r
+    if(content == NULL)\r
+    {\r
+        ALOGW("voice_loadconfig(%s) malloc fail!\n", path);\r
+        close(fd);\r
+        return -1;\r
+    }\r
+    res = read(fd, content, st.st_size);\r
+    if(res <= 0)\r
+    {\r
+        ALOGW("voice_loadconfig(%s) read fail! res=%d\n", path, res);\r
+        close(fd);\r
+        return -1;\r
+    }\r
+    content[res] = 0;\r
+    voice_conf_parse_config(&config, content);\r
+    close(fd);\r
+\r
+    gConfig = config;\r
+    return 0;\r
+}\r
+\r
+\r
+\r
+\r
+static char * voice_api_GetConfig(char * group, char * item)\r
+{\r
+    int i;\r
+    tVoice_Hidraw_Settings * entry;\r
+\r
+    if(item == NULL)\r
+        return NULL;\r
+    entry = gConfig;\r
+    while(entry)\r
+    {\r
+        if(group&&(entry->group)&&(strcmp(entry->group, group)==0)&&(strcmp(entry->item, item)==0))\r
+            return entry->val;\r
+        if((group==NULL)&&(entry->group==NULL)&&(strcmp(entry->item, item)==0))\r
+            return entry->val;\r
+\r
+        entry = entry->next;\r
+    }\r
+    return NULL;\r
+}\r
+\r
+int voice_get_int_config(char *group, char *item) {\r
+    char *str;\r
+    int value = -1;\r
+\r
+    str = voice_api_GetConfig(group, item);\r
+    if(str == NULL) {\r
+        ALOGE("failed to get int value: %s-%s", group, item);\r
+        goto result;\r
+    }\r
+\r
+    value = strtol(str, NULL, 16);\r
+\r
+result:\r
+    return value;\r
+}\r
+\r
+int voice_get_byte_array_config(char *group, char *item, char* arr, int len) {\r
+    char *str, *front, *tail;\r
+    int ret = -1;\r
+    int i = 0;\r
+\r
+    str = voice_api_GetConfig(group, item);\r
+    if(str == NULL) {\r
+        goto retval;\r
+    }\r
+\r
+    front = str;\r
+\r
+    while(i < len) {\r
+        tail = strstr(front, ",");\r
+        if(tail == NULL) {\r
+            tail = strstr(front, ";");\r
+        }\r
+\r
+        if(tail == NULL) {\r
+            ALOGE("failed to get byte-array value: %s-%s-No%d", group, item, i + 1);\r
+            goto retval;\r
+        }\r
+\r
+        *tail++ = 0;\r
+        *(arr+i) = (strtol(front, NULL, 16)) & 0xff;\r
+        front = tail;\r
+        i++;\r
+    }\r
+\r
+    if(i == len)ret = i;\r
+\r
+retval:\r
+    return ret;\r
+}\r
+\r
+int voice_conf_exit()\r
+{\r
+    struct tVoice_Hidraw_Settings *item, *p;\r
+    int i;\r
+\r
+    item = gConfig;\r
+    while(item)\r
+    {\r
+        p = item;\r
+        item = item->next;\r
+        free(p);\r
+    }\r
+\r
+    if(gContent)\r
+        free(gContent);\r
+    return 0;\r
+}\r
+\r
+\r
index eeb868a363885c83ef512b8d139e37c8a37833ad..64f50bf167b6954297c92abc2d97621c23daa4b3 100755 (executable)
@@ -1,34 +1,34 @@
-#ifndef CONFIG_H
-#define CONFIG_H
-
-typedef struct tVoice_Hidraw_Settings
-{
-    struct tVoice_Hidraw_Settings * next;
-    char * group;
-    char * item;
-    char * val;
-} tVoice_Hidraw_Settings;
-
-#define CONFIG_GROUP_RCU  "Rcu"
-#define CONFIG_ITEM_RCU_VID  "Vid"
-#define CONFIG_ITEM_RCU_PID  "Pid"
-#define CONFIG_ITEM_RCU_VER  "Ver"
-
-#define CONFIG_GROUP_REPORTID  "ReportID"
-#define CONFIG_ITEM_REPORTID_KEY  "Key"
-#define CONFIG_ITEM_REPORTID_DATA  "Data"
-#define CONFIG_ITEM_REPORTID_CMD  "Cmd"
-
-#define CONFIG_GROUP_REPORTVALUE  "ReportValue"
-#define CONFIG_ITEM_REPORTVALUE_KEYDOWNLEN  "KeyDownLen"
-#define CONFIG_ITEM_REPORTVALUE_KEYDOWN  "KeyDown"
-#define CONFIG_ITEM_REPORTVALUE_KEYUPLEN  "KeyUpLen"
-#define CONFIG_ITEM_REPORTVALUE_KEYUP  "KeyUp"
-
-#define CONFIG_GROUP_SETTINGS  "Settings"
-#define CONFIG_ITEM_SETTINGS_DECODETYPE "DecodeType"
-#define CONFIG_ITEM_SETTINGS_DATAMASK "DataMask"
-#define CONFIG_ITEM_SETTINGS_AUTOCMD "AutoCmd"
-
-
-#endif
+#ifndef CONFIG_H\r
+#define CONFIG_H\r
+\r
+typedef struct tVoice_Hidraw_Settings\r
+{\r
+    struct tVoice_Hidraw_Settings * next;\r
+    char * group;\r
+    char * item;\r
+    char * val;\r
+} tVoice_Hidraw_Settings;\r
+\r
+#define CONFIG_GROUP_RCU  "Rcu"\r
+#define CONFIG_ITEM_RCU_VID  "Vid"\r
+#define CONFIG_ITEM_RCU_PID  "Pid"\r
+#define CONFIG_ITEM_RCU_VER  "Ver"\r
+\r
+#define CONFIG_GROUP_REPORTID  "ReportID"\r
+#define CONFIG_ITEM_REPORTID_KEY  "Key"\r
+#define CONFIG_ITEM_REPORTID_DATA  "Data"\r
+#define CONFIG_ITEM_REPORTID_CMD  "Cmd"\r
+\r
+#define CONFIG_GROUP_REPORTVALUE  "ReportValue"\r
+#define CONFIG_ITEM_REPORTVALUE_KEYDOWNLEN  "KeyDownLen"\r
+#define CONFIG_ITEM_REPORTVALUE_KEYDOWN  "KeyDown"\r
+#define CONFIG_ITEM_REPORTVALUE_KEYUPLEN  "KeyUpLen"\r
+#define CONFIG_ITEM_REPORTVALUE_KEYUP  "KeyUp"\r
+\r
+#define CONFIG_GROUP_SETTINGS  "Settings"\r
+#define CONFIG_ITEM_SETTINGS_DECODETYPE "DecodeType"\r
+#define CONFIG_ITEM_SETTINGS_DATAMASK "DataMask"\r
+#define CONFIG_ITEM_SETTINGS_AUTOCMD "AutoCmd"\r
+\r
+\r
+#endif\r
index 1228b011366cc4071892ecd5562799abef359e71..fe2160f3f0ed029b43dfbca690e515848cb736e1 100755 (executable)
-#include <stdio.h>
-#include <stdlib.h>
-#include "string.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <cutils/log.h>
-#include "get_voice_app.h"
-#include "msbc.h"
-
-
-#define DECODE_SIZE  58
-#define VOICE_MTU                   60
-#define VOICDE_DECODE_UNIT          (VOICE_MTU*4)
-
-
-static uint8* _pVoiceBuf = NULL;
-static uint8* _pdecodeBuf = NULL;
-static uint8* _pdecodeFrameBuf = NULL;
-int voice_fd = -1;
-int voice_fd_origin = -1;
-int voice_fd_wav = -1;
-sbc_t t_sbc;
-static int file_index = 0;
-
-struct wavfile
-{
-    char    id[4];          // should always contain "RIFF"
-    int     totallength;    // total file length minus 8
-    char    wavefmt[8];     // should be "WAVEfmt "
-    int     format;         // 16 for PCM format
-    short   pcm;            // 1 for PCM format
-    short   channels;       // channels
-    int     frequency;      // sampling frequency, 16000 in this case
-    int     bytes_per_second;
-    short   bytes_by_capture;
-    short   bits_per_sample;
-    char    data[4];        // should always contain "data"
-    int     bytes_in_data;
-};
-
-void write_wav_header(char* name, int samples, int channels){
-    struct wavfile filler;
-    FILE *pcm_fd;
-       FILE *wav_fd;
-       char record_name[50] = {0};
-       int size;
-       char ch;
-
-       ALOGE("Start to convert pcm to wav\n");
-    strncpy(filler.id, "RIFF", 4);
-//    filler.totallength = (samples * channels) + sizeof(struct wavfile) - 8; //81956
-    strncpy(filler.wavefmt, "WAVEfmt ", 8);
-    filler.format = 16;
-    filler.pcm = 1;
-    filler.channels = channels;
-    filler.frequency = 16000;
-    filler.bits_per_sample = 16;
-    filler.bytes_per_second = filler.channels * filler.frequency * filler.bits_per_sample/8;
-    filler.bytes_by_capture = filler.channels*filler.bits_per_sample/8;
-//    filler.bytes_in_data = samples * filler.channels * filler.bits_per_sample/8;    
-    strncpy(filler.data, "data", 4);
-
-       pcm_fd = fopen(name, "rb");
-       fseek(pcm_fd, 0, SEEK_END);
-       size = ftell(pcm_fd);
-       fseek(pcm_fd, 0, SEEK_SET);
-       
-       filler.bytes_in_data = size;
-       filler.totallength = size + sizeof(filler) - 8;
-#if 0  // just print data
-       printf("File description header: %s\n", filler.id);
-       printf("Size of file: %d\n", filler.totallength);
-       printf("WAV Format description header: %s\n", filler.wavefmt);
-       printf("Size of WAVE section chunck: %d\n", filler.format);
-       printf("WAVE type format: %d\n", filler.pcm);
-       printf("Number of channels: %d\n", filler.channels);
-       printf("Samples per second: %d\n", filler.frequency);
-       printf("Bytes per second: %d\n", filler.bytes_per_second);
-       printf("Block alignment: %d\n", filler.bytes_by_capture);
-       printf("Bits per sample: %d\n", filler.bits_per_sample);
-       printf("Data description header: %s\n", filler.data);
-       printf("Size of data: %d\n", filler.bytes_in_data);
-#endif
-
-
-    sprintf(record_name,"voice_msbc_wav%d.wav",file_index);
-
-       // store wav header
-    wav_fd = fopen(record_name, "wb");
-    fwrite(&filler, 1, sizeof(filler), wav_fd);
-       fclose(wav_fd);
-
-       // store voice data
-       wav_fd = fopen(record_name, "ab");
-    while(!feof(pcm_fd)) { 
-        fread(&ch, 1, 1, pcm_fd);
-        
-        if(!feof(pcm_fd)) { 
-            fwrite(&ch, 1, 1, wav_fd);
-        }
-    } 
-
-    fclose(pcm_fd);
-       fclose(wav_fd);
-}
-
-void RS_init_sbc()
-{
-    //msbc
-    sbc_init (&t_sbc, 0L);  
-}
-
-void RS_voice_app_create_origin_output()
-{
-    char record_name[50] = {0};
-
-    sprintf(record_name,"/data/vr/voice_msbc_origin%d",file_index);
-    voice_fd_origin =  open (record_name, O_WRONLY | O_CREAT |O_TRUNC, 0644);
-
-    
-    if(voice_fd_origin < 0)
-    {
-        ALOGE("can't open record origin  file:%s ",record_name);
-    }
-
-       RS_init_sbc();
-       
-       return;
-}
-
-void RS_voice_app_create_output()
-{
-    char record_name[50] = {0}; 
-    sprintf(record_name,"/data/vr/voice_msbc%d",file_index);
-
-    voice_fd =  open (record_name, O_WRONLY | O_CREAT |O_TRUNC, 0644);
-
-    if(voice_fd < 0)
-    {
-        ALOGE("can't open record file:%s ",record_name);
-    }
-
-
-       return;
-}
-
-int RS_stop_voice_stream_data (void)
-{
-       char record_name[50] = {0};
-       
-    ALOGE ("in\r\n");
-       
-    if (voice_fd > 0 && -1 == close (voice_fd)  )
-    {
-        ALOGE ("close voice file fail\r\n");
-    }
-
-    if (voice_fd_origin > 0 && -1 == close (voice_fd_origin)  )
-    {
-        ALOGE ("close voice file fail\r\n");
-    }
-
-    voice_fd = 0;
-    voice_fd_origin = 0;
-    sprintf(record_name,"voice_msbc%d",file_index);
-
-       //write_wav_header(record_name, 16000, 1);
-
-    sbc_finish (&t_sbc);
-
-       file_index = ((++file_index)>= 10) ? 0 : file_index;
-       
-    return 0;
-}
-
-int RS_write_decode_buf(uint8* pu_decode, ssize_t len)
-{
-        if (voice_fd > 0)
-        {
-            write (voice_fd, pu_decode, len);
-            return 0;
-        }
-        return -1;
-}
-
-int RS_deal_voice_stream_data(const uint8* input, size_t voice_buf_size, unsigned char* output, size_t output_buf_size, int* frame_len)
-{
-    int framelen;
-
-//    RS_init_sbc();
-
-    
-
-    if (NULL == input || 0 == voice_buf_size)
-    {
-        ALOGE ("input is null \r\n");
-        return -1;
-    }
-
-
-    if (NULL == output || 0 == output_buf_size)
-    {
-        ALOGE ("output is null");
-        return -1;
-    }
-
-    if(voice_buf_size != VOICE_MTU) {
-        ALOGE ("input size error: %d", voice_buf_size);
-        return -1;
-    }
-
-
-    if (input[0] == 0x01 && input[2] == 0xad)
-    { 
-        write(voice_fd_origin, input, voice_buf_size);
-        framelen = sbc_decode (&t_sbc, &input[2], DECODE_SIZE, output, output_buf_size,frame_len);
-        if (framelen <= 0)
-        {
-            ALOGE("fail to decode");
-            return -1;
-        }
-        RS_write_decode_buf(output, *frame_len);
-        return 0;
-    }else {
-        ALOGE("msbc format error !!!");
-        return -1;
-    }
-}
-    
-
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include "string.h"\r
+#include <sys/types.h>\r
+#include <sys/stat.h>\r
+#include <fcntl.h>\r
+#include <sys/ioctl.h>\r
+#include <cutils/log.h>\r
+#include "get_voice_app.h"\r
+#include "msbc.h"\r
+\r
+\r
+#define DECODE_SIZE  58\r
+#define VOICE_MTU                   60\r
+#define VOICDE_DECODE_UNIT          (VOICE_MTU*4)\r
+\r
+\r
+static uint8* _pVoiceBuf = NULL;\r
+static uint8* _pdecodeBuf = NULL;\r
+static uint8* _pdecodeFrameBuf = NULL;\r
+int voice_fd = -1;\r
+int voice_fd_origin = -1;\r
+int voice_fd_wav = -1;\r
+sbc_t t_sbc;\r
+static int file_index = 0;\r
+\r
+struct wavfile\r
+{\r
+    char    id[4];          // should always contain "RIFF"\r
+    int     totallength;    // total file length minus 8\r
+    char    wavefmt[8];     // should be "WAVEfmt "\r
+    int     format;         // 16 for PCM format\r
+    short   pcm;            // 1 for PCM format\r
+    short   channels;       // channels\r
+    int     frequency;      // sampling frequency, 16000 in this case\r
+    int     bytes_per_second;\r
+    short   bytes_by_capture;\r
+    short   bits_per_sample;\r
+    char    data[4];        // should always contain "data"\r
+    int     bytes_in_data;\r
+};\r
+\r
+void write_wav_header(char* name, int samples, int channels){\r
+    struct wavfile filler;\r
+    FILE *pcm_fd;\r
+       FILE *wav_fd;\r
+       char record_name[50] = {0};\r
+       int size;\r
+       char ch;\r
+\r
+       ALOGE("Start to convert pcm to wav\n");\r
+    strncpy(filler.id, "RIFF", 4);\r
+//    filler.totallength = (samples * channels) + sizeof(struct wavfile) - 8; //81956\r
+    strncpy(filler.wavefmt, "WAVEfmt ", 8);\r
+    filler.format = 16;\r
+    filler.pcm = 1;\r
+    filler.channels = channels;\r
+    filler.frequency = 16000;\r
+    filler.bits_per_sample = 16;\r
+    filler.bytes_per_second = filler.channels * filler.frequency * filler.bits_per_sample/8;\r
+    filler.bytes_by_capture = filler.channels*filler.bits_per_sample/8;\r
+//    filler.bytes_in_data = samples * filler.channels * filler.bits_per_sample/8;    \r
+    strncpy(filler.data, "data", 4);\r
+\r
+       pcm_fd = fopen(name, "rb");\r
+       fseek(pcm_fd, 0, SEEK_END);\r
+       size = ftell(pcm_fd);\r
+       fseek(pcm_fd, 0, SEEK_SET);\r
+       \r
+       filler.bytes_in_data = size;\r
+       filler.totallength = size + sizeof(filler) - 8;\r
+#if 0  // just print data\r
+       printf("File description header: %s\n", filler.id);\r
+       printf("Size of file: %d\n", filler.totallength);\r
+       printf("WAV Format description header: %s\n", filler.wavefmt);\r
+       printf("Size of WAVE section chunck: %d\n", filler.format);\r
+       printf("WAVE type format: %d\n", filler.pcm);\r
+       printf("Number of channels: %d\n", filler.channels);\r
+       printf("Samples per second: %d\n", filler.frequency);\r
+       printf("Bytes per second: %d\n", filler.bytes_per_second);\r
+       printf("Block alignment: %d\n", filler.bytes_by_capture);\r
+       printf("Bits per sample: %d\n", filler.bits_per_sample);\r
+       printf("Data description header: %s\n", filler.data);\r
+       printf("Size of data: %d\n", filler.bytes_in_data);\r
+#endif\r
+\r
+\r
+    sprintf(record_name,"voice_msbc_wav%d.wav",file_index);\r
+\r
+       // store wav header\r
+    wav_fd = fopen(record_name, "wb");\r
+    fwrite(&filler, 1, sizeof(filler), wav_fd);\r
+       fclose(wav_fd);\r
+\r
+       // store voice data\r
+       wav_fd = fopen(record_name, "ab");\r
+    while(!feof(pcm_fd)) { \r
+        fread(&ch, 1, 1, pcm_fd);\r
+        \r
+        if(!feof(pcm_fd)) { \r
+            fwrite(&ch, 1, 1, wav_fd);\r
+        }\r
+    } \r
+\r
+    fclose(pcm_fd);\r
+       fclose(wav_fd);\r
+}\r
+\r
+void RS_init_sbc()\r
+{\r
+    //msbc\r
+    sbc_init (&t_sbc, 0L);  \r
+}\r
+\r
+void RS_voice_app_create_origin_output()\r
+{\r
+    char record_name[50] = {0};\r
+\r
+    sprintf(record_name,"/data/vr/voice_msbc_origin%d",file_index);\r
\r
+    voice_fd_origin =  open (record_name, O_WRONLY | O_CREAT |O_TRUNC, 0644);\r
+\r
+    \r
+    if(voice_fd_origin < 0)\r
+    {\r
+        ALOGE("can't open record origin  file:%s ",record_name);\r
+    }\r
+\r
+       RS_init_sbc();\r
+       \r
+       return;\r
+}\r
+\r
+void RS_voice_app_create_output()\r
+{\r
+    char record_name[50] = {0}; \r
+    sprintf(record_name,"/data/vr/voice_msbc%d",file_index);\r
+\r
+    voice_fd =  open (record_name, O_WRONLY | O_CREAT |O_TRUNC, 0644);\r
+\r
+    if(voice_fd < 0)\r
+    {\r
+        ALOGE("can't open record file:%s ",record_name);\r
+    }\r
+\r
+\r
+       return;\r
+}\r
+\r
+int RS_stop_voice_stream_data (void)\r
+{\r
+       char record_name[50] = {0};\r
+       \r
+    ALOGE ("in\r\n");\r
+       \r
+    if (voice_fd > 0 && -1 == close (voice_fd)  )\r
+    {\r
+        ALOGE ("close voice file fail\r\n");\r
+    }\r
+\r
+    if (voice_fd_origin > 0 && -1 == close (voice_fd_origin)  )\r
+    {\r
+        ALOGE ("close voice file fail\r\n");\r
+    }\r
+\r
+    voice_fd = 0;\r
+    voice_fd_origin = 0;\r
\r
+    sprintf(record_name,"voice_msbc%d",file_index);\r
+\r
+       //write_wav_header(record_name, 16000, 1);\r
+\r
+    sbc_finish (&t_sbc);\r
+\r
+       file_index = ((++file_index)>= 10) ? 0 : file_index;\r
+       \r
+    return 0;\r
+}\r
+\r
+int RS_write_decode_buf(uint8* pu_decode, ssize_t len)\r
+{\r
+        if (voice_fd > 0)\r
+        {\r
+            write (voice_fd, pu_decode, len);\r
+            return 0;\r
+        }\r
+        return -1;\r
+}\r
+\r
+int RS_deal_voice_stream_data(const uint8* input, size_t voice_buf_size, unsigned char* output, size_t output_buf_size, int* frame_len)\r
+{\r
+    int framelen;\r
+\r
+//    RS_init_sbc();\r
+\r
+    \r
+\r
+    if (NULL == input || 0 == voice_buf_size)\r
+    {\r
+        ALOGE ("input is null \r\n");\r
+        return -1;\r
+    }\r
+\r
+\r
+    if (NULL == output || 0 == output_buf_size)\r
+    {\r
+        ALOGE ("output is null");\r
+        return -1;\r
+    }\r
+\r
+    if(voice_buf_size != VOICE_MTU) {\r
+        ALOGE ("input size error: %d", voice_buf_size);\r
+        return -1;\r
+    }\r
+\r
+\r
+    if (input[0] == 0x01 && input[2] == 0xad)\r
+    { \r
+        write(voice_fd_origin, input, voice_buf_size);\r
+        framelen = sbc_decode (&t_sbc, &input[2], DECODE_SIZE, output, output_buf_size,frame_len);\r
+        if (framelen <= 0)\r
+        {\r
+            ALOGE("fail to decode");\r
+            return -1;\r
+        }\r
+        RS_write_decode_buf(output, *frame_len);\r
+        return 0;\r
+    }else {\r
+        ALOGE("msbc format error !!!");\r
+        return -1;\r
+    }\r
+}\r
+    \r
+\r
index 64cc362df4f9c69a6387f692a38c9dfde424c074..a55b100b9ca741eac9d39c9970c8b71ce9b233fc 100755 (executable)
@@ -1,22 +1,22 @@
-
-//#define  MSBC_SUPPORT
-#define  VOICE_KEY_DOWN 0x3e
-#define  VOICE_BUFFER_REPORT_ID    0x5a
-#define  ADD_FOR_VOICE_CONTROL
-#define  VOICE_FILE_WITH_MSBC           "/tmp/voice_msbc"
-#define  VOICE_FILE_WITH_NO_MSBC    "/tmp/voice_no_msbc"
-
-typedef unsigned char uint8;
-typedef unsigned short uint16;
-typedef unsigned int uint32;
-typedef signed char int8;
-typedef signed short int16;
-typedef signed int int32;
-
-void RS_voice_app_create_origin_output();
-
-int RS_deal_voice_stream_data(const uint8* input, size_t voice_buf_size, unsigned char* output, size_t output_buf_size, int* frame_len);
-
-int RS_stop_voice_stream_data (void);
-
-void RS_voice_app_create_output();
+\r
+//#define  MSBC_SUPPORT\r
+#define  VOICE_KEY_DOWN 0x3e\r
+#define  VOICE_BUFFER_REPORT_ID    0x5a\r
+#define  ADD_FOR_VOICE_CONTROL\r
+#define  VOICE_FILE_WITH_MSBC           "/tmp/voice_msbc"\r
+#define  VOICE_FILE_WITH_NO_MSBC    "/tmp/voice_no_msbc"\r
+\r
+typedef unsigned char uint8;\r
+typedef unsigned short uint16;\r
+typedef unsigned int uint32;\r
+typedef signed char int8;\r
+typedef signed short int16;\r
+typedef signed int int32;\r
+\r
+void RS_voice_app_create_origin_output();\r
+\r
+int RS_deal_voice_stream_data(const uint8* input, size_t voice_buf_size, unsigned char* output, size_t output_buf_size, int* frame_len);\r
+\r
+int RS_stop_voice_stream_data (void);\r
+\r
+void RS_voice_app_create_output();
\ No newline at end of file
index 309e47c1c7633f84b315ec562eb1626b5e5feec8..05c41fb9ecd482cc90bd4dc5644c20c8b274a460 100755 (executable)
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdint.h>
-#include <dirent.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <sys/inotify.h>
-#include <sys/poll.h>
-#include <linux/input.h>
-#include <linux/hidraw.h>
-#include <errno.h>
-#include <time.h>
-#include <unistd.h>
-
-#include <pthread.h>
-
-
-#include "voice_hidraw.h"
-#include "bee_settings.h"
-#include "get_voice_app.h"
-#include "sbc.h"
-#include "voice_uipc.h"
-#include "config.h"
-
-#define RAW_DATA_PATH "/data/vr/raw_data"
-static int file_counter = 0;
-int raw_fd;
-int gSocket_Running = 0;
-int gTarget_fd = 0;
-
-
-
-typedef struct {
-    int vid;
-    int pid;
-    int vers;
-    unsigned char voice_key_reportID;
-    unsigned char voice_data_reportID;
-    unsigned char voice_cmd_reportID;
-    int voice_keypress_data_len;
-    unsigned char *voice_keypress_data;
-    int voice_keyrelease_data_len;
-    unsigned char *voice_keyrelease_data;
-    int decode_type;
-    int data_mask;
-    int autocmd;
-    
-}VOICE_SETTING;
-
-static struct pollfd *ufds;
-static char **device_names;
-static int nfds;
-
-static int *unused_bt_hid_fds;
-static int nunusedfds;
-static char **unused_device_names;
-
-
-VOICE_SETTING global_voice_setting;
-pthread_mutex_t mutex_voice_settings;
-
-int frame_counter = 0;
-
-int set_rcu_info(int vid, int pid, int vers) {
-    pthread_mutex_lock(&mutex_voice_settings);
-    if(vid != -1)
-        global_voice_setting.vid = vid;
-
-    if(pid != -1)
-        global_voice_setting.pid = pid;
-
-    if(vers != -1)
-        global_voice_setting.vers = vers;
-
-    pthread_mutex_unlock(&mutex_voice_settings);
-
-    return 0;
-}
-
-int set_voice_data_reportID(unsigned char reportID) {
-    pthread_mutex_lock(&mutex_voice_settings);
-    global_voice_setting.voice_data_reportID = reportID;
-    pthread_mutex_unlock(&mutex_voice_settings);
-    return 0;
-}
-
-int set_voice_cmd_reportID(unsigned char reportID) {
-    pthread_mutex_lock(&mutex_voice_settings);
-    global_voice_setting.voice_cmd_reportID = reportID;
-    pthread_mutex_unlock(&mutex_voice_settings);
-    return 0;
-}
-
-int set_voice_key_reportID(unsigned char reportID) {
-    pthread_mutex_lock(&mutex_voice_settings);
-    global_voice_setting.voice_key_reportID = reportID;
-    pthread_mutex_unlock(&mutex_voice_settings);
-    return 0;
-}
-
-int set_voice_keypress_data(int len, unsigned char *data) {
-    if(len > 0) {
-        pthread_mutex_lock(&mutex_voice_settings);
-        if(global_voice_setting.voice_keypress_data != NULL) {
-            if(global_voice_setting.voice_keypress_data_len < len) {
-
-                unsigned char *buf = (unsigned char *)realloc(global_voice_setting.voice_keypress_data, len);
-                if(buf == NULL) {
-                    //log
-                    pthread_mutex_unlock(&mutex_voice_settings);
-                    error("Failed to realloc for voice_keypress_data");
-                    return -1;
-                }else {
-                    global_voice_setting.voice_keypress_data = buf;
-                }
-            }
-        }else {
-            global_voice_setting.voice_keypress_data = (unsigned char *)malloc(len);
-            if(global_voice_setting.voice_keypress_data == NULL) {
-                //log
-                pthread_mutex_unlock(&mutex_voice_settings);
-                error("Failed to malloc for voice_keypress_data");
-                return -2;
-            }
-        }
-
-        memcpy(global_voice_setting.voice_keypress_data, data, len);
-        global_voice_setting.voice_keypress_data_len = len;
-        pthread_mutex_unlock(&mutex_voice_settings);
-        return 0;
-    }else {
-        warn("len is negative for voice_keypress_data");
-        return -3;
-    }
-}
-
-int set_voice_keyrelease_data(int len, unsigned char *data) {
-    if(len > 0) {
-        pthread_mutex_lock(&mutex_voice_settings);
-        if(global_voice_setting.voice_keyrelease_data != NULL) {
-            if(global_voice_setting.voice_keyrelease_data_len < len) {
-                unsigned char *buf = (unsigned char *)realloc(global_voice_setting.voice_keyrelease_data, len);
-                if(buf == NULL) {
-                    //log
-                    pthread_mutex_unlock(&mutex_voice_settings);
-                    error("Failed to realloc for voice_keypress_data");
-                    return -1;
-                }else {
-                    global_voice_setting.voice_keyrelease_data = buf;
-                }
-            }
-        }else {
-            global_voice_setting.voice_keyrelease_data = (unsigned char *)malloc(len);
-            if(global_voice_setting.voice_keyrelease_data == NULL) {
-                pthread_mutex_unlock(&mutex_voice_settings);
-                error("Failed to malloc for voice_keyrelease_data");
-                return -2;
-            }
-        }
-
-        memcpy(global_voice_setting.voice_keyrelease_data, data, len);
-        global_voice_setting.voice_keyrelease_data_len = len;
-        pthread_mutex_unlock(&mutex_voice_settings);
-        return 0;
-    }else {
-        //log
-        warn("len is negative for voice_keyrelease_data");
-        return -3;
-    }
-}
-
-int set_encode_type(int type) {
-    if(type <= DECODE_TYPE_MAX) {
-        pthread_mutex_lock(&mutex_voice_settings);
-        global_voice_setting.decode_type = type;
-        pthread_mutex_unlock(&mutex_voice_settings);
-        return 0;
-    }else {
-        warn("Unknown Decode Type !!!");
-        return -1;
-    }
-}
-
-int data_type_mask(int mask) {
-    //log
-    debug("Set Data Type Mask 0x%04x", mask);
-
-    pthread_mutex_lock(&mutex_voice_settings);
-    
-    if(mask & DATA_TYPE_MASK_RAW) {
-        global_voice_setting.data_mask = DATA_TYPE_MASK_RAW;
-    }else {
-        if(mask & DATA_TYPE_MASK_VOICE) {
-            global_voice_setting.data_mask |= DATA_TYPE_MASK_VOICE;
-        }
-    }
-
-    pthread_mutex_unlock(&mutex_voice_settings);
-    return 0;
-}
-
-int set_auto_cmd(int autocmd) {
-    pthread_mutex_lock(&mutex_voice_settings);
-    if(autocmd == 1) {
-        global_voice_setting.autocmd = AUTOCMD_AUTO;
-    }else if(autocmd == 2){
-        global_voice_setting.autocmd = AUTOCMD_NONE;
-    }
-    pthread_mutex_unlock(&mutex_voice_settings);
-
-    return 0;
-}
-
-
-
-int voice_msbc_init() {
-
-    int ivalue, i;
-   
-    voice_loadconfig(CONFIG_PATH);
-
-    pthread_mutex_lock(&mutex_voice_settings);
-    
-    memset(&global_voice_setting, 0, sizeof(global_voice_setting));
-
-    ivalue = voice_get_int_config(CONFIG_GROUP_RCU, CONFIG_ITEM_RCU_VID);
-    if(ivalue >= 0) {
-        global_voice_setting.vid = ivalue;
-        ALOGD("use config VID: %04x", global_voice_setting.vid);
-    } else {
-        global_voice_setting.vid = BEE_RCU_VID;
-        ALOGD("use default VID: %04x", global_voice_setting.vid);
-    }
-
-    ivalue = voice_get_int_config(CONFIG_GROUP_RCU, CONFIG_ITEM_RCU_PID);
-    if(ivalue >= 0) {
-        global_voice_setting.pid = ivalue;
-        ALOGD("use config PID: %04x", global_voice_setting.pid);
-    } else {
-        global_voice_setting.pid = BEE_RCU_PID;
-        ALOGD("use default PID: %04x", global_voice_setting.pid);
-    }
-
-    ivalue = voice_get_int_config(CONFIG_GROUP_RCU, CONFIG_ITEM_RCU_VER);
-    if(ivalue >= 0) {
-        global_voice_setting.vers = ivalue;
-        ALOGD("use config version: %04x", global_voice_setting.vers);
-    } else {
-        global_voice_setting.vers = BEE_RCU_VERSION;
-        ALOGD("use default VERSION: %04x", global_voice_setting.vers);
-    }
-
-    ivalue = voice_get_int_config(CONFIG_GROUP_REPORTID, CONFIG_ITEM_REPORTID_KEY);
-    if(ivalue > 0) {
-        global_voice_setting.voice_key_reportID = ivalue & 0xff;
-        ALOGD("use config key report id: %02x", global_voice_setting.voice_key_reportID);
-    } else {
-        global_voice_setting.voice_key_reportID = BEE_VOICEKEY_REPORTID;
-        ALOGD("use default key report id: %02x", global_voice_setting.voice_key_reportID);
-    }
-    
-
-    ivalue = voice_get_int_config(CONFIG_GROUP_REPORTID, CONFIG_ITEM_REPORTID_DATA);
-    if(ivalue > 0) {
-        global_voice_setting.voice_data_reportID = ivalue & 0xff;
-        ALOGD("use config data report id: %02x", global_voice_setting.voice_data_reportID);
-    } else {
-        global_voice_setting.voice_data_reportID = BEE_MSBC_VOICEDATA_REPORTID;
-        ALOGD("use default data report id: %02x", global_voice_setting.voice_data_reportID);
-    }
-
-    ivalue = voice_get_int_config(CONFIG_GROUP_REPORTID, CONFIG_ITEM_REPORTID_CMD);
-    if(ivalue > 0) {
-        global_voice_setting.voice_cmd_reportID = ivalue & 0xff;
-        ALOGD("use config cmd report id: %02x", global_voice_setting.voice_cmd_reportID);
-    } else {
-        global_voice_setting.voice_cmd_reportID = BEE_MSBC_VOICECMD_REPORTID;
-        ALOGD("use default cmd report id: %02x", global_voice_setting.voice_cmd_reportID);
-    }
-
-    ivalue = voice_get_int_config(CONFIG_GROUP_REPORTVALUE, CONFIG_ITEM_REPORTVALUE_KEYDOWNLEN);
-    if(ivalue > 0) {
-        global_voice_setting.voice_keypress_data_len = ivalue;
-        ALOGD("use config keydown len: %d", global_voice_setting.voice_keypress_data_len);
-    } else {
-        global_voice_setting.voice_keypress_data_len = BEE_VOICEKEY_LEN;
-        ALOGD("use default keydown len: %d", global_voice_setting.voice_keypress_data_len);
-    }
-
-    global_voice_setting.voice_keypress_data = (unsigned char *)malloc(global_voice_setting.voice_keypress_data_len);
-    if(global_voice_setting.voice_keypress_data == NULL) {
-        //log
-        error("failed to get buf for keydown");
-        pthread_mutex_unlock(&mutex_voice_settings);
-        return -1;
-    }else {
-        if(ivalue > 0) {
-            if(voice_get_byte_array_config(CONFIG_GROUP_REPORTVALUE, CONFIG_ITEM_REPORTVALUE_KEYDOWN,
-                global_voice_setting.voice_keypress_data, global_voice_setting.voice_keypress_data_len)
-                != global_voice_setting.voice_keypress_data_len) {
-                
-                global_voice_setting.voice_keypress_data_len = BEE_VOICEKEY_LEN;
-                if(ivalue < BEE_VOICEKEY_LEN) {
-                    global_voice_setting.voice_keypress_data = (unsigned char *)realloc(global_voice_setting.voice_keypress_data, BEE_VOICEKEY_LEN);
-                    if(global_voice_setting.voice_keypress_data == NULL) {
-                        error("failed to realloc buf for keydown");
-                        pthread_mutex_unlock(&mutex_voice_settings);
-                        return -1;
-                    }
-                }
-                memcpy(global_voice_setting.voice_keypress_data, BEE_VOICE_KEYDOWN_DATA, global_voice_setting.voice_keypress_data_len);
-                ALOGD("use default keydown data");
-            }
-        }else {
-            memcpy(global_voice_setting.voice_keypress_data, BEE_VOICE_KEYDOWN_DATA, global_voice_setting.voice_keypress_data_len);
-            ALOGD("use default keydown data");
-        }
-        ALOGD("key down data:");
-        for(i = 0; i < global_voice_setting.voice_keypress_data_len; i++) {
-            ALOGD("data[%d] = %02x", i, *(global_voice_setting.voice_keypress_data + i));
-        }
-    }
-
-    ivalue = voice_get_int_config(CONFIG_GROUP_REPORTVALUE, CONFIG_ITEM_REPORTVALUE_KEYUPLEN);
-    if(ivalue > 0) {
-        global_voice_setting.voice_keyrelease_data_len = ivalue;
-        ALOGD("use config keyup len: %d", global_voice_setting.voice_keyrelease_data_len);
-    } else {
-        global_voice_setting.voice_keyrelease_data_len = BEE_VOICEKEY_LEN;
-        ALOGD("use default keyup len: %d", global_voice_setting.voice_keyrelease_data_len);
-    }
-
-    global_voice_setting.voice_keyrelease_data = (unsigned char *)malloc(global_voice_setting.voice_keyrelease_data_len);
-    if(global_voice_setting.voice_keyrelease_data == NULL) {
-        //log
-        error("failed to get buf for keyup");
-        pthread_mutex_unlock(&mutex_voice_settings);
-        return -1;
-    }else {
-        if(ivalue > 0) {
-            if(voice_get_byte_array_config(CONFIG_GROUP_REPORTVALUE, CONFIG_ITEM_REPORTVALUE_KEYUP,
-                global_voice_setting.voice_keyrelease_data, global_voice_setting.voice_keyrelease_data_len)
-                != global_voice_setting.voice_keyrelease_data_len) {
-                
-                global_voice_setting.voice_keyrelease_data_len = BEE_VOICEKEY_LEN;
-                if(ivalue < BEE_VOICEKEY_LEN) {
-                    global_voice_setting.voice_keyrelease_data = (unsigned char *)realloc(global_voice_setting.voice_keyrelease_data, BEE_VOICEKEY_LEN);
-                    if(global_voice_setting.voice_keyrelease_data == NULL) {
-                        error("failed to realloc buf for keyup");
-                        pthread_mutex_unlock(&mutex_voice_settings);
-                        return -1;
-                    }
-                }
-                memcpy(global_voice_setting.voice_keyrelease_data, BEE_VOICE_KEYUP_DATA, global_voice_setting.voice_keyrelease_data_len);
-                ALOGD("use default keyup data");
-            }
-        }else {
-            memcpy(global_voice_setting.voice_keyrelease_data, BEE_VOICE_KEYUP_DATA, global_voice_setting.voice_keyrelease_data_len);
-            ALOGD("use default keyup data");
-        }
-        ALOGD("key up data:");
-        for(i = 0; i < global_voice_setting.voice_keyrelease_data_len; i++) {
-            ALOGD("data[%d] = %02x", i, *(global_voice_setting.voice_keyrelease_data + i));
-        }
-    }
-
-    ivalue = voice_get_int_config(CONFIG_GROUP_SETTINGS, CONFIG_ITEM_SETTINGS_DECODETYPE);
-    if(ivalue > 0) {
-        global_voice_setting.decode_type = ivalue;
-        ALOGD("use config decode type: %d", global_voice_setting.decode_type);
-    } else {
-        global_voice_setting.decode_type = DECODE_TYPE_MSBC;
-        ALOGD("use default decode type: %d", global_voice_setting.decode_type);
-    }
-
-    ivalue = voice_get_int_config(CONFIG_GROUP_SETTINGS, CONFIG_ITEM_SETTINGS_DATAMASK);
-    if(ivalue > 0) {
-        global_voice_setting.data_mask = ivalue;
-        ALOGD("use config data mask: %d", global_voice_setting.data_mask);
-    } else {
-        global_voice_setting.data_mask = DATA_TYPE_MASK_VOICE;
-        ALOGD("use default decode type: %d", global_voice_setting.data_mask);
-    }
-
-    ivalue = voice_get_int_config(CONFIG_GROUP_SETTINGS, CONFIG_ITEM_SETTINGS_AUTOCMD);
-    if(ivalue > 0) {
-        global_voice_setting.autocmd = ivalue;
-        ALOGD("use config decode type: %d", global_voice_setting.autocmd);
-    } else {
-        global_voice_setting.autocmd = AUTOCMD_AUTO;
-        ALOGD("use default decode type: %d", global_voice_setting.autocmd);
-    }
-
-    pthread_mutex_unlock(&mutex_voice_settings);
-    voice_conf_exit();
-    return 0;
-}
-
-void voice_open_store_file()
-{
-    char record_name[50] = {0}; 
-    sprintf(record_name, "%s%d", RAW_DATA_PATH, file_counter);
-
-    raw_fd =  open (record_name, O_WRONLY | O_CREAT |O_TRUNC, 0644);
-
-    if(raw_fd < 0)
-    {
-        ALOGE("can't open record file:%s ", record_name);
-    }
-
-
-       return;
-}
-
-int voice_write_decode_buf(uint8* pu_decode, ssize_t len)
-{
-    if (raw_fd > 0)
-    {
-        write (raw_fd, pu_decode, len);
-        return 0;
-    }
-    return -1;
-}
-
-
-/**********************************************
-*
-*   hidraw node related
-*
-***********************************************/
-const char *bus_str(int bus){
-    switch (bus) {
-        case BUS_USB:
-            return "USB";
-            
-        case BUS_HIL:
-            return "HIL";
-            
-        case BUS_BLUETOOTH:
-            return "Bluetooth";
-
-        case BUS_VIRTUAL:
-            return "Virtual";
-                
-        default:
-            return "Other";
-    }
-}
-    
-static int get_hidraw_info(int fd)
-{
-    int i, res, desc_size = 0;
-    char buf[256];
-    struct hidraw_report_descriptor rpt_desc;
-    struct hidraw_devinfo info;
-    
-    memset(&rpt_desc, 0x0, sizeof(rpt_desc));
-    memset(&info, 0x0, sizeof(info));
-    memset(buf, 0x0, sizeof(buf));
-    debug("-----------------------------------------------\n");
-    
-    /* Get Raw Name */
-    res = ioctl(fd, HIDIOCGRAWNAME(256), buf);
-    if (res < 0)
-        perror("HIDIOCGRAWNAME");
-    else
-        debug("Raw Name: %s\n", buf);
-    /* Get Physical Location */
-    res = ioctl(fd, HIDIOCGRAWPHYS(256), buf);
-    if (res < 0)
-        perror("HIDIOCGRAWPHYS");
-    else
-        debug("Raw Phys: %s\n", buf);
-    /* Get Raw Info */
-    res = ioctl(fd, HIDIOCGRAWINFO, &info);
-    if (res < 0) {
-        perror("HIDIOCGRAWINFO");
-    } else {
-        debug("Raw Info:");
-        debug(" bustype: %d (%s)", info.bustype, bus_str(info.bustype));
-        debug(" vendor: 0x%04x", info.vendor);
-        debug(" product: 0x%04x\n", info.product);
-    }
-    /* Get Report Descriptor Size */
-    res = ioctl(fd, HIDIOCGRDESCSIZE, &desc_size);
-    if (res < 0)
-       perror("HIDIOCGRDESCSIZE");
-    else
-        debug("Report Descriptor Size: %d\n", desc_size);
-    /* Get Report Descriptor */
-    rpt_desc.size = desc_size;
-    res = ioctl(fd, HIDIOCGRDESC, &rpt_desc);
-    if (res < 0) {
-        perror("HIDIOCGRDESC");
-    } else {
-        debug("Report Descriptor:");
-        for (i = 0; i < rpt_desc.size; i++)
-        {
-            if((i%16)==0)
-                debug("\n");
-            debug("%02x ", rpt_desc.value[i]);
-        }
-        debug("\n");
-    }
-    info("-----------------------------------------------\n");
-    
-    return 0;
-}
-
-static int send_message(int fd, unsigned char * buf, int len)
-{
-    int res = 0;
-    res = write(fd, buf, len);
-    debug("send_message res=%d\n",res);
-    return res;
-}
-
-static void process_voice_data(unsigned char reportID, unsigned char *buf, int len) {
-    int ret = -1;
-    int offset = 0;
-    int i;
-    int decode_len = 0;
-
-    unsigned char output_buf[1024] = {0x00};
-
-    //debug("reportID=%d, decode_type=%d, global_reportID=%d, len=%d", 
-        //reportID, global_voice_setting.decode_type, global_voice_setting.voice_data_reportID, len);
-
-    if(global_voice_setting.decode_type == DECODE_TYPE_MSBC) {
-        while(offset + BEE_MSBC_FRAME_SIZE <= len) {
-            //debug("offset is %d now, len is %d", offset, len);
-            ret = RS_deal_voice_stream_data(buf + offset, BEE_MSBC_FRAME_SIZE, output_buf, 1024, &decode_len);
-            if(ret < 0) {
-                offset++;
-            }else {
-                UIPC_Send_noblock(UIPC_CH_ID_VOICE_DATA, 0, output_buf, decode_len);
-                offset += BEE_MSBC_FRAME_SIZE;
-            }
-        }
-    }else if(global_voice_setting.decode_type == DECODE_TYPE_SBC) {
-        decode_len = 1024;
-        while(offset + BEE_SBC_FRAME_SIZE <= len) {
-            ret = sbcDecode(buf + offset, BEE_SBC_FRAME_SIZE, output_buf, &decode_len);
-            if(ret < 0) {
-                debug("fail to decode: %d", ret);
-                offset++;
-            }else {
-                UIPC_Send_noblock(UIPC_CH_ID_VOICE_DATA, 0, output_buf, decode_len);
-                offset += BEE_SBC_FRAME_SIZE;
-            }
-        }
-    }
-}
-
-static int read_message(int fd)
-{
-    unsigned char buf[4096];
-    int res,i;
-
-    unsigned char start_rec_command[] = {global_voice_setting.voice_cmd_reportID, 0x01};
-    unsigned char stop_rec_command[] = {global_voice_setting.voice_cmd_reportID, 0x00};
-    static int voice_kpressed = 0;
-
-/*
-    struct hidraw_devinfo info;
-    res = ioctl(fd, HIDIOCGRAWINFO, &info);
-    if (res < 0) {
-        perror("HIDIOCGRAWINFO");
-    }
-*/
-
-    //if( (info.vendor==global_voice_setting.vid) && (info.product==global_voice_setting.pid) )
-    //{
-        res = read(fd, buf, sizeof(buf));
-        if(res > 0)
-        {
-            //debug("Receive From :%04x,%04x number: %d", info.vendor, info.product, res);
-            if( (global_voice_setting.data_mask & DATA_TYPE_MASK_RAW) == DATA_TYPE_MASK_RAW) {
-                //just callback and return
-                UIPC_Send_noblock(UIPC_CH_ID_VOICE_DATA, 0, buf + 1, res - 1);
-                return 0;
-            }else if( (global_voice_setting.data_mask & DATA_TYPE_MASK_VOICE) == DATA_TYPE_MASK_VOICE) {
-                if((voice_kpressed == 0) && (buf[0] == global_voice_setting.voice_key_reportID) && 
-                    (res == global_voice_setting.voice_keypress_data_len + 1) && 
-                    (memcmp(buf + 1, global_voice_setting.voice_keypress_data, global_voice_setting.voice_keypress_data_len) == 0))
-                {
-                    //debug("voice key pressed");
-                    if(global_voice_setting.autocmd == AUTOCMD_AUTO) {
-                        RS_voice_app_create_output();
-                        RS_voice_app_create_origin_output();
-                        voice_open_store_file();
-
-                        send_message(fd, start_rec_command,sizeof(start_rec_command));
-                        voice_kpressed = 1;
-                        frame_counter = 0;
-                    }
-                    return 0;
-                }
-
-                // when voice key is released
-                if ((voice_kpressed == 1) && (buf[0] == global_voice_setting.voice_key_reportID) && 
-                    (res == global_voice_setting.voice_keyrelease_data_len + 1) && 
-                    (memcmp(buf + 1, global_voice_setting.voice_keyrelease_data, global_voice_setting.voice_keyrelease_data_len) == 0))
-                {
-                    //debug("voice key relesed");
-
-                    if(global_voice_setting.autocmd == AUTOCMD_AUTO) {
-                        RS_stop_voice_stream_data();
-                        send_message(fd, stop_rec_command,sizeof(stop_rec_command));
-                        voice_kpressed = 0;
-                        debug("total frame: %d", frame_counter);
-                        close(raw_fd);
-                        file_counter++;
-                        raw_fd = -1;
-                    }
-                    return 0;
-                }
-
-                // store voice data
-                if ((voice_kpressed == 1 ) && (buf[0] == global_voice_setting.voice_data_reportID))
-                {
-                    //debug("deal with voice data");
-                    process_voice_data(buf[0], buf + 1, res-1);
-                    voice_write_decode_buf(buf + 1, res - 1);
-                    frame_counter++;
-                    return 0;
-                }
-            }
-        }else {
-            warn("Read fd %d failed: %s", fd, strerror(errno));
-            return -1;
-        }
-        
-    //}
-
-    return 0;
-}
-
-int get_dev_vid_pid_info(int fd, short* vid, short* pid) {
-    int res = -1;
-    struct hidraw_devinfo info;
-
-    memset(&info, 0x0, sizeof(info));
-
-    res = ioctl(fd, HIDIOCGRAWINFO, &info);
-    if (res < 0) {
-        debug("failed to get HIDIOCGRAWINFO");
-    } else {
-        //debug("Raw Info:");
-        //debug(" bustype: %d (%s)", info.bustype, bus_str(info.bustype));
-        debug(" vendor: 0x%04x, product: 0x%04x", info.vendor, info.product);
-        *vid = info.vendor;
-        *pid = info.product;
-        res = 1;
-    }
-    return res;
-}
-
-static int open_device(const char *device)
-{
-    int version;
-    int fd;
-    int clkid = CLOCK_MONOTONIC;
-    struct pollfd *new_ufds;
-    int *unfds;
-    char **new_device_names;
-    char **new_unused_device_names;
-    char name[80];
-    char location[80];
-    char idstr[80];
-    struct input_id id;
-    int res = -1;
-    struct hidraw_devinfo info;
-
-    fd = open(device, O_RDWR);
-    if(fd < 0) {
-        debug("could not open %s, %s\n", device, strerror(errno));
-        return -1;
-    }
-    debug("new fd is %d", fd);
-
-    res = ioctl(fd, HIDIOCGRAWINFO, &info);
-    if(res < 0) {
-        debug("failed to get hidraw_devinfo, add for now");
-    }else if(info.bustype != BUS_BLUETOOTH){
-        debug("ingore this device");
-        close(fd);
-        return -1;
-    }else if((info.vendor != global_voice_setting.vid) || (info.product != global_voice_setting.pid)) {
-        //res = unlink(fd);
-        debug("Not the device we care, add to unused fds");
-        unfds = realloc(unused_bt_hid_fds, sizeof(unused_bt_hid_fds[0]) * (nunusedfds + 1));
-        if(unfds == NULL) {
-            error("unused fds: out of memory");
-            return -1;
-        }
-
-        new_unused_device_names = realloc(unused_device_names, sizeof(unused_device_names[0]) * (nunusedfds + 1));
-        if(new_unused_device_names == NULL) {
-            error("unused device_names: out of memory");
-            return -1;
-        }
-
-        unused_bt_hid_fds = unfds;
-        unused_device_names = new_unused_device_names;
-        
-        unused_bt_hid_fds[nunusedfds] = fd;
-        unused_device_names[nunusedfds] = strdup(device);
-        nunusedfds++;
-        return 0; 
-    }
-
-    new_ufds = realloc(ufds, sizeof(ufds[0]) * (nfds + 1));
-    if(new_ufds == NULL) {
-        error("out of memory\n");
-        return -1;
-    }
-
-    ufds = new_ufds;
-    new_device_names = realloc(device_names, sizeof(device_names[0]) * (nfds + 1));
-    if(new_device_names == NULL) {
-        debug("out of memory\n");
-        return -1;
-    }
-    device_names = new_device_names;
-    //get_hidraw_info(fd);
-    ufds[nfds].fd = fd;
-    ufds[nfds].events = POLLIN;
-    device_names[nfds] = strdup(device);
-    nfds++;
-
-    return 0;
-}
-
-int close_device(const char *device)
-{
-    int i;
-    for(i = 1; i < nfds; i++) {
-        if(strcmp(device_names[i], device) == 0) {
-            int count = nfds - i - 1;
-            debug("remove device %d: %s\n", i, device);
-            free(device_names[i]);
-            memmove(device_names + i, device_names + i + 1, sizeof(device_names[0]) * count);
-            close(ufds[i].fd);
-            memmove(ufds + i, ufds + i + 1, sizeof(ufds[0]) * count);
-            nfds--;
-            return 0;
-        }
-    }
-
-    for(i = 0; i < nunusedfds; i++) {
-        if(strcmp(unused_device_names[i], device) == 0) {
-            int count = nunusedfds - i;
-            debug("remove unused device %d: %s\n", i, device);
-            free(unused_device_names[i]);
-            memmove(unused_device_names + i, unused_device_names + i + 1, sizeof(unused_device_names[0]) * count);
-            close(unused_bt_hid_fds[i]);
-            memmove(unused_bt_hid_fds + i, unused_bt_hid_fds + i + 1, sizeof(unused_bt_hid_fds[0]) * count);
-            nunusedfds--;
-            return 0;
-        }
-    }
-    
-    error("remote device: %s not found\n", device);
-    return -1;
-}
-
-static int read_notify(const char *dirname, int nfd)
-{
-    int res;
-    char devname[PATH_MAX];
-    char *filename;
-    char event_buf[512];
-    int event_size;
-    int event_pos = 0;
-    struct inotify_event *event;
-
-    res = read(nfd, event_buf, sizeof(event_buf));
-    if(res < (int)sizeof(*event)) {
-        if(errno == EINTR)
-            return 0;
-        error("could not get event, %s\n", strerror(errno));
-        return 1;
-    }
-    //printf("got %d bytes of event information\n", res);
-
-    strcpy(devname, dirname);
-    filename = devname + strlen(devname);
-    *filename++ = '/';
-
-    while(res >= (int)sizeof(*event)) {
-        event = (struct inotify_event *)(event_buf + event_pos);
-        //debug("%d: %08x \"%s\"\n", event->wd, event->mask, event->len ? event->name : "");
-        if((event->len)&&(memcmp(event->name, "hidraw", strlen("hidraw"))==0)) {
-            debug("read_notify: %d: %08x \"%s\"\n", event->wd, event->mask, event->len ? event->name : "");
-            strcpy(filename, event->name);
-            if(event->mask & IN_CREATE) {
-                open_device(devname);
-            }
-            else {
-                close_device(devname);
-            }
-        }
-        event_size = sizeof(*event) + event->len;
-        res -= event_size;
-        event_pos += event_size;
-    }
-    return 0;
-}
-
-
-static int scan_dir(const char *dirname)
-{
-    char devname[PATH_MAX];
-    char *filename;
-    DIR *dir;
-    struct dirent *de;
-    dir = opendir(dirname);
-    if(dir == NULL)
-        return -1;
-    strcpy(devname, dirname);
-    filename = devname + strlen(devname);
-    *filename++ = '/';
-    while((de = readdir(dir))) {
-        if(de->d_name[0] == '.' &&
-           (de->d_name[1] == '\0' ||
-            (de->d_name[1] == '.' && de->d_name[2] == '\0')))
-            continue;
-        if(memcmp(de->d_name,"hidraw",strlen("hidraw")))
-            continue;
-        strcpy(filename, de->d_name);
-        //debug("scan_dir: %s\n",devname);
-        open_device(devname);
-    }
-    closedir(dir);
-    return 0;
-}
-
-static void voice_ctrl_recv(void)
-{
-    unsigned char cmd[256], opcode = 0xFF;
-    int n, i;
-
-    n = UIPC_Read(UIPC_CH_ID_VOICE_CTRL, NULL, cmd, 256);
-
-    /* detach on ctrl channel means audioflinger process was terminated */
-    if (n == 0)
-    {
-        debug("CTRL CH DETACHED");
-        //the ctrl channel will re-open automatically
-        UIPC_Close(UIPC_CH_ID_VOICE_CTRL);
-        return;
-    }
-
-    debug("receive voice-ctrl-cmd read num_of_data = %d ", n);
-    for (i=0; i< n; i++)
-        info("data[%d] = %d ", i, cmd[i]);
-    //receive start or stop cmd from service
-    if( cmd[0] <= OPCODE_MAX)
-    {
-        opcode = cmd[0];
-    }
-    else
-    {
-        //clear the memory
-        UIPC_Ioctl(UIPC_CH_ID_VOICE_CTRL, UIPC_REQ_RX_FLUSH,NULL);
-        info("it is wrong cmd send from service");
-    }
-
-    info("opcode = %d",opcode);
-    switch(opcode)
-    {
-        case OPCODE_SETTING_RESET:              //0   cmd(1)
-            break;
-
-        case OPCODE_VOICE_START_CMD:            //1   cmd(1)
-            debug("start, len=%d", n);
-            break;
-
-        case OPCODE_VOICE_STOP_CMD:             //2   cmd(1)
-            debug("stop, len=%d", n);
-            break;
-
-        case OPCODE_SET_RCU_INFO:               //3   cmd(1) + vid(2) + pid(2) + vers(2)
-            if(n == 7) {
-                int vid = (cmd[1] << 8) + cmd[2];
-                int pid = (cmd[3] << 8) + cmd[4];
-                int vers = (cmd[5] << 8) + cmd[6];
-                set_rcu_info(vid,pid,vers);
-            }
-            break;
-
-        case OPCODE_SET_VOICE_DATA_REPORT_ID:   //4   cmd(1) + reportID(1)
-            if(n == 2) {
-                set_voice_data_reportID(cmd[1]);
-            }
-            break;
-
-        case OPCODE_SET_VOICE_CMD_REPORT_ID:    //5   cmd(1) + reportID(1)
-            if(n == 2) {
-                set_voice_cmd_reportID(cmd[1]);
-            }
-            break;
-
-        case OPCODE_SET_VOICE_KEY_REPORT_ID:    //6   cmd(1) + reportID(1)
-            if(n == 2) {
-                set_voice_key_reportID(cmd[1]);
-            }
-            break;
-
-        case OPCODE_SET_VOICE_KEYPRESS_DATA:    //7   cmd(1) + len(1) + data(n)
-            if(n > 2) {
-                int len = cmd[1];
-                set_voice_keypress_data(len, cmd + 2);
-            }
-            break;
-
-        case OPCODE_SET_VOICE_KEYRELEASE_DATA:  //8   cmd(1) + len(1) + data(n)
-            if(n > 2) {
-                int len = cmd[1];
-                set_voice_keyrelease_data(len, cmd + 2);
-            }
-            break;
-
-        case OPCODE_SET_VOICE_STARTCMD_DATA:    //9   cmd(1) + len(1) + data(n)
-            debug("set voice start data, len=%d", cmd[1]);
-            break;
-
-        case OPCODE_SET_VOICE_STOPCMD_DATA:     //10  cmd(1) + len(1) + data(n)
-            debug("set voice stop data, len=%d", cmd[1]);
-            break;
-
-        case OPCODE_SET_ENCODE_TYPE:            //11  cmd(1) + type(1)
-            if(n == 2) {
-                set_encode_type(cmd[1]);
-            }
-            break;
-
-        case OPCODE_SET_DATA_TYPE_MASK:         //12  cmd(1) + type(1)
-            debug("set type mask: 0x%02x", cmd[1]);
-            break;
-
-        case OPCODE_SET_AUTO_CMD:               //13  cmd(1) + auto(1)
-            if(n == 2) {
-                set_auto_cmd(cmd[1]);
-            }
-            break;
-
-        case OPCODESEND_HIDRAW_DATA:            //14  cmd(1) + reportID(1) + len(1) + data(n)
-            debug("send raw data, reportID=0x%02x, len=0x%02x", cmd[1], cmd[2]);
-            break;
-
-        case OPCODE_EXIT:
-            debug("exit");
-            gSocket_Running = 0;
-    }
-
-    info("voice-ctrl-cmd DOWN!");
-}
-
-static void voice_data_recv(void)
-{
-    unsigned char cmd[256], opcode = 0xFF;
-    int n, i;
-
-    n = UIPC_Read(UIPC_CH_ID_VOICE_DATA, NULL, cmd, 256);
-
-    /* detach on ctrl channel means audioflinger process was terminated */
-    if (n == 0)
-    {
-        debug("DATA CH DETACHED");
-        //the ctrl channel will re-open automatically
-        UIPC_Close(UIPC_CH_ID_VOICE_DATA);
-        return;
-    }
-
-    debug("receive voice-data read num_of_data = %d ", n);
-}
-
-
-static void ctrl_socket_cb(tUIPC_CH_ID ch_id, tUIPC_EVENT event)
-{
-
-    switch(event)
-    {
-        case UIPC_OPEN_EVT:
-            /*
-                in certain case, hid status msg must be sent upon ctrl chan opened
-             */
-            debug("Jim@control_socket_cb: sending hid status msg upon open");
-            break;
-
-        case UIPC_CLOSE_EVT:
-            if (gSocket_Running) {
-                debug("jim@control_socket_cb: re-open ctrl chan");
-                UIPC_Open(UIPC_CH_ID_VOICE_CTRL, ctrl_socket_cb);
-            }
-            break;
-
-        case UIPC_RX_DATA_EVT:
-            info("btif_voice_ctrl_cb, the event is UIPC_RX_DATA_EVT");
-
-        case UIPC_RX_DATA_READY_EVT:
-            voice_ctrl_recv();
-            break;
-
-        default :
-            info("### VOICE-CTRL-CHANNEL EVENT %d NOT HANDLED ###", event);
-            break;
-    }
-}
-
-static void data_socket_cb(tUIPC_CH_ID ch_id, tUIPC_EVENT event)
-{
-
-    debug("data_socket_cb");
-    switch(event)
-    {
-        case UIPC_OPEN_EVT:
-            debug("Jim@data_socket_cb: sending hid status msg upon open");
-            break;
-
-        case UIPC_CLOSE_EVT:
-            if (gSocket_Running) {
-                debug("jim@data_socket_cb: re-open data chan");
-                UIPC_Open(UIPC_CH_ID_VOICE_DATA, data_socket_cb);
-            }
-            break;
-
-        case UIPC_RX_DATA_EVT:
-            info("data_socket_cb, the event is UIPC_RX_DATA_EVT");
-
-        case UIPC_RX_DATA_READY_EVT:
-            voice_data_recv();
-            info("data_socket_cb, the event is UIPC_RX_DATA_READY_EVT");
-            break;
-
-        default :
-            info("### VOICE-DATA-CHANNEL EVENT %d NOT HANDLED ###", event);
-            break;
-    }
-}
-
-
-
-int init(void) {
-
-    pthread_mutex_init(&mutex_voice_settings, NULL);
-    voice_msbc_init();
-    sbcInitDecoder();
-
-    gSocket_Running = 1;
-    UIPC_Init(NULL);
-    UIPC_Open(UIPC_CH_ID_VOICE_CTRL, ctrl_socket_cb);
-    UIPC_Open(UIPC_CH_ID_VOICE_DATA, data_socket_cb);
-
-    return 0;
-}
-
-void cleanup(void) {
-
-    gSocket_Running = 0;
-    UIPC_Close(UIPC_CH_ID_VOICE_DATA);
-    UIPC_Close(UIPC_CH_ID_VOICE_CTRL);
-
-    pthread_mutex_lock(&mutex_voice_settings);
-    
-    
-    if(global_voice_setting.voice_keypress_data != NULL)
-        free(global_voice_setting.voice_keypress_data);
-
-    if(global_voice_setting.voice_keyrelease_data != NULL)
-        free(global_voice_setting.voice_keyrelease_data);
-
-    pthread_mutex_unlock(&mutex_voice_settings);
-    //release other resources here
-}
-
-
-int main(void) {
-    const char *device_path = "/dev";
-    int res;
-    int i;
-
-    init();
-
-    nfds = 1;
-    ufds = calloc(1, sizeof(ufds[0]));
-    ufds[0].fd = inotify_init();
-    ufds[0].events = POLLIN;
-
-    res = inotify_add_watch(ufds[0].fd, device_path, IN_DELETE | IN_CREATE);
-    if(res < 0) {
-        error("could not add watch for %s, %s\n", device_path, strerror(errno));
-        return -1;
-    }
-
-    res = scan_dir(device_path);
-    if(res < 0) {
-        error("scan dir failed for %s\n", device_path);
-        return -2;
-    }
-
-    while(gSocket_Running) {
-        poll(ufds, nfds, -1);
-        if(ufds[0].revents & POLLIN) {
-            //debug("new notify event!!!");
-            read_notify(device_path, ufds[0].fd);
-        }
-
-        for(i = 1; i < nfds; i++) {
-            if(ufds[i].revents) {
-                /*
-                //debug("new message event, fd = %d, event = %04x.", ufds[i].fd, ufds[i].revents);
-                if((ufds[i].revents & POLLHUP) && (ufds[i].revents & POLLERR)) {
-                    debug("close, fd=%d, events=0x%04x", ufds[i].fd, ufds[i].revents);
-                    close(ufds[i].fd);
-                 
-                }else if(ufds[i].revents & POLLIN) {
-                    //debug("new message event!!!");
-                    read_message(ufds[i].fd);
-                }
-                */
-                if(ufds[i].revents & POLLIN) {
-                    //debug("new message event!!!");
-                    read_message(ufds[i].fd);
-                }
-            }
-        }
-    }
-    cleanup();
-    
-    return 0;
-
-}
-
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <stdint.h>\r
+#include <dirent.h>\r
+#include <fcntl.h>\r
+#include <sys/ioctl.h>\r
+#include <sys/inotify.h>\r
+#include <sys/poll.h>\r
+#include <linux/input.h>\r
+#include <linux/hidraw.h>\r
+#include <errno.h>\r
+#include <time.h>\r
+#include <unistd.h>\r
+\r
+#include <pthread.h>\r
+\r
+\r
+#include "voice_hidraw.h"\r
+#include "bee_settings.h"\r
+#include "get_voice_app.h"\r
+#include "sbc.h"\r
+#include "voice_uipc.h"\r
+#include "config.h"\r
+\r
+#define RAW_DATA_PATH "/data/vr/raw_data"\r
+static int file_counter = 0;\r
+int raw_fd;\r
+int gSocket_Running = 0;\r
+int gTarget_fd = 0;\r
+\r
+\r
+\r
+typedef struct {\r
+    int vid;\r
+    int pid;\r
+    int vers;\r
+    unsigned char voice_key_reportID;\r
+    unsigned char voice_data_reportID;\r
+    unsigned char voice_cmd_reportID;\r
+    int voice_keypress_data_len;\r
+    unsigned char *voice_keypress_data;\r
+    int voice_keyrelease_data_len;\r
+    unsigned char *voice_keyrelease_data;\r
+    int decode_type;\r
+    int data_mask;\r
+    int autocmd;\r
+    \r
+}VOICE_SETTING;\r
+\r
+static struct pollfd *ufds;\r
+static char **device_names;\r
+static int nfds;\r
+\r
+static int *unused_bt_hid_fds;\r
+static int nunusedfds;\r
+static char **unused_device_names;\r
+\r
+\r
+VOICE_SETTING global_voice_setting;\r
+pthread_mutex_t mutex_voice_settings;\r
+\r
+int frame_counter = 0;\r
+\r
+int set_rcu_info(int vid, int pid, int vers) {\r
+    pthread_mutex_lock(&mutex_voice_settings);\r
+    if(vid != -1)\r
+        global_voice_setting.vid = vid;\r
+\r
+    if(pid != -1)\r
+        global_voice_setting.pid = pid;\r
+\r
+    if(vers != -1)\r
+        global_voice_setting.vers = vers;\r
+\r
+    pthread_mutex_unlock(&mutex_voice_settings);\r
+\r
+    return 0;\r
+}\r
+\r
+int set_voice_data_reportID(unsigned char reportID) {\r
+    pthread_mutex_lock(&mutex_voice_settings);\r
+    global_voice_setting.voice_data_reportID = reportID;\r
+    pthread_mutex_unlock(&mutex_voice_settings);\r
+    return 0;\r
+}\r
+\r
+int set_voice_cmd_reportID(unsigned char reportID) {\r
+    pthread_mutex_lock(&mutex_voice_settings);\r
+    global_voice_setting.voice_cmd_reportID = reportID;\r
+    pthread_mutex_unlock(&mutex_voice_settings);\r
+    return 0;\r
+}\r
+\r
+int set_voice_key_reportID(unsigned char reportID) {\r
+    pthread_mutex_lock(&mutex_voice_settings);\r
+    global_voice_setting.voice_key_reportID = reportID;\r
+    pthread_mutex_unlock(&mutex_voice_settings);\r
+    return 0;\r
+}\r
+\r
+int set_voice_keypress_data(int len, unsigned char *data) {\r
+    if(len > 0) {\r
+        pthread_mutex_lock(&mutex_voice_settings);\r
+        if(global_voice_setting.voice_keypress_data != NULL) {\r
+            if(global_voice_setting.voice_keypress_data_len < len) {\r
+\r
+                unsigned char *buf = (unsigned char *)realloc(global_voice_setting.voice_keypress_data, len);\r
+                if(buf == NULL) {\r
+                    //log\r
+                    pthread_mutex_unlock(&mutex_voice_settings);\r
+                    error("Failed to realloc for voice_keypress_data");\r
+                    return -1;\r
+                }else {\r
+                    global_voice_setting.voice_keypress_data = buf;\r
+                }\r
+            }\r
+        }else {\r
+            global_voice_setting.voice_keypress_data = (unsigned char *)malloc(len);\r
+            if(global_voice_setting.voice_keypress_data == NULL) {\r
+                //log\r
+                pthread_mutex_unlock(&mutex_voice_settings);\r
+                error("Failed to malloc for voice_keypress_data");\r
+                return -2;\r
+            }\r
+        }\r
+\r
+        memcpy(global_voice_setting.voice_keypress_data, data, len);\r
+        global_voice_setting.voice_keypress_data_len = len;\r
+        pthread_mutex_unlock(&mutex_voice_settings);\r
+        return 0;\r
+    }else {\r
+        warn("len is negative for voice_keypress_data");\r
+        return -3;\r
+    }\r
+}\r
+\r
+int set_voice_keyrelease_data(int len, unsigned char *data) {\r
+    if(len > 0) {\r
+        pthread_mutex_lock(&mutex_voice_settings);\r
+        if(global_voice_setting.voice_keyrelease_data != NULL) {\r
+            if(global_voice_setting.voice_keyrelease_data_len < len) {\r
+                unsigned char *buf = (unsigned char *)realloc(global_voice_setting.voice_keyrelease_data, len);\r
+                if(buf == NULL) {\r
+                    //log\r
+                    pthread_mutex_unlock(&mutex_voice_settings);\r
+                    error("Failed to realloc for voice_keypress_data");\r
+                    return -1;\r
+                }else {\r
+                    global_voice_setting.voice_keyrelease_data = buf;\r
+                }\r
+            }\r
+        }else {\r
+            global_voice_setting.voice_keyrelease_data = (unsigned char *)malloc(len);\r
+            if(global_voice_setting.voice_keyrelease_data == NULL) {\r
+                pthread_mutex_unlock(&mutex_voice_settings);\r
+                error("Failed to malloc for voice_keyrelease_data");\r
+                return -2;\r
+            }\r
+        }\r
+\r
+        memcpy(global_voice_setting.voice_keyrelease_data, data, len);\r
+        global_voice_setting.voice_keyrelease_data_len = len;\r
+        pthread_mutex_unlock(&mutex_voice_settings);\r
+        return 0;\r
+    }else {\r
+        //log\r
+        warn("len is negative for voice_keyrelease_data");\r
+        return -3;\r
+    }\r
+}\r
+\r
+int set_encode_type(int type) {\r
+    if(type <= DECODE_TYPE_MAX) {\r
+        pthread_mutex_lock(&mutex_voice_settings);\r
+        global_voice_setting.decode_type = type;\r
+        pthread_mutex_unlock(&mutex_voice_settings);\r
+        return 0;\r
+    }else {\r
+        warn("Unknown Decode Type !!!");\r
+        return -1;\r
+    }\r
+}\r
+\r
+int data_type_mask(int mask) {\r
+    //log\r
+    debug("Set Data Type Mask 0x%04x", mask);\r
+\r
+    pthread_mutex_lock(&mutex_voice_settings);\r
+    \r
+    if(mask & DATA_TYPE_MASK_RAW) {\r
+        global_voice_setting.data_mask = DATA_TYPE_MASK_RAW;\r
+    }else {\r
+        if(mask & DATA_TYPE_MASK_VOICE) {\r
+            global_voice_setting.data_mask |= DATA_TYPE_MASK_VOICE;\r
+        }\r
+    }\r
+\r
+    pthread_mutex_unlock(&mutex_voice_settings);\r
+    return 0;\r
+}\r
+\r
+int set_auto_cmd(int autocmd) {\r
+    pthread_mutex_lock(&mutex_voice_settings);\r
+    if(autocmd == 1) {\r
+        global_voice_setting.autocmd = AUTOCMD_AUTO;\r
+    }else if(autocmd == 2){\r
+        global_voice_setting.autocmd = AUTOCMD_NONE;\r
+    }\r
+    pthread_mutex_unlock(&mutex_voice_settings);\r
+\r
+    return 0;\r
+}\r
+\r
+\r
+\r
+int voice_msbc_init() {\r
+\r
+    int ivalue, i;\r
+   \r
+    voice_loadconfig(CONFIG_PATH);\r
+\r
+    pthread_mutex_lock(&mutex_voice_settings);\r
+    \r
+    memset(&global_voice_setting, 0, sizeof(global_voice_setting));\r
+\r
+    ivalue = voice_get_int_config(CONFIG_GROUP_RCU, CONFIG_ITEM_RCU_VID);\r
+    if(ivalue >= 0) {\r
+        global_voice_setting.vid = ivalue;\r
+        ALOGD("use config VID: %04x", global_voice_setting.vid);\r
+    } else {\r
+        global_voice_setting.vid = BEE_RCU_VID;\r
+        ALOGD("use default VID: %04x", global_voice_setting.vid);\r
+    }\r
+\r
+    ivalue = voice_get_int_config(CONFIG_GROUP_RCU, CONFIG_ITEM_RCU_PID);\r
+    if(ivalue >= 0) {\r
+        global_voice_setting.pid = ivalue;\r
+        ALOGD("use config PID: %04x", global_voice_setting.pid);\r
+    } else {\r
+        global_voice_setting.pid = BEE_RCU_PID;\r
+        ALOGD("use default PID: %04x", global_voice_setting.pid);\r
+    }\r
+\r
+    ivalue = voice_get_int_config(CONFIG_GROUP_RCU, CONFIG_ITEM_RCU_VER);\r
+    if(ivalue >= 0) {\r
+        global_voice_setting.vers = ivalue;\r
+        ALOGD("use config version: %04x", global_voice_setting.vers);\r
+    } else {\r
+        global_voice_setting.vers = BEE_RCU_VERSION;\r
+        ALOGD("use default VERSION: %04x", global_voice_setting.vers);\r
+    }\r
+\r
+    ivalue = voice_get_int_config(CONFIG_GROUP_REPORTID, CONFIG_ITEM_REPORTID_KEY);\r
+    if(ivalue > 0) {\r
+        global_voice_setting.voice_key_reportID = ivalue & 0xff;\r
+        ALOGD("use config key report id: %02x", global_voice_setting.voice_key_reportID);\r
+    } else {\r
+        global_voice_setting.voice_key_reportID = BEE_VOICEKEY_REPORTID;\r
+        ALOGD("use default key report id: %02x", global_voice_setting.voice_key_reportID);\r
+    }\r
+    \r
+\r
+    ivalue = voice_get_int_config(CONFIG_GROUP_REPORTID, CONFIG_ITEM_REPORTID_DATA);\r
+    if(ivalue > 0) {\r
+        global_voice_setting.voice_data_reportID = ivalue & 0xff;\r
+        ALOGD("use config data report id: %02x", global_voice_setting.voice_data_reportID);\r
+    } else {\r
+        global_voice_setting.voice_data_reportID = BEE_MSBC_VOICEDATA_REPORTID;\r
+        ALOGD("use default data report id: %02x", global_voice_setting.voice_data_reportID);\r
+    }\r
+\r
+    ivalue = voice_get_int_config(CONFIG_GROUP_REPORTID, CONFIG_ITEM_REPORTID_CMD);\r
+    if(ivalue > 0) {\r
+        global_voice_setting.voice_cmd_reportID = ivalue & 0xff;\r
+        ALOGD("use config cmd report id: %02x", global_voice_setting.voice_cmd_reportID);\r
+    } else {\r
+        global_voice_setting.voice_cmd_reportID = BEE_MSBC_VOICECMD_REPORTID;\r
+        ALOGD("use default cmd report id: %02x", global_voice_setting.voice_cmd_reportID);\r
+    }\r
+\r
+    ivalue = voice_get_int_config(CONFIG_GROUP_REPORTVALUE, CONFIG_ITEM_REPORTVALUE_KEYDOWNLEN);\r
+    if(ivalue > 0) {\r
+        global_voice_setting.voice_keypress_data_len = ivalue;\r
+        ALOGD("use config keydown len: %d", global_voice_setting.voice_keypress_data_len);\r
+    } else {\r
+        global_voice_setting.voice_keypress_data_len = BEE_VOICEKEY_LEN;\r
+        ALOGD("use default keydown len: %d", global_voice_setting.voice_keypress_data_len);\r
+    }\r
+\r
+    global_voice_setting.voice_keypress_data = (unsigned char *)malloc(global_voice_setting.voice_keypress_data_len);\r
+    if(global_voice_setting.voice_keypress_data == NULL) {\r
+        //log\r
+        error("failed to get buf for keydown");\r
+        pthread_mutex_unlock(&mutex_voice_settings);\r
+        return -1;\r
+    }else {\r
+        if(ivalue > 0) {\r
+            if(voice_get_byte_array_config(CONFIG_GROUP_REPORTVALUE, CONFIG_ITEM_REPORTVALUE_KEYDOWN,\r
+                global_voice_setting.voice_keypress_data, global_voice_setting.voice_keypress_data_len)\r
+                != global_voice_setting.voice_keypress_data_len) {\r
+                \r
+                global_voice_setting.voice_keypress_data_len = BEE_VOICEKEY_LEN;\r
+                if(ivalue < BEE_VOICEKEY_LEN) {\r
+                    global_voice_setting.voice_keypress_data = (unsigned char *)realloc(global_voice_setting.voice_keypress_data, BEE_VOICEKEY_LEN);\r
+                    if(global_voice_setting.voice_keypress_data == NULL) {\r
+                        error("failed to realloc buf for keydown");\r
+                        pthread_mutex_unlock(&mutex_voice_settings);\r
+                        return -1;\r
+                    }\r
+                }\r
+                memcpy(global_voice_setting.voice_keypress_data, BEE_VOICE_KEYDOWN_DATA, global_voice_setting.voice_keypress_data_len);\r
+                ALOGD("use default keydown data");\r
+            }\r
+        }else {\r
+            memcpy(global_voice_setting.voice_keypress_data, BEE_VOICE_KEYDOWN_DATA, global_voice_setting.voice_keypress_data_len);\r
+            ALOGD("use default keydown data");\r
+        }\r
+        ALOGD("key down data:");\r
+        for(i = 0; i < global_voice_setting.voice_keypress_data_len; i++) {\r
+            ALOGD("data[%d] = %02x", i, *(global_voice_setting.voice_keypress_data + i));\r
+        }\r
+    }\r
+\r
+    ivalue = voice_get_int_config(CONFIG_GROUP_REPORTVALUE, CONFIG_ITEM_REPORTVALUE_KEYUPLEN);\r
+    if(ivalue > 0) {\r
+        global_voice_setting.voice_keyrelease_data_len = ivalue;\r
+        ALOGD("use config keyup len: %d", global_voice_setting.voice_keyrelease_data_len);\r
+    } else {\r
+        global_voice_setting.voice_keyrelease_data_len = BEE_VOICEKEY_LEN;\r
+        ALOGD("use default keyup len: %d", global_voice_setting.voice_keyrelease_data_len);\r
+    }\r
+\r
+    global_voice_setting.voice_keyrelease_data = (unsigned char *)malloc(global_voice_setting.voice_keyrelease_data_len);\r
+    if(global_voice_setting.voice_keyrelease_data == NULL) {\r
+        //log\r
+        error("failed to get buf for keyup");\r
+        pthread_mutex_unlock(&mutex_voice_settings);\r
+        return -1;\r
+    }else {\r
+        if(ivalue > 0) {\r
+            if(voice_get_byte_array_config(CONFIG_GROUP_REPORTVALUE, CONFIG_ITEM_REPORTVALUE_KEYUP,\r
+                global_voice_setting.voice_keyrelease_data, global_voice_setting.voice_keyrelease_data_len)\r
+                != global_voice_setting.voice_keyrelease_data_len) {\r
+                \r
+                global_voice_setting.voice_keyrelease_data_len = BEE_VOICEKEY_LEN;\r
+                if(ivalue < BEE_VOICEKEY_LEN) {\r
+                    global_voice_setting.voice_keyrelease_data = (unsigned char *)realloc(global_voice_setting.voice_keyrelease_data, BEE_VOICEKEY_LEN);\r
+                    if(global_voice_setting.voice_keyrelease_data == NULL) {\r
+                        error("failed to realloc buf for keyup");\r
+                        pthread_mutex_unlock(&mutex_voice_settings);\r
+                        return -1;\r
+                    }\r
+                }\r
+                memcpy(global_voice_setting.voice_keyrelease_data, BEE_VOICE_KEYUP_DATA, global_voice_setting.voice_keyrelease_data_len);\r
+                ALOGD("use default keyup data");\r
+            }\r
+        }else {\r
+            memcpy(global_voice_setting.voice_keyrelease_data, BEE_VOICE_KEYUP_DATA, global_voice_setting.voice_keyrelease_data_len);\r
+            ALOGD("use default keyup data");\r
+        }\r
+        ALOGD("key up data:");\r
+        for(i = 0; i < global_voice_setting.voice_keyrelease_data_len; i++) {\r
+            ALOGD("data[%d] = %02x", i, *(global_voice_setting.voice_keyrelease_data + i));\r
+        }\r
+    }\r
+\r
+    ivalue = voice_get_int_config(CONFIG_GROUP_SETTINGS, CONFIG_ITEM_SETTINGS_DECODETYPE);\r
+    if(ivalue > 0) {\r
+        global_voice_setting.decode_type = ivalue;\r
+        ALOGD("use config decode type: %d", global_voice_setting.decode_type);\r
+    } else {\r
+        global_voice_setting.decode_type = DECODE_TYPE_MSBC;\r
+        ALOGD("use default decode type: %d", global_voice_setting.decode_type);\r
+    }\r
+\r
+    ivalue = voice_get_int_config(CONFIG_GROUP_SETTINGS, CONFIG_ITEM_SETTINGS_DATAMASK);\r
+    if(ivalue > 0) {\r
+        global_voice_setting.data_mask = ivalue;\r
+        ALOGD("use config data mask: %d", global_voice_setting.data_mask);\r
+    } else {\r
+        global_voice_setting.data_mask = DATA_TYPE_MASK_VOICE;\r
+        ALOGD("use default decode type: %d", global_voice_setting.data_mask);\r
+    }\r
+\r
+    ivalue = voice_get_int_config(CONFIG_GROUP_SETTINGS, CONFIG_ITEM_SETTINGS_AUTOCMD);\r
+    if(ivalue > 0) {\r
+        global_voice_setting.autocmd = ivalue;\r
+        ALOGD("use config decode type: %d", global_voice_setting.autocmd);\r
+    } else {\r
+        global_voice_setting.autocmd = AUTOCMD_AUTO;\r
+        ALOGD("use default decode type: %d", global_voice_setting.autocmd);\r
+    }\r
+\r
+    pthread_mutex_unlock(&mutex_voice_settings);\r
+    voice_conf_exit();\r
+    return 0;\r
+}\r
+\r
+void voice_open_store_file()\r
+{\r
+    char record_name[50] = {0}; \r
+    sprintf(record_name, "%s%d", RAW_DATA_PATH, file_counter);\r
+\r
+    raw_fd =  open (record_name, O_WRONLY | O_CREAT |O_TRUNC, 0644);\r
+\r
+    if(raw_fd < 0)\r
+    {\r
+        ALOGE("can't open record file:%s ", record_name);\r
+    }\r
+\r
+\r
+       return;\r
+}\r
+\r
+int voice_write_decode_buf(uint8* pu_decode, ssize_t len)\r
+{\r
+    if (raw_fd > 0)\r
+    {\r
+        write (raw_fd, pu_decode, len);\r
+        return 0;\r
+    }\r
+    return -1;\r
+}\r
+\r
+\r
+/**********************************************\r
+*\r
+*   hidraw node related\r
+*\r
+***********************************************/\r
+const char *bus_str(int bus){\r
+    switch (bus) {\r
+        case BUS_USB:\r
+            return "USB";\r
+            \r
+        case BUS_HIL:\r
+            return "HIL";\r
+            \r
+        case BUS_BLUETOOTH:\r
+            return "Bluetooth";\r
+\r
+        case BUS_VIRTUAL:\r
+            return "Virtual";\r
+                \r
+        default:\r
+            return "Other";\r
+    }\r
+}\r
+    \r
+static int get_hidraw_info(int fd)\r
+{\r
+    int i, res, desc_size = 0;\r
+    char buf[256];\r
+    struct hidraw_report_descriptor rpt_desc;\r
+    struct hidraw_devinfo info;\r
+    \r
+    memset(&rpt_desc, 0x0, sizeof(rpt_desc));\r
+    memset(&info, 0x0, sizeof(info));\r
+    memset(buf, 0x0, sizeof(buf));\r
+    debug("-----------------------------------------------\n");\r
+    \r
+    /* Get Raw Name */\r
+    res = ioctl(fd, HIDIOCGRAWNAME(256), buf);\r
+    if (res < 0)\r
+        perror("HIDIOCGRAWNAME");\r
+    else\r
+        debug("Raw Name: %s\n", buf);\r
+    /* Get Physical Location */\r
+    res = ioctl(fd, HIDIOCGRAWPHYS(256), buf);\r
+    if (res < 0)\r
+        perror("HIDIOCGRAWPHYS");\r
+    else\r
+        debug("Raw Phys: %s\n", buf);\r
+    /* Get Raw Info */\r
+    res = ioctl(fd, HIDIOCGRAWINFO, &info);\r
+    if (res < 0) {\r
+        perror("HIDIOCGRAWINFO");\r
+    } else {\r
+        debug("Raw Info:");\r
+        debug(" bustype: %d (%s)", info.bustype, bus_str(info.bustype));\r
+        debug(" vendor: 0x%04x", info.vendor);\r
+        debug(" product: 0x%04x\n", info.product);\r
+    }\r
+    /* Get Report Descriptor Size */\r
+    res = ioctl(fd, HIDIOCGRDESCSIZE, &desc_size);\r
+    if (res < 0)\r
+       perror("HIDIOCGRDESCSIZE");\r
+    else\r
+        debug("Report Descriptor Size: %d\n", desc_size);\r
+    /* Get Report Descriptor */\r
+    rpt_desc.size = desc_size;\r
+    res = ioctl(fd, HIDIOCGRDESC, &rpt_desc);\r
+    if (res < 0) {\r
+        perror("HIDIOCGRDESC");\r
+    } else {\r
+        debug("Report Descriptor:");\r
+        for (i = 0; i < rpt_desc.size; i++)\r
+        {\r
+            if((i%16)==0)\r
+                debug("\n");\r
+            debug("%02x ", rpt_desc.value[i]);\r
+        }\r
+        debug("\n");\r
+    }\r
+    info("-----------------------------------------------\n");\r
+    \r
+    return 0;\r
+}\r
+\r
+static int send_message(int fd, unsigned char * buf, int len)\r
+{\r
+    int res = 0;\r
+    res = write(fd, buf, len);\r
+    debug("send_message res=%d\n",res);\r
+    return res;\r
+}\r
+\r
+static void process_voice_data(unsigned char reportID, unsigned char *buf, int len) {\r
+    int ret = -1;\r
+    int offset = 0;\r
+    int i;\r
+    int decode_len = 0;\r
+\r
+    unsigned char output_buf[1024] = {0x00};\r
+\r
+    //debug("reportID=%d, decode_type=%d, global_reportID=%d, len=%d", \r
+        //reportID, global_voice_setting.decode_type, global_voice_setting.voice_data_reportID, len);\r
+\r
+    if(global_voice_setting.decode_type == DECODE_TYPE_MSBC) {\r
+        while(offset + BEE_MSBC_FRAME_SIZE <= len) {\r
+            //debug("offset is %d now, len is %d", offset, len);\r
+            ret = RS_deal_voice_stream_data(buf + offset, BEE_MSBC_FRAME_SIZE, output_buf, 1024, &decode_len);\r
+            if(ret < 0) {\r
+                offset++;\r
+            }else {\r
+                UIPC_Send_noblock(UIPC_CH_ID_VOICE_DATA, 0, output_buf, decode_len);\r
+                offset += BEE_MSBC_FRAME_SIZE;\r
+            }\r
+        }\r
+    }else if(global_voice_setting.decode_type == DECODE_TYPE_SBC) {\r
+        decode_len = 1024;\r
+        while(offset + BEE_SBC_FRAME_SIZE <= len) {\r
+            ret = sbcDecode(buf + offset, BEE_SBC_FRAME_SIZE, output_buf, &decode_len);\r
+            if(ret < 0) {\r
+                debug("fail to decode: %d", ret);\r
+                offset++;\r
+            }else {\r
+                UIPC_Send_noblock(UIPC_CH_ID_VOICE_DATA, 0, output_buf, decode_len);\r
+                offset += BEE_SBC_FRAME_SIZE;\r
+            }\r
+        }\r
+    }\r
+}\r
+\r
+static int read_message(int fd)\r
+{\r
+    unsigned char buf[4096];\r
+    int res,i;\r
+\r
+    unsigned char start_rec_command[] = {global_voice_setting.voice_cmd_reportID, 0x01};\r
+    unsigned char stop_rec_command[] = {global_voice_setting.voice_cmd_reportID, 0x00};\r
+    static int voice_kpressed = 0;\r
+\r
+/*\r
+    struct hidraw_devinfo info;\r
\r
+    res = ioctl(fd, HIDIOCGRAWINFO, &info);\r
+    if (res < 0) {\r
+        perror("HIDIOCGRAWINFO");\r
+    }\r
+*/\r
+\r
+    //if( (info.vendor==global_voice_setting.vid) && (info.product==global_voice_setting.pid) )\r
+    //{\r
+        res = read(fd, buf, sizeof(buf));\r
+        if(res > 0)\r
+        {\r
+            //debug("Receive From :%04x,%04x number: %d", info.vendor, info.product, res);\r
+            if( (global_voice_setting.data_mask & DATA_TYPE_MASK_RAW) == DATA_TYPE_MASK_RAW) {\r
+                //just callback and return\r
+                UIPC_Send_noblock(UIPC_CH_ID_VOICE_DATA, 0, buf + 1, res - 1);\r
+                return 0;\r
+            }else if( (global_voice_setting.data_mask & DATA_TYPE_MASK_VOICE) == DATA_TYPE_MASK_VOICE) {\r
+                if((voice_kpressed == 0) && (buf[0] == global_voice_setting.voice_key_reportID) && \r
+                    (res == global_voice_setting.voice_keypress_data_len + 1) && \r
+                    (memcmp(buf + 1, global_voice_setting.voice_keypress_data, global_voice_setting.voice_keypress_data_len) == 0))\r
+                {\r
+                    //debug("voice key pressed");\r
+                    if(global_voice_setting.autocmd == AUTOCMD_AUTO) {\r
+                        RS_voice_app_create_output();\r
+                        RS_voice_app_create_origin_output();\r
+                        voice_open_store_file();\r
+\r
+                        send_message(fd, start_rec_command,sizeof(start_rec_command));\r
+                        voice_kpressed = 1;\r
+                        frame_counter = 0;\r
+                    }\r
+                    return 0;\r
+                }\r
+\r
+                // when voice key is released\r
+                if ((voice_kpressed == 1) && (buf[0] == global_voice_setting.voice_key_reportID) && \r
+                    (res == global_voice_setting.voice_keyrelease_data_len + 1) && \r
+                    (memcmp(buf + 1, global_voice_setting.voice_keyrelease_data, global_voice_setting.voice_keyrelease_data_len) == 0))\r
+                {\r
+                    //debug("voice key relesed");\r
+\r
+                    if(global_voice_setting.autocmd == AUTOCMD_AUTO) {\r
+                        RS_stop_voice_stream_data();\r
+                        send_message(fd, stop_rec_command,sizeof(stop_rec_command));\r
+                        voice_kpressed = 0;\r
+                        debug("total frame: %d", frame_counter);\r
+                        close(raw_fd);\r
+                        file_counter++;\r
+                        raw_fd = -1;\r
+                    }\r
+                    return 0;\r
+                }\r
+\r
+                // store voice data\r
+                if ((voice_kpressed == 1 ) && (buf[0] == global_voice_setting.voice_data_reportID))\r
+                {\r
+                    //debug("deal with voice data");\r
+                    process_voice_data(buf[0], buf + 1, res-1);\r
+                    voice_write_decode_buf(buf + 1, res - 1);\r
+                    frame_counter++;\r
+                    return 0;\r
+                }\r
+            }\r
+        }else {\r
+            warn("Read fd %d failed: %s", fd, strerror(errno));\r
+            return -1;\r
+        }\r
+        \r
+    //}\r
+\r
+    return 0;\r
+}\r
+\r
+int get_dev_vid_pid_info(int fd, short* vid, short* pid) {\r
+    int res = -1;\r
+    struct hidraw_devinfo info;\r
+\r
+    memset(&info, 0x0, sizeof(info));\r
+\r
+    res = ioctl(fd, HIDIOCGRAWINFO, &info);\r
+    if (res < 0) {\r
+        debug("failed to get HIDIOCGRAWINFO");\r
+    } else {\r
+        //debug("Raw Info:");\r
+        //debug(" bustype: %d (%s)", info.bustype, bus_str(info.bustype));\r
+        debug(" vendor: 0x%04x, product: 0x%04x", info.vendor, info.product);\r
+        *vid = info.vendor;\r
+        *pid = info.product;\r
+        res = 1;\r
+    }\r
+    return res;\r
+}\r
+\r
+static int open_device(const char *device)\r
+{\r
+    int version;\r
+    int fd;\r
+    int clkid = CLOCK_MONOTONIC;\r
+    struct pollfd *new_ufds;\r
+    int *unfds;\r
+    char **new_device_names;\r
+    char **new_unused_device_names;\r
+    char name[80];\r
+    char location[80];\r
+    char idstr[80];\r
+    struct input_id id;\r
+    int res = -1;\r
+    struct hidraw_devinfo info;\r
+\r
+    fd = open(device, O_RDWR);\r
+    if(fd < 0) {\r
+        debug("could not open %s, %s\n", device, strerror(errno));\r
+        return -1;\r
+    }\r
+    debug("new fd is %d", fd);\r
+\r
+    res = ioctl(fd, HIDIOCGRAWINFO, &info);\r
+    if(res < 0) {\r
+        debug("failed to get hidraw_devinfo, add for now");\r
+    }else if(info.bustype != BUS_BLUETOOTH){\r
+        debug("ingore this device");\r
+        close(fd);\r
+        return -1;\r
+    }else if((info.vendor != global_voice_setting.vid) || (info.product != global_voice_setting.pid)) {\r
+        //res = unlink(fd);\r
+        debug("Not the device we care, add to unused fds");\r
+        unfds = realloc(unused_bt_hid_fds, sizeof(unused_bt_hid_fds[0]) * (nunusedfds + 1));\r
+        if(unfds == NULL) {\r
+            error("unused fds: out of memory");\r
+            return -1;\r
+        }\r
+\r
+        new_unused_device_names = realloc(unused_device_names, sizeof(unused_device_names[0]) * (nunusedfds + 1));\r
+        if(new_unused_device_names == NULL) {\r
+            error("unused device_names: out of memory");\r
+            return -1;\r
+        }\r
+\r
+        unused_bt_hid_fds = unfds;\r
+        unused_device_names = new_unused_device_names;\r
+        \r
+        unused_bt_hid_fds[nunusedfds] = fd;\r
+        unused_device_names[nunusedfds] = strdup(device);\r
+        nunusedfds++;\r
+        return 0; \r
+    }\r
+\r
+    new_ufds = realloc(ufds, sizeof(ufds[0]) * (nfds + 1));\r
+    if(new_ufds == NULL) {\r
+        error("out of memory\n");\r
+        return -1;\r
+    }\r
+\r
+    ufds = new_ufds;\r
+    new_device_names = realloc(device_names, sizeof(device_names[0]) * (nfds + 1));\r
+    if(new_device_names == NULL) {\r
+        debug("out of memory\n");\r
+        return -1;\r
+    }\r
+    device_names = new_device_names;\r
+    //get_hidraw_info(fd);\r
+    ufds[nfds].fd = fd;\r
+    ufds[nfds].events = POLLIN;\r
+    device_names[nfds] = strdup(device);\r
+    nfds++;\r
+\r
+    return 0;\r
+}\r
+\r
+int close_device(const char *device)\r
+{\r
+    int i;\r
+    for(i = 1; i < nfds; i++) {\r
+        if(strcmp(device_names[i], device) == 0) {\r
+            int count = nfds - i - 1;\r
+            debug("remove device %d: %s\n", i, device);\r
+            free(device_names[i]);\r
+            memmove(device_names + i, device_names + i + 1, sizeof(device_names[0]) * count);\r
+            close(ufds[i].fd);\r
+            memmove(ufds + i, ufds + i + 1, sizeof(ufds[0]) * count);\r
+            nfds--;\r
+            return 0;\r
+        }\r
+    }\r
+\r
+    for(i = 0; i < nunusedfds; i++) {\r
+        if(strcmp(unused_device_names[i], device) == 0) {\r
+            int count = nunusedfds - i;\r
+            debug("remove unused device %d: %s\n", i, device);\r
+            free(unused_device_names[i]);\r
+            memmove(unused_device_names + i, unused_device_names + i + 1, sizeof(unused_device_names[0]) * count);\r
+            close(unused_bt_hid_fds[i]);\r
+            memmove(unused_bt_hid_fds + i, unused_bt_hid_fds + i + 1, sizeof(unused_bt_hid_fds[0]) * count);\r
+            nunusedfds--;\r
+            return 0;\r
+        }\r
+    }\r
+    \r
+    error("remote device: %s not found\n", device);\r
+    return -1;\r
+}\r
+\r
+static int read_notify(const char *dirname, int nfd)\r
+{\r
+    int res;\r
+    char devname[PATH_MAX];\r
+    char *filename;\r
+    char event_buf[512];\r
+    int event_size;\r
+    int event_pos = 0;\r
+    struct inotify_event *event;\r
+\r
+    res = read(nfd, event_buf, sizeof(event_buf));\r
+    if(res < (int)sizeof(*event)) {\r
+        if(errno == EINTR)\r
+            return 0;\r
+        error("could not get event, %s\n", strerror(errno));\r
+        return 1;\r
+    }\r
+    //printf("got %d bytes of event information\n", res);\r
+\r
+    strcpy(devname, dirname);\r
+    filename = devname + strlen(devname);\r
+    *filename++ = '/';\r
+\r
+    while(res >= (int)sizeof(*event)) {\r
+        event = (struct inotify_event *)(event_buf + event_pos);\r
+        //debug("%d: %08x \"%s\"\n", event->wd, event->mask, event->len ? event->name : "");\r
+        if((event->len)&&(memcmp(event->name, "hidraw", strlen("hidraw"))==0)) {\r
+            debug("read_notify: %d: %08x \"%s\"\n", event->wd, event->mask, event->len ? event->name : "");\r
+            strcpy(filename, event->name);\r
+            if(event->mask & IN_CREATE) {\r
+                open_device(devname);\r
+            }\r
+            else {\r
+                close_device(devname);\r
+            }\r
+        }\r
+        event_size = sizeof(*event) + event->len;\r
+        res -= event_size;\r
+        event_pos += event_size;\r
+    }\r
+    return 0;\r
+}\r
+\r
+\r
+static int scan_dir(const char *dirname)\r
+{\r
+    char devname[PATH_MAX];\r
+    char *filename;\r
+    DIR *dir;\r
+    struct dirent *de;\r
+    dir = opendir(dirname);\r
+    if(dir == NULL)\r
+        return -1;\r
+    strcpy(devname, dirname);\r
+    filename = devname + strlen(devname);\r
+    *filename++ = '/';\r
+    while((de = readdir(dir))) {\r
+        if(de->d_name[0] == '.' &&\r
+           (de->d_name[1] == '\0' ||\r
+            (de->d_name[1] == '.' && de->d_name[2] == '\0')))\r
+            continue;\r
+        if(memcmp(de->d_name,"hidraw",strlen("hidraw")))\r
+            continue;\r
+        strcpy(filename, de->d_name);\r
+        //debug("scan_dir: %s\n",devname);\r
+        open_device(devname);\r
+    }\r
+    closedir(dir);\r
+    return 0;\r
+}\r
+\r
+static void voice_ctrl_recv(void)\r
+{\r
+    unsigned char cmd[256], opcode = 0xFF;\r
+    int n, i;\r
+\r
+    n = UIPC_Read(UIPC_CH_ID_VOICE_CTRL, NULL, cmd, 256);\r
+\r
+    /* detach on ctrl channel means audioflinger process was terminated */\r
+    if (n == 0)\r
+    {\r
+        debug("CTRL CH DETACHED");\r
+        //the ctrl channel will re-open automatically\r
+        UIPC_Close(UIPC_CH_ID_VOICE_CTRL);\r
+        return;\r
+    }\r
+\r
+    debug("receive voice-ctrl-cmd read num_of_data = %d ", n);\r
+    for (i=0; i< n; i++)\r
+        info("data[%d] = %d ", i, cmd[i]);\r
+    //receive start or stop cmd from service\r
+    if( cmd[0] <= OPCODE_MAX)\r
+    {\r
+        opcode = cmd[0];\r
+    }\r
+    else\r
+    {\r
+        //clear the memory\r
+        UIPC_Ioctl(UIPC_CH_ID_VOICE_CTRL, UIPC_REQ_RX_FLUSH,NULL);\r
+        info("it is wrong cmd send from service");\r
+    }\r
+\r
+    info("opcode = %d",opcode);\r
+    switch(opcode)\r
+    {\r
+        case OPCODE_SETTING_RESET:              //0   cmd(1)\r
+            break;\r
+\r
+        case OPCODE_VOICE_START_CMD:            //1   cmd(1)\r
+            debug("start, len=%d", n);\r
+            break;\r
+\r
+        case OPCODE_VOICE_STOP_CMD:             //2   cmd(1)\r
+            debug("stop, len=%d", n);\r
+            break;\r
+\r
+        case OPCODE_SET_RCU_INFO:               //3   cmd(1) + vid(2) + pid(2) + vers(2)\r
+            if(n == 7) {\r
+                int vid = (cmd[1] << 8) + cmd[2];\r
+                int pid = (cmd[3] << 8) + cmd[4];\r
+                int vers = (cmd[5] << 8) + cmd[6];\r
+                set_rcu_info(vid,pid,vers);\r
+            }\r
+            break;\r
+\r
+        case OPCODE_SET_VOICE_DATA_REPORT_ID:   //4   cmd(1) + reportID(1)\r
+            if(n == 2) {\r
+                set_voice_data_reportID(cmd[1]);\r
+            }\r
+            break;\r
+\r
+        case OPCODE_SET_VOICE_CMD_REPORT_ID:    //5   cmd(1) + reportID(1)\r
+            if(n == 2) {\r
+                set_voice_cmd_reportID(cmd[1]);\r
+            }\r
+            break;\r
+\r
+        case OPCODE_SET_VOICE_KEY_REPORT_ID:    //6   cmd(1) + reportID(1)\r
+            if(n == 2) {\r
+                set_voice_key_reportID(cmd[1]);\r
+            }\r
+            break;\r
+\r
+        case OPCODE_SET_VOICE_KEYPRESS_DATA:    //7   cmd(1) + len(1) + data(n)\r
+            if(n > 2) {\r
+                int len = cmd[1];\r
+                set_voice_keypress_data(len, cmd + 2);\r
+            }\r
+            break;\r
+\r
+        case OPCODE_SET_VOICE_KEYRELEASE_DATA:  //8   cmd(1) + len(1) + data(n)\r
+            if(n > 2) {\r
+                int len = cmd[1];\r
+                set_voice_keyrelease_data(len, cmd + 2);\r
+            }\r
+            break;\r
+\r
+        case OPCODE_SET_VOICE_STARTCMD_DATA:    //9   cmd(1) + len(1) + data(n)\r
+            debug("set voice start data, len=%d", cmd[1]);\r
+            break;\r
+\r
+        case OPCODE_SET_VOICE_STOPCMD_DATA:     //10  cmd(1) + len(1) + data(n)\r
+            debug("set voice stop data, len=%d", cmd[1]);\r
+            break;\r
+\r
+        case OPCODE_SET_ENCODE_TYPE:            //11  cmd(1) + type(1)\r
+            if(n == 2) {\r
+                set_encode_type(cmd[1]);\r
+            }\r
+            break;\r
+\r
+        case OPCODE_SET_DATA_TYPE_MASK:         //12  cmd(1) + type(1)\r
+            debug("set type mask: 0x%02x", cmd[1]);\r
+            break;\r
+\r
+        case OPCODE_SET_AUTO_CMD:               //13  cmd(1) + auto(1)\r
+            if(n == 2) {\r
+                set_auto_cmd(cmd[1]);\r
+            }\r
+            break;\r
+\r
+        case OPCODESEND_HIDRAW_DATA:            //14  cmd(1) + reportID(1) + len(1) + data(n)\r
+            debug("send raw data, reportID=0x%02x, len=0x%02x", cmd[1], cmd[2]);\r
+            break;\r
+\r
+        case OPCODE_EXIT:\r
+            debug("exit");\r
+            gSocket_Running = 0;\r
+    }\r
+\r
+    info("voice-ctrl-cmd DOWN!");\r
+}\r
+\r
+static void voice_data_recv(void)\r
+{\r
+    unsigned char cmd[256], opcode = 0xFF;\r
+    int n, i;\r
+\r
+    n = UIPC_Read(UIPC_CH_ID_VOICE_DATA, NULL, cmd, 256);\r
+\r
+    /* detach on ctrl channel means audioflinger process was terminated */\r
+    if (n == 0)\r
+    {\r
+        debug("DATA CH DETACHED");\r
+        //the ctrl channel will re-open automatically\r
+        UIPC_Close(UIPC_CH_ID_VOICE_DATA);\r
+        return;\r
+    }\r
+\r
+    debug("receive voice-data read num_of_data = %d ", n);\r
+}\r
+\r
+\r
+static void ctrl_socket_cb(tUIPC_CH_ID ch_id, tUIPC_EVENT event)\r
+{\r
+\r
+    switch(event)\r
+    {\r
+        case UIPC_OPEN_EVT:\r
+            /*\r
+                in certain case, hid status msg must be sent upon ctrl chan opened\r
+             */\r
+            debug("Jim@control_socket_cb: sending hid status msg upon open");\r
+            break;\r
+\r
+        case UIPC_CLOSE_EVT:\r
+            if (gSocket_Running) {\r
+                debug("jim@control_socket_cb: re-open ctrl chan");\r
+                UIPC_Open(UIPC_CH_ID_VOICE_CTRL, ctrl_socket_cb);\r
+            }\r
+            break;\r
+\r
+        case UIPC_RX_DATA_EVT:\r
+            info("btif_voice_ctrl_cb, the event is UIPC_RX_DATA_EVT");\r
+\r
+        case UIPC_RX_DATA_READY_EVT:\r
+            voice_ctrl_recv();\r
+            break;\r
+\r
+        default :\r
+            info("### VOICE-CTRL-CHANNEL EVENT %d NOT HANDLED ###", event);\r
+            break;\r
+    }\r
+}\r
+\r
+static void data_socket_cb(tUIPC_CH_ID ch_id, tUIPC_EVENT event)\r
+{\r
+\r
+    debug("data_socket_cb");\r
+    switch(event)\r
+    {\r
+        case UIPC_OPEN_EVT:\r
+            debug("Jim@data_socket_cb: sending hid status msg upon open");\r
+            break;\r
+\r
+        case UIPC_CLOSE_EVT:\r
+            if (gSocket_Running) {\r
+                debug("jim@data_socket_cb: re-open data chan");\r
+                UIPC_Open(UIPC_CH_ID_VOICE_DATA, data_socket_cb);\r
+            }\r
+            break;\r
+\r
+        case UIPC_RX_DATA_EVT:\r
+            info("data_socket_cb, the event is UIPC_RX_DATA_EVT");\r
+\r
+        case UIPC_RX_DATA_READY_EVT:\r
+            voice_data_recv();\r
+            info("data_socket_cb, the event is UIPC_RX_DATA_READY_EVT");\r
+            break;\r
+\r
+        default :\r
+            info("### VOICE-DATA-CHANNEL EVENT %d NOT HANDLED ###", event);\r
+            break;\r
+    }\r
+}\r
+\r
+\r
+\r
+int init(void) {\r
+\r
+    pthread_mutex_init(&mutex_voice_settings, NULL);\r
+    voice_msbc_init();\r
+    sbcInitDecoder();\r
+\r
+    gSocket_Running = 1;\r
+    UIPC_Init(NULL);\r
+    UIPC_Open(UIPC_CH_ID_VOICE_CTRL, ctrl_socket_cb);\r
+    UIPC_Open(UIPC_CH_ID_VOICE_DATA, data_socket_cb);\r
+\r
+    return 0;\r
+}\r
+\r
+void cleanup(void) {\r
+\r
+    gSocket_Running = 0;\r
+    UIPC_Close(UIPC_CH_ID_VOICE_DATA);\r
+    UIPC_Close(UIPC_CH_ID_VOICE_CTRL);\r
+\r
+    pthread_mutex_lock(&mutex_voice_settings);\r
+    \r
+    \r
+    if(global_voice_setting.voice_keypress_data != NULL)\r
+        free(global_voice_setting.voice_keypress_data);\r
+\r
+    if(global_voice_setting.voice_keyrelease_data != NULL)\r
+        free(global_voice_setting.voice_keyrelease_data);\r
+\r
+    pthread_mutex_unlock(&mutex_voice_settings);\r
+    //release other resources here\r
+}\r
+\r
+\r
+int main(void) {\r
+    const char *device_path = "/dev";\r
+    int res;\r
+    int i;\r
+\r
+    init();\r
+\r
+    nfds = 1;\r
+    ufds = calloc(1, sizeof(ufds[0]));\r
+    ufds[0].fd = inotify_init();\r
+    ufds[0].events = POLLIN;\r
+\r
+    res = inotify_add_watch(ufds[0].fd, device_path, IN_DELETE | IN_CREATE);\r
+    if(res < 0) {\r
+        error("could not add watch for %s, %s\n", device_path, strerror(errno));\r
+        return -1;\r
+    }\r
+\r
+    res = scan_dir(device_path);\r
+    if(res < 0) {\r
+        error("scan dir failed for %s\n", device_path);\r
+        return -2;\r
+    }\r
+\r
+    while(gSocket_Running) {\r
+        poll(ufds, nfds, -1);\r
+        if(ufds[0].revents & POLLIN) {\r
+            //debug("new notify event!!!");\r
+            read_notify(device_path, ufds[0].fd);\r
+        }\r
+\r
+        for(i = 1; i < nfds; i++) {\r
+            if(ufds[i].revents) {\r
+                /*\r
+                //debug("new message event, fd = %d, event = %04x.", ufds[i].fd, ufds[i].revents);\r
+                if((ufds[i].revents & POLLHUP) && (ufds[i].revents & POLLERR)) {\r
+                    debug("close, fd=%d, events=0x%04x", ufds[i].fd, ufds[i].revents);\r
+                    close(ufds[i].fd);\r
+                 \r
+                }else if(ufds[i].revents & POLLIN) {\r
+                    //debug("new message event!!!");\r
+                    read_message(ufds[i].fd);\r
+                }\r
+                */\r
+                if(ufds[i].revents & POLLIN) {\r
+                    //debug("new message event!!!");\r
+                    read_message(ufds[i].fd);\r
+                }\r
+            }\r
+        }\r
+    }\r
+    cleanup();\r
+    \r
+    return 0;\r
+\r
+}\r
+\r
index 9ea31d699276533b404604bbeab52606c05e80ca..7e96138351ead31b6760a2b495a7ff85cad7c3be 100755 (executable)
@@ -1,55 +1,55 @@
-#ifndef VOICE_HIDRAW_H
-#define VOICE_HIDRAW_H
-
-#include <cutils/log.h>
-
-
-#define DECODE_TYPE_MSBC 1
-#define DECODE_TYPE_SBC 2
-#define DECODE_TYPE_MAX 2
-
-#define DATA_TYPE_MASK_VOICE (0x01)
-#define DATA_TYPE_MASK_RAW (0x02)
-
-#define AUTOCMD_AUTO 1
-#define AUTOCMD_NONE 2
-
-#define SW_VERSION (0x0000)
-
-#define CONFIG_PATH "/system/etc/hidraw_setting"
-
-
-#define warn(fmt, ...) ALOGW ("## WARNING : %s(L%d):  " fmt "##",__FUNCTION__, __LINE__, ## __VA_ARGS__)
-#define error(fmt, ...) ALOGE ("## ERROR : %s(L%d): " fmt "##",__FUNCTION__, __LINE__, ## __VA_ARGS__)
-
-#define info(fmt, ...)  ALOGI ("%s(L%d): " fmt,__FUNCTION__, __LINE__,  ## __VA_ARGS__)
-#define debug(fmt, ...) ALOGD ("%s(L%d): " fmt,__FUNCTION__, __LINE__,  ## __VA_ARGS__)
-
-
-#define VOICE_DATA_PATH     "/data/misc/bluedroid/.voice_data"
-#define VOICE_CTRL_PATH     "/data/misc/bluedroid/.voice_ctrl"
-
-
-
-//supported opcode
-
-#define OPCODE_SETTING_RESET                0   //cmd(1)
-#define OPCODE_VOICE_START_CMD              1   //cmd(1)
-#define OPCODE_VOICE_STOP_CMD               2   //cmd(1)
-#define OPCODE_SET_RCU_INFO                 3   //cmd(1) + vid(2) + pid(2) + vers(2)
-#define OPCODE_SET_VOICE_DATA_REPORT_ID     4   //cmd(1) + reportID(1)
-#define OPCODE_SET_VOICE_CMD_REPORT_ID      5   //cmd(1) + reportID(1)
-#define OPCODE_SET_VOICE_KEY_REPORT_ID      6   //cmd(1) + reportID(1)
-#define OPCODE_SET_VOICE_KEYPRESS_DATA      7   //cmd(1) + len(1) + data(n)
-#define OPCODE_SET_VOICE_KEYRELEASE_DATA    8   //cmd(1) + len(1) + data(n)
-#define OPCODE_SET_VOICE_STARTCMD_DATA      9   //cmd(1) + len(1) + data(n)
-#define OPCODE_SET_VOICE_STOPCMD_DATA       10  //cmd(1) + len(1) + data(n)
-#define OPCODE_SET_ENCODE_TYPE              11  //cmd(1) + type(1)
-#define OPCODE_SET_DATA_TYPE_MASK           12  //cmd(1) + type(1)
-#define OPCODE_SET_AUTO_CMD                 13  //cmd(1) + auto(1)
-#define OPCODESEND_HIDRAW_DATA              14  //cmd(1) + reportID(1) + len(1) + data(n)
-#define OPCODE_EXIT                         15  //cmd(1) 
-
-#define OPCODE_MAX                          15
-
-#endif
+#ifndef VOICE_HIDRAW_H\r
+#define VOICE_HIDRAW_H\r
+\r
+#include <cutils/log.h>\r
+\r
+\r
+#define DECODE_TYPE_MSBC 1\r
+#define DECODE_TYPE_SBC 2\r
+#define DECODE_TYPE_MAX 2\r
+\r
+#define DATA_TYPE_MASK_VOICE (0x01)\r
+#define DATA_TYPE_MASK_RAW (0x02)\r
+\r
+#define AUTOCMD_AUTO 1\r
+#define AUTOCMD_NONE 2\r
+\r
+#define SW_VERSION (0x0000)\r
+\r
+#define CONFIG_PATH "/system/etc/hidraw_setting"\r
+\r
+\r
+#define warn(fmt, ...) ALOGW ("## WARNING : %s(L%d):  " fmt "##",__FUNCTION__, __LINE__, ## __VA_ARGS__)\r
+#define error(fmt, ...) ALOGE ("## ERROR : %s(L%d): " fmt "##",__FUNCTION__, __LINE__, ## __VA_ARGS__)\r
+\r
+#define info(fmt, ...)  ALOGI ("%s(L%d): " fmt,__FUNCTION__, __LINE__,  ## __VA_ARGS__)\r
+#define debug(fmt, ...) ALOGD ("%s(L%d): " fmt,__FUNCTION__, __LINE__,  ## __VA_ARGS__)\r
+\r
+\r
+#define VOICE_DATA_PATH     "/data/misc/bluedroid/.voice_data"\r
+#define VOICE_CTRL_PATH     "/data/misc/bluedroid/.voice_ctrl"\r
+\r
+\r
+\r
+//supported opcode\r
+\r
+#define OPCODE_SETTING_RESET                0   //cmd(1)\r
+#define OPCODE_VOICE_START_CMD              1   //cmd(1)\r
+#define OPCODE_VOICE_STOP_CMD               2   //cmd(1)\r
+#define OPCODE_SET_RCU_INFO                 3   //cmd(1) + vid(2) + pid(2) + vers(2)\r
+#define OPCODE_SET_VOICE_DATA_REPORT_ID     4   //cmd(1) + reportID(1)\r
+#define OPCODE_SET_VOICE_CMD_REPORT_ID      5   //cmd(1) + reportID(1)\r
+#define OPCODE_SET_VOICE_KEY_REPORT_ID      6   //cmd(1) + reportID(1)\r
+#define OPCODE_SET_VOICE_KEYPRESS_DATA      7   //cmd(1) + len(1) + data(n)\r
+#define OPCODE_SET_VOICE_KEYRELEASE_DATA    8   //cmd(1) + len(1) + data(n)\r
+#define OPCODE_SET_VOICE_STARTCMD_DATA      9   //cmd(1) + len(1) + data(n)\r
+#define OPCODE_SET_VOICE_STOPCMD_DATA       10  //cmd(1) + len(1) + data(n)\r
+#define OPCODE_SET_ENCODE_TYPE              11  //cmd(1) + type(1)\r
+#define OPCODE_SET_DATA_TYPE_MASK           12  //cmd(1) + type(1)\r
+#define OPCODE_SET_AUTO_CMD                 13  //cmd(1) + auto(1)\r
+#define OPCODESEND_HIDRAW_DATA              14  //cmd(1) + reportID(1) + len(1) + data(n)\r
+#define OPCODE_EXIT                         15  //cmd(1) \r
+\r
+#define OPCODE_MAX                          15\r
+\r
+#endif\r
index 247d6f3959f75cad598e9b7a5136bbe606ee71f9..086f385fc8ddc93fcb59e5552c9a9864ae3eec4a 100755 (executable)
@@ -1,20 +1,20 @@
-[Rcu]
-Vid=005d
-Pid=0001
-Ver=0000
-
-[ReportID]
-Key=1
-Data=5a
-Cmd=5a
-
-[ReportValue]
-KeyDownLen=8
-KeyDown=0,0,3e,0,0,0,0,0;
-KeyUpLen=8
-KeyUp=0,64,0,0,0,0,0,0;
-
-[Settings]
-DecodeType=1
-DataMask=1
-AutoCmd=1
+[Rcu]\r
+Vid=005d\r
+Pid=0001\r
+Ver=0000\r
+\r
+[ReportID]\r
+Key=1\r
+Data=5a\r
+Cmd=5a\r
+\r
+[ReportValue]\r
+KeyDownLen=8\r
+KeyDown=0,0,3e,0,0,0,0,0;\r
+KeyUpLen=8\r
+KeyUp=0,64,0,0,0,0,0,0;\r
+\r
+[Settings]\r
+DecodeType=1\r
+DataMask=1\r
+AutoCmd=1
\ No newline at end of file
index 9135f8378b27eec4b2f21dc92f6f2c5360a1938d..ea2d44890e449eab561365e56f12180b2a96491b 100755 (executable)
@@ -1,35 +1,35 @@
-#ifndef BEE_SETTINGS_H
-#define BEE_SETTINGS_H
-
-#define BEE_RCU_VID (0x005D)
-#define BEE_RCU_PID (0x0001)
-#define BEE_RCU_VERSION (0x0000)
-
-#define BEE_VOICEKEY_LEN 8
-
-#define BEE_VOICEKEY_REPORTID (0x01)
-
-unsigned char BEE_VOICE_KEYDOWN_DATA[BEE_VOICEKEY_LEN] = {0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00};
-unsigned char BEE_VOICE_KEYUP_DATA[BEE_VOICEKEY_LEN] = {0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
-
-//msbc
-#define BEE_MSBC_VOICEDATA_REPORTID     (0x5A)
-#define BEE_MSBC_VOICECMD_REPORTID      (0x5A)
-
-
-#define BEE_MSBC_ATT_FRAME_SIZE         120
-#define BEE_MSBC_FRAME_SIZE             60
-#define BEE_MSBC_DECODE_INPUT_SIZE      58
-#define BEE_MSBC_DECODE_OUTPUT_SIZE     240
-
-//sbc
-#define BEE_SBC_VOICEDATA_REPORTID      (0x5B)
-#define BEE_SBC_VOICECMD_REPORTID       (0x5B)
-
-#define BEE_SBC_ATT_FRAME_SIZE          72
-#define BEE_SBC_FRAME_SIZE              36
-
-#define BEE_SBC_DECODE_INPUT_SIZE      36
-#define BEE_SBC_DECODE_OUTPUT_SIZE     256
-
-#endif
+#ifndef BEE_SETTINGS_H\r
+#define BEE_SETTINGS_H\r
+\r
+#define BEE_RCU_VID (0x005D)\r
+#define BEE_RCU_PID (0x0001)\r
+#define BEE_RCU_VERSION (0x0000)\r
+\r
+#define BEE_VOICEKEY_LEN 8\r
+\r
+#define BEE_VOICEKEY_REPORTID (0x01)\r
+\r
+unsigned char BEE_VOICE_KEYDOWN_DATA[BEE_VOICEKEY_LEN] = {0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00};\r
+unsigned char BEE_VOICE_KEYUP_DATA[BEE_VOICEKEY_LEN] = {0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};\r
+\r
+//msbc\r
+#define BEE_MSBC_VOICEDATA_REPORTID     (0x5A)\r
+#define BEE_MSBC_VOICECMD_REPORTID      (0x5A)\r
+\r
+\r
+#define BEE_MSBC_ATT_FRAME_SIZE         120\r
+#define BEE_MSBC_FRAME_SIZE             60\r
+#define BEE_MSBC_DECODE_INPUT_SIZE      58\r
+#define BEE_MSBC_DECODE_OUTPUT_SIZE     240\r
+\r
+//sbc\r
+#define BEE_SBC_VOICEDATA_REPORTID      (0x5B)\r
+#define BEE_SBC_VOICECMD_REPORTID       (0x5B)\r
+\r
+#define BEE_SBC_ATT_FRAME_SIZE          72\r
+#define BEE_SBC_FRAME_SIZE              36\r
+\r
+#define BEE_SBC_DECODE_INPUT_SIZE      36\r
+#define BEE_SBC_DECODE_OUTPUT_SIZE     256\r
+\r
+#endif
\ No newline at end of file
index e56e8c5ba740e0e712e716dad98ac3fdd348c6cc..17e5e177d92647c72048e3d6e083ee769f501024 100755 (executable)
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <cutils/log.h>
-
-#include "config.h"
-
-
-tVoice_Hidraw_Settings *gConfig = NULL;
-static char * gContent = NULL;
-
-
-static char * voice_conf_getline(char * head, char ** left)
-{
-    char * next;
-    if(*head == 0)
-        return NULL;
-    while((*head == '\r')||(*head == '\n'))
-        head++;
-    if(*head == 0)
-        return NULL;
-    next = head;
-    while((*next != '\r')&&(*next != '\n')&&(*next != 0))
-        next++;
-    if(*next != 0)
-        *next++ = 0;
-    *left = next;
-    return head;
-}
-
-static void voice_conf_parse_config(tVoice_Hidraw_Settings **items, char *content)
-{
-    char * group = NULL;
-    char * item = NULL;
-    char * val = NULL;
-    char * line = NULL;
-    int id = -1;
-    tVoice_Hidraw_Settings* entry, * head, *end;
-
-    char * p;
-    int i = 0;
-
-    head = NULL;
-    end = NULL;
-
-    ALOGD("voice_conf_parse_config\n");
-    while((line = voice_conf_getline(content, &content)) != NULL)
-    {
-        ALOGD("voice_conf_parse_config line:%s\n", line);
-        switch(line[0])
-        {
-            case '[':
-            {
-                p = strstr(line,"]");
-                if(p)
-                {
-                    *p = 0;
-                    group = &(line[1]);
-                    ALOGI("voice_conf_parse_config Find Group[%s]\n", group);
-                }else{
-                    ALOGW("voice_conf_parse_config Expected ']' end of Group(%s)!\n", line);
-                }
-                break;
-            }
-            case '#':
-            {
-                break;
-            }
-            default:
-            {
-                p = strstr(line,"=");
-                if(p)
-                {
-                    *p++ = 0;
-                    item = line;
-                    val = p;
-                    if((item[0]==0)||(val[0]==0))
-                    {
-                        ALOGI("voice_conf_parse_config ignore(item:%s val:%s)\n", item[0]?item:"(null)", val[0]?val:"(null)");
-                        break;
-                    }
-                    ALOGI("voice_conf_parse_config Find Item[%s:%s=%s]\n", group, item, val);
-                    entry = malloc(sizeof(tVoice_Hidraw_Settings));
-                    if(entry)
-                    {
-                        entry->next = NULL;
-                        entry->group = group;
-                        entry->item = item;
-                        entry->val = val;
-                        if(end)
-                        {
-                            end->next = entry;
-                            end = entry;
-                        }else
-                            end = entry;
-                        if(head == NULL)
-                            head = entry;
-                    }
-                }
-            }
-        }
-    }
-    *items = head;
-}
-
-
-int voice_loadconfig(char * path)
-{
-    int i,res,fd;
-    struct stat st;
-    char * content = NULL;
-    struct tVoice_Hidraw_Settings* config = NULL;
-
-    ALOGI("voice_loadconfig(%s) load!\n", path);
-    fd = open(path, O_RDONLY);
-    if(fd < 0)
-    {
-        ALOGW("voice_loadconfig(%s) open fail!\n", path);
-        return -1;
-    }
-    res = fstat(fd, &st);
-    if(res)
-    {
-        ALOGW("voice_loadconfig(%s) stat fail! reason=%d\n", path, res);
-        return -1;
-    }
-    if(st.st_size <= 0)
-    {
-        ALOGW("voice_loadconfig(%s) size fail! size=%d\n", path, (int)st.st_size);
-        close(fd);
-        return -1;
-    }
-    ALOGI("voice_loadconfig(%s) size=%d!\n", path, (int)st.st_size);
-    content = malloc(st.st_size+1);
-    if(content == NULL)
-    {
-        ALOGW("voice_loadconfig(%s) malloc fail!\n", path);
-        close(fd);
-        return -1;
-    }
-    res = read(fd, content, st.st_size);
-    if(res <= 0)
-    {
-        ALOGW("voice_loadconfig(%s) read fail! res=%d\n", path, res);
-        close(fd);
-        return -1;
-    }
-    content[res] = 0;
-    voice_conf_parse_config(&config, content);
-    close(fd);
-
-    gConfig = config;
-    return 0;
-}
-
-
-
-
-static char * voice_api_GetConfig(char * group, char * item)
-{
-    int i;
-    tVoice_Hidraw_Settings * entry;
-
-    if(item == NULL)
-        return NULL;
-    entry = gConfig;
-    while(entry)
-    {
-        if(group&&(entry->group)&&(strcmp(entry->group, group)==0)&&(strcmp(entry->item, item)==0))
-            return entry->val;
-        if((group==NULL)&&(entry->group==NULL)&&(strcmp(entry->item, item)==0))
-            return entry->val;
-
-        entry = entry->next;
-    }
-    return NULL;
-}
-
-int voice_get_int_config(char *group, char *item) {
-    char *str;
-    int value = -1;
-
-    str = voice_api_GetConfig(group, item);
-    if(str == NULL) {
-        ALOGE("failed to get int value: %s-%s", group, item);
-        goto result;
-    }
-
-    value = strtol(str, NULL, 16);
-
-result:
-    return value;
-}
-
-int voice_get_byte_array_config(char *group, char *item, char* arr, int len) {
-    char *str, *front, *tail;
-    int ret = -1;
-    int i = 0;
-
-    str = voice_api_GetConfig(group, item);
-    if(str == NULL) {
-        goto retval;
-    }
-
-    front = str;
-
-    while(i < len) {
-        tail = strstr(front, ",");
-        if(tail == NULL) {
-            tail = strstr(front, ";");
-        }
-
-        if(tail == NULL) {
-            ALOGE("failed to get byte-array value: %s-%s-No%d", group, item, i + 1);
-            goto retval;
-        }
-
-        *tail++ = 0;
-        *(arr+i) = (strtol(front, NULL, 16)) & 0xff;
-        front = tail;
-        i++;
-    }
-
-    if(i == len)ret = i;
-
-retval:
-    return ret;
-}
-
-int voice_conf_exit()
-{
-    struct tVoice_Hidraw_Settings *item, *p;
-    int i;
-
-    item = gConfig;
-    while(item)
-    {
-        p = item;
-        item = item->next;
-        free(p);
-    }
-
-    if(gContent)
-        free(gContent);
-    return 0;
-}
-
-
+#include <string.h>\r
+#include <sys/types.h>\r
+#include <sys/stat.h>\r
+#include <unistd.h>\r
+#include <fcntl.h>\r
+#include <stdlib.h>\r
+#include <cutils/log.h>\r
+\r
+#include "config.h"\r
+\r
+\r
+tVoice_Hidraw_Settings *gConfig = NULL;\r
+static char * gContent = NULL;\r
+\r
+\r
+static char * voice_conf_getline(char * head, char ** left)\r
+{\r
+    char * next;\r
+    if(*head == 0)\r
+        return NULL;\r
+    while((*head == '\r')||(*head == '\n'))\r
+        head++;\r
+    if(*head == 0)\r
+        return NULL;\r
+    next = head;\r
+    while((*next != '\r')&&(*next != '\n')&&(*next != 0))\r
+        next++;\r
+    if(*next != 0)\r
+        *next++ = 0;\r
+    *left = next;\r
+    return head;\r
+}\r
+\r
+static void voice_conf_parse_config(tVoice_Hidraw_Settings **items, char *content)\r
+{\r
+    char * group = NULL;\r
+    char * item = NULL;\r
+    char * val = NULL;\r
+    char * line = NULL;\r
+    int id = -1;\r
+    tVoice_Hidraw_Settings* entry, * head, *end;\r
+\r
+    char * p;\r
+    int i = 0;\r
+\r
+    head = NULL;\r
+    end = NULL;\r
+\r
+    ALOGD("voice_conf_parse_config\n");\r
+    while((line = voice_conf_getline(content, &content)) != NULL)\r
+    {\r
+        ALOGD("voice_conf_parse_config line:%s\n", line);\r
+        switch(line[0])\r
+        {\r
+            case '[':\r
+            {\r
+                p = strstr(line,"]");\r
+                if(p)\r
+                {\r
+                    *p = 0;\r
+                    group = &(line[1]);\r
+                    ALOGI("voice_conf_parse_config Find Group[%s]\n", group);\r
+                }else{\r
+                    ALOGW("voice_conf_parse_config Expected ']' end of Group(%s)!\n", line);\r
+                }\r
+                break;\r
+            }\r
+            case '#':\r
+            {\r
+                break;\r
+            }\r
+            default:\r
+            {\r
+                p = strstr(line,"=");\r
+                if(p)\r
+                {\r
+                    *p++ = 0;\r
+                    item = line;\r
+                    val = p;\r
+                    if((item[0]==0)||(val[0]==0))\r
+                    {\r
+                        ALOGI("voice_conf_parse_config ignore(item:%s val:%s)\n", item[0]?item:"(null)", val[0]?val:"(null)");\r
+                        break;\r
+                    }\r
+                    ALOGI("voice_conf_parse_config Find Item[%s:%s=%s]\n", group, item, val);\r
+                    entry = malloc(sizeof(tVoice_Hidraw_Settings));\r
+                    if(entry)\r
+                    {\r
+                        entry->next = NULL;\r
+                        entry->group = group;\r
+                        entry->item = item;\r
+                        entry->val = val;\r
+                        if(end)\r
+                        {\r
+                            end->next = entry;\r
+                            end = entry;\r
+                        }else\r
+                            end = entry;\r
+                        if(head == NULL)\r
+                            head = entry;\r
+                    }\r
+                }\r
+            }\r
+        }\r
+    }\r
+    *items = head;\r
+}\r
+\r
+\r
+int voice_loadconfig(char * path)\r
+{\r
+    int i,res,fd;\r
+    struct stat st;\r
+    char * content = NULL;\r
+    struct tVoice_Hidraw_Settings* config = NULL;\r
+\r
+    ALOGI("voice_loadconfig(%s) load!\n", path);\r
+    fd = open(path, O_RDONLY);\r
+    if(fd < 0)\r
+    {\r
+        ALOGW("voice_loadconfig(%s) open fail!\n", path);\r
+        return -1;\r
+    }\r
+    res = fstat(fd, &st);\r
+    if(res)\r
+    {\r
+        ALOGW("voice_loadconfig(%s) stat fail! reason=%d\n", path, res);\r
+        return -1;\r
+    }\r
+    if(st.st_size <= 0)\r
+    {\r
+        ALOGW("voice_loadconfig(%s) size fail! size=%d\n", path, (int)st.st_size);\r
+        close(fd);\r
+        return -1;\r
+    }\r
+    ALOGI("voice_loadconfig(%s) size=%d!\n", path, (int)st.st_size);\r
+    content = malloc(st.st_size+1);\r
+    if(content == NULL)\r
+    {\r
+        ALOGW("voice_loadconfig(%s) malloc fail!\n", path);\r
+        close(fd);\r
+        return -1;\r
+    }\r
+    res = read(fd, content, st.st_size);\r
+    if(res <= 0)\r
+    {\r
+        ALOGW("voice_loadconfig(%s) read fail! res=%d\n", path, res);\r
+        close(fd);\r
+        return -1;\r
+    }\r
+    content[res] = 0;\r
+    voice_conf_parse_config(&config, content);\r
+    close(fd);\r
+\r
+    gConfig = config;\r
+    return 0;\r
+}\r
+\r
+\r
+\r
+\r
+static char * voice_api_GetConfig(char * group, char * item)\r
+{\r
+    int i;\r
+    tVoice_Hidraw_Settings * entry;\r
+\r
+    if(item == NULL)\r
+        return NULL;\r
+    entry = gConfig;\r
+    while(entry)\r
+    {\r
+        if(group&&(entry->group)&&(strcmp(entry->group, group)==0)&&(strcmp(entry->item, item)==0))\r
+            return entry->val;\r
+        if((group==NULL)&&(entry->group==NULL)&&(strcmp(entry->item, item)==0))\r
+            return entry->val;\r
+\r
+        entry = entry->next;\r
+    }\r
+    return NULL;\r
+}\r
+\r
+int voice_get_int_config(char *group, char *item) {\r
+    char *str;\r
+    int value = -1;\r
+\r
+    str = voice_api_GetConfig(group, item);\r
+    if(str == NULL) {\r
+        ALOGE("failed to get int value: %s-%s", group, item);\r
+        goto result;\r
+    }\r
+\r
+    value = strtol(str, NULL, 16);\r
+\r
+result:\r
+    return value;\r
+}\r
+\r
+int voice_get_byte_array_config(char *group, char *item, char* arr, int len) {\r
+    char *str, *front, *tail;\r
+    int ret = -1;\r
+    int i = 0;\r
+\r
+    str = voice_api_GetConfig(group, item);\r
+    if(str == NULL) {\r
+        goto retval;\r
+    }\r
+\r
+    front = str;\r
+\r
+    while(i < len) {\r
+        tail = strstr(front, ",");\r
+        if(tail == NULL) {\r
+            tail = strstr(front, ";");\r
+        }\r
+\r
+        if(tail == NULL) {\r
+            ALOGE("failed to get byte-array value: %s-%s-No%d", group, item, i + 1);\r
+            goto retval;\r
+        }\r
+\r
+        *tail++ = 0;\r
+        *(arr+i) = (strtol(front, NULL, 16)) & 0xff;\r
+        front = tail;\r
+        i++;\r
+    }\r
+\r
+    if(i == len)ret = i;\r
+\r
+retval:\r
+    return ret;\r
+}\r
+\r
+int voice_conf_exit()\r
+{\r
+    struct tVoice_Hidraw_Settings *item, *p;\r
+    int i;\r
+\r
+    item = gConfig;\r
+    while(item)\r
+    {\r
+        p = item;\r
+        item = item->next;\r
+        free(p);\r
+    }\r
+\r
+    if(gContent)\r
+        free(gContent);\r
+    return 0;\r
+}\r
+\r
+\r
index eeb868a363885c83ef512b8d139e37c8a37833ad..64f50bf167b6954297c92abc2d97621c23daa4b3 100755 (executable)
@@ -1,34 +1,34 @@
-#ifndef CONFIG_H
-#define CONFIG_H
-
-typedef struct tVoice_Hidraw_Settings
-{
-    struct tVoice_Hidraw_Settings * next;
-    char * group;
-    char * item;
-    char * val;
-} tVoice_Hidraw_Settings;
-
-#define CONFIG_GROUP_RCU  "Rcu"
-#define CONFIG_ITEM_RCU_VID  "Vid"
-#define CONFIG_ITEM_RCU_PID  "Pid"
-#define CONFIG_ITEM_RCU_VER  "Ver"
-
-#define CONFIG_GROUP_REPORTID  "ReportID"
-#define CONFIG_ITEM_REPORTID_KEY  "Key"
-#define CONFIG_ITEM_REPORTID_DATA  "Data"
-#define CONFIG_ITEM_REPORTID_CMD  "Cmd"
-
-#define CONFIG_GROUP_REPORTVALUE  "ReportValue"
-#define CONFIG_ITEM_REPORTVALUE_KEYDOWNLEN  "KeyDownLen"
-#define CONFIG_ITEM_REPORTVALUE_KEYDOWN  "KeyDown"
-#define CONFIG_ITEM_REPORTVALUE_KEYUPLEN  "KeyUpLen"
-#define CONFIG_ITEM_REPORTVALUE_KEYUP  "KeyUp"
-
-#define CONFIG_GROUP_SETTINGS  "Settings"
-#define CONFIG_ITEM_SETTINGS_DECODETYPE "DecodeType"
-#define CONFIG_ITEM_SETTINGS_DATAMASK "DataMask"
-#define CONFIG_ITEM_SETTINGS_AUTOCMD "AutoCmd"
-
-
-#endif
+#ifndef CONFIG_H\r
+#define CONFIG_H\r
+\r
+typedef struct tVoice_Hidraw_Settings\r
+{\r
+    struct tVoice_Hidraw_Settings * next;\r
+    char * group;\r
+    char * item;\r
+    char * val;\r
+} tVoice_Hidraw_Settings;\r
+\r
+#define CONFIG_GROUP_RCU  "Rcu"\r
+#define CONFIG_ITEM_RCU_VID  "Vid"\r
+#define CONFIG_ITEM_RCU_PID  "Pid"\r
+#define CONFIG_ITEM_RCU_VER  "Ver"\r
+\r
+#define CONFIG_GROUP_REPORTID  "ReportID"\r
+#define CONFIG_ITEM_REPORTID_KEY  "Key"\r
+#define CONFIG_ITEM_REPORTID_DATA  "Data"\r
+#define CONFIG_ITEM_REPORTID_CMD  "Cmd"\r
+\r
+#define CONFIG_GROUP_REPORTVALUE  "ReportValue"\r
+#define CONFIG_ITEM_REPORTVALUE_KEYDOWNLEN  "KeyDownLen"\r
+#define CONFIG_ITEM_REPORTVALUE_KEYDOWN  "KeyDown"\r
+#define CONFIG_ITEM_REPORTVALUE_KEYUPLEN  "KeyUpLen"\r
+#define CONFIG_ITEM_REPORTVALUE_KEYUP  "KeyUp"\r
+\r
+#define CONFIG_GROUP_SETTINGS  "Settings"\r
+#define CONFIG_ITEM_SETTINGS_DECODETYPE "DecodeType"\r
+#define CONFIG_ITEM_SETTINGS_DATAMASK "DataMask"\r
+#define CONFIG_ITEM_SETTINGS_AUTOCMD "AutoCmd"\r
+\r
+\r
+#endif\r
index 16e67201704a9321fd767d154b4e8b8afa1c9dc7..748fb8deee2417d908a92bf4c3a31a1c15650cab 100755 (executable)
-#include <stdio.h>
-#include <stdlib.h>
-#include "string.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <cutils/log.h>
-#include "get_voice_app.h"
-#include "msbc.h"
-
-
-#define DECODE_SIZE  58
-#define VOICE_MTU                   60
-#define VOICDE_DECODE_UNIT          (VOICE_MTU*4)
-
-
-static uint8* _pVoiceBuf = NULL;
-static uint8* _pdecodeBuf = NULL;
-static uint8* _pdecodeFrameBuf = NULL;
-int voice_fd = -1;
-int voice_fd_origin = -1;
-int voice_fd_wav = -1;
-sbc_t t_sbc;
-static int file_index = 0;
-
-struct wavfile
-{
-    char    id[4];          // should always contain "RIFF"
-    int     totallength;    // total file length minus 8
-    char    wavefmt[8];     // should be "WAVEfmt "
-    int     format;         // 16 for PCM format
-    short   pcm;            // 1 for PCM format
-    short   channels;       // channels
-    int     frequency;      // sampling frequency, 16000 in this case
-    int     bytes_per_second;
-    short   bytes_by_capture;
-    short   bits_per_sample;
-    char    data[4];        // should always contain "data"
-    int     bytes_in_data;
-};
-
-void write_wav_header(char* name, int samples, int channels){
-    struct wavfile filler;
-    FILE *pcm_fd;
-       FILE *wav_fd;
-       char record_name[50] = {0};
-       int size;
-       char ch;
-
-       ALOGE("Start to convert pcm to wav\n");
-    strncpy(filler.id, "RIFF", 4);
-//    filler.totallength = (samples * channels) + sizeof(struct wavfile) - 8; //81956
-    strncpy(filler.wavefmt, "WAVEfmt ", 8);
-    filler.format = 16;
-    filler.pcm = 1;
-    filler.channels = channels;
-    filler.frequency = 16000;
-    filler.bits_per_sample = 16;
-    filler.bytes_per_second = filler.channels * filler.frequency * filler.bits_per_sample/8;
-    filler.bytes_by_capture = filler.channels*filler.bits_per_sample/8;
-//    filler.bytes_in_data = samples * filler.channels * filler.bits_per_sample/8;    
-    strncpy(filler.data, "data", 4);
-
-       pcm_fd = fopen(name, "rb");
-       fseek(pcm_fd, 0, SEEK_END);
-       size = ftell(pcm_fd);
-       fseek(pcm_fd, 0, SEEK_SET);
-       
-       filler.bytes_in_data = size;
-       filler.totallength = size + sizeof(filler) - 8;
-#if 0  // just print data
-       printf("File description header: %s\n", filler.id);
-       printf("Size of file: %d\n", filler.totallength);
-       printf("WAV Format description header: %s\n", filler.wavefmt);
-       printf("Size of WAVE section chunck: %d\n", filler.format);
-       printf("WAVE type format: %d\n", filler.pcm);
-       printf("Number of channels: %d\n", filler.channels);
-       printf("Samples per second: %d\n", filler.frequency);
-       printf("Bytes per second: %d\n", filler.bytes_per_second);
-       printf("Block alignment: %d\n", filler.bytes_by_capture);
-       printf("Bits per sample: %d\n", filler.bits_per_sample);
-       printf("Data description header: %s\n", filler.data);
-       printf("Size of data: %d\n", filler.bytes_in_data);
-#endif
-
-
-    sprintf(record_name,"voice_msbc_wav%d.wav",file_index);
-
-       // store wav header
-    wav_fd = fopen(record_name, "wb");
-    fwrite(&filler, 1, sizeof(filler), wav_fd);
-       fclose(wav_fd);
-
-       // store voice data
-       wav_fd = fopen(record_name, "ab");
-    while(!feof(pcm_fd)) { 
-        fread(&ch, 1, 1, pcm_fd);
-        
-        if(!feof(pcm_fd)) { 
-            fwrite(&ch, 1, 1, wav_fd);
-        }
-    } 
-
-    fclose(pcm_fd);
-       fclose(wav_fd);
-}
-
-void RS_init_sbc()
-{
-    //msbc
-    sbc_init (&t_sbc, 0L);  
-}
-
-void RS_voice_app_create_origin_output()
-{
-    char record_name[50] = {0};
-
-    sprintf(record_name,"/data/vr/voice_msbc_origin%d",file_index);
-    voice_fd_origin =  open (record_name, O_WRONLY | O_CREAT |O_TRUNC, 0644);
-
-    
-    if(voice_fd_origin < 0)
-    {
-        ALOGE("can't open record origin  file:%s ",record_name);
-    }
-
-       RS_init_sbc();
-       
-       return;
-}
-
-void RS_voice_app_create_output()
-{
-    char record_name[50] = {0}; 
-    sprintf(record_name,"/data/vr/voice_msbc%d",file_index);
-
-    voice_fd =  open (record_name, O_WRONLY | O_CREAT |O_TRUNC, 0644);
-
-    if(voice_fd < 0)
-    {
-        ALOGE("can't open record file:%s ",record_name);
-    }
-
-
-       return;
-}
-
-int RS_stop_voice_stream_data (void)
-{
-       char record_name[50] = {0};
-       
-    ALOGE ("in\r\n");
-       
-    if (voice_fd > 0 && -1 == close (voice_fd)  )
-    {
-        ALOGE ("close voice file fail\r\n");
-    }
-
-    if (voice_fd_origin > 0 && -1 == close (voice_fd_origin)  )
-    {
-        ALOGE ("close voice file fail\r\n");
-    }
-
-    voice_fd = 0;
-    voice_fd_origin = 0;
-    sprintf(record_name,"voice_msbc%d",file_index);
-
-       //write_wav_header(record_name, 16000, 1);
-
-    sbc_finish (&t_sbc);
-
-       file_index = ((++file_index)>= 10) ? 0 : file_index;
-       
-    return 0;
-}
-
-int RS_write_decode_buf(uint8* pu_decode, ssize_t len)
-{
-        if (voice_fd > 0)
-        {
-            write (voice_fd, pu_decode, len);
-            return 0;
-        }
-        return -1;
-}
-
-int RS_deal_voice_stream_data(const uint8* input, size_t voice_buf_size, unsigned char* output, size_t output_buf_size, int* frame_len)
-{
-    int framelen;
-
-//    RS_init_sbc();
-
-    
-
-    if (NULL == input || 0 == voice_buf_size)
-    {
-        ALOGE ("input is null \r\n");
-        return -1;
-    }
-
-
-    if (NULL == output || 0 == output_buf_size)
-    {
-        ALOGE ("output is null");
-        return -1;
-    }
-
-    if(voice_buf_size != VOICE_MTU) {
-        ALOGE ("input size error: %d", voice_buf_size);
-        return -1;
-    }
-
-
-    write(voice_fd_origin, input, voice_buf_size);
-    if (input[0] == 0x01 && input[2] == 0xad)
-    { 
-        framelen = sbc_decode (&t_sbc, &input[2], DECODE_SIZE, output, output_buf_size,frame_len);
-        if (framelen <= 0)
-        {
-            ALOGE("fail to decode");
-            return -1;
-        }
-        RS_write_decode_buf(output, *frame_len);
-        return 0;
-    }else {
-        ALOGE("msbc format error !!!");
-        return -1;
-    }
-}
-    
-
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include "string.h"\r
+#include <sys/types.h>\r
+#include <sys/stat.h>\r
+#include <fcntl.h>\r
+#include <sys/ioctl.h>\r
+#include <cutils/log.h>\r
+#include "get_voice_app.h"\r
+#include "msbc.h"\r
+\r
+\r
+#define DECODE_SIZE  58\r
+#define VOICE_MTU                   60\r
+#define VOICDE_DECODE_UNIT          (VOICE_MTU*4)\r
+\r
+\r
+static uint8* _pVoiceBuf = NULL;\r
+static uint8* _pdecodeBuf = NULL;\r
+static uint8* _pdecodeFrameBuf = NULL;\r
+int voice_fd = -1;\r
+int voice_fd_origin = -1;\r
+int voice_fd_wav = -1;\r
+sbc_t t_sbc;\r
+static int file_index = 0;\r
+\r
+struct wavfile\r
+{\r
+    char    id[4];          // should always contain "RIFF"\r
+    int     totallength;    // total file length minus 8\r
+    char    wavefmt[8];     // should be "WAVEfmt "\r
+    int     format;         // 16 for PCM format\r
+    short   pcm;            // 1 for PCM format\r
+    short   channels;       // channels\r
+    int     frequency;      // sampling frequency, 16000 in this case\r
+    int     bytes_per_second;\r
+    short   bytes_by_capture;\r
+    short   bits_per_sample;\r
+    char    data[4];        // should always contain "data"\r
+    int     bytes_in_data;\r
+};\r
+\r
+void write_wav_header(char* name, int samples, int channels){\r
+    struct wavfile filler;\r
+    FILE *pcm_fd;\r
+       FILE *wav_fd;\r
+       char record_name[50] = {0};\r
+       int size;\r
+       char ch;\r
+\r
+       ALOGE("Start to convert pcm to wav\n");\r
+    strncpy(filler.id, "RIFF", 4);\r
+//    filler.totallength = (samples * channels) + sizeof(struct wavfile) - 8; //81956\r
+    strncpy(filler.wavefmt, "WAVEfmt ", 8);\r
+    filler.format = 16;\r
+    filler.pcm = 1;\r
+    filler.channels = channels;\r
+    filler.frequency = 16000;\r
+    filler.bits_per_sample = 16;\r
+    filler.bytes_per_second = filler.channels * filler.frequency * filler.bits_per_sample/8;\r
+    filler.bytes_by_capture = filler.channels*filler.bits_per_sample/8;\r
+//    filler.bytes_in_data = samples * filler.channels * filler.bits_per_sample/8;    \r
+    strncpy(filler.data, "data", 4);\r
+\r
+       pcm_fd = fopen(name, "rb");\r
+       fseek(pcm_fd, 0, SEEK_END);\r
+       size = ftell(pcm_fd);\r
+       fseek(pcm_fd, 0, SEEK_SET);\r
+       \r
+       filler.bytes_in_data = size;\r
+       filler.totallength = size + sizeof(filler) - 8;\r
+#if 0  // just print data\r
+       printf("File description header: %s\n", filler.id);\r
+       printf("Size of file: %d\n", filler.totallength);\r
+       printf("WAV Format description header: %s\n", filler.wavefmt);\r
+       printf("Size of WAVE section chunck: %d\n", filler.format);\r
+       printf("WAVE type format: %d\n", filler.pcm);\r
+       printf("Number of channels: %d\n", filler.channels);\r
+       printf("Samples per second: %d\n", filler.frequency);\r
+       printf("Bytes per second: %d\n", filler.bytes_per_second);\r
+       printf("Block alignment: %d\n", filler.bytes_by_capture);\r
+       printf("Bits per sample: %d\n", filler.bits_per_sample);\r
+       printf("Data description header: %s\n", filler.data);\r
+       printf("Size of data: %d\n", filler.bytes_in_data);\r
+#endif\r
+\r
+\r
+    sprintf(record_name,"voice_msbc_wav%d.wav",file_index);\r
+\r
+       // store wav header\r
+    wav_fd = fopen(record_name, "wb");\r
+    fwrite(&filler, 1, sizeof(filler), wav_fd);\r
+       fclose(wav_fd);\r
+\r
+       // store voice data\r
+       wav_fd = fopen(record_name, "ab");\r
+    while(!feof(pcm_fd)) { \r
+        fread(&ch, 1, 1, pcm_fd);\r
+        \r
+        if(!feof(pcm_fd)) { \r
+            fwrite(&ch, 1, 1, wav_fd);\r
+        }\r
+    } \r
+\r
+    fclose(pcm_fd);\r
+       fclose(wav_fd);\r
+}\r
+\r
+void RS_init_sbc()\r
+{\r
+    //msbc\r
+    sbc_init (&t_sbc, 0L);  \r
+}\r
+\r
+void RS_voice_app_create_origin_output()\r
+{\r
+    char record_name[50] = {0};\r
+\r
+    sprintf(record_name,"/data/vr/voice_msbc_origin%d",file_index);\r
\r
+    voice_fd_origin =  open (record_name, O_WRONLY | O_CREAT |O_TRUNC, 0644);\r
+\r
+    \r
+    if(voice_fd_origin < 0)\r
+    {\r
+        ALOGE("can't open record origin  file:%s ",record_name);\r
+    }\r
+\r
+       RS_init_sbc();\r
+       \r
+       return;\r
+}\r
+\r
+void RS_voice_app_create_output()\r
+{\r
+    char record_name[50] = {0}; \r
+    sprintf(record_name,"/data/vr/voice_msbc%d",file_index);\r
+\r
+    voice_fd =  open (record_name, O_WRONLY | O_CREAT |O_TRUNC, 0644);\r
+\r
+    if(voice_fd < 0)\r
+    {\r
+        ALOGE("can't open record file:%s ",record_name);\r
+    }\r
+\r
+\r
+       return;\r
+}\r
+\r
+int RS_stop_voice_stream_data (void)\r
+{\r
+       char record_name[50] = {0};\r
+       \r
+    ALOGE ("in\r\n");\r
+       \r
+    if (voice_fd > 0 && -1 == close (voice_fd)  )\r
+    {\r
+        ALOGE ("close voice file fail\r\n");\r
+    }\r
+\r
+    if (voice_fd_origin > 0 && -1 == close (voice_fd_origin)  )\r
+    {\r
+        ALOGE ("close voice file fail\r\n");\r
+    }\r
+\r
+    voice_fd = 0;\r
+    voice_fd_origin = 0;\r
\r
+    sprintf(record_name,"voice_msbc%d",file_index);\r
+\r
+       //write_wav_header(record_name, 16000, 1);\r
+\r
+    sbc_finish (&t_sbc);\r
+\r
+       file_index = ((++file_index)>= 10) ? 0 : file_index;\r
+       \r
+    return 0;\r
+}\r
+\r
+int RS_write_decode_buf(uint8* pu_decode, ssize_t len)\r
+{\r
+        if (voice_fd > 0)\r
+        {\r
+            write (voice_fd, pu_decode, len);\r
+            return 0;\r
+        }\r
+        return -1;\r
+}\r
+\r
+int RS_deal_voice_stream_data(const uint8* input, size_t voice_buf_size, unsigned char* output, size_t output_buf_size, int* frame_len)\r
+{\r
+    int framelen;\r
+\r
+//    RS_init_sbc();\r
+\r
+    \r
+\r
+    if (NULL == input || 0 == voice_buf_size)\r
+    {\r
+        ALOGE ("input is null \r\n");\r
+        return -1;\r
+    }\r
+\r
+\r
+    if (NULL == output || 0 == output_buf_size)\r
+    {\r
+        ALOGE ("output is null");\r
+        return -1;\r
+    }\r
+\r
+    if(voice_buf_size != VOICE_MTU) {\r
+        ALOGE ("input size error: %d", voice_buf_size);\r
+        return -1;\r
+    }\r
+\r
+\r
+    write(voice_fd_origin, input, voice_buf_size);\r
+    if (input[0] == 0x01 && input[2] == 0xad)\r
+    { \r
+        framelen = sbc_decode (&t_sbc, &input[2], DECODE_SIZE, output, output_buf_size,frame_len);\r
+        if (framelen <= 0)\r
+        {\r
+            ALOGE("fail to decode");\r
+            return -1;\r
+        }\r
+        RS_write_decode_buf(output, *frame_len);\r
+        return 0;\r
+    }else {\r
+        ALOGE("msbc format error !!!");\r
+        return -1;\r
+    }\r
+}\r
+    \r
+\r
index 64cc362df4f9c69a6387f692a38c9dfde424c074..a55b100b9ca741eac9d39c9970c8b71ce9b233fc 100755 (executable)
@@ -1,22 +1,22 @@
-
-//#define  MSBC_SUPPORT
-#define  VOICE_KEY_DOWN 0x3e
-#define  VOICE_BUFFER_REPORT_ID    0x5a
-#define  ADD_FOR_VOICE_CONTROL
-#define  VOICE_FILE_WITH_MSBC           "/tmp/voice_msbc"
-#define  VOICE_FILE_WITH_NO_MSBC    "/tmp/voice_no_msbc"
-
-typedef unsigned char uint8;
-typedef unsigned short uint16;
-typedef unsigned int uint32;
-typedef signed char int8;
-typedef signed short int16;
-typedef signed int int32;
-
-void RS_voice_app_create_origin_output();
-
-int RS_deal_voice_stream_data(const uint8* input, size_t voice_buf_size, unsigned char* output, size_t output_buf_size, int* frame_len);
-
-int RS_stop_voice_stream_data (void);
-
-void RS_voice_app_create_output();
+\r
+//#define  MSBC_SUPPORT\r
+#define  VOICE_KEY_DOWN 0x3e\r
+#define  VOICE_BUFFER_REPORT_ID    0x5a\r
+#define  ADD_FOR_VOICE_CONTROL\r
+#define  VOICE_FILE_WITH_MSBC           "/tmp/voice_msbc"\r
+#define  VOICE_FILE_WITH_NO_MSBC    "/tmp/voice_no_msbc"\r
+\r
+typedef unsigned char uint8;\r
+typedef unsigned short uint16;\r
+typedef unsigned int uint32;\r
+typedef signed char int8;\r
+typedef signed short int16;\r
+typedef signed int int32;\r
+\r
+void RS_voice_app_create_origin_output();\r
+\r
+int RS_deal_voice_stream_data(const uint8* input, size_t voice_buf_size, unsigned char* output, size_t output_buf_size, int* frame_len);\r
+\r
+int RS_stop_voice_stream_data (void);\r
+\r
+void RS_voice_app_create_output();
\ No newline at end of file
index 0a062e1d3482f495e5459f980d50b6eced5fcf0a..d0fe74fda36792c4c38c2cee633511b6f92a8b60 100755 (executable)
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdint.h>
-#include <dirent.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <sys/inotify.h>
-#include <sys/poll.h>
-#include <linux/input.h>
-#include <linux/hidraw.h>
-#include <errno.h>
-#include <time.h>
-#include <unistd.h>
-
-#include <pthread.h>
-
-
-#include "voice_hidraw.h"
-#include "bee_settings.h"
-#include "get_voice_app.h"
-#include "sbc.h"
-#include "voice_uipc.h"
-#include "config.h"
-
-#define RAW_DATA_PATH "/data/vr/raw_data"
-static int file_counter = 0;
-int raw_fd;
-int gSocket_Running = 0;
-int gTarget_fd = 0;
-
-
-
-typedef struct {
-    int vid;
-    int pid;
-    int vers;
-    unsigned char voice_key_reportID;
-    unsigned char voice_data_reportID;
-    unsigned char voice_cmd_reportID;
-    int voice_keypress_data_len;
-    unsigned char *voice_keypress_data;
-    int voice_keyrelease_data_len;
-    unsigned char *voice_keyrelease_data;
-    int decode_type;
-    int data_mask;
-    int autocmd;
-    
-}VOICE_SETTING;
-
-static struct pollfd *ufds;
-static char **device_names;
-static int nfds;
-
-static int *unused_bt_hid_fds;
-static int nunusedfds;
-static char **unused_device_names;
-
-
-VOICE_SETTING global_voice_setting;
-pthread_mutex_t mutex_voice_settings;
-
-int frame_counter = 0;
-
-int set_rcu_info(int vid, int pid, int vers) {
-    pthread_mutex_lock(&mutex_voice_settings);
-    if(vid != -1)
-        global_voice_setting.vid = vid;
-
-    if(pid != -1)
-        global_voice_setting.pid = pid;
-
-    if(vers != -1)
-        global_voice_setting.vers = vers;
-
-    pthread_mutex_unlock(&mutex_voice_settings);
-
-    return 0;
-}
-
-int set_voice_data_reportID(unsigned char reportID) {
-    pthread_mutex_lock(&mutex_voice_settings);
-    global_voice_setting.voice_data_reportID = reportID;
-    pthread_mutex_unlock(&mutex_voice_settings);
-    return 0;
-}
-
-int set_voice_cmd_reportID(unsigned char reportID) {
-    pthread_mutex_lock(&mutex_voice_settings);
-    global_voice_setting.voice_cmd_reportID = reportID;
-    pthread_mutex_unlock(&mutex_voice_settings);
-    return 0;
-}
-
-int set_voice_key_reportID(unsigned char reportID) {
-    pthread_mutex_lock(&mutex_voice_settings);
-    global_voice_setting.voice_key_reportID = reportID;
-    pthread_mutex_unlock(&mutex_voice_settings);
-    return 0;
-}
-
-int set_voice_keypress_data(int len, unsigned char *data) {
-    if(len > 0) {
-        pthread_mutex_lock(&mutex_voice_settings);
-        if(global_voice_setting.voice_keypress_data != NULL) {
-            if(global_voice_setting.voice_keypress_data_len < len) {
-
-                unsigned char *buf = (unsigned char *)realloc(global_voice_setting.voice_keypress_data, len);
-                if(buf == NULL) {
-                    //log
-                    pthread_mutex_unlock(&mutex_voice_settings);
-                    error("Failed to realloc for voice_keypress_data");
-                    return -1;
-                }else {
-                    global_voice_setting.voice_keypress_data = buf;
-                }
-            }
-        }else {
-            global_voice_setting.voice_keypress_data = (unsigned char *)malloc(len);
-            if(global_voice_setting.voice_keypress_data == NULL) {
-                //log
-                pthread_mutex_unlock(&mutex_voice_settings);
-                error("Failed to malloc for voice_keypress_data");
-                return -2;
-            }
-        }
-
-        memcpy(global_voice_setting.voice_keypress_data, data, len);
-        global_voice_setting.voice_keypress_data_len = len;
-        pthread_mutex_unlock(&mutex_voice_settings);
-        return 0;
-    }else {
-        warn("len is negative for voice_keypress_data");
-        return -3;
-    }
-}
-
-int set_voice_keyrelease_data(int len, unsigned char *data) {
-    if(len > 0) {
-        pthread_mutex_lock(&mutex_voice_settings);
-        if(global_voice_setting.voice_keyrelease_data != NULL) {
-            if(global_voice_setting.voice_keyrelease_data_len < len) {
-                unsigned char *buf = (unsigned char *)realloc(global_voice_setting.voice_keyrelease_data, len);
-                if(buf == NULL) {
-                    //log
-                    pthread_mutex_unlock(&mutex_voice_settings);
-                    error("Failed to realloc for voice_keypress_data");
-                    return -1;
-                }else {
-                    global_voice_setting.voice_keyrelease_data = buf;
-                }
-            }
-        }else {
-            global_voice_setting.voice_keyrelease_data = (unsigned char *)malloc(len);
-            if(global_voice_setting.voice_keyrelease_data == NULL) {
-                pthread_mutex_unlock(&mutex_voice_settings);
-                error("Failed to malloc for voice_keyrelease_data");
-                return -2;
-            }
-        }
-
-        memcpy(global_voice_setting.voice_keyrelease_data, data, len);
-        global_voice_setting.voice_keyrelease_data_len = len;
-        pthread_mutex_unlock(&mutex_voice_settings);
-        return 0;
-    }else {
-        //log
-        warn("len is negative for voice_keyrelease_data");
-        return -3;
-    }
-}
-
-int set_encode_type(int type) {
-    if(type <= DECODE_TYPE_MAX) {
-        pthread_mutex_lock(&mutex_voice_settings);
-        global_voice_setting.decode_type = type;
-        pthread_mutex_unlock(&mutex_voice_settings);
-        return 0;
-    }else {
-        warn("Unknown Decode Type !!!");
-        return -1;
-    }
-}
-
-int data_type_mask(int mask) {
-    //log
-    debug("Set Data Type Mask 0x%04x", mask);
-
-    pthread_mutex_lock(&mutex_voice_settings);
-    
-    if(mask & DATA_TYPE_MASK_RAW) {
-        global_voice_setting.data_mask = DATA_TYPE_MASK_RAW;
-    }else {
-        if(mask & DATA_TYPE_MASK_VOICE) {
-            global_voice_setting.data_mask |= DATA_TYPE_MASK_VOICE;
-        }
-    }
-
-    pthread_mutex_unlock(&mutex_voice_settings);
-    return 0;
-}
-
-int set_auto_cmd(int autocmd) {
-    pthread_mutex_lock(&mutex_voice_settings);
-    if(autocmd == 1) {
-        global_voice_setting.autocmd = AUTOCMD_AUTO;
-    }else if(autocmd == 2){
-        global_voice_setting.autocmd = AUTOCMD_NONE;
-    }
-    pthread_mutex_unlock(&mutex_voice_settings);
-
-    return 0;
-}
-
-
-
-int voice_msbc_init() {
-
-    int ivalue, i;
-   
-    voice_loadconfig(CONFIG_PATH);
-
-    pthread_mutex_lock(&mutex_voice_settings);
-    
-    memset(&global_voice_setting, 0, sizeof(global_voice_setting));
-
-    ivalue = voice_get_int_config(CONFIG_GROUP_RCU, CONFIG_ITEM_RCU_VID);
-    if(ivalue >= 0) {
-        global_voice_setting.vid = ivalue;
-        ALOGD("use config VID: %04x", global_voice_setting.vid);
-    } else {
-        global_voice_setting.vid = BEE_RCU_VID;
-        ALOGD("use default VID: %04x", global_voice_setting.vid);
-    }
-
-    ivalue = voice_get_int_config(CONFIG_GROUP_RCU, CONFIG_ITEM_RCU_PID);
-    if(ivalue >= 0) {
-        global_voice_setting.pid = ivalue;
-        ALOGD("use config PID: %04x", global_voice_setting.pid);
-    } else {
-        global_voice_setting.pid = BEE_RCU_PID;
-        ALOGD("use default PID: %04x", global_voice_setting.pid);
-    }
-
-    ivalue = voice_get_int_config(CONFIG_GROUP_RCU, CONFIG_ITEM_RCU_VER);
-    if(ivalue >= 0) {
-        global_voice_setting.vers = ivalue;
-        ALOGD("use config version: %04x", global_voice_setting.vers);
-    } else {
-        global_voice_setting.vers = BEE_RCU_VERSION;
-        ALOGD("use default VERSION: %04x", global_voice_setting.vers);
-    }
-
-    ivalue = voice_get_int_config(CONFIG_GROUP_REPORTID, CONFIG_ITEM_REPORTID_KEY);
-    if(ivalue > 0) {
-        global_voice_setting.voice_key_reportID = ivalue & 0xff;
-        ALOGD("use config key report id: %02x", global_voice_setting.voice_key_reportID);
-    } else {
-        global_voice_setting.voice_key_reportID = BEE_VOICEKEY_REPORTID;
-        ALOGD("use default key report id: %02x", global_voice_setting.voice_key_reportID);
-    }
-    
-
-    ivalue = voice_get_int_config(CONFIG_GROUP_REPORTID, CONFIG_ITEM_REPORTID_DATA);
-    if(ivalue > 0) {
-        global_voice_setting.voice_data_reportID = ivalue & 0xff;
-        ALOGD("use config data report id: %02x", global_voice_setting.voice_data_reportID);
-    } else {
-        global_voice_setting.voice_data_reportID = BEE_MSBC_VOICEDATA_REPORTID;
-        ALOGD("use default data report id: %02x", global_voice_setting.voice_data_reportID);
-    }
-
-    ivalue = voice_get_int_config(CONFIG_GROUP_REPORTID, CONFIG_ITEM_REPORTID_CMD);
-    if(ivalue > 0) {
-        global_voice_setting.voice_cmd_reportID = ivalue & 0xff;
-        ALOGD("use config cmd report id: %02x", global_voice_setting.voice_cmd_reportID);
-    } else {
-        global_voice_setting.voice_cmd_reportID = BEE_MSBC_VOICECMD_REPORTID;
-        ALOGD("use default cmd report id: %02x", global_voice_setting.voice_cmd_reportID);
-    }
-
-    ivalue = voice_get_int_config(CONFIG_GROUP_REPORTVALUE, CONFIG_ITEM_REPORTVALUE_KEYDOWNLEN);
-    if(ivalue > 0) {
-        global_voice_setting.voice_keypress_data_len = ivalue;
-        ALOGD("use config keydown len: %d", global_voice_setting.voice_keypress_data_len);
-    } else {
-        global_voice_setting.voice_keypress_data_len = BEE_VOICEKEY_LEN;
-        ALOGD("use default keydown len: %d", global_voice_setting.voice_keypress_data_len);
-    }
-
-    global_voice_setting.voice_keypress_data = (unsigned char *)malloc(global_voice_setting.voice_keypress_data_len);
-    if(global_voice_setting.voice_keypress_data == NULL) {
-        //log
-        error("failed to get buf for keydown");
-        pthread_mutex_unlock(&mutex_voice_settings);
-        return -1;
-    }else {
-        if(ivalue > 0) {
-            if(voice_get_byte_array_config(CONFIG_GROUP_REPORTVALUE, CONFIG_ITEM_REPORTVALUE_KEYDOWN,
-                global_voice_setting.voice_keypress_data, global_voice_setting.voice_keypress_data_len)
-                != global_voice_setting.voice_keypress_data_len) {
-                
-                global_voice_setting.voice_keypress_data_len = BEE_VOICEKEY_LEN;
-                if(ivalue < BEE_VOICEKEY_LEN) {
-                    global_voice_setting.voice_keypress_data = (unsigned char *)realloc(global_voice_setting.voice_keypress_data, BEE_VOICEKEY_LEN);
-                    if(global_voice_setting.voice_keypress_data == NULL) {
-                        error("failed to realloc buf for keydown");
-                        pthread_mutex_unlock(&mutex_voice_settings);
-                        return -1;
-                    }
-                }
-                memcpy(global_voice_setting.voice_keypress_data, BEE_VOICE_KEYDOWN_DATA, global_voice_setting.voice_keypress_data_len);
-                ALOGD("use default keydown data");
-            }
-        }else {
-            memcpy(global_voice_setting.voice_keypress_data, BEE_VOICE_KEYDOWN_DATA, global_voice_setting.voice_keypress_data_len);
-            ALOGD("use default keydown data");
-        }
-        ALOGD("key down data:");
-        for(i = 0; i < global_voice_setting.voice_keypress_data_len; i++) {
-            ALOGD("data[%d] = %02x", i, *(global_voice_setting.voice_keypress_data + i));
-        }
-    }
-
-    ivalue = voice_get_int_config(CONFIG_GROUP_REPORTVALUE, CONFIG_ITEM_REPORTVALUE_KEYUPLEN);
-    if(ivalue > 0) {
-        global_voice_setting.voice_keyrelease_data_len = ivalue;
-        ALOGD("use config keyup len: %d", global_voice_setting.voice_keyrelease_data_len);
-    } else {
-        global_voice_setting.voice_keyrelease_data_len = BEE_VOICEKEY_LEN;
-        ALOGD("use default keyup len: %d", global_voice_setting.voice_keyrelease_data_len);
-    }
-
-    global_voice_setting.voice_keyrelease_data = (unsigned char *)malloc(global_voice_setting.voice_keyrelease_data_len);
-    if(global_voice_setting.voice_keyrelease_data == NULL) {
-        //log
-        error("failed to get buf for keyup");
-        pthread_mutex_unlock(&mutex_voice_settings);
-        return -1;
-    }else {
-        if(ivalue > 0) {
-            if(voice_get_byte_array_config(CONFIG_GROUP_REPORTVALUE, CONFIG_ITEM_REPORTVALUE_KEYUP,
-                global_voice_setting.voice_keyrelease_data, global_voice_setting.voice_keyrelease_data_len)
-                != global_voice_setting.voice_keyrelease_data_len) {
-                
-                global_voice_setting.voice_keyrelease_data_len = BEE_VOICEKEY_LEN;
-                if(ivalue < BEE_VOICEKEY_LEN) {
-                    global_voice_setting.voice_keyrelease_data = (unsigned char *)realloc(global_voice_setting.voice_keyrelease_data, BEE_VOICEKEY_LEN);
-                    if(global_voice_setting.voice_keyrelease_data == NULL) {
-                        error("failed to realloc buf for keyup");
-                        pthread_mutex_unlock(&mutex_voice_settings);
-                        return -1;
-                    }
-                }
-                memcpy(global_voice_setting.voice_keyrelease_data, BEE_VOICE_KEYUP_DATA, global_voice_setting.voice_keyrelease_data_len);
-                ALOGD("use default keyup data");
-            }
-        }else {
-            memcpy(global_voice_setting.voice_keyrelease_data, BEE_VOICE_KEYUP_DATA, global_voice_setting.voice_keyrelease_data_len);
-            ALOGD("use default keyup data");
-        }
-        ALOGD("key up data:");
-        for(i = 0; i < global_voice_setting.voice_keyrelease_data_len; i++) {
-            ALOGD("data[%d] = %02x", i, *(global_voice_setting.voice_keyrelease_data + i));
-        }
-    }
-
-    ivalue = voice_get_int_config(CONFIG_GROUP_SETTINGS, CONFIG_ITEM_SETTINGS_DECODETYPE);
-    if(ivalue > 0) {
-        global_voice_setting.decode_type = ivalue;
-        ALOGD("use config decode type: %d", global_voice_setting.decode_type);
-    } else {
-        global_voice_setting.decode_type = DECODE_TYPE_MSBC;
-        ALOGD("use default decode type: %d", global_voice_setting.decode_type);
-    }
-
-    ivalue = voice_get_int_config(CONFIG_GROUP_SETTINGS, CONFIG_ITEM_SETTINGS_DATAMASK);
-    if(ivalue > 0) {
-        global_voice_setting.data_mask = ivalue;
-        ALOGD("use config data mask: %d", global_voice_setting.data_mask);
-    } else {
-        global_voice_setting.data_mask = DATA_TYPE_MASK_VOICE;
-        ALOGD("use default decode type: %d", global_voice_setting.data_mask);
-    }
-
-    ivalue = voice_get_int_config(CONFIG_GROUP_SETTINGS, CONFIG_ITEM_SETTINGS_AUTOCMD);
-    if(ivalue > 0) {
-        global_voice_setting.autocmd = ivalue;
-        ALOGD("use config decode type: %d", global_voice_setting.autocmd);
-    } else {
-        global_voice_setting.autocmd = AUTOCMD_AUTO;
-        ALOGD("use default decode type: %d", global_voice_setting.autocmd);
-    }
-
-    pthread_mutex_unlock(&mutex_voice_settings);
-    voice_conf_exit();
-    return 0;
-}
-
-void voice_open_store_file()
-{
-    char record_name[50] = {0}; 
-    sprintf(record_name, "%s%d", RAW_DATA_PATH, file_counter);
-
-    raw_fd =  open (record_name, O_WRONLY | O_CREAT |O_TRUNC, 0644);
-
-    if(raw_fd < 0)
-    {
-        ALOGE("can't open record file:%s ", record_name);
-    }
-
-
-       return;
-}
-
-int voice_write_decode_buf(uint8* pu_decode, ssize_t len)
-{
-    if (raw_fd > 0)
-    {
-        write (raw_fd, pu_decode, len);
-        return 0;
-    }
-    return -1;
-}
-
-
-/**********************************************
-*
-*   hidraw node related
-*
-***********************************************/
-const char *bus_str(int bus){
-    switch (bus) {
-        case BUS_USB:
-            return "USB";
-            
-        case BUS_HIL:
-            return "HIL";
-            
-        case BUS_BLUETOOTH:
-            return "Bluetooth";
-
-        case BUS_VIRTUAL:
-            return "Virtual";
-                
-        default:
-            return "Other";
-    }
-}
-    
-static int get_hidraw_info(int fd)
-{
-    int i, res, desc_size = 0;
-    char buf[256];
-    struct hidraw_report_descriptor rpt_desc;
-    struct hidraw_devinfo info;
-    
-    memset(&rpt_desc, 0x0, sizeof(rpt_desc));
-    memset(&info, 0x0, sizeof(info));
-    memset(buf, 0x0, sizeof(buf));
-    debug("-----------------------------------------------\n");
-    
-    /* Get Raw Name */
-    res = ioctl(fd, HIDIOCGRAWNAME(256), buf);
-    if (res < 0)
-        perror("HIDIOCGRAWNAME");
-    else
-        debug("Raw Name: %s\n", buf);
-    /* Get Physical Location */
-    res = ioctl(fd, HIDIOCGRAWPHYS(256), buf);
-    if (res < 0)
-        perror("HIDIOCGRAWPHYS");
-    else
-        debug("Raw Phys: %s\n", buf);
-    /* Get Raw Info */
-    res = ioctl(fd, HIDIOCGRAWINFO, &info);
-    if (res < 0) {
-        perror("HIDIOCGRAWINFO");
-    } else {
-        debug("Raw Info:");
-        debug(" bustype: %d (%s)", info.bustype, bus_str(info.bustype));
-        debug(" vendor: 0x%04x", info.vendor);
-        debug(" product: 0x%04x\n", info.product);
-    }
-    /* Get Report Descriptor Size */
-    res = ioctl(fd, HIDIOCGRDESCSIZE, &desc_size);
-    if (res < 0)
-       perror("HIDIOCGRDESCSIZE");
-    else
-        debug("Report Descriptor Size: %d\n", desc_size);
-    /* Get Report Descriptor */
-    rpt_desc.size = desc_size;
-    res = ioctl(fd, HIDIOCGRDESC, &rpt_desc);
-    if (res < 0) {
-        perror("HIDIOCGRDESC");
-    } else {
-        debug("Report Descriptor:");
-        for (i = 0; i < rpt_desc.size; i++)
-        {
-            if((i%16)==0)
-                debug("\n");
-            debug("%02x ", rpt_desc.value[i]);
-        }
-        debug("\n");
-    }
-    info("-----------------------------------------------\n");
-    
-    return 0;
-}
-
-static int send_message(int fd, unsigned char * buf, int len)
-{
-    int res = 0;
-    res = write(fd, buf, len);
-    debug("send_message res=%d\n",res);
-    return res;
-}
-
-static void process_voice_data(unsigned char reportID, unsigned char *buf, int len) {
-    int ret = -1;
-    int offset = 0;
-    int i;
-    int decode_len = 0;
-
-    unsigned char output_buf[1024] = {0x00};
-
-    //debug("reportID=%d, decode_type=%d, global_reportID=%d, len=%d", 
-        //reportID, global_voice_setting.decode_type, global_voice_setting.voice_data_reportID, len);
-
-    if(global_voice_setting.decode_type == DECODE_TYPE_MSBC) {
-        while(offset + BEE_MSBC_FRAME_SIZE <= len) {
-            //debug("offset is %d now, len is %d", offset, len);
-            ret = RS_deal_voice_stream_data(buf + offset, BEE_MSBC_FRAME_SIZE, output_buf, 1024, &decode_len);
-            if(ret < 0) {
-                offset++;
-            }else {
-                UIPC_Send_noblock(UIPC_CH_ID_VOICE_DATA, 0, output_buf, decode_len);
-                offset += BEE_MSBC_FRAME_SIZE;
-            }
-        }
-    }else if(global_voice_setting.decode_type == DECODE_TYPE_SBC) {
-        decode_len = 1024;
-        while(offset + BEE_SBC_FRAME_SIZE <= len) {
-            ret = sbcDecode(buf + offset, BEE_SBC_FRAME_SIZE, output_buf, &decode_len);
-            if(ret < 0) {
-                debug("fail to decode: %d", ret);
-                offset++;
-            }else {
-                UIPC_Send_noblock(UIPC_CH_ID_VOICE_DATA, 0, output_buf, decode_len);
-                offset += BEE_SBC_FRAME_SIZE;
-            }
-        }
-    }
-}
-
-static int read_message(int fd)
-{
-    unsigned char buf[4096];
-    int res,i;
-
-    unsigned char start_rec_command[] = {global_voice_setting.voice_cmd_reportID, 0x01};
-    unsigned char stop_rec_command[] = {global_voice_setting.voice_cmd_reportID, 0x00};
-    static int voice_kpressed = 0;
-
-/*
-    struct hidraw_devinfo info;
-    res = ioctl(fd, HIDIOCGRAWINFO, &info);
-    if (res < 0) {
-        perror("HIDIOCGRAWINFO");
-    }
-*/
-
-    //if( (info.vendor==global_voice_setting.vid) && (info.product==global_voice_setting.pid) )
-    //{
-        res = read(fd, buf, sizeof(buf));
-        debug("read buffer res: %04x", res);
-        if(res > 0)
-        {
-            //debug("Receive From :%04x,%04x number: %d", info.vendor, info.product, res);
-            if( (global_voice_setting.data_mask & DATA_TYPE_MASK_RAW) == DATA_TYPE_MASK_RAW) {
-                //just callback and return
-                UIPC_Send_noblock(UIPC_CH_ID_VOICE_DATA, 0, buf + 1, res - 1);
-                return 0;
-            }else if( (global_voice_setting.data_mask & DATA_TYPE_MASK_VOICE) == DATA_TYPE_MASK_VOICE) {
-
-                if((voice_kpressed == 0) && (buf[0] == global_voice_setting.voice_key_reportID) && 
-                    (res == global_voice_setting.voice_keypress_data_len + 1) && 
-                    (memcmp(buf + 1, global_voice_setting.voice_keypress_data, global_voice_setting.voice_keypress_data_len) == 0))
-                {
-                    //debug("voice key pressed");
-                    if(global_voice_setting.autocmd == AUTOCMD_AUTO) {
-                        RS_voice_app_create_output();
-                        RS_voice_app_create_origin_output();
-                        voice_open_store_file();
-
-                        //send_message(fd, start_rec_command,sizeof(start_rec_command));
-                        voice_kpressed = 1;
-                        frame_counter = 0;
-                    }
-                    return 0;
-                }
-
-                // when voice key is released
-                if ((voice_kpressed == 1) && (buf[0] == global_voice_setting.voice_key_reportID) && 
-                    (res == global_voice_setting.voice_keyrelease_data_len + 1) && 
-                    (memcmp(buf + 1, global_voice_setting.voice_keyrelease_data, global_voice_setting.voice_keyrelease_data_len) == 0))
-                {
-                    //debug("voice key relesed");
-
-                    if(global_voice_setting.autocmd == AUTOCMD_AUTO) {
-                        RS_stop_voice_stream_data();
-                        //send_message(fd, stop_rec_command,sizeof(stop_rec_command));
-                        voice_kpressed = 0;
-                        debug("total frame: %d", frame_counter);
-                        close(raw_fd);
-                        file_counter++;
-                        raw_fd = -1;
-                    }
-                    return 0;
-                }
-
-                // store voice data
-                if ((voice_kpressed == 1 ) && (buf[0] == global_voice_setting.voice_data_reportID))
-                {
-                    //debug("deal with voice data");
-                    process_voice_data(buf[0], buf + 1, res-1);
-                    voice_write_decode_buf(buf + 1, res - 1);
-                    frame_counter++;
-                    return 0;
-                }
-            }
-        }else {
-            warn("Read fd %d failed: %s", fd, strerror(errno));
-            return -1;
-        }
-
-    //}
-
-    return 0;
-}
-
-int get_dev_vid_pid_info(int fd, short* vid, short* pid) {
-    int res = -1;
-    struct hidraw_devinfo info;
-
-    memset(&info, 0x0, sizeof(info));
-
-    res = ioctl(fd, HIDIOCGRAWINFO, &info);
-    if (res < 0) {
-        debug("failed to get HIDIOCGRAWINFO");
-    } else {
-        //debug("Raw Info:");
-        //debug(" bustype: %d (%s)", info.bustype, bus_str(info.bustype));
-        debug(" vendor: 0x%04x, product: 0x%04x", info.vendor, info.product);
-        *vid = info.vendor;
-        *pid = info.product;
-        res = 1;
-    }
-    return res;
-}
-
-static int open_device(const char *device)
-{
-    int version;
-    int fd;
-    int clkid = CLOCK_MONOTONIC;
-    struct pollfd *new_ufds;
-    int *unfds;
-    char **new_device_names;
-    char **new_unused_device_names;
-    char name[80];
-    char location[80];
-    char idstr[80];
-    struct input_id id;
-    int res = -1;
-    struct hidraw_devinfo info;
-
-    fd = open(device, O_RDWR);
-    if(fd < 0) {
-        debug("could not open %s, %s\n", device, strerror(errno));
-        return -1;
-    }
-    debug("new fd is %d", fd);
-
-    res = ioctl(fd, HIDIOCGRAWINFO, &info);
-    if(res < 0) {
-        debug("failed to get hidraw_devinfo, add for now");
-    }else if(info.bustype != BUS_BLUETOOTH){
-        debug("ingore this device");
-        close(fd);
-        return -1;
-    }else if((info.vendor != global_voice_setting.vid) || (info.product != global_voice_setting.pid)) {
-        //res = unlink(fd);
-        debug("Not the device we care, add to unused fds");
-        unfds = realloc(unused_bt_hid_fds, sizeof(unused_bt_hid_fds[0]) * (nunusedfds + 1));
-        if(unfds == NULL) {
-            error("unused fds: out of memory");
-            return -1;
-        }
-
-        new_unused_device_names = realloc(unused_device_names, sizeof(unused_device_names[0]) * (nunusedfds + 1));
-        if(new_unused_device_names == NULL) {
-            error("unused device_names: out of memory");
-            return -1;
-        }
-
-        unused_bt_hid_fds = unfds;
-        unused_device_names = new_unused_device_names;
-        
-        unused_bt_hid_fds[nunusedfds] = fd;
-        unused_device_names[nunusedfds] = strdup(device);
-        nunusedfds++;
-        return 0; 
-    }
-
-    new_ufds = realloc(ufds, sizeof(ufds[0]) * (nfds + 1));
-    if(new_ufds == NULL) {
-        error("out of memory\n");
-        return -1;
-    }
-
-    ufds = new_ufds;
-    new_device_names = realloc(device_names, sizeof(device_names[0]) * (nfds + 1));
-    if(new_device_names == NULL) {
-        debug("out of memory\n");
-        return -1;
-    }
-    device_names = new_device_names;
-    //get_hidraw_info(fd);
-    ufds[nfds].fd = fd;
-    ufds[nfds].events = POLLIN;
-    device_names[nfds] = strdup(device);
-    nfds++;
-
-    return 0;
-}
-
-int close_device(const char *device)
-{
-    int i;
-    for(i = 1; i < nfds; i++) {
-        if(strcmp(device_names[i], device) == 0) {
-            int count = nfds - i - 1;
-            debug("remove device %d: %s\n", i, device);
-            free(device_names[i]);
-            memmove(device_names + i, device_names + i + 1, sizeof(device_names[0]) * count);
-            close(ufds[i].fd);
-            memmove(ufds + i, ufds + i + 1, sizeof(ufds[0]) * count);
-            nfds--;
-            return 0;
-        }
-    }
-
-    for(i = 0; i < nunusedfds; i++) {
-        if(strcmp(unused_device_names[i], device) == 0) {
-            int count = nunusedfds - i;
-            debug("remove unused device %d: %s\n", i, device);
-            free(unused_device_names[i]);
-            memmove(unused_device_names + i, unused_device_names + i + 1, sizeof(unused_device_names[0]) * count);
-            close(unused_bt_hid_fds[i]);
-            memmove(unused_bt_hid_fds + i, unused_bt_hid_fds + i + 1, sizeof(unused_bt_hid_fds[0]) * count);
-            nunusedfds--;
-            return 0;
-        }
-    }
-    
-    error("remote device: %s not found\n", device);
-    return -1;
-}
-
-static int read_notify(const char *dirname, int nfd)
-{
-    int res;
-    char devname[PATH_MAX];
-    char *filename;
-    char event_buf[512];
-    int event_size;
-    int event_pos = 0;
-    struct inotify_event *event;
-
-    res = read(nfd, event_buf, sizeof(event_buf));
-    if(res < (int)sizeof(*event)) {
-        if(errno == EINTR)
-            return 0;
-        error("could not get event, %s\n", strerror(errno));
-        return 1;
-    }
-    //printf("got %d bytes of event information\n", res);
-
-    strcpy(devname, dirname);
-    filename = devname + strlen(devname);
-    *filename++ = '/';
-
-    while(res >= (int)sizeof(*event)) {
-        event = (struct inotify_event *)(event_buf + event_pos);
-        debug("%d: %08x \"%s\"\n", event->wd, event->mask, event->len ? event->name : "");
-        if((event->len)&&(memcmp(event->name, "hidraw", strlen("hidraw"))==0)) {
-            debug("read_notify: %d: %08x \"%s\"\n", event->wd, event->mask, event->len ? event->name : "");
-            strcpy(filename, event->name);
-            if(event->mask & IN_CREATE) {
-                open_device(devname);
-            }
-            else {
-                close_device(devname);
-            }
-        }
-        event_size = sizeof(*event) + event->len;
-        res -= event_size;
-        event_pos += event_size;
-    }
-    return 0;
-}
-
-
-static int scan_dir(const char *dirname)
-{
-    char devname[PATH_MAX];
-    char *filename;
-    DIR *dir;
-    struct dirent *de;
-    dir = opendir(dirname);
-    if(dir == NULL)
-        return -1;
-    strcpy(devname, dirname);
-    filename = devname + strlen(devname);
-    *filename++ = '/';
-    while((de = readdir(dir))) {
-        if(de->d_name[0] == '.' &&
-           (de->d_name[1] == '\0' ||
-            (de->d_name[1] == '.' && de->d_name[2] == '\0')))
-            continue;
-        if(memcmp(de->d_name,"hidraw",strlen("hidraw")))
-            continue;
-        strcpy(filename, de->d_name);
-        //debug("scan_dir: %s\n",devname);
-        open_device(devname);
-    }
-    closedir(dir);
-    return 0;
-}
-
-static void voice_ctrl_recv(void)
-{
-    unsigned char cmd[256], opcode = 0xFF;
-    int n, i;
-
-    n = UIPC_Read(UIPC_CH_ID_VOICE_CTRL, NULL, cmd, 256);
-
-    /* detach on ctrl channel means audioflinger process was terminated */
-    if (n == 0)
-    {
-        debug("CTRL CH DETACHED");
-        //the ctrl channel will re-open automatically
-        UIPC_Close(UIPC_CH_ID_VOICE_CTRL);
-        return;
-    }
-
-    debug("receive voice-ctrl-cmd read num_of_data = %d ", n);
-    for (i=0; i< n; i++)
-        info("data[%d] = %d ", i, cmd[i]);
-    //receive start or stop cmd from service
-    if( cmd[0] <= OPCODE_MAX)
-    {
-        opcode = cmd[0];
-    }
-    else
-    {
-        //clear the memory
-        UIPC_Ioctl(UIPC_CH_ID_VOICE_CTRL, UIPC_REQ_RX_FLUSH,NULL);
-        info("it is wrong cmd send from service");
-    }
-
-    info("opcode = %d",opcode);
-    switch(opcode)
-    {
-        case OPCODE_SETTING_RESET:              //0   cmd(1)
-            break;
-
-        case OPCODE_VOICE_START_CMD:            //1   cmd(1)
-            debug("start, len=%d", n);
-            break;
-
-        case OPCODE_VOICE_STOP_CMD:             //2   cmd(1)
-            debug("stop, len=%d", n);
-            break;
-
-        case OPCODE_SET_RCU_INFO:               //3   cmd(1) + vid(2) + pid(2) + vers(2)
-            if(n == 7) {
-                int vid = (cmd[1] << 8) + cmd[2];
-                int pid = (cmd[3] << 8) + cmd[4];
-                int vers = (cmd[5] << 8) + cmd[6];
-                set_rcu_info(vid,pid,vers);
-            }
-            break;
-
-        case OPCODE_SET_VOICE_DATA_REPORT_ID:   //4   cmd(1) + reportID(1)
-            if(n == 2) {
-                set_voice_data_reportID(cmd[1]);
-            }
-            break;
-
-        case OPCODE_SET_VOICE_CMD_REPORT_ID:    //5   cmd(1) + reportID(1)
-            if(n == 2) {
-                set_voice_cmd_reportID(cmd[1]);
-            }
-            break;
-
-        case OPCODE_SET_VOICE_KEY_REPORT_ID:    //6   cmd(1) + reportID(1)
-            if(n == 2) {
-                set_voice_key_reportID(cmd[1]);
-            }
-            break;
-
-        case OPCODE_SET_VOICE_KEYPRESS_DATA:    //7   cmd(1) + len(1) + data(n)
-            if(n > 2) {
-                int len = cmd[1];
-                set_voice_keypress_data(len, cmd + 2);
-            }
-            break;
-
-        case OPCODE_SET_VOICE_KEYRELEASE_DATA:  //8   cmd(1) + len(1) + data(n)
-            if(n > 2) {
-                int len = cmd[1];
-                set_voice_keyrelease_data(len, cmd + 2);
-            }
-            break;
-
-        case OPCODE_SET_VOICE_STARTCMD_DATA:    //9   cmd(1) + len(1) + data(n)
-            debug("set voice start data, len=%d", cmd[1]);
-            break;
-
-        case OPCODE_SET_VOICE_STOPCMD_DATA:     //10  cmd(1) + len(1) + data(n)
-            debug("set voice stop data, len=%d", cmd[1]);
-            break;
-
-        case OPCODE_SET_ENCODE_TYPE:            //11  cmd(1) + type(1)
-            if(n == 2) {
-                set_encode_type(cmd[1]);
-            }
-            break;
-
-        case OPCODE_SET_DATA_TYPE_MASK:         //12  cmd(1) + type(1)
-            debug("set type mask: 0x%02x", cmd[1]);
-            break;
-
-        case OPCODE_SET_AUTO_CMD:               //13  cmd(1) + auto(1)
-            if(n == 2) {
-                set_auto_cmd(cmd[1]);
-            }
-            break;
-
-        case OPCODESEND_HIDRAW_DATA:            //14  cmd(1) + reportID(1) + len(1) + data(n)
-            debug("send raw data, reportID=0x%02x, len=0x%02x", cmd[1], cmd[2]);
-            break;
-
-        case OPCODE_EXIT:
-            debug("exit");
-            gSocket_Running = 0;
-    }
-
-    info("voice-ctrl-cmd DOWN!");
-}
-
-static void voice_data_recv(void)
-{
-    unsigned char cmd[256], opcode = 0xFF;
-    int n, i;
-
-    n = UIPC_Read(UIPC_CH_ID_VOICE_DATA, NULL, cmd, 256);
-
-    /* detach on ctrl channel means audioflinger process was terminated */
-    if (n == 0)
-    {
-        debug("DATA CH DETACHED");
-        //the ctrl channel will re-open automatically
-        UIPC_Close(UIPC_CH_ID_VOICE_DATA);
-        return;
-    }
-
-    debug("receive voice-data read num_of_data = %d ", n);
-}
-
-
-static void ctrl_socket_cb(tUIPC_CH_ID ch_id, tUIPC_EVENT event)
-{
-
-    switch(event)
-    {
-        case UIPC_OPEN_EVT:
-            /*
-                in certain case, hid status msg must be sent upon ctrl chan opened
-             */
-            debug("Jim@control_socket_cb: sending hid status msg upon open");
-            break;
-
-        case UIPC_CLOSE_EVT:
-            if (gSocket_Running) {
-                debug("jim@control_socket_cb: re-open ctrl chan");
-                UIPC_Open(UIPC_CH_ID_VOICE_CTRL, ctrl_socket_cb);
-            }
-            break;
-
-        case UIPC_RX_DATA_EVT:
-            info("btif_voice_ctrl_cb, the event is UIPC_RX_DATA_EVT");
-
-        case UIPC_RX_DATA_READY_EVT:
-            voice_ctrl_recv();
-            break;
-
-        default :
-            info("### VOICE-CTRL-CHANNEL EVENT %d NOT HANDLED ###", event);
-            break;
-    }
-}
-
-static void data_socket_cb(tUIPC_CH_ID ch_id, tUIPC_EVENT event)
-{
-
-    debug("data_socket_cb");
-    switch(event)
-    {
-        case UIPC_OPEN_EVT:
-            debug("Jim@data_socket_cb: sending hid status msg upon open");
-            break;
-
-        case UIPC_CLOSE_EVT:
-            if (gSocket_Running) {
-                debug("jim@data_socket_cb: re-open data chan");
-                UIPC_Open(UIPC_CH_ID_VOICE_DATA, data_socket_cb);
-            }
-            break;
-
-        case UIPC_RX_DATA_EVT:
-            info("data_socket_cb, the event is UIPC_RX_DATA_EVT");
-
-        case UIPC_RX_DATA_READY_EVT:
-            voice_data_recv();
-            info("data_socket_cb, the event is UIPC_RX_DATA_READY_EVT");
-            break;
-
-        default :
-            info("### VOICE-DATA-CHANNEL EVENT %d NOT HANDLED ###", event);
-            break;
-    }
-}
-
-
-
-int init(void) {
-
-    pthread_mutex_init(&mutex_voice_settings, NULL);
-    voice_msbc_init();
-    sbcInitDecoder();
-
-    gSocket_Running = 1;
-    UIPC_Init(NULL);
-    UIPC_Open(UIPC_CH_ID_VOICE_CTRL, ctrl_socket_cb);
-    UIPC_Open(UIPC_CH_ID_VOICE_DATA, data_socket_cb);
-
-    return 0;
-}
-
-void cleanup(void) {
-
-    gSocket_Running = 0;
-    UIPC_Close(UIPC_CH_ID_VOICE_DATA);
-    UIPC_Close(UIPC_CH_ID_VOICE_CTRL);
-
-    pthread_mutex_lock(&mutex_voice_settings);
-    
-    
-    if(global_voice_setting.voice_keypress_data != NULL)
-        free(global_voice_setting.voice_keypress_data);
-
-    if(global_voice_setting.voice_keyrelease_data != NULL)
-        free(global_voice_setting.voice_keyrelease_data);
-
-    pthread_mutex_unlock(&mutex_voice_settings);
-    //release other resources here
-}
-
-
-int main(void) {
-    const char *device_path = "/dev";
-    int res;
-    int i;
-
-    init();
-
-    nfds = 1;
-    ufds = calloc(1, sizeof(ufds[0]));
-    ufds[0].fd = inotify_init();
-    ufds[0].events = POLLIN;
-
-    res = inotify_add_watch(ufds[0].fd, device_path, IN_DELETE | IN_CREATE);
-    if(res < 0) {
-        error("could not add watch for %s, %s\n", device_path, strerror(errno));
-        return -1;
-    }
-
-    res = scan_dir(device_path);
-    if(res < 0) {
-        error("scan dir failed for %s\n", device_path);
-        return -2;
-    }
-
-    while(gSocket_Running) {
-        poll(ufds, nfds, -1);
-        if(ufds[0].revents & POLLIN) {
-            //debug("new notify event!!!");
-            read_notify(device_path, ufds[0].fd);
-        }
-
-        for(i = 1; i < nfds; i++) {
-            if(ufds[i].revents) {
-                /*
-                //debug("new message event, fd = %d, event = %04x.", ufds[i].fd, ufds[i].revents);
-                if((ufds[i].revents & POLLHUP) && (ufds[i].revents & POLLERR)) {
-                    debug("close, fd=%d, events=0x%04x", ufds[i].fd, ufds[i].revents);
-                    close(ufds[i].fd);
-                 
-                }else if(ufds[i].revents & POLLIN) {
-                    //debug("new message event!!!");
-                    read_message(ufds[i].fd);
-                }
-                */
-                if(ufds[i].revents & POLLIN) {
-                    //debug("new message event!!!");
-                    read_message(ufds[i].fd);
-                }
-            }
-        }
-    }
-    cleanup();
-    
-    return 0;
-
-}
-
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <stdint.h>\r
+#include <dirent.h>\r
+#include <fcntl.h>\r
+#include <sys/ioctl.h>\r
+#include <sys/inotify.h>\r
+#include <sys/poll.h>\r
+#include <linux/input.h>\r
+#include <linux/hidraw.h>\r
+#include <errno.h>\r
+#include <time.h>\r
+#include <unistd.h>\r
+\r
+#include <pthread.h>\r
+\r
+\r
+#include "voice_hidraw.h"\r
+#include "bee_settings.h"\r
+#include "get_voice_app.h"\r
+#include "sbc.h"\r
+#include "voice_uipc.h"\r
+#include "config.h"\r
+\r
+#define RAW_DATA_PATH "/data/vr/raw_data"\r
+static int file_counter = 0;\r
+int raw_fd;\r
+int gSocket_Running = 0;\r
+int gTarget_fd = 0;\r
+\r
+\r
+\r
+typedef struct {\r
+    int vid;\r
+    int pid;\r
+    int vers;\r
+    unsigned char voice_key_reportID;\r
+    unsigned char voice_data_reportID;\r
+    unsigned char voice_cmd_reportID;\r
+    int voice_keypress_data_len;\r
+    unsigned char *voice_keypress_data;\r
+    int voice_keyrelease_data_len;\r
+    unsigned char *voice_keyrelease_data;\r
+    int decode_type;\r
+    int data_mask;\r
+    int autocmd;\r
+    \r
+}VOICE_SETTING;\r
+\r
+static struct pollfd *ufds;\r
+static char **device_names;\r
+static int nfds;\r
+\r
+static int *unused_bt_hid_fds;\r
+static int nunusedfds;\r
+static char **unused_device_names;\r
+\r
+\r
+VOICE_SETTING global_voice_setting;\r
+pthread_mutex_t mutex_voice_settings;\r
+\r
+int frame_counter = 0;\r
+\r
+int set_rcu_info(int vid, int pid, int vers) {\r
+    pthread_mutex_lock(&mutex_voice_settings);\r
+    if(vid != -1)\r
+        global_voice_setting.vid = vid;\r
+\r
+    if(pid != -1)\r
+        global_voice_setting.pid = pid;\r
+\r
+    if(vers != -1)\r
+        global_voice_setting.vers = vers;\r
+\r
+    pthread_mutex_unlock(&mutex_voice_settings);\r
+\r
+    return 0;\r
+}\r
+\r
+int set_voice_data_reportID(unsigned char reportID) {\r
+    pthread_mutex_lock(&mutex_voice_settings);\r
+    global_voice_setting.voice_data_reportID = reportID;\r
+    pthread_mutex_unlock(&mutex_voice_settings);\r
+    return 0;\r
+}\r
+\r
+int set_voice_cmd_reportID(unsigned char reportID) {\r
+    pthread_mutex_lock(&mutex_voice_settings);\r
+    global_voice_setting.voice_cmd_reportID = reportID;\r
+    pthread_mutex_unlock(&mutex_voice_settings);\r
+    return 0;\r
+}\r
+\r
+int set_voice_key_reportID(unsigned char reportID) {\r
+    pthread_mutex_lock(&mutex_voice_settings);\r
+    global_voice_setting.voice_key_reportID = reportID;\r
+    pthread_mutex_unlock(&mutex_voice_settings);\r
+    return 0;\r
+}\r
+\r
+int set_voice_keypress_data(int len, unsigned char *data) {\r
+    if(len > 0) {\r
+        pthread_mutex_lock(&mutex_voice_settings);\r
+        if(global_voice_setting.voice_keypress_data != NULL) {\r
+            if(global_voice_setting.voice_keypress_data_len < len) {\r
+\r
+                unsigned char *buf = (unsigned char *)realloc(global_voice_setting.voice_keypress_data, len);\r
+                if(buf == NULL) {\r
+                    //log\r
+                    pthread_mutex_unlock(&mutex_voice_settings);\r
+                    error("Failed to realloc for voice_keypress_data");\r
+                    return -1;\r
+                }else {\r
+                    global_voice_setting.voice_keypress_data = buf;\r
+                }\r
+            }\r
+        }else {\r
+            global_voice_setting.voice_keypress_data = (unsigned char *)malloc(len);\r
+            if(global_voice_setting.voice_keypress_data == NULL) {\r
+                //log\r
+                pthread_mutex_unlock(&mutex_voice_settings);\r
+                error("Failed to malloc for voice_keypress_data");\r
+                return -2;\r
+            }\r
+        }\r
+\r
+        memcpy(global_voice_setting.voice_keypress_data, data, len);\r
+        global_voice_setting.voice_keypress_data_len = len;\r
+        pthread_mutex_unlock(&mutex_voice_settings);\r
+        return 0;\r
+    }else {\r
+        warn("len is negative for voice_keypress_data");\r
+        return -3;\r
+    }\r
+}\r
+\r
+int set_voice_keyrelease_data(int len, unsigned char *data) {\r
+    if(len > 0) {\r
+        pthread_mutex_lock(&mutex_voice_settings);\r
+        if(global_voice_setting.voice_keyrelease_data != NULL) {\r
+            if(global_voice_setting.voice_keyrelease_data_len < len) {\r
+                unsigned char *buf = (unsigned char *)realloc(global_voice_setting.voice_keyrelease_data, len);\r
+                if(buf == NULL) {\r
+                    //log\r
+                    pthread_mutex_unlock(&mutex_voice_settings);\r
+                    error("Failed to realloc for voice_keypress_data");\r
+                    return -1;\r
+                }else {\r
+                    global_voice_setting.voice_keyrelease_data = buf;\r
+                }\r
+            }\r
+        }else {\r
+            global_voice_setting.voice_keyrelease_data = (unsigned char *)malloc(len);\r
+            if(global_voice_setting.voice_keyrelease_data == NULL) {\r
+                pthread_mutex_unlock(&mutex_voice_settings);\r
+                error("Failed to malloc for voice_keyrelease_data");\r
+                return -2;\r
+            }\r
+        }\r
+\r
+        memcpy(global_voice_setting.voice_keyrelease_data, data, len);\r
+        global_voice_setting.voice_keyrelease_data_len = len;\r
+        pthread_mutex_unlock(&mutex_voice_settings);\r
+        return 0;\r
+    }else {\r
+        //log\r
+        warn("len is negative for voice_keyrelease_data");\r
+        return -3;\r
+    }\r
+}\r
+\r
+int set_encode_type(int type) {\r
+    if(type <= DECODE_TYPE_MAX) {\r
+        pthread_mutex_lock(&mutex_voice_settings);\r
+        global_voice_setting.decode_type = type;\r
+        pthread_mutex_unlock(&mutex_voice_settings);\r
+        return 0;\r
+    }else {\r
+        warn("Unknown Decode Type !!!");\r
+        return -1;\r
+    }\r
+}\r
+\r
+int data_type_mask(int mask) {\r
+    //log\r
+    debug("Set Data Type Mask 0x%04x", mask);\r
+\r
+    pthread_mutex_lock(&mutex_voice_settings);\r
+    \r
+    if(mask & DATA_TYPE_MASK_RAW) {\r
+        global_voice_setting.data_mask = DATA_TYPE_MASK_RAW;\r
+    }else {\r
+        if(mask & DATA_TYPE_MASK_VOICE) {\r
+            global_voice_setting.data_mask |= DATA_TYPE_MASK_VOICE;\r
+        }\r
+    }\r
+\r
+    pthread_mutex_unlock(&mutex_voice_settings);\r
+    return 0;\r
+}\r
+\r
+int set_auto_cmd(int autocmd) {\r
+    pthread_mutex_lock(&mutex_voice_settings);\r
+    if(autocmd == 1) {\r
+        global_voice_setting.autocmd = AUTOCMD_AUTO;\r
+    }else if(autocmd == 2){\r
+        global_voice_setting.autocmd = AUTOCMD_NONE;\r
+    }\r
+    pthread_mutex_unlock(&mutex_voice_settings);\r
+\r
+    return 0;\r
+}\r
+\r
+\r
+\r
+int voice_msbc_init() {\r
+\r
+    int ivalue, i;\r
+   \r
+    voice_loadconfig(CONFIG_PATH);\r
+\r
+    pthread_mutex_lock(&mutex_voice_settings);\r
+    \r
+    memset(&global_voice_setting, 0, sizeof(global_voice_setting));\r
+\r
+    ivalue = voice_get_int_config(CONFIG_GROUP_RCU, CONFIG_ITEM_RCU_VID);\r
+    if(ivalue >= 0) {\r
+        global_voice_setting.vid = ivalue;\r
+        ALOGD("use config VID: %04x", global_voice_setting.vid);\r
+    } else {\r
+        global_voice_setting.vid = BEE_RCU_VID;\r
+        ALOGD("use default VID: %04x", global_voice_setting.vid);\r
+    }\r
+\r
+    ivalue = voice_get_int_config(CONFIG_GROUP_RCU, CONFIG_ITEM_RCU_PID);\r
+    if(ivalue >= 0) {\r
+        global_voice_setting.pid = ivalue;\r
+        ALOGD("use config PID: %04x", global_voice_setting.pid);\r
+    } else {\r
+        global_voice_setting.pid = BEE_RCU_PID;\r
+        ALOGD("use default PID: %04x", global_voice_setting.pid);\r
+    }\r
+\r
+    ivalue = voice_get_int_config(CONFIG_GROUP_RCU, CONFIG_ITEM_RCU_VER);\r
+    if(ivalue >= 0) {\r
+        global_voice_setting.vers = ivalue;\r
+        ALOGD("use config version: %04x", global_voice_setting.vers);\r
+    } else {\r
+        global_voice_setting.vers = BEE_RCU_VERSION;\r
+        ALOGD("use default VERSION: %04x", global_voice_setting.vers);\r
+    }\r
+\r
+    ivalue = voice_get_int_config(CONFIG_GROUP_REPORTID, CONFIG_ITEM_REPORTID_KEY);\r
+    if(ivalue > 0) {\r
+        global_voice_setting.voice_key_reportID = ivalue & 0xff;\r
+        ALOGD("use config key report id: %02x", global_voice_setting.voice_key_reportID);\r
+    } else {\r
+        global_voice_setting.voice_key_reportID = BEE_VOICEKEY_REPORTID;\r
+        ALOGD("use default key report id: %02x", global_voice_setting.voice_key_reportID);\r
+    }\r
+    \r
+\r
+    ivalue = voice_get_int_config(CONFIG_GROUP_REPORTID, CONFIG_ITEM_REPORTID_DATA);\r
+    if(ivalue > 0) {\r
+        global_voice_setting.voice_data_reportID = ivalue & 0xff;\r
+        ALOGD("use config data report id: %02x", global_voice_setting.voice_data_reportID);\r
+    } else {\r
+        global_voice_setting.voice_data_reportID = BEE_MSBC_VOICEDATA_REPORTID;\r
+        ALOGD("use default data report id: %02x", global_voice_setting.voice_data_reportID);\r
+    }\r
+\r
+    ivalue = voice_get_int_config(CONFIG_GROUP_REPORTID, CONFIG_ITEM_REPORTID_CMD);\r
+    if(ivalue > 0) {\r
+        global_voice_setting.voice_cmd_reportID = ivalue & 0xff;\r
+        ALOGD("use config cmd report id: %02x", global_voice_setting.voice_cmd_reportID);\r
+    } else {\r
+        global_voice_setting.voice_cmd_reportID = BEE_MSBC_VOICECMD_REPORTID;\r
+        ALOGD("use default cmd report id: %02x", global_voice_setting.voice_cmd_reportID);\r
+    }\r
+\r
+    ivalue = voice_get_int_config(CONFIG_GROUP_REPORTVALUE, CONFIG_ITEM_REPORTVALUE_KEYDOWNLEN);\r
+    if(ivalue > 0) {\r
+        global_voice_setting.voice_keypress_data_len = ivalue;\r
+        ALOGD("use config keydown len: %d", global_voice_setting.voice_keypress_data_len);\r
+    } else {\r
+        global_voice_setting.voice_keypress_data_len = BEE_VOICEKEY_LEN;\r
+        ALOGD("use default keydown len: %d", global_voice_setting.voice_keypress_data_len);\r
+    }\r
+\r
+    global_voice_setting.voice_keypress_data = (unsigned char *)malloc(global_voice_setting.voice_keypress_data_len);\r
+    if(global_voice_setting.voice_keypress_data == NULL) {\r
+        //log\r
+        error("failed to get buf for keydown");\r
+        pthread_mutex_unlock(&mutex_voice_settings);\r
+        return -1;\r
+    }else {\r
+        if(ivalue > 0) {\r
+            if(voice_get_byte_array_config(CONFIG_GROUP_REPORTVALUE, CONFIG_ITEM_REPORTVALUE_KEYDOWN,\r
+                global_voice_setting.voice_keypress_data, global_voice_setting.voice_keypress_data_len)\r
+                != global_voice_setting.voice_keypress_data_len) {\r
+                \r
+                global_voice_setting.voice_keypress_data_len = BEE_VOICEKEY_LEN;\r
+                if(ivalue < BEE_VOICEKEY_LEN) {\r
+                    global_voice_setting.voice_keypress_data = (unsigned char *)realloc(global_voice_setting.voice_keypress_data, BEE_VOICEKEY_LEN);\r
+                    if(global_voice_setting.voice_keypress_data == NULL) {\r
+                        error("failed to realloc buf for keydown");\r
+                        pthread_mutex_unlock(&mutex_voice_settings);\r
+                        return -1;\r
+                    }\r
+                }\r
+                memcpy(global_voice_setting.voice_keypress_data, BEE_VOICE_KEYDOWN_DATA, global_voice_setting.voice_keypress_data_len);\r
+                ALOGD("use default keydown data");\r
+            }\r
+        }else {\r
+            memcpy(global_voice_setting.voice_keypress_data, BEE_VOICE_KEYDOWN_DATA, global_voice_setting.voice_keypress_data_len);\r
+            ALOGD("use default keydown data");\r
+        }\r
+        ALOGD("key down data:");\r
+        for(i = 0; i < global_voice_setting.voice_keypress_data_len; i++) {\r
+            ALOGD("data[%d] = %02x", i, *(global_voice_setting.voice_keypress_data + i));\r
+        }\r
+    }\r
+\r
+    ivalue = voice_get_int_config(CONFIG_GROUP_REPORTVALUE, CONFIG_ITEM_REPORTVALUE_KEYUPLEN);\r
+    if(ivalue > 0) {\r
+        global_voice_setting.voice_keyrelease_data_len = ivalue;\r
+        ALOGD("use config keyup len: %d", global_voice_setting.voice_keyrelease_data_len);\r
+    } else {\r
+        global_voice_setting.voice_keyrelease_data_len = BEE_VOICEKEY_LEN;\r
+        ALOGD("use default keyup len: %d", global_voice_setting.voice_keyrelease_data_len);\r
+    }\r
+\r
+    global_voice_setting.voice_keyrelease_data = (unsigned char *)malloc(global_voice_setting.voice_keyrelease_data_len);\r
+    if(global_voice_setting.voice_keyrelease_data == NULL) {\r
+        //log\r
+        error("failed to get buf for keyup");\r
+        pthread_mutex_unlock(&mutex_voice_settings);\r
+        return -1;\r
+    }else {\r
+        if(ivalue > 0) {\r
+            if(voice_get_byte_array_config(CONFIG_GROUP_REPORTVALUE, CONFIG_ITEM_REPORTVALUE_KEYUP,\r
+                global_voice_setting.voice_keyrelease_data, global_voice_setting.voice_keyrelease_data_len)\r
+                != global_voice_setting.voice_keyrelease_data_len) {\r
+                \r
+                global_voice_setting.voice_keyrelease_data_len = BEE_VOICEKEY_LEN;\r
+                if(ivalue < BEE_VOICEKEY_LEN) {\r
+                    global_voice_setting.voice_keyrelease_data = (unsigned char *)realloc(global_voice_setting.voice_keyrelease_data, BEE_VOICEKEY_LEN);\r
+                    if(global_voice_setting.voice_keyrelease_data == NULL) {\r
+                        error("failed to realloc buf for keyup");\r
+                        pthread_mutex_unlock(&mutex_voice_settings);\r
+                        return -1;\r
+                    }\r
+                }\r
+                memcpy(global_voice_setting.voice_keyrelease_data, BEE_VOICE_KEYUP_DATA, global_voice_setting.voice_keyrelease_data_len);\r
+                ALOGD("use default keyup data");\r
+            }\r
+        }else {\r
+            memcpy(global_voice_setting.voice_keyrelease_data, BEE_VOICE_KEYUP_DATA, global_voice_setting.voice_keyrelease_data_len);\r
+            ALOGD("use default keyup data");\r
+        }\r
+        ALOGD("key up data:");\r
+        for(i = 0; i < global_voice_setting.voice_keyrelease_data_len; i++) {\r
+            ALOGD("data[%d] = %02x", i, *(global_voice_setting.voice_keyrelease_data + i));\r
+        }\r
+    }\r
+\r
+    ivalue = voice_get_int_config(CONFIG_GROUP_SETTINGS, CONFIG_ITEM_SETTINGS_DECODETYPE);\r
+    if(ivalue > 0) {\r
+        global_voice_setting.decode_type = ivalue;\r
+        ALOGD("use config decode type: %d", global_voice_setting.decode_type);\r
+    } else {\r
+        global_voice_setting.decode_type = DECODE_TYPE_MSBC;\r
+        ALOGD("use default decode type: %d", global_voice_setting.decode_type);\r
+    }\r
+\r
+    ivalue = voice_get_int_config(CONFIG_GROUP_SETTINGS, CONFIG_ITEM_SETTINGS_DATAMASK);\r
+    if(ivalue > 0) {\r
+        global_voice_setting.data_mask = ivalue;\r
+        ALOGD("use config data mask: %d", global_voice_setting.data_mask);\r
+    } else {\r
+        global_voice_setting.data_mask = DATA_TYPE_MASK_VOICE;\r
+        ALOGD("use default decode type: %d", global_voice_setting.data_mask);\r
+    }\r
+\r
+    ivalue = voice_get_int_config(CONFIG_GROUP_SETTINGS, CONFIG_ITEM_SETTINGS_AUTOCMD);\r
+    if(ivalue > 0) {\r
+        global_voice_setting.autocmd = ivalue;\r
+        ALOGD("use config decode type: %d", global_voice_setting.autocmd);\r
+    } else {\r
+        global_voice_setting.autocmd = AUTOCMD_AUTO;\r
+        ALOGD("use default decode type: %d", global_voice_setting.autocmd);\r
+    }\r
+\r
+    pthread_mutex_unlock(&mutex_voice_settings);\r
+    voice_conf_exit();\r
+    return 0;\r
+}\r
+\r
+void voice_open_store_file()\r
+{\r
+    char record_name[50] = {0}; \r
+    sprintf(record_name, "%s%d", RAW_DATA_PATH, file_counter);\r
+\r
+    raw_fd =  open (record_name, O_WRONLY | O_CREAT |O_TRUNC, 0644);\r
+\r
+    if(raw_fd < 0)\r
+    {\r
+        ALOGE("can't open record file:%s ", record_name);\r
+    }\r
+\r
+\r
+       return;\r
+}\r
+\r
+int voice_write_decode_buf(uint8* pu_decode, ssize_t len)\r
+{\r
+    if (raw_fd > 0)\r
+    {\r
+        write (raw_fd, pu_decode, len);\r
+        return 0;\r
+    }\r
+    return -1;\r
+}\r
+\r
+\r
+/**********************************************\r
+*\r
+*   hidraw node related\r
+*\r
+***********************************************/\r
+const char *bus_str(int bus){\r
+    switch (bus) {\r
+        case BUS_USB:\r
+            return "USB";\r
+            \r
+        case BUS_HIL:\r
+            return "HIL";\r
+            \r
+        case BUS_BLUETOOTH:\r
+            return "Bluetooth";\r
+\r
+        case BUS_VIRTUAL:\r
+            return "Virtual";\r
+                \r
+        default:\r
+            return "Other";\r
+    }\r
+}\r
+    \r
+static int get_hidraw_info(int fd)\r
+{\r
+    int i, res, desc_size = 0;\r
+    char buf[256];\r
+    struct hidraw_report_descriptor rpt_desc;\r
+    struct hidraw_devinfo info;\r
+    \r
+    memset(&rpt_desc, 0x0, sizeof(rpt_desc));\r
+    memset(&info, 0x0, sizeof(info));\r
+    memset(buf, 0x0, sizeof(buf));\r
+    debug("-----------------------------------------------\n");\r
+    \r
+    /* Get Raw Name */\r
+    res = ioctl(fd, HIDIOCGRAWNAME(256), buf);\r
+    if (res < 0)\r
+        perror("HIDIOCGRAWNAME");\r
+    else\r
+        debug("Raw Name: %s\n", buf);\r
+    /* Get Physical Location */\r
+    res = ioctl(fd, HIDIOCGRAWPHYS(256), buf);\r
+    if (res < 0)\r
+        perror("HIDIOCGRAWPHYS");\r
+    else\r
+        debug("Raw Phys: %s\n", buf);\r
+    /* Get Raw Info */\r
+    res = ioctl(fd, HIDIOCGRAWINFO, &info);\r
+    if (res < 0) {\r
+        perror("HIDIOCGRAWINFO");\r
+    } else {\r
+        debug("Raw Info:");\r
+        debug(" bustype: %d (%s)", info.bustype, bus_str(info.bustype));\r
+        debug(" vendor: 0x%04x", info.vendor);\r
+        debug(" product: 0x%04x\n", info.product);\r
+    }\r
+    /* Get Report Descriptor Size */\r
+    res = ioctl(fd, HIDIOCGRDESCSIZE, &desc_size);\r
+    if (res < 0)\r
+       perror("HIDIOCGRDESCSIZE");\r
+    else\r
+        debug("Report Descriptor Size: %d\n", desc_size);\r
+    /* Get Report Descriptor */\r
+    rpt_desc.size = desc_size;\r
+    res = ioctl(fd, HIDIOCGRDESC, &rpt_desc);\r
+    if (res < 0) {\r
+        perror("HIDIOCGRDESC");\r
+    } else {\r
+        debug("Report Descriptor:");\r
+        for (i = 0; i < rpt_desc.size; i++)\r
+        {\r
+            if((i%16)==0)\r
+                debug("\n");\r
+            debug("%02x ", rpt_desc.value[i]);\r
+        }\r
+        debug("\n");\r
+    }\r
+    info("-----------------------------------------------\n");\r
+    \r
+    return 0;\r
+}\r
+\r
+static int send_message(int fd, unsigned char * buf, int len)\r
+{\r
+    int res = 0;\r
+    res = write(fd, buf, len);\r
+    debug("send_message res=%d\n",res);\r
+    return res;\r
+}\r
+\r
+static void process_voice_data(unsigned char reportID, unsigned char *buf, int len) {\r
+    int ret = -1;\r
+    int offset = 0;\r
+    int i;\r
+    int decode_len = 0;\r
+\r
+    unsigned char output_buf[1024] = {0x00};\r
+\r
+    //debug("reportID=%d, decode_type=%d, global_reportID=%d, len=%d", \r
+        //reportID, global_voice_setting.decode_type, global_voice_setting.voice_data_reportID, len);\r
+\r
+    if(global_voice_setting.decode_type == DECODE_TYPE_MSBC) {\r
+        while(offset + BEE_MSBC_FRAME_SIZE <= len) {\r
+            //debug("offset is %d now, len is %d", offset, len);\r
+            ret = RS_deal_voice_stream_data(buf + offset, BEE_MSBC_FRAME_SIZE, output_buf, 1024, &decode_len);\r
+            if(ret < 0) {\r
+                offset++;\r
+            }else {\r
+                UIPC_Send_noblock(UIPC_CH_ID_VOICE_DATA, 0, output_buf, decode_len);\r
+                offset += BEE_MSBC_FRAME_SIZE;\r
+            }\r
+        }\r
+    }else if(global_voice_setting.decode_type == DECODE_TYPE_SBC) {\r
+        decode_len = 1024;\r
+        while(offset + BEE_SBC_FRAME_SIZE <= len) {\r
+            ret = sbcDecode(buf + offset, BEE_SBC_FRAME_SIZE, output_buf, &decode_len);\r
+            if(ret < 0) {\r
+                debug("fail to decode: %d", ret);\r
+                offset++;\r
+            }else {\r
+                UIPC_Send_noblock(UIPC_CH_ID_VOICE_DATA, 0, output_buf, decode_len);\r
+                offset += BEE_SBC_FRAME_SIZE;\r
+            }\r
+        }\r
+    }\r
+}\r
+\r
+static int read_message(int fd)\r
+{\r
+    unsigned char buf[4096];\r
+    int res,i;\r
+\r
+    unsigned char start_rec_command[] = {global_voice_setting.voice_cmd_reportID, 0x01};\r
+    unsigned char stop_rec_command[] = {global_voice_setting.voice_cmd_reportID, 0x00};\r
+    static int voice_kpressed = 0;\r
+\r
+/*\r
+    struct hidraw_devinfo info;\r
\r
+    res = ioctl(fd, HIDIOCGRAWINFO, &info);\r
+    if (res < 0) {\r
+        perror("HIDIOCGRAWINFO");\r
+    }\r
+*/\r
+\r
+    //if( (info.vendor==global_voice_setting.vid) && (info.product==global_voice_setting.pid) )\r
+    //{\r
+        res = read(fd, buf, sizeof(buf));\r
+        debug("read buffer res: %04x", res);\r
+        if(res > 0)\r
+        {\r
+            //debug("Receive From :%04x,%04x number: %d", info.vendor, info.product, res);\r
+            if( (global_voice_setting.data_mask & DATA_TYPE_MASK_RAW) == DATA_TYPE_MASK_RAW) {\r
+                //just callback and return\r
+                UIPC_Send_noblock(UIPC_CH_ID_VOICE_DATA, 0, buf + 1, res - 1);\r
+                return 0;\r
+            }else if( (global_voice_setting.data_mask & DATA_TYPE_MASK_VOICE) == DATA_TYPE_MASK_VOICE) {\r
+\r
+                if((voice_kpressed == 0) && (buf[0] == global_voice_setting.voice_key_reportID) && \r
+                    (res == global_voice_setting.voice_keypress_data_len + 1) && \r
+                    (memcmp(buf + 1, global_voice_setting.voice_keypress_data, global_voice_setting.voice_keypress_data_len) == 0))\r
+                {\r
+                    //debug("voice key pressed");\r
+                    if(global_voice_setting.autocmd == AUTOCMD_AUTO) {\r
+                        RS_voice_app_create_output();\r
+                        RS_voice_app_create_origin_output();\r
+                        voice_open_store_file();\r
+\r
+                        //send_message(fd, start_rec_command,sizeof(start_rec_command));\r
+                        voice_kpressed = 1;\r
+                        frame_counter = 0;\r
+                    }\r
+                    return 0;\r
+                }\r
+\r
+                // when voice key is released\r
+                if ((voice_kpressed == 1) && (buf[0] == global_voice_setting.voice_key_reportID) && \r
+                    (res == global_voice_setting.voice_keyrelease_data_len + 1) && \r
+                    (memcmp(buf + 1, global_voice_setting.voice_keyrelease_data, global_voice_setting.voice_keyrelease_data_len) == 0))\r
+                {\r
+                    //debug("voice key relesed");\r
+\r
+                    if(global_voice_setting.autocmd == AUTOCMD_AUTO) {\r
+                        RS_stop_voice_stream_data();\r
+                        //send_message(fd, stop_rec_command,sizeof(stop_rec_command));\r
+                        voice_kpressed = 0;\r
+                        debug("total frame: %d", frame_counter);\r
+                        close(raw_fd);\r
+                        file_counter++;\r
+                        raw_fd = -1;\r
+                    }\r
+                    return 0;\r
+                }\r
+\r
+                // store voice data\r
+                if ((voice_kpressed == 1 ) && (buf[0] == global_voice_setting.voice_data_reportID))\r
+                {\r
+                    //debug("deal with voice data");\r
+                    process_voice_data(buf[0], buf + 1, res-1);\r
+                    voice_write_decode_buf(buf + 1, res - 1);\r
+                    frame_counter++;\r
+                    return 0;\r
+                }\r
+            }\r
+        }else {\r
+            warn("Read fd %d failed: %s", fd, strerror(errno));\r
+            return -1;\r
+        }\r
+\r
+    //}\r
+\r
+    return 0;\r
+}\r
+\r
+int get_dev_vid_pid_info(int fd, short* vid, short* pid) {\r
+    int res = -1;\r
+    struct hidraw_devinfo info;\r
+\r
+    memset(&info, 0x0, sizeof(info));\r
+\r
+    res = ioctl(fd, HIDIOCGRAWINFO, &info);\r
+    if (res < 0) {\r
+        debug("failed to get HIDIOCGRAWINFO");\r
+    } else {\r
+        //debug("Raw Info:");\r
+        //debug(" bustype: %d (%s)", info.bustype, bus_str(info.bustype));\r
+        debug(" vendor: 0x%04x, product: 0x%04x", info.vendor, info.product);\r
+        *vid = info.vendor;\r
+        *pid = info.product;\r
+        res = 1;\r
+    }\r
+    return res;\r
+}\r
+\r
+static int open_device(const char *device)\r
+{\r
+    int version;\r
+    int fd;\r
+    int clkid = CLOCK_MONOTONIC;\r
+    struct pollfd *new_ufds;\r
+    int *unfds;\r
+    char **new_device_names;\r
+    char **new_unused_device_names;\r
+    char name[80];\r
+    char location[80];\r
+    char idstr[80];\r
+    struct input_id id;\r
+    int res = -1;\r
+    struct hidraw_devinfo info;\r
+\r
+    fd = open(device, O_RDWR);\r
+    if(fd < 0) {\r
+        debug("could not open %s, %s\n", device, strerror(errno));\r
+        return -1;\r
+    }\r
+    debug("new fd is %d", fd);\r
+\r
+    res = ioctl(fd, HIDIOCGRAWINFO, &info);\r
+    if(res < 0) {\r
+        debug("failed to get hidraw_devinfo, add for now");\r
+    }else if(info.bustype != BUS_BLUETOOTH){\r
+        debug("ingore this device");\r
+        close(fd);\r
+        return -1;\r
+    }else if((info.vendor != global_voice_setting.vid) || (info.product != global_voice_setting.pid)) {\r
+        //res = unlink(fd);\r
+        debug("Not the device we care, add to unused fds");\r
+        unfds = realloc(unused_bt_hid_fds, sizeof(unused_bt_hid_fds[0]) * (nunusedfds + 1));\r
+        if(unfds == NULL) {\r
+            error("unused fds: out of memory");\r
+            return -1;\r
+        }\r
+\r
+        new_unused_device_names = realloc(unused_device_names, sizeof(unused_device_names[0]) * (nunusedfds + 1));\r
+        if(new_unused_device_names == NULL) {\r
+            error("unused device_names: out of memory");\r
+            return -1;\r
+        }\r
+\r
+        unused_bt_hid_fds = unfds;\r
+        unused_device_names = new_unused_device_names;\r
+        \r
+        unused_bt_hid_fds[nunusedfds] = fd;\r
+        unused_device_names[nunusedfds] = strdup(device);\r
+        nunusedfds++;\r
+        return 0; \r
+    }\r
+\r
+    new_ufds = realloc(ufds, sizeof(ufds[0]) * (nfds + 1));\r
+    if(new_ufds == NULL) {\r
+        error("out of memory\n");\r
+        return -1;\r
+    }\r
+\r
+    ufds = new_ufds;\r
+    new_device_names = realloc(device_names, sizeof(device_names[0]) * (nfds + 1));\r
+    if(new_device_names == NULL) {\r
+        debug("out of memory\n");\r
+        return -1;\r
+    }\r
+    device_names = new_device_names;\r
+    //get_hidraw_info(fd);\r
+    ufds[nfds].fd = fd;\r
+    ufds[nfds].events = POLLIN;\r
+    device_names[nfds] = strdup(device);\r
+    nfds++;\r
+\r
+    return 0;\r
+}\r
+\r
+int close_device(const char *device)\r
+{\r
+    int i;\r
+    for(i = 1; i < nfds; i++) {\r
+        if(strcmp(device_names[i], device) == 0) {\r
+            int count = nfds - i - 1;\r
+            debug("remove device %d: %s\n", i, device);\r
+            free(device_names[i]);\r
+            memmove(device_names + i, device_names + i + 1, sizeof(device_names[0]) * count);\r
+            close(ufds[i].fd);\r
+            memmove(ufds + i, ufds + i + 1, sizeof(ufds[0]) * count);\r
+            nfds--;\r
+            return 0;\r
+        }\r
+    }\r
+\r
+    for(i = 0; i < nunusedfds; i++) {\r
+        if(strcmp(unused_device_names[i], device) == 0) {\r
+            int count = nunusedfds - i;\r
+            debug("remove unused device %d: %s\n", i, device);\r
+            free(unused_device_names[i]);\r
+            memmove(unused_device_names + i, unused_device_names + i + 1, sizeof(unused_device_names[0]) * count);\r
+            close(unused_bt_hid_fds[i]);\r
+            memmove(unused_bt_hid_fds + i, unused_bt_hid_fds + i + 1, sizeof(unused_bt_hid_fds[0]) * count);\r
+            nunusedfds--;\r
+            return 0;\r
+        }\r
+    }\r
+    \r
+    error("remote device: %s not found\n", device);\r
+    return -1;\r
+}\r
+\r
+static int read_notify(const char *dirname, int nfd)\r
+{\r
+    int res;\r
+    char devname[PATH_MAX];\r
+    char *filename;\r
+    char event_buf[512];\r
+    int event_size;\r
+    int event_pos = 0;\r
+    struct inotify_event *event;\r
+\r
+    res = read(nfd, event_buf, sizeof(event_buf));\r
+    if(res < (int)sizeof(*event)) {\r
+        if(errno == EINTR)\r
+            return 0;\r
+        error("could not get event, %s\n", strerror(errno));\r
+        return 1;\r
+    }\r
+    //printf("got %d bytes of event information\n", res);\r
+\r
+    strcpy(devname, dirname);\r
+    filename = devname + strlen(devname);\r
+    *filename++ = '/';\r
+\r
+    while(res >= (int)sizeof(*event)) {\r
+        event = (struct inotify_event *)(event_buf + event_pos);\r
+        debug("%d: %08x \"%s\"\n", event->wd, event->mask, event->len ? event->name : "");\r
+        if((event->len)&&(memcmp(event->name, "hidraw", strlen("hidraw"))==0)) {\r
+            debug("read_notify: %d: %08x \"%s\"\n", event->wd, event->mask, event->len ? event->name : "");\r
+            strcpy(filename, event->name);\r
+            if(event->mask & IN_CREATE) {\r
+                open_device(devname);\r
+            }\r
+            else {\r
+                close_device(devname);\r
+            }\r
+        }\r
+        event_size = sizeof(*event) + event->len;\r
+        res -= event_size;\r
+        event_pos += event_size;\r
+    }\r
+    return 0;\r
+}\r
+\r
+\r
+static int scan_dir(const char *dirname)\r
+{\r
+    char devname[PATH_MAX];\r
+    char *filename;\r
+    DIR *dir;\r
+    struct dirent *de;\r
+    dir = opendir(dirname);\r
+    if(dir == NULL)\r
+        return -1;\r
+    strcpy(devname, dirname);\r
+    filename = devname + strlen(devname);\r
+    *filename++ = '/';\r
+    while((de = readdir(dir))) {\r
+        if(de->d_name[0] == '.' &&\r
+           (de->d_name[1] == '\0' ||\r
+            (de->d_name[1] == '.' && de->d_name[2] == '\0')))\r
+            continue;\r
+        if(memcmp(de->d_name,"hidraw",strlen("hidraw")))\r
+            continue;\r
+        strcpy(filename, de->d_name);\r
+        //debug("scan_dir: %s\n",devname);\r
+        open_device(devname);\r
+    }\r
+    closedir(dir);\r
+    return 0;\r
+}\r
+\r
+static void voice_ctrl_recv(void)\r
+{\r
+    unsigned char cmd[256], opcode = 0xFF;\r
+    int n, i;\r
+\r
+    n = UIPC_Read(UIPC_CH_ID_VOICE_CTRL, NULL, cmd, 256);\r
+\r
+    /* detach on ctrl channel means audioflinger process was terminated */\r
+    if (n == 0)\r
+    {\r
+        debug("CTRL CH DETACHED");\r
+        //the ctrl channel will re-open automatically\r
+        UIPC_Close(UIPC_CH_ID_VOICE_CTRL);\r
+        return;\r
+    }\r
+\r
+    debug("receive voice-ctrl-cmd read num_of_data = %d ", n);\r
+    for (i=0; i< n; i++)\r
+        info("data[%d] = %d ", i, cmd[i]);\r
+    //receive start or stop cmd from service\r
+    if( cmd[0] <= OPCODE_MAX)\r
+    {\r
+        opcode = cmd[0];\r
+    }\r
+    else\r
+    {\r
+        //clear the memory\r
+        UIPC_Ioctl(UIPC_CH_ID_VOICE_CTRL, UIPC_REQ_RX_FLUSH,NULL);\r
+        info("it is wrong cmd send from service");\r
+    }\r
+\r
+    info("opcode = %d",opcode);\r
+    switch(opcode)\r
+    {\r
+        case OPCODE_SETTING_RESET:              //0   cmd(1)\r
+            break;\r
+\r
+        case OPCODE_VOICE_START_CMD:            //1   cmd(1)\r
+            debug("start, len=%d", n);\r
+            break;\r
+\r
+        case OPCODE_VOICE_STOP_CMD:             //2   cmd(1)\r
+            debug("stop, len=%d", n);\r
+            break;\r
+\r
+        case OPCODE_SET_RCU_INFO:               //3   cmd(1) + vid(2) + pid(2) + vers(2)\r
+            if(n == 7) {\r
+                int vid = (cmd[1] << 8) + cmd[2];\r
+                int pid = (cmd[3] << 8) + cmd[4];\r
+                int vers = (cmd[5] << 8) + cmd[6];\r
+                set_rcu_info(vid,pid,vers);\r
+            }\r
+            break;\r
+\r
+        case OPCODE_SET_VOICE_DATA_REPORT_ID:   //4   cmd(1) + reportID(1)\r
+            if(n == 2) {\r
+                set_voice_data_reportID(cmd[1]);\r
+            }\r
+            break;\r
+\r
+        case OPCODE_SET_VOICE_CMD_REPORT_ID:    //5   cmd(1) + reportID(1)\r
+            if(n == 2) {\r
+                set_voice_cmd_reportID(cmd[1]);\r
+            }\r
+            break;\r
+\r
+        case OPCODE_SET_VOICE_KEY_REPORT_ID:    //6   cmd(1) + reportID(1)\r
+            if(n == 2) {\r
+                set_voice_key_reportID(cmd[1]);\r
+            }\r
+            break;\r
+\r
+        case OPCODE_SET_VOICE_KEYPRESS_DATA:    //7   cmd(1) + len(1) + data(n)\r
+            if(n > 2) {\r
+                int len = cmd[1];\r
+                set_voice_keypress_data(len, cmd + 2);\r
+            }\r
+            break;\r
+\r
+        case OPCODE_SET_VOICE_KEYRELEASE_DATA:  //8   cmd(1) + len(1) + data(n)\r
+            if(n > 2) {\r
+                int len = cmd[1];\r
+                set_voice_keyrelease_data(len, cmd + 2);\r
+            }\r
+            break;\r
+\r
+        case OPCODE_SET_VOICE_STARTCMD_DATA:    //9   cmd(1) + len(1) + data(n)\r
+            debug("set voice start data, len=%d", cmd[1]);\r
+            break;\r
+\r
+        case OPCODE_SET_VOICE_STOPCMD_DATA:     //10  cmd(1) + len(1) + data(n)\r
+            debug("set voice stop data, len=%d", cmd[1]);\r
+            break;\r
+\r
+        case OPCODE_SET_ENCODE_TYPE:            //11  cmd(1) + type(1)\r
+            if(n == 2) {\r
+                set_encode_type(cmd[1]);\r
+            }\r
+            break;\r
+\r
+        case OPCODE_SET_DATA_TYPE_MASK:         //12  cmd(1) + type(1)\r
+            debug("set type mask: 0x%02x", cmd[1]);\r
+            break;\r
+\r
+        case OPCODE_SET_AUTO_CMD:               //13  cmd(1) + auto(1)\r
+            if(n == 2) {\r
+                set_auto_cmd(cmd[1]);\r
+            }\r
+            break;\r
+\r
+        case OPCODESEND_HIDRAW_DATA:            //14  cmd(1) + reportID(1) + len(1) + data(n)\r
+            debug("send raw data, reportID=0x%02x, len=0x%02x", cmd[1], cmd[2]);\r
+            break;\r
+\r
+        case OPCODE_EXIT:\r
+            debug("exit");\r
+            gSocket_Running = 0;\r
+    }\r
+\r
+    info("voice-ctrl-cmd DOWN!");\r
+}\r
+\r
+static void voice_data_recv(void)\r
+{\r
+    unsigned char cmd[256], opcode = 0xFF;\r
+    int n, i;\r
+\r
+    n = UIPC_Read(UIPC_CH_ID_VOICE_DATA, NULL, cmd, 256);\r
+\r
+    /* detach on ctrl channel means audioflinger process was terminated */\r
+    if (n == 0)\r
+    {\r
+        debug("DATA CH DETACHED");\r
+        //the ctrl channel will re-open automatically\r
+        UIPC_Close(UIPC_CH_ID_VOICE_DATA);\r
+        return;\r
+    }\r
+\r
+    debug("receive voice-data read num_of_data = %d ", n);\r
+}\r
+\r
+\r
+static void ctrl_socket_cb(tUIPC_CH_ID ch_id, tUIPC_EVENT event)\r
+{\r
+\r
+    switch(event)\r
+    {\r
+        case UIPC_OPEN_EVT:\r
+            /*\r
+                in certain case, hid status msg must be sent upon ctrl chan opened\r
+             */\r
+            debug("Jim@control_socket_cb: sending hid status msg upon open");\r
+            break;\r
+\r
+        case UIPC_CLOSE_EVT:\r
+            if (gSocket_Running) {\r
+                debug("jim@control_socket_cb: re-open ctrl chan");\r
+                UIPC_Open(UIPC_CH_ID_VOICE_CTRL, ctrl_socket_cb);\r
+            }\r
+            break;\r
+\r
+        case UIPC_RX_DATA_EVT:\r
+            info("btif_voice_ctrl_cb, the event is UIPC_RX_DATA_EVT");\r
+\r
+        case UIPC_RX_DATA_READY_EVT:\r
+            voice_ctrl_recv();\r
+            break;\r
+\r
+        default :\r
+            info("### VOICE-CTRL-CHANNEL EVENT %d NOT HANDLED ###", event);\r
+            break;\r
+    }\r
+}\r
+\r
+static void data_socket_cb(tUIPC_CH_ID ch_id, tUIPC_EVENT event)\r
+{\r
+\r
+    debug("data_socket_cb");\r
+    switch(event)\r
+    {\r
+        case UIPC_OPEN_EVT:\r
+            debug("Jim@data_socket_cb: sending hid status msg upon open");\r
+            break;\r
+\r
+        case UIPC_CLOSE_EVT:\r
+            if (gSocket_Running) {\r
+                debug("jim@data_socket_cb: re-open data chan");\r
+                UIPC_Open(UIPC_CH_ID_VOICE_DATA, data_socket_cb);\r
+            }\r
+            break;\r
+\r
+        case UIPC_RX_DATA_EVT:\r
+            info("data_socket_cb, the event is UIPC_RX_DATA_EVT");\r
+\r
+        case UIPC_RX_DATA_READY_EVT:\r
+            voice_data_recv();\r
+            info("data_socket_cb, the event is UIPC_RX_DATA_READY_EVT");\r
+            break;\r
+\r
+        default :\r
+            info("### VOICE-DATA-CHANNEL EVENT %d NOT HANDLED ###", event);\r
+            break;\r
+    }\r
+}\r
+\r
+\r
+\r
+int init(void) {\r
+\r
+    pthread_mutex_init(&mutex_voice_settings, NULL);\r
+    voice_msbc_init();\r
+    sbcInitDecoder();\r
+\r
+    gSocket_Running = 1;\r
+    UIPC_Init(NULL);\r
+    UIPC_Open(UIPC_CH_ID_VOICE_CTRL, ctrl_socket_cb);\r
+    UIPC_Open(UIPC_CH_ID_VOICE_DATA, data_socket_cb);\r
+\r
+    return 0;\r
+}\r
+\r
+void cleanup(void) {\r
+\r
+    gSocket_Running = 0;\r
+    UIPC_Close(UIPC_CH_ID_VOICE_DATA);\r
+    UIPC_Close(UIPC_CH_ID_VOICE_CTRL);\r
+\r
+    pthread_mutex_lock(&mutex_voice_settings);\r
+    \r
+    \r
+    if(global_voice_setting.voice_keypress_data != NULL)\r
+        free(global_voice_setting.voice_keypress_data);\r
+\r
+    if(global_voice_setting.voice_keyrelease_data != NULL)\r
+        free(global_voice_setting.voice_keyrelease_data);\r
+\r
+    pthread_mutex_unlock(&mutex_voice_settings);\r
+    //release other resources here\r
+}\r
+\r
+\r
+int main(void) {\r
+    const char *device_path = "/dev";\r
+    int res;\r
+    int i;\r
+\r
+    init();\r
+\r
+    nfds = 1;\r
+    ufds = calloc(1, sizeof(ufds[0]));\r
+    ufds[0].fd = inotify_init();\r
+    ufds[0].events = POLLIN;\r
+\r
+    res = inotify_add_watch(ufds[0].fd, device_path, IN_DELETE | IN_CREATE);\r
+    if(res < 0) {\r
+        error("could not add watch for %s, %s\n", device_path, strerror(errno));\r
+        return -1;\r
+    }\r
+\r
+    res = scan_dir(device_path);\r
+    if(res < 0) {\r
+        error("scan dir failed for %s\n", device_path);\r
+        return -2;\r
+    }\r
+\r
+    while(gSocket_Running) {\r
+        poll(ufds, nfds, -1);\r
+        if(ufds[0].revents & POLLIN) {\r
+            //debug("new notify event!!!");\r
+            read_notify(device_path, ufds[0].fd);\r
+        }\r
+\r
+        for(i = 1; i < nfds; i++) {\r
+            if(ufds[i].revents) {\r
+                /*\r
+                //debug("new message event, fd = %d, event = %04x.", ufds[i].fd, ufds[i].revents);\r
+                if((ufds[i].revents & POLLHUP) && (ufds[i].revents & POLLERR)) {\r
+                    debug("close, fd=%d, events=0x%04x", ufds[i].fd, ufds[i].revents);\r
+                    close(ufds[i].fd);\r
+                 \r
+                }else if(ufds[i].revents & POLLIN) {\r
+                    //debug("new message event!!!");\r
+                    read_message(ufds[i].fd);\r
+                }\r
+                */\r
+                if(ufds[i].revents & POLLIN) {\r
+                    //debug("new message event!!!");\r
+                    read_message(ufds[i].fd);\r
+                }\r
+            }\r
+        }\r
+    }\r
+    cleanup();\r
+    \r
+    return 0;\r
+\r
+}\r
+\r
index 9ea31d699276533b404604bbeab52606c05e80ca..7e96138351ead31b6760a2b495a7ff85cad7c3be 100755 (executable)
@@ -1,55 +1,55 @@
-#ifndef VOICE_HIDRAW_H
-#define VOICE_HIDRAW_H
-
-#include <cutils/log.h>
-
-
-#define DECODE_TYPE_MSBC 1
-#define DECODE_TYPE_SBC 2
-#define DECODE_TYPE_MAX 2
-
-#define DATA_TYPE_MASK_VOICE (0x01)
-#define DATA_TYPE_MASK_RAW (0x02)
-
-#define AUTOCMD_AUTO 1
-#define AUTOCMD_NONE 2
-
-#define SW_VERSION (0x0000)
-
-#define CONFIG_PATH "/system/etc/hidraw_setting"
-
-
-#define warn(fmt, ...) ALOGW ("## WARNING : %s(L%d):  " fmt "##",__FUNCTION__, __LINE__, ## __VA_ARGS__)
-#define error(fmt, ...) ALOGE ("## ERROR : %s(L%d): " fmt "##",__FUNCTION__, __LINE__, ## __VA_ARGS__)
-
-#define info(fmt, ...)  ALOGI ("%s(L%d): " fmt,__FUNCTION__, __LINE__,  ## __VA_ARGS__)
-#define debug(fmt, ...) ALOGD ("%s(L%d): " fmt,__FUNCTION__, __LINE__,  ## __VA_ARGS__)
-
-
-#define VOICE_DATA_PATH     "/data/misc/bluedroid/.voice_data"
-#define VOICE_CTRL_PATH     "/data/misc/bluedroid/.voice_ctrl"
-
-
-
-//supported opcode
-
-#define OPCODE_SETTING_RESET                0   //cmd(1)
-#define OPCODE_VOICE_START_CMD              1   //cmd(1)
-#define OPCODE_VOICE_STOP_CMD               2   //cmd(1)
-#define OPCODE_SET_RCU_INFO                 3   //cmd(1) + vid(2) + pid(2) + vers(2)
-#define OPCODE_SET_VOICE_DATA_REPORT_ID     4   //cmd(1) + reportID(1)
-#define OPCODE_SET_VOICE_CMD_REPORT_ID      5   //cmd(1) + reportID(1)
-#define OPCODE_SET_VOICE_KEY_REPORT_ID      6   //cmd(1) + reportID(1)
-#define OPCODE_SET_VOICE_KEYPRESS_DATA      7   //cmd(1) + len(1) + data(n)
-#define OPCODE_SET_VOICE_KEYRELEASE_DATA    8   //cmd(1) + len(1) + data(n)
-#define OPCODE_SET_VOICE_STARTCMD_DATA      9   //cmd(1) + len(1) + data(n)
-#define OPCODE_SET_VOICE_STOPCMD_DATA       10  //cmd(1) + len(1) + data(n)
-#define OPCODE_SET_ENCODE_TYPE              11  //cmd(1) + type(1)
-#define OPCODE_SET_DATA_TYPE_MASK           12  //cmd(1) + type(1)
-#define OPCODE_SET_AUTO_CMD                 13  //cmd(1) + auto(1)
-#define OPCODESEND_HIDRAW_DATA              14  //cmd(1) + reportID(1) + len(1) + data(n)
-#define OPCODE_EXIT                         15  //cmd(1) 
-
-#define OPCODE_MAX                          15
-
-#endif
+#ifndef VOICE_HIDRAW_H\r
+#define VOICE_HIDRAW_H\r
+\r
+#include <cutils/log.h>\r
+\r
+\r
+#define DECODE_TYPE_MSBC 1\r
+#define DECODE_TYPE_SBC 2\r
+#define DECODE_TYPE_MAX 2\r
+\r
+#define DATA_TYPE_MASK_VOICE (0x01)\r
+#define DATA_TYPE_MASK_RAW (0x02)\r
+\r
+#define AUTOCMD_AUTO 1\r
+#define AUTOCMD_NONE 2\r
+\r
+#define SW_VERSION (0x0000)\r
+\r
+#define CONFIG_PATH "/system/etc/hidraw_setting"\r
+\r
+\r
+#define warn(fmt, ...) ALOGW ("## WARNING : %s(L%d):  " fmt "##",__FUNCTION__, __LINE__, ## __VA_ARGS__)\r
+#define error(fmt, ...) ALOGE ("## ERROR : %s(L%d): " fmt "##",__FUNCTION__, __LINE__, ## __VA_ARGS__)\r
+\r
+#define info(fmt, ...)  ALOGI ("%s(L%d): " fmt,__FUNCTION__, __LINE__,  ## __VA_ARGS__)\r
+#define debug(fmt, ...) ALOGD ("%s(L%d): " fmt,__FUNCTION__, __LINE__,  ## __VA_ARGS__)\r
+\r
+\r
+#define VOICE_DATA_PATH     "/data/misc/bluedroid/.voice_data"\r
+#define VOICE_CTRL_PATH     "/data/misc/bluedroid/.voice_ctrl"\r
+\r
+\r
+\r
+//supported opcode\r
+\r
+#define OPCODE_SETTING_RESET                0   //cmd(1)\r
+#define OPCODE_VOICE_START_CMD              1   //cmd(1)\r
+#define OPCODE_VOICE_STOP_CMD               2   //cmd(1)\r
+#define OPCODE_SET_RCU_INFO                 3   //cmd(1) + vid(2) + pid(2) + vers(2)\r
+#define OPCODE_SET_VOICE_DATA_REPORT_ID     4   //cmd(1) + reportID(1)\r
+#define OPCODE_SET_VOICE_CMD_REPORT_ID      5   //cmd(1) + reportID(1)\r
+#define OPCODE_SET_VOICE_KEY_REPORT_ID      6   //cmd(1) + reportID(1)\r
+#define OPCODE_SET_VOICE_KEYPRESS_DATA      7   //cmd(1) + len(1) + data(n)\r
+#define OPCODE_SET_VOICE_KEYRELEASE_DATA    8   //cmd(1) + len(1) + data(n)\r
+#define OPCODE_SET_VOICE_STARTCMD_DATA      9   //cmd(1) + len(1) + data(n)\r
+#define OPCODE_SET_VOICE_STOPCMD_DATA       10  //cmd(1) + len(1) + data(n)\r
+#define OPCODE_SET_ENCODE_TYPE              11  //cmd(1) + type(1)\r
+#define OPCODE_SET_DATA_TYPE_MASK           12  //cmd(1) + type(1)\r
+#define OPCODE_SET_AUTO_CMD                 13  //cmd(1) + auto(1)\r
+#define OPCODESEND_HIDRAW_DATA              14  //cmd(1) + reportID(1) + len(1) + data(n)\r
+#define OPCODE_EXIT                         15  //cmd(1) \r
+\r
+#define OPCODE_MAX                          15\r
+\r
+#endif\r
index 749617784194c92fa5598c76cbbc2fee3ba61938..da9e082414fb26980277093408ab72ec8a8bcdfc 100755 (executable)
@@ -1,20 +1,20 @@
-[Rcu]
-Vid=005d
-Pid=0002
-Ver=0000
-
-[ReportID]
-Key=1
-Data=5a
-Cmd=5a
-
-[ReportValue]
-KeyDownLen=8
-KeyDown=0,0,3e,0,0,0,0,0;
-KeyUpLen=8
-KeyUp=0,0,3f,0,0,0,0,0;
-
-[Settings]
-DecodeType=1
-DataMask=1
-AutoCmd=1
+[Rcu]\r
+Vid=005d\r
+Pid=0002\r
+Ver=0000\r
+\r
+[ReportID]\r
+Key=1\r
+Data=5a\r
+Cmd=5a\r
+\r
+[ReportValue]\r
+KeyDownLen=8\r
+KeyDown=0,0,3e,0,0,0,0,0;\r
+KeyUpLen=8\r
+KeyUp=0,0,3f,0,0,0,0,0;\r
+\r
+[Settings]\r
+DecodeType=1\r
+DataMask=1\r
+AutoCmd=1
\ No newline at end of file
index fbb1a76172b3928ea582b21fca0b495ad932735c..2b874349b9b8e6add14c8c5a7eecafacebf1df71 100755 (executable)
@@ -384,7 +384,7 @@ static bt_status_t init(rtkbt_callbacks_t* callbacks)
     rtkbt_callbacks = callbacks;
     UIPC_Init(0);
     loadplugins(&rtkbt_api_callbacks);
-    rtkbt_api_Hook(RTKBT_HOOK_ENABLE_BT_COMPLETE, (void *)BT_STATE_ON, 0);
+    //rtkbt_api_Hook(RTKBT_HOOK_ENABLE_BT_COMPLETE, (void *)BT_STATE_ON, 0);
     return BT_STATUS_SUCCESS;
 }
 static void cleanup()
index 3bf5083a2088ba1dbee8dd07b03d050a1130fcd7..01afe699630d69a78f3446df4252dd6e05527cec 100755 (executable)
@@ -123,16 +123,13 @@ static int op(bt_vendor_opcode_t opcode, void *param)
                 int *state = (int *) param;
                 if (*state == BT_VND_PWR_OFF)
                 {
-                    //upio_set_bluetooth_power(UPIO_BT_POWER_OFF);
-                    //usleep(200000);
-                    //BTVNDDBG("set power off and delay 200ms");
+                   upio_set_bluetooth_power(UPIO_BT_POWER_OFF);
+                   usleep(200000);
+                   BTVNDDBG("set power off and delay 200ms");
 
                 }
                 else if (*state == BT_VND_PWR_ON)
                 {
-                    upio_set_bluetooth_power(UPIO_BT_POWER_OFF);
-                    usleep(500000);
-                    BTVNDDBG("set power off and delay 500ms");
                     upio_set_bluetooth_power(UPIO_BT_POWER_ON);
                     usleep(500000);
                     BTVNDDBG("set power on and delay 500ms");
index 360b5c6dfc303e8469e9eec6f64a2dc550b34633..f9914c5423a972fd177859bbb1ed0924139d7b7a 100755 (executable)
@@ -1,5 +1,4 @@
-# this file is auto generated. 
-# RELEASE_TIME: 20161215 17:51:29
+# RELEASE NAME: 20161222_TV_ANDROID_7.x
 # RTKBT_API_VERSION=3.1.1.0
 
 #BOARD_HAVE_BLUETOOTH := true
index 5c3fe939e3b431accd20f81706a92ff27de7a1d0..e67a9cc1e9f35b620ac919dec382f14670b129e8 100755 (executable)
@@ -1,3 +1,4 @@
+# RELEASE NAME: 20161222_TV_ANDROID_7.x
 # Bluetooth Device Name; NULL or comment means "ro.product.model"
 #Name=Realtek Bluetooth
 
index 84793ae4d3a9eb3edfc4fedba773fe856a29d059..de66652e55773d7f6c94f717f9c15a12d2933cd9 100755 (executable)
Binary files a/rtkbt/system/etc/firmware/rtl8723d_config and b/rtkbt/system/etc/firmware/rtl8723d_config differ
index c6bf13c2f3304ebef8128ea7cc6be9e64b1feeda..0e228db068e4ad5e8a8d08f1487400c2bd9207bb 100755 (executable)
Binary files a/rtkbt/system/etc/firmware/rtl8723d_fw and b/rtkbt/system/etc/firmware/rtl8723d_fw differ
index 4f87c30dd01f8b8f415e6cf9f08f2ce9a922dd18..077c4da41356360f71592bad44d5f59ffec4dc7b 100755 (executable)
Binary files a/rtkbt/system/etc/firmware/rtl8723ds_fw and b/rtkbt/system/etc/firmware/rtl8723ds_fw differ
index 2bc8ddfa94380d76bb4192a6b2e11e78170720c8..efbcf53760cfc97d5bc7d214e81e22a01aa65220 100755 (executable)
Binary files a/rtkbt/system/etc/firmware/rtl8821c_config and b/rtkbt/system/etc/firmware/rtl8821c_config differ
index cf0ecd3c6cbd245bba07f0f40d57bdcbc26d8223..7635a6439fec95f8b1cc157a69f405ae59c56ca1 100755 (executable)
Binary files a/rtkbt/system/etc/firmware/rtl8821cs_config and b/rtkbt/system/etc/firmware/rtl8821cs_config differ
index f47e7b53e570b114656afa30d1da31f56d8878ed..0c6dc6f9e483433afd9793d2d9ee7ac3fd046b25 100755 (executable)
Binary files a/rtkbt/system/etc/firmware/rtl8822b_config and b/rtkbt/system/etc/firmware/rtl8822b_config differ
index 0fe0c40b5234ec7804c5a39f1a6eb2d3171dee42..33fd7105e5ff7dfe895afb750f6482aa1390adc4 100755 (executable)
Binary files a/rtkbt/system/etc/firmware/rtl8822bs_config and b/rtkbt/system/etc/firmware/rtl8822bs_config differ