2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (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://www.tizenopensource.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.
25 #include "mp-video-log.h"
26 #include "mp-video-player-mgr.h"
28 #define MAX_PATH_LEN 2048
30 static int nAntiShock = 0;
31 static MMHandleType playerHandle = 0;
33 bool MpPlayerMgrIsActive(void)
35 return playerHandle ? true : false;
38 void MpPlayerMgrSetMessageCallback(MMMessageCallback Callback, void *pUserData)
43 VideoLogInfo("[ERR]");
47 if (!MpPlayerMgrIsActive()) {
48 VideoLogInfo("[ERR]");
52 if (mm_player_set_message_callback(playerHandle, Callback, pUserData) !=
54 VideoLogInfo("[ERR]");
59 bool MpPlayerMgrSetAudioCallback(mm_player_audio_stream_callback CallBack,
65 VideoLogInfo("[ERR]");
69 if (!MpPlayerMgrIsActive()) {
70 VideoLogInfo("[ERR]");
74 if (mm_player_set_audio_stream_callback
75 (playerHandle, CallBack, pUserData) != MM_ERROR_NONE) {
76 VideoLogInfo("[ERR]");
83 bool MpPlayerMgrCreate(const char *szPath)
88 VideoLogInfo("[ERR] Not correct Meida URI.");
92 int nPathLength = strlen(szPath);
93 int nErr = MM_ERROR_NONE;
94 char *pErrName = NULL;
96 VideoLogInfo(" Media path (%s)", szPath);
98 if (nPathLength > 0 && nPathLength < MAX_PATH_LEN) {
99 nErr = mm_player_create(&playerHandle);
100 if (nErr != MM_ERROR_NONE) {
102 ("[ERR] Fail to create player handle. (MMF Error code : %x)",
108 mm_player_set_attribute(playerHandle, &pErrName,
109 "profile_uri", szPath,
110 strlen(szPath), NULL);
112 if (nErr != MM_ERROR_NONE) {
113 VideoLogInfo("[ERR] (%x):: Fail to set attribute ",
120 VideoLogInfo("[ERR] File path is too long.");
125 nErr = mm_player_set_attribute(playerHandle, &pErrName,
126 "sound_fadeup", 1, NULL);
127 if (nErr != MM_ERROR_NONE) {
128 VideoLogInfo("[ERR] (%x):: Fail to set attribute ",
135 nErr = mm_player_set_attribute(playerHandle, &pErrName,
136 "sound_fadeup", 0, NULL);
137 if (nErr != MM_ERROR_NONE) {
138 VideoLogInfo("[ERR] (%x):: Fail to set attribute ",
146 nErr = mm_player_set_attribute(playerHandle, &pErrName,
148 MM_SOUND_VOLUME_TYPE_MEDIA, NULL);
149 if (nErr != MM_ERROR_NONE) {
150 VideoLogInfo("[ERR] (%x):: Fail to set attribute ", nErr,
159 bool MpPlayerMgrDestroy(void)
163 if (!MpPlayerMgrIsActive()) {
164 VideoLogInfo("[ERR]");
168 int nErr = mm_player_destroy(playerHandle);
169 if (nErr != MM_ERROR_NONE) {
170 VideoLogInfo("[ERR] Error code : 0x%x", nErr);
179 bool MpPlayerMgrRealize(void)
183 if (!MpPlayerMgrIsActive()) {
184 VideoLogInfo("[ERR]");
188 int nErr = mm_player_realize(playerHandle);
189 if (nErr != MM_ERROR_NONE) {
190 VideoLogInfo("[ERR] Error code : 0x%x", nErr);
197 bool MpPlayerMgrUnrealize(void)
201 if (!MpPlayerMgrIsActive()) {
202 VideoLogInfo("[ERR]");
206 int nErr = mm_player_unrealize(playerHandle);
207 if (nErr != MM_ERROR_NONE) {
208 VideoLogInfo("[ERR] Error code : 0x%x", nErr);
215 bool MpPlayerMgrPlay(void)
219 if (!MpPlayerMgrIsActive()) {
220 VideoLogInfo("[ERR]");
224 int nErr = mm_player_start(playerHandle);
225 if (nErr != MM_ERROR_NONE) {
226 VideoLogInfo("[ERR] Error code : 0x%x", nErr);
233 bool MpPlayerMgrStop(void)
237 if (!MpPlayerMgrIsActive()) {
238 VideoLogInfo("[ERR]");
242 int nErr = mm_player_stop(playerHandle);
243 if (nErr != MM_ERROR_NONE) {
244 VideoLogInfo("[ERR] Error code : 0x%x", nErr);
251 bool MpPlayerMgrResume(void)
255 if (!MpPlayerMgrIsActive()) {
256 VideoLogInfo("[ERR]");
260 char *pErrName = NULL;
261 int nErr = MM_ERROR_NONE;
264 nErr = mm_player_set_attribute(playerHandle, &pErrName,
265 "sound_fadeup", 1, NULL);
266 if (nErr != MM_ERROR_NONE) {
268 ("[ERR] Error code : 0x%x - Fail to set attribute ",
276 nErr = mm_player_set_attribute(playerHandle, &pErrName,
277 "sound_fadeup", 0, NULL);
278 if (nErr != MM_ERROR_NONE) {
280 ("[ERR] Error code : 0x%x - Fail to set attribute ",
289 nErr = mm_player_resume(playerHandle);
290 if (nErr != MM_ERROR_NONE) {
291 VideoLogInfo("[ERR] Error code : 0x%x", nErr);
298 bool MpPlayerMgrPause(void)
302 if (!MpPlayerMgrIsActive()) {
303 VideoLogInfo("[ERR]");
307 int nErr = mm_player_pause(playerHandle);
308 if (nErr != MM_ERROR_NONE) {
309 VideoLogInfo("[ERR] Error code : 0x%x", nErr);
316 int MpPlayerMgrGetPosition(void)
318 if (!MpPlayerMgrIsActive()) {
325 nErr = mm_player_get_position(playerHandle, MM_PLAYER_POS_FORMAT_TIME,
327 if (nErr != MM_ERROR_NONE) {
328 VideoLogInfo("[ERR] Error code : 0x%x ", nErr);
335 void MpPlayerMgrSetPosition(unsigned int nPos)
339 if (!MpPlayerMgrIsActive()) {
340 VideoLogInfo("[ERR]");
344 VideoLogInfo("Set position - %d", nPos);
348 nErr = mm_player_set_position(playerHandle, MM_PLAYER_POS_FORMAT_TIME,
350 if (nErr != MM_ERROR_NONE) {
351 VideoLogInfo("[ERR] Error code : 0x%x ", nErr);
355 bool MpPlayerMgrGetVisible(void)
359 if (!MpPlayerMgrIsActive()) {
360 VideoLogInfo("[ERR]");
364 int nErr = MM_ERROR_NONE;
366 char *pErrName = NULL;
369 mm_player_get_attribute(playerHandle, &pErrName, "display_visible",
371 if (nErr != MM_ERROR_NONE) {
372 VideoLogInfo("[ERR] Error code : 0x%x - Fail to get attribute.",
378 return (bool) nVisible;
381 void MpPlayerMgrSetVisible(bool bEnabled)
385 if (!MpPlayerMgrIsActive()) {
386 VideoLogInfo("[ERR]");
390 if (MpPlayerMgrGetVisible() == bEnabled) {
391 VideoLogInfo("[ERR]");
395 int nErr = MM_ERROR_NONE;
396 char *pErrName = NULL;
399 mm_player_set_attribute(playerHandle, &pErrName, "display_visible",
400 (int)bEnabled, NULL);
401 if (nErr != MM_ERROR_NONE) {
402 VideoLogInfo("[ERR] Error code : 0x%x - Fail to set attribute ",
408 void MpPlayerMgrSetMute(bool bMuteEnable)
412 if (!MpPlayerMgrIsActive()) {
413 VideoLogInfo("[ERR]");
417 if (mm_player_set_mute(playerHandle, (int)bMuteEnable) != MM_ERROR_NONE) {
418 VideoLogInfo("[ERR]");
422 bool MpPlayerMgrGetMute(void)
426 if (!MpPlayerMgrIsActive()) {
427 VideoLogInfo("[ERR]");
431 bool bIsMute = FALSE;
433 if (mm_player_get_mute(playerHandle, (int *)&bIsMute) != MM_ERROR_NONE) {
434 VideoLogInfo("[ERR]");
441 bool MpPlayerMgrSetBtHeadset(bool bEnable, char *szAddress)
445 VideoLogInfo("bt headset enable(%d)", bEnable);
446 VideoLogInfo("============================================");
447 VideoLogInfo("bluetooth headset enable(%d), addr(%s)", bEnable,
449 VideoLogInfo("============================================");
451 if (!MpPlayerMgrIsActive()) {
452 VideoLogInfo("[ERR]");
456 MMBluetoothType BluetoothParam;
457 memset(&BluetoothParam, 0, sizeof(MMBluetoothType));
460 BluetoothParam.mode = 1;
463 strncpy(BluetoothParam.addr, szAddress,
466 VideoLogInfo("[ERR]");
470 VideoLogInfo("address : %s", szAddress);
476 int MpPlayerMgrGetStreamingType(void)
480 if (!MpPlayerMgrIsActive()) {
481 VideoLogInfo("[ERR]");
485 int nErr = MM_ERROR_NONE;
486 char *pErrName = NULL;
487 int streaming_type = STREAMING_SERVICE_NONE;
490 mm_player_get_attribute(playerHandle, &pErrName, "streaming_type",
491 &streaming_type, NULL);
493 if (nErr != MM_ERROR_NONE) {
494 VideoLogInfo("[ERR] Error code : 0x%x - Fail to get attribute ",
500 return (int)streaming_type;
503 void MpPlayerMgrSetProgressiveDownload(int nFileSize)
507 if (!MpPlayerMgrIsActive()) {
508 VideoLogInfo("[ERR]");
512 int nErr = MM_ERROR_NONE;
513 char *pErrName = NULL;
515 nErr = mm_player_set_attribute(playerHandle, &pErrName, "pd_enable", 1,
516 "pd_full_content_size", nFileSize, NULL);
517 if (nErr != MM_ERROR_NONE) {
518 VideoLogInfo("[ERR] Error code : 0x%x - Fail to set attribute ",
524 void MpPlayerMgrSetDownloadComplete(void)
528 if (!MpPlayerMgrIsActive()) {
529 VideoLogInfo("[ERR]");
533 int nErr = MM_ERROR_NONE;
534 char *pErrName = NULL;
537 mm_player_set_attribute(playerHandle, &pErrName, "pd_down_complete",
539 if (nErr != MM_ERROR_NONE) {
540 VideoLogInfo("[ERR] Error code : 0x%x - Fail to set attribute ",
546 void MpPlayerMgrSetProgressTimerInterval(int nInterval)
550 if (!MpPlayerMgrIsActive()) {
551 VideoLogInfo("[ERR]");
555 char *pErrName = NULL;
556 int nErr = MM_ERROR_NONE;
558 nErr = mm_player_set_attribute(playerHandle, &pErrName,
559 "profile_progress_interval", nInterval,
561 if (nErr != MM_ERROR_NONE) {
562 VideoLogInfo("[ERR] Error code : 0x%x - Fail to set attribute ",
568 int MpPlayerMgrGetPdduration(void)
572 if (!MpPlayerMgrIsActive()) {
573 VideoLogInfo("[ERR]");
578 char *pErrName = NULL;
579 int nErr = MM_ERROR_NONE;
582 mm_player_get_attribute(playerHandle, &pErrName, "content_duration",
584 if (nErr != MM_ERROR_NONE) {
585 VideoLogInfo("[ERR] Error code : 0x%x - Fail to get attribute ",
594 int MpPlayerMgrGetDuration(char *szFilePath)
596 VideoLogInfo("%s", szFilePath);
598 if (!MpPlayerMgrIsActive()) {
599 VideoLogInfo("[ERR]");
604 char *pErrName = NULL;
605 int nErr = MM_ERROR_NONE;
608 mm_player_get_attribute(playerHandle, &pErrName, "content_duration",
610 if (nErr != MM_ERROR_NONE) {
611 VideoLogInfo("[ERR] Error code : 0x%x - Fail to get attribute ",
620 bool MpPlayerMgrSetRatioVideoScreenSize(MpPlayerMgrDisplayMethod ScreenSize)
622 VideoLogInfo("Screen size : %d", ScreenSize);
624 if (!MpPlayerMgrIsActive()) {
625 VideoLogInfo("[ERR]");
629 char *pErrName = NULL;
630 int nErr = MM_ERROR_NONE;
633 mm_player_set_attribute(playerHandle, &pErrName, "display_method",
635 if (nErr != MM_ERROR_NONE) {
636 VideoLogInfo("[ERR] Error code : 0x%x - Fail to set attribute ",
645 bool MpPlayerMgrSetOverlayXid(void *pOverlayXid)
647 if (!MpPlayerMgrIsActive()) {
648 VideoLogInfo("[ERR]");
653 VideoLogInfo("[ERR]");
657 int nErr = MM_ERROR_NONE;
658 char *pErrName = NULL;
660 VideoLogInfo("XID : %d", *((int *)pOverlayXid));
663 mm_player_set_attribute(playerHandle, &pErrName, "display_overlay",
664 pOverlayXid, sizeof(int),
666 MM_DISPLAY_ROTATION_NONE, NULL);
668 if (nErr != MM_ERROR_NONE) {
669 VideoLogInfo("[ERR] Error code : 0x%x - Fail to set attribute ",
678 bool MpPlayerMgrSetSoundPriority(void)
682 if (!MpPlayerMgrIsActive()) {
683 VideoLogInfo("[ERR]");
687 char *pErrName = NULL;
688 int nErr = MM_ERROR_NONE;
690 nErr = mm_player_set_attribute(playerHandle, &pErrName,
692 MM_SOUND_VOLUME_TYPE_MEDIA, NULL);
693 if (nErr != MM_ERROR_NONE) {
695 ("[ERR] Error code : 0x%x - Fail to set attribute ", nErr,
704 int MpPlayerMgrGetVideoWidthResolution(void)
708 if (!MpPlayerMgrIsActive()) {
709 VideoLogInfo("[ERR]");
713 char *pErrName = NULL;
715 int nErr = MM_ERROR_NONE;
717 nErr = mm_player_get_attribute(playerHandle, &pErrName,
718 "content_video_width", &nWidth, NULL);
719 if (nErr != MM_ERROR_NONE) {
720 VideoLogInfo("[ERR] Error code : 0x%x - Fail to get attribute ",
729 int MpPlayerMgrGetVideoHeightResolution(void)
733 if (!MpPlayerMgrIsActive()) {
734 VideoLogInfo("[ERR]");
738 char *pErrName = NULL;
740 int nErr = MM_ERROR_NONE;
742 nErr = mm_player_get_attribute(playerHandle, &pErrName,
743 "content_video_height", &nHeight, NULL);
744 if (nErr != MM_ERROR_NONE) {
745 VideoLogInfo("[ERR] Error code : 0x%x - Fail to get attribute ",
754 bool MpPlayerMgrSetSubtitleSilent(bool bSilent)
758 if (!MpPlayerMgrIsActive()) {
759 VideoLogInfo("[ERR]");
763 int nErr = mm_player_set_subtitle_silent(playerHandle, (int)bSilent);
764 if (nErr != MM_ERROR_NONE) {
765 VideoLogInfo("[ERR] Error code : 0x%x - ", nErr);
772 bool MpPlayerMgrSetSubtitle(const char *szSubtitlePath)
774 VideoLogInfo("%s", szSubtitlePath);
776 if (!MpPlayerMgrIsActive()) {
777 VideoLogInfo("[ERR]");
781 if (!szSubtitlePath) {
782 VideoLogInfo("[ERR] subtitle path is null.");
786 char *pErrName = NULL;
789 nErr = mm_player_set_attribute(playerHandle, &pErrName, "subtitle_uri",
790 (const char *)szSubtitlePath,
791 strlen(szSubtitlePath), NULL);
792 if (nErr != MM_ERROR_NONE) {
793 VideoLogInfo("[ERR] Error code : 0x%x - Fail to set attribute ",
798 VideoLogInfo("Success to set subtitle.");
804 int MpPlayerMgrSetBluetoothHeadset(char *szBlutoothAddress, int nMode)
811 int MpPlayerMgrSetDisplayArea(int nX, int nY, int nWidth, int nHeight)
815 if (!MpPlayerMgrIsActive()) {
816 VideoLogInfo("[ERR]");
820 char *pErrName = NULL;
823 nErr = mm_player_set_attribute(playerHandle, &pErrName, "display_roi_x",
824 nX, "display_roi_y", nY,
825 "display_roi_width", nWidth,
826 "display_roi_height", nHeight, NULL);
827 if (nErr != MM_ERROR_NONE) {
828 VideoLogInfo("[ERR] Error code : 0x%x - Fail to set attribute ",
837 int MpPlayerMgrSetVerticalOverlayPos(int nY)
841 if (!MpPlayerMgrIsActive()) {
842 VideoLogInfo("[ERR]");
846 char *pErrName = NULL;
849 nErr = mm_player_set_attribute(playerHandle, &pErrName, "display_roi_y",
851 if (nErr != MM_ERROR_NONE) {
852 VideoLogInfo("[ERR] Error code : 0x%x - Fail to set attribute ",
861 bool MpPlayerMgrSetUseragentForStreaming(const char *szUserAgent)
865 if (!MpPlayerMgrIsActive()) {
866 VideoLogInfo("[ERR]");
871 VideoLogInfo("[ERR]");
875 int nErr = MM_ERROR_NONE;
876 char *pErrName = NULL;
878 if (strlen(szUserAgent) > 0) {
879 VideoLogInfo("User agent (%s)", szUserAgent);
880 nErr = mm_player_set_attribute(playerHandle, &pErrName,
881 "streaming_user_agent",
882 szUserAgent, strlen(szUserAgent),
885 if (nErr != MM_ERROR_NONE) {
886 VideoLogInfo("[ERR] (%x):: Fail to set attribute [%s]",
892 VideoLogInfo("No have useragnet value.");
899 bool MpPlayerMgrSetProxAddressForStreaming(const char *szProxyAddress)
903 if (!MpPlayerMgrIsActive()) {
904 VideoLogInfo("[ERR]");
908 if (!szProxyAddress) {
909 VideoLogInfo("[ERR]");
913 int nErr = MM_ERROR_NONE;
914 char *pErrName = NULL;
916 if (strlen(szProxyAddress) > 0) {
917 VideoLogInfo("Proxy Setting (%s)", szProxyAddress);
918 nErr = mm_player_set_attribute(playerHandle, &pErrName,
921 strlen(szProxyAddress), NULL);
923 if (nErr != MM_ERROR_NONE) {
924 VideoLogInfo("[ERR] (%x):: Fail to set attribute [%s]",
933 bool MpPlayerMgrSetCookieForStreaming(const char *szCookie)
937 if (!MpPlayerMgrIsActive()) {
938 VideoLogInfo("[ERR]");
943 VideoLogInfo("[ERR]");
947 int nErr = MM_ERROR_NONE;
948 char *pErrName = NULL;
950 if (strlen(szCookie) > 0) {
951 VideoLogInfo("Cookie (%s)", szCookie);
952 nErr = mm_player_set_attribute(playerHandle, &pErrName,
953 "streaming_cookie", szCookie,
954 strlen(szCookie), NULL);
956 if (nErr != MM_ERROR_NONE) {
957 VideoLogInfo("[ERR] (%x):: Fail to set attribute [%s]",
966 VideoLogInfo("No have useragnet value.");
974 int MpPlayerMgrGetBufferingPosition(void)
976 if (!MpPlayerMgrIsActive()) {
977 VideoLogInfo("[ERR]");
981 int nErr = MM_ERROR_NONE;
983 int startPos = 0, stopPos = 0;
984 nErr = mm_player_get_buffer_position(playerHandle,
985 MM_PLAYER_POS_FORMAT_PERCENT,
986 &startPos, &stopPos);
987 if (nErr != MM_ERROR_NONE) {
988 VideoLogInfo("[ERR]");