1212import org .deviceconnect .android .deviceplugin .host .recorder .HostMediaRecorderManager ;
1313import org .deviceconnect .android .deviceplugin .host .recorder .camera .Camera2Recorder ;
1414import 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 ;
1517import org .deviceconnect .android .event .Event ;
1618import org .deviceconnect .android .event .EventError ;
1719import org .deviceconnect .android .event .EventManager ;
1820import org .deviceconnect .android .libmedia .streaming .MediaEncoderException ;
1921import org .deviceconnect .android .deviceplugin .host .recorder .util .LiveStreamingClient ;
2022import org .deviceconnect .android .libmedia .streaming .video .CanvasVideoEncoder ;
23+ import org .deviceconnect .android .libmedia .streaming .video .VideoEncoder ;
2124import org .deviceconnect .android .message .MessageUtils ;
2225import org .deviceconnect .android .profile .DConnectProfile ;
2326import 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" );
0 commit comments