From bb6cd5de7fb18faef70c0c657636ca1e12ec965c Mon Sep 17 00:00:00 2001 From: kifio Date: Sat, 25 Sep 2021 13:21:50 +0300 Subject: [PATCH 1/5] Update ExoPlayer and other dependencies; Dependencies refactoring; --- build.gradle | 14 +++++-- gpuv/build.gradle | 2 +- .../daasuu/gpuv/player/GPUPlayerRenderer.java | 6 ++- gradle/wrapper/gradle-wrapper.properties | 2 +- sample/build.gradle | 10 ++--- .../gpuvideoandroid/PlayerActivity.java | 39 +++++++------------ 6 files changed, 37 insertions(+), 36 deletions(-) diff --git a/build.gradle b/build.gradle index a9bc046..8145dd4 100644 --- a/build.gradle +++ b/build.gradle @@ -1,13 +1,19 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.10' + ext.kotlin_version = '1.5.31' + ext.exo_player_version = '2.15.1' + ext.app_compat_version = '1.3.1' + ext.constraint_layout_version = '2.1.1' + ext.glide_version = '4.12.0' + repositories { google() - jcenter() + mavenCentral() } + dependencies { - classpath 'com.android.tools.build:gradle:3.2.1' + classpath 'com.android.tools.build:gradle:4.2.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong @@ -18,7 +24,7 @@ buildscript { allprojects { repositories { google() - jcenter() + mavenCentral() } } diff --git a/gpuv/build.gradle b/gpuv/build.gradle index 6e39dc1..f605bec 100644 --- a/gpuv/build.gradle +++ b/gpuv/build.gradle @@ -23,6 +23,6 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - compileOnly 'com.google.android.exoplayer:exoplayer-core:2.9.3' + compileOnly "com.google.android.exoplayer:exoplayer-core:$exo_player_version" } diff --git a/gpuv/src/main/java/com/daasuu/gpuv/player/GPUPlayerRenderer.java b/gpuv/src/main/java/com/daasuu/gpuv/player/GPUPlayerRenderer.java index 8ff983e..afc6977 100644 --- a/gpuv/src/main/java/com/daasuu/gpuv/player/GPUPlayerRenderer.java +++ b/gpuv/src/main/java/com/daasuu/gpuv/player/GPUPlayerRenderer.java @@ -3,6 +3,8 @@ import android.graphics.SurfaceTexture; import android.opengl.GLES20; import android.opengl.Matrix; +import android.os.Handler; +import android.os.Looper; import android.util.Log; import android.view.Surface; import com.daasuu.gpuv.egl.*; @@ -41,11 +43,13 @@ public class GPUPlayerRenderer extends GlFrameBufferObjectRenderer implements Su private float aspectRatio = 1f; private SimpleExoPlayer simpleExoPlayer; + private Handler uiHandler; GPUPlayerRenderer(GPUPlayerView glPreview) { super(); Matrix.setIdentityM(STMatrix, 0); this.glPreview = glPreview; + this.uiHandler = new Handler(Looper.getMainLooper()); } void setGlFilter(final GlFilter filter) { @@ -91,7 +95,7 @@ public void onSurfaceCreated(final EGLConfig config) { previewFilter.setup(); Surface surface = new Surface(previewTexture.getSurfaceTexture()); - this.simpleExoPlayer.setVideoSurface(surface); + uiHandler.post(() -> simpleExoPlayer.setVideoSurface(surface)); Matrix.setLookAtM(VMatrix, 0, 0.0f, 0.0f, 5.0f, diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9a4163a..1f3fdbc 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/sample/build.gradle b/sample/build.gradle index 566c1bf..4fee2d5 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -27,17 +27,17 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'androidx.appcompat:appcompat:1.1.0-alpha01' - implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3' + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" + implementation "androidx.appcompat:appcompat:$app_compat_version" + implementation "androidx.constraintlayout:constraintlayout:$constraint_layout_version" + implementation "com.google.android.exoplayer:exoplayer-core:$exo_player_version" + implementation "com.github.bumptech.glide:glide:$glide_version" - implementation 'com.google.android.exoplayer:exoplayer-core:2.9.3' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' - implementation 'com.github.bumptech.glide:glide:4.8.0' implementation project(':gpuv') } diff --git a/sample/src/main/java/com/daasuu/gpuvideoandroid/PlayerActivity.java b/sample/src/main/java/com/daasuu/gpuvideoandroid/PlayerActivity.java index 33cd08e..021eee9 100644 --- a/sample/src/main/java/com/daasuu/gpuvideoandroid/PlayerActivity.java +++ b/sample/src/main/java/com/daasuu/gpuvideoandroid/PlayerActivity.java @@ -4,31 +4,29 @@ import android.content.Intent; import android.net.Uri; import android.os.Bundle; -import androidx.appcompat.app.AppCompatActivity; import android.view.View; import android.view.ViewGroup; -import android.widget.*; +import android.widget.AdapterView; +import android.widget.Button; +import android.widget.ListView; +import android.widget.RelativeLayout; +import android.widget.SeekBar; + +import androidx.appcompat.app.AppCompatActivity; import com.daasuu.gpuv.egl.filter.GlFilter; import com.daasuu.gpuv.player.GPUPlayerView; import com.daasuu.gpuvideoandroid.widget.MovieWrapperView; import com.daasuu.gpuvideoandroid.widget.PlayerTimer; -import com.google.android.exoplayer2.ExoPlayerFactory; +import com.google.android.exoplayer2.MediaItem; import com.google.android.exoplayer2.SimpleExoPlayer; -import com.google.android.exoplayer2.source.ExtractorMediaSource; -import com.google.android.exoplayer2.source.MediaSource; import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; -import com.google.android.exoplayer2.trackselection.TrackSelector; -import com.google.android.exoplayer2.upstream.DataSource; -import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter; -import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; -import com.google.android.exoplayer2.util.Util; import java.util.List; public class PlayerActivity extends AppCompatActivity { - private static final String STREAM_URL_MP4_VOD_LONG = "https://www.radiantmediaplayer.com/media/bbb-360p.mp4"; + private static final String STREAM_URL_MP4_VOD_LONG = "https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/360/Big_Buck_Bunny_360_10s_1MB.mp4"; public static void startActivity(Activity activity) { Intent intent = new Intent(activity, PlayerActivity.class); @@ -152,21 +150,14 @@ public void onItemClick(AdapterView parent, View view, int position, long id) private void setUpSimpleExoPlayer() { - - TrackSelector trackSelector = new DefaultTrackSelector(); - - // Measures bandwidth during playback. Can be null if not required. - DefaultBandwidthMeter defaultBandwidthMeter = new DefaultBandwidthMeter(); - // Produces DataSource instances through which media data is loaded. - DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "yourApplicationName"), defaultBandwidthMeter); - MediaSource mediaSource = new ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(STREAM_URL_MP4_VOD_LONG)); - // SimpleExoPlayer - player = ExoPlayerFactory.newSimpleInstance(this, trackSelector); - // Prepare the player with the source. - player.prepare(mediaSource); - player.setPlayWhenReady(true); + player = new SimpleExoPlayer.Builder(this) + .setTrackSelector(new DefaultTrackSelector(this)) + .build(); + player.addMediaItem(MediaItem.fromUri(Uri.parse(STREAM_URL_MP4_VOD_LONG))); + player.prepare(); + player.setPlayWhenReady(true); } From 9e5f2706043b058d5bcbf76131c15b8a49ca6790 Mon Sep 17 00:00:00 2001 From: Masayuki Suda Date: Tue, 12 Oct 2021 17:20:55 +0900 Subject: [PATCH 2/5] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2df7237..5a5ef06 100644 --- a/README.md +++ b/README.md @@ -44,9 +44,9 @@ allprojects { Step 2. Add the dependency ```groovy dependencies { - implementation 'com.github.MasayukiSuda:GPUVideo-android:v0.1.1' + implementation 'com.github.MasayukiSuda:GPUVideo-android:v0.1.2' // if apply video filter on ExoPlayer video - implementation 'com.google.android.exoplayer:exoplayer-core:2.9.3' + implementation 'com.google.android.exoplayer:exoplayer-core:2.15.1' } ``` From c74fd6af0271dde4caf1a3c9fdd80eeac3fe3e47 Mon Sep 17 00:00:00 2001 From: silvershort Date: Sun, 14 Nov 2021 16:45:54 +0900 Subject: [PATCH 3/5] Added constructor to support ScopedStorage --- .../daasuu/gpuv/composer/GPUMp4Composer.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/gpuv/src/main/java/com/daasuu/gpuv/composer/GPUMp4Composer.java b/gpuv/src/main/java/com/daasuu/gpuv/composer/GPUMp4Composer.java index 601f315..0932f09 100644 --- a/gpuv/src/main/java/com/daasuu/gpuv/composer/GPUMp4Composer.java +++ b/gpuv/src/main/java/com/daasuu/gpuv/composer/GPUMp4Composer.java @@ -1,6 +1,8 @@ package com.daasuu.gpuv.composer; +import android.content.Context; import android.media.MediaMetadataRetriever; +import android.net.Uri; import android.util.Log; import android.util.Size; import com.daasuu.gpuv.egl.filter.GlFilter; @@ -17,6 +19,7 @@ public class GPUMp4Composer { private final static String TAG = GPUMp4Composer.class.getSimpleName(); + private Context context; private final String srcPath; private final String destPath; private GlFilter filter; @@ -39,6 +42,12 @@ public GPUMp4Composer(final String srcPath, final String destPath) { this.destPath = destPath; } + public GPUMp4Composer(final Context context, final String srcPath, final String destPath) { + this.context = context; + this.srcPath = srcPath; + this.destPath = destPath; + } + public GPUMp4Composer filter(GlFilter filter) { this.filter = filter; return this; @@ -122,13 +131,24 @@ public void onProgress(final double progress) { final File srcFile = new File(srcPath); final FileInputStream fileInputStream; try { - fileInputStream = new FileInputStream(srcFile); + if (srcPath.contains("content:/")) { + fileInputStream = (FileInputStream) context.getContentResolver().openInputStream(Uri.parse(srcPath)); + } else { + fileInputStream = new FileInputStream(srcFile); + } } catch (FileNotFoundException e) { e.printStackTrace(); if (listener != null) { listener.onFailed(e); } return; + } catch (NullPointerException e) { + Log.e(TAG, "Must have a context when use ScopedStorage"); + e.printStackTrace(); + if (listener != null) { + listener.onFailed(e); + } + return; } try { From 683810a941496e096d41f0f21befcb61d2599efa Mon Sep 17 00:00:00 2001 From: Ali Date: Thu, 5 Jan 2023 05:49:18 +0400 Subject: [PATCH 4/5] Upgrade exoplayer 2.15.1 to 2.18.2 --- build.gradle | 2 +- .../daasuu/gpuv/player/GPUPlayerRenderer.java | 31 +++++++++---------- .../com/daasuu/gpuv/player/GPUPlayerView.java | 21 +++++++------ .../gpuvideoandroid/PlayerActivity.java | 23 ++++++-------- 4 files changed, 36 insertions(+), 41 deletions(-) diff --git a/build.gradle b/build.gradle index 8145dd4..de22940 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ buildscript { ext.kotlin_version = '1.5.31' - ext.exo_player_version = '2.15.1' + ext.exo_player_version = '2.18.2' ext.app_compat_version = '1.3.1' ext.constraint_layout_version = '2.1.1' ext.glide_version = '4.12.0' diff --git a/gpuv/src/main/java/com/daasuu/gpuv/player/GPUPlayerRenderer.java b/gpuv/src/main/java/com/daasuu/gpuv/player/GPUPlayerRenderer.java index afc6977..ca77561 100644 --- a/gpuv/src/main/java/com/daasuu/gpuv/player/GPUPlayerRenderer.java +++ b/gpuv/src/main/java/com/daasuu/gpuv/player/GPUPlayerRenderer.java @@ -10,7 +10,7 @@ import com.daasuu.gpuv.egl.*; import com.daasuu.gpuv.egl.filter.GlFilter; import com.daasuu.gpuv.egl.filter.GlLookUpTableFilter; -import com.google.android.exoplayer2.SimpleExoPlayer; +import com.google.android.exoplayer2.ExoPlayer; import javax.microedition.khronos.egl.EGLConfig; @@ -42,7 +42,7 @@ public class GPUPlayerRenderer extends GlFrameBufferObjectRenderer implements Su private float aspectRatio = 1f; - private SimpleExoPlayer simpleExoPlayer; + private ExoPlayer exoPlayer; private Handler uiHandler; GPUPlayerRenderer(GPUPlayerView glPreview) { @@ -53,20 +53,17 @@ public class GPUPlayerRenderer extends GlFrameBufferObjectRenderer implements Su } void setGlFilter(final GlFilter filter) { - glPreview.queueEvent(new Runnable() { - @Override - public void run() { - if (glFilter != null) { - glFilter.release(); - if (glFilter instanceof GlLookUpTableFilter) { - ((GlLookUpTableFilter) glFilter).releaseLutBitmap(); - } - glFilter = null; + glPreview.queueEvent(() -> { + if (glFilter != null) { + glFilter.release(); + if (glFilter instanceof GlLookUpTableFilter) { + ((GlLookUpTableFilter) glFilter).releaseLutBitmap(); } - glFilter = filter; - isNewFilter = true; - glPreview.requestRender(); + glFilter = null; } + glFilter = filter; + isNewFilter = true; + glPreview.requestRender(); }); } @@ -95,7 +92,7 @@ public void onSurfaceCreated(final EGLConfig config) { previewFilter.setup(); Surface surface = new Surface(previewTexture.getSurfaceTexture()); - uiHandler.post(() -> simpleExoPlayer.setVideoSurface(surface)); + uiHandler.post(() -> exoPlayer.setVideoSurface(surface)); Matrix.setLookAtM(VMatrix, 0, 0.0f, 0.0f, 5.0f, @@ -173,8 +170,8 @@ public synchronized void onFrameAvailable(final SurfaceTexture previewTexture) { glPreview.requestRender(); } - void setSimpleExoPlayer(SimpleExoPlayer simpleExoPlayer) { - this.simpleExoPlayer = simpleExoPlayer; + void setExoPlayer(ExoPlayer exoPlayer) { + this.exoPlayer = exoPlayer; } void release() { diff --git a/gpuv/src/main/java/com/daasuu/gpuv/player/GPUPlayerView.java b/gpuv/src/main/java/com/daasuu/gpuv/player/GPUPlayerView.java index ec5668a..ebba086 100644 --- a/gpuv/src/main/java/com/daasuu/gpuv/player/GPUPlayerView.java +++ b/gpuv/src/main/java/com/daasuu/gpuv/player/GPUPlayerView.java @@ -6,15 +6,16 @@ import com.daasuu.gpuv.egl.GlConfigChooser; import com.daasuu.gpuv.egl.GlContextFactory; import com.daasuu.gpuv.egl.filter.GlFilter; -import com.google.android.exoplayer2.SimpleExoPlayer; -import com.google.android.exoplayer2.video.VideoListener; +import com.google.android.exoplayer2.ExoPlayer; +import com.google.android.exoplayer2.Player; +import com.google.android.exoplayer2.video.VideoSize; -public class GPUPlayerView extends GLSurfaceView implements VideoListener { +public class GPUPlayerView extends GLSurfaceView implements Player.Listener { private final static String TAG = GPUPlayerView.class.getSimpleName(); private final GPUPlayerRenderer renderer; - private SimpleExoPlayer player; + private ExoPlayer player; private float videoAspect = 1f; private PlayerScaleType playerScaleType = PlayerScaleType.RESIZE_FIT_WIDTH; @@ -34,14 +35,14 @@ public GPUPlayerView(Context context, AttributeSet attrs) { } - public GPUPlayerView setSimpleExoPlayer(SimpleExoPlayer player) { + public GPUPlayerView setExoPlayer(ExoPlayer player) { if (this.player != null) { this.player.release(); this.player = null; } this.player = player; - this.player.addVideoListener(this); - this.renderer.setSimpleExoPlayer(player); + this.player.addListener(this); + this.renderer.setExoPlayer(player); return this; } @@ -86,12 +87,12 @@ public void onPause() { } ////////////////////////////////////////////////////////////////////////// - // SimpleExoPlayer.VideoListener + // Player.Listener @Override - public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) { + public void onVideoSizeChanged(VideoSize videoSize) { // Log.d(TAG, "width = " + width + " height = " + height + " unappliedRotationDegrees = " + unappliedRotationDegrees + " pixelWidthHeightRatio = " + pixelWidthHeightRatio); - videoAspect = ((float) width / height) * pixelWidthHeightRatio; + videoAspect = ((float) videoSize.width / videoSize.height) * videoSize.pixelWidthHeightRatio; // Log.d(TAG, "videoAspect = " + videoAspect); requestLayout(); } diff --git a/sample/src/main/java/com/daasuu/gpuvideoandroid/PlayerActivity.java b/sample/src/main/java/com/daasuu/gpuvideoandroid/PlayerActivity.java index 021eee9..bc02e22 100644 --- a/sample/src/main/java/com/daasuu/gpuvideoandroid/PlayerActivity.java +++ b/sample/src/main/java/com/daasuu/gpuvideoandroid/PlayerActivity.java @@ -18,8 +18,8 @@ import com.daasuu.gpuv.player.GPUPlayerView; import com.daasuu.gpuvideoandroid.widget.MovieWrapperView; import com.daasuu.gpuvideoandroid.widget.PlayerTimer; +import com.google.android.exoplayer2.ExoPlayer; import com.google.android.exoplayer2.MediaItem; -import com.google.android.exoplayer2.SimpleExoPlayer; import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; import java.util.List; @@ -34,7 +34,7 @@ public static void startActivity(Activity activity) { } private GPUPlayerView gpuPlayerView; - private SimpleExoPlayer player; + private ExoPlayer player; private Button button; private SeekBar timeSeekBar; private SeekBar filterSeekBar; @@ -151,7 +151,7 @@ public void onItemClick(AdapterView parent, View view, int position, long id) private void setUpSimpleExoPlayer() { // SimpleExoPlayer - player = new SimpleExoPlayer.Builder(this) + player = new ExoPlayer.Builder(this) .setTrackSelector(new DefaultTrackSelector(this)) .build(); @@ -163,7 +163,7 @@ private void setUpSimpleExoPlayer() { private void setUoGlPlayerView() { gpuPlayerView = new GPUPlayerView(this); - gpuPlayerView.setSimpleExoPlayer(player); + gpuPlayerView.setExoPlayer(player); gpuPlayerView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); ((MovieWrapperView) findViewById(R.id.layout_movie_wrapper)).addView(gpuPlayerView); gpuPlayerView.onResume(); @@ -172,17 +172,14 @@ private void setUoGlPlayerView() { private void setUpTimer() { playerTimer = new PlayerTimer(); - playerTimer.setCallback(new PlayerTimer.Callback() { - @Override - public void onTick(long timeMillis) { - long position = player.getCurrentPosition(); - long duration = player.getDuration(); + playerTimer.setCallback(timeMillis -> { + long position = player.getCurrentPosition(); + long duration = player.getDuration(); - if (duration <= 0) return; + if (duration <= 0) return; - timeSeekBar.setMax((int) duration / 1000); - timeSeekBar.setProgress((int) position / 1000); - } + timeSeekBar.setMax((int) duration / 1000); + timeSeekBar.setProgress((int) position / 1000); }); playerTimer.start(); } From 6980da5c7b4fd8a42092f604b72e45e5a73c498c Mon Sep 17 00:00:00 2001 From: Pablo Date: Wed, 18 Jan 2023 00:07:21 +0100 Subject: [PATCH 5/5] fix issue when rendering landscape video --- .../daasuu/gpuv/camerarecorder/capture/EncodeRenderHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gpuv/src/main/java/com/daasuu/gpuv/camerarecorder/capture/EncodeRenderHandler.java b/gpuv/src/main/java/com/daasuu/gpuv/camerarecorder/capture/EncodeRenderHandler.java index 9618098..49cec0c 100644 --- a/gpuv/src/main/java/com/daasuu/gpuv/camerarecorder/capture/EncodeRenderHandler.java +++ b/gpuv/src/main/java/com/daasuu/gpuv/camerarecorder/capture/EncodeRenderHandler.java @@ -62,7 +62,7 @@ static EncodeRenderHandler createHandler(final String name, final EncodeRenderHandler handler = new EncodeRenderHandler( flipVertical, flipHorizontal, - fileHeight / fileWidth, + fileHeight > fileWidth ? fileHeight / fileWidth : fileWidth / fileHeight, viewAspect, fileWidth, fileHeight,