OSDN Git Service

source: Register state callback for specified audio device
authorSzymon Janc <szymon.janc@tieto.com>
Tue, 5 Mar 2013 14:59:55 +0000 (15:59 +0100)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Wed, 6 Mar 2013 09:50:34 +0000 (11:50 +0200)
State callback will now be registered and called for specified device
only. This will allow for more cleaner callback register/unregister
in roles code.

profiles/audio/source.c
profiles/audio/source.h
profiles/audio/transport.c

index 147a92c..5d9e237 100644 (file)
@@ -70,6 +70,7 @@ struct source {
 
 struct source_state_callback {
        source_state_cb cb;
+       struct audio_device *dev;
        void *user_data;
        unsigned int id;
 };
@@ -96,6 +97,10 @@ static void source_set_state(struct audio_device *dev, source_state_t new_state)
 
        for (l = source_callbacks; l != NULL; l = l->next) {
                struct source_state_callback *cb = l->data;
+
+               if (cb->dev != dev)
+                       continue;
+
                cb->cb(dev, old_state, new_state, cb->user_data);
        }
 
@@ -439,13 +444,15 @@ int source_disconnect(struct audio_device *dev, gboolean shutdown)
        return avdtp_close(source->session, source->stream, FALSE);
 }
 
-unsigned int source_add_state_cb(source_state_cb cb, void *user_data)
+unsigned int source_add_state_cb(struct audio_device *dev, source_state_cb cb,
+                                                               void *user_data)
 {
        struct source_state_callback *state_cb;
        static unsigned int id = 0;
 
        state_cb = g_new(struct source_state_callback, 1);
        state_cb->cb = cb;
+       state_cb->dev = dev;
        state_cb->user_data = user_data;
        state_cb->id = ++id;
 
index 4c01d27..61afd94 100644 (file)
@@ -37,7 +37,8 @@ typedef void (*source_state_cb) (struct audio_device *dev,
                                source_state_t new_state,
                                void *user_data);
 
-unsigned int source_add_state_cb(source_state_cb cb, void *user_data);
+unsigned int source_add_state_cb(struct audio_device *dev, source_state_cb cb,
+                                                       void *user_data);
 gboolean source_remove_state_cb(unsigned int id);
 
 struct source *source_init(struct audio_device *dev);
index 98106a2..f585c3a 100644 (file)
@@ -764,9 +764,6 @@ static void source_state_changed(struct audio_device *dev,
 {
        struct media_transport *transport = user_data;
 
-       if (dev != transport->device)
-               return;
-
        if (new_state == SOURCE_STATE_PLAYING)
                transport_update_playing(transport, TRUE);
        else
@@ -813,7 +810,7 @@ struct media_transport *media_transport_create(struct audio_device *device,
                } else {
                        a2dp->volume = 127;
                        avrcp_set_volume(device, a2dp->volume);
-                       transport->source_watch = source_add_state_cb(
+                       transport->source_watch = source_add_state_cb(device,
                                                        source_state_changed,
                                                        transport);
                }