Skip to content

Commit 7159977

Browse files
committed
Add scalabilityMode support for AV1/VP9. (#90)
* add scalabilityMode for AV1. * fix bug for scalability-mode. * add scalability-mode support for VP9. * wip: ScalabilityModes for android. * update. * wip. * wip. * wip. * wip. * done. * fix * update.
1 parent 87977ca commit 7159977

25 files changed

+188
-28
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/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 createNativeVideoEncoder() {
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;

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
}

sdk/android/instrumentationtests/src/org/webrtc/AndroidVideoDecoderInstrumentationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public AndroidVideoDecoderInstrumentationTest(String codecName, boolean useEglCo
4848
if (codecName.equals("H264")) {
4949
this.codecType = H264Utils.DEFAULT_H264_BASELINE_PROFILE_CODEC;
5050
} else {
51-
this.codecType = new VideoCodecInfo(codecName, new HashMap<>());
51+
this.codecType = new VideoCodecInfo(codecName, new HashMap<>(), new ArrayList<>());
5252
}
5353
this.useEglContext = useEglContext;
5454
}

sdk/android/instrumentationtests/src/org/webrtc/DefaultVideoEncoderFactoryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void setUp() {
4747
@SmallTest
4848
@Test
4949
public void getSupportedCodecs_hwVp8SameParamsAsSwVp8_oneVp8() {
50-
VideoCodecInfo hwVp8Encoder = new VideoCodecInfo("VP8", new HashMap<>());
50+
VideoCodecInfo hwVp8Encoder = new VideoCodecInfo("VP8", new HashMap<>(), new ArrayList<>());
5151
VideoEncoderFactory hwFactory = new CustomHardwareVideoEncoderFactory(hwVp8Encoder);
5252
DefaultVideoEncoderFactory defFactory = new DefaultVideoEncoderFactory(hwFactory);
5353
VideoCodecInfo[] supportedCodecs = defFactory.getSupportedCodecs();
@@ -62,7 +62,7 @@ public void getSupportedCodecs_hwVp8SameParamsAsSwVp8_oneVp8() {
6262
public void getSupportedCodecs_hwVp8WithDifferentParams_twoVp8() {
6363
VideoCodecInfo hwVp8Encoder = new VideoCodecInfo("VP8", new HashMap<String, String>() {
6464
{ put("param", "value"); }
65-
});
65+
}, new ArrayList<>());
6666
VideoEncoderFactory hwFactory = new CustomHardwareVideoEncoderFactory(hwVp8Encoder);
6767
DefaultVideoEncoderFactory defFactory = new DefaultVideoEncoderFactory(hwFactory);
6868
VideoCodecInfo[] supportedCodecs = defFactory.getSupportedCodecs();

sdk/android/instrumentationtests/src/org/webrtc/SoftwareVideoDecoderFactoryTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import androidx.annotation.Nullable;
1616
import androidx.test.filters.SmallTest;
17+
import java.util.ArrayList;
1718
import java.util.HashMap;
1819
import org.junit.Before;
1920
import org.junit.Test;
@@ -55,7 +56,7 @@ public void createDecoder_supportedCodec_returnsNotNull() {
5556
@Test
5657
public void createDecoder_unsupportedCodec_returnsNull() {
5758
VideoDecoderFactory factory = new SoftwareVideoDecoderFactory();
58-
VideoCodecInfo codec = new VideoCodecInfo("unsupported", new HashMap<String, String>());
59+
VideoCodecInfo codec = new VideoCodecInfo("unsupported", new HashMap<String, String>(), new ArrayList<>());
5960
VideoDecoder decoder = factory.createDecoder(codec);
6061
assertThat(decoder).isNull();
6162
}

sdk/android/instrumentationtests/src/org/webrtc/SoftwareVideoEncoderFactoryTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import androidx.annotation.Nullable;
1616
import androidx.test.filters.SmallTest;
17+
import java.util.ArrayList;
1718
import java.util.HashMap;
1819
import org.junit.Before;
1920
import org.junit.Test;
@@ -52,7 +53,7 @@ public void createEncoder_supportedCodec_returnsNotNull() {
5253
@Test
5354
public void createEncoder_unsupportedCodec_returnsNull() {
5455
VideoEncoderFactory factory = new SoftwareVideoEncoderFactory();
55-
VideoCodecInfo codec = new VideoCodecInfo("unsupported", new HashMap<String, String>());
56+
VideoCodecInfo codec = new VideoCodecInfo("unsupported", new HashMap<String, String>(), new ArrayList<>());
5657
VideoEncoder encoder = factory.createEncoder(codec);
5758
assertThat(encoder).isNull();
5859
}

0 commit comments

Comments
 (0)