Browse Source

Refactored Description::Direction serialization

Paul-Louis Ageneau 2 years ago
parent
commit
c5f80388f1
1 changed files with 12 additions and 39 deletions
  1. 12 39
      src/description.cpp

+ 12 - 39
src/description.cpp

@@ -599,46 +599,18 @@ string Description::Entry::generateSdpLines(string_view eol) const {
 		auto &map = it->second;
 
 		sdp << "a=extmap:" << map.id;
-		switch (map.direction) {
-		case Direction::SendOnly:
-			sdp << "/sendonly";
-			break;
-		case Direction::RecvOnly:
-			sdp << "/recvonly";
-			break;
-		case Direction::SendRecv:
-			sdp << "/sendrecv";
-			break;
-		case Direction::Inactive:
-			sdp << "/inactive";
-			break;
-		default:
-			// Ignore
-			break;
-		}
+		if (map.direction != Direction::Unknown)
+			sdp << '/' << map.direction;
+
 		sdp << ' ' << map.uri;
 		if (!map.attributes.empty())
 			sdp << ' ' << map.attributes;
+
 		sdp << eol;
 	}
 
-	switch (mDirection) {
-	case Direction::SendOnly:
-		sdp << "a=sendonly" << eol;
-		break;
-	case Direction::RecvOnly:
-		sdp << "a=recvonly" << eol;
-		break;
-	case Direction::SendRecv:
-		sdp << "a=sendrecv" << eol;
-		break;
-	case Direction::Inactive:
-		sdp << "a=inactive" << eol;
-		break;
-	default:
-		// Ignore
-		break;
-	}
+	if (mDirection != Direction::Unknown)
+		sdp << "a=" << mDirection << eol;
 
 	for (const auto &attr : mAttributes)
 		sdp << "a=" << attr << eol;
@@ -1261,22 +1233,23 @@ std::ostream &operator<<(std::ostream &out, rtc::Description::Role role) {
 }
 
 std::ostream &operator<<(std::ostream &out, const rtc::Description::Direction &direction) {
+	// Used for SDP generation, do not change
 	switch (direction) {
 	case rtc::Description::Direction::RecvOnly:
-		out << "RecvOnly";
+		out << "recvonly";
 		break;
 	case rtc::Description::Direction::SendOnly:
-		out << "SendOnly";
+		out << "sendonly";
 		break;
 	case rtc::Description::Direction::SendRecv:
-		out << "SendRecv";
+		out << "sendrecv";
 		break;
 	case rtc::Description::Direction::Inactive:
-		out << "Inactive";
+		out << "inactive";
 		break;
 	case rtc::Description::Direction::Unknown:
 	default:
-		out << "Unknown";
+		out << "unknown";
 		break;
 	}
 	return out;