CURLOPT_INTERLEAVEFUNCTION.md (3174B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLOPT_INTERLEAVEFUNCTION 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLOPT_INTERLEAVEDATA (3) 9 - CURLOPT_RTSP_REQUEST (3) 10 Protocol: 11 - RTSP 12 Added-in: 7.20.0 13 --- 14 15 # NAME 16 17 CURLOPT_INTERLEAVEFUNCTION - callback for RTSP interleaved data 18 19 # SYNOPSIS 20 21 ~~~c 22 #include <curl/curl.h> 23 24 size_t interleave_callback(void *ptr, size_t size, size_t nmemb, 25 void *userdata); 26 27 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_INTERLEAVEFUNCTION, 28 interleave_callback); 29 ~~~ 30 31 # DESCRIPTION 32 33 Pass a pointer to your callback function, which should match the prototype 34 shown above. 35 36 This callback function gets called by libcurl as soon as it has received 37 interleaved RTP data. This function gets called for each $ block and therefore 38 contains exactly one upper-layer protocol unit (e.g. one RTP packet). curl 39 writes the interleaved header as well as the included data for each call. The 40 first byte is always an ASCII dollar sign. The dollar sign is followed by a 41 one byte channel identifier and then a 2 byte integer length in network byte 42 order. See RFC 2326 Section 10.12 for more information on how RTP interleaving 43 behaves. If unset or set to NULL, curl uses the default write function. 44 45 Interleaved RTP poses some challenges for the client application. Since the 46 stream data is sharing the RTSP control connection, it is critical to service 47 the RTP in a timely fashion. If the RTP data is not handled quickly, 48 subsequent response processing may become unreasonably delayed and the 49 connection may close. The application may use *CURL_RTSPREQ_RECEIVE* to 50 service RTP data when no requests are desired. If the application makes a 51 request, (e.g. *CURL_RTSPREQ_PAUSE*) then the response handler processes 52 any pending RTP data before marking the request as finished. 53 54 The CURLOPT_INTERLEAVEDATA(3) is passed in the *userdata* argument in 55 the callback. 56 57 Your callback should return the number of bytes actually taken care of. If 58 that amount differs from the amount passed to your callback function, it 59 signals an error condition to the library. This causes the transfer to abort 60 and the libcurl function used returns *CURLE_WRITE_ERROR*. 61 62 You can also abort the transfer by returning CURL_WRITEFUNC_ERROR. (7.87.0) 63 64 # DEFAULT 65 66 NULL, the interleave data is then passed to the regular write function: 67 CURLOPT_WRITEFUNCTION(3). 68 69 # %PROTOCOLS% 70 71 # EXAMPLE 72 73 ~~~c 74 struct local { 75 void *custom; 76 }; 77 78 static size_t rtp_write(void *ptr, size_t size, size_t nmemb, void *userp) 79 { 80 struct local *l = userp; 81 printf("our ptr: %p\n", l->custom); 82 /* take care of the packet in 'ptr', then return... */ 83 return size * nmemb; 84 } 85 86 int main(void) 87 { 88 struct local rtp_data; 89 CURL *curl = curl_easy_init(); 90 if(curl) { 91 curl_easy_setopt(curl, CURLOPT_INTERLEAVEFUNCTION, rtp_write); 92 curl_easy_setopt(curl, CURLOPT_INTERLEAVEDATA, &rtp_data); 93 } 94 } 95 ~~~ 96 97 # %AVAILABILITY% 98 99 # RETURN VALUE 100 101 curl_easy_setopt(3) returns a CURLcode indicating success or error. 102 103 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 104 libcurl-errors(3).