11package io .agora .api .example .examples .advanced ;
22
3+ import static io .agora .api .example .common .model .Examples .ADVANCED ;
4+ import static io .agora .rtc .video .VideoCanvas .RENDER_MODE_HIDDEN ;
5+ import static io .agora .rtc .video .VideoEncoderConfiguration .STANDARD_BITRATE ;
6+
37import android .content .Context ;
48import android .os .Bundle ;
59import android .text .TextUtils ;
1115import android .widget .Button ;
1216import android .widget .EditText ;
1317import android .widget .FrameLayout ;
18+ import android .widget .SeekBar ;
19+ import android .widget .TextView ;
1420
1521import androidx .annotation .NonNull ;
1622import androidx .annotation .Nullable ;
3137import io .agora .rtc .video .VideoCanvas ;
3238import io .agora .rtc .video .VideoEncoderConfiguration ;
3339
34- import static io .agora .api .example .common .model .Examples .ADVANCED ;
35- import static io .agora .rtc .video .VideoCanvas .RENDER_MODE_HIDDEN ;
36- import static io .agora .rtc .video .VideoEncoderConfiguration .STANDARD_BITRATE ;
37-
3840/**
3941 * This demo demonstrates how to make a one-to-one video call
4042 */
@@ -49,15 +51,17 @@ public class LiveStreaming extends BaseFragment implements View.OnClickListener
4951 private static final String TAG = LiveStreaming .class .getSimpleName ();
5052
5153 private FrameLayout foreGroundVideo , backGroundVideo ;
52- private Button join , publish , latency ;
54+ private Button join , publish , latency , super_resolution ;
5355 private EditText et_channel ;
5456 private RtcEngine engine ;
5557 private int myUid ;
5658 private int remoteUid ;
5759 private boolean joined = false ;
5860 private boolean isHost = false ;
5961 private boolean isLowLatency = false ;
60- private boolean isLocalVideoForeground = false ;
62+ private boolean isLocalVideoForeground = true ;
63+ private boolean enableSuperResolution = false ;
64+ private SeekBar sbCameraRotate ;
6165
6266 @ Nullable
6367 @ Override
@@ -73,6 +77,8 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
7377 publish = view .findViewById (R .id .btn_publish );
7478 latency = view .findViewById (R .id .btn_latency );
7579 et_channel = view .findViewById (R .id .et_channel );
80+ super_resolution = view .findViewById (R .id .btn_super_resolution );
81+ super_resolution .setOnClickListener (this );
7682 latency .setEnabled (false );
7783 publish .setEnabled (false );
7884 view .findViewById (R .id .btn_join ).setOnClickListener (this );
@@ -81,6 +87,30 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
8187 view .findViewById (R .id .foreground_video ).setOnClickListener (this );
8288 foreGroundVideo = view .findViewById (R .id .background_video );
8389 backGroundVideo = view .findViewById (R .id .foreground_video );
90+ initCameraRotateView ();
91+ }
92+
93+ private void initCameraRotateView (){
94+ TextView tvValue = getView ().findViewById (R .id .tv_camera_rotation_value );
95+ sbCameraRotate = getView ().findViewById (R .id .sb_camera_rotation );
96+ sbCameraRotate .setMax (3 );
97+ sbCameraRotate .setOnSeekBarChangeListener (new SeekBar .OnSeekBarChangeListener () {
98+ @ Override
99+ public void onProgressChanged (SeekBar seekBar , int progress , boolean fromUser ) {
100+ tvValue .setText (progress * 90 + "" );
101+ }
102+
103+ @ Override
104+ public void onStartTrackingTouch (SeekBar seekBar ) {
105+
106+ }
107+
108+ @ Override
109+ public void onStopTrackingTouch (SeekBar seekBar ) {
110+ int progress = seekBar .getProgress ();
111+ engine .setCameraCaptureRotation (progress );
112+ }
113+ });
84114 }
85115
86116 @ Override
@@ -139,6 +169,8 @@ public void onClick(View v) {
139169 joinChannel (channelId );
140170 }).start ();
141171 } else {
172+ remoteUid = 0 ;
173+ isHost = false ;
142174 joined = false ;
143175 /**After joining a channel, the user must call the leaveChannel method to end the
144176 * call before joining another channel. This method returns 0 if the user leaves the
@@ -158,7 +190,17 @@ public void onClick(View v) {
158190 * 2:If you call the leaveChannel method during CDN live streaming, the SDK
159191 * triggers the removeInjectStreamUrl method.*/
160192 engine .leaveChannel ();
193+ engine .stopPreview ();
194+
195+
196+ foreGroundVideo .removeAllViews ();
197+ backGroundVideo .removeAllViews ();
198+
199+ publish .setText (getString (R .string .enable_publish ));
161200 join .setText (getString (R .string .join ));
201+ publish .setEnabled (false );
202+ latency .setEnabled (false );
203+ super_resolution .setEnabled (false );
162204 }
163205 } else if (v .getId () == R .id .btn_publish ) {
164206 isHost = !isHost ;
@@ -211,6 +253,11 @@ public void onClick(View v) {
211253 localView .setZOrderMediaOverlay (true );
212254 localView .setZOrderOnTop (true );
213255 }
256+ }else if (v .getId () == R .id .btn_super_resolution ){
257+ int ret = engine .enableRemoteSuperResolution (remoteUid , !enableSuperResolution );
258+ if (ret !=0 ){
259+ Log .w (TAG , String .format ("enableRemoteSuperResolution error code %d " , ret ));
260+ }
214261 }
215262
216263 }
@@ -330,6 +377,7 @@ public void run() {
330377 join .setText (getString (R .string .leave ));
331378 publish .setEnabled (true );
332379 latency .setEnabled (true );
380+ sbCameraRotate .setEnabled (true );
333381 }
334382 });
335383 }
@@ -450,6 +498,8 @@ public void onUserJoined(int uid, int elapsed) {
450498
451499 // Setup remote video to render
452500 engine .setupRemoteVideo (new VideoCanvas (surfaceView , RENDER_MODE_HIDDEN , remoteUid ));
501+
502+ super_resolution .setEnabled (true );
453503 });
454504 }
455505
@@ -467,13 +517,16 @@ public void onUserJoined(int uid, int elapsed) {
467517 public void onUserOffline (int uid , int reason ) {
468518 Log .i (TAG , String .format ("user %d offline! reason:%d" , uid , reason ));
469519 showLongToast (String .format ("user %d offline! reason:%d" , uid , reason ));
520+ remoteUid = 0 ;
470521 handler .post (new Runnable () {
471522 @ Override
472523 public void run () {
473524 /**Clear render view
474525 Note: The video will stay at its last frame, to completely remove it you will need to
475526 remove the SurfaceView from its parent*/
476527 engine .setupRemoteVideo (new VideoCanvas (null , RENDER_MODE_HIDDEN , uid ));
528+
529+ super_resolution .setEnabled (false );
477530 }
478531 });
479532 }
@@ -494,5 +547,36 @@ public void run() {
494547 }
495548 });
496549 }
550+
551+ /**
552+ *
553+ * @param uid remote user id
554+ * @param enabled updated status of super resolution
555+ * @param reason possible reasons are:
556+ * SR_STATE_REASON_SUCCESS(0)
557+ * SR_STATE_REASON_STREAM_OVER_LIMITATION(1)
558+ * SR_STATE_REASON_USER_COUNT_OVER_LIMITATION(2)
559+ * SR_STATE_REASON_DEVICE_NOT_SUPPORTED(3)
560+ */
561+ @ Override
562+ public void onUserSuperResolutionEnabled (int uid , boolean enabled , int reason ) {
563+ super .onUserSuperResolutionEnabled (uid , enabled , reason );
564+ if (uid == 0 && !enabled && reason == 3 ){
565+ showLongToast (String .format ("Unfortunately, Super Resolution can't enabled because your device doesn't support this feature." ));
566+ return ;
567+ }
568+ if (remoteUid == uid ){
569+ if (reason !=0 ){
570+ showLongToast (String .format ("Super Resolution can't enabled because of reason code: %d" , reason ));
571+ }
572+ enableSuperResolution = enabled ;
573+ handler .post (new Runnable () {
574+ @ Override
575+ public void run () {
576+ super_resolution .setText (enableSuperResolution ?getText (R .string .closesuperr ):getText (R .string .opensuperr ));
577+ }
578+ });
579+ }
580+ }
497581 };
498582}
0 commit comments