Fix lock up issue in TizenWinset widget
[framework/web/webkit-efl.git] / Source / WebCore / html / HTMLMediaElement.cpp
index c2e2bed..118c94d 100755 (executable)
 #include "TizenExtensibleAPI.h"
 #endif
 
-#if ENABLE(TIZEN_DEVICE_ROTATION)
-#include <vconf.h>
+#if ENABLE(TIZEN_GSTREAMER_VIDEO)
+#include <power.h>
 #endif
 
 using namespace std;
@@ -160,18 +160,6 @@ static const char* boolString(bool val)
 static const char* mediaSourceURLProtocol = "x-media-source";
 #endif
 
-#if ENABLE(TIZEN_DEVICE_ROTATION)
-#define RADIAN_VALUE (57.2957)
-
-enum {
-    ROTATE_0,
-    ROTATE_90,
-    ROTATE_180,
-    ROTATE_270,
-    ROTATE_ERROR
-};
-#endif
-
 using namespace HTMLNames;
 using namespace std;
 
@@ -289,9 +277,6 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document* docum
 #if ENABLE(TIZEN_GSTREAMER_VIDEO)
     , m_suspended(false)
 #endif
-#if ENABLE(TIZEN_DEVICE_ROTATION)
-    , m_rotation(ROTATE_0)
-#endif
 {
     LOG(Media, "HTMLMediaElement::HTMLMediaElement");
     document->registerForMediaVolumeCallbacks(this);
@@ -309,8 +294,9 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document* docum
 
     setHasCustomCallbacks();
     addElementToDocumentMap(this, document);
-#if ENABLE(TIZEN_DEVICE_ROTATION)
-    registerRotationCallback();
+
+#if ENABLE(TIZEN_GSTREAMER_AUDIO)
+    document->incrementActiveMediaObjectCount();
 #endif
 }
 
@@ -335,92 +321,15 @@ HTMLMediaElement::~HTMLMediaElement()
         m_mediaController->removeMediaElement(this);
 
     removeElementFromDocumentMap(this, document());
-#if ENABLE(TIZEN_DEVICE_ROTATION)
-    unregisterRotationCallback();
-#endif
-}
-
-#if ENABLE(TIZEN_DEVICE_ROTATION)
-bool HTMLMediaElement::isHorizontal()
-{
-    return (m_rotation == ROTATE_90 || m_rotation == ROTATE_270) ? true : false;
-}
-
-bool HTMLMediaElement::isVertical()
-{
-    return (m_rotation == ROTATE_0 || m_rotation == ROTATE_180) ? true : false;
-}
-
-void HTMLMediaElement::registerRotationCallback()
-{
-    sensor_create(&m_handle);
-    sensor_accelerometer_set_cb(m_handle, 0, onRotationChanged, this);
-    sensor_start(m_handle, SENSOR_ACCELEROMETER);
-
-    return;
-}
-
-void HTMLMediaElement::unregisterRotationCallback()
-{
-    sensor_accelerometer_unset_cb(m_handle);
-    sensor_stop(m_handle, SENSOR_ACCELEROMETER);
-    sensor_destroy(m_handle);
 
-    return;
-}
-
-int HTMLMediaElement::calcRotation(float x, float y, float z)
-{
-    double atanV, normZ, rawZ;
-    int accTheta, accPitch;
-    int rotation;
-
-    atanV = atan2(y, x);
-    accTheta = (int)(atanV * (RADIAN_VALUE) + 270) % 360;
-    rawZ = (double)(z / (0.004 * 9.81));
-
-    if (rawZ > 250)
-        normZ = 1.0;
-    else if (rawZ < -250)
-        normZ = -1.0;
-    else
-        normZ = ((double)rawZ) / 250;
-
-    accPitch = (int)(acos(normZ) * (RADIAN_VALUE));
-
-    if ((accPitch > 35) && (accPitch < 145)) {
-        if ((accTheta >= 315 && accTheta <= 359) || (accTheta >= 0 && accTheta < 45))
-            rotation = ROTATE_0;
-        else if (accTheta >= 45 && accTheta < 135)
-            rotation = ROTATE_90;
-        else if (accTheta >= 135 && accTheta < 225)
-            rotation = ROTATE_180;
-        else if (accTheta >= 225 && accTheta < 315)
-            rotation = ROTATE_270;
-        else
-            rotation = ROTATE_ERROR;
-    } else
-        rotation = ROTATE_ERROR;
-
-    return rotation;
-}
-
-void HTMLMediaElement::onRotationChanged(uint64_t timeStamp, sensor_data_accuracy_e accuracy, float x, float y, float z, void* userData)
-{
-    HTMLMediaElement* that = static_cast<HTMLMediaElement*>(userData);
-
-    int autoRotation = 0;
-    vconf_get_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &autoRotation);
-    if (!autoRotation)
-        return;
-
-    int rotation = that->calcRotation(x, y, z);
-    if (rotation == ROTATE_ERROR || rotation == that->m_rotation)
-        return;
+    m_completelyLoaded = true;
+    if (m_player)
+        m_player->clearMediaPlayerClient();
 
-    that->m_rotation = rotation;
-}
+#if ENABLE(TIZEN_GSTREAMER_AUDIO)
+    document()->decrementActiveMediaObjectCount();
 #endif
+}
 
 void HTMLMediaElement::didMoveToNewDocument(Document* oldDocument)
 {
@@ -473,7 +382,7 @@ void HTMLMediaElement::parseAttribute(const Attribute& attribute)
     else if (attribute.name() == loopAttr)
         updateDisableSleep();
 #endif
-#if ENABLE(TIZEN_MEDIA_STREAM)
+#if ENABLE(TIZEN_GSTREAMER_AUDIO)
     else if (attribute.name() == mutedAttr)
             m_muted = true;
 #endif
@@ -628,6 +537,10 @@ Node::InsertionNotificationRequest HTMLMediaElement::insertedInto(ContainerNode*
     HTMLElement::insertedInto(insertionPoint);
     if (insertionPoint->inDocument() && !getAttribute(srcAttr).isEmpty() && m_networkState == NETWORK_EMPTY)
         scheduleLoad(MediaResource);
+
+#if ENABLE(TIZEN_GSTREAMER_VIDEO)
+    resume();
+#endif
     configureMediaControls();
     return InsertionDone;
 }
@@ -638,7 +551,11 @@ void HTMLMediaElement::removedFrom(ContainerNode* insertionPoint)
         LOG(Media, "HTMLMediaElement::removedFromDocument");
         configureMediaControls();
         if (m_networkState > NETWORK_EMPTY)
+#if ENABLE(TIZEN_GSTREAMER_VIDEO)
+            suspend(PageWillBeSuspended);
+#else
             pause();
+#endif
         if (m_isFullscreen)
             exitFullscreen();
     }
@@ -1102,9 +1019,15 @@ void HTMLMediaElement::loadResource(const KURL& initialURL, ContentType& content
 
     if (!autoplay())
         m_player->setPreload(m_preload);
+#if ENABLE(TIZEN_GSTREAMER_VIDEO)
+    else {
+        if (isVideo())
+            power_lock_state(POWER_STATE_NORMAL, 0);
+    }
+#endif
     m_player->setPreservesPitch(m_webkitPreservesPitch);
 
-#if !ENABLE(TIZEN_MEDIA_STREAM)
+#if !ENABLE(TIZEN_GSTREAMER_AUDIO)
     if (fastHasAttribute(mutedAttr))
         m_muted = true;
     updateVolume();
@@ -1113,7 +1036,7 @@ void HTMLMediaElement::loadResource(const KURL& initialURL, ContentType& content
     if (!m_player->load(url, contentType, keySystem))
         mediaLoadingFailed(MediaPlayer::FormatError);
 
-#if ENABLE(TIZEN_MEDIA_STREAM)
+#if ENABLE(TIZEN_GSTREAMER_AUDIO)
     updateVolume();
 #endif
 
@@ -1621,6 +1544,10 @@ void HTMLMediaElement::mediaEngineError(PassRefPtr<MediaError> err)
 
     // 6 - Abort the overall resource selection algorithm.
     m_currentSourceNode = 0;
+#if ENABLE(TIZEN_GSTREAMER_VIDEO)
+    if (isVideo())
+        power_unlock_state(POWER_STATE_NORMAL);
+#endif
 }
 
 void HTMLMediaElement::cancelPendingEventsAndCallbacks()
@@ -1704,6 +1631,10 @@ void HTMLMediaElement::mediaLoadingFailed(MediaPlayer::NetworkState error)
 
     if (document()->page() && document()->page()->settings()->diagnosticLoggingEnabled())
         document()->page()->chrome()->client()->logDiagnosticMessage(DiagnosticLoggingKeys::mediaLoadingFailedKey(), stringForNetworkState(error), DiagnosticLoggingKeys::failKey());
+#if ENABLE(TIZEN_GSTREAMER_VIDEO)
+    if (isVideo())
+        power_unlock_state(POWER_STATE_NORMAL);
+#endif
 }
 
 void HTMLMediaElement::setNetworkState(MediaPlayer::NetworkState state)
@@ -2447,6 +2378,10 @@ void HTMLMediaElement::play()
             return;
     }
 
+#if ENABLE(TIZEN_GSTREAMER_VIDEO)
+    if (isVideo())
+        power_lock_state(POWER_STATE_NORMAL, 0);
+#endif
     playInternal();
 }
 
@@ -2489,6 +2424,10 @@ void HTMLMediaElement::pause()
     if (userGestureRequiredForRateChange() && !ScriptController::processingUserGesture())
         return;
 
+#if ENABLE(TIZEN_GSTREAMER_VIDEO)
+    if (isVideo())
+        power_unlock_state(POWER_STATE_NORMAL);
+#endif
     pauseInternal();
 }
 
@@ -3988,6 +3927,10 @@ void HTMLMediaElement::stop()
 
     stopPeriodicTimers();
     cancelPendingEventsAndCallbacks();
+#if ENABLE(TIZEN_GSTREAMER_VIDEO)
+    if (isVideo())
+        power_unlock_state(POWER_STATE_NORMAL);
+#endif
 }
 
 void HTMLMediaElement::suspend(ReasonForSuspension why)
@@ -4197,6 +4140,10 @@ void HTMLMediaElement::enterFullscreen()
 #if ENABLE(FULLSCREEN_API)
     if (document() && document()->settings() && document()->settings()->fullScreenEnabled()) {
         document()->requestFullScreenForElement(this, 0, Document::ExemptIFrameAllowFullScreenRequirement);
+#if ENABLE(TIZEN_FULLSCREEN_API)
+        if (hasMediaControls())
+            mediaControls()->updateMediaControlScale();
+#endif
         return;
     }
 #endif
@@ -4234,6 +4181,17 @@ void HTMLMediaElement::exitFullscreen()
     }
 }
 
+#if ENABLE(TIZEN_FULLSCREEN_API)
+void HTMLMediaElement::updateMediaControlsStyle(bool needsRecalc)
+{
+    if (hasMediaControls())
+        mediaControls()->updateMediaControlScale();
+
+    if (needsRecalc)
+        recalcStyle(Node::Force);
+}
+#endif
+
 void HTMLMediaElement::didBecomeFullscreenElement()
 {
     if (hasMediaControls())
@@ -4430,6 +4388,10 @@ bool HTMLMediaElement::createMediaControls()
 
     controls->setMediaController(m_mediaController ? m_mediaController.get() : static_cast<MediaControllerInterface*>(this));
     controls->reset();
+#if ENABLE(TIZEN_FULLSCREEN_API)
+    if (isFullscreen())
+        controls->updateMediaControlScale();
+#endif
     if (isFullscreen())
         controls->enteredFullscreen();
 
@@ -4827,13 +4789,15 @@ bool HTMLMediaElement::shouldSuspendMedia()
     if (!m_player)
         return false;
 
-    if (isVideo())
+    if (isVideo() || hasVideo())
         return true;
 
 #if ENABLE(TIZEN_EXTENSIBLE_API)
     if (!TizenExtensibleAPI::extensibleAPI().backgroundMusic())
         return true;
 #endif
+
+    return false;
 }
 
 void HTMLMediaElement::setSuspended(bool suspended)