| | |
| | | super.onCreate(icicle); |
| | | setContentView(R.layout.main); |
| | | |
| | | 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() { |
| | | |
| | |
| | | public void surfaceCreated(SurfaceHolder holder) { |
| | | Log.v(TAG, "surfaceCreated"); |
| | | if (mRadio1.isChecked()) { |
| | | setSurface(holder.getSurface()); |
| | | //setSurface(1, holder.getSurface()); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | 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); |
| | |
| | | public void onClick(View v) { |
| | | mRadio2.toggle(); |
| | | } |
| | | }); |
| | | }); |
| | | |
| | | // initialize button click handlers |
| | | |
| | |
| | | if (mSelectedVideoSink == null) { |
| | | return; |
| | | } |
| | | mSelectedVideoSink.useAsSinkForNative(); |
| | | //mSelectedVideoSink.useAsSinkForNative(); |
| | | mNativeCodecPlayerVideoSink = mSelectedVideoSink; |
| | | } |
| | | if (mSourceString != null) { |
| | | mCreated = createStreamingMediaPlayer(getResources().getAssets(), |
| | | mSourceString); |
| | | |
| | | setSurface(1, mSurfaceHolder1.getSurface()); |
| | | mGLView1VideoSink.useAsSinkForNative(); |
| | | |
| | | //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"); |
| | | |
| | | } |
| | | } |
| | | if (mCreated) { |
| | | mIsPlaying = !mIsPlaying; |
| | | setPlayingStreamingMediaPlayer(mIsPlaying); |
| | | //setPlayingStreamingMediaPlayer(mIsPlaying); |
| | | } |
| | | } |
| | | |
| | |
| | | @Override |
| | | public void onClick(View view) { |
| | | if (mNativeCodecPlayerVideoSink != null) { |
| | | rewindStreamingMediaPlayer(); |
| | | //rewindStreamingMediaPlayer(); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | 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; |
| | | } |
| | | } |
| | |
| | | protected void onPause() |
| | | { |
| | | mIsPlaying = false; |
| | | setPlayingStreamingMediaPlayer(false); |
| | | //setPlayingStreamingMediaPlayer(false); |
| | | mGLView1.onPause(); |
| | | super.onPause(); |
| | | } |
| | |
| | | @Override |
| | | protected void onDestroy() |
| | | { |
| | | shutdown(); |
| | | shutdown(1); |
| | | shutdown(2); |
| | | mCreated = false; |
| | | super.onDestroy(); |
| | | } |
| | |
| | | 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); |
| | | |
| | | |
| | | /** Load jni .so on initialization */ |
| | | static { |
| | | System.loadLibrary("native-codec-jni"); |
| | | System.loadLibrary("rtspface"); |
| | | } |
| | | |
| | | // VideoSink abstracts out the difference between Surface and SurfaceTexture |
| | |
| | | void useAsSinkForNative() { |
| | | Surface s = mSurfaceHolder.getSurface(); |
| | | Log.i("@@@", "setting surface " + s); |
| | | setSurface(s); |
| | | setSurface(1, s); |
| | | } |
| | | |
| | | } |
| | |
| | | void useAsSinkForNative() { |
| | | SurfaceTexture st = mMyGLSurfaceView.getSurfaceTexture(); |
| | | Surface s = new Surface(st); |
| | | setSurface(s); |
| | | setSurface(2, s); |
| | | s.release(); |
| | | } |
| | | |