xref: /aosp_15_r20/external/webrtc/sdk/android/src/jni/pc/session_description.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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 std::string & sdp,const std::string & type)38 ScopedJavaLocalRef<jobject> NativeToJavaSessionDescription(
39     JNIEnv* jni,
40     const std::string& sdp,
41     const std::string& type) {
42   return Java_SessionDescription_Constructor(
43       jni, Java_Type_fromCanonicalForm(jni, NativeToJavaString(jni, type)),
44       NativeToJavaString(jni, sdp));
45 }
46 
47 }  // namespace jni
48 }  // namespace webrtc
49