Fix the issue that audio is not played after resuming.
[framework/web/webkit-efl.git] / Source / WebCore / platform / graphics / gstreamer / MediaPlayerPrivateGStreamer.cpp
index 660d8f9..07f6508 100755 (executable)
@@ -240,20 +240,23 @@ static GstBusSyncReply mediaPlayerPrivateSyncHandler(GstBus* bus, GstMessage* me
 static ASM_cb_result_t MediaPlayerAudioSessionEventSourcePause(ASM_event_sources_t eventSource, void* callbackData)
 {
     MediaPlayer* player = static_cast<MediaPlayer*>(callbackData);
+    HTMLMediaElement* element = static_cast<HTMLMediaElement*>(player->mediaPlayerClient());
+
     if (!player)
         return ASM_CB_RES_IGNORE;
 
     switch (eventSource) {
     case ASM_EVENT_SOURCE_CALL_START:
     case ASM_EVENT_SOURCE_ALARM_START:
-    case ASM_EVENT_SOURCE_EARJACK_UNPLUG:
     case ASM_EVENT_SOURCE_MEDIA:
     case ASM_EVENT_SOURCE_EMERGENCY_START:
     case ASM_EVENT_SOURCE_OTHER_PLAYER_APP:
     case ASM_EVENT_SOURCE_RESOURCE_CONFLICT:
-        if (player->hasAudio())
-            player->pause();
-        return ASM_CB_RES_PAUSE;
+    case ASM_EVENT_SOURCE_EARJACK_UNPLUG:
+        if (!player->url().string().contains("camera://")) {
+            element->pause();
+            return ASM_CB_RES_PAUSE;
+        }
     default:
         return ASM_CB_RES_NONE;
     }
@@ -262,13 +265,15 @@ static ASM_cb_result_t MediaPlayerAudioSessionEventSourcePause(ASM_event_sources
 static ASM_cb_result_t MediaPlayerAudioSessionEventSourcePlay(ASM_event_sources_t eventSource, void* callbackData)
 {
     MediaPlayer* player = static_cast<MediaPlayer*>(callbackData);
+    HTMLMediaElement* element = static_cast<HTMLMediaElement*>(player->mediaPlayerClient());
+
     if (!player)
         return ASM_CB_RES_IGNORE;
 
     switch (eventSource) {
     case ASM_EVENT_SOURCE_ALARM_END:
-        if (!player->hasVideo()) {
-            player->play();
+        if (!element->isVideo() && !player->url().string().contains("camera://")) {
+            element->play();
             return ASM_CB_RES_PLAYING;
         }
         return ASM_CB_RES_NONE;
@@ -412,13 +417,13 @@ MediaPlayerPrivateGStreamer::~MediaPlayerPrivateGStreamer()
         m_playBin = 0;
     }
 
+    m_player = 0;
+
 #if ENABLE(TIZEN_GSTREAMER_AUDIO)
     if (m_audioSessionManager)
         m_audioSessionManager->setSoundState(ASM_STATE_STOP);
 #endif
 
-    m_player = 0;
-
     if (m_muteTimerHandler)
         g_source_remove(m_muteTimerHandler);
 
@@ -459,6 +464,18 @@ void MediaPlayerPrivateGStreamer::load(const String& url)
 
     LOG_MEDIA_MESSAGE("Load %s", cleanUrl.utf8().data());
 
+#if ENABLE(TIZEN_MEDIA_STREAM)
+    // Workaround modification for getUserMedia.
+    // When 'playing' event is fired videoWidth and videoHeight are not available.
+    // Set m_videoSize as frame size which comes from webkitCameraSource.
+    // This size is fixed.
+    if (isLocalMediaStream())
+        if (gst_element_factory_find("camerasrc"))
+            m_videoSize = IntSize(480, 640);
+        else
+            m_videoSize = IntSize(640, 480);
+#endif
+
     if (m_preload == MediaPlayer::None) {
         LOG_MEDIA_MESSAGE("Delaying load.");
         m_delayingLoad = true;
@@ -577,7 +594,7 @@ void MediaPlayerPrivateGStreamer::prepareToPlay()
 void MediaPlayerPrivateGStreamer::play()
 {
 #if ENABLE(TIZEN_GSTREAMER_AUDIO)
-    if (m_audioSessionManager && !m_audioSessionManager->setSoundState(ASM_STATE_PLAYING))
+    if (!m_audioSessionManager->setSoundState(ASM_STATE_PLAYING) && !isLocalMediaStream())
         return;
 #endif
     if (changePipelineState(GST_STATE_PLAYING)) {
@@ -589,7 +606,7 @@ void MediaPlayerPrivateGStreamer::play()
 void MediaPlayerPrivateGStreamer::pause()
 {
 #if ENABLE(TIZEN_GSTREAMER_AUDIO)
-    if (m_audioSessionManager && !m_audioSessionManager->setSoundState(ASM_STATE_PAUSE))
+    if (!m_audioSessionManager->setSoundState(ASM_STATE_PAUSE) && !isLocalMediaStream())
         return;
 #endif
     if (m_isEndReached)
@@ -698,6 +715,10 @@ void MediaPlayerPrivateGStreamer::seek(float time)
     } else {
         m_seeking = true;
         m_seekTime = time;
+#if ENABLE(TIZEN_GSTREAMER_VIDEO)
+        if (m_seekTime != m_mediaDuration)
+            m_isEndReached = false;
+#endif
     }
 }
 
@@ -775,7 +796,7 @@ IntSize MediaPlayerPrivateGStreamer::naturalSize() const
 
     LOG_MEDIA_MESSAGE("Natural size: %" G_GUINT64_FORMAT "x%" G_GUINT64_FORMAT, width, height);
 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING) && USE(TIZEN_TEXTURE_MAPPER) && ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE) && USE(ACCELERATED_VIDEO_VAAPI)
-    if(!m_displaySize.isEmpty())
+    if (!m_displaySize.isEmpty())
         m_videoSize = scaleHDVideoToDisplaySize(static_cast<int>(width), static_cast<int>(height), m_displaySize.width(), m_displaySize.height());
     else
 #endif
@@ -800,20 +821,24 @@ void MediaPlayerPrivateGStreamer::notifyPlayerOfVideo()
 
     m_hasVideo = videoTracks > 0;
 
-#if ENABLE(TIZEN_ACCELERATED_COMPOSITING) && USE(TIZEN_TEXTURE_MAPPER) && ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
-    int width;
-    int height;
+#if ENABLE(TIZEN_GSTREAMER_VIDEO)
+    int width, height;
     if (gst_video_get_size(m_videoSinkPad.get(), &width, &height)) {
         IntSize size(width, height);
         if (m_videoSize != size) {
             m_videoSize = IntSize();
+#if ENABLE(TIZEN_ACCELERATED_COMPOSITING) && USE(TIZEN_TEXTURE_MAPPER) && ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
             m_videoLayer->setOverlay(naturalSize());
+#endif
         }
     }
-#endif
+
+    m_player->mediaPlayerClient()->mediaPlayerEngineUpdated(m_player);
+#else // ENABLE(TIZEN_GSTREAMER_VIDEO)
     m_videoSize = IntSize();
 
     m_player->mediaPlayerClient()->mediaPlayerEngineUpdated(m_player);
+#endif
 }
 
 void MediaPlayerPrivateGStreamer::audioChanged()
@@ -1072,20 +1097,13 @@ gboolean MediaPlayerPrivateGStreamer::handleMessage(GstMessage* message)
             GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS(GST_BIN(m_playBin.get()), GST_DEBUG_GRAPH_SHOW_ALL, dotFileName.data());
 
 #if ENABLE(TIZEN_GSTREAMER_VIDEO)
-            if (m_suspendTime > 0 && newState == GST_STATE_PAUSED) {
-                if (!isLocalMediaStream())
+            HTMLMediaElement* element = static_cast<HTMLMediaElement*>(player()->mediaPlayerClient());
+            if (element->suspended() && newState == GST_STATE_PAUSED) {
+                if (m_suspendTime > 0 && !(isLocalMediaStream() || m_isEndReached))
                     seek(m_suspendTime);
                 m_suspendTime = 0;
                 m_player->mediaPlayerClient()->setSuspended(false);
             }
-
-            HTMLMediaElement* element = static_cast<HTMLMediaElement*>(player()->mediaPlayerClient());
-            if (element->isVideo()) {
-                if (oldState == GST_STATE_PAUSED && newState == GST_STATE_PLAYING)
-                    power_lock_state(POWER_STATE_NORMAL, 0);
-                else if (oldState == GST_STATE_PLAYING && newState == GST_STATE_PAUSED)
-                    power_unlock_state(POWER_STATE_NORMAL);
-            }
 #endif
         }
         break;
@@ -1489,7 +1507,12 @@ void MediaPlayerPrivateGStreamer::updateStates()
         // On-disk buffering was attempted but the media is live. This
         // can't work so disable on-disk buffering and reset the
         // pipeline.
+
+#if ENABLE(TIZEN_MEDIA_STREAM)
+        if (state == GST_STATE_READY && isLiveStream() && m_preload == MediaPlayer::Auto && !isLocalMediaStream()) {
+#else
         if (state == GST_STATE_READY && isLiveStream() && m_preload == MediaPlayer::Auto) {
+#endif
             setPreload(MediaPlayer::None);
             gst_element_set_state(m_playBin.get(), GST_STATE_NULL);
             gst_element_set_state(m_playBin.get(), GST_STATE_PAUSED);
@@ -1500,7 +1523,11 @@ void MediaPlayerPrivateGStreamer::updateStates()
         }
 
         // A live stream was paused, reset the pipeline.
+#if ENABLE(TIZEN_MEDIA_STREAM)
+        if (state == GST_STATE_PAUSED && pending == GST_STATE_PLAYING && isLiveStream() && !isLocalMediaStream()) {
+#else
         if (state == GST_STATE_PAUSED && pending == GST_STATE_PLAYING && isLiveStream()) {
+#endif
             gst_element_set_state(m_playBin.get(), GST_STATE_NULL);
             gst_element_set_state(m_playBin.get(), GST_STATE_PLAYING);
 #if ENABLE(TIZEN_GSTREAMER_AUDIO)
@@ -1714,7 +1741,11 @@ void MediaPlayerPrivateGStreamer::didEnd()
     // HTMLMediaElement. In some cases like reverse playback the
     // position is not always reported as 0 for instance.
     float now = currentTime();
+#if ENABLE(TIZEN_GSTREAMER_VIDEO)
+    if (now > 0 && now != duration()) {
+#else
     if (now > 0 && now <= duration() && m_mediaDuration != now) {
+#endif
         m_mediaDurationKnown = true;
         m_mediaDuration = now;
         m_player->durationChanged();
@@ -1737,7 +1768,6 @@ void MediaPlayerPrivateGStreamer::didEnd()
         HTMLMediaElement* element = static_cast<HTMLMediaElement*>(player()->mediaPlayerClient());
         if (element->isVideo())
             power_unlock_state(POWER_STATE_NORMAL);
-
 #endif
     }
 }
@@ -1989,7 +2019,9 @@ static HashSet<String> mimeTypeCache()
         "video/ogg",
         "video/quicktime",
         "video/vivo",
+#if !ENABLE(TIZEN_GSTREAMER_VIDEO)
         "video/webm",
+#endif
         "video/x-cdxa",
         "video/x-dirac",
         "video/x-dv",
@@ -2286,16 +2318,13 @@ void MediaPlayerPrivateGStreamer::createGSTPlayBin()
         g_object_set(m_playBin.get(), "video-sink", fakeSink, NULL);
     }
 #endif
-
-#if ENABLE(TIZEN_GSTREAMER_AUDIO)
-    if (m_audioSessionManager)
-        m_audioSessionManager->registerAudioSessionManager(MM_SESSION_TYPE_SHARE, mediaPlayerPrivateAudioSessionNotifyCallback, player());
-#endif
-
 #if ENABLE(TIZEN_GSTREAMER_AUDIO)
     GstElement* realSink = gst_element_factory_make("avsysaudiosink", 0);
     g_object_set(realSink, "close-handle-on-prepare", 1, NULL);
     g_object_set(m_playBin.get(), "audio-sink", realSink, NULL);
+
+    if (m_audioSessionManager)
+        m_audioSessionManager->registerAudioSessionManager(MM_SESSION_TYPE_SHARE, mediaPlayerPrivateAudioSessionNotifyCallback, player());
 #else
     createAudioSink();
 #endif
@@ -2370,8 +2399,10 @@ IntSize MediaPlayerPrivateGStreamer::scaleHDVideoToDisplaySize(int videoWidth, i
 #endif
 void MediaPlayerPrivateGStreamer::xWindowIdPrepared(GstMessage* message)
 {
-    int videoWidth, videoHeight;
+    // It is called in streaming thread.
+    // It should be used only to set window handle to video sink.
 
+    int videoWidth, videoHeight;
     gst_structure_get_int(message->structure, "video-width", &videoWidth);
     gst_structure_get_int(message->structure, "video-height", &videoHeight);
 
@@ -2383,6 +2414,7 @@ void MediaPlayerPrivateGStreamer::xWindowIdPrepared(GstMessage* message)
     int displayWidth, displayHeight;
     gst_structure_get_int(message->structure, "display-width", &displayWidth);
     gst_structure_get_int(message->structure, "display-height", &displayHeight);
+
     m_displaySize = IntSize(displayWidth, displayHeight);
     m_videoSize = scaleHDVideoToDisplaySize(videoWidth, videoHeight, displayWidth, displayHeight);
 #else