[Android] IVLCVout: add setVideoSurface and setSubtitlesSurface

Thomas Guillem git at videolan.org
Thu Jul 2 11:47:07 CEST 2015


vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Thu Jul  2 11:46:53 2015 +0200| [3fc05c226cab75d8315a4a89f66b284e348e483f] | committer: Thomas Guillem

IVLCVout: add setVideoSurface and setSubtitlesSurface

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=3fc05c226cab75d8315a4a89f66b284e348e483f
---

 libvlc/src/org/videolan/libvlc/AWindow.java  |   46 +++++++++++++++++++++++---
 libvlc/src/org/videolan/libvlc/IVLCVout.java |   26 ++++++++++++++-
 2 files changed, 67 insertions(+), 5 deletions(-)

diff --git a/libvlc/src/org/videolan/libvlc/AWindow.java b/libvlc/src/org/videolan/libvlc/AWindow.java
index 93b80f0..97f658f 100644
--- a/libvlc/src/org/videolan/libvlc/AWindow.java
+++ b/libvlc/src/org/videolan/libvlc/AWindow.java
@@ -71,9 +71,16 @@ class AWindow implements IAWindowNativeHandler, IVLCVout {
             mTextureView = textureView;
         }
 
+        private SurfaceHelper(int id, Surface surface, SurfaceHolder surfaceHolder) {
+            mId = id;
+            mSurfaceView = null;
+            mTextureView = null;
+            mSurfaceHolder = surfaceHolder;
+            mSurface = surface;
+        }
+
         private void setSurface(Surface surface) {
-            boolean surfaceValid = surface.isValid();
-            if (surfaceValid && mSurface == null) {
+            if (surface.isValid() && getNativeSurface(mId) == null) {
                 mSurface = surface;
                 setNativeSurface(mId, mSurface);
                 onSurfaceCreated();
@@ -91,12 +98,21 @@ class AWindow implements IAWindowNativeHandler, IVLCVout {
             setSurface(new Surface(mTextureView.getSurfaceTexture()));
         }
 
+        private void attachSurface() {
+            if (mSurfaceHolder != null)
+                mSurfaceHolder.addCallback(mSurfaceHolderCallback);
+            setSurface(mSurface);
+        }
+
         public void attach() {
             if (mSurfaceView != null) {
                 attachSurfaceView();
-            } else {
+            } else if (mTextureView != null) {
                 attachTextureView();
-            }
+            } else if (mSurface != null) {
+                attachSurface();
+            } else
+                throw new IllegalStateException();
         }
 
         @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@@ -224,6 +240,18 @@ class AWindow implements IAWindowNativeHandler, IVLCVout {
         mSurfaceHelpers[id] = new SurfaceHelper(id, view);
     }
 
+    private void setSurface(int id, Surface surface, SurfaceHolder surfaceHolder) {
+        if (mSurfacesState.get() != SURFACE_STATE_INIT)
+            throw new IllegalStateException("Can't set surface when already attached");
+        if (!surface.isValid() || surfaceHolder == null)
+            throw new IllegalStateException("surface is not attached and holder is null");
+        final SurfaceHelper surfaceHelper = mSurfaceHelpers[id];
+        if (surfaceHelper != null)
+            surfaceHelper.release();
+
+        mSurfaceHelpers[id] = new SurfaceHelper(id, surface, surfaceHolder);
+    }
+
     @Override
     @MainThread
     public void setVideoView(SurfaceView videoSurfaceView) {
@@ -237,6 +265,11 @@ class AWindow implements IAWindowNativeHandler, IVLCVout {
     }
 
     @Override
+    public void setVideoSurface(Surface videoSurface, SurfaceHolder surfaceHolder) {
+        setSurface(ID_VIDEO, videoSurface, surfaceHolder);
+    }
+
+    @Override
     @MainThread
     public void setSubtitlesView(SurfaceView subtitlesSurfaceView) {
         setView(ID_SUBTITLES, subtitlesSurfaceView);
@@ -249,6 +282,11 @@ class AWindow implements IAWindowNativeHandler, IVLCVout {
     }
 
     @Override
+    public void setSubtitlesSurface(Surface subtitlesSurface, SurfaceHolder surfaceHolder) {
+        setSurface(ID_SUBTITLES, subtitlesSurface, surfaceHolder);
+    }
+
+    @Override
     @MainThread
     public void attachViews() {
         if (mSurfacesState.get() != SURFACE_STATE_INIT || mSurfaceHelpers[ID_VIDEO] == null)
diff --git a/libvlc/src/org/videolan/libvlc/IVLCVout.java b/libvlc/src/org/videolan/libvlc/IVLCVout.java
index 1b0afb0..47c54d2 100644
--- a/libvlc/src/org/videolan/libvlc/IVLCVout.java
+++ b/libvlc/src/org/videolan/libvlc/IVLCVout.java
@@ -23,6 +23,8 @@ package org.videolan.libvlc;
 import android.annotation.TargetApi;
 import android.os.Build;
 import android.support.annotation.MainThread;
+import android.view.Surface;
+import android.view.SurfaceHolder;
 import android.view.SurfaceView;
 import android.view.TextureView;
 
@@ -60,6 +62,16 @@ public interface IVLCVout {
     void setVideoView(TextureView videoTextureView);
 
     /**
+     * Set a surface used for video out.
+     * @param videoSurface if surfaceHolder is null, this surface must be valid and attached.
+     * @param surfaceHolder optional, used to configure buffers geometry before Android ICS
+     * and to get notified when surface is destroyed.
+     * @see #attachViews()
+     */
+    @MainThread
+    void setVideoSurface(Surface videoSurface, SurfaceHolder surfaceHolder);
+
+    /**
      * Set a surfaceView used for subtitles out.
      * @see #attachViews()
      */
@@ -75,11 +87,23 @@ public interface IVLCVout {
     void setSubtitlesView(TextureView subtitlesTextureView);
 
     /**
-     * Attach views previously set by setVideoView and setSubtitlesView.
+     * Set a surface used for video out.
+     * @param subtitlesSurface if surfaceHolder is null, this surface must be valid and attached.
+     * @param surfaceHolder optional, used to configure buffers geometry before Android ICS
+     * and to get notified when surface is destroyed.
+     * @see #attachViews()
+     */
+    @MainThread
+    void setSubtitlesSurface(Surface subtitlesSurface, SurfaceHolder surfaceHolder);
+
+    /**
+     * Attach views previously set by setVideoView, setSubtitlesView, setVideoSurface, setSubtitleSurface
      * @see #setVideoView(SurfaceView)
      * @see #setVideoView(TextureView)
+     * @see #setVideoSurface(Surface, SurfaceHolder)
      * @see #setSubtitlesView(SurfaceView)
      * @see #setSubtitlesView(TextureView)
+     * @see #setSubtitlesSurface(Surface, SurfaceHolder)
      */
     @MainThread
     void attachViews();



More information about the Android mailing list