Browse Source

Added bitrate control via SDP

Staz M 5 years ago
parent
commit
bf044080e8

+ 3 - 1
examples/media/main.cpp

@@ -40,7 +40,7 @@ int main() {
             pc->sendMedia(ptr);
             pc->sendMedia(ptr);
         }
         }
     });
     });
-    session.requestBitrate(3000000); // Request 3Mbps (Browsers do not encode more than 2.5MBps from a webcam)
+//    session.requestBitrate(4000000); // Request 3Mbps (Browsers do not encode more than 2.5MBps from a webcam)
     pc->onMedia([&session, &sock_fd, &addr](const rtc::message_ptr& ptr) {
     pc->onMedia([&session, &sock_fd, &addr](const rtc::message_ptr& ptr) {
         auto resp = session.onData(ptr);
         auto resp = session.onData(ptr);
         if (resp.has_value()) {
         if (resp.has_value()) {
@@ -52,6 +52,8 @@ int main() {
     rtc::Description offer;
     rtc::Description offer;
     rtc::Description::Media &m = offer.addVideoMedia(rtc::Description::RecvOnly);
     rtc::Description::Media &m = offer.addVideoMedia(rtc::Description::RecvOnly);
     m.addH264Codec(96);
     m.addH264Codec(96);
+    m.setBitrate(3000); // Request 3Mbps (Browsers do not encode more than 2.5MBps from a webcam)
+//    m.setBitrate(5000000);
     pc->setLocalDescription(offer);
     pc->setLocalDescription(offer);
     auto dc = pc->createDataChannel("test");
     auto dc = pc->createDataChannel("test");
 
 

+ 3 - 0
include/rtc/description.hpp

@@ -120,6 +120,9 @@ public:
         void addH264Codec(int payloadType);
         void addH264Codec(int payloadType);
         void addVP8Codec(int payloadType);
         void addVP8Codec(int payloadType);
         void addVP9Codec(int payloadType);
         void addVP9Codec(int payloadType);
+
+        void setBitrate(int bitrate);
+        int getBitrate() const;
     };
     };
 
 
     std::_Rb_tree_iterator<std::pair<const int, Media>> getMedia(int mLine);
     std::_Rb_tree_iterator<std::pair<const int, Media>> getMedia(int mLine);

+ 2 - 1
include/rtc/rtp.hpp

@@ -474,7 +474,8 @@ public:
 
 
             // TODO For the time being, we will send RR's/REMB's when we get an SR
             // TODO For the time being, we will send RR's/REMB's when we get an SR
             pushRR(0);
             pushRR(0);
-            pushREMB(requestedBitrate);
+            if (requestedBitrate > 0)
+                pushREMB(requestedBitrate);
         }
         }
         return std::nullopt;
         return std::nullopt;
     }
     }

+ 7 - 0
src/description.cpp

@@ -465,6 +465,13 @@ Description::Direction Description::Media::getDirection() {
     return Direction::Unknown;
     return Direction::Unknown;
 }
 }
 
 
+void Description::Media::setBitrate(int bitrate) {
+    this->bAS = bitrate;
+}
+int Description::Media::getBitrate() const {
+    return this->bAS;
+}
+
 void Description::Media::setDirection(Description::Direction dir) {
 void Description::Media::setDirection(Description::Direction dir) {
     auto it = attributes.begin();
     auto it = attributes.begin();
     while (it != attributes.end()) {
     while (it != attributes.end()) {

+ 1 - 0
src/dtlssrtptransport.cpp

@@ -87,6 +87,7 @@ bool DtlsSrtpTransport::sendMedia(message_ptr message) {
 //    return outgoing(message);
 //    return outgoing(message);
 
 
 	// The RTP header has a minimum size of 12 bytes
 	// The RTP header has a minimum size of 12 bytes
+	// An RTCP packet can have a minimum size of 8 bytes
 	if (size < 8)
 	if (size < 8)
 		throw std::runtime_error("RTP/RTCP packet too short");
 		throw std::runtime_error("RTP/RTCP packet too short");