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
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.
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.
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.
26 #include "MediaPlayerPrivateMMFW.h"
29 #include "ChromeClient.h"
31 #include "FrameView.h"
32 #include "GraphicsContext.h"
35 #include "MIMETypeRegistry.h"
36 #include "MediaPlayer.h"
37 #include "NotImplemented.h"
39 #include "PlatformContextCairo.h"
40 #include "ResourceHandle.h"
41 #include "ScrollView.h"
42 #include "TimeRanges.h"
46 #include <Ecore_Evas.h>
57 #if ENABLE(TIZEN_MM_PLAYER)
58 #include "FrameLoaderClientEfl.h"
59 #include "HTMLMediaElement.h"
60 #include "HTMLNames.h"
62 #include "UserGestureIndicator.h"
63 // support full-screen
64 #include <Elementary.h>
67 #include "SoupURIUtils.h"
68 #include <libsoup/soup.h>
72 #endif // TIZEN_MM_PLAYER
74 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
75 #if !USE(TIZEN_TEXTURE_MAPPER)
80 #if ENABLE(TIZEN_WAC_CAMERA_SUPPORT)
81 #include "CameraManager.h"
82 #include "HTMLVideoElement.h"
85 #if ENABLE(TIZEN_FILE_SYSTEM)
86 #include "AsyncFileSystem.h"
87 #include "DOMFileSystemBase.h"
88 #include "LocalFileSystem.h"
95 #if ENABLE(TIZEN_MM_PLAYER)
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
106 // PLAY_TIME_FORMAT // for slide bar of controlbar
107 #define MM_PLAY_TIME_FORMAT "02u:%02u:%02u"
109 #define MM_PLAY_TIME_ARGS(t) \
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
121 static MediaPlayerPrivate* gPlayer = 0; // current mm-player
123 static MediaPlayerPrivate* gAudioPlayer[MAX_AUDIO_HANDLE] = {0};
125 void delAudioHandle(void* data)
129 MediaPlayerPrivate* mp = reinterpret_cast<MediaPlayerPrivate*>(data);
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
145 void removeOneAudioHandle()
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]);
154 LOG(Media, "%s() xxx playing %d: %p\n", __FUNCTION__, i, gAudioPlayer[i]);
157 i = i % MAX_AUDIO_HANDLE; // remove first one if all audios are playing.
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();
165 int findEmptyAudioHandleIndex()
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);
177 // no empty handle in the array. remove first one which is not playing.
178 removeOneAudioHandle();
180 return MAX_AUDIO_HANDLE - 1;
183 void addAudioHandle(void* data)
185 MediaPlayerPrivate* mp = reinterpret_cast<MediaPlayerPrivate*>(data);
189 int index = findEmptyAudioHandleIndex();
191 LOG(Media, "%s() +++ audio handle %d: %p\n", __FUNCTION__, index, mp);
192 gAudioPlayer[index] = mp;
199 /////////// define callbasks //////////////////
201 Eina_Bool timerCatchLongPressEvent(void* data)
203 MediaPlayerPrivate* mp = reinterpret_cast<MediaPlayerPrivate*>(data);
207 mp->enterFullscreen();
211 Eina_Bool timerEmbedStop(void* data)
213 LOG(Media, "%s\n", __func__);
214 MediaPlayerPrivate* mp = reinterpret_cast<MediaPlayerPrivate*>(data);
218 mp->destroyEmbedPlayer();
222 Eina_Bool timerEmbedInvalidateRect(void* data)
224 #ifdef __VIDEO_DEBUG_PRINT /* check FPS */
227 static struct timeval tp;
228 static time_t ptp = 0;
229 gettimeofday(&tp, 0);
230 if (ptp != tp.tv_sec) {
232 LOG(Media, "timerEmbedInvalidateRect [FPS:%d]\n", fps);
236 MediaPlayerPrivate* mp = reinterpret_cast<MediaPlayerPrivate*>(data);
241 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
242 Eina_Bool timerFillVideoRect(void* data)
244 LOG(Media, "%s()\n", __func__);
245 MediaPlayerPrivate* mp = reinterpret_cast<MediaPlayerPrivate*>(data);
254 Eina_Bool timerResumeVideo(void* data)
256 LOG(Media, "%s()\n", __FUNCTION__);
257 MediaPlayerPrivate* mp = reinterpret_cast<MediaPlayerPrivate*>(data);
261 HTMLMediaElement* mediaElement = static_cast<HTMLMediaElement*>(mp->getMMPlayer()->mediaPlayerClient());
263 mediaElement->play();
268 Eina_Bool timerRecvInterrupted(void* data)
270 LOG(Media, "%s()\n", __FUNCTION__);
271 MediaPlayerPrivate* mp = reinterpret_cast<MediaPlayerPrivate*>(data);
275 mp->setStatus(MM_PLAYER_PAUSE);
276 mp->setStartedPlaying(false);
277 mp->videoUpdatePause();
279 HTMLMediaElement* mediaElement = static_cast<HTMLMediaElement*>(mp->getMMPlayer()->mediaPlayerClient());
281 mediaElement->pause();
286 Eina_Bool timerRecvBeginOfStream(void* data)
288 LOG(Media, "%s()\n", __FUNCTION__);
289 MediaPlayerPrivate* mp = reinterpret_cast<MediaPlayerPrivate*>(data);
294 mp->getMMPlayer()->durationChanged();
299 Eina_Bool timerMediaReady(void* data)
301 LOG(Media, "%s()\n", __FUNCTION__);
302 MediaPlayerPrivate* mp = reinterpret_cast<MediaPlayerPrivate*>(data);
311 // data structure for registering ewk callback
312 struct ewkCallbackNode {
313 MediaPlayerPrivate* mp;
315 struct ewkCallbackNode* next;
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;
324 void callbackSmartCalculate(void* data, Evas_Object* obj, void* eventInfo)
326 struct ewkCallbackNode* node = ewkCallbackSmartCalculateRoot;
328 if (node->mp && node->o == obj)
329 node->mp->smartCalculate();
334 void callbackSetZoomWeak(void* data, Evas_Object* obj, void* eventInfo)
336 struct ewkCallbackNode* node = ewkCallbackZoomWeakRoot;
338 if (node->mp && node->o == obj)
339 node->mp->setZoomWeak(eventInfo);
344 void callbackSetZoom(void* data, Evas_Object* obj, void* eventInfo)
346 struct ewkCallbackNode* node = ewkCallbackZoomRoot;
348 if (node->mp && node->o == obj)
349 node->mp->setZoom(eventInfo);
354 void callbackPauseOrResume(void* data, Evas_Object* obj, void* eventInfo)
356 struct ewkCallbackNode* node = ewkCallbackPauseOrResumeRoot;
358 if (node->mp && node->o == obj)
359 node->mp->pauseOrResume(*(bool*)eventInfo);
364 void addEwkCallback(Evas_Object* obj, const char* event, Evas_Smart_Cb func, struct ewkCallbackNode** root, void* data)
366 struct ewkCallbackNode* node;
368 node = (struct ewkCallbackNode*)malloc(sizeof(struct ewkCallbackNode));
370 LOG(Media, "%s() malloc fail!\n", __FUNCTION__);
375 node->mp = reinterpret_cast<MediaPlayerPrivate*>(data);
379 // add evas callback if it is not added
380 struct ewkCallbackNode* ptr;
381 bool isExist = false;
384 // check evas object is in the list
392 LOG(Media, "%s() +++++ add evas callback! (%p)\n", __FUNCTION__, obj);
393 evas_object_smart_callback_add(obj, event, func, 0);
397 // make root and add evas callback
400 // append the node to last of the linked list
401 struct ewkCallbackNode* ptr = *root;
404 if (ptr->mp == node->mp) {
405 LOG(Media, "%s() already in the list. (mp: %p)", __FUNCTION__, ptr->mp);
418 void delEwkCallback(Evas_Object* obj, const char* event, Evas_Smart_Cb func, struct ewkCallbackNode** root, void* data)
420 struct ewkCallbackNode* node;
425 if ((*root)->mp == data) {
426 // remove root node and make root with next node
427 node = (*root)->next;
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;
443 // del evas callback if evas object is not in the list
444 struct ewkCallbackNode* ptr;
445 bool isExist = false;
448 // check evas object is in the list
456 LOG(Media, "%s() ----- del evas callback! (%p)\n", __FUNCTION__, obj);
457 evas_object_smart_callback_del(obj, event, func);
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)
464 MediaPlayerPrivate* mp = reinterpret_cast<MediaPlayerPrivate*>(user_param);
465 MMMessageParamType* msgParam = (MMMessageParamType*)param;
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);
472 case MM_MESSAGE_UNKNOWN:
473 LOG(Media, "%s (%d:UNKNOWN)\n", __FUNCTION__, msg);
474 mp->setStatus(MM_PLAYER_STOP);
475 mp->stopInternal(true);
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);
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);
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);
490 case MM_MESSAGE_DRM_NOT_AUTHORIZED: /**< Not authorized to play the content */
491 LOG(Media, "MM_MESSAGE_DRM_NOT_AUTHORIZED %08x\n", msg);
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");
498 case MM_MSG_CODE_INTERRUPTED_BY_CALL_START:
499 LOG(Media, "MM_MSG_CODE_INTERRUPTED_BY_CALL_START\n");
501 case MM_MSG_CODE_INTERRUPTED_BY_CALL_END:
502 LOG(Media, "MM_MSG_CODE_INTERRUPTED_BY_CALL_END\n");
504 case MM_MSG_CODE_INTERRUPTED_BY_EARJACK_UNPLUG:
505 LOG(Media, "MM_MSG_CODE_INTERRUPTED_BY_EARJACK_UNPLUG\n");
507 case MM_MSG_CODE_INTERRUPTED_BY_RESOURCE_CONFLICT:
508 LOG(Media, "MM_MSG_CODE_INTERRUPTED_BY_RESOURCE_CONFLICT\n");
510 case MM_MSG_CODE_INTERRUPTED_BY_ALARM_START:
511 LOG(Media, "MM_MSG_CODE_INTERRUPTED_BY_ALARM_START\n");
513 case MM_MSG_CODE_INTERRUPTED_BY_ALARM_END:
514 LOG(Media, "MM_MSG_CODE_INTERRUPTED_BY_ALARM_END\n");
517 ecore_timer_add(0.0, timerRecvInterrupted, mp);
519 case MM_MESSAGE_READY_TO_RESUME:
520 LOG(Media, "MM_MESSAGE_READY_TO_RESUME %08x\n", msg);
522 case MM_MESSAGE_CONNECTING: /**< Connecting message type 0x100*/
523 LOG(Media, "MM_MESSAGE_CONNECTING %08x\n", msg);
525 case MM_MESSAGE_CONNECTED: /**< Rtspsrc has successed to connecting to server */
526 LOG(Media, "MM_MESSAGE_CONNECTED %08x\n", msg);
528 case MM_MESSAGE_CONNECTION_TIMEOUT: /**< Connection timeout message type */
529 LOG(Media, "MM_MESSAGE_CONNECTION_TIMEOUT %08x\n", msg);
530 mp->stopInternal(true);
532 case MM_MESSAGE_UPDATE_SUBTITLE :
533 LOG(Media, "%s (%d:MM_MESSAGE_UPDATE_SUBTITLE)\n", __FUNCTION__, msg);
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();
540 mp->showEmbedLoadingIcon();
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);
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
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__);
556 case MM_PLAYER_STATE_READY:
557 LOG(Media, "%s (MM_PLAYER_STATE_READY)\n", __FUNCTION__);
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);
565 case MM_PLAYER_STATE_PAUSED:
566 LOG(Media, "%s (MM_PLAYER_STATE_PAUSED)\n", __FUNCTION__);
567 mp->videoUpdatePause();
573 LOG(Media, "No message %08x\n", msg);
576 return MM_ERROR_NONE;
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)
582 MediaPlayerPrivate* mp = reinterpret_cast<MediaPlayerPrivate*>(user_param);
586 if (!stream || streamSize <= 0)
589 if (mp->getSizeChanged()) {
590 LOG(Media, "%s(): change buffer size", __FUNCTION__);
591 mp->setSizeChanged(false);
592 mp->setVideoBuffer(IntSize(width, height));
594 // skip 1 frame for stability
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
608 unsigned char* buf = mp->getEmbedCanvasBuffer();
610 LOG(Media, "%s(): buf is NULL\n", __FUNCTION__);
614 #if !ENABLE(TIZEN_WEBKIT2)
615 memcpy(buf, stream, streamSize); // RGBA frame
618 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
619 mp->setNeedsUpdate(true);
624 /////////// callbasks //////////////////
626 /////////// For Audio //////////////
627 int callbackAudioMessage(int msg, void *param, void *user_param)
629 MediaPlayerPrivate* mp = reinterpret_cast<MediaPlayerPrivate*>(user_param);
630 MMMessageParamType* msgParam = (MMMessageParamType*)param;
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");
637 case MM_MSG_CODE_INTERRUPTED_BY_CALL_START:
638 LOG(Media, "MM_MSG_CODE_INTERRUPTED_BY_CALL_START\n");
640 case MM_MSG_CODE_INTERRUPTED_BY_CALL_END:
641 LOG(Media, "MM_MSG_CODE_INTERRUPTED_BY_CALL_END\n");
643 case MM_MSG_CODE_INTERRUPTED_BY_EARJACK_UNPLUG:
644 LOG(Media, "MM_MSG_CODE_INTERRUPTED_BY_EARJACK_UNPLUG\n");
646 case MM_MSG_CODE_INTERRUPTED_BY_RESOURCE_CONFLICT:
647 LOG(Media, "MM_MSG_CODE_INTERRUPTED_BY_RESOURCE_CONFLICT\n");
649 case MM_MSG_CODE_INTERRUPTED_BY_ALARM_START:
650 LOG(Media, "MM_MSG_CODE_INTERRUPTED_BY_ALARM_START\n");
652 case MM_MSG_CODE_INTERRUPTED_BY_ALARM_END:
653 LOG(Media, "MM_MSG_CODE_INTERRUPTED_BY_ALARM_END\n");
656 ecore_timer_add(0.0, timerRecvInterrupted, mp);
658 case MM_MESSAGE_BUFFERING:
659 LOG(Media, "%s (%d:MM_MESSAGE_BUFFERING) : %d\n", __FUNCTION__, msg, msgParam->connection.buffering);
661 case MM_MESSAGE_BEGIN_OF_STREAM:
662 LOG(Media, "(MM_MESSAGE_BEGIN_OF_STREAM)\n");
663 ecore_timer_add(0.0, timerRecvBeginOfStream, mp);
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
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);
676 case MM_PLAYER_STATE_PAUSED:
677 LOG(Media, "(MM_PLAYER_STATE_PAUSED)\n");
683 return MM_ERROR_NONE;
685 /////////// For Audio //////////////
686 #endif // TIZEN_MM_PLAYER
688 PassOwnPtr<MediaPlayerPrivateInterface> MediaPlayerPrivate::create(MediaPlayer* player)
690 LOG(Media, "%s\n", __func__);
691 return adoptPtr(new MediaPlayerPrivate(player));
694 void MediaPlayerPrivate::registerMediaEngine(MediaEngineRegistrar registrar)
696 LOG(Media, "%s\n", __func__);
698 registrar(create, getSupportedTypes, supportsType, 0, 0, 0);
701 MediaPlayerPrivate::MediaPlayerPrivate(MediaPlayer* player)
704 , m_endTime(numeric_limits<float>::infinity())
705 , m_isEndReached(false)
707 , m_networkState(MediaPlayer::Empty)
708 , m_readyState(MediaPlayer::HaveNothing)
709 , m_startedPlaying(false)
710 #if ENABLE(TIZEN_MM_PLAYER)
711 , m_isStreaming(true)
715 , m_isStreaming(false)
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)
729 , m_mmPlayerHandle(0)
730 , m_embedVideoUpdateTimer(0)
731 , m_embedVideoLongpressTimer(0)
732 , m_resumeVideoTimer(0)
735 #if ENABLE(TIZEN_MM_PLAYER)
736 LOG(Media, "%s\n", __func__);
737 m_usingExternalPlayer = false;
739 m_usingExternalPlayer = true;
742 m_firstPainted = false;
745 if (m_usingExternalPlayer)
748 #if ENABLE(TIZEN_MM_PLAYER)
749 m_bufferingProgressbar = 0;
750 m_bufferingProgressbarBg = 0;
753 m_isEmbedVideo = false;
756 m_isSizeChanged = false;
759 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
760 m_acceleratedCompositing = false;
761 m_needsUpdate = false;
766 MediaPlayerPrivate::~MediaPlayerPrivate()
768 LOG(Media, "%s\n", __func__);
770 if (m_usingExternalPlayer)
773 #if ENABLE(TIZEN_MM_PLAYER)
775 hideEmbedLoadingIcon();
776 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
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);
789 if (ewkCallbackPauseOrResumeRoot)
790 delEwkCallback(m_rootView, "html5video,pauseresume", callbackPauseOrResume, &ewkCallbackPauseOrResumeRoot, this);
794 destroyEmbedPlayer();
795 LOG(Media, "%s\n", __func__);
797 if (gPlayer == this) {
798 LOG(Media, "%s(): gPlayer = NULL\n", __FUNCTION__);
804 void MediaPlayerPrivate::load(const String& url)
806 LOG(Media, "%s\n", __func__);
807 LOG(Media, "Load %s", url.utf8().data());
809 #if ENABLE(TIZEN_MM_PLAYER)
811 if (m_url.contains("rtsp://"))
812 m_isStreaming = true;
814 m_isStreaming = false;
816 #if ENABLE(TIZEN_FILE_SYSTEM)
817 if (m_url.contains("filesystem:")) {
818 AsyncFileSystem::Type type;
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());
827 if (m_url.contains("file://")) /*by kwangmin... url_decode*/
828 m_url.replace("%20", " ");
830 m_startedPlaying = false;
831 m_delayingLoad = true;
833 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
834 if (!platformLayer())
835 acceleratedRenderingStateChanged();
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();
848 if (m_networkState != MediaPlayer::Loaded) {
849 m_networkState = MediaPlayer::Loaded;
850 m_player->networkStateChanged();
852 if (m_readyState != MediaPlayer::HaveEnoughData) {
853 m_readyState = MediaPlayer::HaveEnoughData;
854 m_player->readyStateChanged();
857 repaint(); // paint video rect after load finish
860 LOG(Media, "%s audio\n", __FUNCTION__);
861 if (m_networkState != MediaPlayer::Loading) {
862 m_networkState = MediaPlayer::Loading;
863 m_player->networkStateChanged();
866 m_delayingLoad = false;
872 void MediaPlayerPrivate::commitLoad()
874 LOG(Media, "%s\n", __func__);
875 #if ENABLE(TIZEN_MM_PLAYER)
876 if (hasVideo() && m_isEmbedVideo)
883 #if ENABLE(TIZEN_MM_PLAYER)
884 void MediaPlayerPrivate::setRootView()
886 LOG(Media, "%s()\n", __FUNCTION__);
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();
894 m_rootView = evas_object_smart_parent_get(m_player->frameView()->root()->evasObject());
896 LOG(Media, "%s() cannot get web view.\n", __FUNCTION__);
899 #if USE(ACCELERATED_COMPOSITING)
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);
910 // always register for all media.
911 addEwkCallback(m_rootView, "html5video,pauseresume", callbackPauseOrResume, &ewkCallbackPauseOrResumeRoot, this);
916 void MediaPlayerPrivate::prepareToPlay()
918 LOG(Media, "%s\n", __func__);
919 if (m_delayingLoad) {
920 m_delayingLoad = false;
925 void MediaPlayerPrivate::createWindow()
927 LOG(Media, "%s\n", __func__);
930 void MediaPlayerPrivate::play()
932 LOG(Media, "%s\n", __func__);
934 #if ENABLE(TIZEN_MM_PLAYER)
935 if (!m_url || m_url.length() <= 0)
937 #if !ENABLE(TIZEN_WEBKIT2)
938 // in case of webkit2, can not get rootView. (currently ACCELERATED_COMPOSITING is disabled)
940 LOG(Media, "%s() m_rootView is null.\n", __FUNCTION__);
947 if (!m_isEmbedVideo && hasVideo()) {
948 if (m_startedPlaying) // prevent executing external video-player twice
953 m_startedPlaying = true;
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 */
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;
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");
984 void MediaPlayerPrivate::pause()
986 LOG(Media, "%s\n", __func__);
988 m_startedPlaying = false;
990 if (m_usingExternalPlayer)
993 #if ENABLE(TIZEN_MM_PLAYER)
994 if (!m_mmPlayerHandle)
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__);
1005 m_startedPlaying = false;
1009 float MediaPlayerPrivate::duration() const
1011 // LOG(Media, "%s\n", __func__);
1013 if (m_usingExternalPlayer)
1016 #if ENABLE(TIZEN_MM_PLAYER)
1017 if (m_mmPlayerHandle) {
1018 if (m_contentDuration > 0)
1019 return (float)m_contentDuration / 1000;
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);
1027 return (float)m_contentDuration / 1000;
1033 float MediaPlayerPrivate::currentTime() const
1035 // LOG(Media, "%s\n", __func__);
1037 if (m_usingExternalPlayer)
1039 #if ENABLE(TIZEN_MM_PLAYER)
1040 if (m_isEndReached && m_contentDuration > 0)
1041 return (float)m_contentDuration / 1000;
1042 if (m_mmPlayerHandle) {
1044 int seekPosition = 0;
1045 mm_player_get_position(m_mmPlayerHandle, MM_PLAYER_POS_FORMAT_TIME, &seekPosition);
1046 ret = (float)seekPosition / 1000;
1053 void MediaPlayerPrivate::seek(float time)
1055 LOG(Media, "%s\n", __func__);
1058 #if ENABLE(TIZEN_MM_PLAYER)
1059 if (/* time <= 0.0 || */ !duration())
1061 if (time != duration()) {
1062 LOG(Media, "%s() time != duration\n", __FUNCTION__);
1063 m_isEndReached = false;
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¤t time after seeking.
1068 // To inform that the seeking is ended.
1073 void MediaPlayerPrivate::setEndTime(float time)
1075 LOG(Media, "%s\n", __func__);
1078 void MediaPlayerPrivate::startEndPointTimerIfNeeded()
1080 LOG(Media, "%s\n", __func__);
1084 void MediaPlayerPrivate::cancelSeek()
1086 LOG(Media, "%s\n", __func__);
1090 void MediaPlayerPrivate::endPointTimerFired(Timer<MediaPlayerPrivate>*)
1092 LOG(Media, "%s\n", __func__);
1096 bool MediaPlayerPrivate::paused() const
1098 LOG(Media, "%s\n", __func__);
1099 #if ENABLE(TIZEN_MM_PLAYER)
1100 if (!m_url || m_url.length() <= 0)
1102 if (hasVideo() && !m_isEmbedVideo && m_startedPlaying) // only for external video
1104 if (!m_mmPlayerHandle)
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__);
1111 if (state == MM_PLAYER_STATE_PAUSED) {
1112 LOG(Media, "MM_PLAYER_STATE_PAUSED\n");
1115 if (state == MM_PLAYER_STATE_NULL) {
1116 LOG(Media, "MM_PLAYER_STATE_NULL\n");
1119 if (state == MM_PLAYER_STATE_NONE) {
1120 LOG(Media, "MM_PLAYER_STATE_NONE\n");
1123 if (state == MM_PLAYER_STATE_PLAYING) {
1124 LOG(Media, "MM_PLAYER_STATE_PLAYING\n");
1127 if (state == MM_PLAYER_STATE_READY) {
1128 LOG(Media, "MM_PLAYER_STATE_READY\n");
1131 LOG(Media, "m_playerStatus %d\n", (int)m_playerStatus);
1133 if (m_playerStatus == MM_PLAYER_PLAY) {
1134 LOG(Media, "MM_PLAYER_PLAY\n");
1137 if (m_playerStatus == MM_PLAYER_PAUSE) {
1138 LOG(Media, "MM_PLAYER_PAUSE\n");
1141 if (m_playerStatus == MM_PLAYER_STOP) {
1142 LOG(Media, "MM_PLAYER_STOP\n");
1145 LOG(Media, "return TRUE\n");
1149 return !m_startedPlaying;
1152 bool MediaPlayerPrivate::seeking() const
1154 LOG(Media, "%s\n", __func__);
1158 // Returns the size of the video
1159 IntSize MediaPlayerPrivate::naturalSize() const
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())
1168 return IntSize(240, 180);
1169 // return IntSize(320, 240);
1172 bool MediaPlayerPrivate::hasVideo() const
1174 // LOG(Media, "%s\n", __func__);
1175 #if ENABLE(TIZEN_MM_PLAYER)
1176 HTMLMediaElement* mediaElement = static_cast<HTMLMediaElement*>(m_player->mediaPlayerClient());
1179 if (mediaElement->hasTagName(HTMLNames::videoTag))
1181 if (mediaElement->hasTagName(HTMLNames::audioTag))
1187 bool MediaPlayerPrivate::hasAudio() const
1189 // LOG(Media, "%s\n", __func__);
1193 void MediaPlayerPrivate::setVolume(float volume)
1195 LOG(Media, "%s\n", __func__);
1197 LOG_VERBOSE(Media, "Volume to %f", volume);
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__);
1215 void MediaPlayerPrivate::setMuted(bool b)
1217 LOG(Media, "%s\n", __func__);
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__);
1229 void MediaPlayerPrivate::volumeChanged()
1231 LOG(Media, "%s\n", __func__);
1235 void MediaPlayerPrivate::setRate(float rate)
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);
1246 int MediaPlayerPrivate::dataRate() const
1252 MediaPlayer::NetworkState MediaPlayerPrivate::networkState() const
1254 LOG(Media, "%s\n", __func__);
1255 return m_networkState;
1258 MediaPlayer::ReadyState MediaPlayerPrivate::readyState() const
1260 LOG(Media, "%s\n", __func__);
1261 return m_readyState;
1264 PassRefPtr<TimeRanges> MediaPlayerPrivate::buffered() const
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();
1273 float MediaPlayerPrivate::maxTimeBuffered() const
1276 // LOG_VERBOSE(Media, "maxTimeBuffered");
1277 // rtsp streams are not buffered
1278 return m_isStreaming ? 0 : maxTimeLoaded();
1281 float MediaPlayerPrivate::maxTimeSeekable() const
1283 // LOG_VERBOSE(Media, "maxTimeSeekable");
1285 return numeric_limits<float>::infinity();
1286 // infinite duration means live stream
1287 return maxTimeLoaded();
1290 float MediaPlayerPrivate::maxTimeLoaded() const
1293 // LOG_VERBOSE(Media, "maxTimeLoaded");
1294 #if ENABLE(TIZEN_MM_PLAYER)
1295 if (!m_mmPlayerHandle)
1298 // can not get buffering position in case of local file
1299 if (m_url.contains("file://"))
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);
1311 unsigned MediaPlayerPrivate::bytesLoaded() const
1314 // LOG_VERBOSE(Media, "bytesLoaded");
1315 return 1; // totalBytes() * maxTime / dur;
1318 bool MediaPlayerPrivate::totalBytesKnown() const
1320 LOG(Media, "%s\n", __func__);
1322 LOG_VERBOSE(Media, "totalBytesKnown");
1323 return totalBytes() > 0;
1326 unsigned MediaPlayerPrivate::totalBytes() const
1328 LOG(Media, "%s\n", __func__);
1330 LOG_VERBOSE(Media, "totalBytes");
1334 void MediaPlayerPrivate::cancelLoad()
1336 LOG(Media, "%s\n", __func__);
1337 #if ENABLE(TIZEN_MM_PLAYER)
1343 void MediaPlayerPrivate::updateStates()
1345 LOG(Media, "%s\n", __func__);
1347 if (m_usingExternalPlayer) {
1348 m_player->networkStateChanged();
1349 m_readyState = MediaPlayer::HaveEnoughData;
1350 m_player->readyStateChanged();
1354 MediaPlayer::NetworkState oldNetworkState = m_networkState;
1355 MediaPlayer::ReadyState oldReadyState = m_readyState;
1357 m_readyState = MediaPlayer::HaveEnoughData;
1358 m_networkState = MediaPlayer::Loaded;
1360 if (m_networkState != oldNetworkState) {
1361 LOG_VERBOSE(Media, "Network State Changed from %u to %u",
1362 oldNetworkState, m_networkState);
1363 m_player->networkStateChanged();
1366 if (m_readyState != oldReadyState) {
1367 LOG_VERBOSE(Media, "Ready State Changed from %u to %u",
1368 oldReadyState, m_readyState);
1369 m_player->readyStateChanged();
1373 void MediaPlayerPrivate::loadStateChanged()
1375 LOG(Media, "%s\n", __func__);
1379 void MediaPlayerPrivate::rateChanged()
1381 LOG(Media, "%s\n", __func__);
1385 void MediaPlayerPrivate::sizeChanged()
1387 LOG(Media, "%s\n", __func__);
1391 void MediaPlayerPrivate::timeChanged()
1393 LOG(Media, "%s\n", __func__);
1394 m_player->timeChanged();
1397 void MediaPlayerPrivate::didEnd()
1399 LOG(Media, "%s\n", __func__);
1401 m_isEndReached = true;
1406 void MediaPlayerPrivate::loadingFailed()
1408 LOG(Media, "%s\n", __func__);
1410 if (m_networkState != MediaPlayer::NetworkError) {
1411 m_networkState = MediaPlayer::NetworkError;
1412 m_player->networkStateChanged();
1414 if (m_readyState != MediaPlayer::HaveNothing) {
1415 m_readyState = MediaPlayer::HaveNothing;
1416 m_player->readyStateChanged();
1418 #if ENABLE(TIZEN_MM_PLAYER)
1423 void MediaPlayerPrivate::setSize(const IntSize& size)
1428 void MediaPlayerPrivate::setVisible(bool visible)
1430 m_visible = visible;
1432 #if ENABLE(TIZEN_MM_PLAYER)
1433 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
1434 if (!m_isEmbedVideo)
1438 LOG(Media, "%s() hide embed icons\n", __FUNCTION__);
1439 hideEmbedPlayIcon();
1440 hideEmbedLoadingIcon();
1442 if (getStatus() != MM_PLAYER_PLAY) {
1443 LOG(Media, "%s() show play icon\n", __FUNCTION__);
1444 showEmbedPlayIcon();
1451 void MediaPlayerPrivate::repaint()
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));
1459 #if ENABLE(TIZEN_WEBKIT2)
1460 if (hasVideo() && supportsAcceleratedRendering())
1461 m_platformLayer->setContentsToMedia(this);
1465 m_player->repaint();
1468 void MediaPlayerPrivate::paint(GraphicsContext* context, const IntRect& rect)
1470 // LOG(Media, "%s\n", __func__);
1471 // LOG(Media, "rect(%d, %d, %d, %d)\n", rect.x(), rect.y(), rect.width(), rect.height());
1473 if (context->paintingDisabled()) {
1474 LOG(Media, "disabled\n");
1478 #if ENABLE(TIZEN_WAC_CAMERA_SUPPORT)
1480 HTMLMediaElement* mediaElement = static_cast<HTMLMediaElement*>(m_player->mediaPlayerClient());
1481 CameraManager* cameramManager = 0;
1483 if (mediaElement && mediaElement->getCamera()) {
1484 cameramManager = mediaElement->getCamera();
1486 if (!cameramManager->getStreamBuffer())
1490 cairo_surface_t* surface;
1491 cairo_format_t cairoFormat = CAIRO_FORMAT_ARGB32;
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(),
1498 if (cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) {
1499 LOG(Media, "%s : Error cairo_surface_status\n", __FUNCTION__);
1505 int widthForDisplay = 0;
1506 int heightForDisplay = 0;
1508 widthForDisplay = rect.width();
1509 heightForDisplay = cameramManager->getHeight() * rect.width() / cameramManager->getWidth();
1511 if (heightForDisplay > rect.height()) {
1512 widthForDisplay = widthForDisplay * rect.height() / heightForDisplay;
1513 heightForDisplay = rect.height();
1516 posX = rect.x() + (rect.width() - widthForDisplay) / 2;
1517 posY = rect.y() + (rect.height() - heightForDisplay) / 2;
1519 cairo_t* cr = context->platformContext()->cr();
1521 cairo_translate(cr, posX, posY);
1522 cairo_rectangle(cr, 0, 0, cameramManager->getWidth(), cameramManager->getHeight());
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);
1532 cairo_surface_destroy(surface);
1537 if (!m_player->visible())
1540 #if ENABLE(TIZEN_MM_PLAYER)
1542 repaintVideoCanvas();
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;
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);
1559 cairo_set_source_surface(cr, btImage, x, y);
1562 cairo_surface_destroy(btImage);
1565 cairo_t* cr = context->platformContext()->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);
1576 static HashSet<String> mimeTypeCache()
1578 LOG(Media, "%s\n", __func__);
1579 static HashSet<String> cache;
1580 static bool typeListInitialized = false;
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"));
1614 void MediaPlayerPrivate::getSupportedTypes(HashSet<String>& types)
1616 LOG(Media, "%s\n", __func__);
1617 types = mimeTypeCache();
1620 MediaPlayer::SupportsType MediaPlayerPrivate::supportsType(const String& type, const String& codecs)
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());
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;
1635 bool MediaPlayerPrivate::supportsFullscreen() const
1637 LOG(Media, "%s\n", __func__);
1638 #if ENABLE(TIZEN_MM_PLAYER)
1646 #if ENABLE(TIZEN_MM_PLAYER)
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
1652 IntSize contentSize(m_contentWidth, m_contentHeight);
1654 if (!m_videoTexture)
1655 m_videoTexture = textureMapper->createTexture();
1657 if (m_textureSize != contentSize) {
1658 m_textureSize.setWidth(m_contentWidth);
1659 m_textureSize.setHeight(m_contentHeight);
1660 m_videoTexture->reset(m_textureSize, false);
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;
1669 TextureMapperGL* texmapGL = static_cast<TextureMapperGL*>(textureMapper);
1670 texmapGL->drawTexture(*m_videoTexture.get(), targetRect, matrix, opacity, mask);
1673 PlatformLayer* MediaPlayerPrivate::platformLayer() const
1675 return const_cast<MediaPlayerPrivate*>(this);
1678 bool MediaPlayerPrivate::supportsAcceleratedRendering() const
1683 void MediaPlayerPrivate::acceleratedRenderingStateChanged()
1688 MediaPlayerClient* client = m_player->mediaPlayerClient();
1692 bool composited = client->mediaPlayerRenderingCanBeAccelerated(m_player);
1693 if (composited == m_acceleratedCompositing)
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);
1704 PlatformLayer* MediaPlayerPrivate::platformLayer() const
1706 return m_acceleratedCompositing ? m_platformLayer.get() : 0;
1708 #endif // USE(TIZEN_TEXTURE_MAPPER)
1710 void MediaPlayerPrivate::setVideoRect()
1712 HTMLMediaElement* mediaElement = static_cast<HTMLMediaElement*>(m_player->mediaPlayerClient());
1713 if (!mediaElement || !mediaElement->renderer())
1716 RenderBox* renderer = toRenderBox(mediaElement->renderer());
1720 int x = renderer->offsetLeft();
1721 int y = renderer->offsetTop();
1722 int w = renderer->offsetWidth();
1723 int h = renderer->offsetHeight();
1727 m_frame.setWidth(w);
1728 m_frame.setHeight(h);
1731 void MediaPlayerPrivate::fillVideoRect()
1733 LOG(Media, "%s()\n", __FUNCTION__);
1738 // make minunum buffer to fill video rect black
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__);
1747 memset(m_frameBuffer, 0, bufLength);
1748 setNeedsUpdate(true);
1751 showEmbedPlayIcon();
1754 void MediaPlayerPrivate::showEmbedPlayIcon()
1756 LOG(Media, "%s()\n", __FUNCTION__);
1758 if (!m_player || !m_player->frameView() || !m_rootView)
1760 if (!m_isEmbedVideo || !hasVideo())
1762 if (m_bufferingProgressbar || m_bufferingProgressbarBg)
1766 if (m_frame.location() == IntPoint(0, 0)) {
1767 LOG(Media, "%s() m_frame.location() is not set yet.\n", __FUNCTION__);
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);
1779 IntRect rect = m_player->frameView()->contentsToScreen(m_frame);
1781 evas_object_geometry_get(m_rootView, &x, &y, 0, 0);
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);
1790 void MediaPlayerPrivate::hideEmbedPlayIcon()
1793 evas_object_smart_member_del(m_playIcon);
1794 evas_object_hide(m_playIcon);
1795 evas_object_del(m_playIcon);
1801 void MediaPlayerPrivate::internalPlay()
1803 LOG(Media, "%s\n", __func__);
1805 m_playerStatus = MM_PLAYER_STOP;
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();
1814 LOG(Media, "%s(): gPlayer = %p\n", __FUNCTION__, gPlayer);
1818 addAudioHandle(this);
1820 m_startCalled = false;
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__);
1828 mm_session_init(MM_SESSION_TYPE_SHARE);
1830 initializeVideoPlayer();
1831 if (mm_player_realize(m_mmPlayerHandle) != MM_ERROR_NONE) {
1832 LOG(Media, "%s return error from mm_player_realize\n", __FUNCTION__);
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__);
1841 m_startCalled = true;
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__);
1850 // set initial volume & loop
1851 HTMLMediaElement* mediaElement = static_cast<HTMLMediaElement*>(m_player->mediaPlayerClient());
1853 setVolume(mediaElement->volume());
1854 if (mediaElement->loop()) {
1856 int err = MM_ERROR_NONE;
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__);
1868 showEmbedLoadingIcon();
1871 void MediaPlayerPrivate::catchMouseDown()
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);
1881 void MediaPlayerPrivate::catchMouseUp()
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;
1891 void MediaPlayerPrivate::videoUpdateStart()
1893 LOG(Media, "%s\n", __func__);
1895 return; /* use video update timer when only video element. */
1896 if (!m_mmPlayerHandle) {
1900 if (m_embedVideoUpdateTimer > 0)
1901 ecore_timer_thaw(m_embedVideoUpdateTimer);
1903 m_embedVideoUpdateTimer = ecore_timer_add(VIDEO_FPS, timerEmbedInvalidateRect, this);
1904 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
1905 hideEmbedPlayIcon();
1909 void MediaPlayerPrivate::videoUpdatePause()
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();
1920 void MediaPlayerPrivate::videoUpdateStop()
1922 LOG(Media, "%s\n", __func__);
1923 if (m_embedVideoUpdateTimer > 0) {
1924 ecore_timer_del(m_embedVideoUpdateTimer);
1925 m_embedVideoUpdateTimer = 0;
1929 void MediaPlayerPrivate::enterFullscreen()
1931 LOG(Media, "%s\n", __func__);
1934 LOG(Media, "%s(): destroy gPlayer %p\n", __FUNCTION__, gPlayer);
1935 gPlayer->setStatus(MM_PLAYER_STOP);
1937 gPlayer->stopInternal(true);
1941 struct _HTML5Video html5video;
1943 html5video.path = (char*)malloc(m_url.utf8().length() + 1);
1944 if (!html5video.path) {
1945 LOG(Media, "%s() malloc fail!\n", __FUNCTION__);
1948 memcpy(html5video.path, m_url.utf8().data(), m_url.utf8().length() + 1);
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);
1956 #if !ENABLE(TIZEN_WEBKIT2)
1957 // webkit1: use evas callback call
1958 evas_object_smart_callback_call(m_rootView, "html5video,request", &html5video);
1960 // webkit2: use webkit2 callback
1961 m_player->frameView()->frame()->loader()->client()->postProcessHTML5Video(m_url, String(html5video.cookie));
1964 free(html5video.path);
1966 if (html5video.cookie)
1967 g_free(html5video.cookie);
1970 void MediaPlayerPrivate::exitFullscreen()
1972 LOG(Media, "%s\n", __func__);
1975 bool MediaPlayerPrivate::setContentSize(IntSize sizeContent)
1978 int err = MM_ERROR_NONE;
1980 if (!m_mmPlayerHandle)
1983 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
1984 setNeedsUpdate(false);
1987 int width = sizeContent.width();
1988 int height = sizeContent.height();
1990 if (width > MAX_VIDEO_SIZE) {
1991 height = MAX_VIDEO_SIZE * height / width;
1992 width = MAX_VIDEO_SIZE;
1994 if (height > MAX_VIDEO_SIZE) {
1995 width = MAX_VIDEO_SIZE * width / height;
1996 height = MAX_VIDEO_SIZE;
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);
2003 err = mm_player_set_attribute(m_mmPlayerHandle, &pErrName,
2004 "display_width", width,
2005 "display_height", height,
2007 if (err != MM_ERROR_NONE) {
2008 LOG(Media, "%s failed mm_player_set_attribute\n", __FUNCTION__);
2017 void MediaPlayerPrivate::setVideoBuffer(IntSize sizeBuffer)
2019 LOG(Media, "%s() %d, %d\n", __FUNCTION__, sizeBuffer.width(), sizeBuffer.height());
2021 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
2022 setNeedsUpdate(false);
2025 if (m_frameBuffer) {
2026 free(m_frameBuffer);
2030 m_contentWidth = sizeBuffer.width();
2031 m_contentHeight = sizeBuffer.height();
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__);
2038 memset(m_frameBuffer, 0, m_contentWidth * m_contentHeight * 4);
2041 void MediaPlayerPrivate::stop()
2043 LOG(Media, "%s url = %s\n", __FUNCTION__, m_url.utf8().data());
2044 setStatus(MM_PLAYER_STOP);
2046 hideEmbedLoadingIcon();
2047 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
2048 hideEmbedPlayIcon();
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);
2060 if (ewkCallbackPauseOrResumeRoot)
2061 delEwkCallback(m_rootView, "html5video,pauseresume", callbackPauseOrResume, &ewkCallbackPauseOrResumeRoot, this);
2064 destroyEmbedPlayer();
2067 void MediaPlayerPrivate::stopInternal(bool force)
2069 LOG(Media, "%s:%d url = %s duration:%d\n", __FUNCTION__, __LINE__, m_url.utf8().data(), m_contentDuration);
2071 hideEmbedLoadingIcon();
2072 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
2073 showEmbedPlayIcon();
2076 HTMLMediaElement* mediaElement = static_cast<HTMLMediaElement*>(m_player->mediaPlayerClient());
2079 if (mediaElement->loop()) {
2082 setStatus(MM_PLAYER_PLAY);
2086 m_contentDuration = 0;
2087 if (m_mmPlayerHandle)
2088 ecore_timer_add(0.0, timerEmbedStop, this);
2092 MediaPlayer::MovieLoadType MediaPlayerPrivate::movieLoadType() const
2094 LOG(Media, "%s\n", __func__);
2095 if (m_url.contains("rtsp://")) {
2096 LOG(Media, "MediaPlayer::LiveStream\n");
2097 return MediaPlayer::LiveStream;
2099 if (m_url.contains("file://")) {
2100 LOG(Media, "MediaPlayer::StoredStream\n");
2101 return MediaPlayer::StoredStream;
2103 if (m_url.contains("http://")) {
2104 LOG(Media, "MediaPlayer::Download\n");
2105 return MediaPlayer::StoredStream;
2107 return MediaPlayer::Unknown;
2110 /* for buffering, only http connection */
2111 void MediaPlayerPrivate::showEmbedLoadingIcon()
2113 // LOG(Media, "%s\n", __func__);
2114 if (!hasVideo() || !m_player->frameView() || !m_rootView)
2117 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
2118 hideEmbedPlayIcon();
2121 if (m_frame.location() == IntPoint(0, 0)) {
2122 LOG(Media, "%s() m_frame.location() is not set yet.\n", __FUNCTION__);
2127 /* in case of localfile, can not catch the timing to hide progressbar.*/
2128 if (m_url.contains("file://"))
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);
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);
2143 if (!m_frame.isEmpty()) {
2144 IntRect m_rect = m_player->frameView()->contentsToScreen(m_frame);
2145 if (m_rect.isEmpty())
2148 evas_object_geometry_get(m_rootView, &x, &y, 0, 0);
2150 int progressX, progressY;
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);
2157 evas_object_resize(m_bufferingProgressbar, EVAS_ICON_SIZE, EVAS_ICON_SIZE);
2158 evas_object_resize(m_bufferingProgressbarBg, EVAS_ICON_SIZE, EVAS_ICON_SIZE);
2160 if (m_playerStatus == MM_PLAYER_PLAY)
2161 m_player->repaint();
2163 evas_object_resize(m_bufferingProgressbar, EVAS_ICON_SIZE, EVAS_ICON_SIZE);
2164 evas_object_resize(m_bufferingProgressbarBg, EVAS_ICON_SIZE, EVAS_ICON_SIZE);
2167 evas_object_show(m_bufferingProgressbarBg);
2168 evas_object_show(m_bufferingProgressbar);
2171 void MediaPlayerPrivate::hideEmbedLoadingIcon()
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;
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;
2188 /* panning by webkit */
2189 void MediaPlayerPrivate::smartCalculate()
2192 repaintVideoCanvas();
2196 void MediaPlayerPrivate::setZoomWeak(void* data)
2198 if (!m_url || m_url.length() <= 0)
2200 if (!m_player || !m_player->frameView())
2203 ZoomData* zd = (ZoomData*)data;
2207 if (!m_bufferingProgressbar && !m_playIcon)
2210 int progressX, progressY;
2212 // block panning operation during zooming
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;
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;
2227 if (m_bufferingProgressbar) {
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);
2239 progressX = clipperX + (clipperW - EVAS_ICON_SIZE) / 2;
2240 progressY = clipperY + (clipperH - EVAS_ICON_SIZE) / 2;
2241 evas_object_move(m_playIcon, progressX, progressY);
2245 /* end of zoom by webkit*/
2246 void MediaPlayerPrivate::setZoom(void* data)
2248 LOG(Media, "%s()\n", __FUNCTION__);
2250 m_isZooming = false;
2252 ZoomData* zd = (ZoomData*) data;
2256 m_zoomRatio = zd->zoom;
2257 IntRect rect = m_frame;
2258 rect.scale(m_zoomRatio);
2259 setContentSize(rect.size());
2262 void MediaPlayerPrivate::pauseOrResume(bool bPause)
2264 LOG(Media, "%s() pause: %d\n", __FUNCTION__, bPause);
2266 HTMLMediaElement* mediaElement = static_cast<HTMLMediaElement*>(m_player->mediaPlayerClient());
2267 if (!mediaElement) {
2268 LOG(Media, "%s() mediaElement == NULL\n", __FUNCTION__);
2271 if (bPause && getStatus() == MM_PLAYER_PLAY) {
2272 UserGestureIndicator gestureIndicator(DefinitelyProcessingUserGesture);
2273 mediaElement->pause();
2275 if (m_resumeVideoTimer) {
2276 ecore_timer_del(m_resumeVideoTimer);
2277 m_resumeVideoTimer = 0;
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;
2288 void MediaPlayerPrivate::repaintVideoCanvas()
2290 if (!m_player || !m_player->frameView() || !m_rootView)
2293 if (!m_bufferingProgressbar && !m_playIcon)
2297 int progressX, progressY;
2299 evas_object_geometry_get(m_rootView, &x, &y, 0, 0);
2300 IntRect m_rect = m_player->frameView()->contentsToScreen(m_frame);
2303 if (m_bufferingProgressbar) {
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);
2311 if (m_bufferingProgressbarBg)
2312 evas_object_move(m_bufferingProgressbarBg, progressX, progressY);
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);
2322 /* setting for MM-Player */
2323 int MediaPlayerPrivate::initializeVideoPlayer()
2325 LOG(Media, "%s\n", __func__);
2328 int err = MM_ERROR_NONE;
2330 if (!m_mmPlayerHandle) {
2331 LOG(Media, "%s() ERROR! m_mmPlayerHandle == NULL\n", __FUNCTION__);
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());
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());
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(),
2346 if (err != MM_ERROR_NONE) {
2347 LOG(Media, "%s mm_player_set_attribute = %d\n", __FUNCTION__, err);
2349 LOG(Media, "%s return error from mm_player_set_attribute (%s)\n", __FUNCTION__, pErrName);
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);
2362 LOG(Media, "embed player cookies=%s\n", cookies);
2363 err = mm_player_set_attribute(m_mmPlayerHandle, &pErrName,
2364 "streaming_cookie", cookies, strlen(cookies),
2366 if (err != MM_ERROR_NONE) {
2367 LOG(Media, "%s mm_player_set_attribute = %d\n", __FUNCTION__, err);
2369 LOG(Media, "%s return error from mm_player_set_attribute (%s)\n", __FUNCTION__, pErrName);
2378 #if ENABLE(TIZEN_SET_PROXY)
2380 char* pureProxyURI = 0;
2381 g_object_get(session, SOUP_SESSION_PROXY_URI, &proxy, (void*)0);
2383 WTF::String proxyURI = soupURIToKURL(proxy).string();
2384 if (proxyURI.contains("/"))
2385 proxyURI.replace("/", "");
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;
2392 pureProxyURI = (char*)proxyURI.utf8().data();
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),
2398 soup_uri_free(proxy);
2399 if (err != MM_ERROR_NONE) {
2400 LOG(Media, "%s mm_player_set_attribute = %d\n", __FUNCTION__, err);
2402 LOG(Media, "%s return error from mm_player_set_attribute (%s)\n", __FUNCTION__, pErrName);
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,
2417 if (err != MM_ERROR_NONE) {
2418 LOG(Media, "%s mm_player_set_attribute = %d\n", __FUNCTION__, err);
2425 mm_player_set_message_callback(m_mmPlayerHandle, callbackAudioMessage, this);
2427 if (!m_size.isEmpty()) {
2428 IntSize size = m_size;
2429 size.scale(m_zoomRatio);
2430 setContentSize(size);
2432 LOG(Media, "%s() m_size.isEmpty()\n", __FUNCTION__);
2433 setContentSize(naturalSize());
2435 mm_player_set_message_callback(m_mmPlayerHandle, callbackEmbedVideoMessage, this);
2436 mm_player_set_video_stream_callback(m_mmPlayerHandle, callbackEmbedVideoFrame, this);
2438 if (err != MM_ERROR_NONE) {
2439 LOG(Media, "%s mm_player_set_attribute = %d\n", __FUNCTION__, err);
2441 LOG(Media, "%s return error from mm_player_set_attribute (%s)\n", __FUNCTION__, pErrName);
2450 void MediaPlayerPrivate::destroyEmbedPlayer()
2452 LOG(Media, "%s\n", __func__);
2455 HTMLMediaElement* mediaElement = static_cast<HTMLMediaElement*>(m_player->mediaPlayerClient());
2457 LOG(Media, "%s() pause media.\n", __FUNCTION__);
2458 mediaElement->pause();
2461 m_delayingLoad = true;
2462 delAudioHandle(this);
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();
2469 if (m_readyState != MediaPlayer::HaveNothing) {
2470 m_readyState = MediaPlayer::HaveNothing;
2471 m_player->readyStateChanged();
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();
2483 m_mmPlayerHandle = 0;
2485 if (m_frameBuffer) {
2486 free(m_frameBuffer);
2490 m_contentHeight = 0;
2493 void MediaPlayerPrivate::recvMsgPaused()
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
2501 setStatus(MM_PLAYER_PAUSE);
2504 void MediaPlayerPrivate::setMediaReady()
2506 LOG(Media, "%s()\n", __FUNCTION__);
2509 #endif // TIZEN_MM_PLAYER