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

Dynamic conference rendering #111

Merged
merged 10 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ jobs:

- name: Archive Test Report
if: always()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Test report
path: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.WindowManager;
import android.widget.GridLayout;
import android.widget.Toast;

import androidx.annotation.NonNull;
Expand Down Expand Up @@ -414,6 +415,10 @@ public WebRTCClientConfig getConfig() {
return config;
}

public void setConfig(WebRTCClientConfig config) {
this.config = config;
}

public SDPObserver getSdpObserver(String streamId) {
return new SDPObserver(streamId);
}
Expand Down Expand Up @@ -764,6 +769,7 @@ public void initializeRenderers() {
config.localVideoRenderer.setEnableHardwareScaler(true /* enabled */);
localVideoSink.setTarget(config.localVideoRenderer);
}

}

public void initializePeerConnectionFactory() {
Expand Down Expand Up @@ -1203,10 +1209,8 @@ public void releaseRenderer(SurfaceViewRenderer renderer, VideoTrack track, Vide
renderer.clearAnimation();
mainHandler.postAtFrontOfQueue(renderer::clearImage);

mainHandler.post(() -> {
renderer.release();
renderer.setTag(null);
});
renderer.release();
renderer.setTag(null);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ public void testConferenceReconnect() throws IOException, InterruptedException {

onView(withId(R.id.multitrack_stats_popup_close_button)).perform(click());

//Thread.sleep(5000);
Thread.sleep(5000);

onView(withId(R.id.join_conference_button)).perform(click());

Expand Down Expand Up @@ -465,7 +465,7 @@ public void testConferenceReconnect() throws IOException, InterruptedException {
onView(withId(R.id.broadcasting_text_view))
.check(matches(withText(R.string.live)));

//Thread.sleep(3000);
Thread.sleep(3000);

onView(withId(R.id.join_conference_button)).perform(click());

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
package io.antmedia.webrtc_android_sample_app;

import static android.provider.Settings.System.getString;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.swipeUp;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.RootMatchers.isDialog;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
import static org.hamcrest.CoreMatchers.anyOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;



import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;
import android.widget.GridLayout;
import android.widget.TextView;

import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.test.core.app.ActivityScenario;

import androidx.test.core.app.ApplicationProvider;
import androidx.test.espresso.IdlingRegistry;
import androidx.test.espresso.IdlingResource;

import androidx.test.ext.junit.rules.ActivityScenarioRule;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.rule.GrantPermissionRule;
import androidx.test.uiautomator.UiDevice;



import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import org.junit.runner.RunWith;
import org.webrtc.SurfaceViewRenderer;
import org.webrtc.VideoSink;
import org.webrtc.VideoTrack;

import java.io.IOException;
import java.lang.reflect.Field;

import io.antmedia.webrtc_android_sample_app.basic.DynamicConferenceActivity;
import io.antmedia.webrtc_android_sample_app.basic.SettingsActivity;
import io.antmedia.webrtcandroidframework.core.PermissionHandler;
import io.antmedia.webrtcandroidframework.core.WebRTCClient;


/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class DynamicConferenceActivityTest {

@Rule
public GrantPermissionRule permissionRule
= GrantPermissionRule.grant(PermissionHandler.FULL_PERMISSIONS);

private IdlingResource mIdlingResource;
@Rule
public ActivityScenarioRule<DynamicConferenceActivity> dynamicConferenceActivityScenarioRule = new ActivityScenarioRule<>(DynamicConferenceActivity.class);


private String runningTest;
private String roomName;

@Before
public void before() throws IOException {
System.out.println("before test");
connectInternet();

getInstrumentation().waitForIdleSync();
Context context = ApplicationProvider.getApplicationContext();
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
roomName = sharedPreferences.getString(context.getString(R.string.roomId), SettingsActivity.DEFAULT_ROOM_NAME);
}

@After
public void after() {
System.out.println("after test");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}

}

@Rule
public TestWatcher watchman= new TestWatcher() {

@Override
protected void failed(Throwable e, Description description) {
Log.i("TestWatcher", "*** "+description + " failed!\n");
}

@Override
protected void succeeded(Description description) {
Log.i("TestWatcher", "*** "+description + " succeeded!\n");
}

protected void starting(Description description) {
Log.i("TestWatcher", "******\n*** "+description + " starting!\n");
runningTest = description.toString();
}

protected void finished(Description description) {
Log.i("TestWatcher", "*** "+description + " finished!\n******\n");
}
};

private void disconnectInternet() throws IOException {
UiDevice
.getInstance(androidx.test.InstrumentationRegistry.getInstrumentation())
.executeShellCommand("svc wifi disable"); // Switch off Wifi
UiDevice
.getInstance(androidx.test.InstrumentationRegistry.getInstrumentation())
.executeShellCommand("svc data disable"); // Switch off Mobile Data
}

private void connectInternet() throws IOException {
UiDevice
.getInstance(androidx.test.InstrumentationRegistry.getInstrumentation())
.executeShellCommand("svc wifi enable"); // Switch Wifi on again
UiDevice
.getInstance(androidx.test.InstrumentationRegistry.getInstrumentation())
.executeShellCommand("svc data enable"); // Switch Mobile Data on again
}

@Test
public void dynamicAddRemoveRendererTest() {
dynamicConferenceActivityScenarioRule.getScenario().onActivity(activity -> {
mIdlingResource = activity.getIdlingResource();
IdlingRegistry.getInstance().register(mIdlingResource);
activity.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
SurfaceViewRenderer renderer = null;
for(int i=0;i<10;i++)
renderer = activity.addSurfaceViewRenderer();

try {
Thread.sleep(300);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
GridLayout remoteParticipantsGridLayout = activity.findViewById(R.id.remote_participant_renderer);
assertEquals(remoteParticipantsGridLayout.getChildCount(),10);

activity.removeSurfaceViewRenderer(renderer);
assertEquals(remoteParticipantsGridLayout.getChildCount(),9);

activity.removeAllRenderers();
assertEquals(remoteParticipantsGridLayout.getChildCount(),0);
});
}

}
4 changes: 4 additions & 0 deletions webrtc-android-sample-app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
android:exported="true"
android:theme="@style/Theme.AppCompat.DayNight"
android:configChanges="orientation|keyboard|screenSize|smallestScreenSize|screenLayout"/>
<activity android:name=".basic.DynamicConferenceActivity"
android:exported="true"
android:theme="@style/Theme.AppCompat.DayNight"
android:configChanges="orientation|keyboard|screenSize|smallestScreenSize|screenLayout"/>
<activity android:name=".basic.ConferenceActivity"
android:exported="true"
android:theme="@style/Theme.AppCompat.DayNight"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
import io.antmedia.webrtc_android_sample_app.advanced.USBCameraActivity;
import io.antmedia.webrtc_android_sample_app.basic.ConferenceActivity;
import io.antmedia.webrtc_android_sample_app.basic.DataChannelOnlyActivity;
import io.antmedia.webrtc_android_sample_app.basic.DynamicConferenceActivity;
import io.antmedia.webrtc_android_sample_app.basic.PeerActivity;
import io.antmedia.webrtc_android_sample_app.basic.PlayActivity;
import io.antmedia.webrtc_android_sample_app.basic.PublishActivity;
import io.antmedia.webrtc_android_sample_app.basic.ScreenCaptureActivity;
import io.antmedia.webrtc_android_sample_app.basic.SettingsActivity;
import io.antmedia.webrtc_android_sample_app.basic.StatsActivity;
import io.antmedia.webrtc_android_sample_app.basic.WebviewActivity;
import io.antmedia.webrtc_android_sample_app.minimal.SimplePublishActivity;

import com.google.firebase.FirebaseApp;

Expand All @@ -67,6 +67,7 @@ private void createList() {
addActivity(PublishActivity.class, "Publish");
addActivity(PlayActivity.class, "Play");
addActivity(PeerActivity.class, "Peer");
addActivity(DynamicConferenceActivity.class, "Dynamic Conference");
addActivity(ConferenceActivity.class, "Conference");
addActivity(ScreenCaptureActivity.class, "Screen Share");
addActivity(DataChannelOnlyActivity.class, "DC Only");
Expand Down
Loading
Loading