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

Unified Diff: webrtc/api/java/jni/jni_helpers.cc

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: One more rename 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/api/java/jni/jni_helpers.cc
diff --git a/webrtc/api/java/jni/jni_helpers.cc b/webrtc/api/java/jni/jni_helpers.cc
index 32092e65f8b7e8a2c94cb69b393ccc5f4f2ebb2e..41d34247f2baae1c96a7f5c4022bd90e6eacab07 100644
--- a/webrtc/api/java/jni/jni_helpers.cc
+++ b/webrtc/api/java/jni/jni_helpers.cc
@@ -272,4 +272,55 @@ ScopedLocalRefFrame::~ScopedLocalRefFrame() {
jni_->PopLocalFrame(NULL);
}
+// Creates an iterator representing the end of any collection.
+Iterator::Iterator() : iterator_(NULL) {}
+
+// Creates an iterator pointing to the beginning of the specified collection.
+Iterator::Iterator(JNIEnv* jni, jobject iterable) : jni_(jni) {
+ jclass j_class = GetObjectClass(jni, iterable);
+ jmethodID iterator_id =
+ GetMethodID(jni, j_class, "iterator", "()Ljava/util/Iterator;");
+ iterator_ = jni->CallObjectMethod(iterable, iterator_id);
+ CHECK_EXCEPTION(jni) << "error during CallObjectMethod";
+
+ if (iterator_ == NULL) {
+ // TODO(skvlad): Should this be an exception instead?
Taylor Brandstetter 2016/03/22 01:16:36 That seems reasonable. Just use "RTC_CHECK(iterato
skvlad 2016/03/22 02:19:59 Done.
+ return;
+ }
+
+ jclass iterator_class = GetObjectClass(jni, iterator_);
+ has_next_id_ = GetMethodID(jni, iterator_class, "hasNext", "()Z");
+ next_id_ = GetMethodID(jni, iterator_class, "next", "()Ljava/lang/Object;");
+
+ // Start at the first element in the collection
+ ++(*this);
+}
+
+// Move constructor - necessary to be able to return iterator types from
+// functions
+Iterator::Iterator(Iterator&& other)
+ : jni_(std::move(other.jni_)),
+ iterator_(std::move(other.iterator_)),
+ value_(std::move(other.value_)),
+ has_next_id_(std::move(other.has_next_id_)),
+ next_id_(std::move(other.next_id_)){};
+
+// Advances the iterator one step
+Iterator& Iterator::operator++() {
+ if (iterator_ == NULL) {
+ // Can't iterate past the end
+ return *this;
+ }
+ bool has_next = jni_->CallBooleanMethod(iterator_, has_next_id_);
+ CHECK_EXCEPTION(jni_) << "error during CallBooleanMethod";
+ if (!has_next) {
+ iterator_ = NULL;
+ return *this;
+ }
+
+ value_ = jni_->CallObjectMethod(iterator_, next_id_);
+ CHECK_EXCEPTION(jni_) << "error during CallObjectMethod";
+ return *this;
+}
+
} // namespace webrtc_jni

Powered by Google App Engine
This is Rietveld 408576698