2 * Copyright (c) [2012] Samsung Electronics Co., Ltd.
4 * Licensed under the Flora License, Version 1.1 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <sound_manager.h>
20 #include <Ecore_Evas.h>
21 #include <Elementary.h>
24 #include "mp-video-log.h"
25 #include "video-player.h"
26 #include "mp-video-type-define.h"
27 #include "mp-video-value-define.h"
28 #include "mp-video-string-define.h"
29 #include "mp-video-sound-path-ctrl.h"
31 #define MP_VIDEO_SOUND_PATH_NUM 10
32 #define MP_VIDEO_SOUND_PATH_SPEAKER "Speaker"
33 #define MP_VIDEO_SOUND_PATH_EARJACK "Headphones"
35 static Evas_Object *pVideoSoundPathPopUpHandle = NULL;
36 //static Evas_Object *pVideoSoundPathpPopupWindow = NULL;
37 static Evas_Object *pGroupRadio = NULL;
38 static Evas_Object *pGenList = NULL;
40 static char **szSoundPathItems = NULL;
41 static bool bIsConnectBluetooth = FALSE;
42 static bool bIsConnectEarjack = FALSE;
44 void MpVideoSoundpathDeleteRadioButton(void)
49 evas_object_del(pGroupRadio);
54 void MpVideoSoundpathDeletePopupHandle(void)
62 for(nCount = 0; nCount < MP_VIDEO_SOUND_PATH_NUM; nCount++)
64 if(szSoundPathItems[nCount])
66 free(szSoundPathItems[nCount]);
67 szSoundPathItems[nCount] = NULL;
70 free(szSoundPathItems);
71 szSoundPathItems = NULL;
74 MpVideoSoundpathDeleteRadioButton();
77 evas_object_del(pGenList);
81 if (pVideoSoundPathPopUpHandle) {
82 evas_object_del(pVideoSoundPathPopUpHandle);
83 pVideoSoundPathPopUpHandle = NULL;
86 MpUtilSetAlphaOfMainWindow(TRUE);
89 if (pVideoSoundPathpPopupWindow) {
90 evas_object_del(pVideoSoundPathpPopupWindow);
91 pVideoSoundPathpPopupWindow = NULL;
96 static char *MpVideoSoundpathGetLabelOfGenlistItemCb(const void *pUserData,
102 int nIndex = (int)pUserData;
104 if (!strcmp(pPart, "elm.text")) {
105 VideoLogInfo("Index : %d", nIndex);
106 return strdup(szSoundPathItems[nIndex]);
112 static Evas_Object *MpVideoSoundpathGetIconOfGenlistItemCb(const void
114 Evas_Object *pObject,
119 int nIndex = (int)pUserData;
120 Evas_Object *pTmpRadio = NULL;
122 if (!strcmp(pPart, "elm.icon")) {
123 VideoLogInfo("Index : %d", nIndex);
124 pTmpRadio = elm_radio_add(pObject);
125 elm_radio_state_value_set(pTmpRadio, nIndex);
126 evas_object_show(pTmpRadio);
127 elm_radio_group_add(pTmpRadio, pGroupRadio);
133 static void MpVideoSoundpathSelectSoundPathItemCb(void *pUserData, Evas_Object *pObject, void *pEventInfo)
135 if(pUserData == NULL)
137 VideoLogInfo("[ERR]No have pUserData");
143 VideoAppData *pAppData = (VideoAppData *)pUserData;
146 Elm_Object_Item *pItem = (Elm_Object_Item *) pEventInfo;
150 nIndex = (int)elm_object_item_data_get(pItem);
151 VideoLogInfo("Select sound path : %s", szSoundPathItems[nIndex]);
153 if(!strcmp(szSoundPathItems[nIndex], MP_VIDEO_SOUND_PATH_SPEAKER))
156 nRet = sound_manager_set_active_route(SOUND_ROUTE_OUT_SPEAKER);
158 elm_radio_value_set(pGroupRadio, MP_SOUND_PATH_SPEAKER);
160 else if (!strcmp(szSoundPathItems[nIndex], MP_VIDEO_SOUND_PATH_EARJACK))
162 int nRet = sound_manager_set_active_route(SOUND_ROUTE_OUT_WIRED_ACCESSORY);
163 if(nRet != SOUND_MANAGER_ERROR_NONE)
165 VideoLogInfo("[ERR] set_system_policy(0x%x)", nRet);
169 elm_radio_value_set(pGroupRadio, MP_SOUND_PATH_EARJACK);
174 //int nRet = sound_manager_set_route_policy(SOUND_ROUTE_DEFAULT);
175 int nRet = sound_manager_set_active_route(SOUND_ROUTE_OUT_BLUETOOTH);
176 if(nRet != SOUND_MANAGER_ERROR_NONE)
178 VideoLogInfo("[ERR] set_system_policy(0x%x)", nRet);
182 elm_radio_value_set(pGroupRadio, MP_SOUND_PATH_BLUETOOTH);
187 MpVideoSoundpathDeletePopupHandle();
190 static void MpVideoSoundpathPopupCb(void *pUserData, Evas_Object *pObject,
195 if (pUserData == NULL) {
196 VideoLogInfo("[ERR]No have pUserData");
200 MpVideoSoundpathDeletePopupHandle();
203 static void MpVideoSoundpathCurrentState()
207 bool bBluetoothConnect = 0;
208 char *szBluetoothName = NULL;
209 bIsConnectEarjack = FALSE;
210 bIsConnectBluetooth = FALSE;
213 strncpy(szSoundPathItems[MP_SOUND_PATH_SPEAKER], MP_VIDEO_SOUND_PATH_SPEAKER, STR_LEN_MAX - 1);
215 /* Check and Add earjack sound path. */
216 if(MpUtilIsConnectEarjack())
218 VideoLogInfo("Connect earjack.");
219 bIsConnectEarjack = TRUE;
220 strncpy(szSoundPathItems[MP_SOUND_PATH_EARJACK], MP_VIDEO_SOUND_PATH_EARJACK, STR_LEN_MAX - 1);
224 VideoLogInfo("No connect earjack.");
227 /* Add bluetooth stereo sound path. */
228 if(SOUND_MANAGER_ERROR_NONE != sound_manager_get_a2dp_status(&bBluetoothConnect, &szBluetoothName))
230 VideoLogInfo("[ERR] Fail to check bluetooth stereo sound path.");
234 if(bBluetoothConnect)
238 VideoLogInfo("Connect szBluetoothName : %s", szBluetoothName);
239 bIsConnectBluetooth = TRUE;
240 strncpy(szSoundPathItems[MP_SOUND_PATH_BLUETOOTH], szBluetoothName, STR_LEN_MAX - 1);
241 free(szBluetoothName);
242 szBluetoothName = NULL;
249 free(szBluetoothName);
250 szBluetoothName = NULL;
252 VideoLogInfo("Unactivate Bluetooth stereo A2DP.");
258 void MpVideoSoundpathSetRadioButton(void)
262 sound_device_in_e in;
263 sound_device_out_e out;
265 sound_manager_get_active_device(&in, &out);
269 case SOUND_DEVICE_OUT_SPEAKER:
270 elm_radio_value_set(pGroupRadio, MP_SOUND_PATH_SPEAKER);
273 case SOUND_DEVICE_OUT_WIRED_ACCESSORY:
274 elm_radio_value_set(pGroupRadio, MP_SOUND_PATH_EARJACK);
277 case SOUND_DEVICE_OUT_BT_A2DP:
278 elm_radio_value_set(pGroupRadio, MP_SOUND_PATH_BLUETOOTH);
282 elm_radio_value_set(pGroupRadio, MP_SOUND_PATH_SPEAKER);
287 bool bBluetoothConnect = 0;
288 char *szBluetoothName = NULL;
289 sound_route_policy_e nPolicy = 0;
291 if(sound_manager_get_route_policy(&nPolicy) != SOUND_MANAGER_ERROR_NONE)
293 VideoLogInfo("[ERR] Fail to get sound path route policy.");
297 if(nPolicy == SOUND_ROUTE_DEFAULT)
299 VideoLogInfo("SYSTEM_AUDIO_ROUTE_POLICY_DEFAULT");
301 if(SOUND_MANAGER_ERROR_NONE != sound_manager_get_a2dp_status(&bBluetoothConnect, &szBluetoothName))
303 VideoLogInfo("[ERR] Fail to check bluetooth stereo sound path.");
306 if(bBluetoothConnect)
308 elm_radio_value_set(pGroupRadio, MP_SOUND_PATH_BLUETOOTH);
310 else if(MpUtilIsConnectEarjack())
312 elm_radio_value_set(pGroupRadio, MP_SOUND_PATH_EARJACK);
316 elm_radio_value_set(pGroupRadio, MP_SOUND_PATH_SPEAKER);
319 else if(nPolicy == SOUND_ROUTE_IGNORE_A2DP)
321 VideoLogInfo("SYSTEM_AUDIO_ROUTE_POLICY_IGNORE_A2DP");
323 if(MpUtilIsConnectEarjack())
325 elm_radio_value_set(pGroupRadio, MP_SOUND_PATH_EARJACK);
329 elm_radio_value_set(pGroupRadio, MP_SOUND_PATH_SPEAKER);
334 VideoLogInfo("SYSTEM_AUDIO_ROUTE_POLICY_HANDSET_ONLY");
336 elm_radio_value_set(pGroupRadio, MP_SOUND_PATH_SPEAKER);
344 bool MpVideoSoundpathShow(void *pUserData)
346 if (pUserData == NULL) {
347 VideoLogInfo("No have popup message or pAppData is null.");
353 MpVideoSoundpathIsConnectOtherSoundpath();
355 if (!bIsConnectBluetooth && !bIsConnectEarjack) {
356 VideoLogInfo("Soundpath is only speaker.");
360 Evas_Object *pBox = NULL;
361 Evas_Object *pButton = NULL;
362 VideoAppData *pAppData = (VideoAppData *)pUserData;
364 MpVideoSoundpathDeletePopupHandle();
366 MpUtilSetAlphaOfMainWindow(FALSE);
369 //pVideoSoundPathpPopupWindow = (Evas_Object *)MpUtilCreateWindow("soundpath_popup_window");
370 //pVideoSoundPathPopUpHandle = elm_popup_add(pVideoSoundPathpPopupWindow);
371 pVideoSoundPathPopUpHandle = elm_popup_add(pAppData->pMainWindow);
374 szSoundPathItems = (char **)calloc(1, sizeof(char *) * MP_VIDEO_SOUND_PATH_NUM);
376 for(idx = 0; idx < MP_VIDEO_SOUND_PATH_NUM; idx++)
378 szSoundPathItems[idx] = (char *)calloc(1, STR_LEN_MAX * sizeof(char));
381 MpVideoSoundpathCurrentState();
383 elm_object_style_set(pVideoSoundPathPopUpHandle, "menustyle");
384 elm_object_part_text_set(pVideoSoundPathPopUpHandle, "title,text", MP_VIDEO_SOUND_PATH);
385 evas_object_size_hint_weight_set(pVideoSoundPathPopUpHandle, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
387 pButton = elm_button_add(pVideoSoundPathPopUpHandle);
388 elm_object_style_set (pButton, "popup_button/default");
389 elm_object_text_set(pButton, dgettext(MP_SYS_STRING, MP_COM_BUTTON_CANCEL));
390 elm_object_part_content_set(pVideoSoundPathPopUpHandle, "button1", pButton);
391 evas_object_smart_callback_add(pButton, "clicked", MpVideoSoundpathPopupCb, (void*)pAppData);
393 /* Set item of Genlist. */
394 Elm_Genlist_Item_Class *st_Itc = NULL;
395 st_Itc = elm_genlist_item_class_new();
396 st_Itc->item_style = "1text.1icon.3";
397 st_Itc->func.text_get = (void *)MpVideoSoundpathGetLabelOfGenlistItemCb;
398 st_Itc->func.content_get = (void *)MpVideoSoundpathGetIconOfGenlistItemCb;
399 st_Itc->func.state_get = NULL;
400 st_Itc->func.del = NULL;
402 /* Create genlist handle */
403 pGenList = elm_genlist_add(pVideoSoundPathPopUpHandle);
404 evas_object_size_hint_weight_set(pGenList, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
405 evas_object_size_hint_align_set(pGenList, EVAS_HINT_FILL, EVAS_HINT_FILL);
407 //MpUtilRotateWindow(MpUtilGetRotationState(), pVideoSoundPathpPopupWindow);
409 pGroupRadio = elm_radio_add(pGenList);
411 if (bIsConnectBluetooth) {
412 elm_genlist_item_append(pGenList, st_Itc, (void *)MP_SOUND_PATH_BLUETOOTH, NULL,
413 ELM_GENLIST_ITEM_NONE,
414 MpVideoSoundpathSelectSoundPathItemCb,
418 if (bIsConnectEarjack) {
419 elm_genlist_item_append(pGenList, st_Itc, (void *)MP_SOUND_PATH_EARJACK, NULL,
420 ELM_GENLIST_ITEM_NONE,
421 MpVideoSoundpathSelectSoundPathItemCb,
425 elm_genlist_item_append(pGenList, st_Itc, (void *)MP_SOUND_PATH_SPEAKER, NULL,
426 ELM_GENLIST_ITEM_NONE,
427 MpVideoSoundpathSelectSoundPathItemCb,
430 elm_genlist_item_class_free(st_Itc);
432 MpVideoSoundpathSetRadioButton();
434 pBox = elm_box_add(pVideoSoundPathPopUpHandle);
435 if(bIsConnectBluetooth && bIsConnectEarjack)
437 evas_object_size_hint_min_set(pBox, 614 * elm_config_scale_get(), 338 * elm_config_scale_get());
439 else if(bIsConnectBluetooth || bIsConnectEarjack)
441 evas_object_size_hint_min_set(pBox, 614 * elm_config_scale_get(), 225 * elm_config_scale_get());
445 evas_object_size_hint_min_set(pBox, 614 * elm_config_scale_get(), 451 * elm_config_scale_get());
448 elm_box_pack_end(pBox, pGenList);
449 elm_object_content_set(pVideoSoundPathPopUpHandle, pBox);
451 evas_object_show(pGenList);
452 evas_object_show(pVideoSoundPathPopUpHandle);
457 void MpVideoSoundpathHide(void)
461 MpVideoSoundpathDeletePopupHandle();
464 void MpVideoSoundpathRotatePopupWindow(int nRotateMode)
467 if (!pVideoSoundPathpPopupWindow) {
468 VideoLogInfo("No exist genlist popup window handle.");
474 MpUtilRotateWindow(nRotateMode, pVideoSoundPathpPopupWindow);
480 bool MpVideoSoundpathIsConnectOtherSoundpath(void)
484 bool bBluetoothConnect = 0;
485 char *szBluetoothName = NULL;
487 bIsConnectEarjack = FALSE;
488 bIsConnectBluetooth = FALSE;
490 if(MpUtilIsConnectEarjack())
492 VideoLogInfo("Connect earjack.");
493 bIsConnectEarjack= TRUE;
496 sound_manager_get_a2dp_status(&bBluetoothConnect, &szBluetoothName);
498 if(bBluetoothConnect)
500 if(szBluetoothName) {
501 free(szBluetoothName);
502 szBluetoothName = NULL;
505 VideoLogInfo("Connect bluetooth.");
506 bIsConnectBluetooth = TRUE;
510 if(szBluetoothName) {
511 free(szBluetoothName);
512 szBluetoothName = NULL;
515 VideoLogInfo("Only spaker.");
519 int MpVideoSoundpathGetCurrConnectedSoundpath(void)
523 sound_device_in_e in;
524 sound_device_out_e out;
525 MpSoundPathType nType = MP_SOUND_PATH_SPEAKER;
527 sound_manager_get_active_device(&in, &out);
531 case SOUND_DEVICE_OUT_SPEAKER:
532 nType = MP_SOUND_PATH_SPEAKER;
535 case SOUND_DEVICE_OUT_WIRED_ACCESSORY:
536 nType = MP_SOUND_PATH_EARJACK;
539 case SOUND_DEVICE_OUT_BT_A2DP:
540 nType = MP_SOUND_PATH_BLUETOOTH;
544 nType = MP_SOUND_PATH_SPEAKER;
551 bool bBluetoothConnect = 0;
552 char *szBluetoothName = NULL;
553 sound_route_policy_e nPolicy = 0;
555 if(sound_manager_get_route_policy(&nPolicy) != SOUND_MANAGER_ERROR_NONE)
557 VideoLogInfo("[ERR] Fail to get sound path route policy.");
558 return MP_SOUND_PATH_SPEAKER;
561 if(nPolicy == SOUND_ROUTE_DEFAULT)
563 VideoLogInfo("SYSTEM_AUDIO_ROUTE_POLICY_DEFAULT");
565 if(SOUND_MANAGER_ERROR_NONE != sound_manager_get_a2dp_status(&bBluetoothConnect, &szBluetoothName))
567 VideoLogInfo("[ERR] Fail to check bluetooth stereo sound path.");
570 if(bBluetoothConnect)
572 return MP_SOUND_PATH_BLUETOOTH;
574 else if(MpUtilIsConnectEarjack())
576 return MP_SOUND_PATH_EARJACK;
580 return MP_SOUND_PATH_SPEAKER;
583 else if(nPolicy == SOUND_ROUTE_IGNORE_A2DP)
585 VideoLogInfo("SYSTEM_AUDIO_ROUTE_POLICY_IGNORE_A2DP");
587 if(MpUtilIsConnectEarjack())
589 return MP_SOUND_PATH_EARJACK;
593 return MP_SOUND_PATH_SPEAKER;
598 VideoLogInfo("SYSTEM_AUDIO_ROUTE_POLICY_HANDSET_ONLY");
600 return MP_SOUND_PATH_SPEAKER;
603 return MP_SOUND_PATH_SPEAKER;