Skip to content

Commit

Permalink
Merge branch 'master' into usbCameraSupport
Browse files Browse the repository at this point in the history
  • Loading branch information
burak-58 authored Nov 23, 2023
2 parents f594e7d + 1f642c7 commit 4dcf194
Show file tree
Hide file tree
Showing 17 changed files with 328 additions and 385 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ jobs:
python-version: '3.9'

- name: Install python packages
run: pip3 install requests selenium==3.141.0 flask webdriver-manager


run: |
wget https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/119.0.6045.105/linux64/chromedriver-linux64.zip
unzip chromedriver-linux64.zip
cp chromedriver-linux64/chromedriver /home/ubuntu
pip3 install requests selenium==4.14 flask
- name: Run Multitrack Conference Test Server
run: python3 multitrack-conference-server.py &

Expand All @@ -60,7 +63,7 @@ jobs:
script: |
touch emulator.log
chmod 777 emulator.log
adb logcat >> emulator.log &
adb logcat io.antmedia:I >> emulator.log &
./gradlew jacocoTestReport; EXIT_CODE=$?; exit $EXIT_CODE
- name: Archive Test Report
Expand All @@ -72,6 +75,7 @@ jobs:
webrtc-android-sample-app/build/reports/tests/testDebugUnitTest/
webrtc-android-sample-app/build/reports/jacoco/jacocoTestReport/
webrtc-android-sample-app/build/reports/androidTests/
webrtc-android-sample-app/build/outputs/connected_android_test_additional_output/
webrtc-android-framework/build/reports/tests/testDebugUnitTest/
webrtc-android-framework/build/reports/jacoco/jacocoTestReport/
webrtc-android-framework/build/reports/androidTests/
Expand Down
2 changes: 2 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ coverage:
patch:
default:
target: 75.0
ignore:
- "webrtc-android-sample-app"

65 changes: 44 additions & 21 deletions multitrack-conference-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,36 @@
from selenium.webdriver.common.alert import Alert
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from flask import Flask, request
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service




class Browser:
def init(self, is_headless):
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
chrome_options.add_argument("--use-fake-ui-for-media-stream")
chrome_options.add_argument("--use-fake-device-for-media-stream")
chrome_options.add_argument('--log-level=3')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-extensions')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--disable-setuid-sandbox')
browser_options = Options()
browser_options.add_experimental_option("detach", True)
browser_options.add_argument("--use-fake-ui-for-media-stream")
browser_options.add_argument("--use-fake-device-for-media-stream")
browser_options.add_argument('--log-level=3')
browser_options.add_argument('--no-sandbox')
browser_options.add_argument('--disable-extensions')
browser_options.add_argument('--disable-gpu')
browser_options.add_argument('--disable-dev-shm-usage')
browser_options.add_argument('--disable-setuid-sandbox')
if is_headless:
chrome_options.add_argument("--headless")

browser_options.add_argument("--headless")
dc = DesiredCapabilities.CHROME.copy()
dc['goog:loggingPrefs'] = { 'browser':'ALL' }

service = Service(executable_path='/home/ubuntu/chromedriver')
#service = Service(executable_path='C:/WebDriver/chromedriver.exe')

self.driver = webdriver.Chrome(ChromeDriverManager().install(), chrome_options=chrome_options)
self.driver = webdriver.Chrome(service=service, options=browser_options)

def open_in_new_tab(self, url, tab_id):
self.driver.switch_to.window(self.driver.window_handles[0])
self.driver.execute_script("window.open('about:blank', '"+tab_id+"');")
print (self.driver.window_handles)
self.driver.switch_to.window(tab_id)
Expand All @@ -57,6 +61,9 @@ def write_to_element(self, element, text):
def click_element(self, element):
element.click()

def switch_to_tab(self, tab_id):
self.driver.switch_to.window(tab_id)

def close(self):
self.driver.close()

Expand All @@ -75,29 +82,45 @@ def close_all(self):

@app.route('/create', methods=['GET'])
def create():
# room = request.args.get('room')
chrome.open_in_new_tab(url, "p1")
room = request.args.get('room')
test = request.args.get('test')
participant = request.args.get('participant')
print("\n create for room:"+room+":"+participant+" in "+test)
chrome.open_in_new_tab(url+"?roomId="+room+"&streamId="+participant, participant)
return f'Room created', 200

@app.route('/join', methods=['GET'])
def join():
room = request.args.get('room')
test = request.args.get('test')
participant = request.args.get('participant')
print("\n join for room:"+room+":"+participant+" in "+test)
chrome.switch_to_tab(participant)
join_button = chrome.get_element_by_id("join_publish_button")
join_button.click()
return f'Joined the room', 200

@app.route('/leave', methods=['GET'])
def leave():
room = request.args.get('room')
test = request.args.get('test')
participant = request.args.get('participant')
print("\n leave for room:"+room+":"+participant+" in "+test)
chrome.switch_to_tab(participant)
leave_button = chrome.get_element_by_id("stop_publish_button")
leave_button.click()
return f'Left the room', 200

@app.route('/delete', methods=['GET'])
def delete():
#chrome.close()
#return f'Tab closed', 200
for handle in chrome.window_handles:
chrome.switch_to.window(handle)
chrome.close()
room = request.args.get('room')
test = request.args.get('test')
participant = request.args.get('participant')
print("\n delete for room:"+room+":"+participant+" in "+test)
chrome.switch_to_tab(participant)
chrome.close()
return f'Tab closed', 200


if __name__ == '__main__':
app.run(host='0.0.0.0', port=3030)
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class ScreenCapturerAndroid implements VideoCapturer, VideoSink {
@Nullable private MediaProjection mediaProjection;
private boolean isDisposed;
private WindowManager windowManager;
private int deviceRotation = 0;
public int deviceRotation = 0;
private static final String TAG = ScreenCapturerAndroid.class.getSimpleName();

@Nullable private MediaProjectionManager mediaProjectionManager;
Expand Down Expand Up @@ -213,25 +213,28 @@ VIRTUAL_DISPLAY_DPI, DISPLAY_FLAGS, new Surface(surfaceTextureHelper.getSurfaceT
null /* callback */, null /* callback handler */);
}

// This is called on the internal looper thread of {@Code SurfaceTextureHelper}.
@Override
public void onFrame(VideoFrame frame) {
numCapturedFrames++;
Log.v(TAG, "Frame received " + numCapturedFrames);
int rotation = windowManager.getDefaultDisplay().getRotation();
public void rotateScreen(int rotation) {
if (deviceRotation != rotation) {
Log.w("Rotation", "onFrame: " + rotation);
deviceRotation = rotation;

if (deviceRotation*90 % 180 != 0) {
virtualDisplay.resize(height, width, VIRTUAL_DISPLAY_DPI);
surfaceTextureHelper.setTextureSize(height, width);
}
else {
if (deviceRotation == 0) {
virtualDisplay.resize(width, height, VIRTUAL_DISPLAY_DPI);
surfaceTextureHelper.setTextureSize(width, height);
} else if (deviceRotation == 180) {
// 180 degree is not supported by MediaProjection
} else {
virtualDisplay.resize(height, width, VIRTUAL_DISPLAY_DPI);
surfaceTextureHelper.setTextureSize(height, width);
}
}
}

// This is called on the internal looper thread of {@Code SurfaceTextureHelper}.
@Override
public void onFrame(VideoFrame frame) {
numCapturedFrames++;
Log.v(TAG, "Frame received " + numCapturedFrames);
capturerObserver.onFrameCaptured(frame);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
public class ScreenCapturerAndroidTest {

@Test
public void testOnFrameRotation() {
public void testRotateScreen() {

ScreenCapturerAndroid screenCapturerAndroid = spy(new ScreenCapturerAndroid(null, null));
WindowManager windowManager = Mockito.spy(WindowManager.class);
Expand All @@ -43,30 +43,34 @@ public void testOnFrameRotation() {
screenCapturerAndroid.setVirtualDisplay(virtualDisplay);
screenCapturerAndroid.setSurfaceTextureHelper(surfaceTextureHelper);

screenCapturerAndroid.setCapturerObserver(mock(CapturerObserver.class));
CapturerObserver capturerObserver = mock(CapturerObserver.class);
screenCapturerAndroid.setCapturerObserver(capturerObserver);

int width = 540;
int height = 960;
screenCapturerAndroid.setWidth(width);
screenCapturerAndroid.setHeight(height);

VideoFrame frame = new VideoFrame(mock(VideoFrame.Buffer.class), 0, 0);
screenCapturerAndroid.onFrame(frame);
screenCapturerAndroid.deviceRotation = 0;

screenCapturerAndroid.rotateScreen(90);

Mockito.when(display.getRotation()).thenReturn(1);
screenCapturerAndroid.onFrame(frame);
screenCapturerAndroid.rotateScreen(0);

Mockito.verify(virtualDisplay).resize(height, width, VIRTUAL_DISPLAY_DPI);
Mockito.verify(surfaceTextureHelper).setTextureSize(height, width);

Mockito.when(display.getRotation()).thenReturn(2);
screenCapturerAndroid.onFrame(frame);
screenCapturerAndroid.rotateScreen(90);

Mockito.verify(virtualDisplay).resize(width, height, VIRTUAL_DISPLAY_DPI);
Mockito.verify(surfaceTextureHelper).setTextureSize(width,height);

VideoFrame frame = mock(VideoFrame.class);
screenCapturerAndroid.onFrame(frame);


Mockito.verify(capturerObserver).onFrameCaptured(frame);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
Expand Down Expand Up @@ -905,7 +906,7 @@ public void testCreatePeerConnection() {
doNothing().when(webRTCClient).reportError(anyString(), anyString());
doThrow(new NullPointerException()).when(webRTCClient).createMediaConstraintsInternal();
webRTCClient.createPeerConnection(streamId);
verify(webRTCClient, timeout(1000)).reportError(eq(streamId), anyString());
verify(webRTCClient, timeout(10000)).reportError(eq(streamId), anyString());

}

Expand Down
1 change: 1 addition & 0 deletions webrtc-android-sample-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ android {
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments useTestStorageService: "true"

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.rule.GrantPermissionRule;

import org.apache.commons.lang3.RandomStringUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -52,6 +53,7 @@ public class ConferenceActivityTest {
@Rule
public GrantPermissionRule permissionRule
= GrantPermissionRule.grant(AbstractSampleSDKActivity.REQUIRED_PUBLISH_PERMISSIONS);
private String roomName;

@Before
public void before() {
Expand Down Expand Up @@ -93,12 +95,13 @@ protected void finished(Description description) {
@Test
public void testJoinConfereceActivity() {
Intent intent = new Intent(ApplicationProvider.getApplicationContext(), ConferenceActivity.class);

roomName = "room_"+RandomStringUtils.randomNumeric(3);
ActivityScenario<ConferenceActivity> scenario = ActivityScenario.launch(intent);

scenario.onActivity(new ActivityScenario.ActivityAction<ConferenceActivity>() {
@Override
public void perform(ConferenceActivity activity) {
SettingsActivity.changeRoomName(activity, roomName);
mIdlingResource = activity.getIdlingResource();
IdlingRegistry.getInstance().register(mIdlingResource);
activity.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
Expand Down
Loading

0 comments on commit 4dcf194

Please sign in to comment.