Skip to content

Commit 1a1df11

Browse files
cloudwebrtchiroshihoriegraszka22
committed
Simulcast support for iOS/Android.
Simulcast support for iOS SDK (#4) Support for simulcast in Android SDK (#3) include simulcast headers for mac also (#10) Fix simulcast using hardware encoder on Android (#48) Add scalabilityMode support for AV1/VP9. (#90) Co-authored-by: Hiroshi Horie <[email protected]> Co-authored-by: Angelika Serwa <[email protected]>
1 parent 7454824 commit 1a1df11

37 files changed

+523
-41
lines changed

api/video_codecs/video_encoder_factory.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,8 @@ class VideoEncoderFactory {
8585
virtual CodecSupport QueryCodecSupport(
8686
const SdpVideoFormat& format,
8787
absl::optional<std::string> scalability_mode) const {
88-
// Default implementation, query for supported formats and check if the
89-
// specified format is supported. Returns false if scalability_mode is
90-
// specified.
9188
CodecSupport codec_support;
92-
if (!scalability_mode) {
93-
codec_support.is_supported = format.IsCodecInList(GetSupportedFormats());
94-
}
89+
codec_support.is_supported = format.IsCodecInList(GetSupportedFormats());
9590
return codec_support;
9691
}
9792

sdk/BUILD.gn

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,7 @@ if (is_ios || is_mac) {
723723
]
724724

725725
deps = [
726+
":simulcast",
726727
":base_objc",
727728
":native_video",
728729
":videocodec_objc",
@@ -822,6 +823,22 @@ if (is_ios || is_mac) {
822823
]
823824
}
824825

826+
rtc_library("simulcast") {
827+
sources = [
828+
"objc/components/video_codec/RTCVideoEncoderFactorySimulcast.h",
829+
"objc/components/video_codec/RTCVideoEncoderFactorySimulcast.mm",
830+
"objc/api/video_codec/RTCVideoEncoderSimulcast.h",
831+
"objc/api/video_codec/RTCVideoEncoderSimulcast.mm",
832+
]
833+
834+
deps = [
835+
":base_objc",
836+
":wrapped_native_codec_objc",
837+
"../media:rtc_media_base",
838+
"../media:rtc_simulcast_encoder_adapter",
839+
]
840+
}
841+
825842
rtc_library("mediaconstraints_objc") {
826843
configs += [ "..:no_global_constructors" ]
827844
sources = [
@@ -1368,6 +1385,9 @@ if (is_ios || is_mac) {
13681385
"objc/api/video_codec/RTCVideoEncoderAV1.h",
13691386
"objc/api/video_frame_buffer/RTCNativeI420Buffer.h",
13701387
"objc/api/video_frame_buffer/RTCNativeMutableI420Buffer.h",
1388+
# Added for Simulcast support
1389+
"objc/components/video_codec/RTCVideoEncoderFactorySimulcast.h",
1390+
"objc/api/video_codec/RTCVideoEncoderSimulcast.h",
13711391
]
13721392

13731393
if (!build_with_chromium) {
@@ -1518,6 +1538,9 @@ if (is_ios || is_mac) {
15181538
"objc/components/video_codec/RTCVideoEncoderH264.h",
15191539
"objc/components/video_frame_buffer/RTCCVPixelBuffer.h",
15201540
"objc/helpers/RTCDispatcher.h",
1541+
# Added for Simulcast support
1542+
"objc/components/video_codec/RTCVideoEncoderFactorySimulcast.h",
1543+
"objc/api/video_codec/RTCVideoEncoderSimulcast.h",
15211544
]
15221545
if (!build_with_chromium) {
15231546
sources += [

sdk/android/BUILD.gn

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,8 @@ if (is_android) {
530530
sources = [
531531
"api/org/webrtc/SoftwareVideoDecoderFactory.java",
532532
"api/org/webrtc/SoftwareVideoEncoderFactory.java",
533+
"api/org/webrtc/SimulcastVideoEncoder.java",
534+
"api/org/webrtc/SimulcastVideoEncoderFactory.java",
533535
]
534536

535537
deps = [
@@ -908,6 +910,21 @@ if (current_os == "linux" || is_android) {
908910
]
909911
}
910912

913+
rtc_library("simulcast_jni") {
914+
visibility = [ "*" ]
915+
allow_poison = [ "software_video_codecs" ]
916+
sources = [
917+
"src/jni/simulcast_video_encoder.cc",
918+
"src/jni/simulcast_video_encoder.h"
919+
]
920+
deps = [
921+
":base_jni",
922+
":video_jni",
923+
":native_api_codecs",
924+
"../../media:rtc_simulcast_encoder_adapter"
925+
]
926+
}
927+
911928
rtc_library("swcodecs_jni") {
912929
visibility = [ "*" ]
913930
allow_poison = [ "software_video_codecs" ]
@@ -921,6 +938,7 @@ if (current_os == "linux" || is_android) {
921938
":libvpx_vp8_jni",
922939
":libvpx_vp9_jni",
923940
":native_api_jni",
941+
":simulcast_jni",
924942
":video_jni",
925943
"../../api/environment",
926944
"../../api/video_codecs:builtin_video_decoder_factory",

sdk/android/api/org/webrtc/HardwareVideoEncoderFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ public VideoCodecInfo[] getSupportedCodecs() {
143143
// supported by the decoder.
144144
if (type == VideoCodecMimeType.H264 && isH264HighProfileSupported(codec)) {
145145
supportedCodecInfos.add(new VideoCodecInfo(
146-
name, MediaCodecUtils.getCodecProperties(type, /* highProfile= */ true)));
146+
name, MediaCodecUtils.getCodecProperties(type, /* highProfile= */ true), new ArrayList<>()));
147147
}
148148

149149
supportedCodecInfos.add(new VideoCodecInfo(
150-
name, MediaCodecUtils.getCodecProperties(type, /* highProfile= */ false)));
150+
name, MediaCodecUtils.getCodecProperties(type, /* highProfile= */ false), new ArrayList<>()));
151151
}
152152
}
153153

sdk/android/api/org/webrtc/LibaomAv1Encoder.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
package org.webrtc;
12+
import java.util.List;
1213

1314
public class LibaomAv1Encoder extends WrappedNativeVideoEncoder {
1415
@Override
@@ -22,4 +23,10 @@ public long createNative(long webrtcEnvRef) {
2223
public boolean isHardwareEncoder() {
2324
return false;
2425
}
26+
27+
static List<String> scalabilityModes() {
28+
return nativeGetSupportedScalabilityModes();
29+
}
30+
31+
static native List<String> nativeGetSupportedScalabilityModes();
2532
}

sdk/android/api/org/webrtc/LibvpxVp9Encoder.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
package org.webrtc;
12+
import java.util.List;
1213

1314
public class LibvpxVp9Encoder extends WrappedNativeVideoEncoder {
1415
@Override
@@ -24,4 +25,10 @@ public boolean isHardwareEncoder() {
2425
}
2526

2627
static native boolean nativeIsSupported();
28+
29+
static List<String> scalabilityModes() {
30+
return nativeGetSupportedScalabilityModes();
31+
}
32+
33+
static native List<String> nativeGetSupportedScalabilityModes();
2734
}

sdk/android/api/org/webrtc/RtpParameters.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ public static class Encoding {
7676
// If non-null, scale the width and height down by this factor for video. If null,
7777
// implementation default scaling factor will be used.
7878
@Nullable public Double scaleResolutionDownBy;
79+
// Scalability modes are used to represent simulcast and SVC layers.
80+
@Nullable public String scalabilityMode;
7981
// SSRC to be used by this encoding.
8082
// Can't be changed between getParameters/setParameters.
8183
public Long ssrc;
@@ -93,8 +95,8 @@ public Encoding(String rid, boolean active, Double scaleResolutionDownBy) {
9395
@CalledByNative("Encoding")
9496
Encoding(String rid, boolean active, double bitratePriority, @Priority int networkPriority,
9597
Integer maxBitrateBps, Integer minBitrateBps, Integer maxFramerate,
96-
Integer numTemporalLayers, Double scaleResolutionDownBy, Long ssrc,
97-
boolean adaptiveAudioPacketTime) {
98+
Integer numTemporalLayers, Double scaleResolutionDownBy, String scalabilityMode,
99+
Long ssrc, boolean adaptiveAudioPacketTime) {
98100
this.rid = rid;
99101
this.active = active;
100102
this.bitratePriority = bitratePriority;
@@ -104,6 +106,7 @@ public Encoding(String rid, boolean active, Double scaleResolutionDownBy) {
104106
this.maxFramerate = maxFramerate;
105107
this.numTemporalLayers = numTemporalLayers;
106108
this.scaleResolutionDownBy = scaleResolutionDownBy;
109+
this.scalabilityMode = scalabilityMode;
107110
this.ssrc = ssrc;
108111
this.adaptiveAudioPacketTime = adaptiveAudioPacketTime;
109112
}
@@ -160,6 +163,12 @@ Double getScaleResolutionDownBy() {
160163
return scaleResolutionDownBy;
161164
}
162165

166+
@Nullable
167+
@CalledByNative("Encoding")
168+
String getScalabilityMode() {
169+
return scalabilityMode;
170+
}
171+
163172
@CalledByNative("Encoding")
164173
Long getSsrc() {
165174
return ssrc;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.webrtc;
2+
3+
public class SimulcastVideoEncoder extends WrappedNativeVideoEncoder {
4+
5+
static native long nativeCreateEncoder(long webrtcEnvRef, VideoEncoderFactory primary, VideoEncoderFactory fallback, VideoCodecInfo info);
6+
7+
VideoEncoderFactory primary;
8+
VideoEncoderFactory fallback;
9+
VideoCodecInfo info;
10+
11+
public SimulcastVideoEncoder(VideoEncoderFactory primary, VideoEncoderFactory fallback, VideoCodecInfo info) {
12+
this.primary = primary;
13+
this.fallback = fallback;
14+
this.info = info;
15+
}
16+
17+
@Override
18+
public long createNative(long webrtcEnvRef) {
19+
return nativeCreateEncoder(primary, fallback, info);
20+
}
21+
22+
@Override
23+
public boolean isHardwareEncoder() {
24+
return false;
25+
}
26+
27+
}
28+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2017 The WebRTC project authors. All Rights Reserved.
3+
*
4+
* Use of this source code is governed by a BSD-style license
5+
* that can be found in the LICENSE file in the root of the source
6+
* tree. An additional intellectual property rights grant can be found
7+
* in the file PATENTS. All contributing project authors may
8+
* be found in the AUTHORS file in the root of the source tree.
9+
*/
10+
11+
package org.webrtc;
12+
13+
import androidx.annotation.Nullable;
14+
import java.util.ArrayList;
15+
import java.util.HashMap;
16+
import java.util.List;
17+
import java.util.Arrays;
18+
19+
public class SimulcastVideoEncoderFactory implements VideoEncoderFactory {
20+
21+
VideoEncoderFactory primary;
22+
VideoEncoderFactory fallback;
23+
24+
public SimulcastVideoEncoderFactory(VideoEncoderFactory primary, VideoEncoderFactory fallback) {
25+
this.primary = primary;
26+
this.fallback = fallback;
27+
}
28+
29+
@Nullable
30+
@Override
31+
public VideoEncoder createEncoder(VideoCodecInfo info) {
32+
return new SimulcastVideoEncoder(primary, fallback, info);
33+
}
34+
35+
@Override
36+
public VideoCodecInfo[] getSupportedCodecs() {
37+
List<VideoCodecInfo> codecs = new ArrayList<VideoCodecInfo>();
38+
codecs.addAll(Arrays.asList(primary.getSupportedCodecs()));
39+
codecs.addAll(Arrays.asList(fallback.getSupportedCodecs()));
40+
return codecs.toArray(new VideoCodecInfo[codecs.size()]);
41+
}
42+
43+
}

sdk/android/api/org/webrtc/VideoCodecInfo.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import java.util.Arrays;
1515
import java.util.Locale;
1616
import java.util.Map;
17+
import java.util.List;
18+
import java.util.ArrayList;
1719

1820
/**
1921
* Represent a video codec as encoded in SDP.
@@ -34,20 +36,24 @@ public class VideoCodecInfo {
3436

3537
public final String name;
3638
public final Map<String, String> params;
39+
public final List<String> scalabilityModes;
40+
3741
@Deprecated public final int payload;
3842

3943
@CalledByNative
40-
public VideoCodecInfo(String name, Map<String, String> params) {
44+
public VideoCodecInfo(String name, Map<String, String> params, List<String> scalabilityModes) {
4145
this.payload = 0;
4246
this.name = name;
4347
this.params = params;
48+
this.scalabilityModes = scalabilityModes;
4449
}
4550

4651
@Deprecated
4752
public VideoCodecInfo(int payload, String name, Map<String, String> params) {
4853
this.payload = payload;
4954
this.name = name;
5055
this.params = params;
56+
this.scalabilityModes = new ArrayList<>();
5157
}
5258

5359
@Override
@@ -83,4 +89,9 @@ String getName() {
8389
Map getParams() {
8490
return params;
8591
}
92+
93+
@CalledByNative
94+
List<String> getScalabilityModes() {
95+
return scalabilityModes;
96+
}
8697
}

0 commit comments

Comments
 (0)