解决YX Audio 卡死的问题
Change-Id: I3b26fd9f8b7bf0200ba1fcf41e4dcf9a46145b6e
diff --git a/mbtk/Make.defines b/mbtk/Make.defines
index ce5ab9f..ddb0420 100755
--- a/mbtk/Make.defines
+++ b/mbtk/Make.defines
@@ -104,6 +104,12 @@
DEFINE += -DMBTK_AF_SUPPORT
endif
+MBTK_YX_SUPPORT=$(shell cat $(ROOT)/config | grep CONFIG_YX_SUPPORT | cut -d '=' -f 2)
+$(info MBTK_YX_SUPPORT=$(MBTK_YX_SUPPORT))
+ifeq ($(MBTK_YX_SUPPORT), y)
+DEFINE += -DMBTK_YX_SUPPORT
+endif
+
MBTK_GNSS_MODE=$(shell cat $(ROOT)/config | grep CONFIG_MBTK_GNSS_MODE | cut -d '=' -f 2)
$(info MBTK_GNSS_MODE=$(MBTK_GNSS_MODE))
ifeq ($(MBTK_GNSS_MODE), gnss_6228)
diff --git a/mbtk/mbtk_lib/src/mbtk_adc.c b/mbtk/mbtk_lib/src/mbtk_adc.c
index dface9f..581bcba 100755
--- a/mbtk/mbtk_lib/src/mbtk_adc.c
+++ b/mbtk/mbtk_lib/src/mbtk_adc.c
@@ -33,7 +33,7 @@
//system("echo 3 > /sys/kernel/debug/adc");
if(!access(ADC_DEVICE_803, R_OK))
{
- LOGI("DEV:%s", ADC_DEVICE_803);
+ //LOGI("DEV:%s", ADC_DEVICE_803);
fd = open(ADC_DEVICE_803, O_RDWR|O_CREAT|O_TRUNC, 0644);
}
else
@@ -104,11 +104,11 @@
}
#else
if(!access(ADC_DEVICE_802, R_OK)) {
- LOGI("DEV:%s", ADC_DEVICE_802);
+ //LOGI("DEV:%s", ADC_DEVICE_802);
fd = open(ADC_DEVICE_802, O_RDWR|O_CREAT|O_TRUNC, 0644);
} else {
if(!access(ADC_DEVICE_803, R_OK)) {
- LOGI("DEV:%s", ADC_DEVICE_803);
+ //LOGI("DEV:%s", ADC_DEVICE_803);
fd = open(ADC_DEVICE_803, O_RDWR|O_CREAT|O_TRUNC, 0644);
} else {
LOGE("No found ADC devices.");
@@ -133,7 +133,7 @@
close(fd);
return -2;
}else{
- LOGI("%s %d adc:%s\n", __FUNCTION__, __LINE__, adc_buf);
+ //LOGI("%s %d adc:%s\n", __FUNCTION__, __LINE__, adc_buf);
adc_value = strstr(adc_buf, "channel");
}
close(fd);
diff --git a/mbtk/mbtk_lib/src/mbtk_audio.c b/mbtk/mbtk_lib/src/mbtk_audio.c
index 382bef3..1858fa1 100755
--- a/mbtk/mbtk_lib/src/mbtk_audio.c
+++ b/mbtk/mbtk_lib/src/mbtk_audio.c
@@ -322,7 +322,7 @@
void mbtk_audio_mode_set(int mode)
{
int rc = 0;
-
+#ifndef MBTK_YX_SUPPORT
if(NULL == mbtk_audio_ubus_db)
{
printf("mbtk_dtmf_ubus not init!\n");
@@ -333,7 +333,7 @@
if ((rc = ubus_invoke(mbtk_audio_ubus_db->ctx,
mbtk_audio_ubus_db->audioif_request_id,
AUDIO_UBUS_MODE_SET,
- audio_cm_b.head, NULL, NULL, 0)) != UBUS_STATUS_OK)
+ audio_cm_b.head, NULL, NULL, 2 * 1000)) != UBUS_STATUS_OK)
{
printf("%s, ubus_invoke_async %s failed %s\n", __FUNCTION__, AUDIO_UBUS_MODE_SET, ubus_strerror(rc));
}
@@ -341,13 +341,38 @@
{
printf("%s: ubus_invoke_async success\n", __FUNCTION__);
}
+#else
+ static struct ubus_context *ctx;
+ ctx = ubus_connect(NULL);
+ if (!ctx) {
+ printf("Failed to connect to ubus\n");
+ return;
+ }
+
+ static struct blob_buf b;
+ uint32_t id;
+ int ret;
+ ret = ubus_lookup_id(ctx, AUDIO_UBUS_REQUEST_NAME, &id);
+ if (ret) {
+ printf("ubus_lookup_id() fail.\n");
+ return ret;
+ }
+
+ blob_buf_init(&b, 0);
+ blobmsg_add_u32(&b, "param0", mode);
+ if((ret = ubus_invoke(ctx, id, AUDIO_UBUS_MODE_SET, b.head, NULL, NULL, 0)) != UBUS_STATUS_OK) {
+ printf("ubus_invoke fail:%d.\n", ret);
+ } else {
+ printf("ubus_invoke success.\n");
+ }
+#endif
}
void mbtk_audio_path_enable(int mode)
{
int rc = 0;
-
+#ifndef MBTK_YX_SUPPORT
if(NULL == mbtk_audio_ubus_db)
{
printf("mbtk_dtmf_ubus not init!\n");
@@ -367,6 +392,32 @@
{
printf("%s: ubus_invoke_async success\n", __FUNCTION__);
}
+#else
+ static struct ubus_context *ctx;
+ ctx = ubus_connect(NULL);
+ if (!ctx) {
+ printf("Failed to connect to ubus\n");
+ return;
+ }
+
+ static struct blob_buf b;
+ uint32_t id;
+ int ret;
+ ret = ubus_lookup_id(ctx, AUDIO_UBUS_REQUEST_NAME, &id);
+ if (ret) {
+ printf("ubus_lookup_id() fail.\n");
+ return ret;
+ }
+
+ blob_buf_init(&b, 0);
+ blobmsg_add_u32(&b, "param0", mode);
+ if((ret = ubus_invoke(ctx, id, AUDIO_UBUS_PATH_ENABLE, b.head, NULL, NULL, 0)) != UBUS_STATUS_OK) {
+ printf("ubus_invoke fail:%d.\n", ret);
+ } else {
+ printf("ubus_invoke success.\n");
+ }
+
+#endif
}
@@ -385,37 +436,53 @@
void mbtk_audio_switch_pcm(int mode)
{
int rc = 0;
- struct ubus_request *req = NULL;
-
+#ifndef MBTK_YX_SUPPORT
if(NULL == mbtk_audio_ubus_db)
{
printf("mbtk_dtmf_ubus not init!\n");
return;
}
- req = (struct ubus_request *)malloc(sizeof(struct ubus_request));
- if (req == NULL)
- {
- printf("leave %s: lack of memory\n", __FUNCTION__);
- return;
- }
- memset(req, 0, sizeof(struct ubus_request));
+
blob_buf_init(&audio_cm_b, 0);
blobmsg_add_u32(&audio_cm_b, "param0", mode);
- if ((rc = ubus_invoke_async(mbtk_audio_ubus_db->ctx,
+ if ((rc = ubus_invoke(mbtk_audio_ubus_db->ctx,
mbtk_audio_ubus_db->audioif_request_id,
AUDIO_UBUS_SWITCH_PCM,
- audio_cm_b.head, req)) != UBUS_STATUS_OK)
+ audio_cm_b.head, NULL, NULL, 0/*2 * 1000*/)) != UBUS_STATUS_OK)
{
- free(req);
- printf("%s, ubus_invoke_async %s failed %s\n", __FUNCTION__, AUDIO_UBUS_MODE_SET, ubus_strerror(rc));
+ printf("%s, ubus_invoke %s failed %s\n", __FUNCTION__, AUDIO_UBUS_SWITCH_PCM, ubus_strerror(rc));
}
else
{
- printf("%s: ubus_invoke_async success\n", __FUNCTION__);
- mbtk_audio_ubus_db->work_state++;
- req->complete_cb = mbtk_ubus_complete_cb;
- ubus_complete_request_async(mbtk_audio_ubus_db->ctx, req);
+ printf("%s: ubus_invoke success\n", __FUNCTION__);
}
+#else
+
+ static struct ubus_context *ctx;
+ ctx = ubus_connect(NULL);
+ if (!ctx) {
+ printf("Failed to connect to ubus\n");
+ return;
+ }
+
+ static struct blob_buf b;
+ uint32_t id;
+ int ret;
+ ret = ubus_lookup_id(ctx, AUDIO_UBUS_REQUEST_NAME, &id);
+ if (ret) {
+ printf("ubus_lookup_id() fail.\n");
+ return ret;
+ }
+
+ blob_buf_init(&b, 0);
+ blobmsg_add_u32(&b, "param0", mode);
+ if((ret = ubus_invoke(ctx, id, AUDIO_UBUS_SWITCH_PCM, b.head, NULL, NULL, 0)) != UBUS_STATUS_OK) {
+ printf("ubus_invoke fail:%d.\n", ret);
+ } else {
+ printf("ubus_invoke success.\n");
+ }
+
+#endif
}
int mbtk_audio_dsp_set(int type, int gain)
@@ -826,7 +893,7 @@
int mbtk_audio_ubus_client_init(mbtk_audio_client_handle_type *ph_audio, mbtk_dtmf_cb cb)
{
int id;
-
+#ifndef MBTK_YX_SUPPORT
// Set call handle.
if(ph_audio == NULL || mbtk_audio_ubus_db != NULL)
{
@@ -849,13 +916,16 @@
*ph_audio = mbtk_audio_ubus_db;
LOGI("%s %d:%x", __FUNCTION__, __LINE__, mbtk_audio_ubus_db);
-
+#else
+ // Do nothong for YX.
+#endif
return 0;
}
int mbtk_audio_ubus_client_deinit(mbtk_audio_client_handle_type h_audio)
{
int ret;
+#ifndef MBTK_YX_SUPPORT
struct mbtk_audio_ubus_db_t *audio_ubus = (struct mbtk_audio_ubus_db_t *)h_audio;
mbtk_audio_log("%s \n", __FUNCTION__);
@@ -889,7 +959,9 @@
LOGI("%s %d", __FUNCTION__, __LINE__);
free(h_audio);
mbtk_audio_ubus_db = NULL;
-
+#else
+ // Do nothong for YX.
+#endif
return 0;
}
diff --git a/mbtk/mbtk_lib/src/mbtk_gpio.c b/mbtk/mbtk_lib/src/mbtk_gpio.c
index 9e562a9..18d216d 100755
--- a/mbtk/mbtk_lib/src/mbtk_gpio.c
+++ b/mbtk/mbtk_lib/src/mbtk_gpio.c
@@ -1061,7 +1061,7 @@
}
gpio_register_set_direction(port, 1); //设方向为输出
ret = gpio_register_get_value(port);
- printf("gpio default value is : %d.\n", ret);
+ //printf("gpio default value is : %d.\n", ret);
//[High]
@@ -1069,7 +1069,7 @@
gpio_register_set_value(port, 1);
usleep(50);
valueh = gpio_register_get_value(port);
- printf("set high? %d\n",valueh);
+ //printf("set high? %d\n",valueh);
if(1 == valueh){
break;
}
@@ -1082,7 +1082,7 @@
break;
}
}
- printf("******gpio should is high: %d.******\n", ret);
+ //printf("******gpio should is high: %d.******\n", ret);
if(1 != ret){
ret=-1;
goto exit;
@@ -1096,7 +1096,7 @@
gpio_register_set_value(port, 0); //输出低
usleep(50);
valuel = gpio_register_get_value(port);
- printf("set low? %d\n",valuel);
+ //printf("set low? %d\n",valuel);
if(0 == valuel){
break;
}
@@ -1109,7 +1109,7 @@
break;
}
}
- printf("******gpio should is low: %d.******\n", ret);
+ //printf("******gpio should is low: %d.******\n", ret);
if(0 != ret){
ret=-1;
goto exit;
@@ -1144,7 +1144,7 @@
gpio_register_set_value(port, 1);
usleep(50);
valueh = gpio_register_get_value(port);
- printf("set high? %d\n",valueh);
+ //printf("set high? %d\n",valueh);
if(1 == valueh){
break;
}
@@ -1161,7 +1161,7 @@
ret=-1;
goto exit;
}
- printf("******gpio should is high: %d.******\n", ret);
+ //printf("******gpio should is high: %d.******\n", ret);
//[Low]
@@ -1170,7 +1170,7 @@
gpio_register_set_value(port, 0); //输出低
usleep(50);
valuel = gpio_register_get_value(port);
- printf("set low? %d\n",valuel);
+ //printf("set low? %d\n",valuel);
if(0 == valuel){
break;
}
@@ -1183,7 +1183,7 @@
break;
}
}
- printf("******gpio should is low: %d.******\n", ret);
+ //printf("******gpio should is low: %d.******\n", ret);
if(0 != ret){
ret=-1;
goto exit;
@@ -1385,7 +1385,7 @@
fail_io[n] = test_gpio_0[i];
n++;
}else{
- printf("############gpio [%d] test success############\n", test_gpio_0[i]);
+ //printf("############gpio [%d] test success############\n", test_gpio_0[i]);
}
}
@@ -1397,7 +1397,7 @@
fail_io[n] = test_gpio_1[i];
n++;
}else{
- printf("############gpio [%d] test success############\n", test_gpio_1[i]);
+ //printf("############gpio [%d] test success############\n", test_gpio_1[i]);
}
}
@@ -1405,7 +1405,7 @@
for(i = 0; i < total_2; i=i+2){
ret_2 = gpio_register_test_out_2(test_gpio_2[i], test_gpio_2[i+1], 0);
if(-1 == ret_2){
- printf("!!!!!!!!!!!!gpio [%d] test failed!!!!!!!!!!!!\n", test_gpio_2[i+1]);
+ //printf("!!!!!!!!!!!!gpio [%d] test failed!!!!!!!!!!!!\n", test_gpio_2[i+1]);
fail_io[n] = test_gpio_2[i];
n++;
}else{
diff --git a/mbtk/test/asr1803/audio_test_yx.c b/mbtk/test/asr1803/audio_test_yx.c
index 53a7c01..dd9aec5 100755
--- a/mbtk/test/asr1803/audio_test_yx.c
+++ b/mbtk/test/asr1803/audio_test_yx.c
@@ -8,6 +8,7 @@
#include <sys/time.h>
#include <pthread.h>
#include <signal.h>
+#include <sys/stat.h>
#include "ql/ql_audio.h"
@@ -97,6 +98,7 @@
close(s_play_fd);
mbtk_audio_path_enable(0);
Ql_AudPlayer_Close(s_play_hdl);
+ s_play_hdl = -1;
printf("aplay End...\n");
return 0;
@@ -149,6 +151,7 @@
signal(SIGINT, sig_handler);
signal(SIGTERM, sig_handler);
+ signal(SIGTSTP, sig_handler);
mbtk_audio_ubus_client_init(&handler, dtmf_cb1);
mbtk_audio_switch_pcm(1);
diff --git a/mbtk/test/ubus_demo.c b/mbtk/test/ubus_demo.c
new file mode 100755
index 0000000..4806be3
--- /dev/null
+++ b/mbtk/test/ubus_demo.c
@@ -0,0 +1,79 @@
+#include <unistd.h>
+
+#include <libubox/blobmsg_json.h>
+#include "libubus.h"
+#include "mbtk_audio.h"
+
+void receive_call_result_data(struct ubus_request *req, int type, struct blob_attr *msg)
+{
+ printf("receive_call_result_data()\n");
+ if (!msg)
+ return;
+
+ printf("len - %d,data - %s\n", msg->id_len, msg->data);
+}
+
+
+int main(int argc, char *argv[])
+{
+#if 1
+ if(argc != 3) {
+ printf("ubus_demo switch/mode 0/1/-2/2\n");
+ return -1;
+ }
+ char *type = NULL;
+ int value = atoi(argv[2]);
+ if(!strcmp(argv[1], "switch")) {
+ type = "switch_pcm";
+ if(value != 0 && value != 1) {
+ printf("ubus_demo switch/mode 0/1/-2/2\n");
+ return -1;
+ }
+ } else if(!strcmp(argv[1], "mode")) {
+ type = "audio_mode_set";
+ if(value != -2 && value != 2) {
+ printf("ubus_demo switch/mode 0/1/-2/2\n");
+ return -1;
+ }
+ } else {
+ printf("ubus_demo switch/mode 0/1/-2/2\n");
+ return -1;
+ }
+
+ static struct ubus_context *ctx;
+ ctx = ubus_connect(NULL);
+ if (!ctx) {
+ printf("Failed to connect to ubus\n");
+ return -1;
+ }
+
+ static struct blob_buf b;
+ uint32_t id;
+ int ret;
+ ret = ubus_lookup_id(ctx, "audio_if", &id);
+ if (ret) {
+ printf("ubus_lookup_id() fail.\n");
+ return ret;
+ }
+
+
+
+ blob_buf_init(&b, 0);
+ blobmsg_add_u32(&b, "param0", value);
+ if((ret = ubus_invoke(ctx, id, type, b.head, NULL/*receive_call_result_data*/, NULL, 0)) != UBUS_STATUS_OK) {
+ printf("ubus_invoke fail:%d.\n", ret);
+ } else {
+ printf("ubus_invoke success.\n");
+ }
+#else
+
+ int handler = 0;
+ mbtk_audio_ubus_client_init(&handler, NULL);
+
+ mbtk_audio_switch_pcm(1);
+ mbtk_audio_mode_set(2);
+
+#endif
+
+ return 0;
+}