2 * Copyright 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved
4 * This file is part of org.tizen.video-player
5 * Written by JongDong Lee <jongdong.lee@samsung.com>, ChangSun Lee <cs78.lee@samsung.com>
7 * PROPRIETARY/CONFIDENTIAL
9 * This software is the confidential and proprietary information of SAMSUNG ELECTRONICS ("Confidential Information").
10 * You shall not disclose such Confidential Information and shall
11 * use it only in accordance with the terms of the license agreement you entered into with SAMSUNG ELECTRONICS.
12 * SAMSUNG make no representations or warranties about the suitability
13 * of the software, either express or implied, including but not
14 * limited to the implied warranties of merchantability, fitness for a particular purpose, or non-infringement.
15 * SAMSUNG shall not be liable for any damages suffered by licensee as
16 * a result of using, modifying or distributing this software or its derivatives.
22 #include <Ecore_Evas.h>
23 #include <Elementary.h>
24 #include <appcore-efl.h>
25 #include <appcore-common.h>
28 #include "mp-video-log.h"
29 #include "video-player.h"
30 #include "mp-video-type-define.h"
31 #include "mp-video-value-define.h"
32 #include "mp-video-string-define.h"
33 #include "mp-video-sound-path-ctrl.h"
35 #define MP_VIDEO_SOUND_PATH_NUM 10
36 #define MP_VIDEO_SOUND_PATH_SPEAKER "Speaker"
37 #define MP_VIDEO_SOUND_PATH_EARJACK "Headphones"
39 static Evas_Object *pVideoSoundPathPopUpHandle = NULL;
40 static Evas_Object *pGroupRadio = NULL;
41 static Evas_Object *pGenList = NULL;
43 static Elm_Genlist_Item_Class st_Itc;
44 static char szSoundPathItems[MP_VIDEO_SOUND_PATH_NUM][STR_LEN_MAX];
45 static bool bIsConnectBluetooth = FALSE;
46 static bool bIsConnectEarjack = FALSE;
48 void MpVideoSoundpathDeleteRadioButton(void)
53 evas_object_del(pGroupRadio);
58 void MpVideoSoundpathDeletePopupHandle(void)
64 for (nCount = 0; nCount < MP_VIDEO_SOUND_PATH_NUM; nCount++) {
65 memset(&szSoundPathItems[nCount][0], 0,
66 sizeof(char) * STR_LEN_MAX);
69 MpVideoSoundpathDeleteRadioButton();
71 memset(&st_Itc, 0, sizeof(Elm_Genlist_Item_Class));
74 evas_object_del(pGenList);
78 if (pVideoSoundPathPopUpHandle) {
79 evas_object_del(pVideoSoundPathPopUpHandle);
80 pVideoSoundPathPopUpHandle = NULL;
85 static char *MpVideoSoundpathGetLabelOfGenlistItemCb(const void *pUserData,
91 int nIndex = (int)pUserData;
93 if (!strcmp(pPart, "elm.text")) {
94 VideoLogInfo("Index : %d", nIndex);
95 return strdup(&szSoundPathItems[nIndex][0]);
101 static Evas_Object *MpVideoSoundpathGetIconOfGenlistItemCb(const void
103 Evas_Object *pObject,
108 int nIndex = (int)pUserData;
109 Evas_Object *pTmpRadio = NULL;
111 if (!strcmp(pPart, "elm.icon")) {
112 VideoLogInfo("Index : %d", nIndex);
113 pTmpRadio = elm_radio_add(pObject);
114 elm_radio_state_value_set(pTmpRadio, nIndex);
115 evas_object_show(pTmpRadio);
116 elm_radio_group_add(pTmpRadio, pGroupRadio);
122 static void MpVideoSoundpathSelectSoundPathItemCb(void *pUserData,
123 Evas_Object *pObject,
126 if (pUserData == NULL) {
127 VideoLogInfo("[ERR]No have pUserData");
134 Elm_Object_Item *pItem = (Elm_Object_Item *) pEventInfo;
137 nIndex = (int)elm_object_item_data_get(pItem);
138 VideoLogInfo("Select sound path : %s", szSoundPathItems[nIndex]);
140 if (!strcmp(szSoundPathItems[nIndex], MP_VIDEO_SOUND_PATH_SPEAKER)) {
143 if (MpUtilIsConnectEarjack()) {
144 nRet = mm_sound_route_set_system_policy(SYSTEM_AUDIO_ROUTE_POLICY_HANDSET_ONLY);
146 nRet = mm_sound_route_set_system_policy(SYSTEM_AUDIO_ROUTE_POLICY_IGNORE_A2DP);
149 elm_radio_value_set(pGroupRadio, MP_SOUND_PATH_SPEAKER);
150 } else if (!strcmp(szSoundPathItems[nIndex], MP_VIDEO_SOUND_PATH_EARJACK)) {
151 int nRet = mm_sound_route_set_system_policy(SYSTEM_AUDIO_ROUTE_POLICY_IGNORE_A2DP);
152 if (nRet != MM_ERROR_NONE) {
153 VideoLogInfo("[ERR] mm_sound_route_set_system_policy(0x%x)", nRet);
155 elm_radio_value_set(pGroupRadio, MP_SOUND_PATH_EARJACK);
158 int nRet = mm_sound_route_set_system_policy(SYSTEM_AUDIO_ROUTE_POLICY_DEFAULT);
159 if (nRet != MM_ERROR_NONE) {
160 VideoLogInfo("[ERR] mm_sound_route_set_system_policy(0x%x)", nRet);
162 elm_radio_value_set(pGroupRadio, MP_SOUND_PATH_BLUETOOTH);
167 MpVideoSoundpathDeletePopupHandle();
170 static void MpVideoSoundpathPopupCb(void *pUserData, Evas_Object *pObject,
175 if (pUserData == NULL) {
176 VideoLogInfo("[ERR]No have pUserData");
180 MpVideoSoundpathDeletePopupHandle();
183 void MpVideoSoundpathCurrentState(Evas_Object *pParent)
187 int nBluetoothConnect = 0;
188 char *szBluetoothName = NULL;
189 bIsConnectEarjack = FALSE;
190 bIsConnectBluetooth = FALSE;
193 strncpy(&szSoundPathItems[MP_SOUND_PATH_SPEAKER][0], MP_VIDEO_SOUND_PATH_SPEAKER, STR_LEN_MAX - 1);
195 /* Check and Add earjack sound path. */
196 if (MpUtilIsConnectEarjack()) {
197 VideoLogInfo("Connect earjack.");
198 bIsConnectEarjack = TRUE;
199 strncpy(&szSoundPathItems[MP_SOUND_PATH_EARJACK][0], MP_VIDEO_SOUND_PATH_EARJACK, STR_LEN_MAX - 1);
201 VideoLogInfo("No connect earjack.");
204 /* Add bluetooth stereo sound path. */
205 if (MM_ERROR_NONE != mm_sound_route_get_a2dp_status(&nBluetoothConnect, &szBluetoothName)) {
206 VideoLogInfo("[ERR] Fail to check bluetooth stereo sound path.");
208 if (nBluetoothConnect) {
209 VideoLogInfo("Connect szBluetoothName : %s", szBluetoothName);
210 bIsConnectBluetooth = TRUE;
211 strncpy(&szSoundPathItems[MP_SOUND_PATH_BLUETOOTH][0], szBluetoothName, STR_LEN_MAX - 1);
213 VideoLogInfo("Unactivate Bluetooth stereo A2DP.");
218 void MpVideoSoundpathSetRadioButton(void)
222 int nBluetoothConnect = 0;
223 char *szBluetoothName = NULL;
224 system_audio_route_t nPolicy = 0;
226 mm_sound_route_get_system_policy(&nPolicy);
228 if (nPolicy == SYSTEM_AUDIO_ROUTE_POLICY_DEFAULT) {
229 VideoLogInfo("SYSTEM_AUDIO_ROUTE_POLICY_DEFAULT");
231 if (MM_ERROR_NONE != mm_sound_route_get_a2dp_status(&nBluetoothConnect, &szBluetoothName)) {
232 VideoLogInfo("[ERR] Fail to check bluetooth stereo sound path.");
235 if (nBluetoothConnect) {
236 elm_radio_value_set(pGroupRadio, MP_SOUND_PATH_BLUETOOTH);
237 } else if (MpUtilIsConnectEarjack()) {
238 elm_radio_value_set(pGroupRadio, MP_SOUND_PATH_EARJACK);
240 elm_radio_value_set(pGroupRadio, MP_SOUND_PATH_SPEAKER);
242 } else if (nPolicy == SYSTEM_AUDIO_ROUTE_POLICY_IGNORE_A2DP) {
243 VideoLogInfo("SYSTEM_AUDIO_ROUTE_POLICY_IGNORE_A2DP");
245 if (MpUtilIsConnectEarjack()) {
246 elm_radio_value_set(pGroupRadio, MP_SOUND_PATH_EARJACK);
248 elm_radio_value_set(pGroupRadio, MP_SOUND_PATH_SPEAKER);
251 VideoLogInfo("SYSTEM_AUDIO_ROUTE_POLICY_HANDSET_ONLY");
253 elm_radio_value_set(pGroupRadio, MP_SOUND_PATH_SPEAKER);
260 bool MpVideoSoundpathShow(void *pUserData)
262 if (pUserData == NULL) {
263 VideoLogInfo("No have popup message or pAppData is null.");
269 MpVideoSoundpathIsConnectOtherSoundpath();
271 if (!bIsConnectBluetooth && !bIsConnectEarjack) {
272 VideoLogInfo("Soundpath is only speaker.");
276 Evas_Object *pBox = NULL;
277 Evas_Object *pButton = NULL;
278 VideoAppData *pAppData = (VideoAppData *)pUserData;
280 MpVideoSoundpathDeletePopupHandle();
282 pVideoSoundPathPopUpHandle = elm_popup_add(pAppData->pMainWindow);
284 MpVideoSoundpathCurrentState(pVideoSoundPathPopUpHandle);
286 elm_object_style_set(pVideoSoundPathPopUpHandle, "min_menustyle");
287 elm_object_part_text_set(pVideoSoundPathPopUpHandle, "title,text", MP_VIDEO_SOUND_PATH);
288 evas_object_size_hint_weight_set(pVideoSoundPathPopUpHandle, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
290 pButton = elm_button_add(pVideoSoundPathPopUpHandle);
291 elm_object_text_set(pButton, dgettext(MP_SYS_STRING, MP_COM_BUTTON_CANCEL));
292 elm_object_part_content_set(pVideoSoundPathPopUpHandle, "button1", pButton);
293 evas_object_smart_callback_add(pButton, "clicked", MpVideoSoundpathPopupCb, (void*)pAppData);
295 /* Set item of Genlist. */
296 st_Itc.item_style = "1text.1icon.3";
297 st_Itc.func.text_get = (void *)MpVideoSoundpathGetLabelOfGenlistItemCb;
298 st_Itc.func.content_get = (void *)MpVideoSoundpathGetIconOfGenlistItemCb;
299 st_Itc.func.state_get = NULL;
300 st_Itc.func.del = NULL;
302 /* Create genlist handle */
303 pGenList = elm_genlist_add(pVideoSoundPathPopUpHandle);
304 evas_object_size_hint_weight_set(pGenList, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
305 evas_object_size_hint_align_set(pGenList, EVAS_HINT_FILL, EVAS_HINT_FILL);
307 pGroupRadio = elm_radio_add(pGenList);
309 if (bIsConnectBluetooth) {
310 elm_genlist_item_append(pGenList, &st_Itc, (void *)MP_SOUND_PATH_BLUETOOTH, NULL,
311 ELM_GENLIST_ITEM_NONE,
312 MpVideoSoundpathSelectSoundPathItemCb,
316 if (bIsConnectEarjack) {
317 elm_genlist_item_append(pGenList, &st_Itc, (void *)MP_SOUND_PATH_EARJACK, NULL,
318 ELM_GENLIST_ITEM_NONE,
319 MpVideoSoundpathSelectSoundPathItemCb,
323 elm_genlist_item_append(pGenList, &st_Itc, (void *)MP_SOUND_PATH_SPEAKER, NULL,
324 ELM_GENLIST_ITEM_NONE,
325 MpVideoSoundpathSelectSoundPathItemCb,
328 MpVideoSoundpathSetRadioButton();
330 pBox = elm_box_add(pVideoSoundPathPopUpHandle);
331 if (bIsConnectBluetooth && bIsConnectEarjack) {
332 evas_object_size_hint_min_set(pBox, 614 * elm_config_scale_get(), 338 * elm_config_scale_get());
333 } else if(bIsConnectBluetooth || bIsConnectEarjack) {
334 evas_object_size_hint_min_set(pBox, 614 * elm_config_scale_get(), 225 * elm_config_scale_get());
336 evas_object_size_hint_min_set(pBox, 614 * elm_config_scale_get(), 451 * elm_config_scale_get());
338 elm_box_pack_end(pBox, pGenList);
339 elm_object_content_set(pVideoSoundPathPopUpHandle, pBox);
341 evas_object_show(pGenList);
342 evas_object_show(pVideoSoundPathPopUpHandle);
347 void MpVideoSoundpathHide(void)
351 MpVideoSoundpathDeletePopupHandle();
354 bool MpVideoSoundpathIsConnectOtherSoundpath(void)
358 int nBluetoothConnect = 0;
359 char *szBluetoothName = NULL;
361 bIsConnectEarjack = FALSE;
362 bIsConnectBluetooth = FALSE;
364 if (MpUtilIsConnectEarjack()) {
365 VideoLogInfo("Connect earjack.");
366 bIsConnectEarjack= TRUE;
370 mm_sound_route_get_a2dp_status(&nBluetoothConnect, &szBluetoothName);
371 if (nBluetoothConnect) {
372 VideoLogInfo("Connect bluetooth.");
373 bIsConnectBluetooth = TRUE;
377 VideoLogInfo("Only spaker.");
381 int MpVideoSoundpathGetCurrConnectedSoundpath(void)
385 int nBluetoothConnect = 0;
386 char *szBluetoothName = NULL;
387 system_audio_route_t nPolicy = 0;
389 mm_sound_route_get_system_policy(&nPolicy);
391 if (nPolicy == SYSTEM_AUDIO_ROUTE_POLICY_DEFAULT) {
392 VideoLogInfo("SYSTEM_AUDIO_ROUTE_POLICY_DEFAULT");
394 if (MM_ERROR_NONE != mm_sound_route_get_a2dp_status(&nBluetoothConnect, &szBluetoothName)) {
395 VideoLogInfo("[ERR] Fail to check bluetooth stereo sound path.");
398 if (nBluetoothConnect) {
399 return MP_SOUND_PATH_BLUETOOTH;
400 } else if (MpUtilIsConnectEarjack()) {
401 return MP_SOUND_PATH_EARJACK;
403 return MP_SOUND_PATH_SPEAKER;
405 } else if (nPolicy == SYSTEM_AUDIO_ROUTE_POLICY_IGNORE_A2DP) {
406 VideoLogInfo("SYSTEM_AUDIO_ROUTE_POLICY_IGNORE_A2DP");
408 if (MpUtilIsConnectEarjack()) {
409 return MP_SOUND_PATH_EARJACK;
411 return MP_SOUND_PATH_SPEAKER;
414 VideoLogInfo("SYSTEM_AUDIO_ROUTE_POLICY_HANDSET_ONLY");
416 return MP_SOUND_PATH_SPEAKER;