Add support for device running changed callback 31/158131/5
authorSangchul Lee <sc11.lee@samsung.com>
Wed, 27 Sep 2017 02:51:46 +0000 (11:51 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Mon, 6 Nov 2017 08:22:17 +0000 (17:22 +0900)
 - mm_sound_add_device_running_changed_callback()
 - mm_sound_remove_device_running_changed_callback()
 - mm_sound_is_device_running()

Functions for change of running state are added. Previous device functions
including callback could not represent a device state related to its audio streams.
Now, these new APIs provide functionality regarding the 'running' state based on
the fundamental rule of that a device will be changed to 'running' only if
any stream go through the device.

[Version] 0.12.1
[Issue Type] New APIs

Change-Id: I79c164f706a5903cd2c6c76902d69c11a55ddbc3
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
common/mm_sound_dbus.c
include/mm_sound.h
include/mm_sound_client.h
include/mm_sound_device.h
include/mm_sound_intf.h
include/mm_sound_proxy.h
mm_sound_client.c
mm_sound_device.c
mm_sound_proxy.c
packaging/libmm-sound.spec

index f88e197..bb18bc5 100644 (file)
@@ -145,6 +145,9 @@ const mm_sound_dbus_signal_info_t g_events[AUDIO_EVENT_MAX] = {
        [AUDIO_EVENT_DEVICE_STATE_CHANGED] = {
                .name = "DeviceStateChanged",
        },
+       [AUDIO_EVENT_DEVICE_RUNNING_CHANGED] = {
+               .name = "DeviceRunningChanged",
+       },
        [AUDIO_EVENT_FOCUS_CHANGED] = {
                .name = "FocusChanged",
        },
@@ -415,6 +418,8 @@ static void _dbus_signal_callback(GDBusConnection *connection,
                (cb_data->user_cb)(AUDIO_EVENT_PLAY_FILE_END, params, cb_data->user_data);
        else if (!strcmp(signal_name, g_events[AUDIO_EVENT_EMERGENT_EXIT].name))
                (cb_data->user_cb)(AUDIO_EVENT_EMERGENT_EXIT, params, cb_data->user_data);
+       else if (!strcmp(signal_name, g_events[AUDIO_EVENT_DEVICE_RUNNING_CHANGED].name))
+               (cb_data->user_cb)(AUDIO_EVENT_DEVICE_RUNNING_CHANGED, params, cb_data->user_data);
 }
 
 static void callback_data_free_func(gpointer data)
index 1d70367..542a4f3 100644 (file)
@@ -1008,6 +1008,7 @@ typedef void *MMSoundDeviceList_t;      /**< MMsound Device list handle */
 typedef void (*mm_sound_device_connected_cb) (MMSoundDevice_t device_h, bool is_connected, void *user_data);
 typedef void (*mm_sound_device_info_changed_cb) (MMSoundDevice_t device_h, int changed_info_type, void *user_data);
 typedef void (*mm_sound_device_state_changed_cb) (MMSoundDevice_t device_h, mm_sound_device_state_e state, void *user_data);
+typedef void (*mm_sound_device_running_changed_cb) (MMSoundDevice_t device_h, bool is_running, void *user_data);
 
 int mm_sound_add_device_connected_callback(int flags, mm_sound_device_connected_cb func, void *user_data, unsigned int *id);
 int mm_sound_remove_device_connected_callback(unsigned int id);
@@ -1015,6 +1016,8 @@ int mm_sound_add_device_information_changed_callback(int flags, mm_sound_device_
 int mm_sound_remove_device_information_changed_callback(unsigned int id);
 int mm_sound_add_device_state_changed_callback(int flags, mm_sound_device_state_changed_cb func, void *user_data, unsigned int *id);
 int mm_sound_remove_device_state_changed_callback(unsigned int id);
+int mm_sound_add_device_running_changed_callback(int flags, mm_sound_device_running_changed_cb func, void *user_data, unsigned int *id);
+int mm_sound_remove_device_running_changed_callback(unsigned int id);
 
 int mm_sound_get_current_device_list(mm_sound_device_flags_e device_mask, MMSoundDeviceList_t *device_list);
 int mm_sound_get_device_list(int device_mask, MMSoundDeviceList_t *device_list);
@@ -1063,6 +1066,7 @@ void mm_sound_unsubscribe_signal(unsigned int subscribe_id);
 int mm_sound_send_signal(mm_sound_signal_name_t signal_type, int value);
 int mm_sound_get_signal_value(mm_sound_signal_name_t signal_type, int *value);
 int mm_sound_is_stream_on_device(int stream_id, MMSoundDevice_t device_h, bool *is_on);
+int mm_sound_is_device_running(MMSoundDevice_t device_h, bool *is_running);
 
 #ifdef TIZEN_TV
 void mm_sound_dotnet_cleanup(int signo);
index a1a4dbc..3ef732b 100644 (file)
@@ -56,6 +56,8 @@ int mm_sound_client_add_device_info_changed_callback(int device_flags, mm_sound_
 int mm_sound_client_remove_device_info_changed_callback(unsigned int subs_id);
 int mm_sound_client_add_device_state_changed_callback(int device_flags, mm_sound_device_state_changed_cb func, void *userdata, unsigned int *id);
 int mm_sound_client_remove_device_state_changed_callback(unsigned int id);
+int mm_sound_client_add_device_running_changed_callback(int device_flags, mm_sound_device_running_changed_cb func, void *userdata, unsigned int *id);
+int mm_sound_client_remove_device_running_changed_callback(unsigned int id);
 int mm_sound_client_is_stream_on_device(int stream_id, int device_id, bool *is_on);
 #ifdef USE_FOCUS
 int mm_sound_client_set_session_interrupt_callback(mm_sound_focus_session_interrupt_cb callback, void* user_data);
@@ -83,11 +85,13 @@ int mm_sound_client_test(int a, int b, int* get);
 
 typedef void (*mm_sound_volume_changed_wrapper_cb)(const char *direction, const char *volume_type_str, int volume_level, void *userdata);
 typedef void (*mm_sound_device_connected_wrapper_cb)(int device_id, const char *device_type, int io_direction, int state,
-               const char *name, int vendor_id, int product_id, int *stream_id, int stream_num, gboolean is_connected, void *userdata);
+               const char *name, int vendor_id, int product_id, bool is_running, int *stream_id, int stream_num, bool is_connected, void *userdata);
 typedef void (*mm_sound_device_info_changed_wrapper_cb)(int device_id, const char *device_type, int io_direction, int state,
-               const char *name, int vendor_id, int product_id, int *stream_id, int stream_num, int changed_device_info_type, void *userdata);
+               const char *name, int vendor_id, int product_id, bool is_running, int *stream_id, int stream_num, int changed_device_info_type, void *userdata);
 typedef void (*mm_sound_device_state_changed_wrapper_cb)(int device_id, const char *device_type, int io_direction, int state,
-               const char *name, int vendor_id, int product_id, int *stream_id, int stream_num, void *userdata);
+               const char *name, int vendor_id, int product_id, bool is_running, int *stream_id, int stream_num, void *userdata);
+typedef void (*mm_sound_device_running_changed_wrapper_cb)(int device_id, const char *device_type, int io_direction, int state,
+               const char *name, int vendor_id, int product_id, bool is_running, int *stream_id, int stream_num, void *userdata);
 typedef void (*mm_sound_stop_callback_wrapper_func)(int id, void *userdata);
 
 #ifdef TIZEN_TV
index cfb48c4..58ce2b1 100644 (file)
@@ -55,6 +55,8 @@ typedef struct {
        /* For USB device from udev, if not -1 */
        int vendor_id;
        int product_id;
+
+       bool is_running;
 } mm_sound_device_t;
 
 typedef struct {
index a235f2b..7f29da7 100644 (file)
@@ -90,6 +90,7 @@ typedef enum audio_event {
        AUDIO_EVENT_EMERGENT_EXIT,
        AUDIO_EVENT_CLIENT_SUBSCRIBED, /* Clients send this signal when they subscribed some signal. */
        AUDIO_EVENT_CLIENT_HANDLED, /* Clients send this siganl when they handled some signal. */
+       AUDIO_EVENT_DEVICE_RUNNING_CHANGED,
        AUDIO_EVENT_MAX
 } audio_event_t;
 
index 32031c5..7760000 100644 (file)
@@ -60,6 +60,8 @@ int mm_sound_proxy_add_device_info_changed_callback(int device_flags, mm_sound_d
 int mm_sound_proxy_remove_device_info_changed_callback(unsigned subs_id);
 int mm_sound_proxy_add_device_state_changed_callback(int device_flags, mm_sound_device_state_changed_wrapper_cb func, void* userdata, mm_sound_proxy_userdata_free freefunc, unsigned *subs_id);
 int mm_sound_proxy_remove_device_state_changed_callback(unsigned subs_id);
+int mm_sound_proxy_add_device_running_changed_callback(int device_flags, mm_sound_device_running_changed_wrapper_cb func, void* userdata, mm_sound_proxy_userdata_free freefunc, unsigned *subs_id);
+int mm_sound_proxy_remove_device_running_changed_callback(unsigned subs_id);
 int mm_sound_proxy_is_stream_on_device(int stream_id, int device_id, bool *is_on);
 int mm_sound_proxy_set_volume_by_type(const char *volume_type, const unsigned volume_level);
 int mm_sound_proxy_add_volume_changed_callback(mm_sound_volume_changed_wrapper_cb func, void* userdata, mm_sound_proxy_userdata_free freefunc, unsigned *subs_id);
index 458d2b6..e041674 100644 (file)
@@ -712,7 +712,7 @@ static bool device_is_match_with_mask(const char *type, int direction, int state
 
 static int _fill_sound_device(mm_sound_device_t *device_h, int device_id, const char *device_type,
                int direction, int state, const char *name, int vendor_id, int product_id,
-               int *stream_id, int stream_num)
+               int *stream_id, int stream_num, bool is_running)
 {
        int i;
 
@@ -733,6 +733,7 @@ static int _fill_sound_device(mm_sound_device_t *device_h, int device_id, const
        MMSOUND_STRNCPY(device_h->type, device_type, MAX_DEVICE_TYPE_STR_LEN);
        device_h->vendor_id = vendor_id;
        device_h->product_id = product_id;
+       device_h->is_running = is_running;
 
        if (stream_num > 0) {
                device_h->stream_num = stream_num;
@@ -750,16 +751,16 @@ static int _fill_sound_device(mm_sound_device_t *device_h, int device_id, const
 }
 
 static void _mm_sound_device_connected_callback_wrapper_func(int device_id, const char *device_type, int io_direction,
-                                                       int state, const char *name, int vendor_id, int product_id, int *stream_id, int stream_num,
-                                                       gboolean is_connected, void *userdata)
+                                                                                                                       int state, const char *name, int vendor_id, int product_id, bool is_running,
+                                                                                                                       int *stream_id, int stream_num, bool is_connected, void *userdata)
 {
        mm_sound_device_t device_h;
        struct callback_data *cb_data = (struct callback_data*) userdata;
        int device_flags;
 
-       debug_log("[Device %s] id(%d) type(%s) direction(%d) state(%d) name(%s) vendor-id(%04x) product-id(%04x)",
-                         is_connected ? "Connected" : "Disconnected", device_id, device_type, io_direction,
-                         state, name, vendor_id, product_id, is_connected);
+       debug_log("[Device %s] id(%d) type(%s) direction(%d) state(%d) name(%s) is_running(%d) vendor-id(%04x) product-id(%04x)",
+                               is_connected ? "Connected" : "Disconnected", device_id, device_type, io_direction, state, name,
+                               is_running, vendor_id, product_id, is_connected);
 
        if (cb_data == NULL) {
                debug_warning("device connected changed callback data null");
@@ -771,7 +772,7 @@ static void _mm_sound_device_connected_callback_wrapper_func(int device_id, cons
                return;
 
        if (_fill_sound_device(&device_h, device_id, device_type, io_direction, state, name,
-                               vendor_id, product_id, stream_id, stream_num) < 0) {
+                                                       vendor_id, product_id, stream_id, stream_num, is_running) < 0) {
                debug_error("Failed to fill sound device");
                return;
        }
@@ -811,16 +812,16 @@ int mm_sound_client_remove_device_connected_callback(unsigned int subs_id)
 }
 
 static void _mm_sound_device_info_changed_callback_wrapper_func(int device_id, const char *device_type, int io_direction,
-                                                       int state, const char *name, int vendor_id, int product_id, int *stream_id, int stream_num,
-                                                       int changed_device_info_type, void *userdata)
+                                                                                                                               int state, const char *name, int vendor_id, int product_id, bool is_running,
+                                                                                                                               int *stream_id, int stream_num, int changed_device_info_type, void *userdata)
 {
        mm_sound_device_t device_h;
        struct callback_data *cb_data = (struct callback_data*) userdata;
        int device_flags;
 
-       debug_log("[Device Info Changed] id(%d) type(%s) direction(%d) state(%d) name(%s) "
+       debug_log("[Device Info Changed] id(%d) type(%s) direction(%d) state(%d) name(%s) is_running(%d) "
                        "vendor-id(%04x) product-id(%04x) changed_info_type(%d)",
-                       device_id, device_type, io_direction, state, name, vendor_id, product_id, changed_device_info_type);
+                       device_id, device_type, io_direction, state, name, is_running, vendor_id, product_id, changed_device_info_type);
 
        if (cb_data == NULL) {
                debug_warning("device info changed callback data null");
@@ -832,7 +833,7 @@ static void _mm_sound_device_info_changed_callback_wrapper_func(int device_id, c
                return;
 
        if (_fill_sound_device(&device_h, device_id, device_type, io_direction, state, name,
-                               vendor_id, product_id, stream_id, stream_num) < 0) {
+                               vendor_id, product_id, stream_id, stream_num, is_running) < 0) {
                debug_error("Failed to fill sound device");
                return;
        }
@@ -870,17 +871,16 @@ int mm_sound_client_remove_device_info_changed_callback(unsigned int subs_id)
 
 }
 
-static void _mm_sound_device_state_changed_callback_wrapper_func(int device_id, const char *device_type,
-                                                               int io_direction, int state, const char *name, int vendor_id, int product_id,
-                                                               int *stream_id, int stream_num, void *userdata)
+static void _mm_sound_device_state_changed_callback_wrapper_func(int device_id, const char *device_type, int io_direction,
+                                                                                                                               int state, const char *name, int vendor_id, int product_id,
+                                                                                                                               bool is_running, int *stream_id, int stream_num, void *userdata)
 {
        mm_sound_device_t device_h;
        struct callback_data *cb_data = (struct callback_data*) userdata;
        int device_flags;
 
-       debug_log("[Device State Changed] id(%d) type(%s) direction(%d) state(%d) name(%s)"
-                       "vendor-id(%04x), product-id(%04x)",
-                       device_id, device_type, io_direction, state, name, vendor_id, product_id);
+       debug_log("[Device State Changed] id(%d) type(%s) direction(%d) state(%d) name(%s) is_running(%d) vendor-id(%04x) product-id(%04x)",
+                               device_id, device_type, io_direction, state, name, is_running, vendor_id, product_id);
 
        if (cb_data == NULL) {
                debug_warning("device state changed callback data null");
@@ -893,7 +893,7 @@ static void _mm_sound_device_state_changed_callback_wrapper_func(int device_id,
                return;
 
        if (_fill_sound_device(&device_h, device_id, device_type, io_direction, state, name,
-                               vendor_id, product_id, stream_id, stream_num) < 0) {
+                               vendor_id, product_id, stream_id, stream_num, is_running) < 0) {
                debug_error("Failed to fill sound device");
                return;
        }
@@ -912,8 +912,8 @@ int mm_sound_client_add_device_state_changed_callback(int device_flags, mm_sound
        GET_CB_DATA(cb_data, func, userdata, (void *) device_flags);
 
        ret = mm_sound_proxy_add_device_state_changed_callback(device_flags,
-                                                                                                               _mm_sound_device_state_changed_callback_wrapper_func,
-                                                                                                               cb_data, g_free, id);
+                                                               _mm_sound_device_state_changed_callback_wrapper_func,
+                                                               cb_data, g_free, id);
 
        debug_fleave();
        return ret;
@@ -930,6 +930,65 @@ int mm_sound_client_remove_device_state_changed_callback(unsigned int id)
        return ret;
 }
 
+static void _mm_sound_device_running_changed_callback_wrapper_func(int device_id, const char *device_type, int io_direction,
+                                                                                                                               int state, const char *name, int vendor_id, int product_id,
+                                                                                                                               bool is_running, int *stream_id, int stream_num, void *userdata)
+{
+       mm_sound_device_t device_h;
+       struct callback_data *cb_data = (struct callback_data*) userdata;
+       int device_flags;
+
+       debug_log("[Device Running Changed] id(%d) type(%s) direction(%d) state(%d) name(%s) is_running(%d) vendor-id(%04x), product-id(%04x)",
+                       device_id, device_type, io_direction, state, name, is_running, vendor_id, product_id);
+
+       if (cb_data == NULL) {
+               debug_warning("device running changed callback data null");
+               return;
+       }
+
+       device_flags = (int) cb_data->extra_data;
+
+       if (!device_is_match_with_mask(device_type, io_direction, state, device_flags))
+               return;
+
+       if (_fill_sound_device(&device_h, device_id, device_type, io_direction, state, name,
+                                                       vendor_id, product_id, stream_id, stream_num, is_running) < 0) {
+               debug_error("Failed to fill sound device");
+               return;
+       }
+
+       ((mm_sound_device_running_changed_cb)(cb_data->user_cb))(&device_h, is_running, cb_data->user_data);
+}
+
+int mm_sound_client_add_device_running_changed_callback(int device_flags, mm_sound_device_running_changed_cb func,
+                                                                                                               void *userdata, unsigned int *id)
+{
+       int ret = MM_ERROR_NONE;
+       struct callback_data *cb_data = (struct callback_data*) userdata;
+
+       debug_fenter();
+
+       GET_CB_DATA(cb_data, func, userdata, (void *) device_flags);
+
+       ret = mm_sound_proxy_add_device_running_changed_callback(device_flags,
+                                                                                                                       _mm_sound_device_running_changed_callback_wrapper_func,
+                                                                                                                       cb_data, g_free, id);
+
+       debug_fleave();
+       return ret;
+}
+
+int mm_sound_client_remove_device_running_changed_callback(unsigned int id)
+{
+       int ret = MM_ERROR_NONE;
+       debug_fenter();
+
+       ret =  mm_sound_proxy_remove_device_running_changed_callback(id);
+
+       debug_fleave();
+       return ret;
+}
+
 int mm_sound_client_is_stream_on_device(int stream_id, int device_id, bool *is_on)
 {
        int ret = MM_ERROR_NONE;
index 74db967..23935dd 100644 (file)
@@ -204,6 +204,38 @@ int mm_sound_remove_device_state_changed_callback(unsigned int id)
        return ret;
 }
 
+EXPORT_API
+int mm_sound_add_device_running_changed_callback(int flags, mm_sound_device_running_changed_cb func, void *user_data, unsigned int *id)
+{
+       int ret = MM_ERROR_NONE;
+
+       if (func == NULL || id == NULL) {
+               debug_error("argument is not valid");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+       ret = _check_for_valid_mask(flags);
+       if (ret == MM_ERROR_NONE) {
+               ret = mm_sound_client_add_device_running_changed_callback(flags, func, user_data, id);
+               if (ret < 0) {
+                       debug_error("Could not add device running changed callback, ret = %x", ret);
+               }
+       }
+
+       return ret;
+}
+
+EXPORT_API
+int mm_sound_remove_device_running_changed_callback(unsigned int id)
+{
+       int ret = MM_ERROR_NONE;
+
+       ret = mm_sound_client_remove_device_running_changed_callback(id);
+       if (ret < 0) {
+               debug_error("Could not remove device running changed callback, ret = %x", ret);
+       }
+
+       return ret;
+}
 
 EXPORT_API
 int mm_sound_get_current_device_list(mm_sound_device_flags_e flags, MMSoundDeviceList_t *device_list)
@@ -495,3 +527,17 @@ int mm_sound_is_stream_on_device(int stream_id, MMSoundDevice_t device_h, bool *
 
        return ret;
 }
+
+EXPORT_API
+int mm_sound_is_device_running(MMSoundDevice_t device_h, bool *is_running)
+{
+       mm_sound_device_t *device = (mm_sound_device_t*)device_h;
+       if (!device || !is_running) {
+               debug_error("invalid argument");
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+       *is_running = device->is_running;
+       debug_log("device_handle:0x%x, running:%d", device, *is_running);
+
+       return MM_ERROR_NONE;
+}
\ No newline at end of file
index 95560af..699949b 100644 (file)
@@ -79,7 +79,7 @@ static int _notify_signal_handled(audio_event_t event, uint32_t event_id, uint32
 }
 
 static int parse_device_variant(GVariant *v, int *device_id, const char **device_type, int *direction, int *state,
-                                               const char **device_name, int *vendor_id, int *product_id, int *stream_id, int *stream_num)
+                                               const char **device_name, int *vendor_id, int *product_id, bool *is_running, int *stream_id, int *stream_num)
 {
        const char *v_type;
        GVariant *array_v;
@@ -93,7 +93,7 @@ static int parse_device_variant(GVariant *v, int *device_id, const char **device
        }
 
        v_type = g_variant_get_type_string(v);
-       if (g_variant_type_equal(v_type, "(isiisiiai)") == FALSE) {
+       if (g_variant_type_equal(v_type, "(isiisiibai)") == FALSE) {
                debug_error("device variant type not matching '%s'", v_type);
                return MM_ERROR_NONE;
        }
@@ -106,6 +106,7 @@ static int parse_device_variant(GVariant *v, int *device_id, const char **device
        g_variant_iter_next(&iter, "&s", device_name);
        g_variant_iter_next(&iter, "i", vendor_id);
        g_variant_iter_next(&iter, "i", product_id);
+       g_variant_iter_next(&iter, "b", is_running);
 
        array_v = g_variant_iter_next_value(&iter);
        *stream_num = g_variant_iter_init(&array_iter, array_v);
@@ -136,6 +137,7 @@ static void dbus_callback(audio_event_t event, GVariant *params, void *userdata)
        int stream_id[MAX_STREAM_ON_DEVICE];
        int stream_num;
        int vendor_id, product_id;
+       bool is_running = FALSE;
 
        v_type = g_variant_get_type_string(params);
 
@@ -146,9 +148,9 @@ static void dbus_callback(audio_event_t event, GVariant *params, void *userdata)
                g_variant_get(params, "(&s&su)", &direction, &volume_type_str, &volume_level);
                ((mm_sound_volume_changed_wrapper_cb)(cb_data->user_cb))(direction, volume_type_str, volume_level, cb_data->user_data);
        } else if (event == AUDIO_EVENT_DEVICE_CONNECTED) {
-               gboolean is_connected = FALSE;
+               bool is_connected = false;
 
-               if (g_variant_type_equal(v_type, "(u(isiisiiai)b)") == FALSE) {
+               if (g_variant_type_equal(v_type, "(u(isiisiibai)b)") == FALSE) {
                        debug_error("Device connection changed signature not matching : %s", v_type);
                        return ;
                }
@@ -156,19 +158,19 @@ static void dbus_callback(audio_event_t event, GVariant *params, void *userdata)
                g_variant_iter_next(&iter, "u", &event_id);
                device_v = g_variant_iter_next_value(&iter);
                if (parse_device_variant(device_v, &device_id, &device_type, &direction, &state,
-                                                       &name, &vendor_id, &product_id, stream_id, &stream_num) < 0) {
+                                                       &name, &vendor_id, &product_id, &is_running, stream_id, &stream_num) < 0) {
                        debug_error("Failed to parse device variant");
                        return ;
                }
                g_variant_iter_next(&iter, "b", &is_connected);
 
                ((mm_sound_device_connected_wrapper_cb)(cb_data->user_cb))(device_id, device_type, direction,
-                       state, name, vendor_id, product_id, stream_id, stream_num, is_connected, cb_data->user_data);
+                       state, name, vendor_id, product_id, is_running, stream_id, stream_num, is_connected, cb_data->user_data);
                _notify_signal_handled(event, event_id, cb_data->subs_id, g_variant_new("(ib)", device_id, is_connected));
        } else if (event == AUDIO_EVENT_DEVICE_INFO_CHANGED) {
                int changed_device_info_type = 0;
 
-               if (g_variant_type_equal(v_type, "(u(isiisiiai)i)") == FALSE) {
+               if (g_variant_type_equal(v_type, "(u(isiisiibai)i)") == FALSE) {
                        debug_error("Device information changed signature not matching : %s", v_type);
                        return ;
                }
@@ -177,17 +179,17 @@ static void dbus_callback(audio_event_t event, GVariant *params, void *userdata)
                g_variant_iter_next(&iter, "u", &event_id);
                device_v = g_variant_iter_next_value(&iter);
                if (parse_device_variant(device_v, &device_id, &device_type, &direction, &state,
-                                                       &name, &vendor_id, &product_id, stream_id, &stream_num) < 0) {
+                                                       &name, &vendor_id, &product_id, &is_running, stream_id, &stream_num) < 0) {
                        debug_error("Failed to parse device variant");
                        return ;
                }
                g_variant_iter_next(&iter, "i", &changed_device_info_type);
 
                ((mm_sound_device_info_changed_wrapper_cb)(cb_data->user_cb))(device_id, device_type, direction,
-                       state, name, vendor_id, product_id, stream_id, stream_num, changed_device_info_type, cb_data->user_data);
+                       state, name, vendor_id, product_id, is_running, stream_id, stream_num, changed_device_info_type, cb_data->user_data);
        } else if (event == AUDIO_EVENT_DEVICE_STATE_CHANGED) {
 
-               if (g_variant_type_equal(v_type, "(u(isiisiiai))") == FALSE) {
+               if (g_variant_type_equal(v_type, "(u(isiisiibai))") == FALSE) {
                        debug_error("Device state changed signature not matching : %s", v_type);
                        return ;
                }
@@ -196,13 +198,31 @@ static void dbus_callback(audio_event_t event, GVariant *params, void *userdata)
                g_variant_iter_next(&iter, "u", &event_id);
                device_v = g_variant_iter_next_value(&iter);
                if (parse_device_variant(device_v, &device_id, &device_type, &direction, &state,
-                                                       &name, &vendor_id, &product_id, stream_id, &stream_num) < 0) {
+                                                       &name, &vendor_id, &product_id, &is_running, stream_id, &stream_num) < 0) {
                        debug_error("Failed to parse device variant");
                        return ;
                }
 
                ((mm_sound_device_state_changed_wrapper_cb)(cb_data->user_cb))(device_id, device_type, direction,
-                       state, name, vendor_id, product_id, stream_id, stream_num, cb_data->user_data);
+                       state, name, vendor_id, product_id, is_running, stream_id, stream_num, cb_data->user_data);
+       } else if (event == AUDIO_EVENT_DEVICE_RUNNING_CHANGED) {
+
+               if (g_variant_type_equal(v_type, "(u(isiisiibai))") == FALSE) {
+                       debug_error("Device state changed signature not matching : %s", v_type);
+                       return ;
+               }
+
+               g_variant_iter_init(&iter, params);
+               g_variant_iter_next(&iter, "u", &event_id);
+               device_v = g_variant_iter_next_value(&iter);
+               if (parse_device_variant(device_v, &device_id, &device_type, &direction, &state,
+                                                       &name, &vendor_id, &product_id, &is_running, stream_id, &stream_num) < 0) {
+                       debug_error("Failed to parse device variant");
+                       return ;
+               }
+
+               ((mm_sound_device_running_changed_wrapper_cb)(cb_data->user_cb))(device_id, device_type, direction,
+                       state, name, vendor_id, product_id, is_running, stream_id, stream_num, cb_data->user_data);
        } else if (event == AUDIO_EVENT_FOCUS_CHANGED) {
        } else if (event == AUDIO_EVENT_FOCUS_WATCH) {
        } else if (event == AUDIO_EVENT_TEST) {
@@ -367,15 +387,15 @@ int mm_sound_proxy_get_current_connected_device_list(int device_flags, GList** d
        g_variant_iter_init(&iter, child);
        while (1) {
                device_item = g_malloc0(sizeof(mm_sound_device_t));
-               if (device_item && g_variant_iter_loop(&iter, "(i&sii&sii)",
+               if (device_item && g_variant_iter_loop(&iter, "(i&sii&siib)",
                                        &device_item->id, &device_type_tmp, &device_item->io_direction, &device_item->state,
-                                       &device_name_tmp, &device_item->vendor_id, &device_item->product_id)) {
+                                       &device_name_tmp, &device_item->vendor_id, &device_item->product_id, &device_item->is_running)) {
                        MMSOUND_STRNCPY(device_item->name, device_name_tmp, MAX_DEVICE_NAME_NUM);
                        MMSOUND_STRNCPY(device_item->type, device_type_tmp, MAX_DEVICE_TYPE_STR_LEN);
                        *device_list = g_list_append(*device_list, device_item);
-                       debug_log("Added device id(%d) type(%17s) direction(%d) state(%d) name(%s) vendor-id(%04x) product-id(%04x)",
+                       debug_log("Added device id(%d) type(%17s) direction(%d) state(%d) name(%s) vendor-id(%04x) product-id(%04x) is_running(%d)",
                                        device_item->id, device_item->type, device_item->io_direction, device_item->state,
-                                       device_item->name, device_item->vendor_id, device_item->product_id);
+                                       device_item->name, device_item->vendor_id, device_item->product_id, device_item->is_running);
                        device_item->stream_num = -1;
                } else {
                        if (device_item)
@@ -553,6 +573,36 @@ int mm_sound_proxy_remove_device_state_changed_callback(unsigned subs_id)
        return ret;
 }
 
+int mm_sound_proxy_add_device_running_changed_callback(int device_flags, mm_sound_device_running_changed_wrapper_cb func, void* userdata, mm_sound_proxy_userdata_free freefunc, unsigned *subs_id)
+{
+       int ret = MM_ERROR_NONE;
+       struct callback_data *cb_data;
+
+       debug_fenter();
+
+       CB_DATA_NEW(cb_data, func, userdata, freefunc);
+
+       if ((ret = mm_sound_dbus_signal_subscribe_to(AUDIO_PROVIDER_DEVICE_MANAGER, AUDIO_EVENT_DEVICE_RUNNING_CHANGED, dbus_callback, cb_data, simple_callback_data_free_func, &cb_data->subs_id)) != MM_ERROR_NONE)
+               debug_error("Add device running changed callback failed");
+       else
+               *subs_id = cb_data->subs_id;
+
+       debug_fleave();
+       return ret;
+}
+
+int mm_sound_proxy_remove_device_running_changed_callback(unsigned subs_id)
+{
+       int ret = MM_ERROR_NONE;
+       debug_fenter();
+
+       if ((ret = mm_sound_dbus_signal_unsubscribe(subs_id)) != MM_ERROR_NONE)
+               debug_error("remove device running changed callback failed");
+
+       debug_fleave();
+       return ret;
+}
+
 int mm_sound_proxy_set_volume_by_type(const char *volume_type, const unsigned volume_level)
 {
        int ret = MM_ERROR_NONE;
index 700caa8..f936ae7 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-sound
 Summary:    MMSound Package contains client lib and sound_server binary
-Version:    0.11.31
+Version:    0.12.1
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0