Java tutorial
package com.playrtc.sample.handler; import android.app.AlertDialog; import android.content.DialogInterface; import android.os.Environment; import android.util.Log; import com.playrtc.sample.PlayRTCActivity; import com.playrtc.sample.util.Utils; import com.playrtc.sample.view.PlayRTCVideoViewGroup; import com.sktelecom.playrtc.PlayRTC; import com.sktelecom.playrtc.PlayRTC.PlayRTCCode; import com.sktelecom.playrtc.PlayRTC.PlayRTCStatus; import com.sktelecom.playrtc.PlayRTC.PlayRTCWhiteBalance; import com.sktelecom.playrtc.PlayRTCFactory; import com.sktelecom.playrtc.config.PlayRTCAudioConfig; import com.sktelecom.playrtc.config.PlayRTCAudioConfig.AudioCodec; import com.sktelecom.playrtc.config.PlayRTCConfig; import com.sktelecom.playrtc.config.PlayRTCVideoConfig; import com.sktelecom.playrtc.config.PlayRTCVideoConfig.VideoCodec; import com.sktelecom.playrtc.exception.RequiredConfigMissingException; import com.sktelecom.playrtc.exception.RequiredParameterMissingException; import com.sktelecom.playrtc.exception.UnsupportedPlatformVersionException; import com.sktelecom.playrtc.observer.PlayRTCObserver; import com.sktelecom.playrtc.stream.PlayRTCData; import com.sktelecom.playrtc.stream.PlayRTCMedia; import com.sktelecom.playrtc.util.PlayRTCRange; import org.json.JSONObject; import java.io.File; /* * PlayRTC ? ?, PlayRTC ?? ? PlayRTCObserver ?? * PlayRTC-Handler Class * * * PlayRTC * 1. PlayRTCConfig ? * PlayRTCFactory.createConfig() * * 2. PlayRTC ? ? * PlayRTCConfig, PlayRTCObserver * PlayRTCFactory#newInstance(PlayRTCConfig config, PlayRTCObserver observer) * * 3. ?? ? PlayRTCVideoView * - xml layout? ? ? ? * PlayRTCVideoView ? ? ? ?? PlayRTCActivity#onWindowFocusChanged ? ? * PlayRTCVideoViewGroup#createVideoView() * - xml layout? * PlayRTCVideoView ? ? ? ?? PlayRTCActivity#onWindowFocusChanged ? ? * PlayRTCVideoViewGroup#initVideoView() * * * 4. ? ? ? ?/ -> PlayRTCChannelView ?? ? ? ? PlayRTCChannelViewListener * PlayRTCChannelViewListener#onClickCreateChannel * playRTC.createChannel(parameters) * PlayRTCChannelViewListener#onClickConnectChannel * playRTC.connectChannel(parameters) * * 5. ? ? ? ?/ PlayRTC Connect ? ? * PlayRTCObserver#onConnectChannel(PlayRTC obj, final String channelId, final String reason) * * 6. PlayRTCMedia ? * PlayRTCObserver#onAddLocalStream * PlayRTCMedia ?? ? ? PlayRTCVideoView? renderer ?? ? * PlayRTCMedia#setVideoRenderer(PlayRTCVideoView?#getVideoRenderer()); * * 7. P2P ? PlayRTCMedia ? * PlayRTCObserver#onAddRemoteStream * PlayRTCMedia ?? ? ? PlayRTCVideoView? renderer ?? ? * PlayRTCMedia#setVideoRenderer(PlayRTCVideoView?#getVideoRenderer()); * * 8. Data ? PlayRTCData ? -> ?? ? * PlayRTCObserver#onAddDataStream * PlayRTCData ? ? PlayRTCDataObserver PlayRTCDataChannelHandler ? * PlayRTCDataChannelHandler#setDataChannel(data); * * 9. ? ? ? * ? PlayRTC#disconnectChannel? ?? onOtherDisconnectChannel ?. * ?? onDisconnectChannel * PlayRTCObserver#onOtherDisconnectChannel * * * 10. ? ? * PlayRTC#deleteChannel? ?? ?? ? ? * PlayRTCObserver#onDisconnectChannel * * 11. * Back ? ? PlayRTC#deleteChannel ? PlayRTC#disconnectChannel? * PlayRTCObserver#onDisconnectChannel? * * * * * - PlayRTC playrtc * PlayRTC ? * * - PlayRTCMedia localMedia * (?) ? ?? ? * * - PlayRTCMedia remoteMedia * ?(Remote) ? ?? ? * * - PlayRTCStatsReportHandler statReportHandler * P2P PlayRTC? P2P ? Report ? * PlayRTCObserver#onStateChange? ? ? PlayRTCStatus.PeerSuccess ? ? . * * - PlayRTCLogView logView * PlayRTC TextView Class * * Method * - public void createPlayRTC(); * SDK ?? PlayRTCConfig ? PlayRTC ? ?. * * - void createChannel(JSONObject parameters); * PlayRTC ? PlayRTC ? ? P2P ? ?? ?? ?? . * P2P ?? ?? ?? connectChannel ? . * ?? ?? ?? ? ? . * * - void connectChannel(String channelId, JSONObject parameters); * ? ? ? P2P ?? P2P ? . * * - PlayRTC getPlayRTC(); * PlayRTC ? . * * - void onActivityPause(); * Activity onPause ? onStop PlayRTC? ? Pause . * * - void onActivityResume(); * Activity onResume ? onStart PlayRTC? ? Resume . * * - void close(); * P2P ? ? (P2P , Activity Destroy) . * * - void disconnectChannel(); * PlayRTC ? ?? . * ?? , ?? ? onOtherDisconnectChannel? ?. * * - void delateChannel(); * PlayRTC ? ?? . * ? ?? ? onDisconnectChannel? ?. * */ public class PlayRTCHandler extends PlayRTCObserver { private static final String LOG_TAG = "PLAYRTC"; /** * PlayRTC SDK Log ?. WARN */ private static final int CONSOLE_LOG = PlayRTCConfig.DEBUG; /** * PlayRTC SDK ? Log ?. WARN */ private static final int FILE_LOG = PlayRTCConfig.WARN; /** * PlayRTC ? ? ?? ?. * Sample ? ? ? . ? ? . */ private static final String TDCProjectId = "60ba608a-e228-4530-8711-fa38004719c1"; // playrtc /** * Activity ?. <br> * PlayRTCActivity ? ? ? ? ?? */ private PlayRTCActivity activity = null; /** * PlayRTC ? */ private PlayRTC playrtc = null; /** * PlayRTCMedia */ private PlayRTCMedia localMedia = null; /** * ? PlayRTCMedia */ private PlayRTCMedia remoteMedia = null; /** * P2P PlayRTC? P2P ? Report ? */ private PlayRTCStatsReportHandler statReportHandler = null; /** * ? ? ?? P2P ?? ? */ private String channelId = null; /** * ? ? P2P ? ? ?. */ private String userPid = null; /** * ? ? ?? P2P ? ? ?. */ private String peerId = null; /** * ? . * ? ? ? Acticity ? ? ? ? . * ? ? PlayRTC ? . */ private boolean isChannelConnected = false; public PlayRTCHandler(PlayRTCActivity activity) { this.activity = activity; // P2P PlayRTC? P2P ? Report ? ? statReportHandler = new PlayRTCStatsReportHandler(activity); } /** * SDK ?? PlayRTCConfig ? PlayRTC ? ?. * @param runType int * - 1. ??, ?, p2p data * - 2. ??, ? * - 3. ?, data * - 4. p2p data only * @throws UnsupportedPlatformVersionException Android SDK ? Exception * @throws RequiredParameterMissingException Parameter ? Exception */ public void createPlayRTC(int runType, String channelRing, String videoCodec, String audioCodec) throws UnsupportedPlatformVersionException, RequiredParameterMissingException { // PlayRTC ? ? PlayRTCConfig config = createPlayRTCConfig(runType, channelRing, videoCodec, audioCodec); /* * PlayRTC ?? ? ? ? PlayRTC . static * * @param settings PlayRTCSettings, PlayRTC ? * @param observer PlayRTCObserver, PlayRTC Event * @return PlayRTC */ playrtc = PlayRTCFactory.createPlayRTC(config, (PlayRTCObserver) this); } /** * PlayRTC ? PlayRTC ? ? P2P ? ?? ?? ?? .<br> * P2P ?? ?? ?? connectChannel ? . <br> * ?? ?? ? ? ? ?? ? ? PlayRTCObserver#onConnectChannel? . * @param parameters JSONObject, ? ? ? peer ?? ? , ?? ?? close ? ?. * - channel JSONObject, ?? * - channelName String, ?? ? * - peer JSONObject, peer(?)? * - userId String, User? ID application? ? ? * - userName String, User ? * @throws RequiredConfigMissingException Parameter ? Exception */ public void createChannel(JSONObject parameters) throws RequiredConfigMissingException { playrtc.createChannel(parameters); } /** * ? ? ?? P2P ?? P2P ? .<br> * ?? ? ? ? PlayRTCObserver#onConnectChannel? .<br> * @param channelId String, ? ? ?? ?? ? * @param parameters JSONObject, ? * - peer JSONObject, peer(?)? * - userId String, User? ID application? ? ? * - userName String, User ? (Option) * @throws RequiredConfigMissingException Parameter ? Exception */ public void connectChannel(String channelId, JSONObject parameters) throws RequiredConfigMissingException { playrtc.connectChannel(channelId, parameters); } /** * PlayRTC ? . * @return PlayRTC */ public PlayRTC getPlayRTC() { return playrtc; } /** * Activity onPause ? onStop PlayRTC? ? Pause . */ public void onActivityPause() { if (playrtc != null) { playrtc.pause(); } } /** * Activity onResume ? onStart PlayRTC? ? Resume . */ public void onActivityResume() { if (playrtc != null) { playrtc.resume(); } } /** * P2P ? ? (P2P , Activity Destroy) . */ public void close() { if (playrtc != null) { playrtc.close(); statReportHandler.stop(); } playrtc = null; localMedia = null; remoteMedia = null; statReportHandler = null; activity = null; } /** * ? ? ? ? .<br> * @return String */ public String getChannelId() { return channelId; } /** * PlayRTC ? ? ? ? ?.<br> * ? ?/ ? ? Application ? ?<br> * Peer-Id . Peer-Id PlayRTC ? ??. * @return String */ public String getUserPid() { return userPid; } /** * ? .<br> * ? ? ? Acticity ? ? ? ? .<br> * ? ? PlayRTC ? .<br> * * @return boolean */ public boolean isChannelConnected() { return isChannelConnected; } /** * / ? ? .<br> * ? ? ? . */ public void switchVideoCamera() { if (playrtc != null) { playrtc.switchVideoCamera(); } } /** * ? ? On/Off ? .<br> * ? , ? ? . */ public void switchBackCameraFlash() { if (playrtc != null) { boolean on = !playrtc.isBackCameraFlashOn(); playrtc.setBackCameraFlash(on); } } /** * PlayRTC ? ?? .<br> * ?? , ?? ? onOtherDisconnectChannel? ?.<br> * onOtherDisconnectChannel? ? ? ? ? ??,<br> * ? ?? P2P ? . */ public void disconnectChannel() { if (playrtc != null) { /* * ? ?? ? ? ?. */ playrtc.disconnectChannel(playrtc.getPeerId()); } } /** * PlayRTC ? ?? .<br> * ? ?? ? onDisconnectChannel? ?.<br> * onDisconnectChannel? ? PlayRTC ? ??? .<br> * P2P PlayRTC ? ? ? ? . */ public void delateChannel() { if (playrtc != null) { //?? ? onDisconnectChannel? // PlayRTC ? ??? playrtc.deleteChannel(); } } /** * ? ? Mute. - * ?? ? . <br> * @param on boolean */ public void setLocalAudioMute(boolean on) { if (localMedia != null) { localMedia.setAudioMute(on); } } /** * ?? ? ? Mute. - <br> * ?? . <br> * @param on boolean */ public void setRemoteAudioMute(boolean on) { if (remoteMedia != null) { remoteMedia.setAudioMute(on); } } /** * ?? ? Pause. - <br> * ?? ? ??? ? . <br> * @param on boolean */ public void setLocalVideoPause(boolean on) { if (localMedia != null) { localMedia.setVideoMute(on); } } /** * ? ?? ? Pause.<br> * ?? ??? ? . <br> * @param on boolean */ public void setRemoteVideoPause(boolean on) { if (remoteMedia != null) { remoteMedia.setVideoMute(on); } } /** * ? ?? . v2.2.9 <br> * ? : <br> * ? : <br> * @param rotation int 0, 90, 180, 270 */ public void setCameraRotation(int rotation) { if (playrtc != null) { playrtc.setCameraRotation(rotation); } } /** * ?? Zoom . <br> * v2.2.10 * @return PlayRTCRange<Integer> */ public PlayRTCRange<Integer> getCameraZoomRange() { if (playrtc != null) { return playrtc.getCameraZoomRange(); } return PlayRTCRange.create(0, 0); } /** * ?? Zoom level? .<br> * v2.2.10 * @return int */ public int getCurrentCameraZoom() { if (playrtc != null) { return playrtc.getCurrentCameraZoom(); } return 0; } /** * ?? Zoom level? .<br> * ? getCameraZoomRange()? min ~ max<br> * v2.2.10 * @return boolean */ public boolean setCameraZoom(int value) { if (playrtc != null) { PlayRTCRange<Integer> zoomRange = playrtc.getCameraZoomRange(); if (value >= zoomRange.getMinValue() && value <= zoomRange.getMaxValue()) { return playrtc.setCameraZoom(value); } } return false; } /** * ? ?? WhiteBalance .<br> * v2.3.0 * @return PlayRTCWhiteBalance * <pre> * - Auto * - Incandescent : * - FluoreScent : * - DayLight : , ? * - CloudyDayLight : ?? * - TwiLight : ? * - Shade : , ? * </pre> */ public PlayRTCWhiteBalance getCameraWhiteBalance() { if (playrtc != null) { return playrtc.getCameraWhiteBalance(); } return PlayRTCWhiteBalance.Auto; } /** * ? ? ? WhiteBalance ? .<br> * ? ? <br> * v2.2.10 * @param whiteBalance PlayRTCWhiteBalance * <pre> * - Auto * - Incandescent : * - FluoreScent : * - DayLight : , ? * - CloudyDayLight : ?? * - TwiLight : ? * - Shade : , ? * </pre> * @return boolean, ? * @see com.sktelecom.playrtc.PlayRTC.PlayRTCWhiteBalance */ public boolean isSupportedCameraWhiteBalance(PlayRTCWhiteBalance whiteBalance) { if (playrtc != null) { return playrtc.isSupportedCameraWhiteBalance(whiteBalance); } return false; } /** * ? ?? WhiteBalance .<br> * ?? ? WhiteBalance ? ? ?<br> * v2.2.10 * @param whiteBalance PlayRTCWhiteBalance * <pre> * - Auto * - Incandescent : * - FluoreScent : * - DayLight : , ? * - CloudyDayLight : ?? * - TwiLight : ? * - Shade : , ? * </pre> * @return boolean, */ public boolean setCameraWhiteBalance(PlayRTCWhiteBalance whiteBalance) { if (playrtc != null) { return playrtc.setCameraWhiteBalance(whiteBalance); } return false; } /** * ? ?? .<br> * v2.2.10 * maximim ? 0 ? ? . * @return PlayRTCRange<Integer> */ public PlayRTCRange<Integer> getCameraExposureCompensationRange() { if (playrtc != null) { return playrtc.getCameraExposureCompensationRange(); } return PlayRTCRange.create(0, 0); } /** * ? ?? . <br> * 0 ? ? ??<br> * v2.2.10 * @return int */ public int getCameraExposureCompensation() { if (playrtc != null) { return playrtc.getCameraExposureCompensation(); } return 0; } /** * ? ?? ? .<br> * maximim? 0? ? ? .<br> * ? ?? (getCameraExposureCompensationRange() ) ?<br> * v2.2.10 * @param value int * @return boolean, */ public boolean setCameraExposureCompensation(int value) { if (playrtc != null) { return playrtc.setCameraExposureCompensation(value); } return false; } /////////////////////////////////////////////////////////////////////////////////////////////////// // PlayRTCObserver Implements ////////////////////////////////////////////////////////////////////////////////////////////////// /* * ? ? ? ?/ ? . * @param obj PlayRTC * @param channelId String, ? ? ? * @param reason String, createChannel? "create", connectChannel? "connect" */ @Override public void onConnectChannel(final PlayRTC obj, final String channelId, final String reason, final String channelType) { if (reason.equals("create")) { // ? ? ? ? ? ? activity.getChannelInfoPopup().setChannelId(channelId); this.channelId = channelId; } isChannelConnected = true; // ? ? ? 0.8 activity.getChannelInfoPopup().hide(800); } /* * PlayRTCConfig Channel? ring = true ? ?? ? ? * ? ? . ring ? ?? ??. * @param obj PlayRTC * @param peerId String, ? ?? peer ? * @param peerUid String, ? ?? ? */ @Override public void onRing(final PlayRTC obj, final String peerId, final String peerUid) { activity.appnedLogMessage(">>[" + peerId + "] onRing...."); AlertDialog.Builder alert = new AlertDialog.Builder(activity); alert.setTitle("PlayRTC"); alert.setMessage(peerId + "? ? ."); alert.setPositiveButton("", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Utils.showToast(activity, "[" + peerId + "] accept...."); activity.appnedLogMessage(">>[" + peerId + "] accept...."); obj.accept(peerId); } }); alert.setNegativeButton("", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); Utils.showToast(activity, "[" + peerId + "] reject...."); activity.appnedLogMessage(">>[" + peerId + "] reject...."); obj.reject(peerId); } }); alert.show(); } /* * ? ? ? . * @param obj PlayRTC * @param peerId String, ? ?? peer ? * @param peerUid String, ? ?? ? */ @Override public void onReject(final PlayRTC obj, final String peerId, final String peerUid) { Utils.showToast(activity, "[" + peerId + "] onReject...."); activity.appnedLogMessage(">>[" + peerId + "] onReject...."); } /* * ? ? . * @param obj PlayRTC * @param peerId String, ? ?? peer ? * @param peerUid String, ? ?? ? */ @Override public void onAccept(final PlayRTC obj, final String peerId, final String peerUid) { Utils.showToast(activity, "[" + peerId + "] onAccept...."); activity.appnedLogMessage(">>[" + peerId + "] onAccept...."); } /* * ? User Defined Command(? ?) . * Application? ? JSON String ? Command ?? ? ? . * ? ?. * * @param obj PlayRTC * @param peerId String, ? ?? peer ? * @param peerUid String, ? ?? ? * @param data String, ?? ? */ @Override public void onUserCommand(final PlayRTC obj, final String peerId, final String peerUid, final String data) { Utils.showToast(activity, "[" + peerId + "] onCommand...."); activity.appnedLogMessage(">>[" + peerId + "] onCommand[" + data + "]"); } /* * PlayRTCMedia ? * PlayRTCMedia? * * @param obj PlayRTC * @param media PlayRTCMedia, PlayRTCVideo? PlayRTCVideoRenderer ? */ @Override public void onAddLocalStream(final PlayRTC obj, final PlayRTCMedia media) { Log.e(LOG_TAG, "onMedia onAddLocalStream=============="); // ?? ? . if (media.hasVideoStream() == false) { return; } localMedia = media; localMedia.setAudioMute(false); // ?? . if (activity.getLocalVideoView() == null) { return; } activity.appnedLogMessage(">> onLocalStream..."); //PlayRTCVideoRenderer ? localMedia.setVideoRenderer(activity.getLocalVideoView().getVideoRenderer()); activity.getLocalVideoView().show(400); } /* * P2P ? PlayRTCMedia ? * ? PlayRTCMedia? <br> * @param obj PlayRTC * @param peerId String, ? ?? peer ? * @param peerUid String, ? ?? ? * @param media PlayRTCMedia, PlayRTCVideo? PlayRTCVideoRenderer ? */ @Override public void onAddRemoteStream(final PlayRTC obj, final String peerId, final String peerUid, final PlayRTCMedia media) { Log.e(LOG_TAG, "onMedia onAddRemoteStream=============="); // ?? ? . if (media.hasVideoStream() == false) { return; } remoteMedia = media; remoteMedia.setAudioMute(false); // ?? . if (activity.getRemoteVideoView() == null) { return; } activity.appnedLogMessage(">> onRemoteStream[" + peerId + "]..."); // PlayRTCVideoRenderer ? remoteMedia.setVideoRenderer(activity.getRemoteVideoView().getVideoRenderer()); } /* * Data ? PlayRTCData ? -> ?? ? * Data-Channel? ?? , PlayRTCData(DataChannel) ? * @param obj PlayRTC * @param peerId String, ? ?? peer ? * @param peerUid String, ? ?? ? * @param data PlayRTCData */ @Override public void onAddDataStream(final PlayRTC obj, final String peerId, final String peerUid, final PlayRTCData data) { this.peerId = peerId; activity.appnedLogMessage(">> onDataStream[" + peerId + "]..."); // PlayRTCDataObserver ?. activity.getRtcDataHandler().setDataChannel(data); } /* * ?? ?, ?? * deleteChannel? , disconnectChannel? ?. * PlayRTC ? .( P2P ? ?) * @param obj PlayRTC * @param reason String, deleteChannel? "delete", disconnectChannel? "disconnect" */ @Override public void onDisconnectChannel(final PlayRTC obj, final String reason) { if (reason.equals("disconnect")) { Utils.showToast(activity, "?? ...."); activity.appnedLogMessage(">>PlayRTC ?? ...."); } else { Utils.showToast(activity, "?? ?...."); activity.appnedLogMessage(">>PlayRTC ?? ?...."); } statReportHandler.stop(); // ?? ? false isChannelConnected = false; /** * ?? PlayRTCActivity . */ activity.setOnBackPressed(true); } /** * ?? ?? .<br> * ? disconnectChannel? . <br> * ?? ? ? ? ??, ? ? ? P2P? . <br> * v2.2.11 * @param obj PlayRTC * @param peerId String, ? ?? peer ? * @param peerUid String, ? ?? ? * @param reason String, "disconnect", "timeout" */ @Override public void onOtherDisconnectChannel(final PlayRTC obj, final String peerId, final String peerUid, final String reason) { String notiMsg = ""; if (reason != null && reason.equals("timeout")) { notiMsg = "[" + peerUid + "]? ? ? ?...."; } else { notiMsg = "[" + peerUid + "]? ?? ...."; } Utils.showToast(activity, notiMsg); activity.appnedLogMessage(notiMsg); statReportHandler.stop(); // ? ? View? ?? . // ? ? . if (activity.getRemoteVideoView() != null) { activity.getRemoteVideoView().bgClearColor(); // local videoView ? ? activity.getVideoLayer().resizeLocalVideoView(PlayRTCVideoViewGroup.RTCViewSizeType.Full); } } /* * PlayRTC? ? ? , PlayRTC? enum * @param obj PlayRTC * @param peerId String, ? ?? peer ? * @param peerUid String, ? ?? ? * @param status PlayRTCStatus PlayRTC? ? * @param desc String, Description */ @Override public void onStateChange(final PlayRTC obj, String peerId, final String peerUid, PlayRTCStatus status, String desc) { activity.appnedLogMessage(">>" + peerId + " onStatusChange[" + status + "]..."); // P2P ? ?. 1 // ? ? ?? ? ? PeerDisconnected <-> PeerConnected ? . if (status == PlayRTCStatus.PeerSuccess) { //P2P ? ? ? statReportHandler.start(obj, peerId); } } /* * PlayRTC? ? ? , PlayRTC? enum * @param obj PlayRTC * @param status PlayRTCStatus PlayRTC? ? * @param code PlayRTCCode PlayRTC? * @param desc String, Description */ @Override public void onError(final PlayRTC obj, PlayRTCStatus status, PlayRTCCode code, String desc) { String msg = "Error[" + code + "] Status[" + status + "] " + desc; Utils.showToast(activity, msg); activity.appnedLogMessage(">>" + peerId + " " + msg); //P2P ? ? ? statReportHandler.stop(); } /* * PlayRTC ? ? . * * * - Android Contect, PlayRTC project-ID * - ?? * - ?? : * - ?? ?? : 640 x 480 * - ? * - ? : * - P2P ?? : * - * * @param runType int * - 1. ??, ?, p2p data * - 2. ??, ? * - 3. ?, data * - 4. p2p data only * * @return PlayRTCConfig */ private PlayRTCConfig createPlayRTCConfig(int runType, String channelRing, String videoCodec, String audioCodec) { /* PlayRTC */ // 1. create PlayRTCConfig PlayRTCConfig config = PlayRTCFactory.createConfig(); config.setAndroidContext(activity.getApplicationContext()); // 2. TDCProjectId/TDCLicense set config.setProjectId(TDCProjectId); boolean useChannelRing = (channelRing.equals("true")); // 3. Ring : false ?? ? config.setRingEnable(useChannelRing); // UserMedia ? ? ?? . default true // true : ? ?, ? ? ??? . // false : ? ?? ? ?. blank ? ? // new v2.2.8 config.setPrevUserMediaEnable(true); /* * ?? ?? , 640x480 * min - max ? max ?? * - 320x240 ?? * - 640x480 ?? : ?? * - 1280x720 ?? : ? ? ? ?? ? ?. */ int frameWidth = 640; int frameHeight = 480; int minVideoFrameRate = 15; int maxVideoFrameRate = 30; int videoBitrateKbps = 1500; // ? ?? ? bitrate ,kbps // ISAC 32 // OPUS 32 ~ 64 int audioBitrateKbps = 32; /* * ? * enum PlayRTCVideoConfig.CameraType * - Front, * - Back */ PlayRTCVideoConfig.CameraType cameraType = PlayRTCVideoConfig.CameraType.Front; /* enum PlayRTCVideoConfig.VideoCodec * - VP8 * - VP9 * - H264, Open H.264 */ PlayRTCVideoConfig.VideoCodec videPreferCodec = VideoCodec.VP8; if (videoCodec.equals("vp9")) { videPreferCodec = VideoCodec.VP9; } else if (videoCodec.equals("h264")) { videPreferCodec = VideoCodec.H264; } /* * enum PlayRTCVideoConfig.AudioCodec * - ISAC, * - OPUS */ PlayRTCAudioConfig.AudioCodec audioPreferCodec = AudioCodec.OPUS; if (audioCodec.equals("isac")) { audioPreferCodec = AudioCodec.ISAC; } // 4. Audio/Video/Data Enable runType ? ? // ? + ? + Data if (runType == 1) { /* * ?? . * false SDK read-only ?, ?? ?? ? ? ?. */ config.video.setEnable(true); /* * ? * @param enum CameraType * - Front, * - Back */ config.video.setCameraType(cameraType); /* * Video ??? ?? , default VP8 * ? SDK ?? ?? ?. ? ? ? * v2.2.6 * @param enum VideoCodec, * - VP8 * - VP9 * - H264, Open H.264 */ config.video.setPreferCodec(videPreferCodec); /* * ?? ?? , 640x480 * min - max ? max ?? * - 320x240 ?? * - 640x480 ?? : ?? * - 1280x720 ?? : ? ? ? ?? ? ?. */ config.video.setMaxFrameSize(frameWidth, frameHeight); config.video.setMinFrameSize(frameWidth, frameHeight); config.video.setMinFrameRate(minVideoFrameRate); config.video.setMaxFrameRate(maxVideoFrameRate); /* * PlayRTC Video-Stream BandWidth . * 600 ~ 2500 * default 1500 (640x480) */ config.bandwidth.setVideoBitrateKbps(videoBitrateKbps); /* * ? . * false SDK read-only ?, ?? ? ? ? ?. */ config.audio.setEnable(true); /* * Audio? ?? , default ISAC * ? SDK ?? ?? ?. ? ? ? * v2.2.6 * @param codec AudioCodec * - ISAC, * - OPUS */ config.audio.setPreferCodec(audioPreferCodec); // ? ?? ? bitrate ,kbps // ISAC 32 // OPUS 32 ~ 64 config.bandwidth.setAudioBitrateKbps(audioBitrateKbps); /* * SDK ? ? ? Sound ? ?? * ? ? (AudioManager)? false * default true, loud speaker * * ------------------------------------------------- * ear-speaker | | wired-earphone * ^ | | ^ * | | | | * ? | <-----------> | * | | ? | | * v | | v * loud speaker| | bluetooth-headset * ------------------------------------------------- */ config.audio.setAudioManagerEnable(true); /* P2P ?? ?? DataChannel */ config.data.setEnable(true); } // ?? + ? else if (runType == 2) { /* * ?? . * false SDK read-only ?, ?? ?? ? ? ?. */ config.video.setEnable(true); /* * ? * @param enum CameraType * - Front, * - Back */ config.video.setCameraType(cameraType); /* * Video ??? ?? , default VP8 * ? SDK ?? ?? ?. ? ? ? * v2.2.6 * @param enum VideoCodec, * - VP8 * - VP9 * - H264, Open H.264 */ config.video.setPreferCodec(videPreferCodec); /* * ?? ?? , 640x480 * min - max ? max ?? * - 320x240 ?? * - 640x480 ?? : ?? * - 1280x720 ?? : ? ? ? ?? ? ?. ? ? ? */ config.video.setMaxFrameSize(frameWidth, frameHeight); config.video.setMinFrameSize(frameWidth, frameHeight); config.video.setMinFrameRate(minVideoFrameRate); config.video.setMaxFrameRate(maxVideoFrameRate); /* * PlayRTC Video-Stream BandWidth . * 600 ~ 2500 * default 1500 (640x480) */ config.bandwidth.setVideoBitrateKbps(videoBitrateKbps); /* * ? . * false SDK read-only ?, ?? ? ? ? ?. */ config.audio.setEnable(true); /* * Audio? ?? , default ISAC * ? SDK ?? ?? ?. ? ? ? * v2.2.6 * @param codec AudioCodec * - ISAC, * - OPUS */ config.audio.setPreferCodec(audioPreferCodec); // ? ?? ? bitrate ,kbps // ISAC 32 // OPUS 32 ~ 64 config.bandwidth.setAudioBitrateKbps(audioBitrateKbps); /* * SDK ? ? ? Sound ? ?? * ? ? (AudioManager)? false * default true, speaker */ config.audio.setAudioManagerEnable(true); /* P2P ?? ?? DataChannel */ config.data.setEnable(false); } // ? only else if (runType == 3) { // video . config.video.setEnable(false); /* * ? . * false SDK read-only ?, ?? ? ? ? ?. */ config.audio.setEnable(true); /* * Audio? ?? , default ISAC * ? SDK ?? ?? ?. ? ? ? * v2.2.6 * @param codec AudioCodec * - ISAC, * - OPUS */ config.audio.setPreferCodec(AudioCodec.OPUS); // ? ?? ? bitrate ,kbps // ISAC 32 // OPUS 32 ~ 64 config.bandwidth.setAudioBitrateKbps(audioBitrateKbps); /* * SDK ? ? ? Sound ? ?? * ? ? (AudioManager)? false * default true, speaker */ config.audio.setAudioManagerEnable(true); /* P2P ?? ?? DataChannel */ config.data.setEnable(false); } // Data Only else { config.video.setEnable(false); /* ?? */ config.audio.setEnable(false); /* ? */ config.data.setEnable(true); /* P2P ?? ?? DataChannel */ } /* * SDK Console */ config.log.console.setLevel(CONSOLE_LOG); /* SDK ? */ config.log.file.setLevel(FILE_LOG); /* ? ? ?? . [PATH]/yyyyMMdd.log , default 10? */ /* SDK ? ? ? , ? ? Pass */ File logPath = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + activity.getPackageName() + "/files/log"); // ? 10? config.log.file.setRolling(10); config.log.file.setLogPath(logPath.getAbsolutePath()); return config; } }