From a04a8dde310553ffd1e9fe21ab57f06a77e56159 Mon Sep 17 00:00:00 2001
From: xuxiuxi <xuxiuxi@454eff88-639b-444f-9e54-f578c98de674>
Date: 星期三, 12 四月 2017 10:33:54 +0800
Subject: [PATCH]
---
VisitFace/RtspNativeCodec/app/src/main/java/com/example/nativecodec/NativeCodec.java | 149 ++++++++++++++++++++++++++++++++-----------------
1 files changed, 98 insertions(+), 51 deletions(-)
diff --git a/VisitFace/RtspNativeCodec/app/src/main/java/com/example/nativecodec/NativeCodec.java b/VisitFace/RtspNativeCodec/app/src/main/java/com/example/nativecodec/NativeCodec.java
index ada6508..2775aac 100644
--- a/VisitFace/RtspNativeCodec/app/src/main/java/com/example/nativecodec/NativeCodec.java
+++ b/VisitFace/RtspNativeCodec/app/src/main/java/com/example/nativecodec/NativeCodec.java
@@ -17,7 +17,6 @@
package com.example.nativecodec;
import android.app.Activity;
-import android.content.res.AssetManager;
import android.graphics.SurfaceTexture;
import android.os.Bundle;
import android.util.Log;
@@ -33,7 +32,7 @@
import android.widget.RadioButton;
import android.widget.Spinner;
-import java.io.IOException;
+import cn.com.basic.face.util.RtspFaceNative;
public class NativeCodec extends Activity {
static final String TAG = "NativeCodec";
@@ -52,17 +51,23 @@
boolean mCreated = false;
boolean mIsPlaying = false;
+
+
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
+ RtspFaceNative.init();
+
mGLView1 = (MyGLSurfaceView) findViewById(R.id.glsurfaceview1);
// set up the Surface 1 video sink
mSurfaceView1 = (SurfaceView) findViewById(R.id.surfaceview1);
mSurfaceHolder1 = mSurfaceView1.getHolder();
+
+
mSurfaceHolder1.addCallback(new SurfaceHolder.Callback() {
@@ -76,7 +81,7 @@
public void surfaceCreated(SurfaceHolder holder) {
Log.v(TAG, "surfaceCreated");
if (mRadio1.isChecked()) {
- setSurface(holder.getSurface());
+ //setSurface(1, holder.getSurface());
}
}
@@ -114,33 +119,37 @@
OnCheckedChangeListener checklistener = new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- Log.i("@@@@", "oncheckedchanged");
- if (buttonView == mRadio1 && isChecked) {
- mRadio2.setChecked(false);
- }
- if (buttonView == mRadio2 && isChecked) {
- mRadio1.setChecked(false);
- }
- if (isChecked) {
- if (mRadio1.isChecked()) {
- if (mSurfaceHolder1VideoSink == null) {
- mSurfaceHolder1VideoSink = new SurfaceHolderVideoSink(mSurfaceHolder1);
- }
- mSelectedVideoSink = mSurfaceHolder1VideoSink;
- mGLView1.onPause();
- Log.i("@@@@", "glview pause");
- } else {
- mGLView1.onResume();
- if (mGLView1VideoSink == null) {
- mGLView1VideoSink = new GLViewVideoSink(mGLView1);
- }
- mSelectedVideoSink = mGLView1VideoSink;
- }
- switchSurface();
- }
- }
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ Log.i("@@@@", "oncheckedchanged");
+ if (buttonView == mRadio1 && isChecked) {
+ mRadio2.setChecked(false);
+ }
+ if (buttonView == mRadio2 && isChecked) {
+ mRadio1.setChecked(false);
+ }
+
+
+ if (isChecked) {
+ if (mRadio1.isChecked()) {
+ if (mSurfaceHolder1VideoSink == null) {
+ mSurfaceHolder1VideoSink = new SurfaceHolderVideoSink(mSurfaceHolder1);
+ //mSurfaceHolder1VideoSink.useAsSinkForNative();
+ }
+ mSelectedVideoSink = mSurfaceHolder1VideoSink;
+ mGLView1.onPause();
+ Log.i("@@@@", "glview pause");
+ } else {
+ mGLView1.onResume();
+ if (mGLView1VideoSink == null) {
+ mGLView1VideoSink = new GLViewVideoSink(mGLView1);
+ //mGLView1VideoSink.useAsSinkForNative();
+ }
+ mSelectedVideoSink = mGLView1VideoSink;
+ }
+ switchSurface();
+ }
+ }
};
mRadio1.setOnCheckedChangeListener(checklistener);
mRadio2.setOnCheckedChangeListener(checklistener);
@@ -158,7 +167,7 @@
public void onClick(View v) {
mRadio2.toggle();
}
- });
+ });
// initialize button click handlers
@@ -172,17 +181,31 @@
if (mSelectedVideoSink == null) {
return;
}
- mSelectedVideoSink.useAsSinkForNative();
+ //mSelectedVideoSink.useAsSinkForNative();
mNativeCodecPlayerVideoSink = mSelectedVideoSink;
}
if (mSourceString != null) {
- mCreated = createStreamingMediaPlayer(getResources().getAssets(),
- mSourceString);
+
+ RtspFaceNative.setSurface(1, mSurfaceHolder1.getSurface());
+ mGLView1VideoSink.useAsSinkForNative();
+
+ //mCreated = createStreamingMediaPlayer(getResources().getAssets(), mSourceString);
+ //#todo ok
+ mCreated = RtspFaceNative.createPlayer(1, "rtsp://admin:admin12345@192.168.1.70:554/h264/ch1/main/av_stream");
+ //mCreated = RtspFaceNative.createPlayer(2, "rtsp://admin:admin12345@192.168.1.70:554/h264/ch1/main/av_stream");
+ //mCreated = createPlayer(1, "rtsp://192.168.1.56:8554");
+
+ RtspFaceNative.setFaceCallback(1, "cn/com/basic/face/util/RtspFaceNative", "faceCallBack");
+
+ //byte[] arr = new byte[5];
+ //arr[0] = 3; arr[1] = 4; arr[2] = 5;
+ //RtspFaceNative.getFaceList(1, arr);
+
}
}
if (mCreated) {
mIsPlaying = !mIsPlaying;
- setPlayingStreamingMediaPlayer(mIsPlaying);
+ //setPlayingStreamingMediaPlayer(mIsPlaying);
}
}
@@ -195,7 +218,7 @@
@Override
public void onClick(View view) {
if (mNativeCodecPlayerVideoSink != null) {
- rewindStreamingMediaPlayer();
+ //rewindStreamingMediaPlayer();
}
}
@@ -203,16 +226,27 @@
}
void switchSurface() {
+
+ //mGLView1VideoSink.useAsSinkForNative();
+ //mSurfaceHolder1VideoSink.useAsSinkForNative();
+
if (mCreated && mNativeCodecPlayerVideoSink != mSelectedVideoSink) {
// shutdown and recreate on other surface
- Log.i("@@@", "shutting down player");
- shutdown();
+ Log.i("@@@", "shutting down player");
+ //shutdown(1);
+ //shutdown(2);
mCreated = false;
- mSelectedVideoSink.useAsSinkForNative();
+ //mSelectedVideoSink.useAsSinkForNative();
+
+
+
mNativeCodecPlayerVideoSink = mSelectedVideoSink;
if (mSourceString != null) {
Log.i("@@@", "recreating player");
- mCreated = createStreamingMediaPlayer(getResources().getAssets(),mSourceString);
+ //mCreated = createStreamingMediaPlayer(getResources().getAssets(),mSourceString);
+ //mCreated = createPlayer(1, "rtsp://admin:admin12345@192.168.1.70:554/h264/ch1/main/av_stream");
+ //mCreated = createPlayer(2, "rtsp://admin:admin12345@192.168.1.70:554/h264/ch1/main/av_stream");
+ //mCreated = createPlayer(1, "rtsp://192.168.1.56:8554");
mIsPlaying = false;
}
}
@@ -223,7 +257,7 @@
protected void onPause()
{
mIsPlaying = false;
- setPlayingStreamingMediaPlayer(false);
+ //setPlayingStreamingMediaPlayer(false);
mGLView1.onPause();
super.onPause();
}
@@ -240,7 +274,8 @@
@Override
protected void onDestroy()
{
- shutdown();
+ RtspFaceNative.shutdown(1);
+ RtspFaceNative.shutdown(2);
mCreated = false;
super.onDestroy();
}
@@ -252,16 +287,28 @@
private RadioButton mRadio2;
/** Native methods, implemented in jni folder */
- public static native void createEngine();
- public static native boolean createStreamingMediaPlayer(AssetManager assetMgr, String filename);
- public static native void setPlayingStreamingMediaPlayer(boolean isPlaying);
- public static native void shutdown();
- public static native void setSurface(Surface surface);
- public static native void rewindStreamingMediaPlayer();
+ //public static native void createEngine();
+ //public static native boolean createStreamingMediaPlayer(AssetManager assetMgr, String filename);
+ //public static native void setPlayingStreamingMediaPlayer(boolean isPlaying);
+ //public static native void shutdown();
+ //public static native void setSurface(Surface surface);
+ //public static native void rewindStreamingMediaPlayer();
+
+ //public static native void init();
+ //public static native void setSurface(int cameraIdx, Surface surface);
+ //public static native boolean createPlayer(int cameraIdx, String uri);
+ //public static native void shutdown(int cameraIdx);
+ //// typedef void (* Java_com_example_nativecodec_NativeCodec_FaceCallback_func)(int cameraIdx, int count);
+ //public static native boolean setFaceCallback(int cameraIdx, String func);
+ //public static native void lockFace(int cameraIdx);
+ //public static native void releaseFace(int cameraIdx);
+ //public static native boolean getFaceList(int cameraIdx, byte[] faceListPb);
+ //public static native boolean getFaceImages(int cameraIdx, byte[] faceImagesIdx, byte[] faceImages);
/** Load jni .so on initialization */
static {
- System.loadLibrary("native-codec-jni");
+ System.loadLibrary("rtspface");
+ System.loadLibrary("opencv_java3");
}
// VideoSink abstracts out the difference between Surface and SurfaceTexture
@@ -290,7 +337,7 @@
void useAsSinkForNative() {
Surface s = mSurfaceHolder.getSurface();
Log.i("@@@", "setting surface " + s);
- setSurface(s);
+ RtspFaceNative.setSurface(1, s);
}
}
@@ -311,7 +358,7 @@
void useAsSinkForNative() {
SurfaceTexture st = mMyGLSurfaceView.getSurfaceTexture();
Surface s = new Surface(st);
- setSurface(s);
+ RtspFaceNative.setSurface(2, s);
s.release();
}
--
Gitblit v1.8.0