| | |
| | | package com.example.nativecodec; |
| | | |
| | | import android.app.Activity; |
| | | import android.app.NativeActivity; |
| | | import android.graphics.PixelFormat; |
| | | import android.graphics.SurfaceTexture; |
| | | import android.graphics.drawable.Drawable; |
| | | import android.os.Bundle; |
| | | import android.util.Log; |
| | | import android.util.Xml; |
| | | import android.view.Surface; |
| | | import android.view.SurfaceHolder; |
| | | import android.view.SurfaceView; |
| | |
| | | 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.BufferedReader; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.InputStreamReader; |
| | | import java.nio.ByteBuffer; |
| | | |
| | | import cn.com.basic.face.util.NativeImg; |
| | | import cn.com.basic.face.util.RtspFaceNative; |
| | | |
| | | public class NativeCodec extends Activity { |
| | |
| | | SurfaceView mSurfaceView1; |
| | | SurfaceHolder mSurfaceHolder1; |
| | | |
| | | SurfaceView mSurfaceView2; |
| | | SurfaceHolder mSurfaceHolder2; |
| | | |
| | | SurfaceView mSurfaceView3; |
| | | SurfaceHolder mSurfaceHolder3; |
| | | |
| | | VideoSink mSelectedVideoSink; |
| | | VideoSink mNativeCodecPlayerVideoSink; |
| | | |
| | |
| | | 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); |
| | | ThisActivity = this; |
| | | |
| | | try { |
| | | Process su = Runtime.getRuntime().exec("su"); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | //Runtime.getRuntime().exec(new String[]{"/system/bin/su","-c", cmd}); |
| | | |
| | | RtspFaceNative.init(); |
| | | RtspFaceNative.setLocalIP("192.168.1.10"); |
| | | for (int i=0 ;i < 32; i+=2){ |
| | | RtspFaceNative.setFaceLabel(1, i, "中文名字"); |
| | | RtspFaceNative.setFaceLabel(1, i+1, "abcd"); |
| | | RtspFaceNative.setFaceLabel(2, i, "中文名字"); |
| | | RtspFaceNative.setFaceLabel(2, i+1, "abcd"); |
| | | } |
| | | |
| | | RtspFaceNative.setLocalIP("192.168.1.82"); |
| | | |
| | | mGLView1 = (MyGLSurfaceView) findViewById(R.id.glsurfaceview1); |
| | | |
| | |
| | | mSurfaceView1 = (SurfaceView) findViewById(R.id.surfaceview1); |
| | | mSurfaceHolder1 = mSurfaceView1.getHolder(); |
| | | |
| | | mSurfaceView2 = (SurfaceView) findViewById(R.id.surfaceview2); |
| | | mSurfaceHolder2 = mSurfaceView2.getHolder(); |
| | | |
| | | mSurfaceView3 = (SurfaceView) findViewById(R.id.surfaceview3); |
| | | mSurfaceHolder3 = mSurfaceView3.getHolder(); |
| | | |
| | | |
| | | mSurfaceHolder1.addCallback(new SurfaceHolder.Callback() { |
| | |
| | | } |
| | | }); |
| | | |
| | | // initialize button click handlers |
| | | mSurfaceView1.getHolder().addCallback(new SurfaceHolder.Callback() { |
| | | @Override |
| | | public void surfaceCreated(SurfaceHolder holder) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void surfaceDestroyed(SurfaceHolder holder) { |
| | | |
| | | } |
| | | }); |
| | | |
| | | ((SurfaceView) findViewById(R.id.surfaceview3)).setOnClickListener(new View.OnClickListener() { |
| | | public void onClick(View view) { |
| | | mSurfaceHolder3.setFormat(PixelFormat.RGB_565); |
| | | Surface s3 = mSurfaceHolder3.getSurface(); |
| | | RtspFaceNative.setCaptureSurface(s3); |
| | | } |
| | | }); |
| | | |
| | | // initialize button click handlers |
| | | |
| | | // native MediaPlayer start/pause |
| | | ((Button) findViewById(R.id.start_native)).setOnClickListener(new View.OnClickListener() { |
| | |
| | | } |
| | | if (mSourceString != null) { |
| | | |
| | | RtspFaceNative.setSurface(1, mSurfaceHolder1.getSurface()); |
| | | mGLView1VideoSink.useAsSinkForNative(); |
| | | //RtspFaceNative.setSurface(1, s, mSurfaceHolder1.getSurface()); |
| | | |
| | | //RtspFaceNative.setSurface(1, mSurfaceHolderDecoder1.getSurface()); |
| | | |
| | | //mSurfaceHolder1.setFormat(PixelFormat.RGBA_8888); |
| | | mSurfaceHolder1.setFormat(PixelFormat.RGB_565); |
| | | Surface s = mSurfaceHolder1.getSurface(); |
| | | RtspFaceNative.setSurface(1, s); |
| | | |
| | | //mSurfaceHolder2.setFormat(PixelFormat.RGBA_8888); |
| | | mSurfaceHolder2.setFormat(PixelFormat.RGB_565); |
| | | 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"); |
| | | |
| | | //try |
| | | //{ |
| | | // String str = convertStreamToString(ThisActivity.getAssets().open("license.lic")); |
| | | // RtspFaceNative.dbgSetStfaceLicense(str); |
| | | //} |
| | | //catch(Exception ex) |
| | | //{ |
| | | // return ; |
| | | //} |
| | | |
| | | //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/sub/av_stream"); |
| | | //mCreated = RtspFaceNative.createPlayer(1, "rtsp://admin:admin@192.168.1.188:554/cam/realmonitor?channel=1&subtype=2"); |
| | | mCreated = RtspFaceNative.createPlayer(1, "rtsp://admin:admin12345@192.168.1.202:554/h264/ch1/main/av_stream"); |
| | | //mCreated = RtspFaceNative.createPlayer(2, "rtsp://Admin:1234@192.168.1.22/h264"); |
| | | //mCreated = RtspFaceNative.createPlayer(2, "rtsp://admin:a1234567@192.168.1.201: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"); |
| | | //RtspFaceNative.setFaceCallback(2, "cn/com/basic/face/util/RtspFaceNative", "faceCallBack"); |
| | | |
| | | //byte[] arr = new byte[5]; |
| | | //arr[0] = 3; arr[1] = 4; arr[2] = 5; |
| | |
| | | } |
| | | |
| | | }); |
| | | |
| | | ((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 String convertStreamToString(InputStream is) { |
| | | try |
| | | { |
| | | BufferedReader reader = new BufferedReader(new InputStreamReader(is)); |
| | | StringBuilder sb = new StringBuilder(); |
| | | String line = null; |
| | | while ((line = reader.readLine()) != null) { |
| | | sb.append(line).append("\n"); |
| | | } |
| | | reader.close(); |
| | | return sb.toString(); |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | | return ""; |
| | | } |
| | | } |
| | | |
| | | 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.RGB_565);//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() { |
| | |
| | | |
| | | /** Load jni .so on initialization */ |
| | | static { |
| | | System.loadLibrary("rtspface"); |
| | | System.loadLibrary("opencv_java3"); |
| | | //System.loadLibrary("rtspface_client"); |
| | | System.loadLibrary("rtspface_server"); |
| | | //System.loadLibrary("opencv_java3"); |
| | | } |
| | | |
| | | // VideoSink abstracts out the difference between Surface and SurfaceTexture |
| | |
| | | Surface s = mSurfaceHolder.getSurface(); |
| | | Log.i("@@@", "setting surface " + s); |
| | | //mSurfaceHolder1.setFormat(PixelFormat.RGBA_8888); |
| | | RtspFaceNative.setSurface(1, s); |
| | | //RtspFaceNative.setSurface(1, s); |
| | | } |
| | | |
| | | } |
| | |
| | | SurfaceTexture st = mMyGLSurfaceView.getSurfaceTexture(); |
| | | Surface s = new Surface(st); |
| | | //setEGLConfigChooser(8, 8, 8, 8, 0, 0); |
| | | RtspFaceNative.setSurface(2, s); |
| | | //RtspFaceNative.setSurface(1, s); |
| | | s.release(); |
| | | } |
| | | |