Node.js 从节点加载项响应Dbus调用时Bluez MediaEndpoint1超时问题

Node.js 从节点加载项响应Dbus调用时Bluez MediaEndpoint1超时问题,node.js,dbus,bluez,Node.js,Dbus,Bluez,Bluez版本:5.43 让我直截了当地说: 我在Bluez日志文件中有以下错误: Calling SetConfiguration: name = :1.3 path = /MediaEndpoint/A2DPSink ... Endpoint replied with an error: org.freedesktop.DBus.Error.NoReply 如果我改变这行代码 #定义请求超时时间(3*1000)/*3秒*/ 在~/bluez-5.43/profiles/audio/medi

Bluez版本:5.43

让我直截了当地说:

我在Bluez日志文件中有以下错误:

Calling SetConfiguration: name = :1.3 path = /MediaEndpoint/A2DPSink
...
Endpoint replied with an error: org.freedesktop.DBus.Error.NoReply
如果我改变这行代码

#定义请求超时时间(3*1000)/*3秒*/

~/bluez-5.43/profiles/audio/media.c
文件中

更大的值,如5左右。。。虫子消失了

那么这个bug是什么呢

基本上,我有nodejs插件代码,可以执行以下操作:

初始化端点

void endpoint_init(DBusConnection *connection, const char *endpoint) {
    DBusObjectPathVTable vtable_endpoint;
    vtable_endpoint.message_function = endpoint_handler;
    dbus_connection_register_object_path(connection, endpoint, &vtable_endpoint, NULL);
}
在Bluez日志中,您将看到
bluetoothd[25176]:端点注册:发送方=:1.130路径=/MediaEndpoint/A2DPSink

endpoint\u handler
函数将收到设置\u配置或选择\u配置函数的调用通知

当接到一个电话时,它会得到回复,就像这样

sender = dbus_message_get_sender(m);
r = dbus_message_new_method_return(m);

printf("!! ----- endpoint_set_configuration, time_right_before_reply_sent: ");
print_time();

assert( dbus_connection_send(conn, r, NULL) );
dbus_connection_flush(conn);

    printf("!! ----- endpoint_set_configuration, time_right_after_reply_sent: ");
    print_time();
如你所见,我正在记录一些时间信息

现在,我还在Bluez中记录了时间信息并重新编译

以下是Bluez的日志:

bluetoothd[789]: profiles/audio/media.c:media_endpoint_async_call() Calling SetConfiguration: name = :1.3 path = /MediaEndpoint/A2DPSink
bluetoothd[789]: profiles/audio/media.c:endpoint_reply() [GOT HERE -- endpoint_reply -- original_msg --] SetConfiguration: name = :1.3 path = /MediaEndpoint/A2DPSink
bluetoothd[789]: profiles/audio/media.c:print_time() TIME BEFORE -- dbus_pending_call_steal_reply --: 2017-01-25 04:54:01
bluetoothd[789]: profiles/audio/media.c:print_time() TIME AFTER -- dbus_pending_call_steal_reply --: 2017-01-25 04:54:01
bluetoothd[789]: profiles/audio/media.c:endpoint_reply() [GOT HERE -- endpoint_reply -- reply_msg] (null): name = (null) path = (null)
bluetoothd[789]: Endpoint replied with an error: org.freedesktop.DBus.Error.NoReply
以下是来自我的节点加载项的日志:

 endpoint_handler: path=/MediaEndpoint/A2DPSink, interface=org.bluez.MediaEndpoint1, member=SetConfiguration 
!! ----- endpoint_set_configuration, endpoint_path: /MediaEndpoint/A2DPSink 
!! ----- endpoint_set_configuration, time_right_before_reply_sent: 
 2017-01-25 04:54:03 
!! ----- endpoint_set_configuration, time_right_after_reply_sent: 
 2017-01-25 04:54:03 
您可以清楚地看到,Bluez默认超时3秒太短了。。。答案还在路上

但是pulseaudio的实现没有这个问题。。。为什么?

是因为有两个不同的事件循环,即节点插件使用lib-uv事件循环,而Bluez和pulse使用glib事件循环

这里发生了什么事,有人能解释一下吗

我宁愿将其识别为Bluez bug,或者理解如何在我的节点插件端修复它

多谢各位议员:)

附言

Bluez
~/Bluez-5.43/profiles/audio/media.c
的代码建议将请求超时保持在3,这让我担心

/* Timeout should be less than avdtp request timeout (4 seconds) */
if (g_dbus_send_message_with_reply(btd_get_dbus_connection(),
                    msg, &request->call,
                    REQUEST_TIMEOUT) == FALSE) {
    error("D-Bus send failed");
    g_free(request);
    return FALSE;
}

我发现glib和libuv在同一个进程下同时运行存在一些冲突

我使用的节点dbus插件是一个c级绑定,它实例化了一个glib事件循环

nodejs有一个libuv事件循环

他们合作得不好

这就是我可以假设的问题是

我的解决方案是从bluez media enpoint中删除c代码,并创建自己的nodejs NAN绑定到它……而不使用任何glib事件循环

这是我正在使用的节点dbus库: