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

Side by Side Diff: webrtc/api/android/jni/classreferenceholder.cc

Issue 2547483003: Move /webrtc/api/android files to /webrtc/sdk/android (Closed)
Patch Set: Move to api folder under Android instead of src Created 4 years 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 | « webrtc/api/android/jni/classreferenceholder.h ('k') | webrtc/api/android/jni/jni_helpers.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10 #include "webrtc/api/android/jni/classreferenceholder.h"
11
12 #include "webrtc/api/android/jni/jni_helpers.h"
13
14 namespace webrtc_jni {
15
16 // ClassReferenceHolder holds global reference to Java classes in app/webrtc.
17 class ClassReferenceHolder {
18 public:
19 explicit ClassReferenceHolder(JNIEnv* jni);
20 ~ClassReferenceHolder();
21
22 void FreeReferences(JNIEnv* jni);
23 jclass GetClass(const std::string& name);
24
25 private:
26 void LoadClass(JNIEnv* jni, const std::string& name);
27
28 std::map<std::string, jclass> classes_;
29 };
30
31 // Allocated in LoadGlobalClassReferenceHolder(),
32 // freed in FreeGlobalClassReferenceHolder().
33 static ClassReferenceHolder* g_class_reference_holder = nullptr;
34
35 void LoadGlobalClassReferenceHolder() {
36 RTC_CHECK(g_class_reference_holder == nullptr);
37 g_class_reference_holder = new ClassReferenceHolder(GetEnv());
38 }
39
40 void FreeGlobalClassReferenceHolder() {
41 g_class_reference_holder->FreeReferences(AttachCurrentThreadIfNeeded());
42 delete g_class_reference_holder;
43 g_class_reference_holder = nullptr;
44 }
45
46 ClassReferenceHolder::ClassReferenceHolder(JNIEnv* jni) {
47 LoadClass(jni, "android/graphics/SurfaceTexture");
48 LoadClass(jni, "java/nio/ByteBuffer");
49 LoadClass(jni, "java/util/ArrayList");
50 LoadClass(jni, "org/webrtc/AudioTrack");
51 LoadClass(jni, "org/webrtc/Camera1Enumerator");
52 LoadClass(jni, "org/webrtc/Camera2Enumerator");
53 LoadClass(jni, "org/webrtc/CameraEnumerationAndroid");
54 LoadClass(jni, "org/webrtc/DataChannel");
55 LoadClass(jni, "org/webrtc/DataChannel$Buffer");
56 LoadClass(jni, "org/webrtc/DataChannel$Init");
57 LoadClass(jni, "org/webrtc/DataChannel$State");
58 LoadClass(jni, "org/webrtc/EglBase");
59 LoadClass(jni, "org/webrtc/EglBase$Context");
60 LoadClass(jni, "org/webrtc/EglBase14$Context");
61 LoadClass(jni, "org/webrtc/IceCandidate");
62 LoadClass(jni, "org/webrtc/MediaCodecVideoEncoder");
63 LoadClass(jni, "org/webrtc/MediaCodecVideoEncoder$OutputBufferInfo");
64 LoadClass(jni, "org/webrtc/MediaCodecVideoEncoder$VideoCodecType");
65 LoadClass(jni, "org/webrtc/MediaCodecVideoDecoder");
66 LoadClass(jni, "org/webrtc/MediaCodecVideoDecoder$DecodedTextureBuffer");
67 LoadClass(jni, "org/webrtc/MediaCodecVideoDecoder$DecodedOutputBuffer");
68 LoadClass(jni, "org/webrtc/MediaCodecVideoDecoder$VideoCodecType");
69 LoadClass(jni, "org/webrtc/MediaSource$State");
70 LoadClass(jni, "org/webrtc/MediaStream");
71 LoadClass(jni, "org/webrtc/MediaStreamTrack$State");
72 LoadClass(jni, "org/webrtc/NetworkMonitor");
73 LoadClass(jni, "org/webrtc/NetworkMonitorAutoDetect$ConnectionType");
74 LoadClass(jni, "org/webrtc/NetworkMonitorAutoDetect$IPAddress");
75 LoadClass(jni, "org/webrtc/NetworkMonitorAutoDetect$NetworkInformation");
76 LoadClass(jni, "org/webrtc/PeerConnectionFactory");
77 LoadClass(jni, "org/webrtc/PeerConnection$BundlePolicy");
78 LoadClass(jni, "org/webrtc/PeerConnection$ContinualGatheringPolicy");
79 LoadClass(jni, "org/webrtc/PeerConnection$RtcpMuxPolicy");
80 LoadClass(jni, "org/webrtc/PeerConnection$IceConnectionState");
81 LoadClass(jni, "org/webrtc/PeerConnection$IceGatheringState");
82 LoadClass(jni, "org/webrtc/PeerConnection$IceTransportsType");
83 LoadClass(jni, "org/webrtc/PeerConnection$TcpCandidatePolicy");
84 LoadClass(jni, "org/webrtc/PeerConnection$CandidateNetworkPolicy");
85 LoadClass(jni, "org/webrtc/PeerConnection$KeyType");
86 LoadClass(jni, "org/webrtc/PeerConnection$SignalingState");
87 LoadClass(jni, "org/webrtc/RtpReceiver");
88 LoadClass(jni, "org/webrtc/RtpSender");
89 LoadClass(jni, "org/webrtc/SessionDescription");
90 LoadClass(jni, "org/webrtc/SessionDescription$Type");
91 LoadClass(jni, "org/webrtc/StatsReport");
92 LoadClass(jni, "org/webrtc/StatsReport$Value");
93 LoadClass(jni, "org/webrtc/SurfaceTextureHelper");
94 LoadClass(jni, "org/webrtc/VideoCapturer");
95 LoadClass(jni, "org/webrtc/VideoRenderer$I420Frame");
96 LoadClass(jni, "org/webrtc/VideoTrack");
97 }
98
99 ClassReferenceHolder::~ClassReferenceHolder() {
100 RTC_CHECK(classes_.empty()) << "Must call FreeReferences() before dtor!";
101 }
102
103 void ClassReferenceHolder::FreeReferences(JNIEnv* jni) {
104 for (std::map<std::string, jclass>::const_iterator it = classes_.begin();
105 it != classes_.end(); ++it) {
106 jni->DeleteGlobalRef(it->second);
107 }
108 classes_.clear();
109 }
110
111 jclass ClassReferenceHolder::GetClass(const std::string& name) {
112 std::map<std::string, jclass>::iterator it = classes_.find(name);
113 RTC_CHECK(it != classes_.end()) << "Unexpected GetClass() call for: " << name;
114 return it->second;
115 }
116
117 void ClassReferenceHolder::LoadClass(JNIEnv* jni, const std::string& name) {
118 jclass localRef = jni->FindClass(name.c_str());
119 CHECK_EXCEPTION(jni) << "error during FindClass: " << name;
120 RTC_CHECK(localRef) << name;
121 jclass globalRef = reinterpret_cast<jclass>(jni->NewGlobalRef(localRef));
122 CHECK_EXCEPTION(jni) << "error during NewGlobalRef: " << name;
123 RTC_CHECK(globalRef) << name;
124 bool inserted = classes_.insert(std::make_pair(name, globalRef)).second;
125 RTC_CHECK(inserted) << "Duplicate class name: " << name;
126 }
127
128 // Returns a global reference guaranteed to be valid for the lifetime of the
129 // process.
130 jclass FindClass(JNIEnv* jni, const char* name) {
131 return g_class_reference_holder->GetClass(name);
132 }
133
134 } // namespace webrtc_jni
OLDNEW
« no previous file with comments | « webrtc/api/android/jni/classreferenceholder.h ('k') | webrtc/api/android/jni/jni_helpers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698