Remove SMACK rule file(.rule) according three domain model
[apps/core/preloaded/video-player.git] / src / mp-video-ctrl-mgr.c
1 /*
2  * Copyright (c) [2012] Samsung Electronics Co., Ltd.
3  *
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
7  *
8  *     http://floralicense.org/license/
9  *
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.
15  */
16
17
18 #include <stdio.h>
19 #include <string.h>
20 #include <image_util.h>
21
22 #include "mp-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"
29
30 bool MpVideoCtrlMgrMediaCreate(char *szMediaURI, void *pOverlayXid, void *pEvasSinkID, char* szSubtitleUri, void *pUserData)
31 {
32         if(!pUserData)
33         {
34                 VideoLogInfo("[ERR] No exist pUserData.");
35                 return FALSE;
36         }
37
38         VideoAppData *pAppData = (VideoAppData *)pUserData;
39
40         VideoLogInfo("");
41
42         if(!MpPlayerMgrCreate(szMediaURI))
43         {
44                 VideoLogInfo("[ERR] Fail to create player handle.");
45                 return FALSE;
46         }
47
48         MpUtilGetUserAgent(pAppData);
49
50         if(!MpPlayerMgrSetUseragentForStreaming(pAppData->szUserAgent))
51         {
52                 VideoLogInfo("[ERR] Fail to set useragent.");
53                 return FALSE;
54         }
55
56         if(!MpPlayerMgrSetProxyAddressForStreaming(pAppData->szProxyAddress))
57         {
58                 VideoLogInfo("[ERR] Fail to set proxy address.");
59                 return FALSE;
60         }
61
62         if(!MpPlayerMgrSetCookieForStreaming(pAppData->szCookie))
63         {
64                 VideoLogInfo("[ERR] Fail to set Cookie.");
65                 return FALSE;
66         }
67
68         if(szSubtitleUri && strlen((char*)szSubtitleUri) > 0)
69         {
70                 VideoLogInfo("Subtitle URI : %s", szSubtitleUri);
71
72                 if(!MpPlayerMgrSetSubtitle(szSubtitleUri))
73                 {
74                         VideoLogInfo("Fail to set subtitle uri.");
75                 }
76         }
77         else
78         {
79                 VideoLogInfo("No exist subtitle uri.");
80         }
81
82         if(!MpPlayerMgrSetOverlayXid(pOverlayXid))
83         {
84                 VideoLogInfo("[ERR] Fail to set overlay window.");
85                 return FALSE;
86         }
87
88         if(!MpVideoCtrlMgrSetScaling(FALSE))
89         {
90                 VideoLogInfo("[ERR] Fail to set scaling.");
91                 return FALSE;
92         }
93
94         if(!MpPlayerMgrSetSoundPriority())
95         {
96                 VideoLogInfo("[ERR] Fail to set sound priority.");
97                 return FALSE;
98         }
99
100         pAppData->nCurPlayerState = MP_PLAYER_STATE_CLEAR;
101
102         return TRUE;
103 }
104
105 bool MpVideoCtrlMgrMediaRealize(void)
106 {
107         VideoLogInfo("");
108
109         if(!MpPlayerMgrRealize())
110         {
111                 VideoLogInfo("[ERR] Fail relization.");
112                 return FALSE;
113         }
114         return TRUE;
115 }
116
117 bool MpVideoCtrlMgrMediaRealizeAsync(void *pReailzeCb, void *pUserData)
118 {
119         VideoLogInfo("");
120
121         if(!MpPlayerMgrRealizeAsync(pReailzeCb, pUserData))
122         {
123                 VideoLogInfo("[ERR] Fail relization.");
124                 return FALSE;
125         }
126         return TRUE;
127 }
128
129 void MpVideoCtrlMgrMediaDestroy(void *pUserData)
130 {
131         if (!pUserData) {
132                 VideoLogInfo("[ERR] No exist pUserData.");
133                 return;
134         }
135
136         VideoAppData *pAppData = (VideoAppData *)pUserData;
137
138         VideoLogInfo("");
139
140         if (!MpPlayerMgrIsActive()) {
141                 VideoLogInfo(" Already destroy player handle.");
142                 return;
143         }
144
145         if (!MpPlayerMgrUnrealize()) {
146                 VideoLogInfo("[ERR] Fail to unrealize player handle.");
147         }
148
149         if (!MpPlayerMgrDestroy()) {
150                 VideoLogInfo("[ERR] Fail to destroy player handle.");
151                 return;
152         }
153
154         pAppData->nCurPlayerState = MP_PLAYER_STATE_CLEAR;
155 }
156
157 bool MpVideoCtrlMgrMediaPlay(void *pUserData)
158 {
159         if (!pUserData) {
160                 VideoLogInfo("[ERR] No exist pUserData.");
161                 return FALSE;
162         }
163
164         VideoAppData *pAppData = (VideoAppData *)pUserData;
165
166         VideoLogInfo("");
167
168         if (!MpPlayerMgrPlay()) {
169                 VideoLogInfo("[ERR] Fail to play multimedia player.");
170                 return FALSE;
171         }
172
173         pAppData->nCurPlayerState = MP_PLAYER_STATE_PLAY;
174
175         return TRUE;
176 }
177
178 void MpVideoCtrlMgrMediaStop(void *pUserData)
179 {
180         if (!pUserData) {
181                 VideoLogInfo("[ERR] No exist pUserData.");
182                 return;
183         }
184
185         VideoAppData *pAppData = (VideoAppData *)pUserData;
186
187         VideoLogInfo("");
188
189         if (!MpPlayerMgrIsActive()) {
190                 VideoLogInfo("[ERR] Player handle is destroyed.");
191                 return;
192         }
193
194         if (!MpPlayerMgrStop()) {
195                 VideoLogInfo("[ERR] Fail to stop multimedia player.");
196                 return;
197         }
198
199         pAppData->nCurPlayerState = MP_PLAYER_STATE_STOP;
200 }
201
202 void MpVideoCtrlMgrMediaPause(void *pUserData)
203 {
204         if (!pUserData) {
205                 VideoLogInfo("[ERR] No exist pUserData.");
206                 return;
207         }
208
209         VideoAppData *pAppData = (VideoAppData *)pUserData;
210
211         VideoLogInfo("");
212
213         if (pAppData->nCurPlayerState == MP_PLAYER_STATE_STOP) {
214                 VideoLogInfo
215                     ("It is not possible to pause when player state is stop.");
216                 return;
217         }
218
219         if (!MpPlayerMgrPause()) {
220                 VideoLogInfo("[ERR] Fail to pause multimedia player.");
221                 return;
222         }
223
224         pAppData->nCurPlayerState = MP_PLAYER_STATE_PAUSE;
225 }
226
227 void MpVideoCtrlMgrMediaResume(void *pUserData)
228 {
229         if (!pUserData) {
230                 VideoLogInfo("[ERR] No exist pUserData.");
231                 return;
232         }
233
234         VideoAppData *pAppData = (VideoAppData *)pUserData;
235
236         VideoLogInfo("");
237
238         if (pAppData->nCurPlayerState == MP_PLAYER_STATE_STOP) {
239                 VideoLogInfo
240                     ("It is not possible to resume when player state is stop.");
241                 return;
242         }
243
244         if (!MpPlayerMgrResume()) {
245                 VideoLogInfo("[ERR] Fail to resume multimedia player.");
246                 return;
247         }
248
249         pAppData->nCurPlayerState = MP_PLAYER_STATE_RESUME;
250 }
251
252 void MpVideoCtrlMgrSetPlayerCallback(void *PlayerCompletedCb, void *PlayerInterruptedCb, void *PlayerErrorCb, void *PlayerBufferingCb, void *PlayerSubtitleCb, void *pUserData)
253 {
254         if(!pUserData)
255         {
256                 VideoLogInfo("[ERR] No exist pUserData.");
257                 return;
258         }
259
260         if(!PlayerCompletedCb || !PlayerInterruptedCb || !PlayerErrorCb || !PlayerBufferingCb)
261         {
262                 VideoLogInfo("[ERR] No exist player callback function pointer.");
263                 return;
264         }
265
266         VideoLogInfo("");
267
268         MpPlayerMgrRegistePlayerCallback(PlayerCompletedCb, PlayerInterruptedCb, PlayerErrorCb, PlayerBufferingCb, PlayerSubtitleCb, pUserData);
269 }
270
271 void MpVideoCtrlMgrSetOverlayXid(void *pXid)
272 {
273         VideoLogInfo("");
274
275         if (!MpPlayerMgrSetOverlayXid(pXid)) {
276                 VideoLogInfo("[ERR] Fail to set overlay window.");
277                 return;
278         }
279 }
280 void MpVideoCtrlMgrSetEvasSinkID(void *pEvasSinkID)
281 {
282         VideoLogInfo("");
283
284         if (!MpPlayerMgrSetEvasSinkID(pEvasSinkID)) {
285                 VideoLogInfo("[ERR] Fail to set overlay window.");
286                 return;
287         }
288 }
289
290 void MpVideoCtrlMgrSetPosition(int nSetPosition, void *pSeekCb, void *pUserData)
291 {
292         VideoLogInfo("");
293
294         VideoLogInfo("Set position - %d", nSetPosition);
295
296         if (nSetPosition > -1) {
297                 MpPlayerMgrSetPosition(nSetPosition, pSeekCb, pUserData);
298         }
299 }
300 void MpVideoCtrlMgrSetSubtitlePosition(int nSetPosition)
301 {
302         VideoLogInfo("");
303
304         if (nSetPosition > -1) {
305                 MpPlayerMgrSetSubtitlePosition(nSetPosition);
306         }
307 }
308
309 int MpVideoCtrlMgrGetPosition(void)
310 {
311         /* VideoLogInfo(""); */
312
313         return MpPlayerMgrGetPosition();
314 }
315
316 int MpVideoCtrlMgrGetDuration(void)
317 {
318         VideoLogInfo("");
319
320         int nDuration = 0;
321
322         nDuration = MpPlayerMgrGetDuration();
323
324         VideoLogInfo(" content duration : %d ms", nDuration);
325
326         return nDuration;
327 }
328
329 void MpVideoCtrlMgrResetPlaySpeed(void *pUserData)
330 {
331         if (!pUserData) {
332                 VideoLogInfo("[ERR] No exist pUserData.");
333                 return;
334         }
335
336         VideoAppData *pAppData = (VideoAppData *)pUserData;
337
338         VideoLogInfo("");
339
340         if (!MpPlayerMgrSetPlaySpeed(1.0)) {
341                 VideoLogInfo("[ERR] Fail to reset play speed.");
342                 return;
343         }
344
345         pAppData->nPlayingSpeed = MP_PLAYING_SPEED_NORMAL;
346 }
347
348 void MpVideoCtrlMgrSetPlaySpeedUp(void *pUserData)
349 {
350         if (!pUserData) {
351                 VideoLogInfo("[ERR] No exist pUserData.");
352                 return;
353         }
354
355         VideoAppData *pAppData = (VideoAppData *)pUserData;
356
357         VideoLogInfo("");
358
359         if (pAppData->nPlayingSpeed > MP_PLAYING_SPEED_MAX) {
360                 VideoLogInfo("Current speed is full.(5X)");
361                 pAppData->nPlayingSpeed = MP_PLAYING_SPEED_5X;
362         }
363
364
365         float val = 0;
366         val = (float)pAppData->nPlayingSpeed;
367
368         MpPlayerMgrSetPlaySpeed(val);
369
370 }
371
372 void MpVideoCtrlMgrSetPlaySpeedDown(void *pUserData)
373 {
374         if (!pUserData) {
375                 VideoLogInfo("[ERR] No exist pUserData.");
376                 return;
377         }
378
379         VideoAppData *pAppData = (VideoAppData *)pUserData;
380
381         VideoLogInfo("");
382
383         if (pAppData->nPlayingSpeed > MP_PLAYING_SPEED_MAX) {
384                 VideoLogInfo("Current speed is full.(5X)");
385                 return;
386         }
387
388         float val = 0;
389         val = -(float)pAppData->nPlayingSpeed;
390         MpPlayerMgrSetPlaySpeed(val);
391
392 }
393
394 int MpVideoCtrlMgrGetVideoWidthResolution(void)
395 {
396         VideoLogInfo("");
397
398         int nVideoWidthResolution = MpPlayerMgrGetVideoWidthResolution();
399
400         VideoLogInfo("Video width resolution : %d", nVideoWidthResolution);
401
402         return nVideoWidthResolution;
403 }
404
405 int MpVideoCtrlMgrGetVideoHeightResolution(void)
406 {
407         VideoLogInfo("");
408
409         int nVideoHeightResolution = MpPlayerMgrGetVideoHeightResolution();
410
411         VideoLogInfo("Video height resolution : %d", nVideoHeightResolution);
412
413         return nVideoHeightResolution;
414 }
415
416 void MpVideoCtrlMgrSetRatioVideoScreen(void *pUserData, int nRatioScreenSize)
417 {
418         if (!pUserData) {
419                 VideoLogInfo("[ERR] No exist pUserData.");
420                 return;
421         }
422
423         VideoLogInfo("");
424
425         int nDisplayMode = PLAYER_DISPLAY_MODE_LETTER_BOX;
426
427         MpPlayerMgrSetDisplayMode(nDisplayMode);
428 }
429
430 void MpVideoCtrlMgrRotateVideoScreen(int nVideoRotateValue)
431 {
432         VideoLogInfo("");
433
434         switch (nVideoRotateValue) {
435         case VIDEO_ROTATE_PORTRAIT_NORMAL:
436                 VideoLogInfo("Set Portrait.");
437                 MpPlayerMgrSetRotate(VIDEO_SCREEN_PORTRAIT);
438                 break;
439
440         case VIDEO_ROTATE_LANDSCAPE_NORMAL:
441                 VideoLogInfo("Set Landscape.");
442                 MpPlayerMgrSetRotate(VIDEO_SCREEN_LANDSCAPE);
443                 break;
444
445         case VIDEO_ROTATE_PORTRAIT_REVERSE:
446                 VideoLogInfo("Set Portrait reverse.");
447                 MpPlayerMgrSetRotate(VIDEO_SCREEN_PORTRAIT_UPSIDEDOWN);
448                 break;
449
450         case VIDEO_ROTATE_LANDSCAPE_REVERSE:
451                 VideoLogInfo("Set Landscape reverse.");
452                 MpPlayerMgrSetRotate(VIDEO_SCREEN_LANDSCAPE_UPSIDEDOWN);
453                 break;
454
455         default:
456                 VideoLogInfo("Set Portrait.");
457                 MpPlayerMgrSetRotate(VIDEO_SCREEN_PORTRAIT);
458                 break;
459         }
460 }
461
462 void MpVideoCtrlMgrSetMute(bool bMuteEnable)
463 {
464         VideoLogInfo("");
465
466         MpPlayerMgrSetMute(bMuteEnable);
467 }
468
469 bool MpVideoCtrlMgrGetMuteState(void)
470 {
471         VideoLogInfo("");
472
473         return MpPlayerMgrGetMute();
474 }
475
476 bool MpVideoCtrlMgrStartCapture(void *pVideoCaptureCb, void *pUserData)
477 {
478         VideoLogInfo("");
479
480         return MpPlayerMgrCaptureVideo(pVideoCaptureCb, pUserData);
481 }
482
483 int MpVideoCtrlMgrGetBufferingPosition(void)
484 {
485         return MpPlayerMgrGetBufferingPosition();
486 }
487
488 bool MpVideoCtrlMgrIsExistPlayerHandle(void)
489 {
490         VideoLogInfo("");
491
492         return MpPlayerMgrIsActive();
493 }
494
495 bool MpVideoCtrlMgrIsOnlyAudio(void)
496 {
497         VideoLogInfo("");
498
499         int nStreamFileType = MpPlayerMgrGetFileStreamType();
500
501         if(nStreamFileType == MP_FILE_STREAM_TYPE_AUDIO)
502         {
503                 VideoLogInfo("A file stream type is only audio.");
504                 return TRUE;
505         }
506
507         return FALSE;
508 }
509
510 bool MpVideoCtrlMgrSetScaling(bool bScale)
511 {
512         VideoLogInfo("");
513
514         return MpPlayerMgrSetScaling(bScale);
515
516 }
517
518 int MpVideoCtrlMgrGetErrorType(int nErrorVal)
519 {
520         VideoLogInfo("");
521
522         switch(nErrorVal)
523         {
524         case PLAYER_ERROR_NONE:
525                 return MP_PLAYER_ERROR_NONE;
526
527         case PLAYER_ERROR_OUT_OF_MEMORY:
528                 return MP_PLAYER_ERROR_OUT_OF_MEMORY;
529
530         case PLAYER_ERROR_INVALID_PARAMETER:
531                 return MP_PLAYER_ERROR_INVALID_PARAMETER;
532
533         case PLAYER_ERROR_NO_SUCH_FILE:
534                 return MP_PLAYER_ERROR_NO_SUCH_FILE;
535
536         case PLAYER_ERROR_INVALID_OPERATION:
537                 return MP_PLAYER_ERROR_INVALID_OPERATION;
538
539         case PLAYER_ERROR_SEEK_FAILED:
540                 return MP_PLAYER_ERROR_SEEK_FAILED;
541
542         case PLAYER_ERROR_INVALID_STATE:
543                 return MP_PLAYER_ERROR_INVALID_STATE;
544
545         case PLAYER_ERROR_NOT_SUPPORTED_FILE:
546                 return MP_PLAYER_ERROR_NOT_SUPPORTED_FILE;
547
548         case PLAYER_ERROR_INVALID_URI:
549                 return MP_PLAYER_ERROR_INVALID_URI;
550
551         case PLAYER_ERROR_SOUND_POLICY:
552                 return MP_PLAYER_ERROR_SOUND_POLICY;
553
554         case PLAYER_ERROR_CONNECTION_FAILED:
555                 return MP_PLAYER_ERROR_CONNECTION_FAILED;
556
557         case PLAYER_ERROR_VIDEO_CAPTURE_FAILED:
558                 return MP_PLAYER_ERROR_VIDEO_CAPTURE_FAILED;
559
560         default:
561                 return MP_PLAYER_ERROR_UNKNOWN_ERROR;
562         }
563 }
564
565 int MpVideoCtrlMgrGetClosedCaptionCount(void)
566 {
567         VideoLogInfo("");
568
569         return MpPlayerMgrGetClosedCaptionCount();
570
571 }