CURLOPT_IN...VEFUNCTION(3)
π NAME π
CURLOPT_INTERLEAVEFUNCTION β okay so this is the callback for RTSP interleaved data, and yes bestie the page header is literally CURLOPT_IN...VEFUNCTION(3) because it got truncated, that's just how the Library Functions Manual rolls, iykyk π
β¨ SYNOPSIS β¨
#include <curl/curl.h>
size_t interleave_callback(void *ptr, size_t size, size_t nmemb,
void *userdata);
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_INTERLEAVEFUNCTION,
interleave_callback);
π¦ DESCRIPTION π¦
So you pass in a pointer to your callback function, and it has to match the prototype up there. No improvising, okay?
This callback gets called by libcurl the literal second it has received interleaved RTP data. It gets called for each $ block, so each call contains exactly one upper-layer protocol unit (like, one RTP packet, for example). curl writes the interleaved header as well as the included data on every single call. The first byte is always an ASCII dollar sign π° β and that dollar sign is followed by a one byte channel identifier, and then a 2 byte integer length in network byte order. If you wanna know more about how RTP interleaving behaves, go read RFC 2326 Section 10.12. And if this is unset or set to NULL, curl just uses the default write function, no biggie.
Bestie, interleaved RTP is lowkey a lot for the client application. Since the stream data is sharing the RTSP control connection, servicing the RTP in a timely fashion is, like, critical. If the RTP data is not handled quickly, subsequent response processing may become unreasonably delayed and the connection may close π. The application may useCURL_RTSPREQ_RECEIVEto service RTP data when no requests are desired. And if the application makes a request (e.g.CURL_RTSPREQ_PAUSE) then the response handler processes any pending RTP data before marking the request as finished.
Also, CURLOPT_INTERLEAVEDATA(3) is what gets passed in the userdata argument in the callback. That's the vibe. π«Ά
Your callback should return the number of bytes actually taken care of. If that amount differs from the amount passed to your callback function, it signals an error condition to the library β the transfer aborts and the libcurl function used returns CURLE_WRITE_ERROR. π
You can also abort the transfer by returning CURL_WRITEFUNC_ERROR. (7.87.0) β¨
πΈ DEFAULT πΈ
NULL β the interleave data is then passed to the regular write function: CURLOPT_WRITEFUNCTION(3).
π PROTOCOLS π
This functionality affects rtsp only. That's it. That's the whole protocol list. π
π EXAMPLE π
struct local {
void *custom;
};
static size_t rtp_write(void *ptr, size_t size, size_t nmemb, void *userp)
{
struct local *l = userp;
printf("our ptr: %p\n", l->custom);
/* take care of the packet in 'ptr', then return... */
return size * nmemb;
}
int main(void)
{
struct local rtp_data;
CURL *curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_INTERLEAVEFUNCTION, rtp_write);
curl_easy_setopt(curl, CURLOPT_INTERLEAVEDATA, &rtp_data);
}
}
β AVAILABILITY β
Added in curl 7.20.0 β vintage, but make it cute π
π RETURN VALUE π
curl_easy_setopt(3) returns a CURLcode indicating success or error.
CURLE_OK (0) means everything was OK π₯³, and non-zero means an error occurred, so go see libcurl-errors(3).
π SEE ALSO π
and that's the whole page bestie, xoxo π
This one's from the libcurl fam, dated 2026-10-12 β see you in the next manpage, mwah π§ββοΈβ¨
π¦ where this page comes from
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms