Media API
Subsystems (2)
Luiz Augusto von Dentz
maintainercover Media API
From: Luiz Augusto von Dentz <[email protected]>
Hi,
Now that DBus 1.4 has finally been released I guess it is time to integrate the Media API that I've been working since the beginning of the year. For those not aware of what it is about the discussion can be found here:
http://thread.gmane.org/gmane.linux.bluez.kernel/4125
For now it is disabled by default to avoid a build dependency on DBus 1.4 and to buy some time while Im working to getting it working reliably with PulseAudio. To enable it just add the following to /etc/bluetooth/audio.conf (won't work if DBus is < 1.3 but better use 1.3.1 or latter):
Enable=<...,>Media
It can be used together with old unix socket, but I also add the possibility to complete disable it by doing (highly suggested if the system is running PA):
Disable=<...,>Socket
To register endpoint test/simple-endpoint can be used, note that it will not stream anything, it basically configure a transport object which can be used by e.g. gstreamer plugin:
$./simple-endpoint
dbus.Dictionary({'Codec': dbus.Byte(0), 'UUID': '0000110A-0000-1000-8000-00805F9B34FB', 'DelayReporting': True, 'Capabilities': dbus.Array([dbus.Byte(255), dbus.Byte(255), dbus.Byte(2), dbus.Byte(64)], signature=None)}, signature=None) SelectConfiguration (dbus.Array([dbus.Byte(255), dbus.Byte(255), dbus.Byte(2), dbus.Byte(32)], signature=dbus.Signature('y')))
SetConfiguration (/org/bluez/16530/hci0/dev_00_0D_3C_B1_DD_56/fd0, dbus.Array([dbus.Byte(33), dbus.Byte(21), dbus.Byte(2), dbus.Byte(32)], signature=dbus.Signature('y')))
$gst-launch-0.10 filesrc location=<file to stream> ! decodebin ! audioconvert ! sbcenc ! a2dpsink transport=/org/bluez/16530/hci0/dev_00_0D_3C_B1_DD_56/fd0
Or for mp3:
$./simple-endpoint hci0 mp3source
dbus.Dictionary({'Codec': dbus.Byte(1), 'UUID': '0000110A-0000-1000-8000-00805F9B34FB', 'Capabilities': dbus.Array([dbus.Byte(63), dbus.Byte(7), dbus.Byte(255), dbus.Byte(254)], signature=None)}, signature=None) SelectConfiguration (dbus.Array([dbus.Byte(63), dbus.Byte(7), dbus.Byte(255), dbus.Byte(254)], signature=dbus.Signature('y')))
SetConfiguration (/org/bluez/15317/hci0/dev_00_0D_3C_B1_DD_56/fd2, dbus.Array([dbus.Byte(33), dbus.Byte(2), dbus.Byte(0), dbus.Byte(128)], signature=dbus.Signature('y')))
$gst-launch-0.10 filesrc location=<file to stream> ! mp3parse ! a2dpsink transport=/org/bluez/15317/hci0/dev_00_0D_3C_B1_DD_56/fd2
Endpoints can be used with old unix socket so it should not break anything if Media API got enabled but Socket doesn't got disabled, but note that PA will probably try to use/lock if one register a sbcsource.
There are things that doesn't work though:
- Simple-endpoint uses fixed configuration for sbc and mp3, also it should probably support streaming and more codecs via gstreamer to make it easier to test.
- A2dp setconf callback need to be change since right now it expect a return from the endpoint but in case of MediaEndpoit this has to be async. For now it will block while waiting for SetConfiguration reply of the endpoint. Also to support BlueZ x BlueZ streams this has to take less than 4 sec. otherwise it will timeout on the requestor side, so timeout for SetConfiguration is set to 3 sec.
- Properties such as Delay, NREC and InbandRingtone are not really writeable right now.
Luiz Augusto von Dentz (10):
Add media API documentation
Add rule to enabling talking to org.bluez.MediaEndpoint Add option to enable/disable unix ipc via audio.conf Add support for media transport in gstreamer plugin Add simple-endpoint test script
Add initial implementation of org.bluez.Media spec Introduce headset_get_inband
Update a2dp transport delay when it changes Remove local cache for nrec and inband
Add proper checks for MediaTransport.SetProperty
Makefile.am | 6 +- audio/a2dp-codecs.h | 116 ++++++++ audio/a2dp.c | 749 +++++++++++++++++++++++++++++++++++++++++-------- audio/a2dp.h | 15 + audio/avdtp.c | 88 +++---- audio/avdtp.h | 5 +- audio/gsta2dpsink.c | 33 ++- audio/gsta2dpsink.h | 1 + audio/gstavdtpsink.c | 609 +++++++++++++++++++++++++++++++++++++++- audio/gstavdtpsink.h | 6 + audio/headset.c | 10 + audio/headset.h | 1 + audio/main.c | 9 - audio/manager.c | 66 +++++ audio/manager.h | 2 + audio/media.c | 689 +++++++++++++++++++++++++++++++++++++++++++++ audio/media.h | 54 ++++ audio/sink.c | 179 ++----------- audio/source.c | 174 ++---------- audio/transport.c | 758 ++++++++++++++++++++++++++++++++++++++++++++++++++ audio/transport.h | 36 +++ audio/unix.c | 1 + doc/media-api.txt | 169 +++++++++++ src/bluetooth.conf | 1 + test/simple-endpoint | 126 +++++++++ 25 files changed, 3395 insertions(+), 508 deletions(-) create mode 100644 audio/a2dp-codecs.h create mode 100644 audio/media.c create mode 100644 audio/media.h create mode 100644 audio/transport.c create mode 100644 audio/transport.h create mode 100644 doc/media-api.txt create mode 100755 test/simple-endpoint
Luiz Augusto von Dentz
maintainerPATCH 1/10 Add media API documentation
From: Luiz Augusto von Dentz <[email protected]>
Media API is a replacement for the internal audio IPC which is no longer necessary as DBus 1.3 and newer are capable of transfering file descriptors.
--- doc/media-api.txt | 169 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 169 insertions(+), 0 deletions(-) create mode 100644 doc/media-api.txt
doc/media-api.txt new file +169 -0
@@ -0,0 +1,169 @@ +BlueZ D-Bus Media API description +********************************* + +Media hierarchy +=============== + +Service org.bluez +Interface org.bluez.Media +Object path [variable prefix]/{hci0,hci1,...} + +Methods void RegisterEndpoint(object endpoint, dict properties) + + 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 properties: + + string UUID: + + UUID of the profile which the endpoint + is for. + + byte Codec: + + Assigned mumber of codec that the + endpoint implements. The values should + match the profile specification which + is indicated by the UUID. + + array{byte} Capabilities: + + Capabilities blob, it is used as it is + so the size and byte order must match. + + void UnregisterEndpoint(object endpoint) + + Unregister sender end point. + +MediaEndpoint hierarchy +======================= + +Service unique name +Interface org.bluez.MediaEndpoint +Object path freely definable + +Methods void SetConfiguration(object transport, array{byte} configuration) + + Set configuration for the transport. + + array{byte} SelectConfiguration(array{byte} capabilities) + + Select preferable configuration from the supported + capabilities. + + Returns a configuration which can be used to setup + a transport. + + Note: There is no need to cache the selected + configuration since on success the configuration is + send back as parameter of SetConfiguration. + + void ClearConfiguration() + + Clear any configuration set. + + void Release() + + This method gets called when the service daemon + unregisters the endpoint. An endpoint can use it to do + cleanup tasks. There is no need to unregister the + endpoint, because when this method gets called it has + already been unregistered. + +MediaTransport hierarchy +======================== + +Service org.bluez +Interface org.bluez.MediaTransport +Object path [variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX/fdX + +Methods dict GetProperties() + + Returns all properties for the interface. See the + properties section for available properties. + + fd Acquire(string accesstype) + + Acquire transport file descriptor. + + possible accesstype: + + "r" : Read only access + + "w" : Write only access + + "rw": Read and write access + + void Release(string accesstype) + + Releases file descriptor. + + void SetProperty(string name, variant value) + + Changes the value of the specified property. Only + properties that are listed a read-write can be changed. + + On success this will emit a PropertyChanged signal. + +Signals void PropertyChanged(string name, variant value) + + This signal indicates a changed value of the given + property. + +Properties object Device [readonly] + + Device object which the transport is connected to. + + boolean ReadLock [readonly] + + Transport read lock. + + boolean WriteLock [readonly] + + Transport read lock. + + uint16 IMTU [readonly] + + Transport input MTU. + + uint16 OMTU [readonly] + + Transport output MTU. + + string UUID [readonly] + + UUID of the profile which the transport is for. + + byte Codec [readonly] + + Assigned mumber of codec that the transport support. + The values should match the profile specification which + is indicated by the UUID. + + array{byte} Configuration [readonly] + + Configuration blob, it is used as it is so the size and + byte order must match. + + uint16 Delay [readwrite] + + Optional. Transport delay in 1/10 of milisecond, this + property is only writeable when the transport was + acquired by the sender. + + boolean NREC [readwrite] + + Optional. Indicates if echo cancelling and noise + reduction functions are active in the transport, this + property is only writeable when the transport was + acquired by the sender. + + boolean InbandRingtone [readwrite] + + Optional. Indicates if the transport support sending + ringtones, this property is only writeable when the + transport was acquired by the sender.
Signature · 1 line
1.7.1
Luiz Augusto von Dentz
maintainerPATCH 2/10 Add rule to enabling talking to org.bluez.MediaEndpoint
In reply to Luiz Augusto von DentzFrom: Luiz Augusto Von Dentz <[email protected]>
--- src/bluetooth.conf | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
src/bluetooth.conf +1 -0
@@ -12,6 +12,7 @@ <allow send_destination="org.bluez"/> <allow send_interface="org.bluez.Agent"/> <allow send_interface="org.bluez.HandsfreeAgent"/> + <allow send_interface="org.bluez.MediaEndpoint"/> </policy> <policy at_console="true">
Signature · 1 line
1.7.1
Luiz Augusto von Dentz
maintainerPATCH 3/10 Add option to enable/disable unix ipc via audio.conf
In reply to Luiz Augusto von DentzFrom: Luiz Augusto Von Dentz <[email protected]>
--- audio/main.c | 9 --------- audio/manager.c | 12 ++++++++++++ audio/manager.h | 1 + 3 files changed, 13 insertions(+), 9 deletions(-)
audio/main.c +0 -9
@@ -42,7 +42,6 @@#include "plugin.h" #include "log.h" #include "device.h" -#include "unix.h" #include "headset.h" #include "manager.h" #include "gateway.h"
@@ -151,11 +150,6 @@ static int audio_init(void) config =load_config_file (CONFIGDIR "/audio.conf" ); -if (unix_init () <0 ) { -error ("Unable to setup unix socket" ); - goto failed; - } -if (audio_manager_init (connection, config, &enable_sco) <0 ) goto failed;
@@ -174,7 +168,6 @@ static int audio_init(void) failed:audio_manager_exit (); -unix_exit ();if (connection) {dbus_connection_unref (connection);
@@ -194,8 +187,6 @@ static void audio_exit(void)audio_manager_exit (); -unix_exit (); -dbus_connection_unref (connection); }
audio/manager.c +12 -0
@@ -70,6 +70,7 @@#include "manager.h" #include "sdpd.h" #include "telephony.h" +#include "unix.h" typedef enum { HEADSET = 1 << 0,
@@ -113,6 +114,7 @@ static struct enabled_interfaces enabled = { .sink = TRUE, .source = FALSE, .control = TRUE, + .socket = TRUE, }; static struct audio_adapter *find_adapter(GSList *list,
@@ -1074,6 +1076,8 @@ int audio_manager_init(DBusConnection *conn, GKeyFile *conf, enabled.source = TRUE; else if (g_str_equal(list[i], "Control")) enabled.control = TRUE; + else if (g_str_equal(list[i], "Socket")) + enabled.socket = TRUE; }g_strfreev (list);
@@ -1090,6 +1094,8 @@ int audio_manager_init(DBusConnection *conn, GKeyFile *conf, enabled.source = FALSE; else if (g_str_equal(list[i], "Control")) enabled.control = FALSE; + else if (g_str_equal(list[i], "Socket")) + enabled.socket = FALSE; }g_strfreev (list);
@@ -1117,6 +1123,9 @@ int audio_manager_init(DBusConnection *conn, GKeyFile *conf, max_connected_headsets = i; proceed: +if (enabled.socket) +unix_init (); +if (enabled.headset) {telephony_init ();btd_register_adapter_driver (&headset_server_driver);
@@ -1152,6 +1161,9 @@ void audio_manager_exit(void) config =NULL ; } +if (enabled.socket) +unix_exit (); +if (enabled.headset) {btd_unregister_adapter_driver (&headset_server_driver);telephony_exit ();
audio/manager.h +1 -0
@@ -29,6 +29,7 @@ struct enabled_interfaces {gboolean sink;gboolean source;gboolean control; +gboolean socket; }; int audio_manager_init(DBusConnection *conn, GKeyFile *config,
Signature · 1 line
1.7.1
Luiz Augusto von Dentz
maintainerPATCH 4/10 Add support for media transport in gstreamer plugin
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
--- Makefile.am | 4 +- audio/a2dp-codecs.h | 116 ++++++++++ audio/gsta2dpsink.c | 33 +++- audio/gsta2dpsink.h | 1 + audio/gstavdtpsink.c | 609 +++++++++++++++++++++++++++++++++++++++++++++++++- audio/gstavdtpsink.h | 6 + 6 files changed, 757 insertions(+), 12 deletions(-) create mode 100644 audio/a2dp-codecs.h
Makefile.am +2 -2
@@ -307,9 +307,9 @@ audio_libgstbluetooth_la_SOURCES = audio/gstbluetooth.c audio/gstpragma.h \ audio/rtp.h audio/ipc.h audio/ipc.c audio_libgstbluetooth_la_LDFLAGS = -module -avoid-version audio_libgstbluetooth_la_LIBADD = sbc/libsbc.la lib/libbluetooth.la \ - @GSTREAMER_LIBS@ -lgstaudio-0.10 -lgstrtp-0.10 + @DBUS_LIBS@ @GSTREAMER_LIBS@ -lgstaudio-0.10 -lgstrtp-0.10 audio_libgstbluetooth_la_CFLAGS = -fvisibility=hidden -fno-strict-aliasing \ - $(AM_CFLAGS) @GSTREAMER_CFLAGS@ + $(AM_CFLAGS) @DBUS_CFLAGS@ @GSTREAMER_CFLAGS@ endif endif
audio/a2dp-codecs.h new file +116 -0
116 lines not on this page · raw message
audio/gsta2dpsink.c +31 -2
@@ -44,7 +44,8 @@ GST_DEBUG_CATEGORY_STATIC(gst_a2dp_sink_debug);enum {PROP_0 ,PROP_DEVICE , -PROP_AUTOCONNECT +PROP_AUTOCONNECT , +PROP_TRANSPORT };GST_BOILERPLATE (GstA2dpSink, gst_a2dp_sink, GstBin,GST_TYPE_BIN );
@@ -175,6 +176,16 @@ static void gst_a2dp_sink_set_property(GObject *object, guint prop_id, self->device =g_value_dup_string (value);break ; +case PROP_TRANSPORT : +if (self->sink !=NULL ) +gst_avdtp_sink_set_transport (self->sink, +g_value_get_string (value)); + +if (self->transport !=NULL ) +g_free (self->transport); + self->transport =g_value_dup_string (value); +break ; +case PROP_AUTOCONNECT : self->autoconnect =g_value_get_boolean (value);
@@ -193,7 +204,7 @@ static void gst_a2dp_sink_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) {GstA2dpSink *self =GST_A2DP_SINK (object); -gchar *device; +gchar *device, *transport;switch (prop_id) {case PROP_DEVICE :
@@ -210,6 +221,13 @@ static void gst_a2dp_sink_get_property(GObject *object, guint prop_id,g_value_set_boolean (value, self->autoconnect);break ; +case PROP_TRANSPORT : +if (self->sink !=NULL ) { + transport =gst_avdtp_sink_get_transport (self->sink); +if (transport !=NULL ) +g_value_take_string (value, transport); + } +break ;default :G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);break ;
@@ -285,6 +303,10 @@ static GstStateChangeReturn gst_a2dp_sink_change_state(GstElement *element,gst_avdtp_sink_set_device (self->sink, self->device); +if (self->transport !=NULL ) +gst_avdtp_sink_set_transport (self->sink, + self->transport); +g_object_set (G_OBJECT (self->sink),"auto-connect" , self->autoconnect,NULL );
@@ -365,6 +387,11 @@ static void gst_a2dp_sink_class_init(GstA2dpSinkClass *klass)"Automatically attempt to connect to device" , DEFAULT_AUTOCONNECT, G_PARAM_READWRITE)); +g_object_class_install_property (object_class,PROP_TRANSPORT , +g_param_spec_string ("transport" ,"Transport" , +"Use configured transport" , +NULL ,G_PARAM_READWRITE )); +GST_DEBUG_CATEGORY_INIT (gst_a2dp_sink_debug,"a2dpsink" ,0 ,"A2DP sink element" ); }
@@ -437,6 +464,7 @@ static gboolean gst_a2dp_sink_init_avdtp_sink(GstA2dpSink *self) self->sink =GST_AVDTP_SINK (sink); self->sink_is_in_bin = TRUE;g_object_set (G_OBJECT (self->sink),"device" , self->device,NULL ); +g_object_set (G_OBJECT (self->sink),"transport" , self->transport,NULL );gst_element_set_state (sink,GST_STATE_PAUSED );
@@ -674,6 +702,7 @@ static void gst_a2dp_sink_init(GstA2dpSink *self, self->fakesink =NULL ; self->rtp =NULL ; self->device =NULL ; + self->transport =NULL ; self->autoconnect =DEFAULT_AUTOCONNECT ; self->capsfilter =NULL ; self->newseg_event =NULL ;
audio/gsta2dpsink.h +1 -0
@@ -53,6 +53,7 @@ struct _GstA2dpSink {GstElement *fakesink;gchar *device; +gchar *transport;gboolean autoconnect;gboolean sink_is_in_bin;
audio/gstavdtpsink.c +601 -8
741 lines not on this page · raw message
audio/gstavdtpsink.h +6 -0
@@ -51,6 +51,7 @@ struct _GstAvdtpSink {GstBaseSink sink;gchar *device; +gchar *transport;GIOChannel *stream;struct bluetooth_data *data;
@@ -86,8 +87,13 @@ guint gst_avdtp_sink_get_link_mtu(GstAvdtpSink *sink);void gst_avdtp_sink_set_device (GstAvdtpSink *sink,const gchar * device); +void gst_avdtp_sink_set_transport (GstAvdtpSink *sink, +const gchar *transport); +gchar *gst_avdtp_sink_get_device (GstAvdtpSink *sink); +gchar *gst_avdtp_sink_get_transport (GstAvdtpSink *sink); +gboolean gst_avdtp_sink_plugin_init (GstPlugin *plugin);void gst_avdtp_sink_set_crc (GstAvdtpSink *self,gboolean crc);
Signature · 1 line
1.7.1
Luiz Augusto von Dentz
maintainerPATCH 5/10 Add simple-endpoint test script
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
--- test/simple-endpoint | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 126 insertions(+), 0 deletions(-) create mode 100755 test/simple-endpoint
test/simple-endpoint new file +126 -0
@@ -0,0 +1,126 @@ +#!/usr/bin/python + +import sys +import dbus +import dbus.service +import dbus.mainloop.glib +import gobject + +A2DP_SOURCE_UUID = "0000110A-0000-1000-8000-00805F9B34FB" +A2DP_SINK_UUID = "0000110B-0000-1000-8000-00805F9B34FB" +HFP_AG_UUID = "0000111F-0000-1000-8000-00805F9B34FB" +HSP_AG_UUID = "00001112-0000-1000-8000-00805F9B34FB" + +SBC_CODEC = dbus.Byte(0x00) +#Channel Modes: Mono DualChannel Stereo JointStereo +#Frequencies: 16Khz 32Khz 44.1Khz 48Khz +#Subbands: 4 8 +#Blocks: 4 8 12 16 +#Bitpool Range: 2-64 +SBC_CAPABILITIES = dbus.Array([dbus.Byte(0xff), dbus.Byte(0xff), dbus.Byte(2), dbus.Byte(64)]) +# JointStereo 44.1Khz Subbands: Blocks: 16 Bitpool Range: 2-32 +SBC_CONFIGURATION = dbus.Array([dbus.Byte(0x21), dbus.Byte(0x15), dbus.Byte(2), dbus.Byte(32)]) + +MP3_CODEC = dbus.Byte(0x01) +#Channel Modes: Mono DualChannel Stereo JointStereo +#Frequencies: 32Khz 44.1Khz 48Khz +#CRC: YES +#Layer: 3 +#Bit Rate: All except Free format +#VBR: Yes +#Payload Format: RFC-2250 +MP3_CAPABILITIES = dbus.Array([dbus.Byte(0x3f), dbus.Byte(0x07), dbus.Byte(0xff), dbus.Byte(0xfe)]) +# JointStereo 44.1Khz Layer: 3 Bit Rate: VBR Format: RFC-2250 +MP3_CONFIGURATION = dbus.Array([dbus.Byte(0x21), dbus.Byte(0x02), dbus.Byte(0x00), dbus.Byte(0x80)]) + +PCM_CODEC = dbus.Byte(0x00) +PCM_CONFIGURATION = dbus.Array([], signature="ay") + +class Rejected(dbus.DBusException): + _dbus_error_name = "org.bluez.Error.Rejected" + +class Endpoint(dbus.service.Object): + exit_on_release = True + configuration = SBC_CONFIGURATION + + def set_exit_on_release(self, exit_on_release): + self.exit_on_release = exit_on_release + + def default_configuration(self, configuration): + self.configuration = configuration + + @dbus.service.method("org.bluez.MediaEndpoint", + in_signature="", out_signature="") + def Release(self): + print "Release" + if self.exit_on_release: + mainloop.quit() + + @dbus.service.method("org.bluez.MediaEndpoint", + in_signature="", out_signature="") + def ClearConfiguration(self): + print "ClearConfiguration" + + @dbus.service.method("org.bluez.MediaEndpoint", + in_signature="oay", out_signature="") + def SetConfiguration(self, transport, config): + print "SetConfiguration (%s, %s)" % (transport, config) + return + + @dbus.service.method("org.bluez.MediaEndpoint", + in_signature="ay", out_signature="ay") + def SelectConfiguration(self, caps): + print "SelectConfiguration (%s)" % (caps) + return self.configuration + +if __name__ == '__main__': + dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) + + bus = dbus.SystemBus() + manager = dbus.Interface(bus.get_object("org.bluez", "/"), + "org.bluez.Manager") + + if len(sys.argv) > 1: + path = manager.FindAdapter(sys.argv[1]) + else: + path = manager.DefaultAdapter() + + media = dbus.Interface(bus.get_object("org.bluez", path), + "org.bluez.Media") + + path = "/test/endpoint" + endpoint = Endpoint(bus, path) + mainloop = gobject.MainLoop() + + properties = dbus.Dictionary({ "UUID" : A2DP_SOURCE_UUID, + "Codec" : SBC_CODEC, + "DelayReporting" : True, + "Capabilities" : SBC_CAPABILITIES }) + + if len(sys.argv) > 2: + if sys.argv[2] == "sbcsink": + properties = dbus.Dictionary({ "UUID" : A2DP_SINK_UUID, + "Codec" : SBC_CODEC, + "DelayReporting" : True, + "Capabilities" : SBC_CAPABILITIES }) + if sys.argv[2] == "mp3source": + properties = dbus.Dictionary({ "UUID" : A2DP_SOURCE_UUID, + "Codec" : MP3_CODEC, + "Capabilities" : MP3_CAPABILITIES }) + endpoint.default_configuration(MP3_CONFIGURATION) + if sys.argv[2] == "mp3sink": + properties = dbus.Dictionary({ "UUID" : A2DP_SINK_UUID, + "Codec" : MP3_CODEC, + "Capabilities" : MP3_CAPABILITIES }) + endpoint.default_configuration(MP3_CONFIGURATION) + if sys.argv[2] == "hfpag" or sys.argv[2] == "hspag": + properties = dbus.Dictionary({ "UUID" : HFP_AG_UUID, + "Codec" : PCM_CODEC, + "Capabilities" : PCM_CONFIGURATION }) + endpoint.default_configuration(dbus.Array([])) + + print properties + + media.RegisterEndpoint(path, properties) + + mainloop.run()
Signature · 1 line
1.7.1
Luiz Augusto von Dentz
maintainerPATCH 6/10 Add initial implementation of org.bluez.Media spec
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
--- Makefile.am | 2 + audio/a2dp.c | 726 ++++++++++++++++++++++++++++++++++++++++++++--------- audio/a2dp.h | 15 ++ audio/avdtp.c | 88 +++---- audio/avdtp.h | 5 +- audio/manager.c | 54 ++++ audio/manager.h | 1 + audio/media.c | 683 +++++++++++++++++++++++++++++++++++++++++++++++++ audio/media.h | 52 ++++ audio/sink.c | 179 ++------------ audio/source.c | 174 ++----------- audio/transport.c | 671 +++++++++++++++++++++++++++++++++++++++++++++++++ audio/transport.h | 34 +++ audio/unix.c | 1 + 14 files changed, 2198 insertions(+), 487 deletions(-) create mode 100644 audio/media.c create mode 100644 audio/media.h create mode 100644 audio/transport.c create mode 100644 audio/transport.h
Makefile.am +2 -0
@@ -139,6 +139,8 @@ builtin_sources += audio/main.c \ audio/avdtp.h audio/avdtp.c \ audio/ipc.h audio/ipc.c \ audio/unix.h audio/unix.c \ + audio/media.h audio/media.c \ + audio/transport.h audio/transport.c \ audio/telephony.h builtin_nodist += audio/telephony.c
audio/a2dp.c +603 -123
932 lines not on this page · raw message
audio/a2dp.h +15 -0
@@ -121,6 +121,10 @@ struct mpeg_codec_cap {struct a2dp_sep ; + +typedef void (*a2dp_select_cb_t ) (struct avdtp *session, +struct a2dp_sep *sep,GSList *caps, +void *user_data); typedef void (*a2dp_config_cb_t) (struct avdtp *session, struct a2dp_sep *sep, struct avdtp_stream *stream, struct avdtp_error *err,
@@ -132,7 +136,17 @@ typedef void (*a2dp_stream_cb_t) (struct avdtp *session,int a2dp_register (DBusConnection *conn,const bdaddr_t *src,GKeyFile *config);void a2dp_unregister (const bdaddr_t *src); +struct a2dp_sep *a2dp_add_sep (const bdaddr_t *src,uint8_t type, +uint8_t codec,gboolean delay_reporting, +struct media_endpoint *endpoint); +void a2dp_remove_sep (struct a2dp_sep *sep); +struct a2dp_sep *a2dp_get (struct avdtp *session,struct avdtp_remote_sep *sep); + +unsigned int a2dp_select_capabilities (struct avdtp *session, +uint8_t type,const char *sender, +a2dp_select_cb_t cb, +void *user_data);unsigned int a2dp_config (struct avdtp *session,struct a2dp_sep *sep,a2dp_config_cb_t cb,GSList *caps,void *user_data);
@@ -145,5 +159,6 @@ gboolean a2dp_cancel(struct audio_device *dev, unsigned int id);gboolean a2dp_sep_lock (struct a2dp_sep *sep,struct avdtp *session);gboolean a2dp_sep_unlock (struct a2dp_sep *sep,struct avdtp *session);gboolean a2dp_sep_get_lock (struct a2dp_sep *sep); +struct avdtp_stream *a2dp_sep_get_stream (struct a2dp_sep *sep);struct a2dp_sep *a2dp_get_sep (struct avdtp *session,struct avdtp_stream *stream);
audio/avdtp.c +34 -54
119 lines not on this page · raw message
audio/avdtp.h +2 -3
@@ -290,9 +290,8 @@ struct avdtp_local_sep *avdtp_register_sep(const bdaddr_t *src, uint8_t type, void *user_data);/* Find a matching pair of local and remote SEP ID's */ -int avdtp_get_seps (struct avdtp *session,uint8_t type,uint8_t media, -uint8_t codec,struct avdtp_local_sep **lsep, -struct avdtp_remote_sep **rsep); +struct avdtp_remote_sep *avdtp_find_remote_sep (struct avdtp *session, +struct avdtp_local_sep *lsep);int avdtp_unregister_sep (struct avdtp_local_sep *sep);
audio/manager.c +54 -0
108 lines not on this page · raw message
audio/manager.h +1 -0
@@ -30,6 +30,7 @@ struct enabled_interfaces {gboolean source;gboolean control;gboolean socket; +gboolean media; }; int audio_manager_init(DBusConnection *conn, GKeyFile *config,
audio/media.c new file +683 -0
683 lines not on this page · raw message
audio/media.h new file +52 -0
52 lines not on this page · raw message
audio/sink.c +22 -157
208 lines not on this page · raw message
audio/source.c +24 -150
205 lines not on this page · raw message
audio/transport.c new file +671 -0
634 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.1
Part of the diff is not shown here. View the raw message.
Luiz Augusto von Dentz
maintainerPATCH 7/10 Introduce headset_get_inband
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
--- audio/headset.c | 10 ++++++++++ audio/headset.h | 1 + 2 files changed, 11 insertions(+), 0 deletions(-)
audio/headset.c +10 -0
@@ -2701,6 +2701,16 @@ gboolean headset_get_nrec(struct audio_device *dev)return hs->slc->nrec; } +gboolean headset_get_inband (struct audio_device *dev) +{ +struct headset *hs = dev->headset; + +if (!hs->slc) +return TRUE; + +return hs->slc->inband_ring; +} +gboolean headset_get_sco_hci (struct audio_device *dev) {return sco_hci;
audio/headset.h +1 -0
@@ -90,6 +90,7 @@ int headset_get_channel(struct audio_device *dev);int headset_get_sco_fd (struct audio_device *dev);gboolean headset_get_nrec (struct audio_device *dev); +gboolean headset_get_inband (struct audio_device *dev);gboolean headset_get_sco_hci (struct audio_device *dev);gboolean headset_is_active (struct audio_device *dev);
Signature · 1 line
1.7.1
Luiz Augusto von Dentz
maintainerPATCH 8/10 Update a2dp transport delay when it changes
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
--- audio/a2dp.c | 31 +++++++++++++++++++++++++++---- audio/media.c | 6 ++++++ audio/media.h | 2 ++ audio/transport.c | 14 ++++++++++++++ audio/transport.h | 2 ++ 5 files changed, 51 insertions(+), 4 deletions(-)
audio/a2dp.c +27 -4
@@ -44,6 +44,7 @@#include "source.h" #include "unix.h" #include "media.h" +#include "transport.h" #include "a2dp.h" #include "sdpd.h"
@@ -600,9 +601,9 @@ static gboolean endpoint_setconf_ind(struct avdtp *session, }static gboolean endpoint_getcap_ind (struct avdtp *session, -struct avdtp_local_sep *sep, -gboolean get_all, -GSList **caps,uint8_t *err,void *user_data) +struct avdtp_local_sep *sep, +gboolean get_all,GSList **caps, +uint8_t *err,void *user_data) {struct a2dp_sep *a2dp_sep = user_data;struct avdtp_service_capability *media_transport, *media_codec;
@@ -1031,6 +1032,28 @@ static gboolean delayreport_ind(struct avdtp *session,return TRUE; } +static gboolean endpoint_delayreport_ind (struct avdtp *session, +struct avdtp_local_sep *sep, +uint8_t rseid,uint16_t delay, +uint8_t *err,void *user_data) +{ +struct a2dp_sep *a2dp_sep = user_data; +struct media_transport *transport; + +if (a2dp_sep->type ==AVDTP_SEP_TYPE_SINK ) +DBG ("Sink %p: DelayReport_Ind" , sep); +else +DBG ("Source %p: DelayReport_Ind" , sep); + + transport =media_endpoint_get_transport (a2dp_sep->endpoint); +if (transport ==NULL ) +return FALSE; + +media_transport_update_delay (transport, delay); + +return TRUE; +} +static void reconf_cfm (struct avdtp *session,struct avdtp_local_sep *sep,struct avdtp_stream *stream,struct avdtp_error *err,void *user_data)
@@ -1115,7 +1138,7 @@ static struct avdtp_sep_ind endpoint_ind = { .close = close_ind, .abort = abort_ind, .reconfigure = reconf_ind, - .delayreport = delayreport_ind, + .delayreport = endpoint_delayreport_ind, };static sdp_record_t *a2dp_record (uint8_t type,uint16_t avdtp_ver)
audio/media.c +6 -0
@@ -681,3 +681,9 @@ uint8_t media_endpoint_get_codec(struct media_endpoint *endpoint) {return endpoint->codec; } + +struct media_transport *media_endpoint_get_transport ( +struct media_endpoint *endpoint) +{ +return endpoint->transport; +}
audio/media.h +2 -0
@@ -50,3 +50,5 @@ void media_endpoint_release(struct media_endpoint *endpoint);struct a2dp_sep *media_endpoint_get_sep (struct media_endpoint *endpoint);const char *media_endpoint_get_uuid (struct media_endpoint *endpoint);uint8_t media_endpoint_get_codec (struct media_endpoint *endpoint); +struct media_transport *media_endpoint_get_transport ( +struct media_endpoint *endpoint);
audio/transport.c +14 -0
@@ -669,3 +669,17 @@ const char *media_transport_get_path(struct media_transport *transport) {return transport->path; } + +void media_transport_update_delay (struct media_transport *transport, +uint16_t delay) +{ +/* Check if delay really changed */ +if (transport->delay == delay) +return ; + + transport->delay = delay; + +emit_property_changed (transport->conn, transport->path, +MEDIA_TRANSPORT_INTERFACE ,"Delay" , +DBUS_TYPE_UINT16 , &transport->delay); +}
audio/transport.h +2 -0
@@ -32,3 +32,5 @@ struct media_transport *media_transport_create(DBusConnection *conn,void media_transport_remove (struct media_transport *transport);const char *media_transport_get_path (struct media_transport *transport); +void media_transport_update_delay (struct media_transport *transport, +uint16_t delay);
Signature · 1 line
1.7.1
Luiz Augusto von Dentz
maintainerPATCH 9/10 Remove local cache for nrec and inband
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Those can be acessed directly from device/headset.
--- audio/transport.c | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-)
audio/transport.c +6 -5
@@ -72,8 +72,6 @@ struct media_transport {uint16_t imtu;/* Transport input mtu */ uint16_t omtu;/* Transport output mtu */ uint16_t delay;/* Transport delay (a2dp only) */ -gboolean nrec;/* Transport nrec (hfp only) */ -gboolean inband;/* Transport inband ringtone support (hfp only) */ gboolean read_lock;gboolean write_lock;gboolean in_use;
@@ -519,10 +517,13 @@ static void get_properties_a2dp(struct media_transport *transport,static void get_properties_headset (struct media_transport *transport,DBusMessageIter *dict) { -dict_append_entry (dict,"NREC" ,DBUS_TYPE_BOOLEAN , &transport->nrec); +gboolean nrec, inband; -dict_append_entry (dict,"InbandRingtone" ,DBUS_TYPE_BOOLEAN , - &transport->inband); + nrec =headset_get_nrec (transport->device); +dict_append_entry (dict,"NREC" ,DBUS_TYPE_BOOLEAN , &nrec); + + inband =headset_get_inband (transport->device); +dict_append_entry (dict,"InbandRingtone" ,DBUS_TYPE_BOOLEAN , &inband); } static DBusMessage *get_properties(DBusConnection *conn, DBusMessage *msg,
Signature · 1 line
1.7.1
Luiz Augusto von Dentz
maintainerPATCH 10/10 Add proper checks for MediaTransport.SetProperty
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
--- audio/transport.c | 116 +++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 94 insertions(+), 22 deletions(-)
audio/transport.c +94 -22
@@ -83,12 +83,23 @@ struct media_transport {void (*get_properties) (struct media_transport *transport,DBusMessageIter *dict); -DBusMessage *(*set_property) ( +int (*set_property) (struct media_transport *transport, -DBusConnection *conn, -DBusMessage *msg); +const char *property, +DBusMessageIter *value); }; +static inline DBusMessage *invalid_args (DBusMessage *msg) +{ +return g_dbus_create_error (msg,ERROR_INTERFACE ".InvalidArguments" , +"Invalid arguments in method call" ); +} + +static inline DBusMessage *error_failed (DBusMessage *msg,const char *desc) +{ +return g_dbus_create_error (msg,ERROR_INTERFACE ".Failed" ,"%s" , desc); +} +void media_transport_remove (struct media_transport *transport) {char *path;
@@ -434,14 +445,10 @@ static DBusMessage *acquire(DBusConnection *conn, DBusMessage *msg, renderer =media_transport_find_renderer (transport, sender);if (renderer !=NULL ) -return g_dbus_create_error (msg,ERROR_INTERFACE -".Failed" , -"Permission denied" ); +return error_failed (msg,strerror (EPERM ));if (media_transport_acquire (transport, accesstype) == FALSE) -return g_dbus_create_error (msg,ERROR_INTERFACE -".Failed" , -"Permission denied" ); +return error_failed (msg,strerror (EPERM )); renderer =media_renderer_create (transport, msg, accesstype); req = g_new0(struct acquire_request, 1);
@@ -471,9 +478,7 @@ static DBusMessage *release(DBusConnection *conn, DBusMessage *msg, renderer =media_transport_find_renderer (transport, sender);if (renderer ==NULL ) -return g_dbus_create_error (msg,ERROR_INTERFACE -".Failed" , -"Permission denied" ); +return error_failed (msg,strerror (EPERM ));if (g_strcmp0 (renderer->accesstype, accesstype) ==0 )media_renderer_remove (renderer);
@@ -481,31 +486,98 @@ static DBusMessage *release(DBusConnection *conn, DBusMessage *msg,media_transport_release (transport, accesstype);g_strdelimit (renderer->accesstype, accesstype,' ' ); }else -return g_dbus_create_error (msg,ERROR_INTERFACE -".Failed" , -"Permission denied" ); +return error_failed (msg,strerror (EPERM ));return g_dbus_create_reply (msg,DBUS_TYPE_INVALID ); } -static DBusMessage *set_property_a2dp (struct media_transport *transport, -DBusConnection *conn,DBusMessage *msg) +static int set_property_a2dp (struct media_transport *transport, +const char *property, +DBusMessageIter *value) { -return NULL ; +if (g_strcmp0 (property,"Delay" ) ==0 ) { +if (dbus_message_iter_get_arg_type (value) !=DBUS_TYPE_UINT16 ) +return -EINVAL ; +dbus_message_iter_get_basic (value, &transport->delay); + +/* FIXME: send new delay */ +return 0 ; + } + +return -EINVAL ; } -static DBusMessage *set_property_headset (struct media_transport *transport, -DBusConnection *conn,DBusMessage *msg) +static int set_property_headset (struct media_transport *transport, +const char *property, +DBusMessageIter *value) { -return NULL ; +if (g_strcmp0 (property,"NREC" ) ==0 ) { +gboolean nrec; + +if (dbus_message_iter_get_arg_type (value) !=DBUS_TYPE_BOOLEAN ) +return -EINVAL ; +dbus_message_iter_get_basic (value, &nrec); + +/* FIXME: set new nrec */ +return 0 ; + }else if (g_strcmp0 (property,"InbandRingtone" ) ==0 ) { +gboolean inband; + +if (dbus_message_iter_get_arg_type (value) !=DBUS_TYPE_BOOLEAN ) +return -EINVAL ; +dbus_message_iter_get_basic (value, &inband); + +/* FIXME: set new inband */ +return 0 ; + } + +return -EINVAL ; }static DBusMessage *set_property (DBusConnection *conn,DBusMessage *msg,void *data) {struct media_transport *transport = data; +DBusMessageIter iter; +DBusMessageIter value; +const char *property, *sender; +GSList *l; +int err; + +if (!dbus_message_iter_init (msg, &iter)) +return invalid_args (msg); + +if (dbus_message_iter_get_arg_type (&iter) !=DBUS_TYPE_STRING ) +return invalid_args (msg); + +dbus_message_iter_get_basic (&iter, &property); +dbus_message_iter_next (&iter); + +if (dbus_message_iter_get_arg_type (&iter) !=DBUS_TYPE_VARIANT ) +return invalid_args (msg); +dbus_message_iter_recurse (&iter, &value); + + sender =dbus_message_get_sender (msg); + err = -EINVAL ; -return transport->set_property (transport, conn, msg); +/* Check if sender has acquired the transport */ +for (l = transport->renderers; l; l = l->next) { +struct media_renderer *renderer = l->data; + +if (g_strcmp0 (renderer->name, sender) ==0 ) { + err = transport->set_property (transport, property, + &value); +break ; + } + } + +if (err <0 ) { +if (err == -EINVAL ) +return invalid_args (msg); +return error_failed (msg,strerror (-err)); + } + +return g_dbus_create_reply (msg,DBUS_TYPE_INVALID ); } static void get_properties_a2dp(struct media_transport *transport,
Signature · 1 line
1.7.1
Hi Luiz,
Quoted 37 lines · Luiz Augusto von Dentz
Luiz Augusto von Dentz (10):
Add media API documentation
Add rule to enabling talking to org.bluez.MediaEndpoint Add option to enable/disable unix ipc via audio.conf Add support for media transport in gstreamer plugin Add simple-endpoint test script
Add initial implementation of org.bluez.Media spec Introduceheadset_get_inband
Update a2dp transport delay when it changes Remove local cache for nrec and inband
Add proper checks for MediaTransport.SetPropertyMakefile.am | 6 +- audio/a2dp-codecs.h | 116 ++++++++ audio/a2dp.c | 749 +++++++++++++++++++++++++++++++++++++++++-------- audio/a2dp.h | 15 + audio/avdtp.c | 88 +++---- audio/avdtp.h | 5 +- audio/gsta2dpsink.c | 33 ++- audio/gsta2dpsink.h | 1 + audio/gstavdtpsink.c | 609 +++++++++++++++++++++++++++++++++++++++- audio/gstavdtpsink.h | 6 + audio/headset.c | 10 + audio/headset.h | 1 + audio/main.c | 9 - audio/manager.c | 66 +++++ audio/manager.h | 2 + audio/media.c | 689 +++++++++++++++++++++++++++++++++++++++++++++ audio/media.h | 54 ++++ audio/sink.c | 179 ++----------- audio/source.c | 174 ++---------- audio/transport.c | 758 ++++++++++++++++++++++++++++++++++++++++++++++++++ audio/transport.h | 36 +++ audio/unix.c | 1 + doc/media-api.txt | 169 +++++++++++ src/bluetooth.conf | 1 + test/simple-endpoint | 126 +++++++++
Quoted 8 lines
25 files changed, 3395 insertions(+), 508 deletions(-) create mode 100644 audio/a2dp-codecs.h create mode 100644 audio/media.c create mode 100644 audio/media.h create mode 100644 audio/transport.c create mode 100644 audio/transport.h create mode 100644 doc/media-api.txt create mode 100755 test/simple-endpoint
All patches have been pushed upstream now (with the few minor changes that we discussed). Next step: talk to PulseAudio guys and get this merged there too.
Johan