Skip to content

Commit da81528

Browse files
Merge pull request #484 from TakayukiHoshi1984/bugfix_rtsp_closure
HostプラグインのRTSPサーバが動作していない問題の修正
2 parents c7b0a0c + 76d8a66 commit da81528

3 files changed

Lines changed: 75 additions & 75 deletions

File tree

dConnectDevicePlugin/dConnectDeviceHost/app/build.gradle

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,7 @@ dependencies {
7575
implementation 'org.deviceconnect:dconnect-device-plugin-sdk:2.8.2'
7676
implementation project(':dconnect-demo-lib')
7777
implementation project(':libstreaming')
78-
implementation('com.serenegiant:common:2.12.5') {
79-
exclude module: 'support-v4'
80-
//exclude module: 'recyclerview-v7'
81-
exclude module: 'support-fragment'
82-
exclude module: 'support-core-ui'
83-
exclude module: 'appcompat-v7'
84-
}
78+
implementation 'com.serenegiant:common:2.12.5'
8579
}
8680

8781
task zipDemo(type:Zip) {

dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/camera/Camera2RTSPPreviewServer.java

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -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

dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/screen/ScreenCastRTSPPreviewServer.java

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -306,39 +306,42 @@ protected Object processRequest(final int request, final int arg1, final int arg
306306
}
307307
};
308308

309-
private final Runnable mDrawTask = () -> {
310-
boolean localRequestDraw;
311-
synchronized (mSync) {
312-
localRequestDraw = requestDraw;
313-
if (!requestDraw) {
314-
try {
315-
mSync.wait(intervals);
316-
localRequestDraw = requestDraw;
317-
requestDraw = false;
318-
} catch (final InterruptedException e) {
319-
if (DEBUG) {
320-
Log.v(TAG, "draw:InterruptedException");
309+
private final Runnable mDrawTask = new Runnable() {
310+
@Override
311+
public void run() {
312+
boolean localRequestDraw;
313+
synchronized (mSync) {
314+
localRequestDraw = requestDraw;
315+
if (!requestDraw) {
316+
try {
317+
mSync.wait(intervals);
318+
localRequestDraw = requestDraw;
319+
requestDraw = false;
320+
} catch (final InterruptedException e) {
321+
if (DEBUG) {
322+
Log.v(TAG, "draw:InterruptedException");
323+
}
324+
return;
321325
}
322-
return;
323326
}
324327
}
325-
}
326-
if (mIsRecording) {
327-
if (localRequestDraw) {
328-
mSourceTexture.updateTexImage();
329-
mSourceTexture.getTransformMatrix(mTexMatrix);
328+
if (mIsRecording) {
329+
if (localRequestDraw) {
330+
mSourceTexture.updateTexImage();
331+
mSourceTexture.getTransformMatrix(mTexMatrix);
332+
}
333+
// SurfaceTextureで受け取った画像をMediaCodecの入力用Surfaceへ描画する
334+
mEncoderSurface.makeCurrent();
335+
mDrawer.draw(mTexId, mTexMatrix, 0);
336+
mEncoderSurface.swap();
337+
// EGL保持用のオフスクリーンに描画しないとハングアップする機種の為のworkaround
338+
makeCurrent();
339+
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
340+
GLES20.glFlush();
341+
queueEvent(this);
342+
} else {
343+
releaseSelf();
330344
}
331-
// SurfaceTextureで受け取った画像をMediaCodecの入力用Surfaceへ描画する
332-
mEncoderSurface.makeCurrent();
333-
mDrawer.draw(mTexId, mTexMatrix, 0);
334-
mEncoderSurface.swap();
335-
// EGL保持用のオフスクリーンに描画しないとハングアップする機種の為のworkaround
336-
makeCurrent();
337-
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
338-
GLES20.glFlush();
339-
queueEvent(this);
340-
} else {
341-
releaseSelf();
342345
}
343346
};
344347

0 commit comments

Comments
 (0)