|
10 | 10 | import android.content.Context; |
11 | 11 | import android.graphics.Bitmap; |
12 | 12 | import android.graphics.PixelFormat; |
| 13 | +import android.media.AudioFormat; |
13 | 14 | import android.media.ImageReader; |
14 | 15 | import android.net.Uri; |
15 | 16 | import android.os.Build; |
|
19 | 20 | import android.util.Log; |
20 | 21 |
|
21 | 22 | import org.deviceconnect.android.deviceplugin.host.BuildConfig; |
| 23 | +import org.deviceconnect.android.deviceplugin.host.recorder.HostDeviceLiveStreamRecorder; |
22 | 24 | import org.deviceconnect.android.deviceplugin.host.recorder.HostDevicePhotoRecorder; |
23 | 25 | import org.deviceconnect.android.deviceplugin.host.recorder.HostDeviceStreamRecorder; |
24 | 26 | import org.deviceconnect.android.deviceplugin.host.recorder.HostMediaRecorder; |
25 | 27 | import org.deviceconnect.android.deviceplugin.host.recorder.PreviewServer; |
26 | 28 | import org.deviceconnect.android.deviceplugin.host.recorder.PreviewServerProvider; |
| 29 | +import org.deviceconnect.android.deviceplugin.host.recorder.camera.CameraVideoEncoder; |
| 30 | +import org.deviceconnect.android.deviceplugin.host.recorder.util.LiveStreamingClient; |
27 | 31 | import org.deviceconnect.android.deviceplugin.host.recorder.util.MediaSharing; |
28 | 32 | import org.deviceconnect.android.deviceplugin.host.recorder.util.RecorderSetting; |
| 33 | +import org.deviceconnect.android.libmedia.streaming.audio.AudioEncoder; |
| 34 | +import org.deviceconnect.android.libmedia.streaming.audio.AudioQuality; |
| 35 | +import org.deviceconnect.android.libmedia.streaming.audio.MicAACLATMEncoder; |
29 | 36 | import org.deviceconnect.android.provider.FileManager; |
30 | 37 |
|
31 | 38 | import java.io.ByteArrayOutputStream; |
|
49 | 56 | * @author NTT DOCOMO, INC. |
50 | 57 | */ |
51 | 58 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
52 | | -public class ScreenCastRecorder implements HostMediaRecorder, HostDevicePhotoRecorder, HostDeviceStreamRecorder { |
| 59 | +public class ScreenCastRecorder implements HostMediaRecorder, HostDevicePhotoRecorder, HostDeviceStreamRecorder, HostDeviceLiveStreamRecorder { |
53 | 60 |
|
54 | 61 | private static final boolean DEBUG = BuildConfig.DEBUG; |
55 | 62 |
|
@@ -88,6 +95,7 @@ public class ScreenCastRecorder implements HostMediaRecorder, HostDevicePhotoRec |
88 | 95 |
|
89 | 96 | private ScreenCastPreviewServerProvider mScreenCastPreviewServerProvider; |
90 | 97 | private Context mContext; |
| 98 | + private LiveStreamingClient mLiveStreamingClient; |
91 | 99 |
|
92 | 100 | public ScreenCastRecorder(final Context context, |
93 | 101 | final FileManager fileMgr) { |
@@ -465,4 +473,153 @@ private void registerPhoto(final File photoFile) { |
465 | 473 | } |
466 | 474 | } |
467 | 475 | } |
| 476 | + |
| 477 | + @Override |
| 478 | + public void createLiveStreamingClient(String broadcastURI, LiveStreamingClient.EventListener eventListener) { |
| 479 | + mLiveStreamingClient = new LiveStreamingClient(broadcastURI, eventListener); |
| 480 | + } |
| 481 | + |
| 482 | + @Override |
| 483 | + public void setVideoEncoder(Integer width, Integer height, Integer bitrate, Integer frameRate) { |
| 484 | + if (DEBUG) { |
| 485 | + Log.d(TAG, "setVideoEncoder()"); |
| 486 | + Log.d(TAG, "width : " + width); |
| 487 | + Log.d(TAG, "height : " + height); |
| 488 | + Log.d(TAG, "bitrate : " + bitrate); |
| 489 | + Log.d(TAG, "framerate : " + frameRate); |
| 490 | + Log.d(TAG, "mLiveStreamingClient : " + mLiveStreamingClient); |
| 491 | + } |
| 492 | + if (mLiveStreamingClient != null) { |
| 493 | + ScreenCastVideoEncoder encoder = new ScreenCastVideoEncoder(mScreenCastMgr); |
| 494 | + // widthかheightがnullの場合は、PreviewSizeの最小値を設定する |
| 495 | + if (width == null || height == null) { |
| 496 | + PictureSize pSize = mSupportedPreviewSizes.get(0); |
| 497 | + width = pSize.getWidth(); |
| 498 | + height = pSize.getHeight(); |
| 499 | + for (int i = 1; i < mSupportedPreviewSizes.size(); i++) { |
| 500 | + if (pSize.getWidth() < mSupportedPreviewSizes.get(i).getWidth()) { |
| 501 | + width = mSupportedPreviewSizes.get(i).getWidth(); |
| 502 | + height = mSupportedPreviewSizes.get(i).getHeight(); |
| 503 | + } |
| 504 | + } |
| 505 | + } |
| 506 | + mLiveStreamingClient.setVideoEncoder(encoder, width, height, bitrate, frameRate); |
| 507 | + } |
| 508 | + } |
| 509 | + |
| 510 | + @Override |
| 511 | + public void setAudioEncoder() { |
| 512 | + if (DEBUG) { |
| 513 | + Log.d(TAG, "setAudioEncoder()"); |
| 514 | + Log.d(TAG, "mLiveStreamingClient : " + mLiveStreamingClient); |
| 515 | + } |
| 516 | + if (mLiveStreamingClient != null) { |
| 517 | + AudioEncoder audioEncoder = new MicAACLATMEncoder(); |
| 518 | + AudioQuality audioQuality = audioEncoder.getAudioQuality(); |
| 519 | + audioQuality.setChannel(AudioFormat.CHANNEL_IN_MONO); |
| 520 | + audioQuality.setSamplingRate(44100); |
| 521 | + mLiveStreamingClient.setAudioEncoder(audioEncoder); |
| 522 | + } |
| 523 | + } |
| 524 | + |
| 525 | + @Override |
| 526 | + public void startLiveStreaming() { |
| 527 | + if (DEBUG) { |
| 528 | + Log.d(TAG, "liveStreamingStart()"); |
| 529 | + Log.d(TAG, "mLiveStreamingClient : " + mLiveStreamingClient); |
| 530 | + } |
| 531 | + if (mLiveStreamingClient != null) { |
| 532 | + mLiveStreamingClient.start(); |
| 533 | + } |
| 534 | + } |
| 535 | + |
| 536 | + @Override |
| 537 | + public void stopLiveStreaming() { |
| 538 | + if (DEBUG) { |
| 539 | + Log.d(TAG, "liveStreamingStop()"); |
| 540 | + Log.d(TAG, "mLiveStreamingClient : " + mLiveStreamingClient); |
| 541 | + } |
| 542 | + if (mLiveStreamingClient != null) { |
| 543 | + mLiveStreamingClient.stop(); |
| 544 | + } |
| 545 | + } |
| 546 | + |
| 547 | + @Override |
| 548 | + public boolean isStreaming() { |
| 549 | + if (mLiveStreamingClient != null) { |
| 550 | + return mLiveStreamingClient.isStreaming(); |
| 551 | + } |
| 552 | + return false; |
| 553 | + } |
| 554 | + |
| 555 | + @Override |
| 556 | + public void setMute(boolean mute) { |
| 557 | + if (mLiveStreamingClient != null) { |
| 558 | + mLiveStreamingClient.setMute(mute); |
| 559 | + } |
| 560 | + } |
| 561 | + |
| 562 | + @Override |
| 563 | + public boolean isMute() { |
| 564 | + if (mLiveStreamingClient != null) { |
| 565 | + return mLiveStreamingClient.isMute(); |
| 566 | + } |
| 567 | + return false; |
| 568 | + } |
| 569 | + |
| 570 | + @Override |
| 571 | + public boolean isError() { |
| 572 | + if (mLiveStreamingClient != null) { |
| 573 | + return mLiveStreamingClient.isError(); |
| 574 | + } |
| 575 | + return false; |
| 576 | + } |
| 577 | + |
| 578 | + @Override |
| 579 | + public int getVideoWidth() { |
| 580 | + if (mLiveStreamingClient != null) { |
| 581 | + return mLiveStreamingClient.getVideoWidth(); |
| 582 | + } |
| 583 | + return 0; |
| 584 | + } |
| 585 | + |
| 586 | + @Override |
| 587 | + public int getVideoHeight() { |
| 588 | + if (mLiveStreamingClient != null) { |
| 589 | + return mLiveStreamingClient.getVideoHeight(); |
| 590 | + } |
| 591 | + return 0; |
| 592 | + } |
| 593 | + |
| 594 | + @Override |
| 595 | + public int getBitrate() { |
| 596 | + if (mLiveStreamingClient != null) { |
| 597 | + return mLiveStreamingClient.getBitrate(); |
| 598 | + } |
| 599 | + return 0; |
| 600 | + } |
| 601 | + |
| 602 | + @Override |
| 603 | + public int getFrameRate() { |
| 604 | + if (mLiveStreamingClient != null) { |
| 605 | + return mLiveStreamingClient.getFrameRate(); |
| 606 | + } |
| 607 | + return 0; |
| 608 | + } |
| 609 | + |
| 610 | + @Override |
| 611 | + public String getLiveStreamingMimeType() { |
| 612 | + if (mLiveStreamingClient != null) { |
| 613 | + return mLiveStreamingClient.getMimeType(); |
| 614 | + } |
| 615 | + return MIME_TYPE_JPEG; |
| 616 | + } |
| 617 | + |
| 618 | + @Override |
| 619 | + public String getBroadcastURI() { |
| 620 | + if (mLiveStreamingClient != null) { |
| 621 | + return mLiveStreamingClient.getBroadcastURI(); |
| 622 | + } |
| 623 | + return null; |
| 624 | + } |
468 | 625 | } |
0 commit comments