Skip to content

Commit

Permalink
Merge pull request #235 from AgoraIO/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
xia ning authored Nov 30, 2021
2 parents e1213bf + 6cabbaa commit c0e0e56
Show file tree
Hide file tree
Showing 44 changed files with 396 additions and 211 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast;

Expand All @@ -28,6 +31,7 @@
import io.agora.rtc.IRtcEngineEventHandler;
import io.agora.rtc.RtcEngine;
import io.agora.rtc.internal.LastmileProbeConfig;
import io.agora.rtc.models.EchoTestConfiguration;

import static io.agora.api.example.common.model.Examples.ADVANCED;

Expand All @@ -43,18 +47,18 @@ public class PreCallTest extends BaseFragment implements View.OnClickListener {

private RtcEngine engine;
private int myUid;
private Button btn_lastmile, btn_echo;
private Button btn_lastmile, btn_echo, btn_echoVideo;
private FrameLayout preview;
private StatisticsInfo statisticsInfo;
private TextView lastmileQuality, lastmileResult;
private static final Integer MAX_COUNT_DOWN = 8;
private int num;
private Timer timer;
private TimerTask task;
private boolean echoTesting = false;
private Thread countDownThread;

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
handler = new Handler();
}

@Nullable
Expand All @@ -81,8 +85,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
* The SDK uses this class to report to the app on SDK runtime events.*/
String appId = getString(R.string.agora_app_id);
engine = RtcEngine.create(getContext().getApplicationContext(), appId, iRtcEngineEventHandler);
}
catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
getActivity().onBackPressed();
}
Expand All @@ -94,40 +97,23 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
statisticsInfo = new StatisticsInfo();
btn_echo = view.findViewById(R.id.btn_echo);
btn_echo.setOnClickListener(this);
btn_echoVideo = view.findViewById(R.id.btn_echoVideoTest);
btn_echoVideo.setOnClickListener(this);
btn_lastmile = view.findViewById(R.id.btn_lastmile);
btn_lastmile.setOnClickListener(this);
lastmileQuality = view.findViewById(R.id.lastmile_quality);
lastmileResult = view.findViewById(R.id.lastmile_result);
task = new TimerTask(){
public void run() {
num++;
if(num >= MAX_COUNT_DOWN * 2){
handler.post(() -> {
btn_echo.setEnabled(true);
btn_echo.setText("Start");
});
engine.stopEchoTest();
timer.cancel();
task.cancel();
}
else if(num >= MAX_COUNT_DOWN) {
handler.post(() -> btn_echo.setText("PLaying with " + (MAX_COUNT_DOWN * 2 - num) + "Seconds"));
}
else{
handler.post(() -> btn_echo.setText("Recording with " + (MAX_COUNT_DOWN - num) + "Seconds"));
}
}
};
preview = view.findViewById(R.id.echoTestView);
}

@Override
public void onClick(View v) {
if (v.getId() == R.id.btn_lastmile)
{
if (v.getId() == R.id.btn_lastmile) {
// Configure a LastmileProbeConfig instance.
LastmileProbeConfig config = new LastmileProbeConfig(){};
LastmileProbeConfig config = new LastmileProbeConfig() {
};
// Probe the uplink network quality.
config.probeUplink = true;
config.probeUplink = true;
// Probe the downlink network quality.
config.probeDownlink = true;
// The expected uplink bitrate (bps). The value range is [100000, 5000000].
Expand All @@ -138,14 +124,34 @@ public void onClick(View v) {
engine.startLastmileProbeTest(config);
btn_lastmile.setEnabled(false);
btn_lastmile.setText("Testing ...");
}
else if (v.getId() == R.id.btn_echo){
} else if (v.getId() == R.id.btn_echo) {
num = 0;
engine.startEchoTest(MAX_COUNT_DOWN);
btn_echo.setEnabled(false);
btn_echo.setText("Recording on Microphone ...");
timer = new Timer(true);
timer.schedule(task, 1000, 1000);
btn_echo.setText(R.string.recording_start);
countDownThread = new Thread(new CountDownTask());
countDownThread.start();
} else if (v.getId() == R.id.btn_echoVideoTest) {
if (!echoTesting) {
SurfaceView surfaceView = RtcEngine.CreateRendererView(getContext());
// Add to the local container
preview.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
EchoTestConfiguration config = new EchoTestConfiguration();
config.enableAudio = true;
config.enableVideo = true;
config.channelId = "randomChannel";
config.view = surfaceView;
engine.startEchoTest(config);
echoTesting = true;
btn_echoVideo.setText(getText(R.string.stop_echo_video_audio_test));
} else {
engine.stopEchoTest();
if (preview.getChildCount() > 0) {
preview.removeAllViews();
}
echoTesting = false;
btn_echoVideo.setText(getText(R.string.start_echo_video_audio_test));
}
}
}

Expand Down Expand Up @@ -263,7 +269,7 @@ public void onUserOffline(int uid, int reason) {
* @param quality
*/
@Override
public void onLastmileQuality(int quality){
public void onLastmileQuality(int quality) {
statisticsInfo.setLastMileQuality(quality);
updateLastMileResult();
}
Expand All @@ -281,20 +287,80 @@ public void onLastmileProbeResult(LastmileProbeResult lastmileProbeResult) {
updateLastMileResult();
handler.post(() -> {
btn_lastmile.setEnabled(true);
btn_lastmile.setText("Start");
btn_lastmile.setText(getString(R.string.start));
});
}
};

private void updateLastMileResult() {
handler.post(() -> {
if(statisticsInfo.getLastMileQuality() != null){
if (statisticsInfo.getLastMileQuality() != null) {
lastmileQuality.setText("Quality: " + statisticsInfo.getLastMileQuality());
}
if(statisticsInfo.getLastMileResult() != null){
if (statisticsInfo.getLastMileResult() != null) {
lastmileResult.setText(statisticsInfo.getLastMileResult());
}
});
}

}

@Override
public void onDestroy() {
/**leaveChannel and Destroy the RtcEngine instance*/
if (engine != null) {
/**After joining a channel, the user must call the leaveChannel method to end the
* call before joining another channel. This method returns 0 if the user leaves the
* channel and releases all resources related to the call. This method call is
* asynchronous, and the user has not exited the channel when the method call returns.
* Once the user leaves the channel, the SDK triggers the onLeaveChannel callback.
* A successful leaveChannel method call triggers the following callbacks:
* 1:The local client: onLeaveChannel.
* 2:The remote client: onUserOffline, if the user leaving the channel is in the
* Communication channel, or is a BROADCASTER in the Live Broadcast profile.
* @returns 0: Success.
* < 0: Failure.
* PS:
* 1:If you call the destroy method immediately after calling the leaveChannel
* method, the leaveChannel process interrupts, and the SDK does not trigger
* the onLeaveChannel callback.
* 2:If you call the leaveChannel method during CDN live streaming, the SDK
* triggers the removeInjectStreamUrl method.*/
engine.leaveChannel();
}
handler.post(RtcEngine::destroy);
engine = null;
super.onDestroy();
}

class CountDownTask implements Runnable {

private void updateCountDown() {
if (num > MAX_COUNT_DOWN * 2)
return;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (num == MAX_COUNT_DOWN * 2) {
handler.post(() -> {
btn_echo.setText(getString(R.string.start_echo_audio_test));
btn_echo.setEnabled(true);
});
engine.stopEchoTest();
} else if (num >= MAX_COUNT_DOWN) {
handler.post(() -> btn_echo.setText(getString(R.string.echo_playing_countdown) + " " + (MAX_COUNT_DOWN * 2 - num + 1)));
} else {
handler.post(() -> btn_echo.setText(getString(R.string.echo_record_countdown) + " " + (MAX_COUNT_DOWN - num + 1)));
}
num++;
updateCountDown();
}

@Override
public void run() {
updateCountDown();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ public class AudioRecordService extends Service {

/**
* Since v3.5.1
* 根据实际需求,你可以将外部音频帧推送到音频采集后、编码前或本地播放前的位置。
* 你可以多次调用该方法,将一个音频帧推送到多个位置或者将多个音频帧推送到不同位置。
* 例如,在 KTV 场景中,你可以将歌声推送到音频采集后的位置,让歌声经过 SDK 音频模块的处理,
* 从而获取优质的音频体验;将伴奏推送到音频编码前的位置,让伴奏不受 SDK 音频模块的影响。
* https://docs.agora.io/en/Interactive%20Broadcast/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_rtc_engine.html?platform=Android#acc77cfbe4ddfcf36d722a89af6729ce5
*
* {@link io.agora.rtc.Constants.AudioExternalSourcePos}
* AUDIO_EXTERNAL_PLAYOUT_SOURCE(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="Lastmile Network Pretest" />
android:text="@string/lastmile_network_pretest" />

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/btn_lastmile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/lb_lastmile"
android:clickable="true"
android:text="start" />
android:text="@string/start" />

<TextView
android:id="@+id/lastmile_quality"
Expand Down Expand Up @@ -61,15 +61,31 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="Echo Pretest" />
android:text="@string/echo_pretest" />

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/btn_echo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/lb_echo"
android:clickable="true"
android:text="start" />
android:text="@string/start_echo_audio_test" />

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/btn_echoVideoTest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/btn_echo"
android:clickable="true"
android:text="@string/start_echo_video_audio_test" />

<FrameLayout
android:id="@+id/echoTestView"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_marginTop="10dp"
android:layout_below="@id/btn_echoVideoTest"
/>

</RelativeLayout>

Expand Down
9 changes: 9 additions & 0 deletions Android/APIExample/app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,13 @@
<string name="track_change">音轨切换(%d)</string>
<string name="track_last">上一个</string>
<string name="track_next">下一个</string>
<string name="start_echo_video_audio_test">开始音视频测试</string>
<string name="start_echo_audio_test">开始音频测试</string>
<string name="stop_echo_video_audio_test">停止音视频测试</string>
<string name="stop_echo_audio_test">停止音频测试</string>
<string name="echo_pretest">网络回路测试</string>
<string name="lastmile_network_pretest">网络延迟测试</string>
<string name="echo_record_countdown">录制倒计时</string>
<string name="echo_playing_countdown">播放倒计时</string>
<string name="recording_start">开始麦克风录制</string>
</resources>
9 changes: 9 additions & 0 deletions Android/APIExample/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,13 @@
<string name="track_change">change track(%d)</string>
<string name="track_last">LAST</string>
<string name="track_next">NEXT</string>
<string name="start_echo_video_audio_test">Start Echo Video/Audio Test</string>
<string name="start_echo_audio_test">Start Echo Audio Test</string>
<string name="stop_echo_video_audio_test">Stop Echo Video/Audio Test</string>
<string name="stop_echo_audio_test">Stop Echo Audio Test</string>
<string name="echo_pretest">Echo Test</string>
<string name="lastmile_network_pretest">Lastmile Network Pretest</string>
<string name="echo_record_countdown">Recording Countdown</string>
<string name="echo_playing_countdown">Playing Countdown</string>
<string name="recording_start">Recording on Microphone</string>
</resources>
2 changes: 1 addition & 1 deletion Android/APIExample/lib-component/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

api 'io.agora.rtc:full-sdk:3.5.1'
api 'io.agora.rtc:full-sdk:3.5.2'
api 'io.agora:player:1.3.0'

}
Loading

0 comments on commit c0e0e56

Please sign in to comment.