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

Side by Side Diff: webrtc/api/java/jni/jni_helpers.h

Issue 1819553002: Added the JNI interface to get and set RtpParameters and the maximum bitrate limits. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Code review feedback Created 4 years, 9 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
OLDNEW
1 /* 1 /*
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2015 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
11 // This file contain convenience functions and classes for JNI. 11 // This file contain convenience functions and classes for JNI.
12 // Before using any of the methods, InitGlobalJniVariables must be called. 12 // Before using any of the methods, InitGlobalJniVariables must be called.
13 13
14 #ifndef WEBRTC_API_JAVA_JNI_JNI_HELPERS_H_ 14 #ifndef WEBRTC_API_JAVA_JNI_JNI_HELPERS_H_
15 #define WEBRTC_API_JAVA_JNI_JNI_HELPERS_H_ 15 #define WEBRTC_API_JAVA_JNI_JNI_HELPERS_H_
16 16
17 #include <jni.h> 17 #include <jni.h>
18 #include <string> 18 #include <string>
19 19
20 #include "webrtc/base/constructormagic.h"
20 #include "webrtc/base/checks.h" 21 #include "webrtc/base/checks.h"
22 #include "webrtc/base/thread_checker.h"
21 23
22 // Abort the process if |jni| has a Java exception pending. 24 // Abort the process if |jni| has a Java exception pending.
23 // This macros uses the comma operator to execute ExceptionDescribe 25 // This macros uses the comma operator to execute ExceptionDescribe
24 // and ExceptionClear ignoring their return values and sending "" 26 // and ExceptionClear ignoring their return values and sending ""
25 // to the error stream. 27 // to the error stream.
26 #define CHECK_EXCEPTION(jni) \ 28 #define CHECK_EXCEPTION(jni) \
27 RTC_CHECK(!jni->ExceptionCheck()) \ 29 RTC_CHECK(!jni->ExceptionCheck()) \
28 << (jni->ExceptionDescribe(), jni->ExceptionClear(), "") 30 << (jni->ExceptionDescribe(), jni->ExceptionClear(), "")
29 31
30 // Helper that calls ptr->Release() and aborts the process with a useful 32 // Helper that calls ptr->Release() and aborts the process with a useful
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 ~ScopedGlobalRef() { 117 ~ScopedGlobalRef() {
116 DeleteGlobalRef(AttachCurrentThreadIfNeeded(), obj_); 118 DeleteGlobalRef(AttachCurrentThreadIfNeeded(), obj_);
117 } 119 }
118 T operator*() const { 120 T operator*() const {
119 return obj_; 121 return obj_;
120 } 122 }
121 private: 123 private:
122 T obj_; 124 T obj_;
123 }; 125 };
124 126
127 // Provides a convenient way to iterate over a Java Iterable using the
128 // C++ range-for loop.
129 // E.g. for (jobject value : Iterable(jni, j_iterable)) { ... }
130 // Note: Since Java iterators cannot be duplicated, the iterator class is not
131 // copyable to prevent creating multiple C++ iterators that refer to the same
132 // Java iterator.
133 class Iterable {
134 public:
135 Iterable(JNIEnv* jni, jobject iterable) : jni_(jni), iterable_(iterable) {}
136
137 class Iterator {
138 public:
139 // Creates an iterator representing the end of any collection.
140 Iterator();
141 // Creates an iterator pointing to the beginning of the specified
142 // collection.
143 Iterator(JNIEnv* jni, jobject iterable);
144
145 // Move constructor - necessary to be able to return iterator types from
146 // functions.
147 Iterator(Iterator&& other);
148
149 // Move assignment should not be used.
150 Iterator& operator=(Iterator&&) = delete;
151
152 // Advances the iterator one step.
153 Iterator& operator++();
154
155 // Provides a way to compare the iterator with itself and with the end
156 // iterator.
157 // Note: all other comparison results are undefined, just like for C++ input
158 // iterators.
159 bool operator==(const Iterator& other);
160 bool operator!=(const Iterator& other) { return !(*this == other); }
161 jobject operator*();
162
163 private:
164 bool AtEnd() const;
165
166 JNIEnv* jni_ = nullptr;
167 jobject iterator_ = nullptr;
168 jobject value_ = nullptr;
169 jmethodID has_next_id_ = nullptr;
170 jmethodID next_id_ = nullptr;
171 rtc::ThreadChecker thread_checker_;
172
173 RTC_DISALLOW_COPY_AND_ASSIGN(Iterator);
174 };
175
176 Iterable::Iterator begin() { return Iterable::Iterator(jni_, iterable_); }
177 Iterable::Iterator end() { return Iterable::Iterator(); }
178
179 private:
180 JNIEnv* jni_;
181 jobject iterable_;
182
183 RTC_DISALLOW_COPY_AND_ASSIGN(Iterable);
184 };
185
125 } // namespace webrtc_jni 186 } // namespace webrtc_jni
126 187
127 #endif // WEBRTC_API_JAVA_JNI_JNI_HELPERS_H_ 188 #endif // WEBRTC_API_JAVA_JNI_JNI_HELPERS_H_
OLDNEW
« no previous file with comments | « webrtc/api/androidtests/src/org/webrtc/PeerConnectionTest.java ('k') | webrtc/api/java/jni/jni_helpers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698