Index: src/CMakeLists.txt =================================================================== --- src/CMakeLists.txt +++ src/CMakeLists.txt @@ -6,6 +6,11 @@ device.cpp device_p.cpp input.cpp + media.cpp + media_p.cpp + mediaendpoint.cpp + mediaendpoint_p.cpp + mediaendpointadaptor.cpp mediaplayer.cpp mediaplayer_p.cpp mediaplayertrack.cpp @@ -47,6 +52,8 @@ qt5_add_dbus_interface(bluezqt_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.bluez.AgentManager1.xml bluezagentmanager1) qt5_add_dbus_interface(bluezqt_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.bluez.ProfileManager1.xml bluezprofilemanager1) qt5_add_dbus_interface(bluezqt_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.bluez.Device1.xml bluezdevice1) +qt5_add_dbus_interface(bluezqt_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.bluez.Media1.xml bluezmedia1) +qt5_add_dbus_interface(bluezqt_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.bluez.MediaEndpoint1.xml bluezmediaendpoint1) qt5_add_dbus_interface(bluezqt_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.bluez.MediaPlayer1.xml bluezmediaplayer1) qt5_add_dbus_interface(bluezqt_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.bluez.obex.AgentManager1.xml obexagentmanager1) qt5_add_dbus_interface(bluezqt_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/interfaces/org.bluez.obex.Client1.xml obexclient1) Index: src/a2dp-codecs.h =================================================================== --- /dev/null +++ src/a2dp-codecs.h @@ -0,0 +1,244 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2006-2010 Nokia Corporation + * Copyright (C) 2004-2010 Marcel Holtmann + * + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#define A2DP_CODEC_SBC 0x00 +#define A2DP_CODEC_MPEG12 0x01 +#define A2DP_CODEC_MPEG24 0x02 +#define A2DP_CODEC_ATRAC 0x03 +#define A2DP_CODEC_VENDOR 0xFF + +#define SBC_SAMPLING_FREQ_16000 (1 << 3) +#define SBC_SAMPLING_FREQ_32000 (1 << 2) +#define SBC_SAMPLING_FREQ_44100 (1 << 1) +#define SBC_SAMPLING_FREQ_48000 1 + +#define SBC_CHANNEL_MODE_MONO (1 << 3) +#define SBC_CHANNEL_MODE_DUAL_CHANNEL (1 << 2) +#define SBC_CHANNEL_MODE_STEREO (1 << 1) +#define SBC_CHANNEL_MODE_JOINT_STEREO 1 + +#define SBC_BLOCK_LENGTH_4 (1 << 3) +#define SBC_BLOCK_LENGTH_8 (1 << 2) +#define SBC_BLOCK_LENGTH_12 (1 << 1) +#define SBC_BLOCK_LENGTH_16 1 + +#define SBC_SUBBANDS_4 (1 << 1) +#define SBC_SUBBANDS_8 1 + +#define SBC_ALLOCATION_SNR (1 << 1) +#define SBC_ALLOCATION_LOUDNESS 1 + +#define MAX_BITPOOL 64 +#define MIN_BITPOOL 2 + +#define MPEG_CHANNEL_MODE_MONO (1 << 3) +#define MPEG_CHANNEL_MODE_DUAL_CHANNEL (1 << 2) +#define MPEG_CHANNEL_MODE_STEREO (1 << 1) +#define MPEG_CHANNEL_MODE_JOINT_STEREO 1 + +#define MPEG_LAYER_MP1 (1 << 2) +#define MPEG_LAYER_MP2 (1 << 1) +#define MPEG_LAYER_MP3 1 + +#define MPEG_SAMPLING_FREQ_16000 (1 << 5) +#define MPEG_SAMPLING_FREQ_22050 (1 << 4) +#define MPEG_SAMPLING_FREQ_24000 (1 << 3) +#define MPEG_SAMPLING_FREQ_32000 (1 << 2) +#define MPEG_SAMPLING_FREQ_44100 (1 << 1) +#define MPEG_SAMPLING_FREQ_48000 1 + +#define MPEG_BIT_RATE_VBR 0x8000 +#define MPEG_BIT_RATE_320000 0x4000 +#define MPEG_BIT_RATE_256000 0x2000 +#define MPEG_BIT_RATE_224000 0x1000 +#define MPEG_BIT_RATE_192000 0x0800 +#define MPEG_BIT_RATE_160000 0x0400 +#define MPEG_BIT_RATE_128000 0x0200 +#define MPEG_BIT_RATE_112000 0x0100 +#define MPEG_BIT_RATE_96000 0x0080 +#define MPEG_BIT_RATE_80000 0x0040 +#define MPEG_BIT_RATE_64000 0x0020 +#define MPEG_BIT_RATE_56000 0x0010 +#define MPEG_BIT_RATE_48000 0x0008 +#define MPEG_BIT_RATE_40000 0x0004 +#define MPEG_BIT_RATE_32000 0x0002 +#define MPEG_BIT_RATE_FREE 0x0001 + +#define AAC_OBJECT_TYPE_MPEG2_AAC_LC 0x80 +#define AAC_OBJECT_TYPE_MPEG4_AAC_LC 0x40 +#define AAC_OBJECT_TYPE_MPEG4_AAC_LTP 0x20 +#define AAC_OBJECT_TYPE_MPEG4_AAC_SCA 0x10 + +#define AAC_SAMPLING_FREQ_8000 0x0800 +#define AAC_SAMPLING_FREQ_11025 0x0400 +#define AAC_SAMPLING_FREQ_12000 0x0200 +#define AAC_SAMPLING_FREQ_16000 0x0100 +#define AAC_SAMPLING_FREQ_22050 0x0080 +#define AAC_SAMPLING_FREQ_24000 0x0040 +#define AAC_SAMPLING_FREQ_32000 0x0020 +#define AAC_SAMPLING_FREQ_44100 0x0010 +#define AAC_SAMPLING_FREQ_48000 0x0008 +#define AAC_SAMPLING_FREQ_64000 0x0004 +#define AAC_SAMPLING_FREQ_88200 0x0002 +#define AAC_SAMPLING_FREQ_96000 0x0001 + +#define AAC_CHANNELS_1 0x02 +#define AAC_CHANNELS_2 0x01 + +#define AAC_GET_BITRATE(a) ((a).bitrate1 << 16 | \ + (a).bitrate2 << 8 | (a).bitrate3) +#define AAC_GET_FREQUENCY(a) ((a).frequency1 << 4 | (a).frequency2) + +#define AAC_SET_BITRATE(a, b) \ + do { \ + (a).bitrate1 = (b >> 16) & 0x7f; \ + (a).bitrate2 = (b >> 8) & 0xff; \ + (a).bitrate3 = b & 0xff; \ + } while (0) +#define AAC_SET_FREQUENCY(a, f) \ + do { \ + (a).frequency1 = (f >> 4) & 0xff; \ + (a).frequency2 = f & 0x0f; \ + } while (0) + +#define AAC_INIT_BITRATE(b) \ + .bitrate1 = (b >> 16) & 0x7f, \ + .bitrate2 = (b >> 8) & 0xff, \ + .bitrate3 = b & 0xff, +#define AAC_INIT_FREQUENCY(f) \ + .frequency1 = (f >> 4) & 0xff, \ + .frequency2 = f & 0x0f, + +#define APTX_VENDOR_ID 0x0000004f +#define APTX_CODEC_ID 0x0001 + +#define APTX_CHANNEL_MODE_MONO 0x01 +#define APTX_CHANNEL_MODE_STEREO 0x02 + +#define APTX_SAMPLING_FREQ_16000 0x08 +#define APTX_SAMPLING_FREQ_32000 0x04 +#define APTX_SAMPLING_FREQ_44100 0x02 +#define APTX_SAMPLING_FREQ_48000 0x01 + +#define LDAC_VENDOR_ID 0x0000012d +#define LDAC_CODEC_ID 0x00aa + +typedef struct { + uint32_t vendor_id; + uint16_t codec_id; +} __attribute__ ((packed)) a2dp_vendor_codec_t; + +#if __BYTE_ORDER == __LITTLE_ENDIAN + +typedef struct { + uint8_t channel_mode:4; + uint8_t frequency:4; + uint8_t allocation_method:2; + uint8_t subbands:2; + uint8_t block_length:4; + uint8_t min_bitpool; + uint8_t max_bitpool; +} __attribute__ ((packed)) a2dp_sbc_t; + +typedef struct { + uint8_t channel_mode:4; + uint8_t crc:1; + uint8_t layer:3; + uint8_t frequency:6; + uint8_t mpf:1; + uint8_t rfa:1; + uint16_t bitrate; +} __attribute__ ((packed)) a2dp_mpeg_t; + +typedef struct { + uint8_t object_type; + uint8_t frequency1; + uint8_t rfa:2; + uint8_t channels:2; + uint8_t frequency2:4; + uint8_t bitrate1:7; + uint8_t vbr:1; + uint8_t bitrate2; + uint8_t bitrate3; +} __attribute__ ((packed)) a2dp_aac_t; + +typedef struct { + a2dp_vendor_codec_t info; + uint8_t channel_mode:4; + uint8_t frequency:4; +} __attribute__ ((packed)) a2dp_aptx_t; + +typedef struct { + a2dp_vendor_codec_t info; + uint8_t unknown[2]; +} __attribute__ ((packed)) a2dp_ldac_t; + +#elif __BYTE_ORDER == __BIG_ENDIAN + +typedef struct { + uint8_t frequency:4; + uint8_t channel_mode:4; + uint8_t block_length:4; + uint8_t subbands:2; + uint8_t allocation_method:2; + uint8_t min_bitpool; + uint8_t max_bitpool; +} __attribute__ ((packed)) a2dp_sbc_t; + +typedef struct { + uint8_t layer:3; + uint8_t crc:1; + uint8_t channel_mode:4; + uint8_t rfa:1; + uint8_t mpf:1; + uint8_t frequency:6; + uint16_t bitrate; +} __attribute__ ((packed)) a2dp_mpeg_t; + +typedef struct { + uint8_t object_type; + uint8_t frequency1; + uint8_t frequency2:4; + uint8_t channels:2; + uint8_t rfa:2; + uint8_t vbr:1; + uint8_t bitrate1:7; + uint8_t bitrate2; + uint8_t bitrate3; +} __attribute__ ((packed)) a2dp_aac_t; + +typedef struct { + a2dp_vendor_codec_t info; + uint8_t frequency:4; + uint8_t channel_mode:4; +} __attribute__ ((packed)) a2dp_aptx_t; + +typedef struct { + a2dp_vendor_codec_t info; + uint8_t unknown[2]; +} __attribute__ ((packed)) a2dp_ldac_t; + +#else +#error "Unknown byte order" +#endif Index: src/interfaces/org.bluez.Media1.xml =================================================================== --- /dev/null +++ src/interfaces/org.bluez.Media1.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + Index: src/interfaces/org.bluez.MediaEndpoint1.xml =================================================================== --- /dev/null +++ src/interfaces/org.bluez.MediaEndpoint1.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + Index: src/media.h =================================================================== --- /dev/null +++ src/media.h @@ -0,0 +1,98 @@ +/* + * BluezQt - Asynchronous BlueZ wrapper library + * + * Copyright (C) 2018 Manuel Weichselbaumer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#ifndef BLUEZQT_MEDIA_H +#define BLUEZQT_MEDIA_H + +#include + +#include "bluezqt_export.h" + +namespace BluezQt +{ + +class MediaEndpoint; +class PendingCall; + +/** + * @class BluezQt::Media Media.h + * + * Bluetooth Media. + * + * This allows media endpoints to be established in accordance with the + * capabilities of a specific media service profile. + * + * For example, an A2DP media endpoint could be created allowing data from a + * remote device to be streamed to/from the sender. + * + * Each media endpoint is associated with a service object instance that + * implements the required behaviours of the endpoint. The service object + * must be created at a given path before it is registered. + * + * @see MediaEndpoint, ObexAgent, Profile + */ +class BLUEZQT_EXPORT Media : public QObject +{ + Q_OBJECT + +public: + /** + * Creates a new Media object. + * + * @param parent + */ + explicit Media(QObject *parent = nullptr); + + /** + * Destroys a Media object. + */ + ~Media(); + + /** + * Registers endpoint. + * + * Register a local end point to sender, the sender can register as many end points as it likes. + * + * Note: If the sender disconnects the end points are automatically unregistered. + * + * Possible errors: PendingCall::InvalidArguments, PendingCall::NotSupported + * + * @param endpoint endpoint to be registered + * @return void pending call + */ + PendingCall *registerEndpoint(MediaEndpoint *endpoint); + + /** + * Unregisters endpoint. + * + * @param endpoint endpoint to be unregistered + * @return void pending call + */ + PendingCall *unregisterEndpoint(MediaEndpoint *endpoint); + +private: + class MediaPrivate *const d; +}; + +} // namespace BluezQt + +#endif // BLUEZQT_MEDIA_H Index: src/media.cpp =================================================================== --- /dev/null +++ src/media.cpp @@ -0,0 +1,77 @@ +/* + * BluezQt - Asynchronous Bluez wrapper library + * + * Copyright (C) 2018 Manuel Weichselbaumer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#include "media.h" +#include "media_p.h" +#include "mediaendpoint.h" +#include "mediaendpointadaptor.h" +#include "pendingcall.h" +#include "utils.h" +#include "debug.h" + +namespace BluezQt +{ + +Media::Media(QObject *parent) + : QObject(parent) + , d(new MediaPrivate(this)) +{ +} + +Media::~Media() +{ + delete d; +} + +PendingCall *Media::registerEndpoint(MediaEndpoint *endpoint) +{ + Q_ASSERT(endpoint); + + if (!d->m_bluezMedia) { + return new PendingCall(PendingCall::InternalError, QStringLiteral("Media not operational!")); + } + + new MediaEndpointAdaptor(endpoint); + + if (!DBusConnection::orgBluez().registerObject(endpoint->objectPath().path(), endpoint)) { + qCDebug(BLUEZQT) << "Cannot register object" << endpoint->objectPath().path(); + } + + return new PendingCall(d->m_bluezMedia->RegisterEndpoint(endpoint->objectPath(), endpoint->properties()), + PendingCall::ReturnVoid, this); +} + +PendingCall *Media::unregisterEndpoint(MediaEndpoint *endpoint) +{ + Q_ASSERT(endpoint); + + if (!d->m_bluezMedia) { + return new PendingCall(PendingCall::InternalError, QStringLiteral("Media not operational!")); + } + + DBusConnection::orgBluez().unregisterObject(endpoint->objectPath().path()); + + return new PendingCall(d->m_bluezMedia->UnregisterEndpoint(endpoint->objectPath()), + PendingCall::ReturnVoid, this); +} + +} // namespace BluezQt Index: src/media_p.h =================================================================== --- /dev/null +++ src/media_p.h @@ -0,0 +1,48 @@ +/* + * BluezQt - Asynchronous Bluez wrapper library + * + * Copyright (C) 2018 Manuel Weichselbaumer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#ifndef BLUEZQT_MEDIA_P_H +#define BLUEZQT_MEDIA_P_H + +#include "bluezmedia1.h" + +namespace BluezQt +{ + +typedef org::bluez::Media1 BluezMedia; + +class Media; + +class MediaPrivate : public QObject +{ + Q_OBJECT + +public: + explicit MediaPrivate(Media *q); + + Media *q = nullptr; + BluezMedia *m_bluezMedia = nullptr; +}; + +} // namespace BluezQt + +#endif // BLUEZQT_MEDIA_P_H Index: src/media_p.cpp =================================================================== --- /dev/null +++ src/media_p.cpp @@ -0,0 +1,38 @@ +/* + * BluezQt - Asynchronous Bluez wrapper library + * + * Copyright (C) 2018 Manuel Weichselbaumer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#include "media_p.h" +#include "media.h" +#include "utils.h" + +namespace BluezQt +{ + +MediaPrivate::MediaPrivate(Media *q) + : QObject(q) + , q(q) +{ + // TODO: obtain object path + m_bluezMedia = new BluezMedia(Strings::orgBluez(), QString(), DBusConnection::orgBluez(), this); +} + +} // namespace BluezQt Index: src/mediaendpoint.h =================================================================== --- /dev/null +++ src/mediaendpoint.h @@ -0,0 +1,142 @@ +/* + * BluezQt - Asynchronous BlueZ wrapper library + * + * Copyright (C) 2018 Manuel Weichselbaumer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#ifndef BLUEZQT_MEDIAENDPOINT_H +#define BLUEZQT_MEDIAENDPOINT_H + +#include + +#include "bluezqt_export.h" + +class QDBusObjectPath; + +namespace BluezQt +{ + +class TransportPtr; + +/** + * @class BluezQt::MediaEndpoint MediaEndpoint.h + * + * Bluetooth MediaEndpoint. + * + * This class represents a Bluetooth MediaEndpoint. + * + * @note The return value of requests will be sent asynchronously with Request class. + * It is also possible to cancel/reject all requests. + */ +class BLUEZQT_EXPORT MediaEndpoint : public QObject +{ + Q_OBJECT + +public: + /** Role which this mediapoint acts as. */ + enum class Role { + AudioSource, + AudioSink + }; + + /** Codec which this mediapoint supports. */ + enum class Codec { + Sbc, + Aac + }; + + /** Codec which this mediapoint supports. */ + struct Configuration { + Role role; + Codec codec; + }; + + /** + * Creates a new MediaEndpoint object. + * + * @param parent + */ + explicit MediaEndpoint(const Configuration &configuration, QObject *parent = nullptr); + + /** + * Destroys a MediaEndpoint object. + */ + ~MediaEndpoint(); + + /** + * D-Bus object path of the MediaEndpoint. + * + * The path where the MediaEndpoint will be registered. + * + * @note You must provide valid object path! + * + * @return object path of MediaEndpoint + */ + virtual QDBusObjectPath objectPath() const = 0; + + /** + * Properties of the endpoint. + * + * @return Properties of the endpoint + */ + virtual const QVariantMap &properties() const; + + /** + * Set configuration for the transport. + * + * @param transport transport to be configured + * @param properties properties to be set for transport + */ + virtual void setConfiguration(const QString &transportObjectPath, const QVariantMap &properties); + + /** + * Select preferable configuration from the supported capabilities. + * + * @note There is no need to cache the selected configuration since on success + * the configuration is send back as parameter of SetConfiguration. + * + * @param capabilities supported capabilities + * @return configuration which can be used to setup a transport + */ + virtual QByteArray selectConfiguration(const QByteArray &capabilities) const = 0; + + /** + * Clear transport configuration. + */ + virtual void clearConfiguration(const QString &transportObjectPath); + + /** + * Indicates that the MediaEndpoint was unregistered. + * + * This method gets called when the Bluetooth daemon + * unregisters the MediaEndpoint. + * + * An MediaEndpoint can use it to do cleanup tasks. There is no need + * to unregister the MediaEndpoint, because when this method gets called + * it has already been unregistered. + */ + virtual void release(); + +private: + class MediaEndpointPrivate *const d; +}; + +} // namespace BluezQt + +#endif // BLUEZQT_MEDIAENDPOINT_H Index: src/mediaendpoint.cpp =================================================================== --- /dev/null +++ src/mediaendpoint.cpp @@ -0,0 +1,57 @@ +/* + * BluezQt - Asynchronous Bluez wrapper library + * + * Copyright (C) 2018 Manuel Weichselbaumer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#include "mediaendpoint.h" +#include "mediaendpoint_p.h" + +namespace BluezQt +{ + +MediaEndpoint::MediaEndpoint(const Configuration& configuration, QObject *parent) + : QObject(parent), + d(new MediaEndpointPrivate(configuration)) +{ +} + +MediaEndpoint::~MediaEndpoint() +{ + delete d; +} + +const QVariantMap& MediaEndpoint::properties() const +{ + return d->m_properties; +} + +void MediaEndpoint::setConfiguration(const QString& /*transportObjectPath*/, const QVariantMap& /*properties*/) +{ +} + +void MediaEndpoint::clearConfiguration(const QString& /*transportObjectPath*/) +{ +} + +void MediaEndpoint::release() +{ +} + +} // namespace BluezQt Index: src/mediaendpoint_p.h =================================================================== --- /dev/null +++ src/mediaendpoint_p.h @@ -0,0 +1,46 @@ +/* + * BluezQt - Asynchronous Bluez wrapper library + * + * Copyright (C) 2018 Manuel Weichselbaumer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#ifndef BLUEZQT_MEDIAENDPOINT_P_H +#define BLUEZQT_MEDIAENDPOINT_P_H + +#include + +#include "mediaendpoint.h" + +namespace BluezQt +{ + +class MediaEndpointPrivate +{ +public: + explicit MediaEndpointPrivate(const MediaEndpoint::Configuration &configuration); + + void init(const MediaEndpoint::Configuration &configuration); + + QVariantMap m_properties; + MediaEndpoint::Configuration m_configuration; +}; + +} // namespace BluezQt + +#endif // BLUEZQT_MEDIAENDPOINT_P_H Index: src/mediaendpoint_p.cpp =================================================================== --- /dev/null +++ src/mediaendpoint_p.cpp @@ -0,0 +1,63 @@ +/* + * BluezQt - Asynchronous Bluez wrapper library + * + * Copyright (C) 2018 Manuel Weichselbaumer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#include "mediaendpoint_p.h" + +#include "a2dp-codecs.h" + +namespace BluezQt +{ + +MediaEndpointPrivate::MediaEndpointPrivate(const MediaEndpoint::Configuration &configuration) + : m_configuration(configuration) +{ + init(configuration); +} + +void MediaEndpointPrivate::init(const MediaEndpoint::Configuration &configuration) +{ + QString uuid = QStringLiteral("UUID"); + QString codec = QStringLiteral("Codec"); + QString capabilities = QStringLiteral("Capabilities"); + + switch (configuration.role) { + case MediaEndpoint::Role::AudioSource: + m_properties[uuid] = QStringLiteral("0000110a-0000-1000-8000-00805f9b34fb"); + break; + case MediaEndpoint::Role::AudioSink: + m_properties[uuid] = QStringLiteral("0000110b-0000-1000-8000-00805f9b34fb"); + break; + } + + switch (configuration.codec) { + case MediaEndpoint::Codec::Sbc: + m_properties[codec] = uchar(A2DP_CODEC_SBC); + m_properties[capabilities] = QByteArray(); //TODO + break; + case MediaEndpoint::Codec::Aac: + m_properties[codec] = uchar(A2DP_CODEC_MPEG24); + m_properties[capabilities] = QByteArray(); //TODO + break; + } +} + +} // namespace BluezQt Index: src/mediaendpointadaptor.h =================================================================== --- /dev/null +++ src/mediaendpointadaptor.h @@ -0,0 +1,55 @@ +/* + * BluezQt - Asynchronous Bluez wrapper library + * + * Copyright (C) 2018 Manuel Weichselbaumer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#ifndef BLUEZQT_MEDIAENDPOINTADAPTOR_H +#define BLUEZQT_MEDIAENDPOINTADAPTOR_H + +#include + +class QDBusObjectPath; + +namespace BluezQt +{ + +class MediaEndpoint; + +class MediaEndpointAdaptor : public QDBusAbstractAdaptor +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.bluez.MediaEndpoint1") + +public: + explicit MediaEndpointAdaptor(MediaEndpoint *parent); + +public Q_SLOTS: + void SetConfiguration(const QDBusObjectPath &transport, const QVariantMap &properties); + QByteArray SelectConfiguration(const QByteArray &capabilities); + void ClearConfiguration(const QDBusObjectPath &transport); + Q_NOREPLY void Release(); + +private: + MediaEndpoint *m_endpoint; +}; + +} // namespace BluezQt + +#endif // BLUEZQT_MEDIAENDPOINTADAPTOR_H Index: src/mediaendpointadaptor.cpp =================================================================== --- /dev/null +++ src/mediaendpointadaptor.cpp @@ -0,0 +1,57 @@ +/* + * BluezQt - Asynchronous Bluez wrapper library + * + * Copyright (C) 2018 Manuel Weichselbaumer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#include "mediaendpointadaptor.h" +#include "mediaendpoint.h" + +#include + +namespace BluezQt +{ + +MediaEndpointAdaptor::MediaEndpointAdaptor(MediaEndpoint *parent) + : QDBusAbstractAdaptor(parent) + , m_endpoint(parent) +{ +} + +void MediaEndpointAdaptor::SetConfiguration(const QDBusObjectPath &transport, const QVariantMap &properties) +{ + m_endpoint->setConfiguration(transport.path(), properties); +} + +QByteArray MediaEndpointAdaptor::SelectConfiguration(const QByteArray &capabilities) +{ + return m_endpoint->selectConfiguration(capabilities); +} + +void MediaEndpointAdaptor::ClearConfiguration(const QDBusObjectPath &transport) +{ + m_endpoint->clearConfiguration(transport.path()); +} + +void MediaEndpointAdaptor::Release() +{ + m_endpoint->release(); +} + +} // namespace BluezQt Index: src/pendingcall.h =================================================================== --- src/pendingcall.h +++ src/pendingcall.h @@ -192,6 +192,7 @@ friend class Manager; friend class Adapter; friend class Device; + friend class Media; friend class MediaPlayer; friend class ObexManager; friend class ObexTransfer;