Explorar el Código

Fixed cicular dependency on RtcpHandler

Staz M hace 5 años
padre
commit
77475b57b0
Se han modificado 4 ficheros con 21 adiciones y 12 borrados
  1. 16 5
      include/rtc/rtcp.hpp
  2. 0 1
      include/rtc/track.hpp
  3. 5 1
      src/rtcp.cpp
  4. 0 5
      src/track.cpp

+ 16 - 5
include/rtc/rtcp.hpp

@@ -30,30 +30,41 @@
 namespace rtc {
 
 class RtcpHandler {
+protected:
+    /**
+     * Use this callback when trying to send custom data (such as RTCP) to the client.
+     */
+    synchronized_callback<rtc::message_ptr> outgoingCallback;
 public:
     /**
-     * If there is traffic coming from the remote side
+     * Called when there is traffic coming from the peer
      * @param ptr
      * @return
      */
     virtual rtc::message_ptr incoming(rtc::message_ptr ptr) = 0;
 
     /**
-     * If there is traffic being sent to the remote side
+     * Called when there is traffic that needs to be sent to the peer
      * @param ptr
      * @return
      */
     virtual rtc::message_ptr outgoing(rtc::message_ptr ptr) = 0;
+
+
+    /**
+     * This callback is used to send traffic back to the peer.
+     * This callback skips calling the track's methods.
+     * @param cb
+     */
+    void onOutgoing(const std::function<void(rtc::message_ptr)>& cb);
+
 };
 
 class Track;
 
 // An RtcpSession can be plugged into a Track to handle the whole RTCP session
 class RtcpReceivingSession : public RtcpHandler {
-protected:
-    std::shared_ptr<Track> track;
 public:
-    RtcpReceivingSession(std::shared_ptr<Track> track): track(std::move(track)) {}
 
     rtc::message_ptr incoming(rtc::message_ptr ptr) override;
     rtc::message_ptr outgoing(rtc::message_ptr ptr) override;

+ 0 - 1
include/rtc/track.hpp

@@ -46,7 +46,6 @@ public:
 	void close(void) override;
 	bool send(message_variant data) override;
 	bool send(const byte *data, size_t size);
-    bool sendControl(message_ptr msg);
 
 	bool isOpen(void) const override;
 	bool isClosed(void) const override;

+ 5 - 1
src/rtcp.cpp

@@ -115,12 +115,16 @@ void RtcpReceivingSession::pushRR(unsigned int lastSR_delay) {
 
 bool RtcpReceivingSession::send(message_ptr msg) {
 	try {
-	    return track->sendControl(std::move(msg));
+	    outgoingCallback(std::move(msg));
+	    return true;
 	} catch (const std::exception &e) {
 		LOG_DEBUG << "RTCP tx failed: " << e.what();
 	}
 	return false;
 }
 
+void RtcpHandler::onOutgoing(const std::function<void(rtc::message_ptr)>& cb) {
+    this->outgoingCallback = synchronized_callback<rtc::message_ptr>(cb);
+}
 } // namespace rtc
 

+ 0 - 5
src/track.cpp

@@ -91,11 +91,6 @@ bool Track::outgoing(message_ptr message) {
         PLOG_WARNING << "Track media direction does not allow reception, dropping";
     }
 
-	return sendControl(message);
-}
-
-bool Track::sendControl(message_ptr message) {
-
     if (mIsClosed)
         throw std::runtime_error("Track is closed");