| | |
| | | package com.bsk.zhangbo.demoforbsk.ui.fragment; |
| | | |
| | | import android.content.res.AssetManager; |
| | | import android.graphics.Rect; |
| | | import android.graphics.SurfaceTexture; |
| | | import android.os.Bundle; |
| | | import android.support.v4.view.ViewPager; |
| | | import android.support.v7.widget.GridLayoutManager; |
| | | import android.support.v7.widget.LinearLayoutManager; |
| | | import android.support.v7.widget.RecyclerView; |
| | |
| | | import android.view.View; |
| | | import android.widget.RadioButton; |
| | | import android.widget.RadioGroup; |
| | | import android.widget.Toast; |
| | | |
| | | import com.bsk.zhangbo.demoforbsk.R; |
| | | import com.bsk.zhangbo.demoforbsk.adapter.MyFragmentPagerAdapter; |
| | | import com.bsk.zhangbo.demoforbsk.adapter.OneBottomRecylerViewAdapter; |
| | | import com.bsk.zhangbo.demoforbsk.base.BaseFragment; |
| | | import com.bsk.zhangbo.demoforbsk.util.RtspFaceNative; |
| | | import com.bsk.zhangbo.demoforbsk.util.WindowsUtil; |
| | | import com.bsk.zhangbo.demoforbsk.widget.MyGLSurfaceView; |
| | | import com.camnter.easyrecyclerview.widget.EasyRecyclerView; |
| | | import com.orhanobut.logger.Logger; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import cn.com.basic.face.discern.query.item.FacePhotoItem; |
| | | |
| | | |
| | | /** |
| | |
| | | private List mList; |
| | | private EasyRecyclerView mRecyclerViewRegister, mRecyclerViewUser; |
| | | |
| | | |
| | | //播放 |
| | | |
| | | String mSourceString = "clips/testfile.mp4"; |
| | | |
| | | // SurfaceHolderVideoSink mSurfaceHolder1VideoSink; |
| | | // VideoSink mSelectedVideoSink; |
| | | // VideoSink mNativeCodecPlayerVideoSink; |
| | | // SurfaceView mSurfaceView1; |
| | | // SurfaceHolder mSurfaceHolder1; |
| | | // boolean mCreated = false; |
| | | // boolean mIsPlaying = false; |
| | | // String mSourceString = "clips/testfile.mp4"; |
| | | SurfaceView mSurfaceView1; |
| | | SurfaceView mSurfaceView2; |
| | | SurfaceHolder mSurfaceHolder1; |
| | | |
| | | /** |
| | | * 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(); |
| | | VideoSink mSelectedVideoSink; |
| | | |
| | | |
| | | SurfaceHolderVideoSink mSurfaceHolder1VideoSink; |
| | | |
| | | VideoSink mNativeCodecPlayerVideoSink; |
| | | GLViewVideoSink mGLView1VideoSink; |
| | | boolean mCreated = false; |
| | | boolean mIsPlaying = false; |
| | | |
| | | /** Load jni .so on initialization */ |
| | | static { |
| | | System.loadLibrary("native-codec-jni"); |
| | | System.loadLibrary("rtspface");//xiuxi |
| | | } |
| | | |
| | | |
| | | public static OneFragment newInstance() { |
| | | return new OneFragment(); |
| | | private static OneFragment instance = new OneFragment(); |
| | | |
| | | public static OneFragment getInstance() { |
| | | return instance; |
| | | } |
| | | |
| | | @Override |
| | |
| | | mAdapter = new OneBottomRecylerViewAdapter(getActivity()); |
| | | |
| | | |
| | | // set up the Surface 1 video sink |
| | | // mSurfaceView1 = (SurfaceView) view.findViewById(R.id.surfaceview1); |
| | | // mSurfaceHolder1 = mSurfaceView1.getHolder(); |
| | | // |
| | | // mSurfaceHolder1.addCallback(new SurfaceHolder.Callback() { |
| | | // |
| | | // @Override |
| | | // public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
| | | // Log.v("", "surfaceChanged format=" + format + ", width=" + width + ", height=" |
| | | // + height); |
| | | // } |
| | | // |
| | | // @Override |
| | | // public void surfaceCreated(SurfaceHolder holder) { |
| | | // Log.v("", "surfaceCreated"); |
| | | // setSurface(holder.getSurface()); |
| | | // } |
| | | // |
| | | // @Override |
| | | // public void surfaceDestroyed(SurfaceHolder holder) { |
| | | // Log.v("", "surfaceDestroyed"); |
| | | // } |
| | | // |
| | | // }); |
| | | } |
| | | mSurfaceView2 = (SurfaceView) view.findViewById(R.id.surfaceview2); |
| | | mSurfaceView1 = (SurfaceView) view.findViewById(R.id.surfaceview1); |
| | | RtspFaceNative.init(); |
| | | RtspFaceNative.setSurface(1, mSurfaceView1.getHolder().getSurface()); |
| | | RtspFaceNative.setSurface(2, mSurfaceView2.getHolder().getSurface()); |
| | | |
| | | @Override |
| | | protected void initToolbar(Bundle savedInstanceState) { |
| | | mSurfaceHolder1 = mSurfaceView1.getHolder(); |
| | | |
| | | mSurfaceHolder1.addCallback(new SurfaceHolder.Callback() { |
| | | |
| | | @Override |
| | | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
| | | Logger.e( "surfaceChanged format=" + format + ", width=" + width + ", height=" |
| | | + height); |
| | | } |
| | | |
| | | @Override |
| | | public void surfaceCreated(SurfaceHolder holder) { |
| | | Logger.e( "surfaceCreated"); |
| | | } |
| | | |
| | | @Override |
| | | public void surfaceDestroyed(SurfaceHolder holder) { |
| | | Logger.e( "surfaceDestroyed"); |
| | | } |
| | | |
| | | }); |
| | | //surfaceview |
| | | if (mSurfaceHolder1VideoSink == null) { |
| | | mSurfaceHolder1VideoSink = new SurfaceHolderVideoSink(mSurfaceHolder1); |
| | | } |
| | | mSelectedVideoSink = mSurfaceHolder1VideoSink; |
| | | |
| | | |
| | | //openGL |
| | | if(mSurfaceView2 instanceof MyGLSurfaceView) { |
| | | ((MyGLSurfaceView)mSurfaceView2).onResume(); |
| | | } |
| | | if (mGLView1VideoSink == null) { |
| | | mGLView1VideoSink = new GLViewVideoSink(mSurfaceView2); |
| | | } |
| | | mSelectedVideoSink = mGLView1VideoSink; |
| | | |
| | | |
| | | //播放延迟(初始化较慢,可能导致无法正常播放) |
| | | Thread thread = new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | try { |
| | | Thread.sleep(5000); |
| | | if (!mCreated) { |
| | | if (mNativeCodecPlayerVideoSink == null) { |
| | | if (mSelectedVideoSink == null) { |
| | | return; |
| | | } |
| | | mSelectedVideoSink.useAsSinkForNative(); |
| | | mSurfaceHolder1VideoSink.useAsSinkForNative(); |
| | | //mSelectedVideoSink.useAsSinkForNative(); |
| | | //mSurfaceHolder1VideoSink.useAsSinkForNative(); |
| | | mNativeCodecPlayerVideoSink = mSelectedVideoSink; |
| | | } |
| | | if (mSourceString != null) { |
| | | //mCreated = createStreamingMediaPlayer(getResources().getAssets(), |
| | | // mSourceString); |
| | | mCreated = RtspFaceNative.createPlayer(1, "rtsp://admin:admin12345@192.168.1.70:554/h264/ch1/sub/av_stream"); |
| | | mCreated = RtspFaceNative.createPlayer(2, "rtsp://admin:admin12345@192.168.1.70:554/h264/ch1/sub/av_stream"); |
| | | ////mCreated = createPlayer(2, "rtsp://admin:admin12345@192.168.1.70:554/h264/ch1/main/av_stream"); |
| | | } |
| | | } |
| | | if (mCreated) { |
| | | mIsPlaying = !mIsPlaying; |
| | | //setPlayingStreamingMediaPlayer(mIsPlaying); |
| | | } |
| | | |
| | | |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }); |
| | | thread.start();//xiuxi |
| | | } |
| | | |
| | | @Override |
| | |
| | | protected void initData() { |
| | | // switchSurface(); |
| | | mList = new ArrayList(); |
| | | for (int i = 0; i < 25; i++) { |
| | | mList.add(""); |
| | | for (int i = 0; i < 125; i++) { |
| | | FacePhotoItem item = new FacePhotoItem(); |
| | | //item.setType(); |
| | | item.setName("张三"+i); |
| | | if (i % 3 == 0) { |
| | | item.setStatus("来访登记"); |
| | | } else { |
| | | item.setStatus("签离"); |
| | | } |
| | | if (i % 5 == 0) { |
| | | item.setWarning(""); |
| | | } else { |
| | | item.setWarning("警告"); |
| | | } |
| | | mList.add(item); |
| | | } |
| | | mAdapter.setList(mList); |
| | | mRecyclerViewRegister.setAdapter(mAdapter); |
| | | |
| | | |
| | | // mSurfaceHolder1VideoSink = new SurfaceHolderVideoSink(mSurfaceHolder1); |
| | | // mSelectedVideoSink = mSurfaceHolder1VideoSink; |
| | | // mSelectedVideoSink.useAsSinkForNative(); |
| | | // mNativeCodecPlayerVideoSink = mSelectedVideoSink; |
| | | // |
| | | // mCreated = createStreamingMediaPlayer(getResources().getAssets(), |
| | | // mSourceString); |
| | | // mIsPlaying = !mIsPlaying; |
| | | // setPlayingStreamingMediaPlayer(mIsPlaying); |
| | | |
| | | } |
| | | |
| | | private class SpaceItemDecoration extends RecyclerView.ItemDecoration { |
| | |
| | | if (parent.getChildLayoutPosition(view) % 2 == 0) { |
| | | outRect.bottom = WindowsUtil.dip2px(getActivity(), 7); |
| | | } |
| | | // if (parent.getChildLayoutPosition(view) % 2 == 1) { |
| | | // outRect.right = WindowsUtil.dip2px(getActivity(), 4); |
| | | // }else { |
| | | // |
| | | // } |
| | | } |
| | | } |
| | | |
| | | void switchSurface() { |
| | | if (mCreated && mNativeCodecPlayerVideoSink != mSelectedVideoSink) { |
| | | // shutdown and recreate on other surface |
| | | Log.i("@@@", "shutting down player"); |
| | | RtspFaceNative.shutdown(1); |
| | | mCreated = false; |
| | | mSelectedVideoSink.useAsSinkForNative(); |
| | | mNativeCodecPlayerVideoSink = mSelectedVideoSink; |
| | | if (mSourceString != null) { |
| | | Log.i("@@@", "recreating player"); |
| | | //mCreated = createStreamingMediaPlayer(getResources().getAssets(), mSourceString); |
| | | mIsPlaying = false; |
| | | 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(2, "rtsp://admin:admin12345@192.168.1.70:554/h264/ch1/main/av_stream"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // void switchSurface() { |
| | | // if (mCreated && mNativeCodecPlayerVideoSink != mSelectedVideoSink) { |
| | | // // shutdown and recreate on other surface |
| | | // Log.i("@@@", "shutting down player"); |
| | | // shutdown(); |
| | | // mCreated = false; |
| | | // mSelectedVideoSink.useAsSinkForNative(); |
| | | // mNativeCodecPlayerVideoSink = mSelectedVideoSink; |
| | | // if (mSourceString != null) { |
| | | // Log.i("@@@", "recreating player"); |
| | | // mCreated = createStreamingMediaPlayer(getResources().getAssets(), mSourceString); |
| | | // mIsPlaying = false; |
| | | // } |
| | | // } |
| | | // } |
| | | /** |
| | | * Called when the activity is about to be paused. |
| | | */ |
| | | @Override |
| | | public void onPause() { |
| | | mIsPlaying = false; |
| | | if(mSurfaceView2 instanceof MyGLSurfaceView) { |
| | | ((MyGLSurfaceView)mSurfaceView2).onPause(); |
| | | } |
| | | //setPlayingStreamingMediaPlayer(false);//xiuxi |
| | | super.onPause(); |
| | | } |
| | | |
| | | // /** |
| | | // * Called when the activity is about to be paused. |
| | | // */ |
| | | // @Override |
| | | // public void onPause() { |
| | | // mIsPlaying = false; |
| | | // setPlayingStreamingMediaPlayer(false); |
| | | // super.onPause(); |
| | | // } |
| | | // |
| | | // /** |
| | | // * Called when the activity is about to be destroyed. |
| | | // */ |
| | | // @Override |
| | | // public void onDestroy() { |
| | | // shutdown(); |
| | | // mCreated = false; |
| | | // super.onDestroy(); |
| | | // } |
| | | // |
| | | // |
| | | // // VideoSink abstracts out the difference between Surface and SurfaceTexture |
| | | // // aka SurfaceHolder and GLSurfaceView |
| | | // static abstract class VideoSink { |
| | | // |
| | | // abstract void setFixedSize(int width, int height); |
| | | // |
| | | // abstract void useAsSinkForNative(); |
| | | // |
| | | // } |
| | | // |
| | | // static class SurfaceHolderVideoSink extends VideoSink { |
| | | // |
| | | // private final SurfaceHolder mSurfaceHolder; |
| | | // |
| | | // SurfaceHolderVideoSink(SurfaceHolder surfaceHolder) { |
| | | // mSurfaceHolder = surfaceHolder; |
| | | // } |
| | | // |
| | | // @Override |
| | | // void setFixedSize(int width, int height) { |
| | | // mSurfaceHolder.setFixedSize(width, height); |
| | | // } |
| | | // |
| | | // @Override |
| | | // void useAsSinkForNative() { |
| | | // Surface s = mSurfaceHolder.getSurface(); |
| | | // Log.i("@@@", "setting surface " + s); |
| | | // setSurface(s); |
| | | // } |
| | | // |
| | | // } |
| | | @Override |
| | | public void onResume() { |
| | | super.onResume(); |
| | | if(mSurfaceView2 instanceof MyGLSurfaceView) { |
| | | ((MyGLSurfaceView)mSurfaceView2).onResume(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Called when the activity is about to be destroyed. |
| | | */ |
| | | @Override |
| | | public void onDestroy() { |
| | | RtspFaceNative.shutdown(1); |
| | | mCreated = false; |
| | | super.onDestroy(); |
| | | } |
| | | |
| | | |
| | | // VideoSink abstracts out the difference between Surface and SurfaceTexture |
| | | // aka SurfaceHolder and GLSurfaceView |
| | | static abstract class VideoSink { |
| | | |
| | | abstract void setFixedSize(int width, int height); |
| | | |
| | | abstract void useAsSinkForNative(); |
| | | |
| | | } |
| | | |
| | | static class SurfaceHolderVideoSink extends VideoSink { |
| | | |
| | | private final SurfaceHolder mSurfaceHolder; |
| | | |
| | | SurfaceHolderVideoSink(SurfaceHolder surfaceHolder) { |
| | | mSurfaceHolder = surfaceHolder; |
| | | } |
| | | |
| | | @Override |
| | | void setFixedSize(int width, int height) { |
| | | mSurfaceHolder.setFixedSize(width, height); |
| | | } |
| | | |
| | | @Override |
| | | void useAsSinkForNative() { |
| | | Surface s = mSurfaceHolder.getSurface(); |
| | | Log.i("@@@", "setting surface " + s); |
| | | RtspFaceNative.setSurface(1, s); |
| | | |
| | | |
| | | /*SurfaceTexture st = mSurfaceHolder.getSurfaceTexture(); |
| | | Surface s = new Surface(st); |
| | | RtspFaceNative.setSurface(2, s); |
| | | s.release();*/ |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | static class GLViewVideoSink extends VideoSink { |
| | | |
| | | private final SurfaceView SurfaceView; |
| | | private final SurfaceHolder mSurfaceHolder; |
| | | |
| | | GLViewVideoSink(SurfaceView myGLSurfaceView) { |
| | | SurfaceView = myGLSurfaceView; |
| | | mSurfaceHolder = SurfaceView.getHolder(); |
| | | } |
| | | |
| | | @Override |
| | | void setFixedSize(int width, int height) { |
| | | mSurfaceHolder.setFixedSize(width, height); |
| | | } |
| | | |
| | | @Override |
| | | void useAsSinkForNative() { |
| | | if(SurfaceView instanceof MyGLSurfaceView) { |
| | | SurfaceTexture st = ((MyGLSurfaceView)SurfaceView).getSurfaceTexture(); |
| | | Surface s = new Surface(st); |
| | | RtspFaceNative.setSurface(2, s); |
| | | s.release(); |
| | | } else { |
| | | RtspFaceNative.setSurface(2, SurfaceView.getHolder().getSurface()); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | } |