@@ -44,7 +44,7 @@ class Camera2RTSPPreviewServer extends AbstractRTSPPreviewServer implements Rtsp
4444
4545 static final String MIME_TYPE = "video/x-rtp" ;
4646
47- private static final String SERVER_NAME = "Android Host Screen RTSP Server" ;
47+ private static final String SERVER_NAME = "Android Host Camera2 RTSP Server" ;
4848
4949 private final Object mLockObj = new Object ();
5050
@@ -62,7 +62,7 @@ class Camera2RTSPPreviewServer extends AbstractRTSPPreviewServer implements Rtsp
6262 private final Object mSync = new Object ();
6363 private volatile boolean mIsRecording ;
6464 private boolean requestDraw ;
65- private DrawTask mScreenCaptureTask ;
65+ private DrawTask mCameraCaptureTask ;
6666 private AACStream mAac ;
6767
6868 Camera2RTSPPreviewServer (final Context context ,
@@ -108,7 +108,7 @@ public void startWebServer(final OnWebServerStartCallback callback) {
108108 }
109109 }
110110 if (mHandler == null ) {
111- HandlerThread thread = new HandlerThread ("ScreenCastRTSPPreviewServer " );
111+ HandlerThread thread = new HandlerThread ("Camera2RTSPPreviewServer " );
112112 thread .start ();
113113 mHandler = new Handler (thread .getLooper ());
114114 }
@@ -159,7 +159,7 @@ public void onDisplayRotation(final int rotation) {
159159 if (DEBUG ) {
160160 Log .d (TAG , "onDisplayRotation: rotation=" + rotation );
161161 }
162- DrawTask drawTask = mScreenCaptureTask ;
162+ DrawTask drawTask = mCameraCaptureTask ;
163163 synchronized (mLockObj ) {
164164 if (drawTask != null ) {
165165 drawTask .onDisplayRotationChange (rotation );
@@ -209,9 +209,9 @@ private Session startPreviewStreaming(final Socket clientSocket) throws IOExcept
209209 synchronized (mLockObj ) {
210210 mClientSocket = clientSocket ;
211211 mVideoStream = new SurfaceH264Stream (prefs , videoQuality );
212- mScreenCaptureTask = new DrawTask (null , 0 , videoQuality );
212+ mCameraCaptureTask = new DrawTask (null , 0 , videoQuality );
213213 mIsRecording = true ;
214- new Thread (mScreenCaptureTask , "ScreenCaptureThread " ).start ();
214+ new Thread (mCameraCaptureTask , "CameraCaptureThread " ).start ();
215215 }
216216
217217 SessionBuilder builder = new SessionBuilder ();
@@ -335,7 +335,7 @@ protected void onStop() {
335335
336336 @ Override
337337 protected boolean onError (final Exception e ) {
338- Log .w (TAG , "mScreenCaptureTask :" , e );
338+ Log .w (TAG , "mCameraCaptureTask :" , e );
339339 return false ;
340340 }
341341
@@ -354,43 +354,46 @@ protected Object processRequest(final int request, final int arg1, final int arg
354354 }
355355 };
356356
357- private final Runnable mDrawTask = () -> {
358- boolean localRequestDraw ;
359- synchronized (mSync ) {
360- localRequestDraw = requestDraw ;
361- if (!requestDraw ) {
362- try {
363- mSync .wait (intervals );
364- localRequestDraw = requestDraw ;
365- requestDraw = false ;
366- } catch (final InterruptedException e ) {
367- if (DEBUG ) {
368- Log .v (TAG , "draw:InterruptedException" );
357+ private final Runnable mDrawTask = new Runnable () {
358+ @ Override
359+ public void run () {
360+ boolean localRequestDraw ;
361+ synchronized (mSync ) {
362+ localRequestDraw = requestDraw ;
363+ if (!requestDraw ) {
364+ try {
365+ mSync .wait (intervals );
366+ localRequestDraw = requestDraw ;
367+ requestDraw = false ;
368+ } catch (final InterruptedException e ) {
369+ if (DEBUG ) {
370+ Log .v (TAG , "draw:InterruptedException" );
371+ }
372+ return ;
369373 }
370- return ;
371374 }
372375 }
373- }
374- if (mIsRecording ) {
375- synchronized (mDrawSync ) {
376- if (localRequestDraw ) {
377- mSourceTexture .updateTexImage ();
378- mSourceTexture .getTransformMatrix (mTexMatrix );
379- Matrix .rotateM (mTexMatrix , 0 , mRotationDegree , 0 , 0 , 1 );
380- Matrix .translateM (mTexMatrix , 0 , mDeltaX , mDeltaY , 0 );
376+ if (mIsRecording ) {
377+ synchronized (mDrawSync ) {
378+ if (localRequestDraw ) {
379+ mSourceTexture .updateTexImage ();
380+ mSourceTexture .getTransformMatrix (mTexMatrix );
381+ Matrix .rotateM (mTexMatrix , 0 , mRotationDegree , 0 , 0 , 1 );
382+ Matrix .translateM (mTexMatrix , 0 , mDeltaX , mDeltaY , 0 );
383+ }
384+ // SurfaceTextureで受け取った画像をMediaCodecの入力用Surfaceへ描画する
385+ mEncoderSurface .makeCurrent ();
386+ mDrawer .draw (mTexId , mTexMatrix , 0 );
387+ mEncoderSurface .swap ();
388+ // EGL保持用のオフスクリーンに描画しないとハングアップする機種の為のworkaround
389+ makeCurrent ();
390+ GLES20 .glClear (GLES20 .GL_COLOR_BUFFER_BIT );
391+ GLES20 .glFlush ();
392+ queueEvent (this );
381393 }
382- // SurfaceTextureで受け取った画像をMediaCodecの入力用Surfaceへ描画する
383- mEncoderSurface .makeCurrent ();
384- mDrawer .draw (mTexId , mTexMatrix , 0 );
385- mEncoderSurface .swap ();
386- // EGL保持用のオフスクリーンに描画しないとハングアップする機種の為のworkaround
387- makeCurrent ();
388- GLES20 .glClear (GLES20 .GL_COLOR_BUFFER_BIT );
389- GLES20 .glFlush ();
390- queueEvent (this );
394+ } else {
395+ releaseSelf ();
391396 }
392- } else {
393- releaseSelf ();
394397 }
395398 };
396399
0 commit comments