• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright 2017 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 
11 #include "sdk/android/src/jni/pc/sdp_observer.h"
12 
13 #include <utility>
14 
15 #include "sdk/android/generated_peerconnection_jni/SdpObserver_jni.h"
16 #include "sdk/android/native_api/jni/java_types.h"
17 #include "sdk/android/src/jni/jni_helpers.h"
18 #include "sdk/media_constraints.h"
19 
20 namespace webrtc {
21 namespace jni {
22 
CreateSdpObserverJni(JNIEnv * env,const JavaRef<jobject> & j_observer,std::unique_ptr<MediaConstraints> constraints)23 CreateSdpObserverJni::CreateSdpObserverJni(
24     JNIEnv* env,
25     const JavaRef<jobject>& j_observer,
26     std::unique_ptr<MediaConstraints> constraints)
27     : j_observer_global_(env, j_observer),
28       constraints_(std::move(constraints)) {}
29 
30 CreateSdpObserverJni::~CreateSdpObserverJni() = default;
31 
OnSuccess(SessionDescriptionInterface * desc)32 void CreateSdpObserverJni::OnSuccess(SessionDescriptionInterface* desc) {
33   JNIEnv* env = AttachCurrentThreadIfNeeded();
34   std::string sdp;
35   RTC_CHECK(desc->ToString(&sdp)) << "got so far: " << sdp;
36   Java_SdpObserver_onCreateSuccess(
37       env, j_observer_global_,
38       NativeToJavaSessionDescription(env, sdp, desc->type()));
39   // OnSuccess transfers ownership of the description (there's a TODO to make
40   // it use unique_ptr...).
41   delete desc;
42 }
43 
OnFailure(webrtc::RTCError error)44 void CreateSdpObserverJni::OnFailure(webrtc::RTCError error) {
45   JNIEnv* env = AttachCurrentThreadIfNeeded();
46   Java_SdpObserver_onCreateFailure(env, j_observer_global_,
47                                    NativeToJavaString(env, error.message()));
48 }
49 
SetLocalSdpObserverJni(JNIEnv * env,const JavaRef<jobject> & j_observer)50 SetLocalSdpObserverJni::SetLocalSdpObserverJni(
51     JNIEnv* env,
52     const JavaRef<jobject>& j_observer)
53     : j_observer_global_(env, j_observer) {}
54 
OnSetLocalDescriptionComplete(RTCError error)55 void SetLocalSdpObserverJni::OnSetLocalDescriptionComplete(RTCError error) {
56   JNIEnv* env = AttachCurrentThreadIfNeeded();
57   if (error.ok()) {
58     Java_SdpObserver_onSetSuccess(env, j_observer_global_);
59   } else {
60     Java_SdpObserver_onSetFailure(env, j_observer_global_,
61                                   NativeToJavaString(env, error.message()));
62   }
63 }
64 
SetRemoteSdpObserverJni(JNIEnv * env,const JavaRef<jobject> & j_observer)65 SetRemoteSdpObserverJni::SetRemoteSdpObserverJni(
66     JNIEnv* env,
67     const JavaRef<jobject>& j_observer)
68     : j_observer_global_(env, j_observer) {}
69 
OnSetRemoteDescriptionComplete(RTCError error)70 void SetRemoteSdpObserverJni::OnSetRemoteDescriptionComplete(RTCError error) {
71   JNIEnv* env = AttachCurrentThreadIfNeeded();
72   if (error.ok()) {
73     Java_SdpObserver_onSetSuccess(env, j_observer_global_);
74   } else {
75     Java_SdpObserver_onSetFailure(env, j_observer_global_,
76                                   NativeToJavaString(env, error.message()));
77   }
78 }
79 
80 }  // namespace jni
81 }  // namespace webrtc
82