浏览代码

Allow updating track description

Paul-Louis Ageneau 4 年之前
父节点
当前提交
476528b464
共有 4 个文件被更改,包括 21 次插入14 次删除
  1. 1 4
      include/rtc/description.hpp
  2. 2 0
      include/rtc/track.hpp
  3. 14 10
      src/peerconnection.cpp
  4. 4 0
      src/track.cpp

+ 1 - 4
include/rtc/description.hpp

@@ -94,8 +94,7 @@ public:
 	struct Application : public Entry {
 	public:
 		Application(string mid = "data");
-		Application(const Application &other) = default;
-		Application(Application &&other) = default;
+		virtual ~Application() = default;
 
 		string description() const override;
 		Application reciprocate() const;
@@ -121,8 +120,6 @@ public:
 	public:
 		Media(const string &sdp);
 		Media(const string &mline, string mid, Direction dir = Direction::SendOnly);
-		Media(const Media &other) = default;
-		Media(Media &&other) = default;
 		virtual ~Media() = default;
 
 		string description() const override;

+ 2 - 0
include/rtc/track.hpp

@@ -43,6 +43,8 @@ public:
 	string mid() const;
 	Description::Media description() const;
 
+	void setDescription(Description::Media description);
+
 	void close(void) override;
 	bool send(message_variant data) override;
 	bool send(const byte *data, size_t size);

+ 14 - 10
src/peerconnection.cpp

@@ -368,19 +368,23 @@ void PeerConnection::onSignalingStateChange(std::function<void(SignalingState st
 }
 
 std::shared_ptr<Track> PeerConnection::addTrack(Description::Media description) {
-	if (auto it = mTracks.find(description.mid()); it != mTracks.end())
-		if (auto track = it->second.lock())
-			return track;
-
 #if !RTC_ENABLE_MEDIA
 	if (mTracks.empty()) {
 		PLOG_WARNING << "Tracks will be inative (not compiled with SRTP support)";
 	}
 #endif
-	auto track = std::make_shared<Track>(std::move(description));
-	mTracks.emplace(std::make_pair(track->mid(), track));
 
-	// Renegotiation is needed for the new track
+    std::shared_ptr<Track> track;
+	if (auto it = mTracks.find(description.mid()); it != mTracks.end())
+		if(track = it->second.lock(); track)
+			track->setDescription(std::move(description));
+
+	if(!track) {
+		track = std::make_shared<Track>(std::move(description));
+		mTracks.emplace(std::make_pair(track->mid(), track));
+	}
+
+	// Renegotiation is needed for the new or updated track
 	mNegotiationNeeded = true;
 
 	return track;
@@ -1051,7 +1055,7 @@ bool PeerConnection::changeState(State state) {
 bool PeerConnection::changeGatheringState(GatheringState state) {
 	if (mGatheringState.exchange(state) == state)
 		return false;
-	
+
 	std::ostringstream s;
 	s << state;
 	PLOG_INFO << "Changed gathering state to " << s.str();
@@ -1060,9 +1064,9 @@ bool PeerConnection::changeGatheringState(GatheringState state) {
 }
 
 bool PeerConnection::changeSignalingState(SignalingState state) {
-	if (mSignalingState.exchange(state) == state) 
+	if (mSignalingState.exchange(state) == state)
 		return false;
-	
+
 	std::ostringstream s;
 	s << state;
 	PLOG_INFO << "Changed signaling state to " << s.str();

+ 4 - 0
src/track.cpp

@@ -32,6 +32,10 @@ string Track::mid() const { return mMediaDescription.mid(); }
 
 Description::Media Track::description() const { return mMediaDescription; }
 
+void Track::setDescription(Description::Media description) {
+	mMediaDescription = std::move(description);
+}
+
 void Track::close() {
 	mIsClosed = true;
 	resetCallbacks();