Merge 1. Support DOCK Audio 2. Fix build breaks 2.0alpha master 2.0_alpha submit/master/20120920.151102
authorSeungbae Shin <seungbae.shin@samsung.com>
Thu, 30 Aug 2012 06:24:02 +0000 (15:24 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Thu, 30 Aug 2012 06:24:02 +0000 (15:24 +0900)
include/mm_sound.h
packaging/libmm-sound.spec
server/Makefile.am
server/include/mm_sound_mgr_dock.h [new file with mode: 0644]
server/mm_sound_mgr_dock.c [new file with mode: 0644]
server/mm_sound_mgr_session.c
server/mm_sound_server.c

index 148a7b4..8a9c594 100644 (file)
@@ -1907,6 +1907,7 @@ typedef enum{
        MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY     = 0x04<<8,      /**< Wired output devices such as headphone, headset, and so on. */
        MM_SOUND_DEVICE_OUT_BT_SCO                      = 0x08<<8,      /**< Bluetooth SCO device */
        MM_SOUND_DEVICE_OUT_BT_A2DP                     = 0x10<<8,      /**< Bluetooth A2DP device */
+       MM_SOUND_DEVICE_OUT_DOCK                        = 0x20<<8,      /**< DOCK device */
 } mm_sound_device_out;
 
 #define MM_SOUND_ROUTE_NUM 10
@@ -1915,6 +1916,7 @@ typedef enum{
        MM_SOUND_ROUTE_OUT_SPEAKER = MM_SOUND_DEVICE_OUT_SPEAKER, /**< Routing audio output to builtin device such as internal speaker. */
        MM_SOUND_ROUTE_OUT_WIRED_ACCESSORY = MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY,/**< Routing audio output to wired accessory such as headphone, headset, and so on. */
        MM_SOUND_ROUTE_OUT_BLUETOOTH = MM_SOUND_DEVICE_OUT_BT_A2DP, /**< Routing audio output to bluetooth A2DP. */
+       MM_SOUND_ROUTE_OUT_DOCK = MM_SOUND_DEVICE_OUT_DOCK, /**< Routing audio output to DOCK */
        MM_SOUND_ROUTE_IN_MIC = MM_SOUND_DEVICE_IN_MIC, /**< Routing audio input to device builtin mic. */
        MM_SOUND_ROUTE_IN_WIRED_ACCESSORY = MM_SOUND_DEVICE_IN_WIRED_ACCESSORY, /**< Routing audio input to wired accessory. */
        MM_SOUND_ROUTE_IN_MIC_OUT_RECEIVER = MM_SOUND_DEVICE_IN_MIC | MM_SOUND_DEVICE_OUT_RECEIVER, /**< Routing audio input to device builtin mic and routing audio output to builtin receiver*/
index b81a613..503fc96 100644 (file)
@@ -1,7 +1,7 @@
 Name:       libmm-sound
 Summary:    MMSound Package contains client lib and sound_server binary
 Version:    0.6.0
-Release:    15
+Release:    17
 Group:      System/Libraries
 License:    LGPL
 Source0:    %{name}-%{version}.tar.gz
index 9a02966..8509f7e 100644 (file)
@@ -7,6 +7,7 @@ sound_server_SOURCES = mm_sound_mgr_codec.c \
                                                mm_sound_mgr_asm.c \
                                                mm_sound_mgr_device.c \
                                                mm_sound_mgr_headset.c \
+                                               mm_sound_mgr_dock.c \
                                                mm_sound_mgr_session.c \
                                                mm_sound_mgr_run.c \
                                                mm_sound_plugin.c \
diff --git a/server/include/mm_sound_mgr_dock.h b/server/include/mm_sound_mgr_dock.h
new file mode 100644 (file)
index 0000000..387fdfd
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * libmm-sound
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Seungbae Shin <seungbae.shin@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __MM_SOUND_MGR_DOCK_H__
+#define __MM_SOUND_MGR_DOCK_H__
+
+#include "../../include/mm_ipc.h"
+
+int MMSoundMgrDockInit(void);
+int MMSoundMgrDockFini(void);
+
+
+#endif /* __MM_SOUND_MGR_DOCK_H__ */
+
diff --git a/server/mm_sound_mgr_dock.c b/server/mm_sound_mgr_dock.c
new file mode 100644 (file)
index 0000000..275e04a
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * libmm-sound
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Seungbae Shin <seungbae.shin@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <pthread.h>
+#include <sys/shm.h>
+#include <sys/msg.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdbool.h>
+
+#include <errno.h>
+
+#include "include/mm_sound_mgr_common.h"
+#include "../include/mm_sound_common.h"
+
+#include <mm_error.h>
+#include <mm_debug.h>
+
+#include "include/mm_sound_mgr_dock.h"
+#include "include/mm_sound_mgr_session.h"
+
+/******************************* Dock Code **********************************/
+
+#include <sys/types.h>
+#include <stdbool.h>
+#include <errno.h>
+#include <assert.h>
+
+#include "mm_ipc.h"
+#include "mm_sound_common.h"
+#include "mm_sound.h"
+
+#include <vconf.h>
+#include <vconf-keys.h>
+
+static void dock_changed_cb(keynode_t* node, void* data)
+{
+       int dock_available = 0;
+
+       /* Get actual vconf value */
+       vconf_get_int(VCONFKEY_SYSMAN_CRADLE_STATUS, &dock_available);
+
+       debug_msg ("[%s] changed callback called, key value is [%d]\n", vconf_keynode_get_name(node), dock_available);
+
+       /* Set device available based on vconf key value */
+       MMSoundMgrSessionSetDeviceAvailable (DEVICE_DOCK, dock_available, 0, NULL);
+}
+
+int _register_dock_status ()
+{
+       /* set callback for vconf key change */
+       int ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_CRADLE_STATUS, dock_changed_cb, NULL);
+       debug_msg ("vconf [%s] set ret = %d\n", VCONFKEY_SYSMAN_CRADLE_STATUS, ret);
+       return ret;
+}
+
+
+int MMSoundMgrDockInit(void)
+{
+       debug_enter("\n");
+
+       _register_dock_status ();
+
+       debug_leave("\n");
+       return MM_ERROR_NONE;
+}
+
+int MMSoundMgrDockFini(void)
+{
+       debug_enter("\n");
+
+       debug_leave("\n");
+       return MM_ERROR_NONE;
+}
+
index bdcfa07..cf5351e 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "include/mm_sound_mgr_common.h"
 #include "../include/mm_sound_common.h"
+#include "../include/mm_sound.h"
 
 #include <mm_error.h>
 #include <mm_debug.h>
@@ -102,6 +103,8 @@ static int __set_sound_path_to_dual ();
 #define _mm_sound_mgr_device_active_device_callback(a,b)       MM_ERROR_NONE
 #endif
 
+#define SOUND_DOCK_ON  "/usr/share/svi/sound/operation/new_chat.wav"
+#define SOUND_DOCK_OFF "/usr/share/svi/sound/operation/sent_chat.wav"
 
 typedef struct _session_info_struct
 {
@@ -122,7 +125,7 @@ typedef struct _session_info_struct
 
 SESSION_INFO_STRUCT g_info;
 
-#define PLAYBACK_NUM   5
+#define PLAYBACK_NUM   6
 #define CAPTURE_NUM    3
 
 typedef enum
@@ -136,7 +139,7 @@ static void dump_info ()
 {
        int i = 0;
 
-       char *playback_device_str[] = { "SPEAKER ", "RECEIVER ", "HEADSET ", "BTSCO ", "BTA2DP " };
+       char *playback_device_str[] = { "SPEAKER ", "RECEIVER ", "HEADSET ", "BTSCO ", "BTA2DP ", "DOCK " };
        char *capture_device_str[] = { "MAINMIC ", "HEADSET ", "BTMIC "  };
 
        static char tmp_str[128];
@@ -508,6 +511,8 @@ static int __set_sound_path_for_current_active ()
                out = AVSYS_AUDIO_PATH_EX_BTHEADSET;
        } else if (IS_ACTIVE(MM_SOUND_DEVICE_OUT_BT_A2DP)) {
                out = AVSYS_AUDIO_PATH_EX_A2DP;
+       } else if (IS_ACTIVE(MM_SOUND_DEVICE_OUT_DOCK)) {
+               out = AVSYS_AUDIO_PATH_EX_DOCK;
        }
 
        /* GAIN */
@@ -599,6 +604,9 @@ static void _select_playback_active_device ()
        if (IS_AVAILABLE(MM_SOUND_DEVICE_OUT_BT_A2DP)) {
                debug_log ("BT A2DP available, set as active!!\n");
                SET_ACTIVE(MM_SOUND_DEVICE_OUT_BT_A2DP);
+       } else if (IS_AVAILABLE(MM_SOUND_DEVICE_OUT_DOCK)) {
+               debug_log ("DOCK available, set as active!!\n");
+               SET_ACTIVE(MM_SOUND_DEVICE_OUT_DOCK);
        } else if (IS_AVAILABLE(MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY)) {
                debug_log ("WIRED available, set as active!!\n");
                SET_ACTIVE(MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY);
@@ -826,6 +834,75 @@ static void handle_headset_off ()
        dump_info ();
 }
 
+void _sound_finished_cb (void *data)
+{
+       debug_log ("sound play finished!!!\n");
+       *(bool*)data = true;
+}
+
+static void _play_dock_sound_sync(int is_on)
+{
+       int handle;
+       bool is_play_finished = false;
+
+       debug_log ("start to play dock sound [%d]\n", is_on);
+       mm_sound_play_loud_solo_sound((is_on? SOUND_DOCK_ON : SOUND_DOCK_OFF), VOLUME_TYPE_FIXED, _sound_finished_cb, &is_play_finished, &handle);
+       /* FIXME : need to enhance waiting method */
+       debug_log ("waiting for dock sound finish\n");
+       while (!is_play_finished) {
+               usleep (10000); // 10 ms
+       }
+       debug_log ("dock sound finished!!!\n");
+}
+
+static void handle_dock_on ()
+{
+       /* ToDo : alarm/notification session ???? */
+       if (IS_COMMUNICATION_SESSION()) {
+               debug_log ("Current session is VOICECALL, no auto-activation!!!\n");
+               return;
+       }
+
+       debug_log ("Activate DOCK device\n");
+       SET_PLAYBACK_ONLY_ACTIVE(MM_SOUND_DEVICE_OUT_DOCK);
+
+       /* Enforced audio */
+       _play_dock_sound_sync(true);
+
+       /* Do set path and notify result */
+       _set_path_with_notification(DO_NOTI);
+
+       dump_info ();
+}
+
+static void handle_dock_off ()
+{
+       if (!IS_ACTIVE(MM_SOUND_DEVICE_OUT_DOCK)) {
+               debug_msg("MM_SOUND_DEVICE_OUT_WIRED_ACCESSORY was not active. nothing to do here.");
+               return;
+       }
+
+       /* if DOCK was active, then do asm pause */
+       debug_msg("Do pause here");
+       _asm_pause_process (g_info.asm_handle);
+
+       /* Enforced audio */
+       _play_dock_sound_sync(false);
+
+       /* set DOCK device to none */
+       debug_msg("Deactivate DOCK device\n");
+       UNSET_ACTIVE(MM_SOUND_DEVICE_OUT_DOCK);
+
+       /* activate current available device based on priority */
+       _select_playback_active_device();
+
+       /* Do set path and notify result */
+       _set_path_with_notification(DO_NOTI);
+
+       dump_info ();
+}
+
+
 /* ------------------------- EXTERNAL FUNCTIONS ------------------------------------*/
 /* DEVICE : Called by mgr_pulse for updating current default_sink_name */
 int MMSoundMgrSessionSetDefaultSink (char *default_sink_name)
@@ -955,6 +1032,30 @@ int MMSoundMgrSessionSetDeviceAvailable (device_type_t device, int available, in
                break;
 
        case DEVICE_DOCK:
+               if (available) {
+                       if (!IS_AVAILABLE(MM_SOUND_DEVICE_OUT_DOCK)) {
+                               SET_AVAILABLE(MM_SOUND_DEVICE_OUT_DOCK);
+                               _mm_sound_mgr_device_available_device_callback(
+                                                                                       MM_SOUND_DEVICE_IN_NONE,
+                                                                                       MM_SOUND_DEVICE_OUT_DOCK,
+                                                                                       AVAILABLE);
+                               handle_dock_on();
+                       } else {
+                               debug_log ("Already device [%d] is available...\n", device);
+                       }
+               } else {
+                       if (IS_AVAILABLE(MM_SOUND_DEVICE_OUT_DOCK)) {
+                               UNSET_AVAILABLE(MM_SOUND_DEVICE_OUT_DOCK);
+                               _mm_sound_mgr_device_available_device_callback(
+                                                                                       MM_SOUND_DEVICE_IN_NONE,
+                                                                                       MM_SOUND_DEVICE_OUT_DOCK,
+                                                                                       NOT_AVAILABLE);
+
+                               handle_dock_off();
+                       } else {
+                               debug_log ("Already device [%d] is unavailable...\n", device);
+                       }
+               }
                break;
        }
 
index d569227..6ec5025 100644 (file)
@@ -40,6 +40,7 @@
 #include "include/mm_sound_mgr_asm.h"
 #include "include/mm_sound_mgr_session.h"
 #include "include/mm_sound_mgr_headset.h"
+#include "include/mm_sound_mgr_dock.h"
 #include "include/mm_sound_recovery.h"
 #include "include/mm_sound_utils.h"
 #include "include/mm_sound_common.h"
@@ -212,6 +213,7 @@ int main(int argc, char **argv)
                wait_for_asm_ready();
                _mm_sound_mgr_device_init();
                MMSoundMgrHeadsetInit();
+               MMSoundMgrDockInit();
                MMSoundMgrSessionInit();
        }
 
@@ -235,6 +237,7 @@ int main(int argc, char **argv)
                MMSoundMgrRunFini();
                MMSoundThreadPoolFini();
 
+               MMSoundMgrDockFini();
                MMSoundMgrHeadsetFini();
                MMSoundMgrSessionFini();
                _mm_sound_mgr_device_fini();