tizen beta release
[framework/web/webkit-efl.git] / Source / WebCore / platform / graphics / efl / MediaPlayerPrivateMMFW.cpp
1 /*
2  * Copyright (C) 2007, 2009 Apple Inc.  All rights reserved.
3  * Copyright (C) 2007 Collabora Ltd.  All rights reserved.
4  * Copyright (C) 2009-2010 SAMSUNG Electronics
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * aint with this library; see the file COPYING.LIB.  If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21
22 #include "config.h"
23
24 #if ENABLE(VIDEO)
25
26 #include "MediaPlayerPrivateMMFW.h"
27
28 #include "Chrome.h"
29 #include "ChromeClient.h"
30 #include "Frame.h"
31 #include "FrameView.h"
32 #include "GraphicsContext.h"
33 #include "IntRect.h"
34 #include "KURL.h"
35 #include "MIMETypeRegistry.h"
36 #include "MediaPlayer.h"
37 #include "NotImplemented.h"
38 #include "Page.h"
39 #include "PlatformContextCairo.h"
40 #include "ResourceHandle.h"
41 #include "ScrollView.h"
42 #include "TimeRanges.h"
43 #include "Widget.h"
44
45 #include <Ecore.h>
46 #include <Ecore_Evas.h>
47 #include <Ecore_X.h>
48 #include <Evas.h>
49 #include <GOwnPtr.h>
50 #include <limits>
51 #include <math.h>
52
53 #ifndef NDEBUG   
54 #include <time.h>
55 #endif
56
57 #if ENABLE(TIZEN_MM_PLAYER)
58 #include "FrameLoaderClientEfl.h"
59 #include "HTMLMediaElement.h"
60 #include "HTMLNames.h"
61 #include "Settings.h"
62 #include "UserGestureIndicator.h"
63 // support full-screen
64 #include <Elementary.h>
65 #include <utilX.h>
66 #if USE(SOUP)
67 #include "SoupURIUtils.h"
68 #include <libsoup/soup.h>
69 #endif
70
71 #include <cairo.h>
72 #endif // TIZEN_MM_PLAYER
73
74 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
75 #if !USE(TIZEN_TEXTURE_MAPPER)
76 #include "EflLayer.h"
77 #endif
78 #endif
79
80 #if ENABLE(TIZEN_WAC_CAMERA_SUPPORT)
81 #include "CameraManager.h"
82 #include "HTMLVideoElement.h"
83 #endif
84
85 #if ENABLE(TIZEN_FILE_SYSTEM)
86 #include "AsyncFileSystem.h"
87 #include "DOMFileSystemBase.h"
88 #include "LocalFileSystem.h"
89 #endif
90
91 using namespace std;
92
93 namespace WebCore {
94
95 #if ENABLE(TIZEN_MM_PLAYER)
96
97 // settings
98 // #define __VIDEO_DEBUG_PRINT
99 #define MM_PLAY_GET_HEXADECIMAL(p) ((p / 16) * 16)
100 #define HTML5_VIDEO_PLAY_ICON "/usr/share/ewebkit-0/images/html5_video_play.png"
101 #define MAX_VIDEO_SIZE 640
102 #define EVAS_ICON_SIZE 40
103
104 // alias
105
106 // PLAY_TIME_FORMAT   // for slide bar of controlbar
107 #define MM_PLAY_TIME_FORMAT "02u:%02u:%02u"
108 // PLAY_TIME_ARGS
109 #define MM_PLAY_TIME_ARGS(t) \
110         (t) / (60 * 60), \
111         ((t) / 60) % 60, \
112         (t) % 60
113 #define PANLE_BUTTON_WIDTH 52
114 #define HTML5_VIDEO_USER_AGENT_KEY  "db/browser/UserAgent"
115 #define CONTROLBAR_HIDE_TIME 5
116 #define VIDEO_FPS 0.03
117 #define VIDEO_RESUME_TIME 0.5
118 #define AUDIO_READY_TIME 0.0
119 #define MAX_AUDIO_HANDLE 10
120
121 static MediaPlayerPrivate* gPlayer = 0; // current mm-player
122
123 static MediaPlayerPrivate* gAudioPlayer[MAX_AUDIO_HANDLE] = {0};
124
125 void delAudioHandle(void* data)
126 {
127     int i, j;
128
129     MediaPlayerPrivate* mp = reinterpret_cast<MediaPlayerPrivate*>(data);
130     if (!mp)
131         return;
132
133     for (i = 0; i < MAX_AUDIO_HANDLE; i++) {
134         // find audio handle to remove
135         if (gAudioPlayer[i] == mp) {
136             LOG(Media, "%s() --- audio handle %d: %p\n", __FUNCTION__, i, mp);
137             for (j = i; j < MAX_AUDIO_HANDLE - 1; j++)
138                 gAudioPlayer[j] = gAudioPlayer[j + 1]; // shift remaining audio handles
139             gAudioPlayer[j] = 0; // set null
140             break;
141         }
142     }
143 }
144
145 void removeOneAudioHandle()
146 {
147     int i;
148
149     for (i = 0; i < MAX_AUDIO_HANDLE; i++) {
150         if (gAudioPlayer[i]->getStatus() == MM_PLAYER_STOP) {
151             LOG(Media, "%s() !!! audio handle not playing %d: %p\n", __FUNCTION__, i, gAudioPlayer[i]);
152             break;
153         }
154         LOG(Media, "%s() xxx playing %d: %p\n", __FUNCTION__, i, gAudioPlayer[i]);
155     }
156
157     i = i % MAX_AUDIO_HANDLE; //  remove first one if all audios are playing.
158
159     // remove audio handle
160     LOG(Media, "%s() !!! audio handle remove %d: %p\n", __FUNCTION__, i, gAudioPlayer[i]);
161     gAudioPlayer[i]->setStatus(MM_PLAYER_STOP);
162     gAudioPlayer[i]->destroyEmbedPlayer();
163 }
164
165 int findEmptyAudioHandleIndex()
166 {
167     int i;
168
169     for (i = 0; i < MAX_AUDIO_HANDLE; i++) {
170         // find empty handle index
171         if (!gAudioPlayer[i]) {
172             LOG(Media, "%s() !!! audio handle %d\n", __FUNCTION__, i);
173             return i;
174         }
175     }
176
177     // no empty handle in the array. remove first one which is not playing.
178     removeOneAudioHandle();
179
180     return MAX_AUDIO_HANDLE - 1;
181 }
182
183 void addAudioHandle(void* data)
184 {
185     MediaPlayerPrivate* mp = reinterpret_cast<MediaPlayerPrivate*>(data);
186     if (!mp)
187         return;
188
189     int index = findEmptyAudioHandleIndex();
190
191     LOG(Media, "%s() +++ audio handle %d: %p\n", __FUNCTION__, index, mp);
192     gAudioPlayer[index] = mp;
193 }
194
195 struct _HTML5Video {
196     char* path;
197     char* cookie;
198 };
199 /////////// define callbasks //////////////////
200
201 Eina_Bool timerCatchLongPressEvent(void* data)
202 {
203     MediaPlayerPrivate* mp = reinterpret_cast<MediaPlayerPrivate*>(data);
204     if (!mp)
205         return EINA_FALSE;
206
207     mp->enterFullscreen();
208     return EINA_FALSE;
209 }
210
211 Eina_Bool timerEmbedStop(void* data)
212 {
213     LOG(Media, "%s\n", __func__);
214     MediaPlayerPrivate* mp = reinterpret_cast<MediaPlayerPrivate*>(data);
215     if (!mp)
216         return EINA_FALSE;
217
218     mp->destroyEmbedPlayer();
219     return EINA_FALSE;
220 }
221
222 Eina_Bool timerEmbedInvalidateRect(void* data)
223 {
224 #ifdef __VIDEO_DEBUG_PRINT /*  check FPS */
225     static int fps = 0;
226     fps++;
227     static struct timeval tp;
228     static time_t ptp = 0;
229     gettimeofday(&tp, 0);
230     if (ptp != tp.tv_sec) {
231         ptp = tp.tv_sec;
232         LOG(Media, "timerEmbedInvalidateRect [FPS:%d]\n", fps);
233         fps = 0;
234     }
235 #endif
236     MediaPlayerPrivate* mp = reinterpret_cast<MediaPlayerPrivate*>(data);
237     mp->repaint();
238     return EINA_TRUE;
239 }
240
241 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
242 Eina_Bool timerFillVideoRect(void* data)
243 {
244     LOG(Media, "%s()\n", __func__);
245     MediaPlayerPrivate* mp = reinterpret_cast<MediaPlayerPrivate*>(data);
246     if (!mp)
247         return EINA_FALSE;
248
249     mp->fillVideoRect();
250     return EINA_FALSE;
251 }
252 #endif
253
254 Eina_Bool timerResumeVideo(void* data)
255 {
256     LOG(Media, "%s()\n", __FUNCTION__);
257     MediaPlayerPrivate* mp = reinterpret_cast<MediaPlayerPrivate*>(data);
258     if (!mp)
259         return EINA_FALSE;
260
261     HTMLMediaElement* mediaElement = static_cast<HTMLMediaElement*>(mp->getMMPlayer()->mediaPlayerClient());
262     if (mediaElement)
263         mediaElement->play();
264
265     return EINA_FALSE;
266 }
267
268 Eina_Bool timerRecvInterrupted(void* data)
269 {
270     LOG(Media, "%s()\n", __FUNCTION__);
271     MediaPlayerPrivate* mp = reinterpret_cast<MediaPlayerPrivate*>(data);
272     if (!mp)
273         return EINA_FALSE;
274
275     mp->setStatus(MM_PLAYER_PAUSE);
276     mp->setStartedPlaying(false);
277     mp->videoUpdatePause();
278
279     HTMLMediaElement* mediaElement = static_cast<HTMLMediaElement*>(mp->getMMPlayer()->mediaPlayerClient());
280     if (mediaElement)
281         mediaElement->pause();
282
283     return EINA_FALSE;
284 }
285
286 Eina_Bool timerRecvBeginOfStream(void* data)
287 {
288     LOG(Media, "%s()\n", __FUNCTION__);
289     MediaPlayerPrivate* mp = reinterpret_cast<MediaPlayerPrivate*>(data);
290     if (!mp)
291         return EINA_FALSE;
292
293     mp->duration();
294     mp->getMMPlayer()->durationChanged();
295
296     return EINA_FALSE;
297 }
298
299 Eina_Bool timerMediaReady(void* data)
300 {
301     LOG(Media, "%s()\n", __FUNCTION__);
302     MediaPlayerPrivate* mp = reinterpret_cast<MediaPlayerPrivate*>(data);
303     if (!mp)
304         return EINA_FALSE;
305
306     mp->setMediaReady();
307
308     return EINA_FALSE;
309 }
310
311 // data structure for registering ewk callback
312 struct ewkCallbackNode {
313     MediaPlayerPrivate* mp;
314     Evas_Object* o;
315     struct ewkCallbackNode* next;
316 } ewkCallbackNode;
317
318 // root nodes for ewk callbacks
319 struct ewkCallbackNode* ewkCallbackSmartCalculateRoot = 0;
320 struct ewkCallbackNode* ewkCallbackZoomWeakRoot = 0;
321 struct ewkCallbackNode* ewkCallbackZoomRoot = 0;
322 struct ewkCallbackNode* ewkCallbackPauseOrResumeRoot = 0;
323
324 void callbackSmartCalculate(void* data, Evas_Object* obj, void* eventInfo)
325 {
326     struct ewkCallbackNode* node = ewkCallbackSmartCalculateRoot;
327     while (node) {
328         if (node->mp && node->o == obj)
329             node->mp->smartCalculate();
330         node = node->next;
331     }
332 }
333
334 void callbackSetZoomWeak(void* data, Evas_Object* obj, void* eventInfo)
335 {
336     struct ewkCallbackNode* node = ewkCallbackZoomWeakRoot;
337     while (node) {
338         if (node->mp && node->o == obj)
339             node->mp->setZoomWeak(eventInfo);
340         node = node->next;
341     }
342 }
343
344 void callbackSetZoom(void* data, Evas_Object* obj, void* eventInfo)
345 {
346     struct ewkCallbackNode* node = ewkCallbackZoomRoot;
347     while (node) {
348         if (node->mp && node->o == obj)
349             node->mp->setZoom(eventInfo);
350         node = node->next;
351     }
352 }
353
354 void callbackPauseOrResume(void* data, Evas_Object* obj, void* eventInfo)
355 {
356     struct ewkCallbackNode* node = ewkCallbackPauseOrResumeRoot;
357     while (node) {
358         if (node->mp && node->o == obj)
359             node->mp->pauseOrResume(*(bool*)eventInfo);
360         node = node->next;
361     }
362 }
363
364 void addEwkCallback(Evas_Object* obj, const char* event, Evas_Smart_Cb func, struct ewkCallbackNode** root, void* data)
365 {
366     struct ewkCallbackNode* node;
367
368     node = (struct ewkCallbackNode*)malloc(sizeof(struct ewkCallbackNode));
369     if (!node) {
370         LOG(Media, "%s() malloc fail!\n", __FUNCTION__);
371         return;
372     }
373
374     // make a node
375     node->mp = reinterpret_cast<MediaPlayerPrivate*>(data);
376     node->o = obj;
377     node->next = 0;
378
379     // add evas callback if it is not added
380     struct ewkCallbackNode* ptr;
381     bool isExist = false;
382     ptr = *root;
383     while (ptr) {
384         // check evas object is in the list
385         if (ptr->o == obj) {
386             isExist = true;
387             break;
388         }
389         ptr = ptr->next;
390     }
391     if (!isExist) {
392         LOG(Media, "%s() +++++ add evas callback! (%p)\n", __FUNCTION__, obj);
393         evas_object_smart_callback_add(obj, event, func, 0);
394     }
395
396     if (!*root) {
397         // make root and add evas callback
398         *root = node;
399     } else {
400         // append the node to last of the linked list
401         struct ewkCallbackNode* ptr = *root;
402         isExist = false;
403         while (ptr) {
404             if (ptr->mp == node->mp) {
405                 LOG(Media, "%s() already in the list. (mp: %p)", __FUNCTION__, ptr->mp);
406                 isExist = true;
407                 break;
408             }
409             if (!ptr->next)
410                 break;
411             ptr = ptr->next;
412         }
413         if (!isExist)
414             ptr->next = node;
415     }
416 }
417
418 void delEwkCallback(Evas_Object* obj, const char* event, Evas_Smart_Cb func, struct ewkCallbackNode** root, void* data)
419 {
420     struct ewkCallbackNode* node;
421
422     if (!*root)
423         return;
424
425     if ((*root)->mp == data) {
426         // remove root node and make root with next node
427         node = (*root)->next;
428         free(*root);
429         *root = node;
430     } else {
431         // remove matched node and re-link list
432         struct ewkCallbackNode* ptr = *root;
433         while (node = ptr->next) {
434             if (node->mp == data) {
435                 ptr->next = node->next;
436                 free(node);
437                 break;
438             }
439             ptr = ptr->next;
440         }
441     }
442
443     // del evas callback if evas object is not in the list
444     struct ewkCallbackNode* ptr;
445     bool isExist = false;
446     ptr = *root;
447     while (ptr) {
448         // check evas object is in the list
449         if (ptr->o == obj) {
450             isExist = true;
451             break;
452         }
453         ptr = ptr->next;
454     }
455     if (!isExist) {
456         LOG(Media, "%s() ----- del evas callback! (%p)\n", __FUNCTION__, obj);
457         evas_object_smart_callback_del(obj, event, func);
458     }
459 }
460
461 /* In case of sound plugin, message callback funtion draws control pannel. That's why in case of sound plugin, the video out callback doesn't exist */
462 static int callbackEmbedVideoMessage(int msg, void *param, void *user_param)
463 {
464     MediaPlayerPrivate* mp = reinterpret_cast<MediaPlayerPrivate*>(user_param);
465     MMMessageParamType* msgParam = (MMMessageParamType*)param;
466     switch (msg) {
467     case MM_MESSAGE_ERROR:
468         LOG(Media, "%s (%d:MM_MESSAGE_ERROR)\n", __FUNCTION__, msg);
469         mp->setStatus(MM_PLAYER_STOP);
470         mp->stopInternal(true);
471         break;
472     case MM_MESSAGE_UNKNOWN:
473         LOG(Media, "%s (%d:UNKNOWN)\n", __FUNCTION__, msg);
474         mp->setStatus(MM_PLAYER_STOP);
475         mp->stopInternal(true);
476         break;
477     case MM_MESSAGE_RESUMED_BY_REW:
478         LOG(Media, "%s (%d:MM_MESSAGE_RESUMED_BY_REW)\n", __FUNCTION__, msg);
479         mp->setStatus(MM_PLAYER_PLAY);
480         mp->play();
481         break;
482     case MM_MESSAGE_FILE_NOT_SUPPORTED:          /**< Not supported file */
483         LOG(Media, "MM_MESSAGE_FILE_NOT_SUPPORTED %08x\n", msg);
484         mp->stopInternal(true);
485         break;
486     case MM_MESSAGE_FILE_NOT_FOUND:                      /**< Not founded file */
487         LOG(Media, "MM_MESSAGE_FILE_NOT_FOUND %08x\n", msg);
488         mp->stopInternal(true);
489         break;
490     case MM_MESSAGE_DRM_NOT_AUTHORIZED:          /**< Not authorized to play the content */
491         LOG(Media, "MM_MESSAGE_DRM_NOT_AUTHORIZED %08x\n", msg);
492         break;
493     case MM_MESSAGE_STATE_INTERRUPTED:
494         switch ((int)msgParam->code) {
495         case MM_MSG_CODE_INTERRUPTED_BY_OTHER_APP:
496             LOG(Media, "MM_MSG_CODE_INTERRUPTED_BY_OTHER_APP\n");
497             break;
498         case MM_MSG_CODE_INTERRUPTED_BY_CALL_START:
499             LOG(Media, "MM_MSG_CODE_INTERRUPTED_BY_CALL_START\n");
500             break;
501         case MM_MSG_CODE_INTERRUPTED_BY_CALL_END:
502             LOG(Media, "MM_MSG_CODE_INTERRUPTED_BY_CALL_END\n");
503             break;
504         case MM_MSG_CODE_INTERRUPTED_BY_EARJACK_UNPLUG:
505             LOG(Media, "MM_MSG_CODE_INTERRUPTED_BY_EARJACK_UNPLUG\n");
506             break;
507         case MM_MSG_CODE_INTERRUPTED_BY_RESOURCE_CONFLICT:
508             LOG(Media, "MM_MSG_CODE_INTERRUPTED_BY_RESOURCE_CONFLICT\n");
509             break;
510         case MM_MSG_CODE_INTERRUPTED_BY_ALARM_START:
511             LOG(Media, "MM_MSG_CODE_INTERRUPTED_BY_ALARM_START\n");
512             break;
513         case MM_MSG_CODE_INTERRUPTED_BY_ALARM_END:
514             LOG(Media, "MM_MSG_CODE_INTERRUPTED_BY_ALARM_END\n");
515             break;
516         }
517         ecore_timer_add(0.0, timerRecvInterrupted, mp);
518         break;
519     case MM_MESSAGE_READY_TO_RESUME:
520         LOG(Media, "MM_MESSAGE_READY_TO_RESUME %08x\n", msg);
521         break;
522     case MM_MESSAGE_CONNECTING:           /**< Connecting message type 0x100*/
523         LOG(Media, "MM_MESSAGE_CONNECTING %08x\n", msg);
524         break;
525     case MM_MESSAGE_CONNECTED:                           /**< Rtspsrc has successed to connecting to server */
526         LOG(Media, "MM_MESSAGE_CONNECTED %08x\n", msg);
527         break;
528     case MM_MESSAGE_CONNECTION_TIMEOUT:          /**< Connection timeout message type */
529         LOG(Media, "MM_MESSAGE_CONNECTION_TIMEOUT %08x\n", msg);
530         mp->stopInternal(true);
531         break;
532     case MM_MESSAGE_UPDATE_SUBTITLE :
533         LOG(Media, "%s (%d:MM_MESSAGE_UPDATE_SUBTITLE)\n", __FUNCTION__, msg);
534         break;
535     case MM_MESSAGE_BUFFERING:
536         LOG(Media, "%s (%d:MM_MESSAGE_BUFFERING) : %d\n", __FUNCTION__, msg, msgParam->connection.buffering);
537         if (msgParam->connection.buffering > 95)
538             mp->hideEmbedLoadingIcon();
539         else
540             mp->showEmbedLoadingIcon();
541         break;
542     case MM_MESSAGE_BEGIN_OF_STREAM:
543         LOG(Media, "%s (%d:MM_MESSAGE_BEGIN_OF_STREAM)\n", __FUNCTION__, msg);
544         ecore_timer_add(0.0, timerRecvBeginOfStream, mp);
545         break;
546     case MM_MESSAGE_END_OF_STREAM:
547         LOG(Media, "%s (%d:MM_MESSAGE_END_OF_STREAM)\n", __FUNCTION__, msg);
548         mp->setStatus(MM_PLAYER_STOP);
549         mp->didEnd(); // repaint controls
550         break;
551     case MM_MESSAGE_STATE_CHANGED:
552         switch ((int)msgParam->state.current) {
553         case MM_PLAYER_STATE_NONE:
554             LOG(Media, "%s (MM_PLAYER_STATE_NONE)\n", __FUNCTION__);
555             break;
556         case MM_PLAYER_STATE_READY:
557             LOG(Media, "%s (MM_PLAYER_STATE_READY)\n", __FUNCTION__);
558             break;
559         case MM_PLAYER_STATE_PLAYING:
560             LOG(Media, "%s (MM_PLAYER_STATE_PLAYING)\n", __FUNCTION__);
561             mp->hideEmbedLoadingIcon();
562             mp->videoUpdateStart();
563             mp->setStatus(MM_PLAYER_PLAY);
564             break;
565         case MM_PLAYER_STATE_PAUSED:
566             LOG(Media, "%s (MM_PLAYER_STATE_PAUSED)\n", __FUNCTION__);
567             mp->videoUpdatePause();
568             mp->recvMsgPaused();
569             break;
570         }
571         break;
572         default :
573         LOG(Media, "No message %08x\n", msg);
574         break;
575     }
576     return MM_ERROR_NONE;
577 }
578
579 /* In case of video media plug, video callback funtion draws frame data and control pannel */
580 static bool callbackEmbedVideoFrame(void *stream, int streamSize, void *user_param, int width, int height)
581 {
582     MediaPlayerPrivate* mp = reinterpret_cast<MediaPlayerPrivate*>(user_param);
583     if (!mp)
584         return false;
585
586     if (!stream || streamSize <= 0)
587         return false;
588
589     if (mp->getSizeChanged()) {
590         LOG(Media, "%s(): change buffer size", __FUNCTION__);
591         mp->setSizeChanged(false);
592         mp->setVideoBuffer(IntSize(width, height));
593
594         // skip 1 frame for stability
595         return false;
596     }
597
598     IntSize contentInfo = mp->getContentSize();
599     if (contentInfo.width() != width || contentInfo.height() != height) {
600         LOG(Media, "%s(): content size mismatch!!\n", __FUNCTION__);
601         mp->setSizeChanged(true);
602 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
603         mp->setNeedsUpdate(false); // stop video layer painting
604 #endif
605         return false;
606     }
607
608     unsigned char* buf = mp->getEmbedCanvasBuffer();
609     if (!buf) {
610         LOG(Media, "%s(): buf is NULL\n", __FUNCTION__);
611         return false;
612     }
613
614 #if !ENABLE(TIZEN_WEBKIT2)
615     memcpy(buf, stream, streamSize); // RGBA frame
616 #endif
617
618 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
619     mp->setNeedsUpdate(true);
620 #endif
621
622     return true;
623 }
624 /////////// callbasks //////////////////
625
626 /////////// For Audio //////////////
627 int callbackAudioMessage(int msg, void *param, void *user_param)
628 {
629     MediaPlayerPrivate* mp = reinterpret_cast<MediaPlayerPrivate*>(user_param);
630     MMMessageParamType* msgParam = (MMMessageParamType*)param;
631     switch (msg) {
632     case MM_MESSAGE_STATE_INTERRUPTED:
633         switch ((int)msgParam->code) {
634         case MM_MSG_CODE_INTERRUPTED_BY_OTHER_APP:
635             LOG(Media, "MM_MSG_CODE_INTERRUPTED_BY_OTHER_APP\n");
636             break;
637         case MM_MSG_CODE_INTERRUPTED_BY_CALL_START:
638             LOG(Media, "MM_MSG_CODE_INTERRUPTED_BY_CALL_START\n");
639             break;
640         case MM_MSG_CODE_INTERRUPTED_BY_CALL_END:
641             LOG(Media, "MM_MSG_CODE_INTERRUPTED_BY_CALL_END\n");
642             break;
643         case MM_MSG_CODE_INTERRUPTED_BY_EARJACK_UNPLUG:
644             LOG(Media, "MM_MSG_CODE_INTERRUPTED_BY_EARJACK_UNPLUG\n");
645             break;
646         case MM_MSG_CODE_INTERRUPTED_BY_RESOURCE_CONFLICT:
647             LOG(Media, "MM_MSG_CODE_INTERRUPTED_BY_RESOURCE_CONFLICT\n");
648             break;
649         case MM_MSG_CODE_INTERRUPTED_BY_ALARM_START:
650             LOG(Media, "MM_MSG_CODE_INTERRUPTED_BY_ALARM_START\n");
651             break;
652         case MM_MSG_CODE_INTERRUPTED_BY_ALARM_END:
653             LOG(Media, "MM_MSG_CODE_INTERRUPTED_BY_ALARM_END\n");
654             break;
655         }
656         ecore_timer_add(0.0, timerRecvInterrupted, mp);
657         break;
658     case MM_MESSAGE_BUFFERING:
659         LOG(Media, "%s (%d:MM_MESSAGE_BUFFERING) : %d\n", __FUNCTION__, msg, msgParam->connection.buffering);
660         break;
661     case MM_MESSAGE_BEGIN_OF_STREAM:
662         LOG(Media, "(MM_MESSAGE_BEGIN_OF_STREAM)\n");
663         ecore_timer_add(0.0, timerRecvBeginOfStream, mp);
664         break;
665     case MM_MESSAGE_END_OF_STREAM:
666         LOG(Media, "(MM_MESSAGE_END_OF_STREAM)\n");
667         mp->setStatus(MM_PLAYER_STOP);
668         mp->didEnd(); // repaint controls
669         break;
670     case MM_MESSAGE_STATE_CHANGED:
671         switch ((int)msgParam->state.current) {
672         case MM_PLAYER_STATE_PLAYING:
673             LOG(Media, "(MM_PLAYER_STATE_PLAYING)\n");
674             mp->setStatus(MM_PLAYER_PLAY);
675             break;
676         case MM_PLAYER_STATE_PAUSED:
677             LOG(Media, "(MM_PLAYER_STATE_PAUSED)\n");
678             mp->recvMsgPaused();
679             break;
680         }
681         break;
682     }
683     return MM_ERROR_NONE;
684 }
685 /////////// For Audio //////////////
686 #endif // TIZEN_MM_PLAYER
687
688 PassOwnPtr<MediaPlayerPrivateInterface> MediaPlayerPrivate::create(MediaPlayer* player)
689 {
690     LOG(Media, "%s\n", __func__);
691     return adoptPtr(new MediaPlayerPrivate(player));
692 }
693
694 void MediaPlayerPrivate::registerMediaEngine(MediaEngineRegistrar registrar)
695 {
696     LOG(Media, "%s\n", __func__);
697     if (isAvailable())
698         registrar(create, getSupportedTypes, supportsType, 0, 0, 0);
699 }
700
701 MediaPlayerPrivate::MediaPlayerPrivate(MediaPlayer* player)
702     : m_player(player)
703     , m_rate(1.0f)
704     , m_endTime(numeric_limits<float>::infinity())
705     , m_isEndReached(false)
706     , m_volume(0.5f)
707     , m_networkState(MediaPlayer::Empty)
708     , m_readyState(MediaPlayer::HaveNothing)
709     , m_startedPlaying(false)
710 #if ENABLE(TIZEN_MM_PLAYER)
711     , m_isStreaming(true)
712     , m_size(IntSize())
713     , m_visible(false)
714 #else
715     , m_isStreaming(false)
716     , m_size(IntSize())
717     , m_visible(true)
718 #endif
719     , m_errorOccured(false)
720 #if ENABLE(TIZEN_MM_PLAYER)
721     , m_delayingLoad(false)
722     , m_videoKeyHandler(0)
723     , m_playerStatus(MM_PLAYER_STOP)
724     , m_contentSeekPosition(0)
725     , m_contentDuration(0)
726     , m_frameBuffer(0)
727     , m_contentWidth(0)
728     , m_contentHeight(0)
729     , m_mmPlayerHandle(0)
730     , m_embedVideoUpdateTimer(0)
731     , m_embedVideoLongpressTimer(0)
732     , m_resumeVideoTimer(0)
733 #endif
734 {
735 #if ENABLE(TIZEN_MM_PLAYER)
736     LOG(Media, "%s\n", __func__);
737     m_usingExternalPlayer = false;
738 #else
739     m_usingExternalPlayer = true;
740 #endif
741
742     m_firstPainted = false;
743     m_pixmapid = 0;
744
745     if (m_usingExternalPlayer)
746         return;
747
748 #if ENABLE(TIZEN_MM_PLAYER)
749     m_bufferingProgressbar = 0;
750     m_bufferingProgressbarBg = 0;
751     m_playIcon = 0;
752     m_rootView = 0;
753     m_isEmbedVideo = false;
754     m_isZooming = false;
755     m_zoomRatio = 1.0;
756     m_isSizeChanged = false;
757     m_suspended = false;
758
759 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
760     m_acceleratedCompositing = false;
761     m_needsUpdate = false;
762 #endif
763 #endif
764 }
765
766 MediaPlayerPrivate::~MediaPlayerPrivate()
767 {
768     LOG(Media, "%s\n", __func__);
769
770     if (m_usingExternalPlayer)
771         return;
772
773 #if ENABLE(TIZEN_MM_PLAYER)
774     videoUpdateStop();
775     hideEmbedLoadingIcon();
776 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
777     hideEmbedPlayIcon();
778 #endif
779     if (m_rootView) {
780         LOG(Media, "%s() evas_object_smart_callback_del()\n", __FUNCTION__);
781 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
782         if (ewkCallbackSmartCalculateRoot)
783             delEwkCallback(m_rootView, "html5video,panning", callbackSmartCalculate, &ewkCallbackSmartCalculateRoot, this);
784         if (ewkCallbackZoomWeakRoot)
785             delEwkCallback(m_rootView, "html5video,weakzoom", callbackSetZoomWeak, &ewkCallbackZoomWeakRoot, this);
786         if (ewkCallbackZoomRoot)
787             delEwkCallback(m_rootView, "html5video,zoom", callbackSetZoom, &ewkCallbackZoomRoot, this);
788 #endif
789         if (ewkCallbackPauseOrResumeRoot)
790             delEwkCallback(m_rootView, "html5video,pauseresume", callbackPauseOrResume, &ewkCallbackPauseOrResumeRoot, this);
791         m_rootView = 0;
792     }
793
794     destroyEmbedPlayer();
795     LOG(Media, "%s\n", __func__);
796
797     if (gPlayer == this) {
798         LOG(Media, "%s(): gPlayer = NULL\n", __FUNCTION__);
799         gPlayer = 0;
800     }
801 #endif
802 }
803
804 void MediaPlayerPrivate::load(const String& url)
805 {
806     LOG(Media, "%s\n", __func__);
807     LOG(Media, "Load %s", url.utf8().data());
808
809 #if ENABLE(TIZEN_MM_PLAYER)
810     m_url = url;
811     if (m_url.contains("rtsp://"))
812         m_isStreaming = true;
813     else
814         m_isStreaming = false;
815
816 #if ENABLE(TIZEN_FILE_SYSTEM)
817     if (m_url.contains("filesystem:")) {
818         AsyncFileSystem::Type type;
819         String filePath;
820         const KURL filesystemURL(ParsedURLString, m_url.utf8().data());
821         DOMFileSystemBase::crackFileSystemURL(filesystemURL, type, filePath);
822         m_url = "file://" + LocalFileSystem::localFileSystem().fileSystemBasePath() + filePath;
823         LOG_ERROR("[MediaPlayerPrivate::load] %s", m_url.utf8().data());
824     }
825 #endif
826
827     if (m_url.contains("file://")) /*by kwangmin... url_decode*/
828         m_url.replace("%20", " ");
829
830     m_startedPlaying = false;
831     m_delayingLoad = true;
832
833 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
834     if (!platformLayer())
835         acceleratedRenderingStateChanged();
836 #endif
837
838     setRootView();
839
840     if (hasVideo()) { // video
841         LOG(Media, "%s video\n", __FUNCTION__);
842         if (m_isEmbedVideo) {
843             if (m_networkState != MediaPlayer::Idle) {
844                 m_networkState = MediaPlayer::Idle;
845                 m_player->networkStateChanged();
846             }
847         } else {
848             if (m_networkState != MediaPlayer::Loaded) {
849                 m_networkState = MediaPlayer::Loaded;
850                 m_player->networkStateChanged();
851             }
852             if (m_readyState != MediaPlayer::HaveEnoughData) {
853                 m_readyState = MediaPlayer::HaveEnoughData;
854                 m_player->readyStateChanged();
855             }
856
857             repaint(); // paint video rect after load finish
858         }
859     } else { // audio
860         LOG(Media, "%s audio\n", __FUNCTION__);
861         if (m_networkState != MediaPlayer::Loading) {
862             m_networkState = MediaPlayer::Loading;
863             m_player->networkStateChanged();
864         }
865
866         m_delayingLoad = false;
867         internalPlay();
868     }
869 #endif
870 }
871
872 void MediaPlayerPrivate::commitLoad()
873 {
874     LOG(Media, "%s\n", __func__);
875 #if ENABLE(TIZEN_MM_PLAYER)
876     if (hasVideo() && m_isEmbedVideo)
877         internalPlay();
878     else
879         updateStates();
880 #endif
881 }
882
883 #if ENABLE(TIZEN_MM_PLAYER)
884 void MediaPlayerPrivate::setRootView()
885 {
886     LOG(Media, "%s()\n", __FUNCTION__);
887
888     if (m_player->frameView()) {
889 #if USE(ACCELERATED_COMPOSITING)
890         // it is available only ACCELERATED_COMPOSITING is enabled.
891         m_isEmbedVideo = m_player->frameView()->frame()->page()->settings()->acceleratedCompositingForVideoEnabled()
892                         && m_player->frameView()->frame()->page()->settings()->acceleratedCompositingEnabled();
893 #endif
894         m_rootView = evas_object_smart_parent_get(m_player->frameView()->root()->evasObject());
895         if (!m_rootView) {
896             LOG(Media, "%s() cannot get web view.\n", __FUNCTION__);
897             return;
898         }
899 #if USE(ACCELERATED_COMPOSITING)
900         if (hasVideo()) {
901             if (m_isEmbedVideo) {
902                 ecore_timer_add(0.2, timerFillVideoRect, this);
903                 LOG(Media, "%s() evas_object_smart_callback_add()\n", __FUNCTION__);
904                 addEwkCallback(m_rootView, "html5video,panning", callbackSmartCalculate, &ewkCallbackSmartCalculateRoot, this);
905                 addEwkCallback(m_rootView, "html5video,weakzoom", callbackSetZoomWeak, &ewkCallbackZoomWeakRoot, this);
906                 addEwkCallback(m_rootView, "html5video,zoom", callbackSetZoom, &ewkCallbackZoomRoot, this);
907             }
908         }
909 #endif
910         // always register for all media.
911         addEwkCallback(m_rootView, "html5video,pauseresume", callbackPauseOrResume, &ewkCallbackPauseOrResumeRoot, this);
912     }
913 }
914 #endif
915
916 void MediaPlayerPrivate::prepareToPlay()
917 {
918     LOG(Media, "%s\n", __func__);
919     if (m_delayingLoad) {
920         m_delayingLoad = false;
921         commitLoad();
922     }
923 }
924
925 void MediaPlayerPrivate::createWindow()
926 {
927     LOG(Media, "%s\n", __func__);
928 }
929
930 void MediaPlayerPrivate::play()
931 {
932     LOG(Media, "%s\n", __func__);
933
934 #if ENABLE(TIZEN_MM_PLAYER)
935     if (!m_url || m_url.length() <= 0)
936         return;
937 #if !ENABLE(TIZEN_WEBKIT2)
938     // in case of webkit2, can not get rootView. (currently ACCELERATED_COMPOSITING is disabled)
939     if (!m_rootView) {
940         LOG(Media, "%s() m_rootView is null.\n", __FUNCTION__);
941         setRootView();
942     }
943 #endif
944     if (hasVideo())
945         updateStates();
946
947     if (!m_isEmbedVideo && hasVideo()) {
948         if (m_startedPlaying) // prevent executing external video-player twice
949             return;
950
951         enterFullscreen();
952
953         m_startedPlaying = true;
954         return;
955     }
956
957     MMPlayerStateType state = MM_PLAYER_STATE_NONE;
958     int ret = MM_ERROR_NONE;
959     ret = mm_player_get_state(m_mmPlayerHandle, &state);
960     m_startedPlaying = true;
961     m_isEndReached = false;
962     if (ret !=MM_ERROR_NONE || state == MM_PLAYER_STATE_NULL || state == MM_PLAYER_STATE_NONE) {
963         /* create mm-player handle and set all attributes then  start video */
964         internalPlay();
965         return;
966     }
967     if (state == MM_PLAYER_STATE_PAUSED) {
968         m_playerStatus = MM_PLAYER_PAUSE;
969         if (!m_startCalled) { // mm_player_start required for the first time
970             LOG(Media, "%s() play!\n", __FUNCTION__);
971             mm_player_start(m_mmPlayerHandle);
972             m_startCalled = true;
973             return;
974         }
975         LOG(Media, "%s Try resume\n", __FUNCTION__);
976         if (mm_player_resume(m_mmPlayerHandle) != MM_ERROR_NONE) {
977             LOG(Media, "return error from mm_player_resume\n");
978             return;
979         }
980     }
981 #endif
982 }
983
984 void MediaPlayerPrivate::pause()
985 {
986     LOG(Media, "%s\n", __func__);
987  
988     m_startedPlaying = false;
989     
990     if (m_usingExternalPlayer)
991         return;
992
993 #if ENABLE(TIZEN_MM_PLAYER)
994     if (!m_mmPlayerHandle)
995         return;
996
997     LOG(Media, "url = %s\n", m_url.utf8().data());
998     MMPlayerStateType state;
999     if (mm_player_get_state(m_mmPlayerHandle, &state) != MM_ERROR_NONE)
1000         LOG(Media, "%s return error from mm_player_get_state\n", __FUNCTION__);
1001     if (state == MM_PLAYER_STATE_PLAYING) {
1002         if (mm_player_pause(m_mmPlayerHandle) != MM_ERROR_NONE)
1003             LOG(Media, "%s return error from mm_player_pause\n", __FUNCTION__);
1004     }
1005     m_startedPlaying = false;
1006 #endif
1007 }
1008
1009 float MediaPlayerPrivate::duration() const
1010 {
1011 //    LOG(Media, "%s\n", __func__);
1012
1013     if (m_usingExternalPlayer)
1014         return 10.0;
1015
1016 #if ENABLE(TIZEN_MM_PLAYER)
1017     if (m_mmPlayerHandle) {
1018         if (m_contentDuration > 0)
1019             return (float)m_contentDuration / 1000;
1020         char* pErrName = 0;
1021         if (mm_player_get_attribute(m_mmPlayerHandle, &pErrName,
1022                             MM_PLAYER_CONTENT_DURATION, &m_contentDuration, (void*)0) != MM_ERROR_NONE) {
1023             LOG(Media, "%s get duration error[%s]\n", __FUNCTION__, pErrName);
1024             free(pErrName);
1025             return 0.0;
1026         }
1027         return (float)m_contentDuration / 1000;
1028     }
1029     return 0.0;
1030 #endif
1031 }
1032
1033 float MediaPlayerPrivate::currentTime() const
1034 {
1035 //    LOG(Media, "%s\n", __func__);
1036
1037     if (m_usingExternalPlayer)
1038         return 0;
1039 #if ENABLE(TIZEN_MM_PLAYER)
1040     if (m_isEndReached && m_contentDuration > 0)
1041         return (float)m_contentDuration / 1000;
1042     if (m_mmPlayerHandle) {
1043         float ret;
1044         int seekPosition = 0;
1045         mm_player_get_position(m_mmPlayerHandle, MM_PLAYER_POS_FORMAT_TIME, &seekPosition);
1046         ret = (float)seekPosition / 1000;
1047         return ret;
1048     }
1049     return 0.0;
1050 #endif
1051 }
1052
1053 void MediaPlayerPrivate::seek(float time)
1054 {
1055     LOG(Media, "%s\n", __func__);
1056     if (time < 0.0)
1057         return;
1058 #if ENABLE(TIZEN_MM_PLAYER)
1059     if (/* time <= 0.0 || */ !duration())
1060         return;
1061     if (time != duration()) {
1062         LOG(Media, "%s() time != duration\n", __FUNCTION__);
1063         m_isEndReached = false;
1064     }
1065     if (m_mmPlayerHandle)
1066         mm_player_set_position(m_mmPlayerHandle, MM_PLAYER_POS_FORMAT_TIME, (int)(time*1000));
1067     // timeChanged should be needed to update the progress bar&current time after seeking.
1068     // To inform that the seeking is ended.
1069     timeChanged();
1070 #endif
1071 }
1072
1073 void MediaPlayerPrivate::setEndTime(float time)
1074 {
1075     LOG(Media, "%s\n", __func__);
1076 }
1077
1078 void MediaPlayerPrivate::startEndPointTimerIfNeeded()
1079 {
1080     LOG(Media, "%s\n", __func__);
1081     notImplemented();
1082 }
1083
1084 void MediaPlayerPrivate::cancelSeek()
1085 {
1086     LOG(Media, "%s\n", __func__);
1087     notImplemented();
1088 }
1089
1090 void MediaPlayerPrivate::endPointTimerFired(Timer<MediaPlayerPrivate>*)
1091 {
1092     LOG(Media, "%s\n", __func__);
1093     notImplemented();
1094 }
1095
1096 bool MediaPlayerPrivate::paused() const
1097 {
1098     LOG(Media, "%s\n", __func__);
1099 #if ENABLE(TIZEN_MM_PLAYER)
1100     if (!m_url || m_url.length() <= 0)
1101         return true;
1102     if (hasVideo() && !m_isEmbedVideo && m_startedPlaying) // only for external video
1103         return false;
1104     if (!m_mmPlayerHandle)
1105         return true;
1106     MMPlayerStateType state;
1107     if (mm_player_get_state(m_mmPlayerHandle, &state) != MM_ERROR_NONE) {
1108         LOG(Media, "%s fail mm_player_get_state\n", __FUNCTION__);
1109         return false;
1110     }
1111     if (state == MM_PLAYER_STATE_PAUSED) {
1112         LOG(Media, "MM_PLAYER_STATE_PAUSED\n");
1113         return true;
1114     }
1115     if (state == MM_PLAYER_STATE_NULL) {
1116         LOG(Media, "MM_PLAYER_STATE_NULL\n");
1117         return false;
1118     }
1119     if (state == MM_PLAYER_STATE_NONE) {
1120         LOG(Media, "MM_PLAYER_STATE_NONE\n");
1121         return false;
1122     }
1123     if (state == MM_PLAYER_STATE_PLAYING) {
1124         LOG(Media, "MM_PLAYER_STATE_PLAYING\n");
1125         return false;
1126     }
1127     if (state == MM_PLAYER_STATE_READY) {
1128         LOG(Media, "MM_PLAYER_STATE_READY\n");
1129         return true;
1130     }
1131     LOG(Media, "m_playerStatus %d\n", (int)m_playerStatus);
1132
1133     if (m_playerStatus == MM_PLAYER_PLAY) {
1134         LOG(Media, "MM_PLAYER_PLAY\n");
1135         return false;
1136     }
1137     if (m_playerStatus == MM_PLAYER_PAUSE) {
1138         LOG(Media, "MM_PLAYER_PAUSE\n");
1139         return true;
1140     }
1141     if (m_playerStatus == MM_PLAYER_STOP) {
1142         LOG(Media, "MM_PLAYER_STOP\n");
1143         return true;
1144     }
1145     LOG(Media, "return TRUE\n");
1146     return true;
1147 #endif
1148
1149     return !m_startedPlaying;
1150 }
1151
1152 bool MediaPlayerPrivate::seeking() const
1153 {
1154     LOG(Media, "%s\n", __func__);
1155     return false;
1156 }
1157
1158 // Returns the size of the video
1159 IntSize MediaPlayerPrivate::naturalSize() const
1160 {
1161 //    LOG(Media, "%s\n", __func__);
1162 #if ENABLE(TIZEN_MM_PLAYER)
1163     if (!hasVideo()) /* it mean Only Audio */
1164         return IntSize(0, 0);
1165     if (!m_size.isEmpty())
1166         return m_size;
1167 #endif
1168     return IntSize(240, 180);
1169 //    return IntSize(320, 240);
1170 }
1171
1172 bool MediaPlayerPrivate::hasVideo() const
1173 {
1174 //    LOG(Media, "%s\n", __func__);
1175 #if ENABLE(TIZEN_MM_PLAYER)
1176     HTMLMediaElement* mediaElement = static_cast<HTMLMediaElement*>(m_player->mediaPlayerClient());
1177     if (!mediaElement)
1178         return false;
1179     if (mediaElement->hasTagName(HTMLNames::videoTag))
1180         return true;
1181     if (mediaElement->hasTagName(HTMLNames::audioTag))
1182         return false;
1183 #endif
1184     return true;
1185 }
1186
1187 bool MediaPlayerPrivate::hasAudio() const 
1188 {
1189 //    LOG(Media, "%s\n", __func__);
1190     return true;
1191 }
1192
1193 void MediaPlayerPrivate::setVolume(float volume)
1194 {
1195     LOG(Media, "%s\n", __func__);
1196     m_volume = volume;
1197     LOG_VERBOSE(Media, "Volume to %f", volume);
1198
1199 #if ENABLE(TIZEN_MM_PLAYER)
1200     MMPlayerVolumeType volInfo;
1201     memset(&volInfo, 0, sizeof(MMPlayerVolumeType));
1202     for (int nCount = 0; nCount < MM_CHANNEL_NUM; nCount++)
1203         volInfo.level[nCount] = volume;
1204     if (m_mmPlayerHandle) {
1205         if (mm_player_set_volume(m_mmPlayerHandle, &volInfo) != MM_ERROR_NONE) {
1206             LOG(Media, "%s fail mm_player_set_volume\n", __FUNCTION__);
1207             return;
1208         }
1209     }
1210     return;
1211 #endif
1212     setMuted(false);
1213 }
1214
1215 void MediaPlayerPrivate::setMuted(bool b)
1216 {
1217     LOG(Media, "%s\n", __func__);
1218
1219 #if ENABLE(TIZEN_MM_PLAYER)
1220     if (m_mmPlayerHandle) {
1221         if (mm_player_set_mute(m_mmPlayerHandle, (int)b) != MM_ERROR_NONE)
1222                 LOG(Media, "%s fail mm_player_set_mute \n", __FUNCTION__);
1223     }
1224     return;
1225 #endif
1226     notImplemented();
1227 }
1228
1229 void MediaPlayerPrivate::volumeChanged()
1230 {
1231     LOG(Media, "%s\n", __func__);
1232     notImplemented();
1233 }
1234
1235 void MediaPlayerPrivate::setRate(float rate)
1236 {
1237     LOG(Media, "%s\n", __func__);
1238 #if ENABLE(TIZEN_MM_PLAYER) // not support Rate yet
1239     LOG(Media, "%s rate = %f\n", __FUNCTION__, rate);
1240     m_rate = rate;
1241     return;
1242 #endif
1243     notImplemented();
1244 }
1245
1246 int MediaPlayerPrivate::dataRate() const
1247 {
1248     notImplemented();
1249     return 1;
1250 }
1251
1252 MediaPlayer::NetworkState MediaPlayerPrivate::networkState() const
1253 {
1254     LOG(Media, "%s\n", __func__);
1255     return m_networkState;
1256 }
1257
1258 MediaPlayer::ReadyState MediaPlayerPrivate::readyState() const
1259 {
1260     LOG(Media, "%s\n", __func__);
1261     return m_readyState;
1262 }
1263
1264 PassRefPtr<TimeRanges> MediaPlayerPrivate::buffered() const
1265 {
1266     RefPtr<TimeRanges> timeRanges = TimeRanges::create();
1267     float loaded = maxTimeLoaded();
1268     if (!m_errorOccured && !m_isStreaming && loaded > 0)
1269         timeRanges->add(0, loaded);
1270     return timeRanges.release();
1271 }
1272
1273 float MediaPlayerPrivate::maxTimeBuffered() const
1274 {
1275     notImplemented();
1276 //    LOG_VERBOSE(Media, "maxTimeBuffered");
1277     // rtsp streams are not buffered
1278     return m_isStreaming ? 0 : maxTimeLoaded();
1279 }
1280
1281 float MediaPlayerPrivate::maxTimeSeekable() const
1282 {
1283 //    LOG_VERBOSE(Media, "maxTimeSeekable");
1284     if (m_isStreaming)
1285         return numeric_limits<float>::infinity();
1286     // infinite duration means live stream
1287     return maxTimeLoaded();
1288 }
1289
1290 float MediaPlayerPrivate::maxTimeLoaded() const
1291 {
1292     // TODO
1293 //    LOG_VERBOSE(Media, "maxTimeLoaded");
1294 #if ENABLE(TIZEN_MM_PLAYER)
1295     if (!m_mmPlayerHandle)
1296         return 0.0;
1297
1298     // can not get buffering position in case of local file
1299     if (m_url.contains("file://"))
1300         return duration();
1301
1302     int startPos = 0, stopPos = 0;
1303     mm_player_get_buffer_position(m_mmPlayerHandle, MM_PLAYER_POS_FORMAT_PERCENT, &startPos, &stopPos);
1304     return duration() * (stopPos / 100.0);
1305 #else
1306     notImplemented();
1307     return duration();
1308 #endif
1309 }
1310
1311 unsigned MediaPlayerPrivate::bytesLoaded() const
1312 {
1313     notImplemented();
1314 //    LOG_VERBOSE(Media, "bytesLoaded");
1315     return 1; // totalBytes() * maxTime / dur;
1316 }
1317
1318 bool MediaPlayerPrivate::totalBytesKnown() const
1319 {
1320     LOG(Media, "%s\n", __func__);
1321     notImplemented();
1322     LOG_VERBOSE(Media, "totalBytesKnown");
1323     return totalBytes() > 0;
1324 }
1325
1326 unsigned MediaPlayerPrivate::totalBytes() const
1327 {
1328     LOG(Media, "%s\n", __func__);
1329     notImplemented();
1330     LOG_VERBOSE(Media, "totalBytes");
1331     return 1;
1332 }
1333
1334 void MediaPlayerPrivate::cancelLoad()
1335 {
1336     LOG(Media, "%s\n", __func__);
1337 #if ENABLE(TIZEN_MM_PLAYER)
1338     stop();
1339 #endif
1340     notImplemented();
1341 }
1342
1343 void MediaPlayerPrivate::updateStates()
1344 {
1345     LOG(Media, "%s\n", __func__);
1346     
1347     if (m_usingExternalPlayer) {
1348         m_player->networkStateChanged();
1349         m_readyState = MediaPlayer::HaveEnoughData;
1350         m_player->readyStateChanged();
1351         return;
1352     }
1353
1354     MediaPlayer::NetworkState oldNetworkState = m_networkState;
1355     MediaPlayer::ReadyState oldReadyState = m_readyState;
1356
1357     m_readyState = MediaPlayer::HaveEnoughData;
1358     m_networkState = MediaPlayer::Loaded;
1359
1360     if (m_networkState != oldNetworkState) {
1361        LOG_VERBOSE(Media, "Network State Changed from %u to %u",
1362        oldNetworkState, m_networkState);
1363        m_player->networkStateChanged();
1364     }
1365
1366     if (m_readyState != oldReadyState) {
1367         LOG_VERBOSE(Media, "Ready State Changed from %u to %u",
1368         oldReadyState, m_readyState);
1369         m_player->readyStateChanged();
1370     }
1371 }
1372
1373 void MediaPlayerPrivate::loadStateChanged()
1374 {
1375     LOG(Media, "%s\n", __func__);
1376     updateStates();
1377 }
1378
1379 void MediaPlayerPrivate::rateChanged()
1380 {
1381     LOG(Media, "%s\n", __func__);
1382     updateStates();
1383 }
1384
1385 void MediaPlayerPrivate::sizeChanged()
1386 {
1387     LOG(Media, "%s\n", __func__);
1388     notImplemented();
1389 }
1390
1391 void MediaPlayerPrivate::timeChanged()
1392 {
1393     LOG(Media, "%s\n", __func__);
1394     m_player->timeChanged();
1395 }
1396
1397 void MediaPlayerPrivate::didEnd()
1398 {
1399     LOG(Media, "%s\n", __func__);
1400
1401     m_isEndReached = true;
1402     pause();
1403     timeChanged();
1404 }
1405
1406 void MediaPlayerPrivate::loadingFailed()
1407 {
1408     LOG(Media, "%s\n", __func__);
1409
1410     if (m_networkState != MediaPlayer::NetworkError) {
1411         m_networkState = MediaPlayer::NetworkError;
1412         m_player->networkStateChanged();
1413     }
1414     if (m_readyState != MediaPlayer::HaveNothing) {
1415         m_readyState = MediaPlayer::HaveNothing;
1416         m_player->readyStateChanged();
1417     }
1418 #if ENABLE(TIZEN_MM_PLAYER)
1419     stop();
1420 #endif
1421 }
1422
1423 void MediaPlayerPrivate::setSize(const IntSize& size)
1424 {
1425     m_size = size;
1426 }
1427
1428 void MediaPlayerPrivate::setVisible(bool visible)
1429
1430     m_visible = visible;
1431
1432 #if ENABLE(TIZEN_MM_PLAYER)
1433 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
1434     if (!m_isEmbedVideo)
1435         return;
1436
1437     if (!m_visible) {
1438         LOG(Media, "%s() hide embed icons\n", __FUNCTION__);
1439         hideEmbedPlayIcon();
1440         hideEmbedLoadingIcon();
1441     } else {
1442         if (getStatus() != MM_PLAYER_PLAY) {
1443             LOG(Media, "%s() show play icon\n", __FUNCTION__);
1444             showEmbedPlayIcon();
1445         }
1446     }
1447 #endif
1448 #endif
1449 }
1450
1451 void MediaPlayerPrivate::repaint()
1452 {
1453 //    LOG(Media, "%s\n", __func__);
1454 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
1455 #if !USE(TIZEN_TEXTURE_MAPPER)
1456     if (hasVideo() && m_platformLayer && supportsAcceleratedRendering())
1457         m_platformLayer->setNeedsDisplayInRect(FloatRect(0, 0, m_contentWidth, m_contentHeight));
1458 #else
1459 #if ENABLE(TIZEN_WEBKIT2)
1460     if (hasVideo() && supportsAcceleratedRendering())
1461         m_platformLayer->setContentsToMedia(this);
1462 #endif
1463 #endif
1464 #endif
1465     m_player->repaint();
1466 }
1467
1468 void MediaPlayerPrivate::paint(GraphicsContext* context, const IntRect& rect)
1469 {
1470 //    LOG(Media, "%s\n", __func__);
1471 //    LOG(Media, "rect(%d, %d, %d, %d)\n", rect.x(), rect.y(), rect.width(), rect.height());
1472
1473     if (context->paintingDisabled()) {
1474         LOG(Media, "disabled\n");
1475         return;
1476     }
1477
1478 #if ENABLE(TIZEN_WAC_CAMERA_SUPPORT)
1479
1480     HTMLMediaElement* mediaElement = static_cast<HTMLMediaElement*>(m_player->mediaPlayerClient());
1481     CameraManager* cameramManager = 0;
1482
1483     if (mediaElement && mediaElement->getCamera()) {
1484         cameramManager = mediaElement->getCamera();
1485
1486         if (!cameramManager->getStreamBuffer())
1487              return;
1488
1489         int stride = 0;
1490         cairo_surface_t* surface;
1491         cairo_format_t cairoFormat = CAIRO_FORMAT_ARGB32;
1492
1493         stride = cairo_format_stride_for_width(cairoFormat, cameramManager->getWidth());
1494         surface = cairo_image_surface_create_for_data(cameramManager->getStreamBuffer(), CAIRO_FORMAT_ARGB32,
1495                                                       cameramManager->getWidth(), cameramManager->getHeight(),
1496                                                       stride);
1497
1498         if (cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) {
1499             LOG(Media, "%s : Error cairo_surface_status\n", __FUNCTION__);
1500             return;
1501         }
1502
1503         int posX = 0;
1504         int posY = 0;
1505         int widthForDisplay = 0;
1506         int heightForDisplay = 0;
1507
1508         widthForDisplay = rect.width();
1509         heightForDisplay = cameramManager->getHeight() * rect.width() / cameramManager->getWidth();
1510
1511         if (heightForDisplay > rect.height()) {
1512             widthForDisplay = widthForDisplay * rect.height() / heightForDisplay;
1513             heightForDisplay = rect.height();
1514         }
1515
1516         posX = rect.x() + (rect.width() - widthForDisplay) / 2;
1517         posY = rect.y() + (rect.height() - heightForDisplay) / 2;
1518
1519         cairo_t* cr = context->platformContext()->cr();
1520         cairo_save(cr);
1521         cairo_translate(cr, posX, posY);
1522         cairo_rectangle(cr, 0, 0, cameramManager->getWidth(), cameramManager->getHeight());
1523         cairo_fill(cr);
1524         int scaleFactorX = 0;
1525         int scaleFactorY = 0;
1526         scaleFactorX = widthForDisplay * 100 / cameramManager->getWidth();
1527         scaleFactorY = heightForDisplay * 100 / cameramManager->getHeight();
1528         cairo_scale(cr, static_cast<double>(scaleFactorX) / 100, static_cast<double>(scaleFactorY) / 100);
1529         cairo_set_source_surface(cr, surface, 0, 0);
1530         cairo_paint(cr);
1531         cairo_restore(cr);
1532         cairo_surface_destroy(surface);
1533         return;
1534     }
1535 #endif
1536
1537     if (!m_player->visible())
1538         return;
1539
1540 #if ENABLE(TIZEN_MM_PLAYER)
1541     m_frame = rect;
1542     repaintVideoCanvas();
1543
1544     if (!m_isEmbedVideo && hasVideo()) {
1545         if (!m_bufferingProgressbar) { // Black screen & Play Icon
1546             cairo_t* cr = context->platformContext()->cr();
1547             cairo_surface_t* btImage;
1548             btImage = cairo_image_surface_create_from_png(HTML5_VIDEO_PLAY_ICON);
1549             double btWidth = cairo_image_surface_get_width(btImage);
1550             double btHeight = cairo_image_surface_get_height(btImage);
1551             double x = (rect.width() - btWidth) / 2.0;
1552             double y = (rect.height() - btHeight) / 2.0;
1553
1554             cairo_save(cr);
1555             cairo_translate(cr, rect.x(), rect.y());
1556             cairo_rectangle(cr, 0, 0, rect.width(), rect.height());
1557             cairo_set_source_rgb(cr, (double)0.0, (double)0.0, (double)0.0);
1558             cairo_fill(cr);
1559             cairo_set_source_surface(cr, btImage, x, y);
1560             cairo_paint(cr);
1561             cairo_restore(cr);
1562             cairo_surface_destroy(btImage);
1563         } else {
1564             /* black screen  */
1565             cairo_t* cr = context->platformContext()->cr();
1566             cairo_save(cr);
1567             cairo_rectangle(cr, rect.x(), rect.y(), rect.width(), rect.height());
1568             cairo_set_source_rgb(cr, (double)0.0, (double)0.0, (double)0.0);
1569             cairo_fill(cr);
1570             cairo_restore(cr);
1571         }
1572     }
1573 #endif
1574 }
1575
1576 static HashSet<String> mimeTypeCache()
1577 {
1578     LOG(Media, "%s\n", __func__);
1579     static HashSet<String> cache;
1580     static bool typeListInitialized = false;
1581
1582     if (!typeListInitialized) {
1583         cache.add(String("video/mp4"));
1584         cache.add(String("audio/aac"));
1585         cache.add(String("video/ogg"));
1586         cache.add(String("audio/ogg"));
1587         cache.add(String("audio/wav"));
1588         cache.add(String("audio/mpeg"));
1589         cache.add(String("audio/mp3"));
1590 #if ENABLE(TIZEN_MM_PLAYER)
1591         cache.add(String("audio/3gpp"));
1592         cache.add(String("audio/3gpp2"));
1593         cache.add(String("audio/mp4"));
1594         cache.add(String("audio/x-midi"));
1595         cache.add(String("audio/x-mpeg"));
1596         cache.add(String("audio/x-ogg"));
1597         cache.add(String("audio/x-vorbis"));
1598         cache.add(String("audio/x-vorbis+ogg"));
1599         cache.add(String("audio/x-wav"));
1600         cache.add(String("video/m4v"));
1601         cache.add(String("video/mpeg"));
1602         cache.add(String("video/x-m4v"));
1603         cache.add(String("video/x-ogg"));
1604         cache.add(String("video/x-theora"));
1605         cache.add(String("video/x-theora+ogg"));
1606         cache.add(String("video/webm"));
1607         cache.add(String("audio/webm"));
1608 #endif
1609     }
1610
1611     return cache;
1612 }
1613
1614 void MediaPlayerPrivate::getSupportedTypes(HashSet<String>& types)
1615 {
1616     LOG(Media, "%s\n", __func__);
1617     types = mimeTypeCache();
1618 }
1619
1620 MediaPlayer::SupportsType MediaPlayerPrivate::supportsType(const String& type, const String& codecs)
1621 {
1622     LOG(Media, "%s\n", __func__);
1623     if (type.isNull() || type.isEmpty())
1624         return MediaPlayer::IsNotSupported;
1625 #if ENABLE(TIZEN_MM_PLAYER)
1626     LOG(Media, "%s MediaPlayerPrivate::supportsType() ! : type: %s codecs: %s\n", __FUNCTION__,
1627                                                         type.utf8().data(), codecs.utf8().data());
1628 #endif
1629     // spec says we should not return "probably" if the codecs string is empty
1630     if (mimeTypeCache().contains(type))
1631         return codecs.isEmpty() ? MediaPlayer::MayBeSupported : MediaPlayer::IsSupported;
1632     return MediaPlayer::IsNotSupported;
1633 }
1634
1635 bool MediaPlayerPrivate::supportsFullscreen() const
1636 {
1637     LOG(Media, "%s\n", __func__);
1638 #if ENABLE(TIZEN_MM_PLAYER)
1639     if (hasVideo())
1640         return true;
1641     return false;
1642 #endif
1643     return true;
1644 }
1645
1646 #if ENABLE(TIZEN_MM_PLAYER)
1647
1648 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
1649 #if USE(TIZEN_TEXTURE_MAPPER)
1650 void MediaPlayerPrivate::paintToTextureMapper(TextureMapper* textureMapper, const FloatRect& targetRect, const TransformationMatrix& matrix, float opacity, BitmapTexture* mask) const
1651 {
1652     IntSize contentSize(m_contentWidth, m_contentHeight);
1653
1654     if (!m_videoTexture)
1655         m_videoTexture = textureMapper->createTexture();
1656
1657     if (m_textureSize != contentSize) {
1658         m_textureSize.setWidth(m_contentWidth);
1659         m_textureSize.setHeight(m_contentHeight);
1660         m_videoTexture->reset(m_textureSize, false);
1661     }
1662
1663     if (m_needsUpdate) {
1664         IntRect target(0, 0, m_textureSize.width(), m_textureSize.height());
1665         m_videoTexture->updateContents(BitmapTexture::BGRAFormat, target, m_frameBuffer);
1666         m_needsUpdate = false;
1667     }
1668
1669     TextureMapperGL* texmapGL = static_cast<TextureMapperGL*>(textureMapper);
1670     texmapGL->drawTexture(*m_videoTexture.get(), targetRect, matrix, opacity, mask);
1671 }
1672
1673 PlatformLayer* MediaPlayerPrivate::platformLayer() const
1674 {
1675     return const_cast<MediaPlayerPrivate*>(this);
1676 }
1677 #else
1678 bool MediaPlayerPrivate::supportsAcceleratedRendering() const
1679 {
1680     return true;
1681 }
1682
1683 void MediaPlayerPrivate::acceleratedRenderingStateChanged()
1684 {
1685     if (!m_player)
1686         return;
1687
1688     MediaPlayerClient* client = m_player->mediaPlayerClient();
1689     if (!client)
1690         return;
1691
1692     bool composited = client->mediaPlayerRenderingCanBeAccelerated(m_player);
1693     if (composited == m_acceleratedCompositing)
1694         return;
1695
1696     m_acceleratedCompositing = composited;
1697     if (m_acceleratedCompositing && !m_platformLayer.get()) {
1698         LOG(AcceleratedCompositing, "[%p] MediaPlayerPrivate::%s()\n", this, __func__);
1699         m_platformLayer = EflLayer::create(0);
1700         m_platformLayer->setContentsToVideo(this);
1701     }
1702 }
1703
1704 PlatformLayer* MediaPlayerPrivate::platformLayer() const
1705 {
1706     return m_acceleratedCompositing ? m_platformLayer.get() : 0;
1707 }
1708 #endif // USE(TIZEN_TEXTURE_MAPPER)
1709
1710 void MediaPlayerPrivate::setVideoRect()
1711 {
1712     HTMLMediaElement* mediaElement = static_cast<HTMLMediaElement*>(m_player->mediaPlayerClient());
1713     if (!mediaElement || !mediaElement->renderer())
1714         return;
1715
1716     RenderBox* renderer = toRenderBox(mediaElement->renderer());
1717     if (!renderer)
1718         return;
1719
1720     int x = renderer->offsetLeft();
1721     int y = renderer->offsetTop();
1722     int w = renderer->offsetWidth();
1723     int h = renderer->offsetHeight();
1724
1725     m_frame.setX(x);
1726     m_frame.setY(y);
1727     m_frame.setWidth(w);
1728     m_frame.setHeight(h);
1729 }
1730
1731 void MediaPlayerPrivate::fillVideoRect()
1732 {
1733     LOG(Media, "%s()\n", __FUNCTION__);
1734
1735     if (m_frameBuffer)
1736         return;
1737
1738     // make minunum buffer to fill video rect black
1739     m_contentWidth = 2;
1740     m_contentHeight = 2;
1741     int bufLength = m_contentWidth * m_contentHeight * 4;
1742     m_frameBuffer = (unsigned char*)malloc(bufLength);
1743     if (!m_frameBuffer) {
1744         LOG(Media, "%s(): malloc fail\n", __FUNCTION__);
1745         return;
1746     }
1747     memset(m_frameBuffer, 0, bufLength);
1748     setNeedsUpdate(true);
1749     repaint();
1750
1751     showEmbedPlayIcon();
1752 }
1753
1754 void MediaPlayerPrivate::showEmbedPlayIcon()
1755 {
1756     LOG(Media, "%s()\n", __FUNCTION__);
1757
1758     if (!m_player || !m_player->frameView() || !m_rootView)
1759         return;
1760     if (!m_isEmbedVideo || !hasVideo())
1761         return;
1762     if (m_bufferingProgressbar || m_bufferingProgressbarBg)
1763         return;
1764
1765     setVideoRect();
1766     if (m_frame.location() == IntPoint(0, 0)) {
1767         LOG(Media, "%s() m_frame.location() is not set yet.\n", __FUNCTION__);
1768         return;
1769     }
1770
1771     if (!m_playIcon) {
1772         m_playIcon = evas_object_image_add(evas_object_evas_get(m_rootView));
1773         evas_object_smart_member_add(m_playIcon, m_rootView);
1774         evas_object_image_file_set(m_playIcon, HTML5_VIDEO_PLAY_ICON, 0);
1775         evas_object_resize(m_playIcon, EVAS_ICON_SIZE, EVAS_ICON_SIZE);
1776         evas_object_image_fill_set(m_playIcon, 0, 0, EVAS_ICON_SIZE, EVAS_ICON_SIZE);
1777     }
1778
1779     IntRect rect = m_player->frameView()->contentsToScreen(m_frame);
1780     Evas_Coord x, y;
1781     evas_object_geometry_get(m_rootView, &x, &y, 0, 0);
1782     rect.move(x, y);
1783
1784     int iconX = rect.x() + (rect.width() - EVAS_ICON_SIZE) / 2;
1785     int iconY = rect.y() + (rect.height() - EVAS_ICON_SIZE) / 2;
1786     evas_object_move(m_playIcon, iconX, iconY);
1787     evas_object_show(m_playIcon);
1788 }
1789
1790 void MediaPlayerPrivate::hideEmbedPlayIcon()
1791 {
1792     if (m_playIcon) {
1793         evas_object_smart_member_del(m_playIcon);
1794         evas_object_hide(m_playIcon);
1795         evas_object_del(m_playIcon);
1796         m_playIcon = 0;
1797     }
1798 }
1799 #endif
1800
1801 void MediaPlayerPrivate::internalPlay()
1802 {
1803     LOG(Media, "%s\n", __func__);
1804
1805     m_playerStatus = MM_PLAYER_STOP;
1806
1807     if (hasVideo() && m_isEmbedVideo) {
1808         if (gPlayer && gPlayer != this) {
1809             LOG(Media, "%s(): destroy gPlayer %p\n", __FUNCTION__, gPlayer);
1810             gPlayer->setStatus(MM_PLAYER_STOP);
1811             gPlayer->destroyEmbedPlayer();
1812         }
1813         gPlayer = this;
1814         LOG(Media, "%s(): gPlayer = %p\n", __FUNCTION__, gPlayer);
1815     }
1816
1817     if (!hasVideo())
1818         addAudioHandle(this);
1819
1820     m_startCalled = false;
1821
1822     if (!m_mmPlayerHandle) {
1823         if (mm_player_create(&m_mmPlayerHandle) != MM_ERROR_NONE) {
1824             LOG(Media, "%s return error from mm_player_create\n", __FUNCTION__);
1825             return;
1826         }
1827     }
1828     mm_session_init(MM_SESSION_TYPE_SHARE);
1829
1830     initializeVideoPlayer();
1831     if (mm_player_realize(m_mmPlayerHandle) != MM_ERROR_NONE) {
1832         LOG(Media, "%s return error from mm_player_realize\n", __FUNCTION__);
1833         return;
1834     }
1835
1836     if (m_readyState == MediaPlayer::HaveEnoughData) { // video played more than once
1837         if (mm_player_start(m_mmPlayerHandle) != MM_ERROR_NONE) {
1838             LOG(Media, "%s return error from mm_player_start\n", __FUNCTION__);
1839             return;
1840         }
1841         m_startCalled = true;
1842     } else {
1843         // explicit load operation for audio and embedded video
1844         if (mm_player_pause(m_mmPlayerHandle) != MM_ERROR_NONE) {
1845             LOG(Media, "%s return error from mm_player_pause\n", __FUNCTION__);
1846             return;
1847         }
1848     }
1849
1850     // set initial volume & loop
1851     HTMLMediaElement* mediaElement = static_cast<HTMLMediaElement*>(m_player->mediaPlayerClient());
1852     if (mediaElement) {
1853         setVolume(mediaElement->volume());
1854         if (mediaElement->loop()) {
1855             char* pErrName = 0;
1856             int err = MM_ERROR_NONE;
1857             
1858             err = mm_player_set_attribute(m_mmPlayerHandle, &pErrName, "profile_play_count", -1, (void*)0);
1859             if (err != MM_ERROR_NONE) {
1860                 LOG(Media, "%s failed mm_player_set_attribute\n", __FUNCTION__);
1861                 if (pErrName)
1862                     free(pErrName);
1863             }
1864         }
1865     }
1866
1867     if (hasVideo())
1868         showEmbedLoadingIcon();
1869 }
1870
1871 void MediaPlayerPrivate::catchMouseDown()
1872 {
1873     LOG(Media, "%s\n", __func__);
1874     if (m_isEmbedVideo) {
1875         if (m_embedVideoLongpressTimer > 0)
1876             ecore_timer_del(m_embedVideoLongpressTimer);
1877         m_embedVideoLongpressTimer = ecore_timer_add(2.0, timerCatchLongPressEvent, this);
1878     }
1879 }
1880
1881 void MediaPlayerPrivate::catchMouseUp()
1882 {
1883     LOG(Media, "%s\n", __func__);
1884     if (m_isEmbedVideo) {
1885         if (m_embedVideoLongpressTimer > 0)
1886             ecore_timer_del(m_embedVideoLongpressTimer);
1887         m_embedVideoLongpressTimer = 0;
1888     }
1889 }
1890
1891 void MediaPlayerPrivate::videoUpdateStart()
1892 {
1893     LOG(Media, "%s\n", __func__);
1894     if (!hasVideo())
1895         return; /* use video update timer when only video element. */
1896     if (!m_mmPlayerHandle) {
1897         videoUpdateStop();
1898         return;
1899     }
1900     if (m_embedVideoUpdateTimer > 0)
1901          ecore_timer_thaw(m_embedVideoUpdateTimer);
1902     else
1903         m_embedVideoUpdateTimer = ecore_timer_add(VIDEO_FPS, timerEmbedInvalidateRect, this);
1904 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
1905     hideEmbedPlayIcon();
1906 #endif
1907 }
1908
1909 void MediaPlayerPrivate::videoUpdatePause()
1910 {
1911     LOG(Media, "%s\n", __func__);
1912     if (m_embedVideoUpdateTimer > 0)
1913          ecore_timer_freeze(m_embedVideoUpdateTimer);
1914 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
1915     if (!m_startedPlaying && m_startCalled)
1916         showEmbedPlayIcon();
1917 #endif
1918 }
1919
1920 void MediaPlayerPrivate::videoUpdateStop()
1921 {
1922     LOG(Media, "%s\n", __func__);
1923     if (m_embedVideoUpdateTimer > 0) {
1924         ecore_timer_del(m_embedVideoUpdateTimer);
1925         m_embedVideoUpdateTimer = 0;
1926     }
1927 }
1928
1929 void MediaPlayerPrivate::enterFullscreen()
1930 {
1931     LOG(Media, "%s\n", __func__);
1932
1933     if (gPlayer) {
1934         LOG(Media, "%s(): destroy gPlayer %p\n", __FUNCTION__, gPlayer);
1935         gPlayer->setStatus(MM_PLAYER_STOP);
1936         gPlayer->didEnd();
1937         gPlayer->stopInternal(true);
1938     }
1939     gPlayer = 0;
1940
1941     struct _HTML5Video html5video;
1942
1943     html5video.path = (char*)malloc(m_url.utf8().length() + 1);
1944     if (!html5video.path) {
1945         LOG(Media, "%s() malloc fail!\n", __FUNCTION__);
1946         return;
1947     }
1948     memcpy(html5video.path, m_url.utf8().data(), m_url.utf8().length() + 1);
1949
1950     SoupSession* session = ResourceHandle::defaultSession();
1951     SoupCookieJar* cookieJar = SOUP_COOKIE_JAR(soup_session_get_feature(session, SOUP_TYPE_COOKIE_JAR));
1952     SoupURI* uri = soup_uri_new(m_url.utf8().data());
1953     EINA_SAFETY_ON_NULL_RETURN(uri);
1954     html5video.cookie = soup_cookie_jar_get_cookies(cookieJar, uri, FALSE);
1955
1956 #if !ENABLE(TIZEN_WEBKIT2)
1957     // webkit1: use evas callback call
1958     evas_object_smart_callback_call(m_rootView, "html5video,request", &html5video);
1959 #else
1960     // webkit2: use webkit2 callback
1961     m_player->frameView()->frame()->loader()->client()->postProcessHTML5Video(m_url, String(html5video.cookie));
1962 #endif
1963
1964     free(html5video.path);
1965     soup_uri_free(uri);
1966     if (html5video.cookie)
1967         g_free(html5video.cookie);
1968 }
1969
1970 void MediaPlayerPrivate::exitFullscreen()
1971 {
1972     LOG(Media, "%s\n", __func__);
1973 }
1974
1975 bool MediaPlayerPrivate::setContentSize(IntSize sizeContent)
1976 {
1977     char* pErrName = 0;
1978     int err = MM_ERROR_NONE;
1979
1980     if (!m_mmPlayerHandle)
1981         return false;
1982
1983 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
1984     setNeedsUpdate(false);
1985 #endif
1986
1987     int width = sizeContent.width();
1988     int height = sizeContent.height();
1989
1990     if (width > MAX_VIDEO_SIZE) {
1991         height = MAX_VIDEO_SIZE * height / width;
1992         width = MAX_VIDEO_SIZE;
1993     }
1994     if (height > MAX_VIDEO_SIZE) {
1995         width = MAX_VIDEO_SIZE * width / height;
1996         height = MAX_VIDEO_SIZE;
1997     }
1998
1999     width =  MM_PLAY_GET_HEXADECIMAL(width);
2000     height =  MM_PLAY_GET_HEXADECIMAL(height);
2001     LOG(Media, "%s(): content_size: %d, %d\n", __FUNCTION__, width, height);
2002
2003     err = mm_player_set_attribute(m_mmPlayerHandle, &pErrName,
2004                                     "display_width", width,
2005                                     "display_height", height,
2006                                     (void*)0);
2007     if (err != MM_ERROR_NONE) {
2008         LOG(Media, "%s failed mm_player_set_attribute\n", __FUNCTION__);
2009         if (pErrName)
2010             free(pErrName);
2011         return false;
2012     }
2013
2014     return true;
2015 }
2016
2017 void MediaPlayerPrivate::setVideoBuffer(IntSize sizeBuffer)
2018 {
2019     LOG(Media, "%s() %d, %d\n", __FUNCTION__, sizeBuffer.width(), sizeBuffer.height());
2020
2021 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
2022     setNeedsUpdate(false);
2023 #endif
2024
2025     if (m_frameBuffer) {
2026         free(m_frameBuffer);
2027         m_frameBuffer = 0;
2028     }
2029
2030     m_contentWidth = sizeBuffer.width();
2031     m_contentHeight = sizeBuffer.height();
2032
2033     m_frameBuffer = (unsigned char*)malloc(m_contentWidth * m_contentHeight * 4);
2034     if (!m_frameBuffer) {
2035         LOG(Media, "%s(): m_frameBuffer malloc fail!!\n", __FUNCTION__);
2036         return;
2037     }
2038     memset(m_frameBuffer, 0, m_contentWidth * m_contentHeight * 4);
2039 }
2040
2041 void MediaPlayerPrivate::stop()
2042 {
2043     LOG(Media, "%s url = %s\n", __FUNCTION__, m_url.utf8().data());
2044     setStatus(MM_PLAYER_STOP);
2045     videoUpdateStop();
2046     hideEmbedLoadingIcon();
2047 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
2048     hideEmbedPlayIcon();
2049 #endif
2050     if (m_rootView) {
2051         LOG(Media, "%s() evas_object_smart_callback_del()\n", __FUNCTION__);
2052 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
2053         if (ewkCallbackSmartCalculateRoot)
2054             delEwkCallback(m_rootView, "html5video,panning", callbackSmartCalculate, &ewkCallbackSmartCalculateRoot, this);
2055         if (ewkCallbackZoomWeakRoot)
2056             delEwkCallback(m_rootView, "html5video,weakzoom", callbackSetZoomWeak, &ewkCallbackZoomWeakRoot, this);
2057         if (ewkCallbackZoomRoot)
2058             delEwkCallback(m_rootView, "html5video,zoom", callbackSetZoom, &ewkCallbackZoomRoot, this);
2059 #endif
2060         if (ewkCallbackPauseOrResumeRoot)
2061             delEwkCallback(m_rootView, "html5video,pauseresume", callbackPauseOrResume, &ewkCallbackPauseOrResumeRoot, this);
2062         m_rootView = 0;
2063     }
2064     destroyEmbedPlayer();
2065 }
2066
2067 void MediaPlayerPrivate::stopInternal(bool force)
2068 {
2069     LOG(Media, "%s:%d url = %s duration:%d\n", __FUNCTION__, __LINE__, m_url.utf8().data(), m_contentDuration);
2070     videoUpdateStop();
2071     hideEmbedLoadingIcon();
2072 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
2073     showEmbedPlayIcon();
2074 #endif
2075
2076     HTMLMediaElement* mediaElement = static_cast<HTMLMediaElement*>(m_player->mediaPlayerClient());
2077     if (mediaElement) {
2078         if (!force) {
2079             if (mediaElement->loop()) {
2080                 if (hasVideo())
2081                     videoUpdateStart();
2082                 setStatus(MM_PLAYER_PLAY);
2083                 return;
2084             }
2085         }
2086         m_contentDuration = 0;
2087         if (m_mmPlayerHandle)
2088             ecore_timer_add(0.0, timerEmbedStop, this);
2089     }
2090 }
2091
2092 MediaPlayer::MovieLoadType MediaPlayerPrivate::movieLoadType() const
2093 {
2094     LOG(Media, "%s\n", __func__);
2095     if (m_url.contains("rtsp://")) {
2096         LOG(Media, "MediaPlayer::LiveStream\n");
2097         return MediaPlayer::LiveStream;
2098     }
2099     if (m_url.contains("file://")) {
2100         LOG(Media, "MediaPlayer::StoredStream\n");
2101         return MediaPlayer::StoredStream;
2102     }
2103     if (m_url.contains("http://")) {
2104         LOG(Media, "MediaPlayer::Download\n");
2105         return MediaPlayer::StoredStream;
2106     }
2107     return MediaPlayer::Unknown;
2108 }
2109
2110 /* for buffering, only http connection */
2111 void MediaPlayerPrivate::showEmbedLoadingIcon()
2112 {
2113 //    LOG(Media, "%s\n", __func__);
2114     if (!hasVideo() || !m_player->frameView() || !m_rootView)
2115         return;
2116
2117 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
2118     hideEmbedPlayIcon();
2119
2120     setVideoRect();
2121     if (m_frame.location() == IntPoint(0, 0)) {
2122         LOG(Media, "%s() m_frame.location() is not set yet.\n", __FUNCTION__);
2123         return;
2124     }
2125 #endif
2126
2127     /* in case of localfile, can not catch the timing to hide progressbar.*/
2128     if (m_url.contains("file://"))
2129         return;
2130     if (!m_bufferingProgressbar) {
2131         if (!m_bufferingProgressbarBg) {
2132             m_bufferingProgressbarBg = evas_object_rectangle_add(evas_object_evas_get(m_rootView));
2133             evas_object_smart_member_add(m_bufferingProgressbarBg, m_rootView);
2134             evas_object_color_set(m_bufferingProgressbarBg, 0, 0, 0, 125);
2135         }
2136         m_bufferingProgressbar = elm_progressbar_add(m_bufferingProgressbarBg);
2137         evas_object_smart_member_add(m_bufferingProgressbar, evas_object_smart_parent_get(m_bufferingProgressbarBg));
2138         elm_object_style_set(m_bufferingProgressbar, "toolbar_process");
2139         evas_object_size_hint_align_set(m_bufferingProgressbar, EVAS_HINT_FILL, 0.5);
2140         evas_object_size_hint_weight_set(m_bufferingProgressbar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2141         elm_progressbar_pulse(m_bufferingProgressbar, EINA_TRUE);
2142
2143         if (!m_frame.isEmpty()) {
2144             IntRect m_rect = m_player->frameView()->contentsToScreen(m_frame);
2145             if (m_rect.isEmpty())
2146                 return;
2147             Evas_Coord x, y;
2148             evas_object_geometry_get(m_rootView, &x, &y, 0, 0);
2149             m_rect.move(x, y);
2150             int progressX, progressY;
2151
2152             progressX = m_rect.x() + (m_rect.width() - EVAS_ICON_SIZE) / 2;
2153             progressY = m_rect.y() + (m_rect.height() - EVAS_ICON_SIZE) / 2;
2154             evas_object_move(m_bufferingProgressbarBg, progressX, progressY);
2155             evas_object_move(m_bufferingProgressbar, progressX, progressY);
2156
2157             evas_object_resize(m_bufferingProgressbar, EVAS_ICON_SIZE, EVAS_ICON_SIZE);
2158             evas_object_resize(m_bufferingProgressbarBg, EVAS_ICON_SIZE, EVAS_ICON_SIZE);
2159
2160             if (m_playerStatus == MM_PLAYER_PLAY)
2161                 m_player->repaint();
2162         } else {
2163             evas_object_resize(m_bufferingProgressbar, EVAS_ICON_SIZE, EVAS_ICON_SIZE);
2164             evas_object_resize(m_bufferingProgressbarBg, EVAS_ICON_SIZE, EVAS_ICON_SIZE);
2165         }
2166     }
2167     evas_object_show(m_bufferingProgressbarBg);
2168     evas_object_show(m_bufferingProgressbar);
2169 }
2170
2171 void MediaPlayerPrivate::hideEmbedLoadingIcon()
2172 {
2173     LOG(Media, "%s\n", __func__);
2174     if (m_bufferingProgressbar) {
2175         evas_object_smart_member_del(m_bufferingProgressbar);
2176         evas_object_hide(m_bufferingProgressbar);
2177         evas_object_del(m_bufferingProgressbar);
2178         m_bufferingProgressbar = 0;
2179     }
2180     if (m_bufferingProgressbarBg) {
2181         evas_object_smart_member_del(m_bufferingProgressbarBg);
2182         evas_object_hide(m_bufferingProgressbarBg);
2183         evas_object_del(m_bufferingProgressbarBg);
2184         m_bufferingProgressbarBg = 0;
2185     }
2186 }
2187
2188 /* panning by webkit */
2189 void MediaPlayerPrivate::smartCalculate()
2190 {
2191     if (!m_isZooming)
2192         repaintVideoCanvas();
2193 }
2194
2195 /* zoom by webkit*/
2196 void MediaPlayerPrivate::setZoomWeak(void* data)
2197 {
2198     if (!m_url || m_url.length() <= 0)
2199         return;
2200     if (!m_player || !m_player->frameView())
2201         return;
2202
2203     ZoomData* zd = (ZoomData*)data;
2204     if (!zd)
2205         return;
2206
2207     if (!m_bufferingProgressbar && !m_playIcon)
2208         return;
2209
2210     int progressX, progressY;
2211
2212     // block panning operation during zooming
2213     m_isZooming = true;
2214
2215     float zoom = zd->zoom;
2216     Evas_Coord cx = zd->cx;
2217     Evas_Coord cy = zd->cy;
2218     Evas_Coord viewX = zd->view_x;
2219     Evas_Coord viewY = zd->view_y;
2220
2221     IntRect m_rect = m_player->frameView()->contentsToScreen(m_frame);
2222     int clipperX = (m_rect.x() + viewX - cx) * zoom + cx;
2223     int clipperY = (m_rect.y() + viewY - cy) * zoom + cy;
2224     int clipperW = m_rect.width() * zoom;
2225     int clipperH = m_rect.height() * zoom;
2226
2227     if (m_bufferingProgressbar) {
2228         int width;
2229         int height;
2230         evas_object_geometry_get(m_bufferingProgressbar, 0, 0, &width, &height);
2231         progressX = clipperX + (clipperW - width) / 2;
2232         progressY = clipperY + (clipperH - height) / 2;
2233         evas_object_move(m_bufferingProgressbar, progressX, progressY);
2234         if (m_bufferingProgressbarBg)
2235             evas_object_move(m_bufferingProgressbarBg, progressX, progressY);
2236     }
2237
2238     if (m_playIcon) {
2239         progressX = clipperX + (clipperW - EVAS_ICON_SIZE) / 2;
2240         progressY = clipperY + (clipperH - EVAS_ICON_SIZE) / 2;
2241         evas_object_move(m_playIcon, progressX, progressY);
2242     }
2243 }
2244
2245 /* end of zoom by webkit*/
2246 void MediaPlayerPrivate::setZoom(void* data)
2247 {
2248     LOG(Media, "%s()\n", __FUNCTION__);
2249
2250     m_isZooming = false;
2251
2252     ZoomData* zd = (ZoomData*) data;
2253     if (!zd)
2254         return;
2255
2256     m_zoomRatio = zd->zoom;
2257     IntRect rect = m_frame;
2258     rect.scale(m_zoomRatio);
2259     setContentSize(rect.size());
2260 }
2261
2262 void MediaPlayerPrivate::pauseOrResume(bool bPause)
2263 {
2264     LOG(Media, "%s() pause: %d\n", __FUNCTION__, bPause);
2265
2266     HTMLMediaElement* mediaElement = static_cast<HTMLMediaElement*>(m_player->mediaPlayerClient());
2267     if (!mediaElement) {
2268         LOG(Media, "%s() mediaElement == NULL\n", __FUNCTION__);
2269         return;
2270     }
2271     if (bPause && getStatus() == MM_PLAYER_PLAY) {
2272         UserGestureIndicator gestureIndicator(DefinitelyProcessingUserGesture);
2273         mediaElement->pause();
2274         m_suspended = true;
2275         if (m_resumeVideoTimer) {
2276             ecore_timer_del(m_resumeVideoTimer);
2277             m_resumeVideoTimer = 0;
2278         }
2279     } else if (!bPause && m_suspended) {
2280         UserGestureIndicator gestureIndicator(DefinitelyProcessingUserGesture);
2281         setStatus(MM_PLAYER_PLAY);
2282         m_resumeVideoTimer = ecore_timer_add(VIDEO_RESUME_TIME, timerResumeVideo, this);
2283         m_suspended = false;
2284     }
2285     repaint();
2286 }
2287
2288 void MediaPlayerPrivate::repaintVideoCanvas()
2289 {
2290     if (!m_player || !m_player->frameView() || !m_rootView)
2291         return;
2292
2293     if (!m_bufferingProgressbar && !m_playIcon)
2294         return;
2295     
2296     Evas_Coord x, y;
2297     int progressX, progressY;
2298
2299     evas_object_geometry_get(m_rootView, &x, &y, 0, 0);
2300     IntRect m_rect = m_player->frameView()->contentsToScreen(m_frame);
2301     m_rect.move(x, y);
2302
2303     if (m_bufferingProgressbar) {
2304         int width;
2305         int height;
2306         evas_object_geometry_get(m_bufferingProgressbar, 0, 0, &width, &height);
2307         progressX = m_rect.x() + (m_rect.width() - width) / 2;
2308         progressY = m_rect.y() + (m_rect.height() - height) / 2;
2309         evas_object_move(m_bufferingProgressbar, progressX, progressY);
2310
2311         if (m_bufferingProgressbarBg)
2312             evas_object_move(m_bufferingProgressbarBg, progressX, progressY);
2313     }
2314
2315     if (m_playIcon) {
2316         progressX = m_rect.x() + (m_rect.width() - EVAS_ICON_SIZE) / 2;
2317         progressY = m_rect.y() + (m_rect.height() - EVAS_ICON_SIZE) / 2;
2318         evas_object_move(m_playIcon, progressX, progressY);
2319     }
2320 }
2321
2322 /* setting for MM-Player */
2323 int MediaPlayerPrivate::initializeVideoPlayer()
2324 {
2325     LOG(Media, "%s\n", __func__);
2326
2327     char* pErrName = 0;
2328     int err = MM_ERROR_NONE;
2329
2330     if (!m_mmPlayerHandle) {
2331         LOG(Media, "%s() ERROR! m_mmPlayerHandle == NULL\n", __FUNCTION__);
2332         return -1;
2333     }
2334
2335     if (!m_url.contains("file://")) {    /* only for streamming */
2336 #if !ENABLE(TIZEN_WEBKIT2) // FIXME: have to be fixed after ACCELERATED_COMPOSITING is enabled
2337         HTMLMediaElement* mediaElement = static_cast<HTMLMediaElement*>(m_player->mediaPlayerClient());
2338         if (mediaElement) {
2339             const KURL url(ParsedURLString, m_url.utf8().data());
2340             FrameLoaderClient* client = mediaElement->document()->frame()->loader()->client();
2341             LOG(Media, "%s() UA: %s\n", __FUNCTION__, client->userAgent(url).utf8().data());
2342
2343             err = mm_player_set_attribute(m_mmPlayerHandle, &pErrName, MM_PLAYER_STREAMING_USER_AGENT,
2344                     client->userAgent(url).utf8().data(), client->userAgent(url).utf8().length(),
2345                     (void*)0);
2346             if (err != MM_ERROR_NONE) {
2347                 LOG(Media, "%s mm_player_set_attribute = %d\n", __FUNCTION__, err);
2348                 if (pErrName) {
2349                     LOG(Media, "%s return error from mm_player_set_attribute (%s)\n", __FUNCTION__, pErrName);
2350                     free(pErrName);
2351                     pErrName = 0;
2352                 }
2353             }
2354         }
2355 #endif
2356 #if USE(SOUP)
2357         SoupSession* session = ResourceHandle::defaultSession();
2358         SoupCookieJar* cookieJar = SOUP_COOKIE_JAR(soup_session_get_feature(session, SOUP_TYPE_COOKIE_JAR));
2359         SoupURI* uri = soup_uri_new(m_url.utf8().data());
2360         char* cookies = soup_cookie_jar_get_cookies(cookieJar, uri, false);
2361         if (cookies) {
2362             LOG(Media, "embed player cookies=%s\n", cookies);
2363             err = mm_player_set_attribute(m_mmPlayerHandle, &pErrName,
2364                                             "streaming_cookie", cookies, strlen(cookies),
2365                                             (void*)0);
2366             if (err != MM_ERROR_NONE) {
2367                 LOG(Media, "%s mm_player_set_attribute = %d\n", __FUNCTION__, err);
2368                 if (pErrName) {
2369                     LOG(Media, "%s return error from mm_player_set_attribute (%s)\n", __FUNCTION__, pErrName);
2370                     free(pErrName);
2371                     pErrName = 0;
2372                 }
2373             }
2374         }
2375 #endif
2376
2377 #if USE(SOUP)
2378 #if ENABLE(TIZEN_SET_PROXY)
2379         SoupURI* proxy = 0;
2380         char* pureProxyURI = 0;
2381         g_object_get(session, SOUP_SESSION_PROXY_URI, &proxy, (void*)0);
2382         if (proxy) {
2383             WTF::String proxyURI = soupURIToKURL(proxy).string();
2384             if (proxyURI.contains("/"))
2385                 proxyURI.replace("/", "");
2386
2387             if (!memcmp(proxyURI.utf8().data(), "http:", 5))
2388                 pureProxyURI = (char*)proxyURI.utf8().data() + 5;
2389             else if (!memcmp(proxyURI.utf8().data(), "https:", 6))
2390                 pureProxyURI = (char*)proxyURI.utf8().data() + 6;
2391             else
2392                 pureProxyURI = (char*)proxyURI.utf8().data();
2393
2394             LOG(Media, "%s [Proxy : (%s)]\n", __FUNCTION__, pureProxyURI);
2395             err = mm_player_set_attribute(m_mmPlayerHandle, &pErrName,    /*MM_PLAYER_STREAMING_PROXY_IP*/
2396                                         "streaming_proxy", (char*)pureProxyURI, strlen(pureProxyURI),
2397                                         (void*)0);
2398             soup_uri_free(proxy);
2399             if (err != MM_ERROR_NONE) {
2400                 LOG(Media, "%s mm_player_set_attribute = %d\n", __FUNCTION__, err);
2401                 if (pErrName) {
2402                     LOG(Media, "%s return error from mm_player_set_attribute (%s)\n", __FUNCTION__, pErrName);
2403                     free(pErrName);
2404                     pErrName = 0;
2405                 }
2406             }
2407         }
2408 #endif
2409 #endif
2410
2411     }
2412
2413     err = mm_player_set_attribute(m_mmPlayerHandle, &pErrName,
2414                                     MM_PLAYER_CONTENT_URI, m_url.utf8().data(), m_url.length(),
2415                                     MM_PLAYER_VIDEO_ROTATION, MM_DISPLAY_ROTATION_NONE,
2416                                     (void*)0);
2417     if (err != MM_ERROR_NONE) {
2418         LOG(Media, "%s mm_player_set_attribute = %d\n", __FUNCTION__, err);
2419         if (pErrName) {
2420             free(pErrName);
2421             pErrName = 0;
2422         }
2423     }
2424     if (!hasVideo())
2425         mm_player_set_message_callback(m_mmPlayerHandle, callbackAudioMessage, this);
2426     else {
2427         if (!m_size.isEmpty()) {
2428             IntSize size = m_size;
2429             size.scale(m_zoomRatio);
2430             setContentSize(size);
2431         } else {
2432             LOG(Media, "%s() m_size.isEmpty()\n", __FUNCTION__);
2433             setContentSize(naturalSize());
2434         }
2435         mm_player_set_message_callback(m_mmPlayerHandle, callbackEmbedVideoMessage, this);
2436         mm_player_set_video_stream_callback(m_mmPlayerHandle, callbackEmbedVideoFrame, this);
2437     }
2438     if (err != MM_ERROR_NONE) {
2439         LOG(Media, "%s mm_player_set_attribute = %d\n", __FUNCTION__, err);
2440         if (pErrName) {
2441             LOG(Media, "%s return error from mm_player_set_attribute (%s)\n", __FUNCTION__, pErrName);
2442             free(pErrName);
2443             pErrName = 0;
2444         }
2445         return -1;
2446     }
2447     return 0;
2448 }
2449
2450 void MediaPlayerPrivate::destroyEmbedPlayer()
2451 {
2452     LOG(Media, "%s\n", __func__);
2453
2454     if (hasVideo()) {
2455         HTMLMediaElement* mediaElement = static_cast<HTMLMediaElement*>(m_player->mediaPlayerClient());
2456         if (mediaElement) {
2457             LOG(Media, "%s() pause media.\n", __FUNCTION__);
2458             mediaElement->pause();
2459         }
2460     } else {
2461         m_delayingLoad = true;
2462         delAudioHandle(this);
2463
2464         // state change for next play: without this progress bar is not work
2465         if (m_networkState != MediaPlayer::Empty) {
2466             m_networkState = MediaPlayer::Empty;
2467             m_player->networkStateChanged();
2468         }
2469         if (m_readyState != MediaPlayer::HaveNothing) {
2470             m_readyState = MediaPlayer::HaveNothing;
2471             m_player->readyStateChanged();
2472         }
2473     }
2474
2475     m_contentDuration = 0;
2476     if (m_mmPlayerHandle) {
2477         LOG(Media, "%s mm_player_destroy url = %s\n", __FUNCTION__, m_url.utf8().data());
2478         mm_player_stop(m_mmPlayerHandle);
2479         mm_player_unrealize(m_mmPlayerHandle);
2480         mm_player_destroy(m_mmPlayerHandle);
2481         mm_session_finish();
2482     }
2483     m_mmPlayerHandle = 0;
2484
2485     if (m_frameBuffer) {
2486         free(m_frameBuffer);
2487         m_frameBuffer = 0;
2488     }
2489     m_contentWidth = 0;
2490     m_contentHeight = 0;
2491 }
2492
2493 void MediaPlayerPrivate::recvMsgPaused()
2494 {
2495     if (m_readyState != MediaPlayer::HaveEnoughData) {
2496         LOG(Media, "%s() set audio ready.\n", __FUNCTION__);
2497         ecore_timer_add(AUDIO_READY_TIME, timerMediaReady, this); // set media state HaveEnoughData
2498         return;
2499     }
2500
2501     setStatus(MM_PLAYER_PAUSE);
2502 }
2503
2504 void MediaPlayerPrivate::setMediaReady()
2505 {
2506     LOG(Media, "%s()\n", __FUNCTION__);
2507     updateStates();
2508 }
2509 #endif // TIZEN_MM_PLAYER
2510
2511
2512 }
2513
2514 #endif