From b71bf40708a514c267c869d7f2d7d759479dfc4a Mon Sep 17 00:00:00 2001 From: Takayuki Hoshi Date: Thu, 19 Mar 2020 12:22:19 +0900 Subject: [PATCH 01/10] =?UTF-8?q?camera=5F0=E3=81=A7=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E3=81=95=E3=82=8C=E3=81=9F=E5=A0=B4=E5=90=88=E3=81=AF=E3=83=90?= =?UTF-8?q?=E3=83=83=E3=82=AF=E3=82=AB=E3=83=A1=E3=83=A9=E3=80=81camera=5F?= =?UTF-8?q?1=E3=81=AE=E5=A0=B4=E5=90=88=E3=81=AF=E3=83=95=E3=83=AD?= =?UTF-8?q?=E3=83=B3=E3=83=88=E3=82=AB=E3=83=A1=E3=83=A9=E3=81=A7=E9=85=8D?= =?UTF-8?q?=E4=BF=A1=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=81=97?= =?UTF-8?q?=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../profile/HostLiveStreamingProfile.java | 39 +++++-------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostLiveStreamingProfile.java b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostLiveStreamingProfile.java index 5fe813f34b..b67b3f9fa7 100644 --- a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostLiveStreamingProfile.java +++ b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostLiveStreamingProfile.java @@ -48,6 +48,8 @@ public class HostLiveStreamingProfile extends DConnectProfile implements LiveStr private static final String VIDEO_URI_FALSE = "false"; private static final String VIDEO_URI_CAMERA_FRONT = "camera-front"; private static final String VIDEO_URI_CAMERA_BACK = "camera-back"; + private static final String VIDEO_URI_CAMERA_0 = "camera_0"; + private static final String VIDEO_URI_CAMERA_1 = "camera_1"; private static final String AUDIO_URI_TRUE = "true"; private static final String AUDIO_URI_FALSE = "false"; private static final int CAMERA_TYPE_FRONT = 0; @@ -108,6 +110,8 @@ public boolean onRequest(final Intent request, final Intent response) { case VIDEO_URI_FALSE: case VIDEO_URI_CAMERA_FRONT: case VIDEO_URI_CAMERA_BACK: + case VIDEO_URI_CAMERA_0: + case VIDEO_URI_CAMERA_1: break; default: MessageUtils.setInvalidRequestParameterError(response, "video parameter illegal"); @@ -373,15 +377,17 @@ private HostDeviceLiveStreamRecorder getHostDeviceLiveStreamRecorder() { } break; } - case VIDEO_URI_CAMERA_FRONT: { - HostMediaRecorder hostMediaRecorder = getRecorder(CAMERA_TYPE_FRONT); + case VIDEO_URI_CAMERA_FRONT: + case VIDEO_URI_CAMERA_1: { + HostMediaRecorder hostMediaRecorder = mHostMediaRecorderManager.getRecorder(VIDEO_URI_CAMERA_1); if (hostMediaRecorder instanceof HostDeviceLiveStreamRecorder) { return (HostDeviceLiveStreamRecorder) hostMediaRecorder; } break; } - case VIDEO_URI_CAMERA_BACK: { - HostMediaRecorder hostMediaRecorder = getRecorder(CAMERA_TYPE_BACK); + case VIDEO_URI_CAMERA_BACK: + case VIDEO_URI_CAMERA_0: { + HostMediaRecorder hostMediaRecorder = mHostMediaRecorderManager.getRecorder(VIDEO_URI_CAMERA_0); if (hostMediaRecorder instanceof HostDeviceLiveStreamRecorder) { return (HostDeviceLiveStreamRecorder) hostMediaRecorder; } @@ -392,31 +398,6 @@ private HostDeviceLiveStreamRecorder getHostDeviceLiveStreamRecorder() { throw new RuntimeException("recorder not found"); } - - private HostMediaRecorder getRecorder(int type) { - if (DEBUG) { - Log.d(TAG, "getRecorder()"); - Log.d(TAG, "type" + type); - } - for(HostMediaRecorder hostMediaRecorder : mHostMediaRecorderManager.getRecorders()) { - if (DEBUG) { - Log.d(TAG, "name : " + hostMediaRecorder.getName()); - } - if (hostMediaRecorder.getName().matches("^Camera [0-9] \\((Front|Back)\\)")) { - if (type == CAMERA_TYPE_FRONT) { - if (hostMediaRecorder.getName().contains("Front")) { - return hostMediaRecorder; - } - } else if (type == CAMERA_TYPE_BACK) { - if (hostMediaRecorder.getName().contains("Back")) { - return hostMediaRecorder; - } - } - } - } - return null; - } - @Override public void onStart() { if (DEBUG) { From 7b4c8a1de2c2b5437bed393a890afa668f57042b Mon Sep 17 00:00:00 2001 From: Takayuki Hoshi Date: Thu, 19 Mar 2020 12:43:07 +0900 Subject: [PATCH 02/10] =?UTF-8?q?Front/Back=E3=82=AB=E3=83=A1=E3=83=A9?= =?UTF-8?q?=E3=82=92=E6=8E=92=E4=BB=96=E7=9A=84=E3=81=AB=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=81=97?= =?UTF-8?q?=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HostMediaStreamingRecordingProfile.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostMediaStreamingRecordingProfile.java b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostMediaStreamingRecordingProfile.java index 7bd32910c9..3bfb3f530b 100755 --- a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostMediaStreamingRecordingProfile.java +++ b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostMediaStreamingRecordingProfile.java @@ -60,6 +60,10 @@ public class HostMediaStreamingRecordingProfile extends MediaStreamRecordingProf */ private final FileManager mFileManager; + /** + * 現在起動中のレコーダーID. + */ + private static volatile String mCurrentRecorderId; /** * KeyEventProfileActivity からの KeyEvent を中継する Broadcast Receiver. */ @@ -431,6 +435,11 @@ public boolean onRequest(final Intent request, final Intent response) { MessageUtils.setInvalidRequestParameterError(response, "target is invalid."); return true; } + if (mCurrentRecorderId != null && !mCurrentRecorderId.equals(recorder.getId())) { + MessageUtils.setInvalidRequestParameterError(response, "Another target in using."); + return true; + } + mCurrentRecorderId = recorder.getId(); if (!(recorder instanceof HostDevicePhotoRecorder)) { MessageUtils.setNotSupportAttributeError(response, @@ -463,12 +472,14 @@ public void onTakePhoto(final String uri, final String filePath, final String mi intent.putExtra(MediaStreamRecordingProfile.PARAM_PHOTO, photo); sendEvent(intent, evt.getAccessToken()); } + mCurrentRecorderId = null; } @Override public void onFailedTakePhoto(final String errorMessage) { MessageUtils.setUnknownError(response, errorMessage); sendResponse(response); + mCurrentRecorderId = null; } }); } @@ -477,6 +488,7 @@ public void onFailedTakePhoto(final String errorMessage) { public void onDisallowed() { MessageUtils.setUnknownError(response, "Permission for camera is not granted."); sendResponse(response); + mCurrentRecorderId = null; } }); @@ -501,7 +513,11 @@ public boolean onRequest(final Intent request, final Intent response) { MessageUtils.setInvalidRequestParameterError(response, "target is invalid."); return true; } - + if (mCurrentRecorderId != null && !mCurrentRecorderId.equals(recorder.getId())) { + MessageUtils.setInvalidRequestParameterError(response, "Another target in using."); + return true; + } + mCurrentRecorderId = recorder.getId(); recorder.requestPermission(new HostMediaRecorder.PermissionCallback() { @Override public void onAllowed() { @@ -559,6 +575,7 @@ public boolean onRequest(final Intent request, final Intent response) { MessageUtils.setInvalidRequestParameterError(response, "target is invalid."); return true; } + mCurrentRecorderId = null; recorder.requestPermission(new HostMediaRecorder.PermissionCallback() { @Override @@ -678,6 +695,11 @@ public boolean onRequest(final Intent request, final Intent response) { MessageUtils.setInvalidRequestParameterError(response, "target is invalid."); return true; } + if (mCurrentRecorderId != null && !mCurrentRecorderId.equals(recorder.getId())) { + MessageUtils.setInvalidRequestParameterError(response, "Another target in using."); + return true; + } + mCurrentRecorderId = recorder.getId(); if (!(recorder instanceof HostDeviceStreamRecorder)) { MessageUtils.setNotSupportAttributeError(response, @@ -744,7 +766,7 @@ public boolean onRequest(final Intent request, final Intent response) { MessageUtils.setInvalidRequestParameterError(response, "target is invalid."); return true; } - + mCurrentRecorderId = null; if (!(recorder instanceof HostDeviceStreamRecorder)) { MessageUtils.setNotSupportAttributeError(response, "target does not support stream recording."); @@ -907,7 +929,7 @@ public void onDisallowed() { public HostMediaStreamingRecordingProfile(final HostMediaRecorderManager mgr, final FileManager fileMgr) { mRecorderMgr = mgr; mFileManager = fileMgr; - + mCurrentRecorderId = null; addApi(mGetMediaRecorderApi); addApi(mGetOptionsApi); addApi(mPutOptionsApi); From 13086f56d39ff9396e32a8afff1eb1b4664d7bbe Mon Sep 17 00:00:00 2001 From: Takayuki Hoshi Date: Tue, 24 Mar 2020 11:13:48 +0900 Subject: [PATCH 03/10] =?UTF-8?q?MediaStreamRecording=E3=82=84LiveStreamin?= =?UTF-8?q?g=E3=82=92=E4=BD=BF=E7=94=A8=E4=B8=AD=E3=81=A7=E3=82=82Light?= =?UTF-8?q?=E3=82=92=E4=BD=BF=E7=94=A8=E3=81=A7=E3=81=8D=E3=82=8B=E6=A7=98?= =?UTF-8?q?=E3=81=AB=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../host/profile/HostLightProfile.java | 30 ------------------- 1 file changed, 30 deletions(-) diff --git a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostLightProfile.java b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostLightProfile.java index 9548d07be4..762c59a7f7 100644 --- a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostLightProfile.java +++ b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostLightProfile.java @@ -89,12 +89,6 @@ public boolean onRequest(final Intent request, final Intent response) { new PermissionUtility.PermissionRequestCallback() { @Override public void onSuccess() { - if (!(isCameraAvailable())) { - MessageUtils.setIllegalDeviceStateError(response, "Camera device is already running."); - sendResponse(response); - return; - } - Bundle lightParam = new Bundle(); setName(lightParam, HOST_DEFAULT_LIGHT_NAME); setConfig(lightParam, ""); @@ -144,12 +138,6 @@ public boolean onRequest(final Intent request, final Intent response) { new PermissionUtility.PermissionRequestCallback() { @Override public void onSuccess() { - if (!(isCameraAvailable())) { - MessageUtils.setIllegalDeviceStateError(response, "Camera device is already running."); - sendResponse(response); - return; - } - if (flashing != null) { flashing(HOST_LIGHT_ID, flashing); setResult(response, DConnectMessage.RESULT_OK); @@ -213,12 +201,6 @@ public boolean onRequest(final Intent request, final Intent response) { new PermissionUtility.PermissionRequestCallback() { @Override public void onSuccess() { - if (!(isCameraAvailable())) { - MessageUtils.setIllegalDeviceStateError(response, "Camera device is already running."); - sendResponse(response); - return; - } - mPhotoRec.turnOffFlashLight(new HostDevicePhotoRecorder.TurnOffFlashLightListener() { @Override public void onRequested() { @@ -294,18 +276,6 @@ private Handler createHandler(final String name) { return new Handler(thread.getLooper()); } - /** - * カメラが使用可能どうかをチェックする. - * - * @return 使用可能の場合は true, そうでない場合は false. - */ - private boolean isCameraAvailable() { - if (((HostMediaRecorder) mPhotoRec).getState() != HostMediaRecorder.RecorderState.INACTTIVE) { - return false; - } - return true; - } - /** * 点滅制御. * From 699beba65be18aa2f95545171c57bdfa971c9e4c Mon Sep 17 00:00:00 2001 From: Takayuki Hoshi Date: Tue, 24 Mar 2020 11:16:18 +0900 Subject: [PATCH 04/10] =?UTF-8?q?Preview=E7=94=A8=E3=81=AENotification?= =?UTF-8?q?=E3=81=8C=E5=87=BA=E3=81=A6=E3=82=8B=E9=9A=9B=E3=80=81=E9=8C=B2?= =?UTF-8?q?=E7=94=BB=E3=81=AE=E6=9C=80=E4=B8=AD=E3=81=AFLiveStreaming?= =?UTF-8?q?=E3=82=92=E8=A1=8C=E3=82=8F=E3=81=AA=E3=81=84=E6=A7=98=E3=81=AB?= =?UTF-8?q?=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit その逆も同じ。 --- .../profile/HostLiveStreamingProfile.java | 21 ++++---- .../HostMediaStreamingRecordingProfile.java | 20 ++------ .../AbstractPreviewServerProvider.java | 9 ++++ .../host/recorder/HostMediaRecorder.java | 5 ++ .../recorder/HostMediaRecorderManager.java | 48 +++++++++++++++++++ .../host/recorder/PreviewServerProvider.java | 6 +++ .../host/recorder/camera/Camera2Recorder.java | 4 ++ 7 files changed, 88 insertions(+), 25 deletions(-) diff --git a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostLiveStreamingProfile.java b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostLiveStreamingProfile.java index b67b3f9fa7..6cd2ee9007 100644 --- a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostLiveStreamingProfile.java +++ b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostLiveStreamingProfile.java @@ -357,21 +357,19 @@ public boolean onRequest(final Intent request, final Intent response) { }); } - private HostDeviceLiveStreamRecorder getHostDeviceLiveStreamRecorder() { + private HostDeviceLiveStreamRecorder getHostDeviceLiveStreamRecorder() { if (DEBUG) { Log.d(TAG, "getHostDeviceLiveStreamRecorder()"); Log.d(TAG, "mVideoURI : " + mVideoURI); } switch (mVideoURI) { - case VIDEO_URI_TRUE: { - HostMediaRecorder hostMediaRecorder = mHostMediaRecorderManager.getRecorder(null); - if (hostMediaRecorder instanceof HostDeviceLiveStreamRecorder) { - return (HostDeviceLiveStreamRecorder) hostMediaRecorder; - } - break; - } + case VIDEO_URI_TRUE: case VIDEO_URI_FALSE: { HostMediaRecorder hostMediaRecorder = mHostMediaRecorderManager.getRecorder(null); + if (mHostMediaRecorderManager.usingStreamingRecorder()) { + throw new RuntimeException("Another target in using."); + } + if (hostMediaRecorder instanceof HostDeviceLiveStreamRecorder) { return (HostDeviceLiveStreamRecorder) hostMediaRecorder; } @@ -380,6 +378,9 @@ private HostDeviceLiveStreamRecorder getHostDeviceLiveStreamRecorder() { case VIDEO_URI_CAMERA_FRONT: case VIDEO_URI_CAMERA_1: { HostMediaRecorder hostMediaRecorder = mHostMediaRecorderManager.getRecorder(VIDEO_URI_CAMERA_1); + if (mHostMediaRecorderManager.usingStreamingRecorder()) { + throw new RuntimeException("Another target in using."); + } if (hostMediaRecorder instanceof HostDeviceLiveStreamRecorder) { return (HostDeviceLiveStreamRecorder) hostMediaRecorder; } @@ -388,6 +389,10 @@ private HostDeviceLiveStreamRecorder getHostDeviceLiveStreamRecorder() { case VIDEO_URI_CAMERA_BACK: case VIDEO_URI_CAMERA_0: { HostMediaRecorder hostMediaRecorder = mHostMediaRecorderManager.getRecorder(VIDEO_URI_CAMERA_0); + if (mHostMediaRecorderManager.usingPreviewOrStreamingRecorder(hostMediaRecorder.getId())) { + throw new RuntimeException("Another target in using."); + } + if (hostMediaRecorder instanceof HostDeviceLiveStreamRecorder) { return (HostDeviceLiveStreamRecorder) hostMediaRecorder; } diff --git a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostMediaStreamingRecordingProfile.java b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostMediaStreamingRecordingProfile.java index 3bfb3f530b..7ca19c111f 100755 --- a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostMediaStreamingRecordingProfile.java +++ b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostMediaStreamingRecordingProfile.java @@ -60,10 +60,6 @@ public class HostMediaStreamingRecordingProfile extends MediaStreamRecordingProf */ private final FileManager mFileManager; - /** - * 現在起動中のレコーダーID. - */ - private static volatile String mCurrentRecorderId; /** * KeyEventProfileActivity からの KeyEvent を中継する Broadcast Receiver. */ @@ -435,11 +431,10 @@ public boolean onRequest(final Intent request, final Intent response) { MessageUtils.setInvalidRequestParameterError(response, "target is invalid."); return true; } - if (mCurrentRecorderId != null && !mCurrentRecorderId.equals(recorder.getId())) { + if (mRecorderMgr.usingPreviewOrStreamingRecorder(recorder.getId())) { MessageUtils.setInvalidRequestParameterError(response, "Another target in using."); return true; } - mCurrentRecorderId = recorder.getId(); if (!(recorder instanceof HostDevicePhotoRecorder)) { MessageUtils.setNotSupportAttributeError(response, @@ -472,14 +467,12 @@ public void onTakePhoto(final String uri, final String filePath, final String mi intent.putExtra(MediaStreamRecordingProfile.PARAM_PHOTO, photo); sendEvent(intent, evt.getAccessToken()); } - mCurrentRecorderId = null; } @Override public void onFailedTakePhoto(final String errorMessage) { MessageUtils.setUnknownError(response, errorMessage); sendResponse(response); - mCurrentRecorderId = null; } }); } @@ -488,7 +481,6 @@ public void onFailedTakePhoto(final String errorMessage) { public void onDisallowed() { MessageUtils.setUnknownError(response, "Permission for camera is not granted."); sendResponse(response); - mCurrentRecorderId = null; } }); @@ -513,11 +505,10 @@ public boolean onRequest(final Intent request, final Intent response) { MessageUtils.setInvalidRequestParameterError(response, "target is invalid."); return true; } - if (mCurrentRecorderId != null && !mCurrentRecorderId.equals(recorder.getId())) { + if (mRecorderMgr.usingPreviewOrStreamingRecorder(recorder.getId())) { MessageUtils.setInvalidRequestParameterError(response, "Another target in using."); return true; } - mCurrentRecorderId = recorder.getId(); recorder.requestPermission(new HostMediaRecorder.PermissionCallback() { @Override public void onAllowed() { @@ -575,8 +566,6 @@ public boolean onRequest(final Intent request, final Intent response) { MessageUtils.setInvalidRequestParameterError(response, "target is invalid."); return true; } - mCurrentRecorderId = null; - recorder.requestPermission(new HostMediaRecorder.PermissionCallback() { @Override public void onAllowed() { @@ -695,11 +684,10 @@ public boolean onRequest(final Intent request, final Intent response) { MessageUtils.setInvalidRequestParameterError(response, "target is invalid."); return true; } - if (mCurrentRecorderId != null && !mCurrentRecorderId.equals(recorder.getId())) { + if (mRecorderMgr.usingPreviewOrStreamingRecorder(recorder.getId())) { MessageUtils.setInvalidRequestParameterError(response, "Another target in using."); return true; } - mCurrentRecorderId = recorder.getId(); if (!(recorder instanceof HostDeviceStreamRecorder)) { MessageUtils.setNotSupportAttributeError(response, @@ -766,7 +754,6 @@ public boolean onRequest(final Intent request, final Intent response) { MessageUtils.setInvalidRequestParameterError(response, "target is invalid."); return true; } - mCurrentRecorderId = null; if (!(recorder instanceof HostDeviceStreamRecorder)) { MessageUtils.setNotSupportAttributeError(response, "target does not support stream recording."); @@ -929,7 +916,6 @@ public void onDisallowed() { public HostMediaStreamingRecordingProfile(final HostMediaRecorderManager mgr, final FileManager fileMgr) { mRecorderMgr = mgr; mFileManager = fileMgr; - mCurrentRecorderId = null; addApi(mGetMediaRecorderApi); addApi(mGetOptionsApi); addApi(mPutOptionsApi); diff --git a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/AbstractPreviewServerProvider.java b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/AbstractPreviewServerProvider.java index 375fb9c23c..9bd6b8adf8 100644 --- a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/AbstractPreviewServerProvider.java +++ b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/AbstractPreviewServerProvider.java @@ -52,6 +52,7 @@ public abstract class AbstractPreviewServerProvider implements PreviewServerProv */ private HostMediaRecorder mRecorder; + private boolean mIsShownNotification; /** * コンストラクタ. * @param context コンテキスト @@ -60,6 +61,7 @@ public AbstractPreviewServerProvider(final Context context, final HostMediaRecor mContext = context; mRecorder = recorder; mNotificationId = notificationId; + mIsShownNotification = false; } // PreviewServerProvider @@ -118,6 +120,7 @@ public void onFail() { // TODO タイムアウト処理 } else { sendNotification(mRecorder.getId(), mRecorder.getName()); + mIsShownNotification = true; } } catch (InterruptedException e) { // ignore. @@ -171,6 +174,7 @@ private void hideNotification(String id) { .getSystemService(Service.NOTIFICATION_SERVICE); if (manager != null) { manager.cancel(id, getNotificationId()); + mIsShownNotification = false; } } @@ -252,4 +256,9 @@ private PendingIntent createPendingIntent(String id) { intent.putExtra(EXTRA_CAMERA_ID, id); return PendingIntent.getBroadcast(mContext, getNotificationId(), intent, 0); } + + @Override + public boolean isShownCameraNotification() { + return mIsShownNotification; + } } diff --git a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/HostMediaRecorder.java b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/HostMediaRecorder.java index a10d0cc460..1ce5ed7fdd 100644 --- a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/HostMediaRecorder.java +++ b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/HostMediaRecorder.java @@ -299,6 +299,11 @@ enum RecorderState { */ RECORDING, + /** + * プレビューが表示されている状態. + */ + PREVIEW, + /** * エラーで停止している状態. */ diff --git a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/HostMediaRecorderManager.java b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/HostMediaRecorderManager.java index 37fc9f78cd..682dd57cdc 100644 --- a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/HostMediaRecorderManager.java +++ b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/HostMediaRecorderManager.java @@ -12,8 +12,10 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; +import android.graphics.Camera; import android.os.Build; import android.os.Bundle; +import android.util.Log; import android.view.WindowManager; import org.deviceconnect.android.deviceplugin.host.camera.CameraWrapper; @@ -235,6 +237,52 @@ public HostMediaRecorder getRecorder(final String id) { return null; } + /** + * 指定された ID 以外のレコーダが. + * + *

+ * id に null が指定された場合には、デフォルトに設定されているレコーダを返却します。 + *

+ * + * @param id レコーダの識別子 + * @return 他のレコーダーが使用中であるかどうか true:使用中 false:使用されていない + */ + public boolean usingPreviewOrStreamingRecorder(String id) { + if (mRecorders.size() == 0) { + return false; + } + if (id == null) { + if (mDefaultPhotoRecorder != null) { + id = mDefaultPhotoRecorder.getId(); + } else { + id = mRecorders.get(0).getId(); + } + } + for (HostMediaRecorder recorder : mRecorders) { + if (!id.equals(recorder.getId()) + && (recorder.getState() == HostMediaRecorder.RecorderState.PREVIEW + || recorder.getState() == HostMediaRecorder.RecorderState.RECORDING)) { + return true; + } else if (recorder instanceof HostDeviceLiveStreamRecorder + && ((HostDeviceLiveStreamRecorder) recorder).isStreaming()) { + return true; + } + } + return false; + } + /** + * レコーダーが使用中である、あるいはストリーミングが開始している場合はtrueを返す. + * + * @return true:使用中 false:使用されていない + */ + public boolean usingStreamingRecorder() { + for (HostMediaRecorder recorder : mRecorders) { + return recorder.getState() == HostMediaRecorder.RecorderState.PREVIEW + || recorder.getState() == HostMediaRecorder.RecorderState.RECORDING + || ((HostDeviceLiveStreamRecorder) recorder).isStreaming(); + } + return false; + } /** * 指定された ID に対応する静止画用のレコーダを取得します. * diff --git a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/PreviewServerProvider.java b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/PreviewServerProvider.java index 3d2dc2d00d..d01be1e96d 100644 --- a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/PreviewServerProvider.java +++ b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/PreviewServerProvider.java @@ -73,4 +73,10 @@ public interface PreviewServerProvider { * 設定が変更されたことを通知します. */ void onConfigChange(); + + /** + * Previewの状態を表すNotificationが表示されているかどうかのフラグを返します. + * return true:表示されている false:表示されていない + */ + boolean isShownCameraNotification(); } diff --git a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/camera/Camera2Recorder.java b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/camera/Camera2Recorder.java index ca52d6afd8..f36d45fbba 100644 --- a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/camera/Camera2Recorder.java +++ b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/camera/Camera2Recorder.java @@ -252,6 +252,10 @@ public RecorderState getState() { if (mCameraWrapper.isRecording() || mCameraWrapper.isTakingStillImage()) { return RecorderState.RECORDING; } + // Preview用のNotificationが表示されている場合は、カメラをPreviewで占有しているものと判断する。 + if (mCamera2PreviewServerProvider.isShownCameraNotification()) { + return RecorderState.PREVIEW; + } return RecorderState.INACTTIVE; } From c0c7caabd56cda7acddc4cc79786effdede05e30 Mon Sep 17 00:00:00 2001 From: Takayuki Hoshi Date: Thu, 26 Mar 2020 10:14:33 +0900 Subject: [PATCH 05/10] =?UTF-8?q?INACTIVE=E3=81=AE=E3=82=B9=E3=83=9A?= =?UTF-8?q?=E3=83=AB=E3=83=9F=E3=82=B9=E3=82=92=E4=BF=AE=E6=AD=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../host/profile/HostMediaStreamingRecordingProfile.java | 4 ++-- .../deviceplugin/host/recorder/HostMediaRecorder.java | 2 +- .../host/recorder/HostMediaRecorderManager.java | 4 +--- .../host/recorder/audio/HostAudioRecorder.java | 6 +++--- .../host/recorder/camera/Camera2Recorder.java | 2 +- .../host/recorder/screen/ScreenCastRecorder.java | 8 ++++---- 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostMediaStreamingRecordingProfile.java b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostMediaStreamingRecordingProfile.java index 7ca19c111f..d99e5b91df 100755 --- a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostMediaStreamingRecordingProfile.java +++ b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostMediaStreamingRecordingProfile.java @@ -695,7 +695,7 @@ public boolean onRequest(final Intent request, final Intent response) { return true; } - if (recorder.getState() != HostMediaRecorder.RecorderState.INACTTIVE) { + if (recorder.getState() != HostMediaRecorder.RecorderState.INACTIVE) { MessageUtils.setIllegalDeviceStateError(response, recorder.getName() + " is already running."); return true; @@ -760,7 +760,7 @@ public boolean onRequest(final Intent request, final Intent response) { return true; } - if (recorder.getState() == HostMediaRecorder.RecorderState.INACTTIVE) { + if (recorder.getState() == HostMediaRecorder.RecorderState.INACTIVE) { MessageUtils.setIllegalDeviceStateError(response, "recorder is stopped already."); return true; } diff --git a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/HostMediaRecorder.java b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/HostMediaRecorder.java index 1ce5ed7fdd..7cd325a94c 100644 --- a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/HostMediaRecorder.java +++ b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/HostMediaRecorder.java @@ -287,7 +287,7 @@ enum RecorderState { /** * 動作していない. */ - INACTTIVE, + INACTIVE, /** * 録画が一時停止中の状態. diff --git a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/HostMediaRecorderManager.java b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/HostMediaRecorderManager.java index 682dd57cdc..68f9b6223c 100644 --- a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/HostMediaRecorderManager.java +++ b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/HostMediaRecorderManager.java @@ -12,10 +12,8 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; -import android.graphics.Camera; import android.os.Build; import android.os.Bundle; -import android.util.Log; import android.view.WindowManager; import org.deviceconnect.android.deviceplugin.host.camera.CameraWrapper; @@ -359,7 +357,7 @@ public void sendEventForRecordingChange(final String serviceId, final HostMediaR case RECORDING: MediaStreamRecordingProfile.setStatus(record, MediaStreamRecordingProfileConstants.RecordingState.RECORDING); break; - case INACTTIVE: + case INACTIVE: MediaStreamRecordingProfile.setStatus(record, MediaStreamRecordingProfileConstants.RecordingState.STOP); break; case ERROR: diff --git a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/audio/HostAudioRecorder.java b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/audio/HostAudioRecorder.java index d1237f12e6..17b48fca7c 100644 --- a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/audio/HostAudioRecorder.java +++ b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/audio/HostAudioRecorder.java @@ -88,7 +88,7 @@ public class HostAudioRecorder implements HostMediaRecorder, HostDeviceStreamRec public HostAudioRecorder(final Context context) { mContext = context; - mState = RecorderState.INACTTIVE; + mState = RecorderState.INACTIVE; } @Override @@ -290,10 +290,10 @@ public synchronized void startRecording(final RecordingListener listener) { @Override public synchronized void stopRecording(final StoppingListener listener) { - if (getState() == RecorderState.INACTTIVE) { + if (getState() == RecorderState.INACTIVE) { listener.onFailed(this, "MediaRecorder is not running."); } else { - mState = RecorderState.INACTTIVE; + mState = RecorderState.INACTIVE; if (listener != null) { if (mMediaRecorder != null) { mMediaRecorder.stop(); diff --git a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/camera/Camera2Recorder.java b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/camera/Camera2Recorder.java index f36d45fbba..892118f833 100644 --- a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/camera/Camera2Recorder.java +++ b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/camera/Camera2Recorder.java @@ -256,7 +256,7 @@ public RecorderState getState() { if (mCamera2PreviewServerProvider.isShownCameraNotification()) { return RecorderState.PREVIEW; } - return RecorderState.INACTTIVE; + return RecorderState.INACTIVE; } @Override diff --git a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/screen/ScreenCastRecorder.java b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/screen/ScreenCastRecorder.java index cc28ee2885..7b286bd116 100644 --- a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/screen/ScreenCastRecorder.java +++ b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/recorder/screen/ScreenCastRecorder.java @@ -82,7 +82,7 @@ public class ScreenCastRecorder implements HostMediaRecorder, HostDevicePhotoRec private int mPreviewBitRate = 1024 * 1024; private double mMaxFps = DEFAULT_MAX_FPS; private int mIFrameInterval = 2; - private RecorderState mState = RecorderState.INACTTIVE; + private RecorderState mState = RecorderState.INACTIVE; private final MediaSharing mMediaSharing = MediaSharing.getInstance(); @@ -420,7 +420,7 @@ private void takePhotoInternal(final @NonNull OnPhotoEventListener listener) { Bitmap bitmap = screenshot.get(); if (bitmap == null) { - mState = RecorderState.INACTTIVE; + mState = RecorderState.INACTIVE; listener.onFailedTakePhoto("Failed to take screenshot."); return; } @@ -433,14 +433,14 @@ private void takePhotoInternal(final @NonNull OnPhotoEventListener listener) { mFileMgr.saveFile(filename, media, true, new FileManager.SaveFileCallback() { @Override public void onSuccess(@NonNull final String uri) { - mState = RecorderState.INACTTIVE; + mState = RecorderState.INACTIVE; registerPhoto(new File(mFileMgr.getBasePath(), filename)); listener.onTakePhoto(uri, null, MIME_TYPE_JPEG); } @Override public void onFail(@NonNull final Throwable throwable) { - mState = RecorderState.INACTTIVE; + mState = RecorderState.INACTIVE; listener.onFailedTakePhoto(throwable.getMessage()); } }); From 43a047fce366199db97db1c4af5f53946d61a803 Mon Sep 17 00:00:00 2001 From: Takayuki Hoshi Date: Thu, 26 Mar 2020 10:15:09 +0900 Subject: [PATCH 06/10] =?UTF-8?q?TakePhoto=E6=99=82=E3=81=AB=E3=82=BF?= =?UTF-8?q?=E3=82=A4=E3=83=9F=E3=83=B3=E3=82=B0=E3=81=AB=E3=82=88=E3=81=A3?= =?UTF-8?q?=E3=81=A6=E3=81=AF=E3=83=AC=E3=82=B9=E3=83=9D=E3=83=B3=E3=82=B9?= =?UTF-8?q?=E3=81=8C=E8=BF=94=E3=81=A3=E3=81=A6=E3=81=93=E3=81=AA=E3=81=8F?= =?UTF-8?q?=E3=82=8B=E4=BB=B6=E3=81=AE=E4=BF=AE=E6=AD=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../android/deviceplugin/host/camera/CameraWrapper.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/camera/CameraWrapper.java b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/camera/CameraWrapper.java index e847cd95af..e94e3046db 100644 --- a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/camera/CameraWrapper.java +++ b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/camera/CameraWrapper.java @@ -99,11 +99,11 @@ void notifyEvent(final CameraEvent event) { private CameraCaptureSession mCaptureSession; - private boolean mIsTakingStillImage; + private static volatile boolean mIsTakingStillImage; - private boolean mIsPreview; + private static volatile boolean mIsPreview; - private boolean mIsRecording; + private static volatile boolean mIsRecording; private Surface mStillImageSurface; From 525ce94969b95d59094772ce6a452cf55e98a7c3 Mon Sep 17 00:00:00 2001 From: Takayuki Hoshi Date: Thu, 26 Mar 2020 11:40:39 +0900 Subject: [PATCH 07/10] =?UTF-8?q?Recorder=E3=81=AE=E7=8A=B6=E6=85=8B?= =?UTF-8?q?=E3=81=8CPREVIEW=E3=81=A8INACTIVE=E7=8A=B6=E6=85=8B=E4=BB=A5?= =?UTF-8?q?=E5=A4=96=E3=81=AE=E3=81=A8=E3=81=8D=E3=81=AF=E3=82=A8=E3=83=A9?= =?UTF-8?q?=E3=83=BC=E3=82=92=E8=BF=94=E3=81=99=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../android/deviceplugin/host/camera/CameraWrapper.java | 6 +++--- .../host/profile/HostMediaStreamingRecordingProfile.java | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/camera/CameraWrapper.java b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/camera/CameraWrapper.java index e94e3046db..e847cd95af 100644 --- a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/camera/CameraWrapper.java +++ b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/camera/CameraWrapper.java @@ -99,11 +99,11 @@ void notifyEvent(final CameraEvent event) { private CameraCaptureSession mCaptureSession; - private static volatile boolean mIsTakingStillImage; + private boolean mIsTakingStillImage; - private static volatile boolean mIsPreview; + private boolean mIsPreview; - private static volatile boolean mIsRecording; + private boolean mIsRecording; private Surface mStillImageSurface; diff --git a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostMediaStreamingRecordingProfile.java b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostMediaStreamingRecordingProfile.java index d99e5b91df..d795bc0ebe 100755 --- a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostMediaStreamingRecordingProfile.java +++ b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostMediaStreamingRecordingProfile.java @@ -218,7 +218,8 @@ private void setOptions(final Intent request, final Intent response) { return; } - if (recorder.getState() != HostMediaRecorder.RecorderState.INACTTIVE) { + if (recorder.getState() != HostMediaRecorder.RecorderState.INACTIVE + && recorder.getState() != HostMediaRecorder.RecorderState.PREVIEW) { MessageUtils.setInvalidRequestParameterError(response, "settings of active target cannot be changed."); return; } From 4848ab08438436e5b98a2ec9b15cdf99ca933ba0 Mon Sep 17 00:00:00 2001 From: Takayuki Hoshi Date: Thu, 26 Mar 2020 15:24:27 +0900 Subject: [PATCH 08/10] =?UTF-8?q?LightOFF=E6=99=82=E3=81=AB=E3=82=AB?= =?UTF-8?q?=E3=83=A1=E3=83=A9=E3=81=AE=E3=82=AA=E3=83=96=E3=82=B8=E3=82=A7?= =?UTF-8?q?=E3=82=AF=E3=83=88=E3=82=92=E4=B8=80=E5=BA=A6=E7=A0=B4=E6=A3=84?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../android/deviceplugin/host/camera/CameraWrapper.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/camera/CameraWrapper.java b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/camera/CameraWrapper.java index e847cd95af..a71d1b4026 100644 --- a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/camera/CameraWrapper.java +++ b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/camera/CameraWrapper.java @@ -848,6 +848,8 @@ public synchronized void turnOffTorch(final @Nullable TorchOffListener listener, throw new IllegalArgumentException(e); } catch (CameraWrapperException e) { throw new IllegalArgumentException(e); + } finally { + close(); } notifyTorchOffEvent(listener, handler); } From 1584c91a06f83292f42ecb8faa47ce1cc8324924 Mon Sep 17 00:00:00 2001 From: Takayuki Hoshi Date: Thu, 26 Mar 2020 16:19:31 +0900 Subject: [PATCH 09/10] =?UTF-8?q?record/preview=E4=B8=AD=E3=81=ABlight?= =?UTF-8?q?=E3=81=8C=E6=93=8D=E4=BD=9C=E3=81=95=E3=82=8C=E3=81=9F=E5=A0=B4?= =?UTF-8?q?=E5=90=88=E3=81=A7=E3=82=82=E5=87=A6=E7=90=86=E3=82=92=E5=81=9C?= =?UTF-8?q?=E6=AD=A2=E3=81=97=E3=81=AA=E3=81=84=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../deviceplugin/host/camera/CameraWrapper.java | 14 ++++++++++++-- .../HostMediaStreamingRecordingProfile.java | 3 ++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/camera/CameraWrapper.java b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/camera/CameraWrapper.java index a71d1b4026..5cc00d6127 100644 --- a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/camera/CameraWrapper.java +++ b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/camera/CameraWrapper.java @@ -551,6 +551,9 @@ public synchronized void stopRecording() throws CameraWrapperException { close(); if (mIsPreview) { startPreview(mPreviewSurface, true); + } else if (mIsTouchOn) { + mIsTouchOn = false; + turnOnTorch(); } notifyCameraEvent(CameraEvent.STOPPED_VIDEO_RECORDING); } @@ -623,17 +626,21 @@ public void onCaptureBufferLost(@NonNull CameraCaptureSession session, @NonNull } resumeRepeatingRequest(); throw new CameraWrapperException(e); + } finally { + mIsTakingStillImage = false; } } private void resumeRepeatingRequest() { - mIsTakingStillImage = false; try { if (mIsRecording) { startRecording(mRecordingSurface, true); } else if (mIsPreview) { startPreview(mPreviewSurface, true); + } else if (mIsTouchOn) { + mIsTouchOn = false; + turnOnTorch(); } else { close(); } @@ -794,6 +801,9 @@ public synchronized void turnOnTorch(final @Nullable TorchOnListener listener, if (mTargetSurface != null) { requestBuilder.addTarget(mTargetSurface); } + } + if (mIsRecording) { + requestBuilder.addTarget(mRecordingSurface); } else { requestBuilder.addTarget(mDummyPreviewReader.getSurface()); } @@ -849,7 +859,7 @@ public synchronized void turnOffTorch(final @Nullable TorchOffListener listener, } catch (CameraWrapperException e) { throw new IllegalArgumentException(e); } finally { - close(); + resumeRepeatingRequest(); } notifyTorchOffEvent(listener, handler); } diff --git a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostMediaStreamingRecordingProfile.java b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostMediaStreamingRecordingProfile.java index d795bc0ebe..2f97ac3cbe 100755 --- a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostMediaStreamingRecordingProfile.java +++ b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostMediaStreamingRecordingProfile.java @@ -696,7 +696,8 @@ public boolean onRequest(final Intent request, final Intent response) { return true; } - if (recorder.getState() != HostMediaRecorder.RecorderState.INACTIVE) { + if (recorder.getState() != HostMediaRecorder.RecorderState.INACTIVE + && recorder.getState() != HostMediaRecorder.RecorderState.PREVIEW) { MessageUtils.setIllegalDeviceStateError(response, recorder.getName() + " is already running."); return true; From 70412c38d5bcc1d31190974065fec03989dde59c Mon Sep 17 00:00:00 2001 From: Takayuki Hoshi Date: Thu, 26 Mar 2020 17:40:48 +0900 Subject: [PATCH 10/10] =?UTF-8?q?preview/record=E7=94=A8=E3=81=AESurface?= =?UTF-8?q?=E3=81=8C=E8=A8=AD=E5=AE=9A=E3=81=95=E3=82=8C=E3=81=A6=E3=81=84?= =?UTF-8?q?=E3=82=8B=E5=A0=B4=E5=90=88=E3=81=AF=E3=80=81Dummy=E3=81=AESurf?= =?UTF-8?q?ace=E3=82=92=E8=A8=AD=E5=AE=9A=E3=81=97=E3=81=AA=E3=81=84?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../android/deviceplugin/host/camera/CameraWrapper.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/camera/CameraWrapper.java b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/camera/CameraWrapper.java index 5cc00d6127..73a5b7e9ae 100644 --- a/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/camera/CameraWrapper.java +++ b/dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/camera/CameraWrapper.java @@ -804,7 +804,9 @@ public synchronized void turnOnTorch(final @Nullable TorchOnListener listener, } if (mIsRecording) { requestBuilder.addTarget(mRecordingSurface); - } else { + } + + if (!mIsPreview && !mIsRecording) { requestBuilder.addTarget(mDummyPreviewReader.getSurface()); } requestBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_TORCH);