From 22fe3eb94f8e65ebad5d55b12c371a0b69bfc04a Mon Sep 17 00:00:00 2001 From: houxiao <houxiao@454eff88-639b-444f-9e54-f578c98de674> Date: 星期五, 12 五月 2017 10:18:12 +0800 Subject: [PATCH] add release --- VisitFace/RtspNativeCodec/app/src/main/java/com/example/nativecodec/NativeCodec.java | 151 ++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 134 insertions(+), 17 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 c9d8eac..3b029de 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,8 +17,9 @@ package com.example.nativecodec; import android.app.Activity; -import android.content.res.AssetManager; +import android.graphics.PixelFormat; import android.graphics.SurfaceTexture; +import android.graphics.drawable.Drawable; import android.os.Bundle; import android.util.Log; import android.view.Surface; @@ -30,10 +31,22 @@ import android.widget.Button; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; +import android.widget.ImageButton; +import android.widget.ImageView; import android.widget.RadioButton; import android.widget.Spinner; +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Canvas; +import android.util.AttributeSet; +import android.widget.Button; +import android.widget.TextView; -import java.io.IOException; +import java.nio.ByteBuffer; + +import cn.com.basic.face.util.NativeImg; +import cn.com.basic.face.util.RtspFaceNative; public class NativeCodec extends Activity { static final String TAG = "NativeCodec"; @@ -42,6 +55,9 @@ SurfaceView mSurfaceView1; SurfaceHolder mSurfaceHolder1; + + SurfaceView mSurfaceView2; + SurfaceHolder mSurfaceHolder2; VideoSink mSelectedVideoSink; VideoSink mNativeCodecPlayerVideoSink; @@ -52,19 +68,27 @@ boolean mCreated = false; boolean mIsPlaying = false; + public static NativeImg faceImg = null; + /** Called when the activity is first created. */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); - init(); + ThisActivity = this; + + RtspFaceNative.init(); + RtspFaceNative.setLocalIP("192.168.1.205"); mGLView1 = (MyGLSurfaceView) findViewById(R.id.glsurfaceview1); // set up the Surface 1 video sink mSurfaceView1 = (SurfaceView) findViewById(R.id.surfaceview1); mSurfaceHolder1 = mSurfaceView1.getHolder(); + + mSurfaceView2 = (SurfaceView) findViewById(R.id.surfaceview2); + mSurfaceHolder2 = mSurfaceView2.getHolder(); @@ -185,13 +209,34 @@ } if (mSourceString != null) { - setSurface(1, mSurfaceHolder1.getSurface()); - mGLView1VideoSink.useAsSinkForNative(); + //RtspFaceNative.setSurface(1, s, mSurfaceHolder1.getSurface()); + + //RtspFaceNative.setSurface(1, mSurfaceHolderDecoder1.getSurface()); + + Surface s = mSurfaceHolder1.getSurface(); + RtspFaceNative.setSurface(1, s); + + Surface s2 = mSurfaceHolder2.getSurface(); + RtspFaceNative.setSurface(2, s2); + + //SurfaceTexture st = mGLView1VideoSink.mMyGLSurfaceView.getSurfaceTexture(); + //Surface sgl = new Surface(st); + //RtspFaceNative.setSurface(2, sgl, sgl); + //mGLView1VideoSink.useAsSinkForNative(); + //sgl.release(); + + RtspFaceNative.setFaceCallback(1, "cn/com/basic/face/util/RtspFaceNative", "faceCallBack"); + //RtspFaceNative.setFaceCallback(2, "cn/com/basic/face/util/RtspFaceNative", "faceCallBack"); //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"); + //#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:a1234567@192.168.1.68:554/h264/ch1/main/av_stream"); //mCreated = createPlayer(1, "rtsp://192.168.1.56:8554"); + + //byte[] arr = new byte[5]; + //arr[0] = 3; arr[1] = 4; arr[2] = 5; + //RtspFaceNative.getFaceList(1, arr); } } @@ -215,6 +260,71 @@ } }); + + ((Button) findViewById(R.id.addface_native)).setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View view) { + Log.i("@@@", "addface_native onClick"); + + } + + }); + + ((ImageView) findViewById(R.id.addface_image)).setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View view) { + Log.i("@@@", "addface_image onClick"); + //ImageView image = (ImageView)ThisActivity.findViewById(R.id.addface_image); + //image.setImageBitmap(faceBitmap); + } + + }); + + ((Button) findViewById(R.id.addface_native)).setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View view) { + Log.i("@@@", "addface_image onClick"); + RtspFaceNative.dbgFaceAdd(ThisActivity.faceImg); + } + + }); + + } + + static NativeCodec ThisActivity; + + public static void setFaceDrawable(NativeImg img) + { + //ImageView image = (ImageView)ThisActivity.findViewById(R.id.addface_image); + //return image; + + ThisActivity.faceImg = img; + + //ImageView image = (ImageView)ThisActivity.findViewById(R.id.addface_image); + //image.callOnClick(); + + new Thread(new Runnable() { + @Override + public void run() { + ThisActivity.runOnUiThread(new Runnable() { + @Override + public void run() { + Bitmap bitmap = Bitmap.createBitmap(faceImg.width, faceImg.height, Bitmap.Config.ARGB_8888); + ByteBuffer byteBuffer = ByteBuffer.wrap(faceImg.image, 0, faceImg.size); + bitmap.copyPixelsFromBuffer(byteBuffer); + + ImageView image = (ImageView)ThisActivity.findViewById(R.id.addface_image); + image.setImageBitmap(bitmap); + + TextView textView1 = (TextView)ThisActivity.findViewById(R.id.textView1); + textView1.setText(RtspFaceNative.dbgGetLog()); + } + }); + } + }).start(); } void switchSurface() { @@ -266,8 +376,8 @@ @Override protected void onDestroy() { - shutdown(1); - shutdown(2); + RtspFaceNative.shutdown(1); + RtspFaceNative.shutdown(2); mCreated = false; super.onDestroy(); } @@ -286,16 +396,21 @@ //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); - + //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("rtspface"); + System.loadLibrary("opencv_java3"); } // VideoSink abstracts out the difference between Surface and SurfaceTexture @@ -324,7 +439,8 @@ void useAsSinkForNative() { Surface s = mSurfaceHolder.getSurface(); Log.i("@@@", "setting surface " + s); - setSurface(1, s); + //mSurfaceHolder1.setFormat(PixelFormat.RGBA_8888); + //RtspFaceNative.setSurface(1, s); } } @@ -345,7 +461,8 @@ void useAsSinkForNative() { SurfaceTexture st = mMyGLSurfaceView.getSurfaceTexture(); Surface s = new Surface(st); - setSurface(2, s); + //setEGLConfigChooser(8, 8, 8, 8, 0, 0); + //RtspFaceNative.setSurface(1, s); s.release(); } -- Gitblit v1.8.0