/*
- * Copyright (c) 2018 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.
#include <cstring>
#include <dali/public-api/object/type-registry.h>
#include <dali/public-api/object/type-registry-helper.h>
-#include <dali/public-api/common/stage.h>
#include <dali/devel-api/scripting/scripting.h>
+#include <dali/devel-api/adaptor-framework/window-devel.h>
#include <dali/public-api/adaptor-framework/native-image-source.h>
-#include <dali/integration-api/adaptors/adaptor.h>
#include <dali/integration-api/debug.h>
#include <dali/public-api/animation/constraint.h>
#include <dali/devel-api/actors/actor-devel.h>
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/controls/video-view/video-view.h>
#include <dali-toolkit/internal/visuals/visual-factory-cache.h>
+#include <dali/integration-api/adaptor-framework/adaptor.h>
+#include <dali-toolkit/internal/controls/control/control-data-impl.h>
namespace Dali
{
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
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
} // 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();
}
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;
}
void VideoView::OnInitialize()
{
mVideoPlayer.FinishedSignal().Connect( this, &VideoView::EmitSignalFinish );
+
+ DevelControl::SetAccessibilityConstructor( Self(), []( Dali::Actor actor ) {
+ return std::unique_ptr< Dali::Accessibility::Accessible >(
+ new Control::Impl::AccessibleImpl( actor, Dali::Accessibility::Role::VIDEO ));
+ } );
}
void VideoView::SetUrl( const std::string& url )
void VideoView::Play()
{
- if( mOverlayRenderer )
- {
- Self().AddRenderer( mOverlayRenderer );
- }
-
mVideoPlayer.Play();
mIsPlay = true;
}
void VideoView::EmitSignalFinish()
{
- if( mOverlayRenderer )
- {
- Self().RemoveRenderer( mOverlayRenderer );
- }
-
if ( !mFinishedSignal.Empty() )
{
Dali::Toolkit::VideoView handle( GetOwner() );
}
}
-void VideoView::OnStageConnection( int depth )
+void VideoView::OnSceneConnection( int depth )
{
- Control::OnStageConnection( depth );
+ Control::OnSceneConnection( depth );
if( mIsUnderlay )
{
}
}
-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()
{
Actor self = Self();
- if( !self.OnStage() )
+ if( !self.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) )
{
// When the control is off the stage, it does not have Window.
return;
mOverlayRenderer = Renderer::New( geometry, shader );
mOverlayRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF );
}
+ Self().AddRenderer( mOverlayRenderer );
if( mIsPlay )
{
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;
}
Actor self( Self() );
- bool positionUsesAnchorPoint = self.GetProperty( DevelActor::Property::POSITION_USES_ANCHOR_POINT ).Get< bool >();
- Vector3 actorSize = self.GetCurrentSize() * self.GetCurrentScale();
- Vector3 anchorPointOffSet = actorSize * ( positionUsesAnchorPoint ? self.GetCurrentAnchorPoint() : AnchorPoint::TOP_LEFT );
+ bool positionUsesAnchorPoint = self.GetProperty( Actor::Property::POSITION_USES_ANCHOR_POINT ).Get< bool >();
+ Vector3 actorSize = self.GetCurrentProperty< Vector3 >( Actor::Property::SIZE ) * self.GetCurrentProperty< Vector3 >( Actor::Property::SCALE );
+ Vector3 anchorPointOffSet = actorSize * ( positionUsesAnchorPoint ? self.GetCurrentProperty< Vector3 >( Actor::Property::ANCHOR_POINT ) : AnchorPoint::TOP_LEFT );
- Vector2 screenPosition = self.GetProperty( DevelActor::Property::SCREEN_POSITION ).Get< Vector2 >();
+ Vector2 screenPosition = self.GetProperty( Actor::Property::SCREEN_POSITION ).Get< Vector2 >();
mDisplayArea.x = screenPosition.x - anchorPointOffSet.x;
mDisplayArea.y = screenPosition.y - anchorPointOffSet.y;
return static_cast< int >( mVideoPlayer.GetDisplayMode() );
}
+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";
}
}
+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