Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: webrtc/api/java/jni/peerconnection_jni.cc

Issue 1917193008: Adding getParameters/setParameters APIs to RtpReceiver. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: objc compile errors Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | webrtc/api/java/src/org/webrtc/RtpReceiver.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2013 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 2013 matching lines...) Expand 10 before | Expand all | Expand 10 after
2024 JOW(jlong, RtpSender_nativeGetTrack)(JNIEnv* jni, 2024 JOW(jlong, RtpSender_nativeGetTrack)(JNIEnv* jni,
2025 jclass, 2025 jclass,
2026 jlong j_rtp_sender_pointer, 2026 jlong j_rtp_sender_pointer,
2027 jlong j_track_pointer) { 2027 jlong j_track_pointer) {
2028 return jlongFromPointer( 2028 return jlongFromPointer(
2029 reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer) 2029 reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)
2030 ->track() 2030 ->track()
2031 .release()); 2031 .release());
2032 } 2032 }
2033 2033
2034 static bool JavaEncodingToJsepRtpEncodingParameters( 2034 static void JavaRtpParametersToJsepRtpParameters(
2035 JNIEnv* jni, 2035 JNIEnv* jni,
2036 jobject j_encodings, 2036 jobject j_parameters,
2037 std::vector<webrtc::RtpEncodingParameters>* encodings) { 2037 webrtc::RtpParameters* parameters) {
2038 RTC_CHECK(parameters != nullptr);
2039 jclass parameters_class = jni->FindClass("org/webrtc/RtpParameters");
2040 jfieldID encodings_id =
2041 GetFieldID(jni, parameters_class, "encodings", "Ljava/util/LinkedList;");
2042 jfieldID codecs_id =
2043 GetFieldID(jni, parameters_class, "codecs", "Ljava/util/LinkedList;");
2044
2045 // Convert encodings.
2046 jobject j_encodings = GetObjectField(jni, j_parameters, encodings_id);
2038 const int kBitrateUnlimited = -1; 2047 const int kBitrateUnlimited = -1;
2039 jclass j_encoding_parameters_class = 2048 jclass j_encoding_parameters_class =
2040 jni->FindClass("org/webrtc/RtpParameters$Encoding"); 2049 jni->FindClass("org/webrtc/RtpParameters$Encoding");
2041 jfieldID active_id = 2050 jfieldID active_id =
2042 GetFieldID(jni, j_encoding_parameters_class, "active", "Z"); 2051 GetFieldID(jni, j_encoding_parameters_class, "active", "Z");
2043 jfieldID bitrate_id = GetFieldID(jni, j_encoding_parameters_class, 2052 jfieldID bitrate_id = GetFieldID(jni, j_encoding_parameters_class,
2044 "maxBitrateBps", "Ljava/lang/Integer;"); 2053 "maxBitrateBps", "Ljava/lang/Integer;");
2045 jclass j_integer_class = jni->FindClass("java/lang/Integer"); 2054 jclass j_integer_class = jni->FindClass("java/lang/Integer");
2046 jmethodID int_value_id = GetMethodID(jni, j_integer_class, "intValue", "()I"); 2055 jmethodID int_value_id = GetMethodID(jni, j_integer_class, "intValue", "()I");
2047 2056
2048 for (jobject j_encoding_parameters : Iterable(jni, j_encodings)) { 2057 for (jobject j_encoding_parameters : Iterable(jni, j_encodings)) {
2049 webrtc::RtpEncodingParameters encoding; 2058 webrtc::RtpEncodingParameters encoding;
2050 encoding.active = GetBooleanField(jni, j_encoding_parameters, active_id); 2059 encoding.active = GetBooleanField(jni, j_encoding_parameters, active_id);
2051 jobject j_bitrate = 2060 jobject j_bitrate =
2052 GetNullableObjectField(jni, j_encoding_parameters, bitrate_id); 2061 GetNullableObjectField(jni, j_encoding_parameters, bitrate_id);
2053 if (!IsNull(jni, j_bitrate)) { 2062 if (!IsNull(jni, j_bitrate)) {
2054 int bitrate_value = jni->CallIntMethod(j_bitrate, int_value_id); 2063 int bitrate_value = jni->CallIntMethod(j_bitrate, int_value_id);
2055 CHECK_EXCEPTION(jni) << "error during CallIntMethod"; 2064 CHECK_EXCEPTION(jni) << "error during CallIntMethod";
2056 encoding.max_bitrate_bps = bitrate_value; 2065 encoding.max_bitrate_bps = bitrate_value;
2057 } else { 2066 } else {
2058 encoding.max_bitrate_bps = kBitrateUnlimited; 2067 encoding.max_bitrate_bps = kBitrateUnlimited;
2059 } 2068 }
2060 encodings->push_back(encoding); 2069 parameters->encodings.push_back(encoding);
2061 } 2070 }
2062 return true;
2063 }
2064 2071
2065 static bool JavaCodecToJsepRtpCodecParameters( 2072 // Convert codecs.
2066 JNIEnv* jni, 2073 jobject j_codecs = GetObjectField(jni, j_parameters, codecs_id);
2067 jobject j_codecs,
2068 std::vector<webrtc::RtpCodecParameters>* codecs) {
2069 jclass codec_class = jni->FindClass("org/webrtc/RtpParameters$Codec"); 2074 jclass codec_class = jni->FindClass("org/webrtc/RtpParameters$Codec");
2070 jfieldID payload_type_id = GetFieldID(jni, codec_class, "payloadType", "I"); 2075 jfieldID payload_type_id = GetFieldID(jni, codec_class, "payloadType", "I");
2071 jfieldID mime_type_id = 2076 jfieldID mime_type_id =
2072 GetFieldID(jni, codec_class, "mimeType", "Ljava/lang/String;"); 2077 GetFieldID(jni, codec_class, "mimeType", "Ljava/lang/String;");
2073 jfieldID clock_rate_id = GetFieldID(jni, codec_class, "clockRate", "I"); 2078 jfieldID clock_rate_id = GetFieldID(jni, codec_class, "clockRate", "I");
2074 jfieldID channels_id = GetFieldID(jni, codec_class, "channels", "I"); 2079 jfieldID channels_id = GetFieldID(jni, codec_class, "channels", "I");
2075 2080
2076 for (jobject j_codec : Iterable(jni, j_codecs)) { 2081 for (jobject j_codec : Iterable(jni, j_codecs)) {
2077 webrtc::RtpCodecParameters codec; 2082 webrtc::RtpCodecParameters codec;
2078 codec.payload_type = GetIntField(jni, j_codec, payload_type_id); 2083 codec.payload_type = GetIntField(jni, j_codec, payload_type_id);
2079 codec.mime_type = 2084 codec.mime_type =
2080 JavaToStdString(jni, GetStringField(jni, j_codec, mime_type_id)); 2085 JavaToStdString(jni, GetStringField(jni, j_codec, mime_type_id));
2081 codec.clock_rate = GetIntField(jni, j_codec, clock_rate_id); 2086 codec.clock_rate = GetIntField(jni, j_codec, clock_rate_id);
2082 codec.channels = GetIntField(jni, j_codec, channels_id); 2087 codec.channels = GetIntField(jni, j_codec, channels_id);
2083 codecs->push_back(codec); 2088 parameters->codecs.push_back(codec);
2084 } 2089 }
2085 return true;
2086 } 2090 }
2087 2091
2088 JOW(jboolean, RtpSender_nativeSetParameters) 2092 static jobject JsepRtpParametersToJavaRtpParameters(
2089 (JNIEnv* jni, jclass, jlong j_rtp_sender_pointer, jobject j_parameters) { 2093 JNIEnv* jni,
2090 if (IsNull(jni, j_parameters)) { 2094 const webrtc::RtpParameters& parameters) {
2091 return false;
2092 }
2093 jclass parameters_class = jni->FindClass("org/webrtc/RtpParameters");
2094 jclass encoding_class = jni->FindClass("org/webrtc/RtpParameters$Encoding");
2095 jfieldID encodings_id =
2096 GetFieldID(jni, parameters_class, "encodings", "Ljava/util/LinkedList;");
2097 jfieldID codecs_id =
2098 GetFieldID(jni, parameters_class, "codecs", "Ljava/util/LinkedList;");
2099
2100 jobject j_encodings = GetObjectField(jni, j_parameters, encodings_id);
2101 jobject j_codecs = GetObjectField(jni, j_parameters, codecs_id);
2102 webrtc::RtpParameters parameters;
2103 JavaEncodingToJsepRtpEncodingParameters(jni, j_encodings,
2104 &parameters.encodings);
2105 JavaCodecToJsepRtpCodecParameters(jni, j_codecs, &parameters.codecs);
2106 return reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)
2107 ->SetParameters(parameters);
2108 }
2109
2110 JOW(jobject, RtpSender_nativeGetParameters)
2111 (JNIEnv* jni, jclass, jlong j_rtp_sender_pointer) {
2112 webrtc::RtpParameters parameters =
2113 reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)
2114 ->GetParameters();
2115
2116 jclass parameters_class = jni->FindClass("org/webrtc/RtpParameters"); 2095 jclass parameters_class = jni->FindClass("org/webrtc/RtpParameters");
2117 jmethodID parameters_ctor = 2096 jmethodID parameters_ctor =
2118 GetMethodID(jni, parameters_class, "<init>", "()V"); 2097 GetMethodID(jni, parameters_class, "<init>", "()V");
2119 jobject j_parameters = jni->NewObject(parameters_class, parameters_ctor); 2098 jobject j_parameters = jni->NewObject(parameters_class, parameters_ctor);
2120 CHECK_EXCEPTION(jni) << "error during NewObject"; 2099 CHECK_EXCEPTION(jni) << "error during NewObject";
2121 2100
2101 // Add encodings.
2122 jclass encoding_class = jni->FindClass("org/webrtc/RtpParameters$Encoding"); 2102 jclass encoding_class = jni->FindClass("org/webrtc/RtpParameters$Encoding");
2123 jmethodID encoding_ctor = GetMethodID(jni, encoding_class, "<init>", "()V"); 2103 jmethodID encoding_ctor = GetMethodID(jni, encoding_class, "<init>", "()V");
2124 jfieldID encodings_id = 2104 jfieldID encodings_id =
2125 GetFieldID(jni, parameters_class, "encodings", "Ljava/util/LinkedList;"); 2105 GetFieldID(jni, parameters_class, "encodings", "Ljava/util/LinkedList;");
2126 jobject j_encodings = GetObjectField(jni, j_parameters, encodings_id); 2106 jobject j_encodings = GetObjectField(jni, j_parameters, encodings_id);
2127 jmethodID encodings_add = GetMethodID(jni, GetObjectClass(jni, j_encodings), 2107 jmethodID encodings_add = GetMethodID(jni, GetObjectClass(jni, j_encodings),
2128 "add", "(Ljava/lang/Object;)Z"); 2108 "add", "(Ljava/lang/Object;)Z");
2129 jfieldID active_id = 2109 jfieldID active_id =
2130 GetFieldID(jni, encoding_class, "active", "Z"); 2110 GetFieldID(jni, encoding_class, "active", "Z");
2131 jfieldID bitrate_id = 2111 jfieldID bitrate_id =
(...skipping 14 matching lines...) Expand all
2146 CHECK_EXCEPTION(jni) << "error during NewObject"; 2126 CHECK_EXCEPTION(jni) << "error during NewObject";
2147 jni->SetObjectField(j_encoding_parameters, bitrate_id, j_bitrate_value); 2127 jni->SetObjectField(j_encoding_parameters, bitrate_id, j_bitrate_value);
2148 CHECK_EXCEPTION(jni) << "error during SetObjectField"; 2128 CHECK_EXCEPTION(jni) << "error during SetObjectField";
2149 } 2129 }
2150 jboolean added = jni->CallBooleanMethod(j_encodings, encodings_add, 2130 jboolean added = jni->CallBooleanMethod(j_encodings, encodings_add,
2151 j_encoding_parameters); 2131 j_encoding_parameters);
2152 CHECK_EXCEPTION(jni) << "error during CallBooleanMethod"; 2132 CHECK_EXCEPTION(jni) << "error during CallBooleanMethod";
2153 RTC_CHECK(added); 2133 RTC_CHECK(added);
2154 } 2134 }
2155 2135
2136 // Add codecs.
2156 jclass codec_class = jni->FindClass("org/webrtc/RtpParameters$Codec"); 2137 jclass codec_class = jni->FindClass("org/webrtc/RtpParameters$Codec");
2157 jmethodID codec_ctor = GetMethodID(jni, codec_class, "<init>", "()V"); 2138 jmethodID codec_ctor = GetMethodID(jni, codec_class, "<init>", "()V");
2158 jfieldID codecs_id = 2139 jfieldID codecs_id =
2159 GetFieldID(jni, parameters_class, "codecs", "Ljava/util/LinkedList;"); 2140 GetFieldID(jni, parameters_class, "codecs", "Ljava/util/LinkedList;");
2160 jobject j_codecs = GetObjectField(jni, j_parameters, codecs_id); 2141 jobject j_codecs = GetObjectField(jni, j_parameters, codecs_id);
2161 jmethodID codecs_add = GetMethodID(jni, GetObjectClass(jni, j_codecs), 2142 jmethodID codecs_add = GetMethodID(jni, GetObjectClass(jni, j_codecs),
2162 "add", "(Ljava/lang/Object;)Z"); 2143 "add", "(Ljava/lang/Object;)Z");
2163 jfieldID payload_type_id = GetFieldID(jni, codec_class, "payloadType", "I"); 2144 jfieldID payload_type_id = GetFieldID(jni, codec_class, "payloadType", "I");
2164 jfieldID mime_type_id = 2145 jfieldID mime_type_id =
2165 GetFieldID(jni, codec_class, "mimeType", "Ljava/lang/String;"); 2146 GetFieldID(jni, codec_class, "mimeType", "Ljava/lang/String;");
(...skipping 13 matching lines...) Expand all
2179 jni->SetIntField(j_codec, channels_id, codec.channels); 2160 jni->SetIntField(j_codec, channels_id, codec.channels);
2180 CHECK_EXCEPTION(jni) << "error during SetIntField"; 2161 CHECK_EXCEPTION(jni) << "error during SetIntField";
2181 jboolean added = jni->CallBooleanMethod(j_codecs, codecs_add, j_codec); 2162 jboolean added = jni->CallBooleanMethod(j_codecs, codecs_add, j_codec);
2182 CHECK_EXCEPTION(jni) << "error during CallBooleanMethod"; 2163 CHECK_EXCEPTION(jni) << "error during CallBooleanMethod";
2183 RTC_CHECK(added); 2164 RTC_CHECK(added);
2184 } 2165 }
2185 2166
2186 return j_parameters; 2167 return j_parameters;
2187 } 2168 }
2188 2169
2170 JOW(jboolean, RtpSender_nativeSetParameters)
2171 (JNIEnv* jni, jclass, jlong j_rtp_sender_pointer, jobject j_parameters) {
2172 if (IsNull(jni, j_parameters)) {
2173 return false;
2174 }
2175 webrtc::RtpParameters parameters;
2176 JavaRtpParametersToJsepRtpParameters(jni, j_parameters, &parameters);
2177 return reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)
2178 ->SetParameters(parameters);
2179 }
2180
2181 JOW(jobject, RtpSender_nativeGetParameters)
2182 (JNIEnv* jni, jclass, jlong j_rtp_sender_pointer) {
2183 webrtc::RtpParameters parameters =
2184 reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)
2185 ->GetParameters();
2186 return JsepRtpParametersToJavaRtpParameters(jni, parameters);
2187 }
2188
2189 JOW(jstring, RtpSender_nativeId)( 2189 JOW(jstring, RtpSender_nativeId)(
2190 JNIEnv* jni, jclass, jlong j_rtp_sender_pointer) { 2190 JNIEnv* jni, jclass, jlong j_rtp_sender_pointer) {
2191 return JavaStringFromStdString( 2191 return JavaStringFromStdString(
2192 jni, reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)->id()); 2192 jni, reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)->id());
2193 } 2193 }
2194 2194
2195 JOW(void, RtpSender_free)(JNIEnv* jni, jclass, jlong j_rtp_sender_pointer) { 2195 JOW(void, RtpSender_free)(JNIEnv* jni, jclass, jlong j_rtp_sender_pointer) {
2196 reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)->Release(); 2196 reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)->Release();
2197 } 2197 }
2198 2198
2199 JOW(jlong, RtpReceiver_nativeGetTrack)(JNIEnv* jni, 2199 JOW(jlong, RtpReceiver_nativeGetTrack)(JNIEnv* jni,
2200 jclass, 2200 jclass,
2201 jlong j_rtp_receiver_pointer, 2201 jlong j_rtp_receiver_pointer,
2202 jlong j_track_pointer) { 2202 jlong j_track_pointer) {
2203 return jlongFromPointer( 2203 return jlongFromPointer(
2204 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer) 2204 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)
2205 ->track() 2205 ->track()
2206 .release()); 2206 .release());
2207 } 2207 }
2208 2208
2209 JOW(jboolean, RtpReceiver_nativeSetParameters)
2210 (JNIEnv* jni, jclass, jlong j_rtp_sender_pointer, jobject j_parameters) {
2211 if (IsNull(jni, j_parameters)) {
2212 return false;
2213 }
2214 webrtc::RtpParameters parameters;
2215 JavaRtpParametersToJsepRtpParameters(jni, j_parameters, &parameters);
2216 return reinterpret_cast<RtpReceiverInterface*>(j_rtp_sender_pointer)
2217 ->SetParameters(parameters);
2218 }
2219
2220 JOW(jobject, RtpReceiver_nativeGetParameters)
2221 (JNIEnv* jni, jclass, jlong j_rtp_sender_pointer) {
2222 webrtc::RtpParameters parameters =
2223 reinterpret_cast<RtpReceiverInterface*>(j_rtp_sender_pointer)
2224 ->GetParameters();
2225 return JsepRtpParametersToJavaRtpParameters(jni, parameters);
2226 }
2227
2209 JOW(jstring, RtpReceiver_nativeId)( 2228 JOW(jstring, RtpReceiver_nativeId)(
2210 JNIEnv* jni, jclass, jlong j_rtp_receiver_pointer) { 2229 JNIEnv* jni, jclass, jlong j_rtp_receiver_pointer) {
2211 return JavaStringFromStdString( 2230 return JavaStringFromStdString(
2212 jni, 2231 jni,
2213 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->id()); 2232 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->id());
2214 } 2233 }
2215 2234
2216 JOW(void, RtpReceiver_free)(JNIEnv* jni, jclass, jlong j_rtp_receiver_pointer) { 2235 JOW(void, RtpReceiver_free)(JNIEnv* jni, jclass, jlong j_rtp_receiver_pointer) {
2217 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->Release(); 2236 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->Release();
2218 } 2237 }
2219 2238
2220 } // namespace webrtc_jni 2239 } // namespace webrtc_jni
OLDNEW
« no previous file with comments | « no previous file | webrtc/api/java/src/org/webrtc/RtpReceiver.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698