Skip to content

Commit 5885a93

Browse files
Merge branch 'modify_livestreaming_screen' into modify_livestreaming_check_parameter
# Conflicts: # dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostLiveStreamingProfile.java
2 parents 43412f8 + 7897a9d commit 5885a93

14 files changed

Lines changed: 337 additions & 98 deletions

File tree

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,9 @@ public synchronized void stopRecording() throws CameraWrapperException {
551551
close();
552552
if (mIsPreview) {
553553
startPreview(mPreviewSurface, true);
554+
} else if (mIsTouchOn) {
555+
mIsTouchOn = false;
556+
turnOnTorch();
554557
}
555558
notifyCameraEvent(CameraEvent.STOPPED_VIDEO_RECORDING);
556559
}
@@ -623,17 +626,21 @@ public void onCaptureBufferLost(@NonNull CameraCaptureSession session, @NonNull
623626
}
624627
resumeRepeatingRequest();
625628
throw new CameraWrapperException(e);
629+
} finally {
630+
mIsTakingStillImage = false;
626631
}
627632
}
628633

629634
private void resumeRepeatingRequest() {
630-
mIsTakingStillImage = false;
631635

632636
try {
633637
if (mIsRecording) {
634638
startRecording(mRecordingSurface, true);
635639
} else if (mIsPreview) {
636640
startPreview(mPreviewSurface, true);
641+
} else if (mIsTouchOn) {
642+
mIsTouchOn = false;
643+
turnOnTorch();
637644
} else {
638645
close();
639646
}
@@ -794,7 +801,12 @@ public synchronized void turnOnTorch(final @Nullable TorchOnListener listener,
794801
if (mTargetSurface != null) {
795802
requestBuilder.addTarget(mTargetSurface);
796803
}
797-
} else {
804+
}
805+
if (mIsRecording) {
806+
requestBuilder.addTarget(mRecordingSurface);
807+
}
808+
809+
if (!mIsPreview && !mIsRecording) {
798810
requestBuilder.addTarget(mDummyPreviewReader.getSurface());
799811
}
800812
requestBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_TORCH);
@@ -848,6 +860,8 @@ public synchronized void turnOffTorch(final @Nullable TorchOffListener listener,
848860
throw new IllegalArgumentException(e);
849861
} catch (CameraWrapperException e) {
850862
throw new IllegalArgumentException(e);
863+
} finally {
864+
resumeRepeatingRequest();
851865
}
852866
notifyTorchOffEvent(listener, handler);
853867
}

dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostLightProfile.java

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,6 @@ public boolean onRequest(final Intent request, final Intent response) {
8989
new PermissionUtility.PermissionRequestCallback() {
9090
@Override
9191
public void onSuccess() {
92-
if (!(isCameraAvailable())) {
93-
MessageUtils.setIllegalDeviceStateError(response, "Camera device is already running.");
94-
sendResponse(response);
95-
return;
96-
}
97-
9892
Bundle lightParam = new Bundle();
9993
setName(lightParam, HOST_DEFAULT_LIGHT_NAME);
10094
setConfig(lightParam, "");
@@ -144,12 +138,6 @@ public boolean onRequest(final Intent request, final Intent response) {
144138
new PermissionUtility.PermissionRequestCallback() {
145139
@Override
146140
public void onSuccess() {
147-
if (!(isCameraAvailable())) {
148-
MessageUtils.setIllegalDeviceStateError(response, "Camera device is already running.");
149-
sendResponse(response);
150-
return;
151-
}
152-
153141
if (flashing != null) {
154142
flashing(HOST_LIGHT_ID, flashing);
155143
setResult(response, DConnectMessage.RESULT_OK);
@@ -213,12 +201,6 @@ public boolean onRequest(final Intent request, final Intent response) {
213201
new PermissionUtility.PermissionRequestCallback() {
214202
@Override
215203
public void onSuccess() {
216-
if (!(isCameraAvailable())) {
217-
MessageUtils.setIllegalDeviceStateError(response, "Camera device is already running.");
218-
sendResponse(response);
219-
return;
220-
}
221-
222204
mPhotoRec.turnOffFlashLight(new HostDevicePhotoRecorder.TurnOffFlashLightListener() {
223205
@Override
224206
public void onRequested() {
@@ -294,18 +276,6 @@ private Handler createHandler(final String name) {
294276
return new Handler(thread.getLooper());
295277
}
296278

297-
/**
298-
* カメラが使用可能どうかをチェックする.
299-
*
300-
* @return 使用可能の場合は true, そうでない場合は false.
301-
*/
302-
private boolean isCameraAvailable() {
303-
if (((HostMediaRecorder) mPhotoRec).getState() != HostMediaRecorder.RecorderState.INACTTIVE) {
304-
return false;
305-
}
306-
return true;
307-
}
308-
309279
/**
310280
* 点滅制御.
311281
*

dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostLiveStreamingProfile.java

Lines changed: 71 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
import org.deviceconnect.android.deviceplugin.host.recorder.HostMediaRecorderManager;
1313
import org.deviceconnect.android.deviceplugin.host.recorder.camera.Camera2Recorder;
1414
import org.deviceconnect.android.deviceplugin.host.recorder.camera.CameraVideoEncoder;
15+
import org.deviceconnect.android.deviceplugin.host.recorder.screen.ScreenCastRecorder;
16+
import org.deviceconnect.android.deviceplugin.host.recorder.screen.ScreenCastVideoEncoder;
1517
import org.deviceconnect.android.event.Event;
1618
import org.deviceconnect.android.event.EventError;
1719
import org.deviceconnect.android.event.EventManager;
1820
import org.deviceconnect.android.libmedia.streaming.MediaEncoderException;
1921
import org.deviceconnect.android.deviceplugin.host.recorder.util.LiveStreamingClient;
2022
import org.deviceconnect.android.libmedia.streaming.video.CanvasVideoEncoder;
23+
import org.deviceconnect.android.libmedia.streaming.video.VideoEncoder;
2124
import org.deviceconnect.android.message.MessageUtils;
2225
import org.deviceconnect.android.profile.DConnectProfile;
2326
import org.deviceconnect.android.profile.api.DeleteApi;
@@ -48,6 +51,9 @@ public class HostLiveStreamingProfile extends DConnectProfile implements LiveStr
4851
private static final String VIDEO_URI_FALSE = "false";
4952
private static final String VIDEO_URI_CAMERA_FRONT = "camera-front";
5053
private static final String VIDEO_URI_CAMERA_BACK = "camera-back";
54+
private static final String VIDEO_URI_CAMERA_0 = "camera_0";
55+
private static final String VIDEO_URI_CAMERA_1 = "camera_1";
56+
private static final String VIDEO_URI_SCREEN = "screen";
5157
private static final String AUDIO_URI_TRUE = "true";
5258
private static final String AUDIO_URI_FALSE = "false";
5359
private static final int CAMERA_TYPE_FRONT = 0;
@@ -105,6 +111,7 @@ public boolean onRequest(final Intent request, final Intent response) {
105111
MessageUtils.setUnknownError(response, ex.getMessage());
106112
return true;
107113
}
114+
108115
((HostMediaRecorder) mHostDeviceLiveStreamRecorder).requestPermission(new HostMediaRecorder.PermissionCallback() {
109116
@Override
110117
public void onAllowed() {
@@ -123,9 +130,28 @@ public void onAllowed() {
123130
Log.d(TAG, "frameRate : " + frameRate);
124131
}
125132
if (!mVideoURI.equals("false")) {
126-
mHostDeviceLiveStreamRecorder.setVideoEncoder(
127-
new CameraVideoEncoder((Camera2Recorder) mHostDeviceLiveStreamRecorder),
128-
width, height, bitrate, frameRate);
133+
VideoEncoder encoder;
134+
if (mVideoURI.equals(VIDEO_URI_SCREEN)) {
135+
ScreenCastRecorder sRecorder = (ScreenCastRecorder) mHostDeviceLiveStreamRecorder;
136+
encoder = new ScreenCastVideoEncoder(sRecorder.getScreenCastMgr());
137+
// widthかheightがnullの場合は、PreviewSizeの最小値を設定する
138+
if (width == null || height == null) {
139+
HostMediaRecorder.PictureSize pSize = sRecorder.getSupportedPreviewSizes().get(0);
140+
width = pSize.getWidth();
141+
height = pSize.getHeight();
142+
for (int i = 1; i < sRecorder.getSupportedPreviewSizes().size(); i++) {
143+
if (pSize.getWidth() < sRecorder.getSupportedPreviewSizes().get(i).getWidth()) {
144+
width = sRecorder.getSupportedPreviewSizes().get(i).getWidth();
145+
height = sRecorder.getSupportedPreviewSizes().get(i).getHeight();
146+
}
147+
}
148+
}
149+
} else {
150+
encoder = new CameraVideoEncoder((Camera2Recorder) mHostDeviceLiveStreamRecorder);
151+
}
152+
153+
mHostDeviceLiveStreamRecorder.setVideoEncoder(encoder,
154+
width, height, bitrate, frameRate);
129155
} else {
130156
mHostDeviceLiveStreamRecorder.setVideoEncoder(new CanvasVideoEncoder() {
131157
@Override
@@ -376,37 +402,60 @@ public boolean onRequest(final Intent request, final Intent response) {
376402
});
377403
}
378404

379-
private HostDeviceLiveStreamRecorder getHostDeviceLiveStreamRecorder() {
405+
private HostDeviceLiveStreamRecorder getHostDeviceLiveStreamRecorder() {
380406
if (DEBUG) {
381407
Log.d(TAG, "getHostDeviceLiveStreamRecorder()");
382408
Log.d(TAG, "mVideoURI : " + mVideoURI);
383409
}
384410
switch (mVideoURI) {
385-
case VIDEO_URI_TRUE: {
411+
case VIDEO_URI_TRUE:
412+
case VIDEO_URI_FALSE: {
386413
HostMediaRecorder hostMediaRecorder = mHostMediaRecorderManager.getRecorder(null);
387-
if (hostMediaRecorder instanceof HostDeviceLiveStreamRecorder) {
388-
return (HostDeviceLiveStreamRecorder) hostMediaRecorder;
414+
if (hostMediaRecorder != null) {
415+
if (mHostMediaRecorderManager.usingStreamingRecorder()) {
416+
throw new RuntimeException("Another target in using.");
417+
}
418+
419+
if (hostMediaRecorder instanceof HostDeviceLiveStreamRecorder) {
420+
return (HostDeviceLiveStreamRecorder) hostMediaRecorder;
421+
}
389422
}
390423
break;
391424
}
392-
case VIDEO_URI_FALSE: {
393-
HostMediaRecorder hostMediaRecorder = mHostMediaRecorderManager.getRecorder(null);
394-
if (hostMediaRecorder instanceof HostDeviceLiveStreamRecorder) {
395-
return (HostDeviceLiveStreamRecorder) hostMediaRecorder;
425+
case VIDEO_URI_CAMERA_FRONT:
426+
case VIDEO_URI_CAMERA_1: {
427+
HostMediaRecorder hostMediaRecorder = mHostMediaRecorderManager.getRecorder(VIDEO_URI_CAMERA_1);
428+
if (hostMediaRecorder != null) {
429+
if (mHostMediaRecorderManager.usingStreamingRecorder()) {
430+
throw new RuntimeException("Another target in using.");
431+
}
432+
if (hostMediaRecorder instanceof HostDeviceLiveStreamRecorder) {
433+
return (HostDeviceLiveStreamRecorder) hostMediaRecorder;
434+
}
396435
}
397436
break;
398437
}
399-
case VIDEO_URI_CAMERA_FRONT: {
400-
HostMediaRecorder hostMediaRecorder = getRecorder(CAMERA_TYPE_FRONT);
401-
if (hostMediaRecorder instanceof HostDeviceLiveStreamRecorder) {
402-
return (HostDeviceLiveStreamRecorder) hostMediaRecorder;
438+
case VIDEO_URI_CAMERA_BACK:
439+
case VIDEO_URI_CAMERA_0: {
440+
HostMediaRecorder hostMediaRecorder = mHostMediaRecorderManager.getRecorder(VIDEO_URI_CAMERA_0);
441+
if (hostMediaRecorder != null) {
442+
if (mHostMediaRecorderManager.usingPreviewOrStreamingRecorder(hostMediaRecorder.getId())) {
443+
throw new RuntimeException("Another target in using.");
444+
}
445+
446+
if (hostMediaRecorder instanceof HostDeviceLiveStreamRecorder) {
447+
return (HostDeviceLiveStreamRecorder) hostMediaRecorder;
448+
}
403449
}
404450
break;
405451
}
406-
case VIDEO_URI_CAMERA_BACK: {
407-
HostMediaRecorder hostMediaRecorder = getRecorder(CAMERA_TYPE_BACK);
408-
if (hostMediaRecorder instanceof HostDeviceLiveStreamRecorder) {
409-
return (HostDeviceLiveStreamRecorder) hostMediaRecorder;
452+
case VIDEO_URI_SCREEN: {
453+
HostMediaRecorder hostMediaRecorder = mHostMediaRecorderManager.getRecorder(VIDEO_URI_SCREEN);
454+
if (hostMediaRecorder != null) {
455+
456+
if (hostMediaRecorder instanceof HostDeviceLiveStreamRecorder) {
457+
return (HostDeviceLiveStreamRecorder) hostMediaRecorder;
458+
}
410459
}
411460
break;
412461
}
@@ -415,30 +464,6 @@ private HostDeviceLiveStreamRecorder getHostDeviceLiveStreamRecorder() {
415464
throw new RuntimeException("recorder not found");
416465
}
417466

418-
419-
private HostMediaRecorder getRecorder(int type) {
420-
if (DEBUG) {
421-
Log.d(TAG, "getRecorder()");
422-
Log.d(TAG, "type" + type);
423-
}
424-
for(HostMediaRecorder hostMediaRecorder : mHostMediaRecorderManager.getRecorders()) {
425-
if (DEBUG) {
426-
Log.d(TAG, "name : " + hostMediaRecorder.getName());
427-
}
428-
if (hostMediaRecorder.getName().matches("^Camera [0-9] \\((Front|Back)\\)")) {
429-
if (type == CAMERA_TYPE_FRONT) {
430-
if (hostMediaRecorder.getName().contains("Front")) {
431-
return hostMediaRecorder;
432-
}
433-
} else if (type == CAMERA_TYPE_BACK) {
434-
if (hostMediaRecorder.getName().contains("Back")) {
435-
return hostMediaRecorder;
436-
}
437-
}
438-
}
439-
}
440-
return null;
441-
}
442467
private String checkRequestParameter(Bundle extras, Intent response) {
443468
//サーバURIの取得
444469
String broadcastURI = (String) extras.get(PARAM_KEY_BROADCAST);
@@ -460,6 +485,9 @@ private String checkRequestParameter(Bundle extras, Intent response) {
460485
case VIDEO_URI_FALSE:
461486
case VIDEO_URI_CAMERA_FRONT:
462487
case VIDEO_URI_CAMERA_BACK:
488+
case VIDEO_URI_CAMERA_0:
489+
case VIDEO_URI_CAMERA_1:
490+
case VIDEO_URI_SCREEN:
463491
break;
464492
default:
465493
MessageUtils.setInvalidRequestParameterError(response, "video parameter illegal");

dConnectDevicePlugin/dConnectDeviceHost/app/src/main/java/org/deviceconnect/android/deviceplugin/host/profile/HostMediaStreamingRecordingProfile.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ private void setOptions(final Intent request, final Intent response) {
218218
return;
219219
}
220220

221-
if (recorder.getState() != HostMediaRecorder.RecorderState.INACTTIVE) {
221+
if (recorder.getState() != HostMediaRecorder.RecorderState.INACTIVE
222+
&& recorder.getState() != HostMediaRecorder.RecorderState.PREVIEW) {
222223
MessageUtils.setInvalidRequestParameterError(response, "settings of active target cannot be changed.");
223224
return;
224225
}
@@ -431,6 +432,10 @@ public boolean onRequest(final Intent request, final Intent response) {
431432
MessageUtils.setInvalidRequestParameterError(response, "target is invalid.");
432433
return true;
433434
}
435+
if (mRecorderMgr.usingPreviewOrStreamingRecorder(recorder.getId())) {
436+
MessageUtils.setInvalidRequestParameterError(response, "Another target in using.");
437+
return true;
438+
}
434439

435440
if (!(recorder instanceof HostDevicePhotoRecorder)) {
436441
MessageUtils.setNotSupportAttributeError(response,
@@ -501,7 +506,10 @@ public boolean onRequest(final Intent request, final Intent response) {
501506
MessageUtils.setInvalidRequestParameterError(response, "target is invalid.");
502507
return true;
503508
}
504-
509+
if (mRecorderMgr.usingPreviewOrStreamingRecorder(recorder.getId())) {
510+
MessageUtils.setInvalidRequestParameterError(response, "Another target in using.");
511+
return true;
512+
}
505513
recorder.requestPermission(new HostMediaRecorder.PermissionCallback() {
506514
@Override
507515
public void onAllowed() {
@@ -559,7 +567,6 @@ public boolean onRequest(final Intent request, final Intent response) {
559567
MessageUtils.setInvalidRequestParameterError(response, "target is invalid.");
560568
return true;
561569
}
562-
563570
recorder.requestPermission(new HostMediaRecorder.PermissionCallback() {
564571
@Override
565572
public void onAllowed() {
@@ -678,14 +685,19 @@ public boolean onRequest(final Intent request, final Intent response) {
678685
MessageUtils.setInvalidRequestParameterError(response, "target is invalid.");
679686
return true;
680687
}
688+
if (mRecorderMgr.usingPreviewOrStreamingRecorder(recorder.getId())) {
689+
MessageUtils.setInvalidRequestParameterError(response, "Another target in using.");
690+
return true;
691+
}
681692

682693
if (!(recorder instanceof HostDeviceStreamRecorder)) {
683694
MessageUtils.setNotSupportAttributeError(response,
684695
"target does not support stream recording.");
685696
return true;
686697
}
687698

688-
if (recorder.getState() != HostMediaRecorder.RecorderState.INACTTIVE) {
699+
if (recorder.getState() != HostMediaRecorder.RecorderState.INACTIVE
700+
&& recorder.getState() != HostMediaRecorder.RecorderState.PREVIEW) {
689701
MessageUtils.setIllegalDeviceStateError(response,
690702
recorder.getName() + " is already running.");
691703
return true;
@@ -744,14 +756,13 @@ public boolean onRequest(final Intent request, final Intent response) {
744756
MessageUtils.setInvalidRequestParameterError(response, "target is invalid.");
745757
return true;
746758
}
747-
748759
if (!(recorder instanceof HostDeviceStreamRecorder)) {
749760
MessageUtils.setNotSupportAttributeError(response,
750761
"target does not support stream recording.");
751762
return true;
752763
}
753764

754-
if (recorder.getState() == HostMediaRecorder.RecorderState.INACTTIVE) {
765+
if (recorder.getState() == HostMediaRecorder.RecorderState.INACTIVE) {
755766
MessageUtils.setIllegalDeviceStateError(response, "recorder is stopped already.");
756767
return true;
757768
}
@@ -907,7 +918,6 @@ public void onDisallowed() {
907918
public HostMediaStreamingRecordingProfile(final HostMediaRecorderManager mgr, final FileManager fileMgr) {
908919
mRecorderMgr = mgr;
909920
mFileManager = fileMgr;
910-
911921
addApi(mGetMediaRecorderApi);
912922
addApi(mGetOptionsApi);
913923
addApi(mPutOptionsApi);

0 commit comments

Comments
 (0)