| | |
| | | package cn.com.basic.face.fragment; |
| | | |
| | | import android.graphics.Rect; |
| | | import android.graphics.SurfaceTexture; |
| | | import android.os.Bundle; |
| | | import android.support.v7.widget.GridLayoutManager; |
| | | import android.support.v7.widget.LinearLayoutManager; |
| | | import android.support.v7.widget.RecyclerView; |
| | | import android.util.Log; |
| | | import android.view.Surface; |
| | | import android.view.SurfaceHolder; |
| | | import android.view.SurfaceView; |
| | | import android.view.View; |
| | | import android.widget.RadioButton; |
| | | import android.widget.RadioGroup; |
| | | import android.widget.VideoView; |
| | | |
| | | import com.bsk.zhangbo.demoforbsk.R; |
| | | import cn.com.basic.face.adapter.SupervisoryAdapter; |
| | | import cn.com.basic.face.adapter.SupervisoryBottomListViewAdapter; |
| | | import cn.com.basic.face.base.BaseFragment; |
| | | import cn.com.basic.face.service.CheckInMng; |
| | | import cn.com.basic.face.util.RtspFaceNative; |
| | | |
| | | import com.bsk.zhangbo.demoforbsk.util.RtspFaceNative; |
| | | |
| | | import cn.com.basic.face.service.SupervisoryMng; |
| | | import cn.com.basic.face.util.WindowsUtil; |
| | | import cn.com.basic.face.widget.MyGLSurfaceView; |
| | | import com.camnter.easyrecyclerview.widget.EasyRecyclerView; |
| | | import com.lidroid.xutils.view.annotation.ViewInject; |
| | | import com.orhanobut.logger.Logger; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | |
| | | */ |
| | | |
| | | public class SupervisoryFragment extends BaseFragment { |
| | | |
| | | static { |
| | | //System.loadLibrary("rtspface");//xiuxi |
| | | } |
| | | |
| | | @ViewInject(R.id.fragment_supervisory_bottom_left_radio_group) |
| | | private RadioGroup fragment_supervisory_bottom_left_radio_group; |
| | |
| | | private EasyRecyclerView fragment_supervisory_bottom_register_list; |
| | | @ViewInject(R.id.fragment_supervisory_bottom_visitor_list) |
| | | private EasyRecyclerView fragment_supervisory_bottom_visitor_list; |
| | | @ViewInject(R.id.fragment_supervisory_enter_camera) |
| | | VideoView fragment_supervisory_enter_camera; |
| | | @ViewInject(R.id.fragment_supervisory_exit_camera) |
| | | VideoView fragment_supervisory_exit_camera; |
| | | |
| | | private SupervisoryAdapter mAdapter; |
| | | private SupervisoryBottomListViewAdapter mAdapter; |
| | | private List mList; |
| | | static boolean useNative = false; |
| | | |
| | | //播放 |
| | | |
| | | String mSourceString = "clips/testfile.mp4"; |
| | | |
| | | SurfaceView fragment_supervisory_enter_camera; |
| | | SurfaceView fragment_supervisory_exit_camera; |
| | | SurfaceHolder mSurfaceHolder1; |
| | | |
| | | VideoSink mSelectedVideoSink; |
| | | |
| | | |
| | | SurfaceHolderVideoSink mSurfaceHolder1VideoSink; |
| | | |
| | | VideoSink mNativeCodecPlayerVideoSink; |
| | | GLViewVideoSink mGLView1VideoSink; |
| | | boolean mCreated = false; |
| | | boolean mIsPlaying = false; |
| | | |
| | | |
| | | |
| | | static { |
| | | if (useNative) { |
| | | System.loadLibrary("rtspface"); |
| | | RtspFaceNative.init(); |
| | | } |
| | | } |
| | | |
| | | private static SupervisoryFragment instance = new SupervisoryFragment(); |
| | | |
| | |
| | | |
| | | @Override |
| | | protected void initViews(View view, Bundle savedInstanceState) { |
| | | fragment_supervisory_bottom_left_radio_group = (RadioGroup) view.findViewById(R.id.fragment_supervisory_bottom_left_radio_group); |
| | | fragment_supervisory_bottom_visitor_radio_button = (RadioButton) view.findViewById(R.id.fragment_supervisory_bottom_visitor_radio_button); |
| | | fragment_supervisory_bottom_attendance_radio_button = (RadioButton) view.findViewById(R.id.fragment_supervisory_bottom_attendance_radio_button); |
| | | fragment_supervisory_bottom_visitor_background = view.findViewById(R.id.fragment_supervisory_bottom_visitor_background); |
| | | fragment_supervisory_bottom_attendance_background = view.findViewById(R.id.fragment_supervisory_bottom_attendance_background); |
| | | fragment_supervisory_bottom_register_list = (EasyRecyclerView) view.findViewById(R.id.fragment_supervisory_bottom_register_list); |
| | | fragment_supervisory_bottom_visitor_list = (EasyRecyclerView) view.findViewById(R.id.fragment_supervisory_bottom_visitor_list); |
| | | fragment_supervisory_bottom_visitor_radio_button.setChecked(true); |
| | | fragment_supervisory_bottom_register_list.addItemDecoration(new SpaceItemDecoration()); |
| | | GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 2); |
| | | gridLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); |
| | | fragment_supervisory_bottom_register_list.setLayoutManager(gridLayoutManager); |
| | | mAdapter = new SupervisoryAdapter(getActivity()); |
| | | |
| | | |
| | | fragment_supervisory_exit_camera = (SurfaceView) view.findViewById(R.id.fragment_supervisory_exit_camera); |
| | | fragment_supervisory_enter_camera = (SurfaceView) view.findViewById(R.id.fragment_supervisory_enter_camera); |
| | | RtspFaceNative.init(); |
| | | RtspFaceNative.setSurface(1, fragment_supervisory_enter_camera.getHolder().getSurface()); |
| | | RtspFaceNative.setSurface(2, fragment_supervisory_exit_camera.getHolder().getSurface()); |
| | | |
| | | mSurfaceHolder1 = fragment_supervisory_enter_camera.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(fragment_supervisory_exit_camera instanceof MyGLSurfaceView) { |
| | | ((MyGLSurfaceView) fragment_supervisory_exit_camera).onResume(); |
| | | } |
| | | if (mGLView1VideoSink == null) { |
| | | mGLView1VideoSink = new GLViewVideoSink(fragment_supervisory_exit_camera); |
| | | } |
| | | mSelectedVideoSink = mGLView1VideoSink; |
| | | |
| | | |
| | | //播放延迟(初始化较慢,可能导致无法正常播放) |
| | | Thread thread = new Thread(new Runnable() { |
| | | mAdapter = new SupervisoryBottomListViewAdapter(getActivity()); |
| | | 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"); |
| | | } |
| | | Thread.sleep(2000); |
| | | if (useNative) { |
| | | RtspFaceNative.setSurface(1, fragment_supervisory_enter_camera.getHolder().getSurface()); |
| | | RtspFaceNative.setSurface(2, fragment_supervisory_exit_camera.getHolder().getSurface()); |
| | | RtspFaceNative.createPlayer(1, "rtsp://admin:admin12345@192.168.1.70:554/h264/ch1/sub/av_stream"); |
| | | RtspFaceNative.createPlayer(2, "rtsp://admin:admin12345@192.168.1.70:554/h264/ch1/sub/av_stream"); |
| | | } else { |
| | | // fragment_supervisory_enter_camera.setVideoURI(Uri.parse("rtsp://admin:admin12345@192.168.1.70:554/h264/ch1/sub/av_stream")); |
| | | // fragment_supervisory_enter_camera.requestFocus(); |
| | | // fragment_supervisory_enter_camera.start(); |
| | | // fragment_supervisory_exit_camera.setVideoURI(Uri.parse("rtsp://admin:admin12345@192.168.1.70:554/h264/ch1/main/av_stream")); |
| | | // fragment_supervisory_exit_camera.requestFocus(); |
| | | // fragment_supervisory_exit_camera.start(); |
| | | } |
| | | if (mCreated) { |
| | | mIsPlaying = !mIsPlaying; |
| | | //setPlayingStreamingMediaPlayer(mIsPlaying); |
| | | } |
| | | |
| | | } catch (InterruptedException e) { |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }); |
| | | thread.start();//xiuxi |
| | | }).start(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | fragment_supervisory_bottom_visitor_list.setVisibility(View.VISIBLE); |
| | | break; |
| | | } |
| | | reloadBottomList(); |
| | | } |
| | | }); |
| | | } |
| | |
| | | public void setMenuVisibility(boolean menuVisible) { |
| | | super.setMenuVisibility(menuVisible); |
| | | if (menuVisible) { |
| | | // reloadBottomList(); |
| | | reloadBottomList(); |
| | | } |
| | | } |
| | | |
| | | private void reloadBottomList() { |
| | | mList = new ArrayList(); |
| | | CheckInMng.getInstance().findVisitorList(); |
| | | mAdapter = new SupervisoryAdapter(getActivity()); |
| | | mAdapter.setList(mList); |
| | | fragment_supervisory_bottom_register_list.setAdapter(mAdapter); |
| | | if (fragment_supervisory_bottom_register_list != null) { |
| | | mList = new ArrayList(); |
| | | SupervisoryMng.getInstance().findSupervisoryBottomList(); |
| | | mAdapter = new SupervisoryBottomListViewAdapter(getActivity()); |
| | | mAdapter.setList(mList); |
| | | fragment_supervisory_bottom_register_list.setAdapter(mAdapter); |
| | | } |
| | | } |
| | | |
| | | private class SpaceItemDecoration extends RecyclerView.ItemDecoration { |
| | | @Override |
| | | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { |
| | | super.getItemOffsets(outRect, view, parent, state); |
| | | // outRect.bottom = WindowsUtil.dip2px(getActivity(), 7); |
| | | outRect.right = WindowsUtil.dip2px(getActivity(), 15); |
| | | |
| | | if (parent.getChildLayoutPosition(view) == 0 || parent.getChildLayoutPosition(view) == 1) { |
| | |
| | | } |
| | | } |
| | | |
| | | 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"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Called when the activity is about to be paused. |
| | | */ |
| | | @Override |
| | | public void onPause() { |
| | | mIsPlaying = false; |
| | | if(fragment_supervisory_exit_camera instanceof MyGLSurfaceView) { |
| | | ((MyGLSurfaceView) fragment_supervisory_exit_camera).onPause(); |
| | | } |
| | | //setPlayingStreamingMediaPlayer(false);//xiuxi |
| | | super.onPause(); |
| | | } |
| | | |
| | | @Override |
| | | public void onResume() { |
| | | super.onResume(); |
| | | if(fragment_supervisory_exit_camera instanceof MyGLSurfaceView) { |
| | | ((MyGLSurfaceView) fragment_supervisory_exit_camera).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()); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | } |