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.
20 #include <image_util.h>
23 #include "mp-video-log.h"
24 #include "video-player.h"
25 #include "mp-video-ctrl-mgr.h"
26 #include "mp-video-player-mgr.h"
27 #include "mp-video-type-define.h"
28 #include "mp-video-service-ctrl.h"
30 bool MpVideoCtrlMgrMediaCreate(char *szMediaURI, void *pOverlayXid, void *pEvasSinkID, char* szSubtitleUri, void *pUserData)
34 VideoLogInfo("[ERR] No exist pUserData.");
38 VideoAppData *pAppData = (VideoAppData *)pUserData;
42 if(!MpPlayerMgrCreate(szMediaURI))
44 VideoLogInfo("[ERR] Fail to create player handle.");
48 MpUtilGetUserAgent(pAppData);
50 if(!MpPlayerMgrSetUseragentForStreaming(pAppData->szUserAgent))
52 VideoLogInfo("[ERR] Fail to set useragent.");
56 if(!MpPlayerMgrSetProxyAddressForStreaming(pAppData->szProxyAddress))
58 VideoLogInfo("[ERR] Fail to set proxy address.");
62 if(!MpPlayerMgrSetCookieForStreaming(pAppData->szCookie))
64 VideoLogInfo("[ERR] Fail to set Cookie.");
68 if(szSubtitleUri && strlen((char*)szSubtitleUri) > 0)
70 VideoLogInfo("Subtitle URI : %s", szSubtitleUri);
72 if(!MpPlayerMgrSetSubtitle(szSubtitleUri))
74 VideoLogInfo("Fail to set subtitle uri.");
79 VideoLogInfo("No exist subtitle uri.");
82 if(!MpPlayerMgrSetOverlayXid(pOverlayXid))
84 VideoLogInfo("[ERR] Fail to set overlay window.");
88 if(!MpVideoCtrlMgrSetScaling(FALSE))
90 VideoLogInfo("[ERR] Fail to set scaling.");
94 if(!MpPlayerMgrSetSoundPriority())
96 VideoLogInfo("[ERR] Fail to set sound priority.");
100 pAppData->nCurPlayerState = MP_PLAYER_STATE_CLEAR;
105 bool MpVideoCtrlMgrMediaRealize(void)
109 if(!MpPlayerMgrRealize())
111 VideoLogInfo("[ERR] Fail relization.");
117 bool MpVideoCtrlMgrMediaRealizeAsync(void *pReailzeCb, void *pUserData)
121 if(!MpPlayerMgrRealizeAsync(pReailzeCb, pUserData))
123 VideoLogInfo("[ERR] Fail relization.");
129 void MpVideoCtrlMgrMediaDestroy(void *pUserData)
132 VideoLogInfo("[ERR] No exist pUserData.");
136 VideoAppData *pAppData = (VideoAppData *)pUserData;
140 if (!MpPlayerMgrIsActive()) {
141 VideoLogInfo(" Already destroy player handle.");
145 if (!MpPlayerMgrUnrealize()) {
146 VideoLogInfo("[ERR] Fail to unrealize player handle.");
149 if (!MpPlayerMgrDestroy()) {
150 VideoLogInfo("[ERR] Fail to destroy player handle.");
154 pAppData->nCurPlayerState = MP_PLAYER_STATE_CLEAR;
157 bool MpVideoCtrlMgrMediaPlay(void *pUserData)
160 VideoLogInfo("[ERR] No exist pUserData.");
164 VideoAppData *pAppData = (VideoAppData *)pUserData;
168 if (!MpPlayerMgrPlay()) {
169 VideoLogInfo("[ERR] Fail to play multimedia player.");
173 pAppData->nCurPlayerState = MP_PLAYER_STATE_PLAY;
178 void MpVideoCtrlMgrMediaStop(void *pUserData)
181 VideoLogInfo("[ERR] No exist pUserData.");
185 VideoAppData *pAppData = (VideoAppData *)pUserData;
189 if (!MpPlayerMgrIsActive()) {
190 VideoLogInfo("[ERR] Player handle is destroyed.");
194 if (!MpPlayerMgrStop()) {
195 VideoLogInfo("[ERR] Fail to stop multimedia player.");
199 pAppData->nCurPlayerState = MP_PLAYER_STATE_STOP;
202 void MpVideoCtrlMgrMediaPause(void *pUserData)
205 VideoLogInfo("[ERR] No exist pUserData.");
209 VideoAppData *pAppData = (VideoAppData *)pUserData;
213 if (pAppData->nCurPlayerState == MP_PLAYER_STATE_STOP) {
215 ("It is not possible to pause when player state is stop.");
219 if (!MpPlayerMgrPause()) {
220 VideoLogInfo("[ERR] Fail to pause multimedia player.");
224 pAppData->nCurPlayerState = MP_PLAYER_STATE_PAUSE;
227 void MpVideoCtrlMgrMediaResume(void *pUserData)
230 VideoLogInfo("[ERR] No exist pUserData.");
234 VideoAppData *pAppData = (VideoAppData *)pUserData;
238 if (pAppData->nCurPlayerState == MP_PLAYER_STATE_STOP) {
240 ("It is not possible to resume when player state is stop.");
244 if (!MpPlayerMgrResume()) {
245 VideoLogInfo("[ERR] Fail to resume multimedia player.");
249 pAppData->nCurPlayerState = MP_PLAYER_STATE_RESUME;
252 void MpVideoCtrlMgrSetPlayerCallback(void *PlayerCompletedCb, void *PlayerInterruptedCb, void *PlayerErrorCb, void *PlayerBufferingCb, void *PlayerSubtitleCb, void *pUserData)
256 VideoLogInfo("[ERR] No exist pUserData.");
260 if(!PlayerCompletedCb || !PlayerInterruptedCb || !PlayerErrorCb || !PlayerBufferingCb)
262 VideoLogInfo("[ERR] No exist player callback function pointer.");
268 MpPlayerMgrRegistePlayerCallback(PlayerCompletedCb, PlayerInterruptedCb, PlayerErrorCb, PlayerBufferingCb, PlayerSubtitleCb, pUserData);
271 void MpVideoCtrlMgrSetOverlayXid(void *pXid)
275 if (!MpPlayerMgrSetOverlayXid(pXid)) {
276 VideoLogInfo("[ERR] Fail to set overlay window.");
280 void MpVideoCtrlMgrSetEvasSinkID(void *pEvasSinkID)
284 if (!MpPlayerMgrSetEvasSinkID(pEvasSinkID)) {
285 VideoLogInfo("[ERR] Fail to set overlay window.");
290 void MpVideoCtrlMgrSetPosition(int nSetPosition, void *pSeekCb, void *pUserData)
294 VideoLogInfo("Set position - %d", nSetPosition);
296 if (nSetPosition > -1) {
297 MpPlayerMgrSetPosition(nSetPosition, pSeekCb, pUserData);
300 void MpVideoCtrlMgrSetSubtitlePosition(int nSetPosition)
304 if (nSetPosition > -1) {
305 MpPlayerMgrSetSubtitlePosition(nSetPosition);
309 int MpVideoCtrlMgrGetPosition(void)
311 /* VideoLogInfo(""); */
313 return MpPlayerMgrGetPosition();
316 int MpVideoCtrlMgrGetDuration(void)
322 nDuration = MpPlayerMgrGetDuration();
324 VideoLogInfo(" content duration : %d ms", nDuration);
329 void MpVideoCtrlMgrResetPlaySpeed(void *pUserData)
332 VideoLogInfo("[ERR] No exist pUserData.");
336 VideoAppData *pAppData = (VideoAppData *)pUserData;
340 if (!MpPlayerMgrSetPlaySpeed(1.0)) {
341 VideoLogInfo("[ERR] Fail to reset play speed.");
345 pAppData->nPlayingSpeed = MP_PLAYING_SPEED_NORMAL;
348 void MpVideoCtrlMgrSetPlaySpeedUp(void *pUserData)
351 VideoLogInfo("[ERR] No exist pUserData.");
355 VideoAppData *pAppData = (VideoAppData *)pUserData;
359 if (pAppData->nPlayingSpeed > MP_PLAYING_SPEED_MAX) {
360 VideoLogInfo("Current speed is full.(5X)");
361 pAppData->nPlayingSpeed = MP_PLAYING_SPEED_5X;
366 val = (float)pAppData->nPlayingSpeed;
368 MpPlayerMgrSetPlaySpeed(val);
372 void MpVideoCtrlMgrSetPlaySpeedDown(void *pUserData)
375 VideoLogInfo("[ERR] No exist pUserData.");
379 VideoAppData *pAppData = (VideoAppData *)pUserData;
383 if (pAppData->nPlayingSpeed > MP_PLAYING_SPEED_MAX) {
384 VideoLogInfo("Current speed is full.(5X)");
389 val = -(float)pAppData->nPlayingSpeed;
390 MpPlayerMgrSetPlaySpeed(val);
394 int MpVideoCtrlMgrGetVideoWidthResolution(void)
398 int nVideoWidthResolution = MpPlayerMgrGetVideoWidthResolution();
400 VideoLogInfo("Video width resolution : %d", nVideoWidthResolution);
402 return nVideoWidthResolution;
405 int MpVideoCtrlMgrGetVideoHeightResolution(void)
409 int nVideoHeightResolution = MpPlayerMgrGetVideoHeightResolution();
411 VideoLogInfo("Video height resolution : %d", nVideoHeightResolution);
413 return nVideoHeightResolution;
416 void MpVideoCtrlMgrSetRatioVideoScreen(void *pUserData, int nRatioScreenSize)
419 VideoLogInfo("[ERR] No exist pUserData.");
425 int nDisplayMode = PLAYER_DISPLAY_MODE_LETTER_BOX;
427 MpPlayerMgrSetDisplayMode(nDisplayMode);
430 void MpVideoCtrlMgrRotateVideoScreen(int nVideoRotateValue)
434 switch (nVideoRotateValue) {
435 case VIDEO_ROTATE_PORTRAIT_NORMAL:
436 VideoLogInfo("Set Portrait.");
437 MpPlayerMgrSetRotate(VIDEO_SCREEN_PORTRAIT);
440 case VIDEO_ROTATE_LANDSCAPE_NORMAL:
441 VideoLogInfo("Set Landscape.");
442 MpPlayerMgrSetRotate(VIDEO_SCREEN_LANDSCAPE);
445 case VIDEO_ROTATE_PORTRAIT_REVERSE:
446 VideoLogInfo("Set Portrait reverse.");
447 MpPlayerMgrSetRotate(VIDEO_SCREEN_PORTRAIT_UPSIDEDOWN);
450 case VIDEO_ROTATE_LANDSCAPE_REVERSE:
451 VideoLogInfo("Set Landscape reverse.");
452 MpPlayerMgrSetRotate(VIDEO_SCREEN_LANDSCAPE_UPSIDEDOWN);
456 VideoLogInfo("Set Portrait.");
457 MpPlayerMgrSetRotate(VIDEO_SCREEN_PORTRAIT);
462 void MpVideoCtrlMgrSetMute(bool bMuteEnable)
466 MpPlayerMgrSetMute(bMuteEnable);
469 bool MpVideoCtrlMgrGetMuteState(void)
473 return MpPlayerMgrGetMute();
476 bool MpVideoCtrlMgrStartCapture(void *pVideoCaptureCb, void *pUserData)
480 return MpPlayerMgrCaptureVideo(pVideoCaptureCb, pUserData);
483 int MpVideoCtrlMgrGetBufferingPosition(void)
485 return MpPlayerMgrGetBufferingPosition();
488 bool MpVideoCtrlMgrIsExistPlayerHandle(void)
492 return MpPlayerMgrIsActive();
495 bool MpVideoCtrlMgrIsOnlyAudio(void)
499 int nStreamFileType = MpPlayerMgrGetFileStreamType();
501 if(nStreamFileType == MP_FILE_STREAM_TYPE_AUDIO)
503 VideoLogInfo("A file stream type is only audio.");
510 bool MpVideoCtrlMgrSetScaling(bool bScale)
514 return MpPlayerMgrSetScaling(bScale);
518 int MpVideoCtrlMgrGetErrorType(int nErrorVal)
524 case PLAYER_ERROR_NONE:
525 return MP_PLAYER_ERROR_NONE;
527 case PLAYER_ERROR_OUT_OF_MEMORY:
528 return MP_PLAYER_ERROR_OUT_OF_MEMORY;
530 case PLAYER_ERROR_INVALID_PARAMETER:
531 return MP_PLAYER_ERROR_INVALID_PARAMETER;
533 case PLAYER_ERROR_NO_SUCH_FILE:
534 return MP_PLAYER_ERROR_NO_SUCH_FILE;
536 case PLAYER_ERROR_INVALID_OPERATION:
537 return MP_PLAYER_ERROR_INVALID_OPERATION;
539 case PLAYER_ERROR_SEEK_FAILED:
540 return MP_PLAYER_ERROR_SEEK_FAILED;
542 case PLAYER_ERROR_INVALID_STATE:
543 return MP_PLAYER_ERROR_INVALID_STATE;
545 case PLAYER_ERROR_NOT_SUPPORTED_FILE:
546 return MP_PLAYER_ERROR_NOT_SUPPORTED_FILE;
548 case PLAYER_ERROR_INVALID_URI:
549 return MP_PLAYER_ERROR_INVALID_URI;
551 case PLAYER_ERROR_SOUND_POLICY:
552 return MP_PLAYER_ERROR_SOUND_POLICY;
554 case PLAYER_ERROR_CONNECTION_FAILED:
555 return MP_PLAYER_ERROR_CONNECTION_FAILED;
557 case PLAYER_ERROR_VIDEO_CAPTURE_FAILED:
558 return MP_PLAYER_ERROR_VIDEO_CAPTURE_FAILED;
561 return MP_PLAYER_ERROR_UNKNOWN_ERROR;
565 int MpVideoCtrlMgrGetClosedCaptionCount(void)
569 return MpPlayerMgrGetClosedCaptionCount();