Add api for get the internal media player handle of the VideoView
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-VideoView.cpp
old mode 100644 (file)
new mode 100755 (executable)
index 8450f3f..a38ec18
@@ -20,6 +20,7 @@
 #include <dali-toolkit-test-suite-utils.h>
 #include <dali-toolkit/dali-toolkit.h>
 #include <dali-toolkit/public-api/controls/video-view/video-view.h>
+#include <dali-toolkit/devel-api/controls/video-view/video-view-devel.h>
 
 using namespace Dali;
 using namespace Dali::Toolkit;
@@ -29,6 +30,36 @@ namespace
 const char* const TEST_FILE( "test.mp4" );
 const char* const VOLUME_LEFT( "volumeLeft" );
 const char* const VOLUME_RIGHT( "volumeRight" );
+const char* const RENDERING_TYPE( "renderingTarget" );
+
+const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
+  attribute mediump vec2 aPosition;\n
+  varying mediump vec2 vTexCoord;\n
+  uniform mediump mat4 uMvpMatrix;\n
+  uniform mediump vec3 uSize;\n
+  \n
+  void main()\n
+  {\n
+    mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
+    vertexPosition.xyz *= uSize;\n
+    vertexPosition = uMvpMatrix * vertexPosition;\n
+    \n
+    vTexCoord = aPosition + vec2(0.5);\n
+    gl_Position = vertexPosition;\n
+  }\n
+);
+
+const char* fragmentShaderPrefix( "#extension GL_OES_EGL_image_external:require\n" );
+const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
+  varying mediump vec2 vTexCoord;\n
+  uniform samplerExternalOES sTexture;\n
+  uniform lowp vec4 uColor;\n
+  \n
+  void main()\n
+  {\n
+    gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
+  }\n
+);
 
 }
 
@@ -121,6 +152,7 @@ int UtcDaliVideoViewProperty1b(void)
 
   Toolkit::VideoView view = Toolkit::VideoView::New();
   DALI_TEST_CHECK( view );
+  Stage stage = Stage::GetCurrent();
 
   std::string file;
   Property::Map map;
@@ -128,10 +160,12 @@ int UtcDaliVideoViewProperty1b(void)
   view.SetProperty( VideoView::Property::VIDEO, Property::Map()
                     .Add("rendererType", "IMAGE")
                     .Add("url", "video.mpg") // Note, videoView doesn't use this url
-                    .Add("RENDERER_TARGET", "windowSurfaceTarget" )
+                    .Add("RENDERING_TARGET", "windowSurfaceTarget" )
                     .Add("width", 100)
                     .Add("height", 100) );
 
+  stage.Add( view );
+
   Property::Value val = view.GetProperty( VideoView::Property::VIDEO );
   Property::Map* resultMap = val.GetMap();
 
@@ -140,6 +174,8 @@ int UtcDaliVideoViewProperty1b(void)
   DALI_TEST_CHECK( value );
   DALI_TEST_EQUALS( value->Get<std::string>(), "video.mpg", TEST_LOCATION );
 
+  stage.Remove( view );
+
   END_TEST;
 }
 
@@ -180,6 +216,7 @@ int UtcDaliVideoViewProperty3(void)
   val = view.GetProperty( VideoView::Property::MUTED );
   DALI_TEST_CHECK( val.Get( muted ) );
   DALI_TEST_CHECK( muted );
+
   END_TEST;
 }
 
@@ -195,20 +232,21 @@ int UtcDaliVideoViewProperty4(void)
   left = right = 0.f;
 
   Property::Map map;
-  map.Insert( VOLUME_LEFT, 1.0f );
+  map.Insert( VOLUME_LEFT, 0.5f );
   map.Insert( VOLUME_RIGHT, 0.5f );
 
-  Property::Map map2;
   view.SetProperty( VideoView::Property::VOLUME, map );
-  Property::Value val4 = view.GetProperty( VideoView::Property::VOLUME );
-  DALI_TEST_CHECK( val4.Get( map2 ) );
+  Property::Value val = view.GetProperty( VideoView::Property::VOLUME );
 
-  Property::Value* volumeLeft = map.Find( VOLUME_LEFT );
-  Property::Value* volumeRight = map.Find( VOLUME_RIGHT );
+  Property::Map map2;
+  DALI_TEST_CHECK( val.Get( map2 ) );
+
+  Property::Value* volumeLeft = map2.Find( VOLUME_LEFT );
+  Property::Value* volumeRight = map2.Find( VOLUME_RIGHT );
 
   DALI_TEST_CHECK( volumeLeft && volumeLeft->Get( left ) );
   DALI_TEST_CHECK( volumeRight && volumeRight->Get( right ) );
-  DALI_TEST_CHECK( left == 1.0f );
+  DALI_TEST_CHECK( left == 0.5f );
   DALI_TEST_CHECK( right == 0.5f );
 
   END_TEST;
@@ -264,8 +302,298 @@ int UtcDaliVideoViewMethodsForCoverage(void)
   videoView.Stop();
   videoView.Forward(10);
   videoView.Backward(10);
+
+  Toolkit::DevelVideoView::GetMediaPlayer( videoView );
+
   VideoView::VideoViewSignalType& signal = videoView.FinishedSignal();
   DALI_TEST_EQUALS( 0, signal.GetConnectionCount(), TEST_LOCATION );
 
   END_TEST;
 }
+
+int UtcDaliVideoViewMethodsForRenderType(void)
+{
+  ToolkitTestApplication application;
+  VideoView videoView = VideoView::New();
+  DALI_TEST_CHECK( videoView );
+
+  Property::Map windowSurfaceTarget;
+  Property::Map nativeImageTarget;
+
+  windowSurfaceTarget.Insert( RENDERING_TYPE, "windowSurfaceTarget" );
+  nativeImageTarget.Insert( RENDERING_TYPE, "nativeImageTarget" );
+
+  Property::Map map;
+  Property::Value value;
+  videoView.SetProperty( VideoView::Property::VIDEO, windowSurfaceTarget );
+
+  value = videoView.GetProperty( VideoView::Property::VIDEO );
+  DALI_TEST_CHECK( value.Get( map ) );
+
+  Property::Value* type = map.Find( RENDERING_TYPE );
+  DALI_TEST_CHECK( type );
+  DALI_TEST_EQUALS( "windowSurfaceTarget", type->Get<std::string>(), TEST_LOCATION );
+
+  videoView.SetProperty( VideoView::Property::VIDEO, nativeImageTarget );
+
+  value = videoView.GetProperty( VideoView::Property::VIDEO );
+  DALI_TEST_CHECK( value.Get( map ) );
+  type = map.Find( RENDERING_TYPE );
+
+  DALI_TEST_CHECK( type );
+  DALI_TEST_EQUALS( "nativeImageTarget", type->Get<std::string>(), TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliVideoViewCustomShaderForCoverage(void)
+{
+  ToolkitTestApplication application;
+  VideoView videoView = VideoView::New();
+  DALI_TEST_CHECK( videoView );
+
+  ToolkitApplication::DECODED_IMAGES_SUPPORTED = true;
+
+  videoView.SetProperty( Toolkit::VideoView::Property::UNDERLAY, false );
+  bool isUnderlay = videoView.GetProperty( Toolkit::VideoView::Property::UNDERLAY ).Get< bool >();
+  DALI_TEST_CHECK( !isUnderlay );
+
+  Stage::GetCurrent().Add( videoView );
+  videoView.SetProperty( VideoView::Property::VIDEO, "testvideo" );
+
+  Property::Map customShader;
+  customShader.Insert( "vertexShader", VERTEX_SHADER );
+  customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
+
+  Property::Map map;
+  map.Insert( "shader", customShader );
+
+  videoView.SetProperty( VideoView::Property::VIDEO, map );
+
+  Property::Map map2;
+  Property::Value value = videoView.GetProperty( VideoView::Property::VIDEO );
+
+  DALI_TEST_CHECK( !value.Get( map2 ) );
+  END_TEST;
+}
+
+int UtcDaliVideoViewMethodsForCoverage2(void)
+{
+  ToolkitTestApplication application;
+  VideoView videoView = VideoView::New();
+  DALI_TEST_CHECK( videoView );
+
+  Property::Map windowSurfaceTarget;
+
+  windowSurfaceTarget.Insert( RENDERING_TYPE, "windowSurfaceTarget" );
+
+  Stage::GetCurrent().Add( videoView );
+
+  application.SendNotification();
+  application.Render();
+
+  Property::Map map;
+  Property::Value value;
+  videoView.SetProperty( VideoView::Property::VIDEO, windowSurfaceTarget );
+
+  value = videoView.GetProperty( VideoView::Property::VIDEO );
+  DALI_TEST_CHECK( value.Get( map ) );
+
+  Property::Value* type = map.Find( RENDERING_TYPE );
+  DALI_TEST_CHECK( type );
+  DALI_TEST_EQUALS( "windowSurfaceTarget", type->Get<std::string>(), TEST_LOCATION );
+
+  Vector3 vector(100.0f, 100.0f, 0.0f);
+
+  DALI_TEST_CHECK(vector != videoView.GetCurrentSize());
+  videoView.SetSize( vector );
+
+  application.SendNotification();
+  application.Render();
+
+  // Check the size in the new frame
+  DALI_TEST_CHECK(vector == videoView.GetCurrentSize());
+
+  END_TEST;
+}
+
+int UtcDaliVideoViewPropertyUnderlay(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliVideoViewPropertyUnderlay");
+  ToolkitApplication::DECODED_IMAGES_SUPPORTED = true;
+
+  VideoView view = VideoView::New();
+  DALI_TEST_CHECK( view );
+
+  Stage::GetCurrent().Add( view );
+  view.Play();
+
+  application.SendNotification();
+  application.Render();
+
+  bool isUnderlay = view.GetProperty( Toolkit::VideoView::Property::UNDERLAY ).Get< bool >();
+  DALI_TEST_CHECK( isUnderlay );
+
+  view.Play();
+  view.SetProperty( Toolkit::VideoView::Property::UNDERLAY, false );
+  isUnderlay = view.GetProperty( Toolkit::VideoView::Property::UNDERLAY ).Get< bool >();
+  DALI_TEST_CHECK( !isUnderlay );
+
+  view.Play();
+  view.SetProperty( Toolkit::VideoView::Property::UNDERLAY, true );
+  isUnderlay = view.GetProperty( Toolkit::VideoView::Property::UNDERLAY ).Get< bool >();
+  DALI_TEST_CHECK( isUnderlay );
+
+  // If platform api doesn't provide any API or feature for decoded images of video,
+  // UNDERLAY should be true
+  ToolkitApplication::DECODED_IMAGES_SUPPORTED = false;
+
+  view.SetProperty( Toolkit::VideoView::Property::UNDERLAY, false );
+  isUnderlay = view.GetProperty( Toolkit::VideoView::Property::UNDERLAY ).Get< bool >();
+  DALI_TEST_CHECK( isUnderlay );
+
+  // For coverage
+  ToolkitApplication::DECODED_IMAGES_SUPPORTED = true;
+
+  view.SetProperty( Toolkit::VideoView::Property::UNDERLAY, true );
+  view.SetProperty( Toolkit::VideoView::Property::UNDERLAY, false );
+  isUnderlay = view.GetProperty( Toolkit::VideoView::Property::UNDERLAY ).Get< bool >();
+  DALI_TEST_CHECK( !isUnderlay );
+
+  view.Stop();
+
+  END_TEST;
+}
+
+int UtcDaliVideoViewPropertyPlayPosition(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliVideoViewPropertyPlayPosition");
+
+  VideoView view = VideoView::New();
+  DALI_TEST_CHECK( view );
+
+  Stage::GetCurrent().Add( view );
+  view.Play();
+
+  application.SendNotification();
+  application.Render();
+
+  int playPos = view.GetProperty( Toolkit::VideoView::Property::PLAY_POSITION ).Get< int >();
+  DALI_TEST_CHECK( playPos == 0 );
+
+  view.SetProperty( Toolkit::VideoView::Property::PLAY_POSITION, 10 );
+  playPos = view.GetProperty( Toolkit::VideoView::Property::PLAY_POSITION ).Get< int >();
+  // Actually setting play position will be async
+  // Actual platform result may be different.
+  DALI_TEST_CHECK( playPos == 10 );
+
+  END_TEST;
+}
+
+// For coverage.
+int UtcDaliVideoViewNew2(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliVideoViewNew2");
+
+  VideoView view = VideoView::New( true );
+  DALI_TEST_CHECK( view );
+
+  Stage::GetCurrent().Add( view );
+  view.Play();
+
+  application.SendNotification();
+  application.Render();
+
+  VideoView view2 = VideoView::New( "", false );
+  DALI_TEST_CHECK( view2 );
+
+  Stage::GetCurrent().Add( view2 );
+  view2.Play();
+
+  application.SendNotification();
+  application.Render();
+
+  END_TEST;
+}
+
+int UtcDaliVideoViewPropertyDisplayMode(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliVideoViewPropertyDisplayMode");
+
+  VideoView view = VideoView::New();
+  DALI_TEST_CHECK( view );
+
+  Stage::GetCurrent().Add( view );
+  view.Play();
+
+  application.SendNotification();
+  application.Render();
+
+  view.SetProperty( Toolkit::VideoView::Property::DISPLAY_MODE, Toolkit::VideoView::DisplayMode::DST_ROI );
+  int displayMode = view.GetProperty( Toolkit::VideoView::Property::DISPLAY_MODE ).Get< int >();
+  DALI_TEST_CHECK( displayMode == Toolkit::VideoView::DisplayMode::DST_ROI );
+
+  END_TEST;
+}
+
+
+int UtcDaliVideoViewCustomShader(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline( "VideoView with custom shader" );
+
+  VideoView view = VideoView::New();
+  DALI_TEST_CHECK( view );
+
+  ToolkitApplication::DECODED_IMAGES_SUPPORTED = true;
+
+  view.SetProperty( Toolkit::VideoView::Property::UNDERLAY, false );
+  bool isUnderlay = view.GetProperty( Toolkit::VideoView::Property::UNDERLAY ).Get< bool >();
+  DALI_TEST_CHECK( !isUnderlay );
+
+  Stage::GetCurrent().Add( view );
+  view.SetProperty( VideoView::Property::VIDEO, "testvideo" );
+
+  /* insert custom shader */
+  Property::Map customShader;
+  std::string fragmentShaderString;
+  fragmentShaderString.reserve( strlen( fragmentShaderPrefix ) + strlen( FRAGMENT_SHADER ) );
+  fragmentShaderString.append( fragmentShaderPrefix );
+  fragmentShaderString.append( FRAGMENT_SHADER );
+  customShader.Insert( "vertexShader", VERTEX_SHADER );
+  customShader.Insert( "fragmentShader", fragmentShaderString );
+
+  Property::Map map;
+  map.Insert( "shader", customShader );
+
+  view.SetProperty( VideoView::Property::VIDEO, map );
+
+  /* do render for check custom shader */
+  Stage::GetCurrent().Add( view );
+  view.Play();
+
+  application.SendNotification();
+  application.Render();
+
+  /* get renderer */
+  DALI_TEST_CHECK( view.GetRendererCount() == 1u );
+  Renderer renderer = view.GetRendererAt( 0 );
+  Shader shader = renderer.GetShader();
+  DALI_TEST_CHECK( shader );
+
+  Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
+  Property::Map* shaderMap = value.GetMap();
+  DALI_TEST_CHECK( shaderMap );
+
+  Property::Value* fragment = shaderMap->Find( "fragment" ); // fragment key name from shader-impl.cpp
+  DALI_TEST_EQUALS( fragmentShaderString, fragment->Get<std::string>(), TEST_LOCATION );
+
+  Property::Value* vertex = shaderMap->Find( "vertex" ); // vertex key name from shader-impl.cpp
+  DALI_TEST_EQUALS( VERTEX_SHADER, vertex->Get<std::string>(), TEST_LOCATION );
+
+  END_TEST;
+}