• 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/session_description.h"
12 
13 #include <string>
14 
15 #include "rtc_base/logging.h"
16 #include "sdk/android/generated_peerconnection_jni/SessionDescription_jni.h"
17 #include "sdk/android/native_api/jni/java_types.h"
18 #include "sdk/android/src/jni/jni_helpers.h"
19 
20 namespace webrtc {
21 namespace jni {
22 
JavaToNativeSessionDescription(JNIEnv * jni,const JavaRef<jobject> & j_sdp)23 std::unique_ptr<SessionDescriptionInterface> JavaToNativeSessionDescription(
24     JNIEnv* jni,
25     const JavaRef<jobject>& j_sdp) {
26   std::string std_type = JavaToStdString(
27       jni, Java_SessionDescription_getTypeInCanonicalForm(jni, j_sdp));
28   std::string std_description =
29       JavaToStdString(jni, Java_SessionDescription_getDescription(jni, j_sdp));
30   absl::optional<SdpType> sdp_type_maybe = SdpTypeFromString(std_type);
31   if (!sdp_type_maybe) {
32     RTC_LOG(LS_ERROR) << "Unexpected SDP type: " << std_type;
33     return nullptr;
34   }
35   return CreateSessionDescription(*sdp_type_maybe, std_description);
36 }
37 
NativeToJavaSessionDescription(JNIEnv * jni,const SessionDescriptionInterface * desc)38 ScopedJavaLocalRef<jobject> NativeToJavaSessionDescription(
39     JNIEnv* jni,
40     const SessionDescriptionInterface* desc) {
41   std::string sdp;
42   RTC_CHECK(desc->ToString(&sdp)) << "got so far: " << sdp;
43   return Java_SessionDescription_Constructor(
44       jni,
45       Java_Type_fromCanonicalForm(jni, NativeToJavaString(jni, desc->type())),
46       NativeToJavaString(jni, sdp));
47 }
48 
49 }  // namespace jni
50 }  // namespace webrtc
51