Replace string type with SdpType enum

This moves all WebRTC internal code from using
SessionDescriptionInterface::type() which returns a string and
from using CreateSessionDescription with a string type parameter.

Bug: webrtc:8613
Change-Id: I1cdd93dc4b26dec157e22476fdac569d5da2810a
Reviewed-on: https://webrtc-review.googlesource.com/29500
Commit-Queue: Steve Anton <steveanton@webrtc.org>
Reviewed-by: Magnus Jedvert <magjed@webrtc.org>
Reviewed-by: Zhi Huang <zhihuang@webrtc.org>
Reviewed-by: Peter Thatcher <pthatcher@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21147}
This commit is contained in:
Steve Anton
2017-12-07 10:27:41 -08:00
committed by Commit Bot
parent 3c1f05db84
commit a3a92c264b
16 changed files with 236 additions and 232 deletions

View File

@ -82,8 +82,9 @@ jobjectArray NativeToJavaCandidateArray(
&NativeToJavaCandidate);
}
SessionDescriptionInterface* JavaToNativeSessionDescription(JNIEnv* jni,
jobject j_sdp) {
std::unique_ptr<SessionDescriptionInterface> JavaToNativeSessionDescription(
JNIEnv* jni,
jobject j_sdp) {
jfieldID j_type_id = GetFieldID(jni, GetObjectClass(jni, j_sdp), "type",
"Lorg/webrtc/SessionDescription$Type;");
jobject j_type = GetObjectField(jni, j_sdp, j_type_id);
@ -94,13 +95,18 @@ SessionDescriptionInterface* JavaToNativeSessionDescription(JNIEnv* jni,
(jstring)jni->CallObjectMethod(j_type, j_canonical_form_id);
CHECK_EXCEPTION(jni) << "error during CallObjectMethod";
std::string std_type = JavaToStdString(jni, j_type_string);
rtc::Optional<SdpType> sdp_type_maybe = SdpTypeFromString(std_type);
if (!sdp_type_maybe) {
RTC_LOG(LS_ERROR) << "Unexpected SDP type: " << std_type;
return nullptr;
}
jfieldID j_description_id = GetFieldID(jni, GetObjectClass(jni, j_sdp),
"description", "Ljava/lang/String;");
jstring j_description = (jstring)GetObjectField(jni, j_sdp, j_description_id);
std::string std_description = JavaToStdString(jni, j_description);
return CreateSessionDescription(std_type, std_description, NULL);
return CreateSessionDescription(*sdp_type_maybe, std_description);
}
jobject NativeToJavaSessionDescription(

View File

@ -45,8 +45,9 @@ jobjectArray NativeToJavaCandidateArray(
JNIEnv* jni,
const std::vector<cricket::Candidate>& candidates);
SessionDescriptionInterface* JavaToNativeSessionDescription(JNIEnv* jni,
jobject j_sdp);
std::unique_ptr<SessionDescriptionInterface> JavaToNativeSessionDescription(
JNIEnv* jni,
jobject j_sdp);
jobject NativeToJavaSessionDescription(JNIEnv* jni,
const SessionDescriptionInterface* desc);

View File

@ -149,7 +149,7 @@ JNI_FUNCTION_DECLARATION(void,
rtc::scoped_refptr<SetSdpObserverJni> observer(
new rtc::RefCountedObject<SetSdpObserverJni>(jni, j_observer, nullptr));
ExtractNativePC(jni, j_pc)->SetLocalDescription(
observer, JavaToNativeSessionDescription(jni, j_sdp));
observer, JavaToNativeSessionDescription(jni, j_sdp).release());
}
JNI_FUNCTION_DECLARATION(void,
@ -161,7 +161,7 @@ JNI_FUNCTION_DECLARATION(void,
rtc::scoped_refptr<SetSdpObserverJni> observer(
new rtc::RefCountedObject<SetSdpObserverJni>(jni, j_observer, nullptr));
ExtractNativePC(jni, j_pc)->SetRemoteDescription(
observer, JavaToNativeSessionDescription(jni, j_sdp));
observer, JavaToNativeSessionDescription(jni, j_sdp).release());
}
JNI_FUNCTION_DECLARATION(void,