From b3636da16f13873c444b913df7bc6acf5b9dacb8 Mon Sep 17 00:00:00 2001 From: Jiyun Yang Date: Thu, 11 Jul 2019 14:34:50 +0900 Subject: [PATCH] Fix VideoView to work in multi-window Change-Id: Iee8738a904e8c835c291ff8d465488e6a7d4ea62 Signed-off-by: Jiyun Yang --- .../dali-toolkit-test-utils/toolkit-adaptor.cpp | 5 + .../controls/video-view/video-view-impl.cpp | 186 +++++++++++++-------- .../internal/controls/video-view/video-view-impl.h | 11 ++ 3 files changed, 130 insertions(+), 72 deletions(-) diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-adaptor.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-adaptor.cpp index 63bacde..9071613 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-adaptor.cpp +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-adaptor.cpp @@ -241,6 +241,11 @@ Any Adaptor::GetNativeWindowHandle() return window; } +Any Adaptor::GetNativeWindowHandle( Actor actor ) +{ + return GetNativeWindowHandle(); +} + void Adaptor::ReleaseSurfaceLock() { } 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 93ce5a3..dfd441b 100755 --- a/dali-toolkit/internal/controls/video-view/video-view-impl.cpp +++ b/dali-toolkit/internal/controls/video-view/video-view-impl.cpp @@ -157,7 +157,6 @@ Toolkit::VideoView VideoView::New() void VideoView::OnInitialize() { mVideoPlayer.FinishedSignal().Connect( this, &VideoView::EmitSignalFinish ); - SetWindowSurfaceTarget(); } void VideoView::SetUrl( const std::string& url ) @@ -228,7 +227,7 @@ bool VideoView::IsLooping() void VideoView::Play() { - if( mIsUnderlay ) + if( mOverlayRenderer ) { Self().AddRenderer( mOverlayRenderer ); } @@ -295,7 +294,7 @@ Dali::Toolkit::VideoView::VideoViewSignalType& VideoView::FinishedSignal() void VideoView::EmitSignalFinish() { - if( mIsUnderlay ) + if( mOverlayRenderer ) { Self().RemoveRenderer( mOverlayRenderer ); } @@ -378,91 +377,103 @@ bool VideoView::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* return connected; } -void VideoView::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ) +void VideoView::SetPropertyInternal( Property::Index index, const Property::Value& value ) { - Toolkit::VideoView videoView = Toolkit::VideoView::DownCast( Dali::BaseHandle( object ) ); - - if( videoView ) + switch( index ) { - VideoView& impl = GetImpl( videoView ); - - switch( index ) + case Toolkit::VideoView::Property::VIDEO: { - case Toolkit::VideoView::Property::VIDEO: - { - std::string videoUrl; - Property::Map map; + std::string videoUrl; + Property::Map map; - if( value.Get( videoUrl ) ) - { - impl.SetUrl( videoUrl ); - } - else if( value.Get( map ) ) - { - impl.SetPropertyMap( map ); - } - break; + if( value.Get( videoUrl ) ) + { + SetUrl( videoUrl ); } - case Toolkit::VideoView::Property::LOOPING: + else if( value.Get( map ) ) { - bool looping; - if( value.Get( looping ) ) - { - impl.SetLooping( looping ); - } - break; + SetPropertyMap( map ); } - case Toolkit::VideoView::Property::MUTED: + break; + } + case Toolkit::VideoView::Property::LOOPING: + { + bool looping; + if( value.Get( looping ) ) { - bool mute; - if( value.Get( mute ) ) - { - impl.SetMute( mute ); - } - break; + SetLooping( looping ); } - case Toolkit::VideoView::Property::VOLUME: + break; + } + case Toolkit::VideoView::Property::MUTED: + { + bool mute; + if( value.Get( mute ) ) { - Property::Map map; - float left, right; - if( value.Get( map ) ) - { - Property::Value* volumeLeft = map.Find( VOLUME_LEFT ); - Property::Value* volumeRight = map.Find( VOLUME_RIGHT ); - if( volumeLeft && volumeLeft->Get( left ) && volumeRight && volumeRight->Get( right ) ) - { - impl.SetVolume( left, right ); - } - } - break; + SetMute( mute ); } - case Toolkit::VideoView::Property::UNDERLAY: + break; + } + case Toolkit::VideoView::Property::VOLUME: + { + Property::Map map; + float left, right; + if( value.Get( map ) ) { - bool underlay; - if( value.Get( underlay ) ) + Property::Value* volumeLeft = map.Find( VOLUME_LEFT ); + Property::Value* volumeRight = map.Find( VOLUME_RIGHT ); + if( volumeLeft && volumeLeft->Get( left ) && volumeRight && volumeRight->Get( right ) ) { - impl.SetUnderlay( underlay ); + SetVolume( left, right ); } - break; } - case Toolkit::VideoView::Property::PLAY_POSITION: + break; + } + case Toolkit::VideoView::Property::UNDERLAY: + { + bool underlay; + if( value.Get( underlay ) ) { - int pos; - if( value.Get( pos ) ) - { - impl.SetPlayPosition( pos ); - } - break; + SetUnderlay( underlay ); } - case Toolkit::VideoView::Property::DISPLAY_MODE: + break; + } + case Toolkit::VideoView::Property::PLAY_POSITION: + { + int pos; + if( value.Get( pos ) ) { - int mode; - if( value.Get( mode ) ) - { - impl.SetDisplayMode( mode ); - } - break; + SetPlayPosition( pos ); } + break; + } + case Toolkit::VideoView::Property::DISPLAY_MODE: + { + int mode; + if( value.Get( mode ) ) + { + SetDisplayMode( mode ); + } + break; + } + } +} + +void VideoView::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ) +{ + Toolkit::VideoView videoView = Toolkit::VideoView::DownCast( Dali::BaseHandle( object ) ); + + if( videoView ) + { + VideoView& impl = GetImpl( videoView ); + + impl.SetPropertyInternal( index, value ); + + if( index != Toolkit::VideoView::Property::UNDERLAY ) + { + // Backup values. + // These values will be used when underlay mode is changed. + impl.mPropertyBackup[index] = value; } } } @@ -543,6 +554,11 @@ void VideoView::SetDepthIndex( int depthIndex ) void VideoView::OnStageConnection( int depth ) { Control::OnStageConnection( depth ); + + if( mIsUnderlay ) + { + SetWindowSurfaceTarget(); + } } void VideoView::OnStageDisconnection() @@ -594,6 +610,13 @@ float VideoView::GetWidthForHeight( float height ) void VideoView::SetWindowSurfaceTarget() { Actor self = Self(); + + if( !self.OnStage() ) + { + // When the control is off the stage, it does not have Window. + return; + } + int curPos = mVideoPlayer.GetPlayPosition(); if( mIsPlay ) @@ -613,8 +636,10 @@ void VideoView::SetWindowSurfaceTarget() self.RemoveRenderer( mTextureRenderer ); } - mVideoPlayer.SetRenderingTarget( Dali::Adaptor::Get().GetNativeWindowHandle() ); - mVideoPlayer.SetUrl( mUrl ); + // Note VideoPlayer::SetRenderingTarget resets all the options. (e.g. url, mute, looping) + mVideoPlayer.SetRenderingTarget( Dali::Adaptor::Get().GetNativeWindowHandle( self ) ); + + ApplyBackupProperties(); if( !mOverlayRenderer ) { @@ -655,6 +680,8 @@ void VideoView::SetNativeImageTarget() if( mOverlayRenderer ) { self.RemoveRenderer( mOverlayRenderer ); + + mOverlayRenderer.Reset(); } self.RemovePropertyNotification( mPositionUpdateNotification ); @@ -684,8 +711,10 @@ void VideoView::SetNativeImageTarget() } Self().AddRenderer( mTextureRenderer ); + // Note VideoPlayer::SetRenderingTarget resets all the options. (e.g. url, mute, looping) mVideoPlayer.SetRenderingTarget( nativeImageSourcePtr ); - mVideoPlayer.SetUrl( mUrl ); + + ApplyBackupProperties(); if( mIsPlay ) { @@ -835,6 +864,19 @@ bool VideoView::GetStringFromProperty( const Dali::Property::Value& value, std:: return extracted; } +void VideoView::ApplyBackupProperties() +{ + Property::Map::SizeType pos = 0; + Property::Map::SizeType count = mPropertyBackup.Count(); + + for( ; pos < count; pos++ ) + { + KeyValuePair property = mPropertyBackup.GetKeyValue( pos ); + + SetPropertyInternal( property.first.indexKey, property.second ); + } +} + } // namespace Internal } // namespace toolkit diff --git a/dali-toolkit/internal/controls/video-view/video-view-impl.h b/dali-toolkit/internal/controls/video-view/video-view-impl.h index bed7c9f..44695bb 100755 --- a/dali-toolkit/internal/controls/video-view/video-view-impl.h +++ b/dali-toolkit/internal/controls/video-view/video-view-impl.h @@ -316,6 +316,16 @@ private: */ bool GetStringFromProperty( const Dali::Property::Value& value, std::string& output ); + /* + * @brief Internal version of SetProperty + */ + void SetPropertyInternal( Property::Index index, const Property::Value& value ); + + /* + * @brief Apply properties after reset video player + */ + void ApplyBackupProperties(); + private: Dali::VideoPlayer mVideoPlayer; @@ -331,6 +341,7 @@ private: Dali::PropertyNotification mPositionUpdateNotification; Dali::PropertyNotification mSizeUpdateNotification; Dali::PropertyNotification mScaleUpdateNotification; + Dali::Property::Map mPropertyBackup; int mCurrentVideoPlayPosition; bool mIsPlay; -- 2.7.4