2 * To apply the Flora License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
4 * Copyright [2012] [JongDong Lee <jongdong.lee@samsung.com>, ChangSun Lee <cs78.lee@samsung.com>]
6 * Licensed under the Flora License, Version 1.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.tizenopensource.org/license
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
24 #include "mp-video-log.h"
25 #include "mp-video-player-mgr.h"
27 #define MAX_PATH_LEN 2048
30 static player_h pPlayerHandle;
33 bool MpPlayerMgrIsActive(void)
35 return pPlayerHandle ? true : false;
38 bool MpPlayerMgrRegistePlayerCallback(void *PlayerCompletedCbFunc, void *PlayerInterruptedCbFunc, void *PlayerErrorCbFunc, void *PlayerBufferingCbFunc, void *PlayerSubtitleCbFunc, void *pUserData)
44 VideoLogInfo("[ERR]");
48 if(!MpPlayerMgrIsActive())
50 VideoLogInfo("[ERR]");
54 if(player_set_completed_cb(pPlayerHandle, PlayerCompletedCbFunc, pUserData) != PLAYER_ERROR_NONE)
56 VideoLogInfo("[ERR]");
60 if(player_set_interrupted_cb(pPlayerHandle, PlayerInterruptedCbFunc, pUserData) != PLAYER_ERROR_NONE)
62 VideoLogInfo("[ERR]");
66 if(player_set_error_cb(pPlayerHandle, PlayerErrorCbFunc, pUserData) != PLAYER_ERROR_NONE)
68 VideoLogInfo("[ERR]");
72 if(player_set_buffering_cb(pPlayerHandle, PlayerBufferingCbFunc, pUserData) != PLAYER_ERROR_NONE)
74 VideoLogInfo("[ERR]");
78 if(player_set_subtitle_updated_cb(pPlayerHandle, PlayerSubtitleCbFunc, pUserData) != PLAYER_ERROR_NONE)
80 VideoLogInfo("[ERR]");
87 bool MpPlayerMgrCreate(const char *szPath)
93 VideoLogInfo("[ERR] Not correct Meida URI.");
97 int nPathLength = strlen(szPath);
98 int nErr = PLAYER_ERROR_NONE;
100 VideoLogInfo(" Media path (%s)", szPath);
102 if(nPathLength > 0 && nPathLength < MAX_PATH_LEN)
104 nErr = player_create(&pPlayerHandle);
105 if(nErr != PLAYER_ERROR_NONE)
107 VideoLogInfo("[ERR] Fail to create player handle. (MMF Error code : %x)", nErr);
111 nErr = player_set_uri(pPlayerHandle, szPath);
112 if(nErr != PLAYER_ERROR_NONE)
114 VideoLogInfo("[ERR] (%x) Fail to set attribute ", nErr);
120 VideoLogInfo("[ERR] File path is too long.");
124 nErr = player_set_sound_type(pPlayerHandle, SOUND_TYPE_MEDIA);
125 if(nErr != PLAYER_ERROR_NONE)
127 VideoLogInfo("[ERR] (%x):: Fail to set attribute ", nErr);
134 bool MpPlayerMgrDestroy(void)
138 if(!MpPlayerMgrIsActive())
140 VideoLogInfo("[ERR]");
144 int nErr = player_destroy(pPlayerHandle);
145 if(nErr != PLAYER_ERROR_NONE)
147 VideoLogInfo("[ERR] Error code : 0x%x", nErr);
150 pPlayerHandle = NULL;
155 bool MpPlayerMgrRealize(void)
159 if(!MpPlayerMgrIsActive())
161 VideoLogInfo("[ERR]");
165 int nErr = player_prepare(pPlayerHandle);
166 if(nErr != PLAYER_ERROR_NONE)
168 VideoLogInfo("[ERR] Error code : 0x%x", nErr);
175 bool MpPlayerMgrRealizeAsync(void *pPrepareCb, void *pUserData)
179 if(!MpPlayerMgrIsActive())
181 VideoLogInfo("[ERR]");
185 int nErr = player_prepare_async(pPlayerHandle, pPrepareCb, pUserData);
186 if(nErr != PLAYER_ERROR_NONE)
188 VideoLogInfo("[ERR] Error code : 0x%x", nErr);
195 bool MpPlayerMgrUnrealize(void)
199 if(!MpPlayerMgrIsActive())
201 VideoLogInfo("[ERR]");
205 int nErr = player_unprepare (pPlayerHandle);
206 if(nErr != PLAYER_ERROR_NONE)
208 VideoLogInfo("[ERR] Error code : 0x%x", nErr);
215 bool MpPlayerMgrPlay(void)
219 if(!MpPlayerMgrIsActive())
221 VideoLogInfo("[ERR]");
225 int nErr = player_start(pPlayerHandle);
226 if(nErr != PLAYER_ERROR_NONE)
228 VideoLogInfo("[ERR] Error code : 0x%x", nErr);
235 bool MpPlayerMgrStop(void)
239 if(!MpPlayerMgrIsActive())
241 VideoLogInfo("[ERR]");
245 int nErr = player_stop (pPlayerHandle);
246 if(nErr != PLAYER_ERROR_NONE)
248 VideoLogInfo("[ERR] Error code : 0x%x", nErr);
255 bool MpPlayerMgrResume(void)
259 if(!MpPlayerMgrIsActive())
261 VideoLogInfo("[ERR]");
265 int nErr = player_start(pPlayerHandle);
266 if(nErr != PLAYER_ERROR_NONE)
268 VideoLogInfo("[ERR] Error code : 0x%x", nErr);
275 bool MpPlayerMgrPause(void)
279 if(!MpPlayerMgrIsActive())
281 VideoLogInfo("[ERR]");
285 int nErr = player_pause(pPlayerHandle);
286 if(nErr != PLAYER_ERROR_NONE)
288 VideoLogInfo("[ERR] Error code : 0x%x", nErr);
295 int MpPlayerMgrGetPosition(void)
297 if(!MpPlayerMgrIsActive())
305 nErr = player_get_position(pPlayerHandle, &nPos);
306 if(nErr != PLAYER_ERROR_NONE)
308 VideoLogInfo("[ERR] Error code : 0x%x ", nErr);
315 void MpPlayerMgrSetPosition(unsigned int nPos, void *pSeekCb, void *pUserData)
319 if(!MpPlayerMgrIsActive())
321 VideoLogInfo("[ERR]");
325 VideoLogInfo("Set position - %d", nPos);
327 int nErr = player_set_position(pPlayerHandle, (int)nPos, pSeekCb, pUserData);
328 if(nErr != PLAYER_ERROR_NONE)
330 VideoLogInfo("[ERR] Error code : 0x%x ", nErr);
334 void MpPlayerMgrSetSubtitlePosition(unsigned int nPos)
338 if(!MpPlayerMgrIsActive())
340 VideoLogInfo("[ERR]");
344 int nErr = player_set_subtitle_position(pPlayerHandle, nPos);
346 if(nErr != PLAYER_ERROR_NONE)
348 VideoLogInfo("[ERR] Error code : 0x%x ", nErr);
353 void MpPlayerMgrSetMute(bool bMuteEnable)
357 if(!MpPlayerMgrIsActive())
359 VideoLogInfo("[ERR]");
363 if(player_set_mute(pPlayerHandle, bMuteEnable) != PLAYER_ERROR_NONE)
365 VideoLogInfo("[ERR] Fail to set mute.");
369 bool MpPlayerMgrGetMute(void)
373 if(!MpPlayerMgrIsActive())
375 VideoLogInfo("[ERR]");
379 bool bIsMute = false;
381 if(player_is_muted(pPlayerHandle, &bIsMute) != PLAYER_ERROR_NONE)
383 VideoLogInfo("[ERR] Fail to get mute state.");
390 bool MpPlayerMgrSetSurroundFilters(int nSurround)
394 if(!MpPlayerMgrIsActive())
396 VideoLogInfo("[ERR]");
400 audio_effect_preset_e ePresetValue = (audio_effect_preset_e)nSurround;
402 bool available = false;
404 player_audio_effect_preset_is_available (pPlayerHandle, ePresetValue, &available);
406 if(available == false)
408 VideoLogInfo("[ERR] unavailable to set audio effect.");
412 if(player_audio_effect_set_preset(pPlayerHandle,ePresetValue) != PLAYER_ERROR_NONE)
414 VideoLogInfo("[ERR] Fail to set audio effect.");
421 int MpPlayerMgrGetDuration(void)
425 if(!MpPlayerMgrIsActive())
427 VideoLogInfo("[ERR]");
433 int nErr = player_get_duration(pPlayerHandle, &nDuration);
434 if(nErr != PLAYER_ERROR_NONE)
436 VideoLogInfo("[ERR] Error code : %x - Fail to get attribute ", nErr);
443 bool MpPlayerMgrSetOverlayXid(void *pOverlayXid)
445 if(!MpPlayerMgrIsActive())
447 VideoLogInfo("[ERR]");
453 VideoLogInfo("[ERR]");
457 VideoLogInfo("XID : %x, %d", pOverlayXid, (int)pOverlayXid);
458 int nErr = player_set_display(pPlayerHandle, PLAYER_DISPLAY_TYPE_X11, (void*)pOverlayXid);
459 if(nErr != PLAYER_ERROR_NONE)
461 VideoLogInfo("[ERR] Error code : %x - Fail to set attribute ", nErr);
467 bool MpPlayerMgrSetEvasSinkID(void *pEvasSinkID)
469 if(!MpPlayerMgrIsActive())
471 VideoLogInfo("[ERR]");
477 VideoLogInfo("[ERR]");
481 VideoLogInfo("Evas Sink ID : %x", pEvasSinkID);
483 int nErr = player_set_display(pPlayerHandle, PLAYER_DISPLAY_TYPE_EVAS, (void*)pEvasSinkID);
484 if(nErr != PLAYER_ERROR_NONE)
486 VideoLogInfo("[ERR] Error code : %x - Fail to set attribute ", nErr);
493 bool MpPlayerMgrSetSoundPriority(void)
497 if(!MpPlayerMgrIsActive())
499 VideoLogInfo("[ERR]");
503 int nErr = player_set_sound_type(pPlayerHandle, SOUND_TYPE_MEDIA);
504 if(nErr != PLAYER_ERROR_NONE)
506 VideoLogInfo("[ERR] Error code : %x - Fail to set attribute ", nErr);
513 int MpPlayerMgrSetPlaySpeed(float nSpeedValue)
517 if(!MpPlayerMgrIsActive())
519 VideoLogInfo("[ERR]");
522 int nErr = player_set_playback_rate(pPlayerHandle, nSpeedValue);
523 if(nErr != PLAYER_ERROR_NONE)
525 VideoLogInfo("[ERR] Error code : %x - Fail to get attribute ", nErr);
532 int MpPlayerMgrGetVideoWidthResolution(void)
536 if(!MpPlayerMgrIsActive())
538 VideoLogInfo("[ERR]");
544 int nErr = player_get_video_size(pPlayerHandle, &nWidth, &nHeight);
545 if(nErr != PLAYER_ERROR_NONE)
547 VideoLogInfo("[ERR] Error code : %x - Fail to get attribute ", nErr);
554 int MpPlayerMgrGetVideoHeightResolution(void)
558 if(!MpPlayerMgrIsActive())
560 VideoLogInfo("[ERR]");
566 int nErr = player_get_video_size(pPlayerHandle, &nWidth, &nHeight);
567 if(nErr != PLAYER_ERROR_NONE)
569 VideoLogInfo("[ERR] Error code : %x - Fail to get attribute ", nErr);
576 bool MpPlayerMgrSetSubtitle(char *szSubtitlePath)
578 VideoLogInfo("%s", szSubtitlePath);
580 if(!MpPlayerMgrIsActive())
582 VideoLogInfo("[ERR]");
588 VideoLogInfo("[ERR] subtitle path is null.");
592 int nErr = player_set_subtitle_path(pPlayerHandle, szSubtitlePath);
593 if(nErr != PLAYER_ERROR_NONE)
595 VideoLogInfo("[ERR] Error code : %x - Fail to set attribute ", nErr);
602 bool MpPlayerMgrSetDisplayMode(MpPlayerMgrDisplayMethod nMethodMode)
606 if(!MpPlayerMgrIsActive())
608 VideoLogInfo("[ERR]");
611 int nRet = player_set_display_mode (pPlayerHandle , nMethodMode);
612 if(nRet != PLAYER_ERROR_NONE)
614 VideoLogInfo("[ERR] Error code : %x - Fail to set attribute ", nRet);
620 bool MpPlayerMgrSetRotate(MpVideoRotation nRotation)
624 if(!MpPlayerMgrIsActive())
626 VideoLogInfo("[ERR]");
630 int nRotVal = PLAYER_DISPLAY_ROTATION_NONE;
632 if(nRotation == VIDEO_SCREEN_PORTRAIT) {
633 nRotVal = PLAYER_DISPLAY_ROTATION_NONE;
635 else if(nRotation == VIDEO_SCREEN_PORTRAIT_UPSIDEDOWN) {
636 nRotVal = PLAYER_DISPLAY_ROTATION_180;
638 else if(nRotation == VIDEO_SCREEN_LANDSCAPE) {
639 nRotVal = PLAYER_DISPLAY_ROTATION_270;
641 else if(nRotation == VIDEO_SCREEN_LANDSCAPE_UPSIDEDOWN) {
642 nRotVal = PLAYER_DISPLAY_ROTATION_90;
645 int nRet = player_set_x11_display_rotation (pPlayerHandle , nRotVal);
646 if(nRet != PLAYER_ERROR_NONE)
648 VideoLogInfo("[ERR] Error code : %x - Fail to set attribute ", nRet);
654 bool MpPlayerMgrSetUseragentForStreaming(const char *szUserAgent)
656 VideoLogInfo("!!!!!! NO EXIST FUNCTION FOR SETTING USER AGENT. !!!!!!");
661 bool MpPlayerMgrSetProxyAddressForStreaming(const char *szProxyAddress)
663 VideoLogInfo("!!!!!! NO EXIST FUNCTION FOR SETTING PROXY ADDRESS. !!!!!!");
667 bool MpPlayerMgrSetCookieForStreaming(const char *szCookie)
669 if(!MpPlayerMgrIsActive())
671 VideoLogInfo("[ERR]");
677 VideoLogInfo("No exist cookie.");
683 int nRet = player_set_streaming_cookie(pPlayerHandle , szCookie, strlen(szCookie));
684 if(nRet == PLAYER_ERROR_INVALID_PARAMETER)
686 VideoLogInfo("PLAYER_ERROR_INVALID_PARAMETER");
693 bool MpPlayerMgrStartCapture()
699 bool MpPlayerMgrCaptureVideo(void *pCallbackFunc, void *pUserData)
701 if(!MpPlayerMgrIsActive())
709 int nRet = player_capture_video(pPlayerHandle, pCallbackFunc, pUserData);
710 if(nRet == PLAYER_ERROR_INVALID_PARAMETER)
712 VideoLogInfo("PLAYER_ERROR_INVALID_PARAMETER");
716 if(nRet == PLAYER_ERROR_INVALID_OPERATION)
718 VideoLogInfo("PLAYER_ERROR_INVALID_OPERATION");
722 if(nRet == PLAYER_ERROR_INVALID_STATE)
724 VideoLogInfo("PLAYER_ERROR_INVALID_STATE");
731 int MpPlayerMgrGetBufferingPosition(void)
736 if(player_get_streaming_download_progress(pPlayerHandle,&nStartPos, &nCurrentPos) != PLAYER_ERROR_NONE)
745 bool MpPlayerMgrRegisteBufferingCallBack(void *pCallbackFunc, void *pUserData)
747 if(!MpPlayerMgrIsActive())
749 VideoLogInfo("[ERR]");
753 // !!! CHECK player_buffering_cb !!!
754 if(player_set_buffering_cb(pPlayerHandle, pCallbackFunc, pUserData) != PLAYER_ERROR_NONE)
763 int MpPlayerMgrGetFileStreamType(void)
768 return FILE_STREAM_TYPE_VIDEO;
771 bool MpPlayerMgrSetScaling(bool bScale)
773 if(!MpPlayerMgrIsActive())
775 VideoLogInfo("[ERR]");
781 if(player_enable_evas_display_scaling(pPlayerHandle, bScale) != PLAYER_ERROR_NONE) {
782 VideoLogInfo("[ERR]");
788 player_state_e MpPlayerMgrGetPlayerState(void)
791 player_state_e player_state = PLAYER_STATE_NONE;
792 ret = player_get_state(pPlayerHandle, &player_state);
793 if (ret != PLAYER_ERROR_NONE) {
794 player_state = PLAYER_STATE_NONE;
799 void MpPlayerMgrSetVolume(float volume)
801 VideoLogInfo("volume = %f", volume);
803 if(!MpPlayerMgrIsActive())
805 VideoLogInfo("[ERR]");
809 if(player_set_volume(pPlayerHandle, volume, volume) != PLAYER_ERROR_NONE)
811 VideoLogInfo("[ERR] Fail to set volume.");
815 float MpPlayerMgrGetVolume(void)
819 if(!MpPlayerMgrIsActive())
821 VideoLogInfo("[ERR]");
825 float volume_left = 0.0;
826 float volume_right = 0.0;
828 if(player_get_volume(pPlayerHandle, &volume_left, &volume_right) != PLAYER_ERROR_NONE)
830 VideoLogInfo("[ERR] Fail to get volume.");
837 int MpPlayerMgrGetClosedCaptionCount(void)
841 if(!MpPlayerMgrIsActive())
843 VideoLogInfo("[ERR]");
848 if(player_get_track_count(pPlayerHandle, PLAYER_TRACK_TYPE_TEXT, &nCount) != PLAYER_ERROR_NONE)
850 VideoLogError("[ERR] player_get_track_count.");
854 VideoLogError("== %d ===========================================", nCount);