MP4(3)

πŸ“¦ version 2.1.0, in fedora 43, fedora 44

πŸ’– MP4(3) β€” the MP4 File Format Library, bestie edition πŸ’–

okay so you're here for MP4ReadRtpPacket, and honestly? iconic behavior. this is a page from the MP4 File Format Library manual (section 3, library calls, if you're keeping score πŸŽ€), and I'm gonna walk you through every single bit of it. grab a snack. let's go. ✨


🌸 NAME 🌸

MP4ReadRtpPacket β€” read an RTP packet. that's it, that's the whole job. she reads one packet. queen of doing one thing well. πŸ‘‘


✨ SYNTAX ✨

#include <mp4.h>

bool MP4ReadRtpPacket(
     MP4FileHandle hFile,
     MP4TrackId trackId,
     u_int16_t packetIndex,
     u_int8_t** ppBytes,
     u_int32_t* pNumBytes,
     u_int32_t ssrc = 0,
     bool includeHeader = true,
     bool includePayload = true
);

look at that signature. the way it has defaults?? ssrc = 0, includeHeader = true, includePayload = true. C++ vibes in a C library, we love a lil flexibility. 🫢


πŸ¦‹ ARGUMENTS πŸ¦‹

  • hFile β€” the mp4 file we're operating on. which file? this file. point at it, love it, pass it in. πŸ’…
  • trackId β€” the hint track we're operating on. not just any track, bestie. the hint track specifically.
  • packetIndex β€” which packet do you want? valid values run from zero up to the number of packets in this hint minus one. so like, zero-indexed, as the universe intended. 🌈
  • pNumPackets β€” pointer to a variable that will hold the number of packets in the hint. (yes she's listed here, no she's not in the signature above β€” I don't make the rules, I just report them faithfully. 😭)
  • ppBytes β€” pointer to the pointer to the packet data. this one's spicy, there are two whole buffering strategies for it, scroll down to DESCRIPTION, I promise it's worth it. πŸ“
  • pNumBytes β€” pointer to a variable that will hold the size, in bytes, of the packet. so you know how big the thing you just got is. very demure, very mindful. ✨
  • ssrc β€” the RTP SSRC to use when constructing the RTP packet header. it's the whole "who made this stream" ID.
  • includeHeader β€” should the library bolt the standard 12 byte RTP header onto the returned packet? the header gets constructed from the info in the hint sample plus the ssrc you passed. yes/no, your call. πŸŽ€
  • includePayload β€” should the library include the packet payload (that's the RTP payload header and the media data) in the returned packet? again, your call.

πŸ’œ RETURN VALUES πŸ’œ

  • success? true (1). slay. βœ…
  • error? false (0). not slay, but at least it's honest. πŸ’€

πŸ‘‘ DESCRIPTION πŸ‘‘

MP4ReadRtpPacket reads the specified packet from the current hint sample β€” and that hint sample is whatever was previously read by MP4ReadRtpHint(). so read your hint first, then come get your packet. order matters, no cap. πŸ”₯


🧚 the ppBytes situation (two ways to buffer, pick your fighter)

Route one: you bring your own buffer. if the calling application wants to handle its own buffering, it can set *ppBytes to the buffer it wishes to use. and then β€” plot twist β€” the calling application is responsible for ensuring that the buffer is large enough to hold the packet. you can figure out how big is big enough by using MP4GetRtpPayload() to retrieve the maximum packet payload size, which tells you how large the receiving buffer must be. ⚠️ Caveat: the value returned by MP4GetRtpPayload is the maxiumum payload size β€” so if the RTP packet header is going to be included by the library, you should increment that value by 12. don't forget the 12. the 12 is not optional. 🫠

Route two: let the library handle it. if the value of *ppBytes is NULL, then an appropriately sized buffer is automatically malloc'ed for the sample data, and *ppBytes gets set to that pointer. sounds great right? well. the calling application is responsible for free'ing this memory. you asked for the malloc, you do the free. that's the deal. πŸ’…


🌟 about that SSRC 🌟

the application is expected to provide the value of the RTP SSRC identifier, which uniquely identifies the originator of the media stream. for most applications, a single random value can be provided. and here's the vibe check: the value should be the same for all packets for the duration of the RTP transmission. consistency is key, bestie. 🫢

oh and β€” if the parameter "includeHeader" is false, then this value has no effect. so don't stress about it if you're not asking for headers. πŸ™ˆ

πŸŽ€ what actually comes back (by default) πŸŽ€

by default, the library:

  1. constructs the standard 12 byte RTP header from the information in the hint sample, plus the specified SSRC, and
  2. then concatenates that RTP header with the packet payload β€” meaning the RTP payload specific header and the media data for the packet.

and the "includeHeader" and "includePayload" parameters let you control those steps, so that either just the packet payloads or just the RTP headers can be returned. πŸ¦‹

a potential use of this feature: if the calling application wishes to construct an extended RTP header with non-standard options. go off, build your weird header, we support you. 🌈


⭐ SEE ALSO ⭐


and that's the whole page, bestie!! πŸ’– you now know MP4ReadRtpPacket better than the people who wrote it (jk jk, they're Cisco). this manual page came to you from Cisco Systems Inc., at Version 0.9 β€” so like, treat it as the classic that it is, and go read some RTP packets. periodt. πŸ’…βœ¨πŸŽ€πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from