Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android refactoring + rtc stats #58

Open
wants to merge 26 commits into
base: development
Choose a base branch
from

Conversation

vona-ben
Copy link
Collaborator

@vona-ben vona-ben commented Aug 28, 2023

Note: A dev branch should be created so we can merge this after review

Complete refactoring of Android code. Using a similar approach of OPENTOK network library JS.

Added NetworkQualityTest class is a utility for testing network quality and gathering statistics during video streaming sessions using the OpenTok platform. It allows monitoring various network and media statistics, such as video bitrate, audio quality, round-trip time, and more.

The NetworkQualityTest will send regular callbacks which can be handled using NetworkQualityTestCallbackListener.

The MainActivityclass is a sample that shows how to use this class and how to handle the callback.

Screenshot 2023-08-30 at 5 40 43 PM

@vona-ben vona-ben changed the title Android rtc stats Android refactoring + rtc stats Aug 30, 2023
}
jitter = rtcStatObject.optDouble(JITTER, -1);
} else if (CANDIDATE_PAIR.equals(statType)) {
boolean isNominated = rtcStatObject.optBoolean(IS_NOMINATED, false);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think several candidates may be nominated. Why not using the selectedCandidatePairId from the transport stats?

https://developer.mozilla.org/en-US/docs/Web/API/RTCIceCandidatePairStats/selected

private AlertDialog dialog;
public class MainActivity extends Activity {
static final String LOGTAG = "quality-stats-demo";
private static final String SESSION_ID = "YOUR_SESSION_ID";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the most distracted users, let's add some documentation on the README about this. By not being empty anymore the app will no longer alert the user and will try to connect for the duration of the timeout.

mHandler.postDelayed(statsRunnable, TEST_DURATION * 1000);
}
```
To stop the test, you can call stopTest. If the test is halted before 5 seconds, an error will be triggered.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: change "you can call stopTest" to "you can call NetworkQualityTest.stopTest()"

@@ -1,7 +1,11 @@
OpenTok Android Network Test Sample
===================================

This sample shows how to use this OpenTok Android SDK to determine the appropriate audio and video
# NetworkQualityTest

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Link to NetworkQualityTest README


6. **Clean Up**

To ensure proper resource release, you should handle cleanup when needed. In your `onPause`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I am not mistaken, onPause() is triggered when app goes to the background. Video is off, but audio is still on. Having that in mind, don't know if there is the need to stop the test (of course, knowing without video, the stats will go up). Your call

@@ -9,6 +8,8 @@
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WRITE_EXTERNAL_STORAGE permission does not have to be requested on the java side as well? On java side only see camera, internet and audio.

Log.d(LOGTAG, "Audio Packet Lost Ratio " + stats.getAudioPacketLostRatio() * 100 + "%");
Log.d(LOGTAG, "Video Packet Lost Ratio " + stats.getVideoPacketLostRatio() * 100 + "%");
Log.d(LOGTAG, "Jitter: " + stats.getJitter());
Log.d(LOGTAG, "Quality Limitation Reason: " + stats.getQualityLimitationReason());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can change the previous logs with Log.d(LOGTAG, sentVideoInfo);. In the future if we have to change something, we only have to change it in one place

}
});
// Start the quality test
networkQualityTest.startTest();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we only start the test when we start publishing? What if the user does not provide the permissions, or takes a lot of time to do so, and the test finishes without even having published? (Based on what I understood, if not explicitly stopped the test only takes 30s)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved permission to the MainActivity and only run the test now if the user accepted the permissions.

```java
new NetworkQualityTestCallbackListener() {
@Override
public void onQualityTestResults(String recommendedSetting) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the recommendedSetting be do not use video or something similar? If the minimum conditions are not met?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a threshold where the video is not recommended, added it to the docs and comments

Copy link

@goncalocostamendes goncalocostamendes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks great.
I left some comments. The majority are nit.
Tomorrow I will test the app to do a final validation

Comment on lines +61 to +63
- `onQualityTestResults`: Receive the final test results and the recommended setting based on quality thresholds.
- `onQualityTestStatsUpdate`: Receive real-time statistics updates during the test.
- `onError`: Handle errors that occur during the test.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide more details on the API:

  • onQualityTestResults() -- What are the possible values of recommendedSetting, and what do they mean?
  • onQualityTestStatsUpdate() -- What are the properties of CallbackQualityStats, and what do they mean?
  • onError() -- What are the possible errors, and what do they mean?

* Voice-only -- Your bandwidth is too low for video.
You can configure the following parameters:

- `sessionId`: The session ID of your OpenTok session.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mention that this should be a routed session (right?) And mention that this session should only be used for the test (not for communications).

Comment on lines +54 to +55
- `resolution`: The camera capture resolution for the publisher. Defaults to `HIGH` if not specified.
- `testDurationSec`: The duration of the test in seconds. Defaults to `30 sec` if not specified.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are possible values for resolution and testDurationSec.

Comment on lines +3 to +5
The `NetworkQualityTest` class is a utility for testing network quality and gathering statistics
during video streaming sessions using the OpenTok platform. It allows you to monitor various network
and media statistics, such as video bitrate, audio quality, round-trip time, and more.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a link to the docs on the callback methods (see my comments on the main README).

@vona-ben vona-ben changed the base branch from master to development August 31, 2023 03:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants