This forum has been archived. All content is frozen. Please use KDE Discuss instead.

D-Bus error is thrown when calling transport->tryAcquire

Tags: None
(comma "," separated)
jashwink
Registered Member
Posts
2
Karma
0
I am new to Bluetooth Programing.
My aim is to write program to hear song in raspberry pi through A2DP played from mobile phone.
After some studies I Plan to use KDE BLUEZQT because I am familiar with Qt programing.

My setup as follows

1. Raspberry Pi 4
2. Installed Latest version of Raspbian OS
3. Build and installed QT5.14 in the Raspberry.
4. Then using bluetoothctl I was able to play or hear the Audio from raspberry pi through A2DP.
5. Installed BluezQt version 5.68.0 using following command and installation was successful


cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_LIBDIR=lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH) -DCMAKE_INSTALL_INCLUDEDIR=include -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS=-std=c++11 -DKDE_INSTALL_QMLDIR=/opt/Qt5.14/qml -DECM_MKSPECS_INSTALL_DIR=/opt/Qt5.14/mkspecs/modules -DCMAKE_PREFIX_PATH=/opt/Qt5.14


6.I used Qt creator to create applications similar to sample program from /bluez-qt/tests path, Chat profile, device receiver. Both the application was working.
7. Then I started to use the mediaendpointconnect example, I was able to pair and connect with the mobile phone but when I started to play song from mobile phone, error was thrown as below.


Transport state: BluezQt::MediaTransport::State::Pending
org.kde.bluez: PendingCall Error: "Operation Not Authorized"
fd: -1 mtu read: 0 mtu write: 0

8. D-Bus error is thrown when the calling TPendingCall<QDBusUnixFileDescriptor, uint16_t, uint16_t> *fd = transport->tryAcquire(); //

After 2 weeks of struggle I could not able to find out what causes this issue.

Snapshot of Code as follow

BTAudioDemo.pro

Code: Select all

QT +=  dbus BluezQt

CONFIG += c++11

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Refer to the documentation for the
# deprecated API to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

#LIBS  += -lKF5BluezQt




audioendpointconnector.cpp

Code: Select all

MediaEndpointConnector::MediaEndpointConnector(Manager *manager, QObject *parent) : QObject(parent), m_manager(manager)
{

    connect(m_manager, &Manager::deviceChanged, [this](DevicePtr device) {
        connect(device.data(), &Device::mediaTransportChanged, this, &MediaEndpointConnector::onTransportChanged);
    });

    NoInputNoOutputAgent *agent = new NoInputNoOutputAgent({Services::AdvancedAudioDistribution,Services::AudioVideoRemoteControl, Services::Headset}); // ,
    connect(agent, &NoInputNoOutputAgent::serviceAuthorized, this, &MediaEndpointConnector::onServiceAuthorized);
    m_manager->registerAgent(agent);
    m_manager->requestDefaultAgent(agent);

    MediaEndpoint *sbcSink = new MediaEndpoint({MediaEndpoint::Role::AudioSink, MediaEndpoint::Codec::Sbc}, m_manager);
    MediaEndpoint *aacSink = new MediaEndpoint({MediaEndpoint::Role::AudioSink, MediaEndpoint::Codec::Aac}, m_manager);
    connect(sbcSink, &MediaEndpoint::configurationSelected, this, &MediaEndpointConnector::onConfigurationSelected);
    connect(aacSink, &MediaEndpoint::configurationSelected, this, &MediaEndpointConnector::onConfigurationSelected);
    connect(sbcSink, &MediaEndpoint::configurationSet, this, &MediaEndpointConnector::onConfigurationSet);
    connect(aacSink, &MediaEndpoint::configurationSet, this, &MediaEndpointConnector::onConfigurationSet);
    connect(sbcSink, &MediaEndpoint::configurationCleared, this, &MediaEndpointConnector::onConfigurationCleared);
    connect(aacSink, &MediaEndpoint::configurationCleared, this, &MediaEndpointConnector::onConfigurationCleared);
    m_manager->usableAdapter()->media()->registerEndpoint(sbcSink);
    m_manager->usableAdapter()->media()->registerEndpoint(aacSink);
}

void MediaEndpointConnector::onTransportChanged(MediaTransportPtr transport)
{



    if (!transport) {
        return;
    }

    connect(transport.data(), &MediaTransport::stateChanged, [transport](MediaTransport::State state){
        qDebug() << "Transport state:" << state;


        if (state == MediaTransport::State::Pending) {

           TPendingCall<QDBusUnixFileDescriptor, uint16_t, uint16_t> *fd = transport->acquire();// transport->tryAcquire();  //

            connect(fd, &PendingCall::finished, [fd]() {
                qDebug() << "fd: " << fd->valueAt<0>().fileDescriptor() << "mtu read:" << fd->valueAt<1>() << "mtu write:" << fd->valueAt<2>();
            });
        }
    });
    connect(transport.data(), &MediaTransport::volumeChanged, [](quint16 volume){
        qDebug() << "Transport volume:" << volume;
    });


}




main.cpp files.

Code: Select all

int main(int argc, char *argv[])
{


    QCoreApplication app(argc, argv);


    qDebug() << "Waiting for bluetooth audio source to connect...";

    Manager *manager = new Manager();
    InitManagerJob *initJob = manager->init();
    initJob->exec();
    if (initJob->error()) {
        qWarning() << "Error initializing manager:" << initJob->errorText();
        return 1;
    }

    if (!manager->usableAdapter()) {
        qWarning() << "No usable adapter";
        return 2;
    }

    if (!manager->usableAdapter()->media()) {
        qWarning() << "No media interface";
        return 2;
    }
    new MediaEndpointConnector(manager);

    DeviceReceiver *deviceReceiver = new DeviceReceiver();
    deviceReceiver->scanDevices(manager);
    return app.exec();
}

jashwink
Registered Member
Posts
2
Karma
0
Dear All,

I was able to solve this issue, I configured bluealsa with profile option a2dp-sink. Once I removed the option "-p a2dp-sink" from file /lib/systemd/system/bluealsa.service and reboot which I configured earlier. My application can call transport->tryAcquire function and able to get file discriptor successfully.


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]