Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.1.2 version #1

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
```

Expand Down
14 changes: 10 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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.18.2'
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
Expand All @@ -18,7 +24,7 @@ buildscript {
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

Expand Down
2 changes: 1 addition & 1 deletion gpuv/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 21 additions & 1 deletion gpuv/src/main/java/com/daasuu/gpuv/composer/GPUMp4Composer.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
35 changes: 18 additions & 17 deletions gpuv/src/main/java/com/daasuu/gpuv/player/GPUPlayerRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
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.*;
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;

Expand Down Expand Up @@ -40,29 +42,28 @@ public class GPUPlayerRenderer extends GlFrameBufferObjectRenderer implements Su

private float aspectRatio = 1f;

private SimpleExoPlayer simpleExoPlayer;
private ExoPlayer exoPlayer;
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) {
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();
});
}

Expand Down Expand Up @@ -91,7 +92,7 @@ public void onSurfaceCreated(final EGLConfig config) {
previewFilter.setup();

Surface surface = new Surface(previewTexture.getSurfaceTexture());
this.simpleExoPlayer.setVideoSurface(surface);
uiHandler.post(() -> exoPlayer.setVideoSurface(surface));

Matrix.setLookAtM(VMatrix, 0,
0.0f, 0.0f, 5.0f,
Expand Down Expand Up @@ -169,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() {
Expand Down
21 changes: 11 additions & 10 deletions gpuv/src/main/java/com/daasuu/gpuv/player/GPUPlayerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
10 changes: 5 additions & 5 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
60 changes: 24 additions & 36 deletions sample/src/main/java/com/daasuu/gpuvideoandroid/PlayerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,37 @@
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.SimpleExoPlayer;
import com.google.android.exoplayer2.source.ExtractorMediaSource;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.MediaItem;
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);
activity.startActivity(intent);
}

private GPUPlayerView gpuPlayerView;
private SimpleExoPlayer player;
private ExoPlayer player;
private Button button;
private SeekBar timeSeekBar;
private SeekBar filterSeekBar;
Expand Down Expand Up @@ -152,27 +150,20 @@ 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 ExoPlayer.Builder(this)
.setTrackSelector(new DefaultTrackSelector(this))
.build();

player.addMediaItem(MediaItem.fromUri(Uri.parse(STREAM_URL_MP4_VOD_LONG)));
player.prepare();
player.setPlayWhenReady(true);
}


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();
Expand All @@ -181,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();
}
Expand Down