[PR #237] [CLOSED] Use libdatachannel RTP packetizer for H264 in WHIP stream #239

Closed
opened 2026-03-02 04:00:52 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/eerimoq/moblin/pull/237
Author: @Copilot
Created: 2/14/2026
Status: Closed

Base: mainHead: copilot/add-rtp-packetizer-for-h264


📝 Commits (3)

  • 7264ae4 Initial plan
  • 13b909c Use libdatachannel RTP packetizer for H264 in WHIP stream with NACK and SR handling
  • 63737b9 Extract magic numbers into named constants for readability

📊 Changes

1 file changed (+68 additions, -101 deletions)

View changed files

📝 Moblin/Media/HaishinKit/Whip/WhipStream.swift (+68 -101)

📄 Description

Replace the custom H264 RTP packetizer with libdatachannel's built-in packetizer and register NACK/SR handlers so lost packets are retransmitted.

  • H264 packetizer: Configure rtcSetH264Packetizer on the video track instead of manually constructing RTP packets with FU-A fragmentation. The H264Packetizer class is simplified to only prepend SPS/PPS NAL units on keyframes—libdatachannel handles RTP header construction, sequencing, and fragmentation.
  • RTCP handlers: Chain rtcChainRtcpSrReporter and rtcChainRtcpNackResponder (512 packet buffer) on the video track to enable sender reports and NACK-based retransmission.
  • Timestamping: Use rtcTransformSecondsToTimestamp/rtcSetTrackRtpTimestamp to set RTP timestamps before each send, replacing manual timestamp conversion.
  • Cleanup: Remove unused rtpMtu constant and ssrc field from H264Packetizer. Audio path (OpusPacketizer, RtpPacket) unchanged.
// Video track setup
try videoTrack.configureH264Packetizer(ssrc: videoSsrc, payloadType: h264PayloadType)

// Per-frame send: set timestamp, send raw NAL data (4-byte length prefix format)
videoTrack.setTimestamp(presentationTimeStamp: presentationTimeStamp)
videoTrack.send(packet: data)

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/eerimoq/moblin/pull/237 **Author:** [@Copilot](https://github.com/apps/copilot-swe-agent) **Created:** 2/14/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `copilot/add-rtp-packetizer-for-h264` --- ### 📝 Commits (3) - [`7264ae4`](https://github.com/eerimoq/moblin/commit/7264ae4372504f7cd1dc939af1f8669d908b31cf) Initial plan - [`13b909c`](https://github.com/eerimoq/moblin/commit/13b909c036165e5474796fc7245cebdc8cad927f) Use libdatachannel RTP packetizer for H264 in WHIP stream with NACK and SR handling - [`63737b9`](https://github.com/eerimoq/moblin/commit/63737b921754e6198328ccb5fa19960829792704) Extract magic numbers into named constants for readability ### 📊 Changes **1 file changed** (+68 additions, -101 deletions) <details> <summary>View changed files</summary> 📝 `Moblin/Media/HaishinKit/Whip/WhipStream.swift` (+68 -101) </details> ### 📄 Description Replace the custom H264 RTP packetizer with libdatachannel's built-in packetizer and register NACK/SR handlers so lost packets are retransmitted. - **H264 packetizer**: Configure `rtcSetH264Packetizer` on the video track instead of manually constructing RTP packets with FU-A fragmentation. The `H264Packetizer` class is simplified to only prepend SPS/PPS NAL units on keyframes—libdatachannel handles RTP header construction, sequencing, and fragmentation. - **RTCP handlers**: Chain `rtcChainRtcpSrReporter` and `rtcChainRtcpNackResponder` (512 packet buffer) on the video track to enable sender reports and NACK-based retransmission. - **Timestamping**: Use `rtcTransformSecondsToTimestamp`/`rtcSetTrackRtpTimestamp` to set RTP timestamps before each send, replacing manual timestamp conversion. - **Cleanup**: Remove unused `rtpMtu` constant and `ssrc` field from `H264Packetizer`. Audio path (`OpusPacketizer`, `RtpPacket`) unchanged. ```swift // Video track setup try videoTrack.configureH264Packetizer(ssrc: videoSsrc, payloadType: h264PayloadType) // Per-frame send: set timestamp, send raw NAL data (4-byte length prefix format) videoTrack.setTimestamp(presentationTimeStamp: presentationTimeStamp) videoTrack.send(packet: data) ``` <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-02 04:00:52 +03:00
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/moblin#239
No description provided.