-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Expose setCodecPreferences/getCapabilities for android. (#61)
* feat: Expose setCodecPreferences/getCapabilities. * chore: update license. * fix bugs.
- Loading branch information
1 parent
ba30ae7
commit 0ee1073
Showing
8 changed files
with
342 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* | ||
* Copyright 2023 LiveKit | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.webrtc; | ||
|
||
import androidx.annotation.Nullable; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.webrtc.MediaStreamTrack; | ||
|
||
public class RtpCapabilities { | ||
public static class CodecCapability { | ||
public int preferredPayloadType; | ||
// Name used to identify the codec. Equivalent to MIME subtype. | ||
public String name; | ||
// The media type of this codec. Equivalent to MIME top-level type. | ||
public MediaStreamTrack.MediaType kind; | ||
// Clock rate in Hertz. | ||
public Integer clockRate; | ||
// The number of audio channels used. Set to null for video codecs. | ||
public Integer numChannels; | ||
// The "format specific parameters" field from the "a=fmtp" line in the SDP | ||
public Map<String, String> parameters; | ||
// The MIME type of the codec. This is a convenience field. | ||
public String mimeType; | ||
|
||
public CodecCapability() {} | ||
|
||
@CalledByNative("CodecCapability") | ||
CodecCapability(int preferredPayloadType, String name, MediaStreamTrack.MediaType kind, | ||
Integer clockRate, Integer numChannels, String mimeType, Map<String, String> parameters) { | ||
this.preferredPayloadType = preferredPayloadType; | ||
this.name = name; | ||
this.kind = kind; | ||
this.clockRate = clockRate; | ||
this.numChannels = numChannels; | ||
this.parameters = parameters; | ||
this.mimeType = mimeType; | ||
} | ||
|
||
@CalledByNative("CodecCapability") | ||
int getPreferredPayloadType() { | ||
return preferredPayloadType; | ||
} | ||
|
||
@CalledByNative("CodecCapability") | ||
String getName() { | ||
return name; | ||
} | ||
|
||
@CalledByNative("CodecCapability") | ||
MediaStreamTrack.MediaType getKind() { | ||
return kind; | ||
} | ||
|
||
@CalledByNative("CodecCapability") | ||
Integer getClockRate() { | ||
return clockRate; | ||
} | ||
|
||
@CalledByNative("CodecCapability") | ||
Integer getNumChannels() { | ||
return numChannels; | ||
} | ||
|
||
@CalledByNative("CodecCapability") | ||
Map getParameters() { | ||
return parameters; | ||
} | ||
} | ||
|
||
public static class HeaderExtensionCapability { | ||
private final String uri; | ||
private final int preferredId; | ||
private final boolean preferredEncrypted; | ||
|
||
@CalledByNative("HeaderExtensionCapability") | ||
HeaderExtensionCapability(String uri, int preferredId, boolean preferredEncrypted) { | ||
this.uri = uri; | ||
this.preferredId = preferredId; | ||
this.preferredEncrypted = preferredEncrypted; | ||
} | ||
|
||
@CalledByNative("HeaderExtensionCapability") | ||
public String getUri() { | ||
return uri; | ||
} | ||
|
||
@CalledByNative("HeaderExtensionCapability") | ||
public int getPreferredId() { | ||
return preferredId; | ||
} | ||
|
||
@CalledByNative("HeaderExtensionCapability") | ||
public boolean getPreferredEncrypted() { | ||
return preferredEncrypted; | ||
} | ||
} | ||
|
||
public List<CodecCapability> codecs; | ||
public List<HeaderExtensionCapability> headerExtensions; | ||
|
||
@CalledByNative | ||
RtpCapabilities(List<CodecCapability> codecs, List<HeaderExtensionCapability> headerExtensions) { | ||
this.headerExtensions = headerExtensions; | ||
this.codecs = codecs; | ||
} | ||
|
||
@CalledByNative | ||
public List<HeaderExtensionCapability> getHeaderExtensions() { | ||
return headerExtensions; | ||
} | ||
|
||
@CalledByNative | ||
List<CodecCapability> getCodecs() { | ||
return codecs; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* Copyright 2023 LiveKit | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "sdk/android/src/jni/pc/rtp_capabilities.h" | ||
|
||
#include "sdk/android/generated_peerconnection_jni/RtpCapabilities_jni.h" | ||
#include "sdk/android/native_api/jni/java_types.h" | ||
#include "sdk/android/src/jni/jni_helpers.h" | ||
#include "sdk/android/src/jni/pc/media_stream_track.h" | ||
|
||
namespace webrtc { | ||
namespace jni { | ||
|
||
namespace { | ||
|
||
ScopedJavaLocalRef<jobject> NativeToJavaRtpCodecParameter( | ||
JNIEnv* env, | ||
const RtpCodecCapability& codec) { | ||
return Java_CodecCapability_Constructor(env, codec.preferred_payload_type.value(), | ||
NativeToJavaString(env, codec.name), | ||
NativeToJavaMediaType(env, codec.kind), | ||
NativeToJavaInteger(env, codec.clock_rate), | ||
NativeToJavaInteger(env, codec.num_channels), | ||
NativeToJavaString(env, codec.mime_type()), | ||
NativeToJavaStringMap(env, codec.parameters)); | ||
} | ||
|
||
ScopedJavaLocalRef<jobject> NativeToJavaRtpHeaderExtensionParameter( | ||
JNIEnv* env, | ||
const RtpHeaderExtensionCapability& extension) { | ||
return Java_HeaderExtensionCapability_Constructor( | ||
env, NativeToJavaString(env, extension.uri), extension.preferred_id.value(), | ||
extension.preferred_encrypt); | ||
} | ||
} // namespace | ||
|
||
RtpCapabilities JavaToNativeRtpCapabilities(JNIEnv* jni, | ||
const JavaRef<jobject>& j_capabilities) { | ||
RtpCapabilities capabilities; | ||
|
||
ScopedJavaLocalRef<jobject> j_header_extensions = | ||
Java_RtpCapabilities_getHeaderExtensions(jni, j_capabilities); | ||
for (const JavaRef<jobject>& j_header_extension : | ||
Iterable(jni, j_header_extensions)) { | ||
RtpHeaderExtensionCapability header_extension; | ||
header_extension.uri = JavaToStdString( | ||
jni, Java_HeaderExtensionCapability_getUri(jni, j_header_extension)); | ||
header_extension.preferred_id = Java_HeaderExtensionCapability_getPreferredId(jni, j_header_extension); | ||
header_extension.preferred_encrypt = | ||
Java_HeaderExtensionCapability_getPreferredEncrypted(jni, j_header_extension); | ||
capabilities.header_extensions.push_back(header_extension); | ||
} | ||
|
||
// Convert codecs. | ||
ScopedJavaLocalRef<jobject> j_codecs = | ||
Java_RtpCapabilities_getCodecs(jni, j_capabilities); | ||
for (const JavaRef<jobject>& j_codec : Iterable(jni, j_codecs)) { | ||
RtpCodecCapability codec; | ||
codec.preferred_payload_type = Java_CodecCapability_getPreferredPayloadType(jni, j_codec); | ||
codec.name = JavaToStdString(jni, Java_CodecCapability_getName(jni, j_codec)); | ||
codec.kind = JavaToNativeMediaType(jni, Java_CodecCapability_getKind(jni, j_codec)); | ||
codec.clock_rate = | ||
JavaToNativeOptionalInt(jni, Java_CodecCapability_getClockRate(jni, j_codec)); | ||
codec.num_channels = | ||
JavaToNativeOptionalInt(jni, Java_CodecCapability_getNumChannels(jni, j_codec)); | ||
auto parameters_map = | ||
JavaToNativeStringMap(jni, Java_CodecCapability_getParameters(jni, j_codec)); | ||
codec.parameters.insert(parameters_map.begin(), parameters_map.end()); | ||
capabilities.codecs.push_back(codec); | ||
} | ||
return capabilities; | ||
} | ||
|
||
ScopedJavaLocalRef<jobject> NativeToJavaRtpCapabilities( | ||
JNIEnv* env, | ||
const RtpCapabilities& capabilities) { | ||
return Java_RtpCapabilities_Constructor( | ||
env, NativeToJavaList(env, capabilities.codecs, &NativeToJavaRtpCodecParameter), | ||
NativeToJavaList(env, capabilities.header_extensions, | ||
&NativeToJavaRtpHeaderExtensionParameter) | ||
); | ||
} | ||
|
||
RtpCodecCapability JavaToNativeRtpCodecCapability(JNIEnv* jni, | ||
const JavaRef<jobject>& j_codec) { | ||
RtpCodecCapability codec; | ||
codec.preferred_payload_type = Java_CodecCapability_getPreferredPayloadType(jni, j_codec); | ||
codec.name = JavaToStdString(jni, Java_CodecCapability_getName(jni, j_codec)); | ||
codec.kind = JavaToNativeMediaType(jni, Java_CodecCapability_getKind(jni, j_codec)); | ||
codec.clock_rate = | ||
JavaToNativeOptionalInt(jni, Java_CodecCapability_getClockRate(jni, j_codec)); | ||
codec.num_channels = | ||
JavaToNativeOptionalInt(jni, Java_CodecCapability_getNumChannels(jni, j_codec)); | ||
auto parameters_map = | ||
JavaToNativeStringMap(jni, Java_CodecCapability_getParameters(jni, j_codec)); | ||
codec.parameters.insert(parameters_map.begin(), parameters_map.end()); | ||
return codec; | ||
} | ||
|
||
} // namespace jni | ||
} // namespace webrtc |
Oops, something went wrong.