Skip to content

Commit

Permalink
add Split Screen 1
Browse files Browse the repository at this point in the history
  • Loading branch information
andev009 committed Dec 26, 2018
1 parent 30315f4 commit 5a05016
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<activity android:name=".activity.NativeActivity"/>
<activity android:name=".activity.EGLActivity"/>
<activity android:name=".activity.LUTActivity"/>
<activity android:name=".activity.SplitScreenOneActivity"/>
<activity android:name=".record.RecordActivity"/>
</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.andev.androidshaderdemo.activity.FilterActivity;
import com.andev.androidshaderdemo.activity.LUTActivity;
import com.andev.androidshaderdemo.activity.NativeActivity;
import com.andev.androidshaderdemo.activity.SplitScreenOneActivity;
import com.andev.androidshaderdemo.record.RecordActivity;

public class MainActivity extends AppCompatActivity {
Expand Down Expand Up @@ -101,6 +102,9 @@ private void toOtherActivity(String section) {
Intent intent = new Intent(MainActivity.this, FilterActivity.class);
intent.putExtra("type", 12);
startActivity(intent);
}else if ("Split Screen 1".equals(section)) {
Intent intent = new Intent(MainActivity.this, SplitScreenOneActivity.class);
startActivity(intent);
}else if ("Record".equals(section)) {
Intent intent = new Intent(MainActivity.this, RecordActivity.class);
startActivity(intent);
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/andev/androidshaderdemo/Section.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public Section(){
sectionList.add("Burr");
sectionList.add("Soul out");
sectionList.add("Shake");
sectionList.add("Split Screen 1");
sectionList.add("Record");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package com.andev.androidshaderdemo.activity;


import android.graphics.SurfaceTexture;
import android.opengl.EGLContext;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.support.v7.app.AppCompatActivity;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

import com.andev.androidshaderdemo.R;
import com.andev.androidshaderdemo.record.render.OffScreenRender;
import com.andev.androidshaderdemo.record.render.OnFrameAvailableCallback;
import com.andev.androidshaderdemo.record.render.OnRenderStateCallback;
import com.andev.androidshaderdemo.record.utils.VideoFrameData;
import com.andev.androidshaderdemo.record.widget.CameraSurfaceView;

import javax.microedition.khronos.opengles.GL10;

public class SplitScreenOneActivity extends AppCompatActivity implements OnRenderStateCallback,
OnFrameAvailableCallback {

CameraSurfaceView cameraSurfaceView;
SurfaceView surfaceView;
EGLContext eglContext;

OffScreenRender offScreenRender;

private HandlerThread handlerThread;
private Handler previewHandler;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.split_screen_one_layout);

initViews();
}

private void initViews(){
cameraSurfaceView = (CameraSurfaceView)findViewById(R.id.cameraSurfaceView);
surfaceView = (SurfaceView)findViewById(R.id.surfaceView);

handlerThread = new HandlerThread("preview");
handlerThread.start();
previewHandler = new Handler(handlerThread.getLooper());

cameraSurfaceView.setOnRenderStateCallback(this);
cameraSurfaceView.setOnFrameAvailableCallback(this);
}


@Override
public void onSurfaceCreatedCallback(GL10 gl, final EGLContext eglContext, SurfaceTexture surfaceTexture) {
this.eglContext = eglContext;

surfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder surfaceHolder) {
previewHandler.post(new Runnable() {
@Override
public void run() {
offScreenRender = new OffScreenRender(eglContext, surfaceView.getHolder().getSurface());
}
});
}

@Override
public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) {

}

@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {

}
});
}

@Override
public void onSurfaceChangedCallback(GL10 gl, int width, int height) {

}


@Override
public void onFrameAvailableCallback(final VideoFrameData frameData) {
previewHandler.post(new Runnable() {
@Override
public void run() {
if(offScreenRender != null){
offScreenRender.draw(frameData.getFilter(), frameData.getMatrix(), frameData.getTextureId()
,frameData.getTimestamp());
}
}
});
}

@Override
public void onStop(){
super.onStop();

cameraSurfaceView.stopPreview();
offScreenRender.release();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void start(){
recordHandler.post(new Runnable() {
@Override
public void run() {
offScreenRender = new OffScreenRender(context, glContext, inputSurface);
offScreenRender = new OffScreenRender(glContext, inputSurface);
mediaCodec.start();
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.andev.androidshaderdemo.record.render;


import android.content.Context;
import android.opengl.EGLContext;
import android.util.Log;
import android.view.Surface;

import com.andev.androidshaderdemo.filter.CameraInputFilter;
Expand All @@ -16,9 +14,8 @@ public class OffScreenRender {
private OffSreenSurface offSreenSurface;

ImageFilter imageFilter;
Context context;

public OffScreenRender( Context context, EGLContext eglContext, Surface surface) {
public OffScreenRender(EGLContext eglContext, Surface surface) {
eglCore = new EglCore(eglContext, EglCore.FLAG_RECORDABLE);

offSreenSurface = new OffSreenSurface(eglCore, surface);
Expand Down Expand Up @@ -46,13 +43,8 @@ public void draw(CameraInputFilter cameraInputFilter, float[] matrix, int textur
// filter.draw(textureId, matrix,0,0);

cameraInputFilter.onDrawFrame(textureId);

Log.w(TAG, "textureId :" + textureId);
Log.w(TAG, "draw :" + time);

offSreenSurface.setPresentationTime(time);


offSreenSurface.swapBuffers();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,5 @@ public void onFrameAvailableCallback(VideoFrameData frameData) {
onFrameAvailableCallback.onFrameAvailableCallback(frameData);
}
}

}
21 changes: 21 additions & 0 deletions app/src/main/res/layout/split_screen_one_layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<com.andev.androidshaderdemo.record.widget.CameraSurfaceView
android:id="@+id/cameraSurfaceView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
/>

<SurfaceView
android:id="@+id/surfaceView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"/>

</LinearLayout>

0 comments on commit 5a05016

Please sign in to comment.