【Fix Bug】RockChip平台Bluez-Alsa Source端播放卡住

概述

RockChip平台当时使用的Bluez-Alsa代码已经比较老了,但由于RK内部维护了一些补丁,因此并未直接使用同步最新的Bluez-Alsa代码,而是沿用老版本的代码。老版本代码存在一些BUG(新版本可能已经修复),本文就记录使用BT Souce功能时,播放会卡住,然后整个线程都被阻塞。此时调节蓝牙音量也是阻塞状态。现象log(阻塞在Connecting…):
在这里插入图片描述

解决补丁

原因:因多处对同一线程使用pthread_join,导致整个主进程阻塞,此时无法再接收新连接,也无法执行新的命令。

diff --git a/src/ctl.c b/src/ctl.c
old mode 100644
new mode 100755
index 88a7743..79d0183
--- a/src/ctl.c
+++ b/src/ctl.c
@@ -161,8 +161,9 @@ static void _transport_release(struct ba_transport *t, int client) {
         * might try to acquire not yet released transport. To prevent this, we have
         * to make sure, that the transport is released (thread is terminated). */
        if (t->profile == BLUETOOTH_PROFILE_A2DP_SOURCE) {
-               pthread_cancel(t->thread);
-               pthread_join(t->thread, NULL);
+               pthread_t thread_tmp = t->thread;
+               pthread_cancel(thread_tmp);
+               pthread_join(thread_tmp, NULL);
        }
 
        switch (t->type) {
diff --git a/src/transport.c b/src/transport.c
old mode 100644
new mode 100755
index bca44b9..2a2b46e
--- a/src/transport.c
+++ b/src/transport.c
@@ -705,7 +705,7 @@ int transport_set_state(struct ba_transport *t, enum ba_transport_state state) {
 
        switch (state) {
        case TRANSPORT_IDLE:
-               if (created) {
+               if (created && (t->profile != BLUETOOTH_PROFILE_A2DP_SOURCE)) {
                        pthread_cancel(t->thread);
                        ret = pthread_join(t->thread, NULL);
                }

你可能感兴趣的:(RockChip)