Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix H264RtpDepacketizer to handle empty payload RTP packet #1140

Merged
merged 2 commits into from
Apr 12, 2024

Conversation

sile
Copy link
Contributor

@sile sile commented Mar 27, 2024

This PR fixes an issue that H264RtpDepacketizer cannot handle empty payload RTP packets that could be sent by Chrome (please see obs-studio#10353 comment for the detailed motivation).

How to reproduce the issue

Please apply the following diff to examples/media-receiver/main.cpp file and build the command.

diff --git a/examples/media-receiver/main.cpp b/examples/media-receiver/main.cpp
index 81e0d1d0..b2fe13c7 100644
--- a/examples/media-receiver/main.cpp
+++ b/examples/media-receiver/main.cpp
@@ -40,8 +40,10 @@ int main() {
                        std::cout << "Gathering State: " << state << std::endl;
                        if (state == rtc::PeerConnection::GatheringState::Complete) {
                                auto description = pc->localDescription();
+                               auto sdp = std::string(description.value());
+                               sdp += "a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\n";
                                json message = {{"type", description->typeString()},
-                                               {"sdp", std::string(description.value())}};
+                                               {"sdp", sdp}};
                                std::cout << message << std::endl;
                        }
                });
@@ -54,13 +56,13 @@ int main() {

                rtc::Description::Video media("video", rtc::Description::Direction::RecvOnly);
                media.addH264Codec(96);
-               media.setBitrate(
-                   3000); // Request 3Mbps (Browsers do not encode more than 2.5MBps from a webcam)

                auto track = pc->addTrack(media);

+               auto video_depacketizer = std::make_shared<rtc::H264RtpDepacketizer>();
                auto session = std::make_shared<rtc::RtcpReceivingSession>();
-               track->setMediaHandler(session);
+               video_depacketizer->addToChain(session);
+               track->setMediaHandler(video_depacketizer);

                track->onMessage(
                    [session, sock, addr](rtc::binary message) {

Execute media-receiver command and communicate with Chrome.
When media-receiver starts receiving video packets, it could emit the following error message:

$ ./media-receiver
...
2024-03-27 14:46:16.535 ERROR [281897] [rtc::impl::DtlsTransport::doRecv@990] DTLS recv: Unknown H264 RTP Packetization
2024-03-27 14:46:16.537 INFO  [281897] [rtc::impl::DtlsTransport::doRecv@994] DTLS closed

Copy link
Owner

@paullouisageneau paullouisageneau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

@paullouisageneau paullouisageneau merged commit d69d52e into paullouisageneau:master Apr 12, 2024
12 checks passed
@sile sile deleted the fix-h264-depacketizer branch April 12, 2024 21:27
edmonds added a commit to edmonds/libdatachannel that referenced this pull request Apr 13, 2024
edmonds added a commit to edmonds/libdatachannel that referenced this pull request Apr 17, 2024
edmonds added a commit to edmonds/libdatachannel that referenced this pull request Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants