Fix pulseaudio.
[scm/bb/meta-tizen.git] / recipes-multimedia / pulseaudio / pulseaudio_5.0 / 0019-bluetooth-Track-oFono-service.patch
1 From: =?utf-8?q?Jo=C3=A3o_Paulo_Rechi_Vita?= <jprvita@openbossa.org>
2 Date: Thu, 11 Jul 2013 11:43:48 -0300
3 Subject: bluetooth: Track oFono service
4
5 Change-Id: I6752f21b848757dbea20c92c68b581141cefbc67
6 ---
7  src/modules/bluetooth/hfaudioagent-ofono.c | 61 ++++++++++++++++++++++++++++--
8  1 file changed, 58 insertions(+), 3 deletions(-)
9
10 diff --git a/src/modules/bluetooth/hfaudioagent-ofono.c b/src/modules/bluetooth/hfaudioagent-ofono.c
11 index 3684bed..97e0fa8 100644
12 --- a/src/modules/bluetooth/hfaudioagent-ofono.c
13 +++ b/src/modules/bluetooth/hfaudioagent-ofono.c
14 @@ -364,6 +364,7 @@ static void hf_audio_agent_unregister(hf_audio_agent_data *hfdata) {
15  
16  static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *data) {
17      const char *sender;
18 +    DBusError err;
19      hf_audio_agent_data *hfdata = data;
20  
21      pa_assert(bus);
22 @@ -374,6 +375,46 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *da
23      if (!pa_safe_streq(hfdata->ofono_bus_id, sender) && !pa_streq("org.freedesktop.DBus", sender))
24          return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
25  
26 +    dbus_error_init(&err);
27 +
28 +    if (dbus_message_is_signal(m, "org.freedesktop.DBus", "NameOwnerChanged")) {
29 +        const char *name, *old_owner, *new_owner;
30 +
31 +        if (!dbus_message_get_args(m, &err,
32 +                                   DBUS_TYPE_STRING, &name,
33 +                                   DBUS_TYPE_STRING, &old_owner,
34 +                                   DBUS_TYPE_STRING, &new_owner,
35 +                                   DBUS_TYPE_INVALID)) {
36 +            pa_log_error("Failed to parse org.freedesktop.DBus.NameOwnerChanged: %s", err.message);
37 +            goto fail;
38 +        }
39 +
40 +        if (pa_streq(name, OFONO_SERVICE)) {
41 +
42 +            if (old_owner && *old_owner) {
43 +                pa_log_debug("oFono disappeared");
44 +
45 +                if (hfdata->hf_audio_cards) {
46 +                    pa_hashmap_free(hfdata->hf_audio_cards);
47 +                    hfdata->hf_audio_cards = NULL;
48 +                }
49 +
50 +                if(hfdata->ofono_bus_id) {
51 +                    pa_xfree(hfdata->ofono_bus_id);
52 +                    hfdata->ofono_bus_id = NULL;
53 +                }
54 +            }
55 +
56 +            if (new_owner && *new_owner) {
57 +                pa_log_debug("oFono appeared");
58 +                hf_audio_agent_register(hfdata);
59 +            }
60 +        }
61 +
62 +    }
63 +
64 +fail:
65 +    dbus_error_free(&err);
66      return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
67  }
68  
69 @@ -390,7 +431,20 @@ static DBusMessage *hf_audio_agent_release(DBusConnection *c, DBusMessage *m, vo
70          return r;
71      }
72  
73 -    r = dbus_message_new_error(m, "org.ofono.Error.NotImplemented", "Operation is not implemented");
74 +    pa_log_debug("HF audio agent has been unregistered by oFono (%s)", hfdata->ofono_bus_id);
75 +
76 +    if (hfdata->hf_audio_cards) {
77 +        pa_hashmap_free(hfdata->hf_audio_cards);
78 +        hfdata->hf_audio_cards = NULL;
79 +    }
80 +
81 +    if(hfdata->ofono_bus_id) {
82 +        pa_xfree(hfdata->ofono_bus_id);
83 +        hfdata->ofono_bus_id = NULL;
84 +    }
85 +
86 +    pa_assert_se(r = dbus_message_new_method_return(m));
87 +
88      return r;
89  }
90  
91 @@ -459,7 +513,8 @@ hf_audio_agent_data *hf_audio_agent_init(pa_core *c) {
92  
93      hfdata = pa_xnew0(hf_audio_agent_data, 1);
94      hfdata->core = c;
95 -    hfdata->hf_audio_cards = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
96 +    hfdata->hf_audio_cards = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func,
97 +                                                 NULL, hf_audio_card_free);
98      hfdata->discovery = pa_shared_get(c, "bluetooth-discovery");
99  
100      dbus_error_init(&err);
101 @@ -505,7 +560,7 @@ void hf_audio_agent_done(hf_audio_agent_data *data) {
102      pa_dbus_free_pending_list(&hfdata->pending);
103  
104      if (hfdata->hf_audio_cards) {
105 -        pa_hashmap_free(hfdata->hf_audio_cards, hf_audio_card_free);
106 +        pa_hashmap_free(hfdata->hf_audio_cards);
107          hfdata->hf_audio_cards = NULL;
108      }
109