X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=Source%2FWebCore%2Fplatform%2Fgraphics%2Fgstreamer%2FMediaPlayerPrivateGStreamer.cpp;h=07f6508c0a7a9eb29f3b3787a0be4683d7230b59;hb=00999621743928894cc34d330270ee6e500186b2;hp=4f373d8c20b3c32a2026befd6b570fb7d61a342a;hpb=abbb72c83e3455b4ddcb3239b2cd23e013dcce4f;p=framework%2Fweb%2Fwebkit-efl.git diff --git a/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp index 4f373d8..07f6508 100755 --- a/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp +++ b/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp @@ -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(callbackData); + HTMLMediaElement* element = static_cast(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(callbackData); + HTMLMediaElement* element = static_cast(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 } } @@ -774,7 +795,12 @@ IntSize MediaPlayerPrivateGStreamer::naturalSize() const } LOG_MEDIA_MESSAGE("Natural size: %" G_GUINT64_FORMAT "x%" G_GUINT64_FORMAT, width, height); - m_videoSize = IntSize(static_cast(width), static_cast(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()) + m_videoSize = scaleHDVideoToDisplaySize(static_cast(width), static_cast(height), m_displaySize.width(), m_displaySize.height()); + else +#endif + m_videoSize = IntSize(static_cast(width), static_cast(height)); return m_videoSize; } @@ -795,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() @@ -1067,19 +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) { - seek(m_suspendTime); + HTMLMediaElement* element = static_cast(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(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; @@ -1483,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); @@ -1494,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) @@ -1708,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(); @@ -1731,13 +1768,15 @@ void MediaPlayerPrivateGStreamer::didEnd() HTMLMediaElement* element = static_cast(player()->mediaPlayerClient()); if (element->isVideo()) power_unlock_state(POWER_STATE_NORMAL); - #endif } } void MediaPlayerPrivateGStreamer::cacheDuration() { +#if ENABLE(TIZEN_GSTREAMER_VIDEO) + float previousDuration = m_mediaDuration; +#endif // Reset cached media duration m_mediaDuration = 0; @@ -1746,6 +1785,19 @@ void MediaPlayerPrivateGStreamer::cacheDuration() gst_element_get_state(m_playBin.get(), &state, 0, 0); float newDuration = duration(); +#if ENABLE(TIZEN_GSTREAMER_VIDEO) + if (state > GST_STATE_READY) { + // Don't set m_mediaDurationKnown yet if the pipeline is not + // paused. This allows duration() query to fail at least once + // before playback starts and duration becomes known. + m_mediaDurationKnown = !isinf(newDuration); + } + + if (!isinf(newDuration)) + m_mediaDuration = newDuration; + else + m_mediaDuration = previousDuration; +#else if (state <= GST_STATE_READY) { // Don't set m_mediaDurationKnown yet if the pipeline is not // paused. This allows duration() query to fail at least once @@ -1760,6 +1812,7 @@ void MediaPlayerPrivateGStreamer::cacheDuration() if (!isinf(newDuration)) m_mediaDuration = newDuration; +#endif } void MediaPlayerPrivateGStreamer::durationChanged() @@ -1966,7 +2019,9 @@ static HashSet mimeTypeCache() "video/ogg", "video/quicktime", "video/vivo", +#if !ENABLE(TIZEN_GSTREAMER_VIDEO) "video/webm", +#endif "video/x-cdxa", "video/x-dirac", "video/x-dv", @@ -2263,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 @@ -2305,21 +2357,72 @@ void MediaPlayerPrivateGStreamer::paintCurrentFrameInContext(GraphicsContext* co m_videoLayer->paintCurrentFrameInContext(context, rect); } +#if USE(ACCELERATED_VIDEO_VAAPI) +// Other device doesn't prefer such optimization, so enclose it in USE(ACCELERATED_VIDEO_VAAPI) macro +IntSize MediaPlayerPrivateGStreamer::scaleHDVideoToDisplaySize(int videoWidth, int videoHeight, int displayWidth, int displayHeight) const +{ + int fitWidth, fitHeight; + +#if ENABLE(TIZEN_DLOG_SUPPORT) + TIZEN_LOGI("videoWidth: %d, videoHeight: %d, displayWidth: %d, displayHeight: %d ", videoWidth, videoHeight, displayWidth, displayHeight); +#endif + fitWidth = videoWidth; + fitHeight = videoHeight; + if (displayWidth > 0 && displayHeight > 0) { + // In case video is rotated, we always use a 'better' + // orientation (landscape or portrait) to calculate fitWidth/fitHeight. + // It means we use a bigger size which doesn't lose quality + // in either landscape or portrait orientation + if ((videoWidth > videoHeight && displayWidth < displayHeight) + || (videoWidth < videoHeight && displayWidth > displayHeight)) { + int tmp; + tmp = displayWidth; + displayWidth = displayHeight; + displayHeight = tmp; + } + + if (videoWidth > displayWidth || videoHeight > displayHeight) { + if (videoWidth * displayHeight > videoHeight * displayWidth) { + fitWidth = displayWidth; + fitHeight = videoHeight * displayWidth / videoWidth; + ASSERT(fitHeight <= displayHeight); + } else { + fitWidth = videoWidth * displayHeight / videoHeight; + fitHeight = displayHeight; + ASSERT(fitWidth <= displayWidth); + } + } + } + + return IntSize(fitWidth, fitHeight); +} +#endif void MediaPlayerPrivateGStreamer::xWindowIdPrepared(GstMessage* message) { - int width; - int height; - gst_structure_get_int(message->structure, "video-width", &width); - gst_structure_get_int(message->structure, "video-height", &height); + // 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); #if ENABLE(TIZEN_DLOG_SUPPORT) - TIZEN_LOGI("Width: %d, Height: %d", width, height); + TIZEN_LOGI("videoWidth: %d, videoHeight: %d", videoWidth, videoHeight); #endif - IntSize size(width, height); - m_videoSize = size; - m_videoLayer->setOverlay(size); +#if USE(ACCELERATED_VIDEO_VAAPI) + 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 + m_videoSize = IntSize(videoWidth, videoHeight); +#endif + m_videoLayer->setOverlay(m_videoSize); } + #endif // ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE) #endif // ENABLE(TIZEN_ACCELERATED_COMPOSITING) && USE(TIZEN_TEXTURE_MAPPER) @@ -2356,14 +2459,29 @@ void MediaPlayerPrivateGStreamer::suspend() void MediaPlayerPrivateGStreamer::resume() { - gst_element_set_state(m_playBin.get(), GST_STATE_PAUSED); + if (isLocalMediaStream()) { + gst_element_set_state(m_playBin.get(), GST_STATE_PLAYING); #if ENABLE(TIZEN_GSTREAMER_AUDIO) - if (m_audioSessionManager) - m_audioSessionManager->setSoundState(ASM_STATE_PAUSE); + if (m_audioSessionManager) + m_audioSessionManager->setSoundState(ASM_STATE_PLAYING); +#endif + } else { + gst_element_set_state(m_playBin.get(), GST_STATE_PAUSED); +#if ENABLE(TIZEN_GSTREAMER_AUDIO) + if (m_audioSessionManager) + m_audioSessionManager->setSoundState(ASM_STATE_PAUSE); #endif + } } -#endif +bool MediaPlayerPrivateGStreamer::isLocalMediaStream() +{ + if (m_url.string().contains("camera://")) + return true; + else + return false; +} +#endif // ENABLE(TIZEN_GSTREAMER_VIDEO) }