[dali_2.3.19] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / video-view / video-view-impl.h
index 5f85a3f..c8b2a83 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_INTERNAL_VIDEO_VIEW_H
 
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
  */
 
 // EXTERNAL INCLUDES
-#include <dali/public-api/object/property-map.h>
-#include <dali/public-api/images/native-image.h>
 #include <dali/devel-api/adaptor-framework/video-player.h>
-#include <dali/integration-api/adaptors/trigger-event-factory.h>
-#include <dali/public-api/object/property-notification.h>
+#include <dali/devel-api/adaptor-framework/video-sync-mode.h>
+#include <dali/integration-api/adaptor-framework/trigger-event-factory.h>
+#include <dali/public-api/adaptor-framework/window.h>
+#include <dali/public-api/images/image-operations.h>
 #include <dali/public-api/object/property-conditions.h>
+#include <dali/public-api/object/property-map.h>
+#include <dali/public-api/object/property-notification.h>
+#include <dali/public-api/rendering/renderer.h>
+#include <dali/public-api/rendering/texture.h>
 
 // INTERNAL INCLUDES
-#include <dali-toolkit/internal/visuals/image/image-visual.h>
 #include <dali-toolkit/public-api/controls/control-impl.h>
 #include <dali-toolkit/public-api/controls/video-view/video-view.h>
 
 namespace Dali
 {
-
 namespace Toolkit
 {
-
 class VideoView;
 
 namespace Internal
 {
-
-class VideoView: public Control
+class VideoView : public Control
 {
 protected:
-
-  VideoView();
+  VideoView(Dali::VideoSyncMode syncMode);
 
   virtual ~VideoView();
 
 public:
-
   /**
-   * @copydoc Toolkit::VideoView::New()
+   * @copydoc Toolkit::DevelVideoView::New()
    */
-  static Toolkit::VideoView New();
+  static Toolkit::VideoView New(VideoSyncMode syncMode);
 
   /**
    * @brief Sets a video url to play.
@@ -63,7 +61,7 @@ public:
    * @SINCE_1_1.38
    * @param [in] url The url of the video resource to play
    */
-  void SetUrl( const std::string& url );
+  void SetUrl(const std::string& url);
 
   /**
    * @brief Returns a video url.
@@ -106,19 +104,19 @@ public:
   /**
    * @copydoc Toolkit::VideoView::Forward()
    */
-  void Forward( int millisecond );
+  void Forward(int millisecond);
 
   /**
    * @copydoc Toolkit::VideoView::Backward()
    */
-  void Backward( int millisecond );
+  void Backward(int millisecond);
 
   /**
    * @brief Sets the player mute status.
    * @SINCE_1_1.38
    * @param[i] mute The new mute status, true is mute.
    */
-  void SetMute( bool mute );
+  void SetMute(bool mute);
 
   /**
    * @brief Returns the player mute status.
@@ -133,7 +131,7 @@ public:
    * @param[in] left The left volume scalar
    * @param[in] right The right volume scalar
    */
-  void SetVolume( float left, float right );
+  void SetVolume(float left, float right);
 
   /**
    * @brief Returns current volume factor.
@@ -141,9 +139,9 @@ public:
    * @param[out] left The current left volume scalar
    * @param[out] right The current right volume scalar
    */
-  void GetVolume( float& left, float& right );
+  void GetVolume(float& left, float& right);
 
- /**
 /**
    * @copydoc Dali::Toolkit::VideoView::FinishedSignal()
    */
   Dali::Toolkit::VideoView::VideoViewSignalType& FinishedSignal();
@@ -158,7 +156,7 @@ public:
    * @SINCE_1_1.38
    * @param[in] map The Dali::Property::Map to use for to display.
    */
-  void SetPropertyMap( Property::Map map );
+  void SetPropertyMap(Property::Map map);
 
   // Properties
   /**
@@ -168,7 +166,7 @@ public:
    * @param[in] index The property index.
    * @param[in] value The new property value.
    */
-  static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
+  static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
 
   /**
    * @brief Called to retrieve a property of an object of this type.
@@ -177,7 +175,7 @@ public:
    * @param[in] index The property index.
    * @return The current value of the property.
    */
-  static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
+  static Property::Value GetProperty(BaseObject* object, Property::Index propertyIndex);
 
   /**
    * @brief Set the depth index of this image renderer
@@ -186,7 +184,7 @@ public:
    * @SINCE_1_1.38
    * @param[in] depthIndex The depth index of this renderer
    */
-  void SetDepthIndex( int depthIndex );
+  void SetDepthIndex(int depthIndex);
 
   /**
    * @brief Performs actions as requested using the action name.
@@ -196,7 +194,7 @@ public:
    * @param[in] attributes The attributes with which to perfrom this action.
    * @return True if action has been accepted by this control
    */
-  static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes );
+  static bool DoAction(BaseObject* object, const std::string& actionName, const Property::Map& attributes);
 
   /**
    * Connects a callback function with the object's signals.
@@ -207,100 +205,232 @@ public:
    * @return True if the signal was connected.
    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the c
    */
-  static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
+  static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
 
   /**
    * @brief Updates video display area for window rendering target
    */
-  void UpdateDisplayArea( Dali::PropertyNotification& source );
+  void UpdateDisplayArea(Dali::PropertyNotification& source);
 
   /**
    * @brief Sets underlay flag and initializes new rendering target by flag.
    */
-  void SetUnderlay( bool set );
+  void SetUnderlay(bool set);
 
   /**
    * @brief Checks underlay flag.
    */
   bool IsUnderlay();
 
-private: // From Control
+  /**
+   * @brief Sets sw codec type.
+   */
+  void SetSWCodec(bool on);
 
   /**
-   * @copydoc Toolkit::Control::OnInitialize()
+   * @brief Gets play position.
    */
-  virtual void OnInitialize();
+  int GetPlayPosition();
 
   /**
-   * @copydoc Toolkit::Control::OnStageConnect()
+   * @brief Sets play position.
    */
-  virtual void OnStageConnection( int depth );
+  void SetPlayPosition(int pos);
 
   /**
-   * @copydoc Toolkit::Control::OnStageDisconnection()
+   * @brief Sets Display mode.
    */
-  virtual void OnStageDisconnection();
+  void SetDisplayMode(int mode);
 
   /**
-   * @copydoc Toolkit::Control::GetNaturalSize
+   * @brief Gets Display mode.
    */
-  virtual Vector3 GetNaturalSize();
+  int GetDisplayMode() const;
 
   /**
-   * @copydoc Toolkit::Control::GetHeightForWidth()
+   * @brief Gets internal media player.
    */
-  virtual float GetHeightForWidth( float width );
+  Any GetMediaPlayer();
 
   /**
-   * @copydoc Toolkit::Control::GetWidthForHeight()
+   * @brief Play the resize or move animation with synchronization between UI(transparent hole) and video player
+   *
+   * The resize and move animation's play() function is called.
+   * If the animation is played, UI and video player will work synchronization.
+   *
+   * @param[in] videoView The current VideoView
+   * @param[in] animation The animation for video view's resize or move.
    */
-  virtual float GetWidthForHeight( float height );
+  void PlayAnimation(Dali::Animation animation);
 
-private:
+  /**
+   * @brief Checks whether the actor is set as a video view or not.
+   *
+   * @param[in] actor The actor to be checked
+   * @return True if actor is video view.
+   */
+  bool IsVideoView(Actor actor) const;
+
+  /**
+   * @brief Gets the Video Player.
+   *
+   * @return The return of video player.
+   */
+  VideoPlayer GetVideoPlayer();
+
+private: // From Control
+  /**
+   * @copydoc Toolkit::Control::OnInitialize()
+   */
+  void OnInitialize() override;
+
+  /**
+   * @copydoc Toolkit::Control::OnSceneConnection()
+   */
+  void OnSceneConnection(int depth) override;
+
+  /**
+   * @copydoc Toolkit::Control::OnSceneDisconnection()
+   */
+  void OnSceneDisconnection() override;
+
+  /**
+   * @copydoc Toolkit::Control::OnSizeSet()
+   */
+  void OnSizeSet(const Vector3& targetSize) override;
+
+  /**
+   * @copydoc Toolkit::Control::GetNaturalSize
+   */
+  Vector3 GetNaturalSize() override;
 
-  // Undefined
-  VideoView( const VideoView& videoView );
+private:
+  /**
+   * @brief Construct a new VideoView.
+   */
+  VideoView(const VideoView& videoView);
 
-  VideoView& operator=( const VideoView& videoView );
+  // Undefined assignment operator.
+  VideoView& operator=(const VideoView& videoView);
 
+  /**
+   * @brief SetWindowSurfaceTarget for underlay video playback.
+   */
   void SetWindowSurfaceTarget();
 
+  /**
+   * @brief SetNativeImageTarget for native image video playback.
+   */
   void SetNativeImageTarget();
 
-private:
+  /**
+   * @brief CreateShader for native image target
+   */
+  Dali::Shader CreateShader();
+
+  /**
+   * @brief Checks whether the property has a string value.
+   * @param Property value
+   * @param String output
+   * @return true if the output was found
+   */
+  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();
 
-  Dali::VideoPlayer mVideoPlayer;
+  /*
+   * @brief FrameRender's callback function
+   *
+   * This function means the resize/move animation is finished,
+   * so Ui and video player's synchronization can be finished.
+   *
+   */
+  void FrameRenderCallback(int frameID);
+
+  /*
+   * @brief Set frameRender Callback function
+   *
+   * This function is added for listenr the resize/move animation is finished,
+   *
+   */
+  void SetFrameRenderCallback();
+
+  /*
+   * @brief resize/move animation finished callback function
+   *
+   * This function is called the resize/move animation is finished,
+   *
+   */
+  void OnAnimationFinished(Dali::Animation& animation);
+
+  /*
+   * @brief window's resize callback function
+   * This function is called when window is resized.
+   *
+   * @param[in] winHandle The resized window's handle.
+   * @param[in] size The window's new size.
+   */
+  void OnWindowResized(Dali::Window winHandle, Dali::Window::WindowSize size);
+
+  /**
+   * @brief This signal is emitted when an actor's children change their sibling order
+   *
+   * @param[in] actor parent actor.
+   */
+  void OnChildOrderChanged(Actor actor);
+
+private:
+  Dali::VideoPlayer     mVideoPlayer;
   Dali::ImageDimensions mVideoSize;
-  Toolkit::Visual::Base mVisual;
-  Dali::Property::Map mPropertyMap;
-  Dali::NativeImage mNativeImage; ///< Native image handle for video rendering by texture streaming
+  Dali::Property::Map   mPropertyMap;
+  Dali::Property::Map   mEffectPropertyMap;
+  Dali::Texture         mNativeTexture;
+
   Dali::Toolkit::VideoView::VideoViewSignalType mFinishedSignal;
-  std::string mUrl;
+
+  std::string       mUrl;
   Dali::DisplayArea mDisplayArea;
-  Dali::Renderer mRenderer;
+  Dali::Renderer    mOverlayRenderer;
+  Dali::Renderer    mTextureRenderer;
+
   Dali::PropertyNotification mPositionUpdateNotification;
   Dali::PropertyNotification mSizeUpdateNotification;
   Dali::PropertyNotification mScaleUpdateNotification;
 
+  Dali::Property::Map mPropertyBackup;
+
   int mCurrentVideoPlayPosition;
+  int mFrameID;
+
   bool mIsPlay;
   bool mIsUnderlay;
+
+  Dali::VideoSyncMode mSyncMode;
+  int                 mSiblingOrder;
 };
 
 } // namespace Internal
 
-inline Toolkit::Internal::VideoView& GetImpl( Toolkit::VideoView& handle )
+inline Toolkit::Internal::VideoView& GetImpl(Toolkit::VideoView& handle)
 {
-  DALI_ASSERT_ALWAYS( handle );
+  DALI_ASSERT_ALWAYS(handle);
   Dali::RefObject& impl = handle.GetImplementation();
-  return static_cast< Toolkit::Internal::VideoView& >( impl );
+  return static_cast<Toolkit::Internal::VideoView&>(impl);
 }
 
-inline const Toolkit::Internal::VideoView& GetImpl( const Toolkit::VideoView& handle )
+inline const Toolkit::Internal::VideoView& GetImpl(const Toolkit::VideoView& handle)
 {
-  DALI_ASSERT_ALWAYS( handle );
+  DALI_ASSERT_ALWAYS(handle);
   const Dali::RefObject& impl = handle.GetImplementation();
-  return static_cast< const Toolkit::Internal::VideoView& >( impl );
+  return static_cast<const Toolkit::Internal::VideoView&>(impl);
 }
 
 } // namespace Toolkit