10000 Add Unified-Plan API. (#359) · next-coder/flutter-webrtc@11c1fd1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 11c1fd1

Browse files
authored
Add Unified-Plan API. (flutter-webrtc#359)
* Add API and files for unified-plan. * Add more. * Add more. * Update. * Fix bug. * Update. * Fix the kind parameter in RTCRTPCodec. * Add PeerConnectionState and add RTCTrackEvent. * Add example for unified-plan. * Update. * Reduce code. * Fix simulcast. * Fix RtpSender.replaceTrack. * More. * Add support for iOS. * Optimized code. * Fix simulcast for iOS. * Update. * Upgrade GoogleWebRTC@android to 1.0.32006. * Update. * Merge changes from master. * Update. * Update README.md * Update. * Use shared code in iOS and macOS. * Update rtc_peerconnection_impl.dart
1 parent 975a9f0 commit 11c1fd1

File tree

75 files changed

+5363
-5428
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+5363
-5428
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ WebRTC plugin for Flutter Mobile/Desktop/Web
99
| Audio/Video | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | [WIP] | [WIP] | |
1010
| Data Channel | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | [WIP] | [WIP] | |
1111
| Screen Capture | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | | | |
12-
| Unified-Plan | | | | | | | |
12+
| Unified-Plan | :heavy_check_mark: | :heavy_check_mark: | | :heavy_check_mark: | | | |
1313
| MediaRecorder| :warning: | :warning: | :heavy_check_mark: | | | | |
1414

1515
## Usage

android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ android {
2525
compileSdkVersion 28
2626

2727
defaultConfig {
28-
minSdkVersion 18
28+
minSdkVersion 21
2929
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
3030
consumerProguardFiles 'proguard-rules.pro'
3131
}
@@ -41,6 +41,6 @@ android {
4141
}
4242

4343
dependencies {
44-
api 'org.webrtc:google-webrtc:1.0.30039'
44+
api 'org.webrtc:google-webrtc:1.0.32006'
4545
implementation "androidx.annotation:annotation:1.1.0"
4646
}

android/src/main/java/com/cloudwebrtc/webrtc/FlutterRTCVideoRenderer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,10 @@ private void setVideoTrack(VideoTrack videoTrack) {
170170
this.videoTrack = videoTrack;
171171

172172
if (videoTrack != null) {
173+
Log.w(TAG, "FlutterRTCVideoRenderer.setVideoTrack, set video track to " + videoTrack.id());
173174
tryAddRendererToVideoTrack();
174175
} else {
175-
Log.w(TAG, "VideoTrack is null");
176+
Log.w(TAG, "FlutterRTCVideoRenderer.setVideoTrack, set video track to null");
176177
}
177178
}
178179
}

android/src/main/java/com/cloudwebrtc/webrtc/GetUserMediaImpl.java

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ public void onResume() {
211211
this.applicationContext = applicationContext;
212212
}
213213

214+
static private void resultError(String method, String error, Result result) {
215+
String errorMsg = method + "(): " + error;
216+
result.error(method, errorMsg,null);
217+
Log.d(TAG, errorMsg);
218+
}
219+
214220
/**
215221
* Includes default constraints set for the audio media type.
216222
*
@@ -396,7 +402,7 @@ void getUserMedia(
396402
// requestedMediaTypes is the empty set, the method invocation fails
397403
// with a TypeError.
398404
if (requestPermissions.isEmpty()) {
399-
result.error("TypeError", "constraints requests no media types", null);
405+
resultError("getUserMedia", "TypeError, constraints requests no media types", result);
400406
return;
401407
}
402408

@@ -423,7 +429,7 @@ public void invoke(Object... args) {
423429
// getUserMedia() algorithm, if the user has denied
424430
// permission, fail "with a new DOMException object whose
425431
// name attribute has the value NotAllowedError."
426-
result.error("DOMException", "NotAllowedError", null);
432+
resultError("getUserMedia", "DOMException, NotAllowedError", result);
427433
}
428434
});
429435
}
@@ -453,7 +459,7 @@ protected void onReceiveResult(int requestCode, Bundle resultData) {
453459
Intent mediaProjectionData = resultData.getParcelable(PROJECTION_DATA);
454460

455461
if (resultCode != Activity.RESULT_OK) {
456-
result.error(null, "User didn't give permission to capture the screen.", null);
462+
resultError("screenRequestPremissions", "User didn't give permission to capture the screen.", result);
457463
return;
458464
}
459465

@@ -465,13 +471,11 @@ protected void onReceiveResult(int requestCode, Bundle resultData) {
465471
new MediaProjection.Callback() {
466472
@Override
467473
public void onStop() {
468-
Log.e(TAG, "User revoked permission to capture the screen.");
469-
result.error(null, "User revoked permission to capture the screen.", null);
474+
resultError("MediaProjection.Callback()", "User revoked permission to capture the screen.", result);
470475
}
471476
});
472477
if (videoCapturer == null) {
473-
result.error(
474-
/* type */ "GetDisplayMediaFailed", "Failed to create new VideoCapturer!", null);
478+
resultError("screenRequestPremissions", "GetDisplayMediaFailed, User revoked permission to capture the screen.", result);
475479
return;
476480
}
477481

@@ -573,7 +577,7 @@ private void getUserMedia(
573577
// specified by
574578
// https://www.w3.org/TR/mediacapture-streams/#dom-mediadevices-getusermedia
575579
// with respect to distinguishing the various causes of failure.
576-
result.error(/* type */ "GetUserMediaFailed", "Failed to create new track", null);
580+
resultError("getUserMedia", "Failed to create new track.", result);
577581
return;
578582
}
579583

@@ -753,7 +757,7 @@ private void requestPermissions(
753757
void switchCamera(String id, Result result) {
754758
VideoCapturer videoCapturer = mVideoCapturers.get(id);
755759
if (videoCapturer == null) {
756-
result.error(null, "Video capturer not found for id: " + id, null);
760+
resultError("switchCamera", "Video capturer not found for id: " + id, result);
757761
return;
758762
}
759763

@@ -767,7 +771,7 @@ public void onCameraSwitchDone(boolean b) {
767771

768772
@Override
769773
public void onCameraSwitchError(String s) {
770-
result.error("Switching camera failed", s, null);
774+
resultError("switchCamera", "Switching camera failed: " + id, result);
771775
}
772776
});
773777
}
@@ -818,7 +822,7 @@ void stopRecording(Integer id) {
818822
void hasTorch(String trackId, Result result) {
819823
VideoCapturer videoCapturer = mVideoCapturers.get(trackId);
820824
if (videoCapturer == null) {
821-
result.error(null, "Video capturer not found for id: " + trackId, null);
825+
resultError("hasTorch", "Video capturer not found for id: " + trackId, result);
822826
return;
823827
}
824828

@@ -837,8 +841,7 @@ void hasTorch(String trackId, Result result) {
837841
(CameraDevice) getPrivateProperty(session.getClass(), session, "cameraDevice");
838842
} catch (NoSuchFieldWithNameException e) {
839843
// Most likely the upstream Camera2Capturer class have changed
840-
Log.e(TAG, "[TORCH] Failed to get `" + e.fieldName + "` from `" + e.className + "`");
841-
result.error(null, "Failed to get `" + e.fieldName + "` from `" + e.className + "`", null);
844+
resultError("hasTorch", "[TORCH] Failed to get `" + e.fieldName + "` from `" + e.className + "`", result);
842845
return;
843846
}
844847

@@ -866,8 +869,7 @@ void hasTorch(String trackId, Result result) {
866869
camera = (Camera) getPrivateProperty(session.getClass(), session, "camera");
867870
} catch (NoSuchFieldWithNameException e) {
868871
// Most likely the upstream Camera1Capturer class have changed
869-
Log.e(TAG, "[TORCH] Failed to get `" + e.fieldName + "` from `" + e.className + "`");
870-
result.error(null, "Failed to get `" + e.fieldName + "` from `" + e.className + "`", null);
872+
resultError("hasTorch", "[TORCH] Failed to get `" + e.fieldName + "` from `" + e.className + "`", result);
871873
return;
872874
}
873875

@@ -879,15 +881,14 @@ void hasTorch(String trackId, Result result) {
879881
return;
880882
}
881883

882-
Log.e(TAG, "[TORCH] Video capturer not compatible");
883-
result.error(null, "Video capturer not compatible", null);
884+
resultError("hasTorch", "[TORCH] Video capturer not compatible", result);
884885
}
885886

886887
@RequiresApi(api = VERSION_CODES.LOLLIPOP)
887888
void setTorch(String trackId, boolean torch, Result result) {
888889
VideoCapturer videoCapturer = mVideoCapturers.get(trackId);
889890
if (videoCapturer == null) {
890-
result.error(null, "Video capturer not found for id: " + trackId, null);
891+
resultError("setTorch", "Video capturer not found for id: " + trackId, result);
891892
return;
892893
}
893894

@@ -919,8 +920,7 @@ void setTorch(String trackId, boolean torch, Result result) {
919920
(Handler) getPrivateProperty(session.getClass(), session, "cameraThreadHandler");
920921
} catch (NoSuchFieldWithNameException e) {
921922
// Most likely the upstream Camera2Capturer class have changed
922-
Log.e(TAG, "[TORCH] Failed to get `" + e.fieldName + "` from `" + e.className + "`");
923-
result.error(null, "Failed to get `" + e.fieldName + "` from `" + e.className + "`", null);
923+
resultError("setTorch", "[TORCH] Failed to get `" + e.fieldName + "` from `" + e.className + "`", result);
924924
return;
925925
}
926926

@@ -959,8 +959,7 @@ void setTorch(String trackId, boolean torch, Result result) {
959959
camera = (Camera) getPrivateProperty(session.getClass(), session, "camera");
960960
} catch (NoSuchFieldWithNameException e) {
961961
// Most likely the upstream Camera1Capturer class have changed
962-
Log.e(TAG, "[TORCH] Failed to get `" + e.fieldName + "` from `" + e.className + "`");
963-
result.error(null, "Failed to get `" + e.fieldName + "` from `" + e.className + "`", null);
962+
resultError("setTorch", "[TORCH] Failed to get `" + e.fieldName + "` from `" + e.className + "`", result);
964963
return;
965964
}
966965

@@ -972,9 +971,7 @@ void setTorch(String trackId, boolean torch, Result result) {
972971
result.success(null);
973972
return;
974973
}
975-
976-
Log.e(TAG, "[TORCH] Video capturer not compatible");
977-
result.error(null, "Video capturer not compatible", null);
974+
resultError("setTorch", "[TORCH] Video capturer not compatible", result);
978975
}
979976

980977
private Object getPrivateProperty(Class klass, Object object, String fieldName)

0 commit comments

Comments
 (0)
0