X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fvideo-view%2Fvideo-view-impl.cpp;h=9f6fc31631a4440cbbd3518cfceca18a7afe80e4;hp=cb5bfcdc02bfa6c44262d5dd01710dadf2a4f8c8;hb=8a647e87a01c5c78451653c1264a9eea81ac9b20;hpb=fca202af829a0657805e44461f08f284cdbf0bbb diff --git a/dali-toolkit/internal/controls/video-view/video-view-impl.cpp b/dali-toolkit/internal/controls/video-view/video-view-impl.cpp index cb5bfcd..9f6fc31 100755 --- a/dali-toolkit/internal/controls/video-view/video-view-impl.cpp +++ b/dali-toolkit/internal/controls/video-view/video-view-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,8 +22,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -33,6 +33,7 @@ #include #include #include +#include namespace Dali { @@ -88,7 +89,7 @@ const char* const CUSTOM_SAMPLER_TYPE_NAME( "samplerExternalOES" ); const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( attribute mediump vec2 aPosition;\n uniform highp mat4 uMvpMatrix;\n - uniform mediump vec3 uSize;\n + uniform highp vec3 uSize;\n \n void main()\n {\n @@ -110,7 +111,7 @@ const char* VERTEX_SHADER_TEXTURE = DALI_COMPOSE_SHADER( attribute mediump vec2 aPosition;\n varying mediump vec2 vTexCoord;\n uniform highp mat4 uMvpMatrix;\n - uniform mediump vec3 uSize;\n + uniform highp vec3 uSize;\n varying mediump vec2 sTexCoordRect;\n void main()\n {\n @@ -131,26 +132,33 @@ const char* FRAGMENT_SHADER_TEXTURE = DALI_COMPOSE_SHADER( } // anonymous namepsace -VideoView::VideoView() +VideoView::VideoView( Dali::VideoSyncMode syncMode ) : Control( ControlBehaviour( ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS ) ), mCurrentVideoPlayPosition( 0 ), + mFrameID( 0 ), mIsPlay( false ), - mIsUnderlay( true ) + mIsUnderlay( true ), + mSyncMode( syncMode ) { - mVideoPlayer = Dali::VideoPlayer::New(); + DevelControl::SetAccessibilityConstructor( Self(), []( Dali::Actor actor ) + { + return std::unique_ptr< Dali::Accessibility::Accessible >( + new Control::Impl::AccessibleImpl( actor, Dali::Accessibility::Role::VIDEO, true ) ); + } + ); } VideoView::~VideoView() { } -Toolkit::VideoView VideoView::New() +Toolkit::VideoView VideoView::New( VideoSyncMode syncMode ) { - VideoView* impl = new VideoView(); + VideoView* impl = new VideoView( syncMode ); Toolkit::VideoView handle = Toolkit::VideoView( *impl ); + impl->mVideoPlayer = Dali::VideoPlayer::New( impl->Self(), syncMode ); impl->Initialize(); - return handle; } @@ -227,11 +235,6 @@ bool VideoView::IsLooping() void VideoView::Play() { - if( mOverlayRenderer ) - { - Self().AddRenderer( mOverlayRenderer ); - } - mVideoPlayer.Play(); mIsPlay = true; } @@ -294,11 +297,6 @@ Dali::Toolkit::VideoView::VideoViewSignalType& VideoView::FinishedSignal() void VideoView::EmitSignalFinish() { - if( mOverlayRenderer ) - { - Self().RemoveRenderer( mOverlayRenderer ); - } - if ( !mFinishedSignal.Empty() ) { Dali::Toolkit::VideoView handle( GetOwner() ); @@ -551,9 +549,9 @@ void VideoView::SetDepthIndex( int depthIndex ) } } -void VideoView::OnStageConnection( int depth ) +void VideoView::OnSceneConnection( int depth ) { - Control::OnStageConnection( depth ); + Control::OnSceneConnection( depth ); if( mIsUnderlay ) { @@ -561,9 +559,19 @@ void VideoView::OnStageConnection( int depth ) } } -void VideoView::OnStageDisconnection() +void VideoView::OnSceneDisconnection() +{ + Control::OnSceneDisconnection(); +} + +void VideoView::OnSizeSet( const Vector3& targetSize ) { - Control::OnStageDisconnection(); + if( mIsUnderlay && mSyncMode == Dali::VideoSyncMode::ENABLED ) + { + SetFrameRenderCallback(); + mVideoPlayer.StartSynchronization(); + } + Control::OnSizeSet( targetSize ); } Vector3 VideoView::GetNaturalSize() @@ -649,6 +657,7 @@ void VideoView::SetWindowSurfaceTarget() mOverlayRenderer = Renderer::New( geometry, shader ); mOverlayRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF ); } + Self().AddRenderer( mOverlayRenderer ); if( mIsPlay ) { @@ -729,7 +738,9 @@ void VideoView::SetNativeImageTarget() void VideoView::UpdateDisplayArea( Dali::PropertyNotification& source ) { - if( !mIsUnderlay ) + // If mSyncMode is enabled, Video player's size and poistion is updated in Video player's constraint. + // Because video view and player should be work syncronization. + if( !mIsUnderlay || mSyncMode == Dali::VideoSyncMode::ENABLED ) { return; } @@ -813,6 +824,22 @@ Any VideoView::GetMediaPlayer() return mVideoPlayer.GetMediaPlayer(); } +void VideoView::OnAnimationFinished( Animation& animation ) +{ + // send desync + SetFrameRenderCallback(); +} + +void VideoView::PlayAnimation( Dali::Animation animation ) +{ + if( mIsUnderlay && mSyncMode == Dali::VideoSyncMode::ENABLED ) + { + mVideoPlayer.StartSynchronization(); + animation.FinishedSignal().Connect( this, &VideoView::OnAnimationFinished ); + } + animation.Play(); +} + Dali::Shader VideoView::CreateShader() { std::string fragmentShader = "#extension GL_OES_EGL_image_external:require\n"; @@ -882,6 +909,23 @@ void VideoView::ApplyBackupProperties() } } +void VideoView::FrameRenderCallback( int frameID ) +{ + // send desync + if( frameID == mFrameID ) + { + mVideoPlayer.FinishSynchronization(); + mFrameID = 0; + } +} + +void VideoView::SetFrameRenderCallback() +{ + mFrameID++; + DevelWindow::AddFrameRenderedCallback( DevelWindow::Get( Self() ), + std::unique_ptr< CallbackBase >( MakeCallback( this, &VideoView::FrameRenderCallback ) ), mFrameID ); +} + } // namespace Internal } // namespace toolkit