2 * Copyright (c) [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://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.
22 #include "mp-video-log.h"
23 #include "mp-video-player-mgr.h"
25 #define MAX_PATH_LEN 2048
28 static player_h pPlayerHandle;
31 bool MpPlayerMgrIsActive(void)
33 return pPlayerHandle ? true : false;
36 bool MpPlayerMgrRegistePlayerCallback(void *PlayerCompletedCbFunc, void *PlayerInterruptedCbFunc, void *PlayerErrorCbFunc, void *PlayerBufferingCbFunc, void *PlayerSubtitleCbFunc, void *pUserData)
42 VideoLogInfo("[ERR]");
46 if(!MpPlayerMgrIsActive())
48 VideoLogInfo("[ERR]");
52 if(player_set_completed_cb(pPlayerHandle, PlayerCompletedCbFunc, pUserData) != PLAYER_ERROR_NONE)
54 VideoLogInfo("[ERR]");
58 if(player_set_interrupted_cb(pPlayerHandle, PlayerInterruptedCbFunc, pUserData) != PLAYER_ERROR_NONE)
60 VideoLogInfo("[ERR]");
64 if(player_set_error_cb(pPlayerHandle, PlayerErrorCbFunc, pUserData) != PLAYER_ERROR_NONE)
66 VideoLogInfo("[ERR]");
70 if(player_set_buffering_cb(pPlayerHandle, PlayerBufferingCbFunc, pUserData) != PLAYER_ERROR_NONE)
72 VideoLogInfo("[ERR]");
76 if(player_set_subtitle_updated_cb(pPlayerHandle, PlayerSubtitleCbFunc, pUserData) != PLAYER_ERROR_NONE)
78 VideoLogInfo("[ERR]");
85 bool MpPlayerMgrCreate(const char *szPath)
91 VideoLogInfo("[ERR] Not correct Meida URI.");
95 int nPathLength = strlen(szPath);
96 int nErr = PLAYER_ERROR_NONE;
98 VideoLogInfo(" Media path (%s)", szPath);
100 if(nPathLength > 0 && nPathLength < MAX_PATH_LEN)
102 nErr = player_create(&pPlayerHandle);
103 if(nErr != PLAYER_ERROR_NONE)
105 VideoLogInfo("[ERR] Fail to create player handle. (MMF Error code : %x)", nErr);
109 nErr = player_set_uri(pPlayerHandle, szPath);
110 if(nErr != PLAYER_ERROR_NONE)
112 VideoLogInfo("[ERR] (%x) Fail to set attribute ", nErr);
118 VideoLogInfo("[ERR] File path is too long.");
122 nErr = player_set_sound_type(pPlayerHandle, SOUND_TYPE_MEDIA);
123 if(nErr != PLAYER_ERROR_NONE)
125 VideoLogInfo("[ERR] (%x):: Fail to set attribute ", nErr);
132 bool MpPlayerMgrDestroy(void)
136 if(!MpPlayerMgrIsActive())
138 VideoLogInfo("[ERR]");
142 int nErr = player_destroy(pPlayerHandle);
143 if(nErr != PLAYER_ERROR_NONE)
145 VideoLogInfo("[ERR] Error code : 0x%x", nErr);
148 pPlayerHandle = NULL;
153 bool MpPlayerMgrRealize(void)
157 if(!MpPlayerMgrIsActive())
159 VideoLogInfo("[ERR]");
163 int nErr = player_prepare(pPlayerHandle);
164 if(nErr != PLAYER_ERROR_NONE)
166 VideoLogInfo("[ERR] Error code : 0x%x", nErr);
173 bool MpPlayerMgrRealizeAsync(void *pPrepareCb, void *pUserData)
177 if(!MpPlayerMgrIsActive())
179 VideoLogInfo("[ERR]");
183 int nErr = player_prepare_async(pPlayerHandle, pPrepareCb, pUserData);
184 if(nErr != PLAYER_ERROR_NONE)
186 VideoLogInfo("[ERR] Error code : 0x%x", nErr);
193 bool MpPlayerMgrUnrealize(void)
197 if(!MpPlayerMgrIsActive())
199 VideoLogInfo("[ERR]");
203 int nErr = player_unprepare (pPlayerHandle);
204 if(nErr != PLAYER_ERROR_NONE)
206 VideoLogInfo("[ERR] Error code : 0x%x", nErr);
213 bool MpPlayerMgrPlay(void)
217 if(!MpPlayerMgrIsActive())
219 VideoLogInfo("[ERR]");
223 int nErr = player_start(pPlayerHandle);
224 if(nErr != PLAYER_ERROR_NONE)
226 VideoLogInfo("[ERR] Error code : 0x%x", nErr);
233 bool MpPlayerMgrStop(void)
237 if(!MpPlayerMgrIsActive())
239 VideoLogInfo("[ERR]");
243 int nErr = player_stop (pPlayerHandle);
244 if(nErr != PLAYER_ERROR_NONE)
246 VideoLogInfo("[ERR] Error code : 0x%x", nErr);
253 bool MpPlayerMgrResume(void)
257 if(!MpPlayerMgrIsActive())
259 VideoLogInfo("[ERR]");
263 int nErr = player_start(pPlayerHandle);
264 if(nErr != PLAYER_ERROR_NONE)
266 VideoLogInfo("[ERR] Error code : 0x%x", nErr);
273 bool MpPlayerMgrPause(void)
277 if(!MpPlayerMgrIsActive())
279 VideoLogInfo("[ERR]");
283 int nErr = player_pause(pPlayerHandle);
284 if(nErr != PLAYER_ERROR_NONE)
286 VideoLogInfo("[ERR] Error code : 0x%x", nErr);
293 int MpPlayerMgrGetPosition(void)
295 if(!MpPlayerMgrIsActive())
303 nErr = player_get_position(pPlayerHandle, &nPos);
304 if(nErr != PLAYER_ERROR_NONE)
306 VideoLogInfo("[ERR] Error code : 0x%x ", nErr);
313 void MpPlayerMgrSetPosition(unsigned int nPos, void *pSeekCb, void *pUserData)
317 if(!MpPlayerMgrIsActive())
319 VideoLogInfo("[ERR]");
323 VideoLogInfo("Set position - %d", nPos);
325 int nErr = player_set_position(pPlayerHandle, (int)nPos, pSeekCb, pUserData);
326 if(nErr != PLAYER_ERROR_NONE)
328 VideoLogInfo("[ERR] Error code : 0x%x ", nErr);
332 void MpPlayerMgrSetSubtitlePosition(unsigned int nPos)
336 if(!MpPlayerMgrIsActive())
338 VideoLogInfo("[ERR]");
342 int nErr = player_set_subtitle_position(pPlayerHandle, nPos);
344 if(nErr != PLAYER_ERROR_NONE)
346 VideoLogInfo("[ERR] Error code : 0x%x ", nErr);
351 void MpPlayerMgrSetMute(bool bMuteEnable)
355 if(!MpPlayerMgrIsActive())
357 VideoLogInfo("[ERR]");
361 if(player_set_mute(pPlayerHandle, bMuteEnable) != PLAYER_ERROR_NONE)
363 VideoLogInfo("[ERR] Fail to set mute.");
367 bool MpPlayerMgrGetMute(void)
371 if(!MpPlayerMgrIsActive())
373 VideoLogInfo("[ERR]");
377 bool bIsMute = false;
379 if(player_is_muted(pPlayerHandle, &bIsMute) != PLAYER_ERROR_NONE)
381 VideoLogInfo("[ERR] Fail to get mute state.");
388 bool MpPlayerMgrSetSurroundFilters(int nSurround)
392 if(!MpPlayerMgrIsActive())
394 VideoLogInfo("[ERR]");
398 audio_effect_preset_e ePresetValue = (audio_effect_preset_e)nSurround;
400 bool available = false;
402 player_audio_effect_preset_is_available (pPlayerHandle, ePresetValue, &available);
404 if(available == false)
406 VideoLogInfo("[ERR] unavailable to set audio effect.");
410 if(player_audio_effect_set_preset(pPlayerHandle,ePresetValue) != PLAYER_ERROR_NONE)
412 VideoLogInfo("[ERR] Fail to set audio effect.");
419 int MpPlayerMgrGetDuration(void)
423 if(!MpPlayerMgrIsActive())
425 VideoLogInfo("[ERR]");
431 int nErr = player_get_duration(pPlayerHandle, &nDuration);
432 if(nErr != PLAYER_ERROR_NONE)
434 VideoLogInfo("[ERR] Error code : %x - Fail to get attribute ", nErr);
441 bool MpPlayerMgrSetOverlayXid(void *pOverlayXid)
443 if(!MpPlayerMgrIsActive())
445 VideoLogInfo("[ERR]");
451 VideoLogInfo("[ERR]");
455 VideoLogInfo("XID : %x, %d", pOverlayXid, (int)pOverlayXid);
456 int nErr = player_set_display(pPlayerHandle, PLAYER_DISPLAY_TYPE_X11, (void*)pOverlayXid);
457 if(nErr != PLAYER_ERROR_NONE)
459 VideoLogInfo("[ERR] Error code : %x - Fail to set attribute ", nErr);
465 bool MpPlayerMgrSetEvasSinkID(void *pEvasSinkID)
467 if(!MpPlayerMgrIsActive())
469 VideoLogInfo("[ERR]");
475 VideoLogInfo("[ERR]");
479 VideoLogInfo("Evas Sink ID : %x", pEvasSinkID);
481 int nErr = player_set_display(pPlayerHandle, PLAYER_DISPLAY_TYPE_EVAS, (void*)pEvasSinkID);
482 if(nErr != PLAYER_ERROR_NONE)
484 VideoLogInfo("[ERR] Error code : %x - Fail to set attribute ", nErr);
491 bool MpPlayerMgrSetSoundPriority(void)
495 if(!MpPlayerMgrIsActive())
497 VideoLogInfo("[ERR]");
501 int nErr = player_set_sound_type(pPlayerHandle, SOUND_TYPE_MEDIA);
502 if(nErr != PLAYER_ERROR_NONE)
504 VideoLogInfo("[ERR] Error code : %x - Fail to set attribute ", nErr);
511 int MpPlayerMgrSetPlaySpeed(float nSpeedValue)
515 if(!MpPlayerMgrIsActive())
517 VideoLogInfo("[ERR]");
520 int nErr = player_set_playback_rate(pPlayerHandle, nSpeedValue);
521 if(nErr != PLAYER_ERROR_NONE)
523 VideoLogInfo("[ERR] Error code : %x - Fail to get attribute ", nErr);
530 int MpPlayerMgrGetVideoWidthResolution(void)
534 if(!MpPlayerMgrIsActive())
536 VideoLogInfo("[ERR]");
542 int nErr = player_get_video_size(pPlayerHandle, &nWidth, &nHeight);
543 if(nErr != PLAYER_ERROR_NONE)
545 VideoLogInfo("[ERR] Error code : %x - Fail to get attribute ", nErr);
552 int MpPlayerMgrGetVideoHeightResolution(void)
556 if(!MpPlayerMgrIsActive())
558 VideoLogInfo("[ERR]");
564 int nErr = player_get_video_size(pPlayerHandle, &nWidth, &nHeight);
565 if(nErr != PLAYER_ERROR_NONE)
567 VideoLogInfo("[ERR] Error code : %x - Fail to get attribute ", nErr);
574 bool MpPlayerMgrSetSubtitle(char *szSubtitlePath)
576 VideoLogInfo("%s", szSubtitlePath);
578 if(!MpPlayerMgrIsActive())
580 VideoLogInfo("[ERR]");
586 VideoLogInfo("[ERR] subtitle path is null.");
590 int nErr = player_set_subtitle_path(pPlayerHandle, szSubtitlePath);
591 if(nErr != PLAYER_ERROR_NONE)
593 VideoLogInfo("[ERR] Error code : %x - Fail to set attribute ", nErr);
600 bool MpPlayerMgrSetDisplayMode(MpPlayerMgrDisplayMethod nMethodMode)
604 if(!MpPlayerMgrIsActive())
606 VideoLogInfo("[ERR]");
609 int nRet = player_set_display_mode (pPlayerHandle , nMethodMode);
610 if(nRet != PLAYER_ERROR_NONE)
612 VideoLogInfo("[ERR] Error code : %x - Fail to set attribute ", nRet);
618 bool MpPlayerMgrSetRotate(MpVideoRotation nRotation)
622 if(!MpPlayerMgrIsActive())
624 VideoLogInfo("[ERR]");
628 int nRotVal = PLAYER_DISPLAY_ROTATION_NONE;
630 if(nRotation == VIDEO_SCREEN_PORTRAIT) {
631 nRotVal = PLAYER_DISPLAY_ROTATION_NONE;
633 else if(nRotation == VIDEO_SCREEN_PORTRAIT_UPSIDEDOWN) {
634 nRotVal = PLAYER_DISPLAY_ROTATION_180;
636 else if(nRotation == VIDEO_SCREEN_LANDSCAPE) {
637 nRotVal = PLAYER_DISPLAY_ROTATION_270;
639 else if(nRotation == VIDEO_SCREEN_LANDSCAPE_UPSIDEDOWN) {
640 nRotVal = PLAYER_DISPLAY_ROTATION_90;
643 int nRet = player_set_x11_display_rotation (pPlayerHandle , nRotVal);
644 if(nRet != PLAYER_ERROR_NONE)
646 VideoLogInfo("[ERR] Error code : %x - Fail to set attribute ", nRet);
652 bool MpPlayerMgrSetUseragentForStreaming(const char *szUserAgent)
654 VideoLogInfo("!!!!!! NO EXIST FUNCTION FOR SETTING USER AGENT. !!!!!!");
659 bool MpPlayerMgrSetProxyAddressForStreaming(const char *szProxyAddress)
661 VideoLogInfo("!!!!!! NO EXIST FUNCTION FOR SETTING PROXY ADDRESS. !!!!!!");
665 bool MpPlayerMgrSetCookieForStreaming(const char *szCookie)
667 if(!MpPlayerMgrIsActive())
669 VideoLogInfo("[ERR]");
675 VideoLogInfo("No exist cookie.");
681 int nRet = player_set_streaming_cookie(pPlayerHandle , szCookie, strlen(szCookie));
682 if(nRet == PLAYER_ERROR_INVALID_PARAMETER)
684 VideoLogInfo("PLAYER_ERROR_INVALID_PARAMETER");
691 bool MpPlayerMgrStartCapture()
697 bool MpPlayerMgrCaptureVideo(void *pCallbackFunc, void *pUserData)
699 if(!MpPlayerMgrIsActive())
707 int nRet = player_capture_video(pPlayerHandle, pCallbackFunc, pUserData);
708 if(nRet == PLAYER_ERROR_INVALID_PARAMETER)
710 VideoLogInfo("PLAYER_ERROR_INVALID_PARAMETER");
714 if(nRet == PLAYER_ERROR_INVALID_OPERATION)
716 VideoLogInfo("PLAYER_ERROR_INVALID_OPERATION");
720 if(nRet == PLAYER_ERROR_INVALID_STATE)
722 VideoLogInfo("PLAYER_ERROR_INVALID_STATE");
729 int MpPlayerMgrGetBufferingPosition(void)
734 if(player_get_streaming_download_progress(pPlayerHandle,&nStartPos, &nCurrentPos) != PLAYER_ERROR_NONE)
743 bool MpPlayerMgrRegisteBufferingCallBack(void *pCallbackFunc, void *pUserData)
745 if(!MpPlayerMgrIsActive())
747 VideoLogInfo("[ERR]");
751 // !!! CHECK player_buffering_cb !!!
752 if(player_set_buffering_cb(pPlayerHandle, pCallbackFunc, pUserData) != PLAYER_ERROR_NONE)
761 int MpPlayerMgrGetFileStreamType(void)
766 return FILE_STREAM_TYPE_VIDEO;
769 bool MpPlayerMgrSetScaling(bool bScale)
771 if(!MpPlayerMgrIsActive())
773 VideoLogInfo("[ERR]");
779 if(player_enable_evas_display_scaling(pPlayerHandle, bScale) != PLAYER_ERROR_NONE) {
780 VideoLogInfo("[ERR]");
786 player_state_e MpPlayerMgrGetPlayerState(void)
789 player_state_e player_state = PLAYER_STATE_NONE;
790 ret = player_get_state(pPlayerHandle, &player_state);
791 if (ret != PLAYER_ERROR_NONE) {
792 player_state = PLAYER_STATE_NONE;
797 void MpPlayerMgrSetVolume(float volume)
799 VideoLogInfo("volume = %f", volume);
801 if(!MpPlayerMgrIsActive())
803 VideoLogInfo("[ERR]");
807 if(player_set_volume(pPlayerHandle, volume, volume) != PLAYER_ERROR_NONE)
809 VideoLogInfo("[ERR] Fail to set volume.");
813 float MpPlayerMgrGetVolume(void)
817 if(!MpPlayerMgrIsActive())
819 VideoLogInfo("[ERR]");
823 float volume_left = 0.0;
824 float volume_right = 0.0;
826 if(player_get_volume(pPlayerHandle, &volume_left, &volume_right) != PLAYER_ERROR_NONE)
828 VideoLogInfo("[ERR] Fail to get volume.");
835 int MpPlayerMgrGetClosedCaptionCount(void)
839 if(!MpPlayerMgrIsActive())
841 VideoLogInfo("[ERR]");
846 if(player_get_track_count(pPlayerHandle, PLAYER_TRACK_TYPE_TEXT, &nCount) != PLAYER_ERROR_NONE)
848 VideoLogError("[ERR] player_get_track_count.");
852 VideoLogError("== %d ===========================================", nCount);