从节点插件回复Dbus呼叫时,Bluez MediaEndpoint1超时问题

时间:2017-01-25 05:06:38

标签: 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

如果我改变这行代码

#define REQUEST_TIMEOUT (3 * 1000) /* 3 seconds */

~/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]: Endpoint registered: sender=:1.130 path=/MediaEndpoint/A2DPSink

endpoint_handler函数将被通知调用set_configuration或select_configuration函数......

收到来电时,会像这样回复......

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或了解如何在我的节点插件端修复它...

谢谢Stackoverflowers:)

P.S。

Bluez ~/bluez-5.43/profiles/audio/media.c的代码建议将REQUEST_TIMEOUT保持在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;
}

1 个答案:

答案 0 :(得分:0)

我发现在相同的过程中与glib和libuv一起运行存在一些冲突。

我使用的node-dbus插件是一个c级绑定,它实例化一个glib事件循环...

nodejs有一个libuv事件循环

他们不能很好地合作......

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

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

这是我正在使用的node-dbus库:

https://github.com/Shouqun/node-dbus