1*6236dae4SAndroid Build Coastguard Worker--- 2*6236dae4SAndroid Build Coastguard Workerc: Copyright (C) Daniel Stenberg, <[email protected]>, et al. 3*6236dae4SAndroid Build Coastguard WorkerSPDX-License-Identifier: curl 4*6236dae4SAndroid Build Coastguard WorkerTitle: CURLOPT_INTERLEAVEFUNCTION 5*6236dae4SAndroid Build Coastguard WorkerSection: 3 6*6236dae4SAndroid Build Coastguard WorkerSource: libcurl 7*6236dae4SAndroid Build Coastguard WorkerSee-also: 8*6236dae4SAndroid Build Coastguard Worker - CURLOPT_INTERLEAVEDATA (3) 9*6236dae4SAndroid Build Coastguard Worker - CURLOPT_RTSP_REQUEST (3) 10*6236dae4SAndroid Build Coastguard WorkerProtocol: 11*6236dae4SAndroid Build Coastguard Worker - RTSP 12*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.20.0 13*6236dae4SAndroid Build Coastguard Worker--- 14*6236dae4SAndroid Build Coastguard Worker 15*6236dae4SAndroid Build Coastguard Worker# NAME 16*6236dae4SAndroid Build Coastguard Worker 17*6236dae4SAndroid Build Coastguard WorkerCURLOPT_INTERLEAVEFUNCTION - callback for RTSP interleaved data 18*6236dae4SAndroid Build Coastguard Worker 19*6236dae4SAndroid Build Coastguard Worker# SYNOPSIS 20*6236dae4SAndroid Build Coastguard Worker 21*6236dae4SAndroid Build Coastguard Worker~~~c 22*6236dae4SAndroid Build Coastguard Worker#include <curl/curl.h> 23*6236dae4SAndroid Build Coastguard Worker 24*6236dae4SAndroid Build Coastguard Workersize_t interleave_callback(void *ptr, size_t size, size_t nmemb, 25*6236dae4SAndroid Build Coastguard Worker void *userdata); 26*6236dae4SAndroid Build Coastguard Worker 27*6236dae4SAndroid Build Coastguard WorkerCURLcode curl_easy_setopt(CURL *handle, CURLOPT_INTERLEAVEFUNCTION, 28*6236dae4SAndroid Build Coastguard Worker interleave_callback); 29*6236dae4SAndroid Build Coastguard Worker~~~ 30*6236dae4SAndroid Build Coastguard Worker 31*6236dae4SAndroid Build Coastguard Worker# DESCRIPTION 32*6236dae4SAndroid Build Coastguard Worker 33*6236dae4SAndroid Build Coastguard WorkerPass a pointer to your callback function, which should match the prototype 34*6236dae4SAndroid Build Coastguard Workershown above. 35*6236dae4SAndroid Build Coastguard Worker 36*6236dae4SAndroid Build Coastguard WorkerThis callback function gets called by libcurl as soon as it has received 37*6236dae4SAndroid Build Coastguard Workerinterleaved RTP data. This function gets called for each $ block and therefore 38*6236dae4SAndroid Build Coastguard Workercontains exactly one upper-layer protocol unit (e.g. one RTP packet). Curl 39*6236dae4SAndroid Build Coastguard Workerwrites the interleaved header as well as the included data for each call. The 40*6236dae4SAndroid Build Coastguard Workerfirst byte is always an ASCII dollar sign. The dollar sign is followed by a 41*6236dae4SAndroid Build Coastguard Workerone byte channel identifier and then a 2 byte integer length in network byte 42*6236dae4SAndroid Build Coastguard Workerorder. See RFC 2326 Section 10.12 for more information on how RTP interleaving 43*6236dae4SAndroid Build Coastguard Workerbehaves. If unset or set to NULL, curl uses the default write function. 44*6236dae4SAndroid Build Coastguard Worker 45*6236dae4SAndroid Build Coastguard WorkerInterleaved RTP poses some challenges for the client application. Since the 46*6236dae4SAndroid Build Coastguard Workerstream data is sharing the RTSP control connection, it is critical to service 47*6236dae4SAndroid Build Coastguard Workerthe RTP in a timely fashion. If the RTP data is not handled quickly, 48*6236dae4SAndroid Build Coastguard Workersubsequent response processing may become unreasonably delayed and the 49*6236dae4SAndroid Build Coastguard Workerconnection may close. The application may use *CURL_RTSPREQ_RECEIVE* to 50*6236dae4SAndroid Build Coastguard Workerservice RTP data when no requests are desired. If the application makes a 51*6236dae4SAndroid Build Coastguard Workerrequest, (e.g. *CURL_RTSPREQ_PAUSE*) then the response handler processes 52*6236dae4SAndroid Build Coastguard Workerany pending RTP data before marking the request as finished. 53*6236dae4SAndroid Build Coastguard Worker 54*6236dae4SAndroid Build Coastguard WorkerThe CURLOPT_INTERLEAVEDATA(3) is passed in the *userdata* argument in 55*6236dae4SAndroid Build Coastguard Workerthe callback. 56*6236dae4SAndroid Build Coastguard Worker 57*6236dae4SAndroid Build Coastguard WorkerYour callback should return the number of bytes actually taken care of. If 58*6236dae4SAndroid Build Coastguard Workerthat amount differs from the amount passed to your callback function, it 59*6236dae4SAndroid Build Coastguard Workersignals an error condition to the library. This causes the transfer to abort 60*6236dae4SAndroid Build Coastguard Workerand the libcurl function used returns *CURLE_WRITE_ERROR*. 61*6236dae4SAndroid Build Coastguard Worker 62*6236dae4SAndroid Build Coastguard WorkerYou can also abort the transfer by returning CURL_WRITEFUNC_ERROR. (7.87.0) 63*6236dae4SAndroid Build Coastguard Worker 64*6236dae4SAndroid Build Coastguard Worker# DEFAULT 65*6236dae4SAndroid Build Coastguard Worker 66*6236dae4SAndroid Build Coastguard WorkerNULL, the interleave data is then passed to the regular write function: 67*6236dae4SAndroid Build Coastguard WorkerCURLOPT_WRITEFUNCTION(3). 68*6236dae4SAndroid Build Coastguard Worker 69*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS% 70*6236dae4SAndroid Build Coastguard Worker 71*6236dae4SAndroid Build Coastguard Worker# EXAMPLE 72*6236dae4SAndroid Build Coastguard Worker 73*6236dae4SAndroid Build Coastguard Worker~~~c 74*6236dae4SAndroid Build Coastguard Workerstruct local { 75*6236dae4SAndroid Build Coastguard Worker void *custom; 76*6236dae4SAndroid Build Coastguard Worker}; 77*6236dae4SAndroid Build Coastguard Worker 78*6236dae4SAndroid Build Coastguard Workerstatic size_t rtp_write(void *ptr, size_t size, size_t nmemb, void *userp) 79*6236dae4SAndroid Build Coastguard Worker{ 80*6236dae4SAndroid Build Coastguard Worker struct local *l = userp; 81*6236dae4SAndroid Build Coastguard Worker printf("our ptr: %p\n", l->custom); 82*6236dae4SAndroid Build Coastguard Worker /* take care of the packet in 'ptr', then return... */ 83*6236dae4SAndroid Build Coastguard Worker return size * nmemb; 84*6236dae4SAndroid Build Coastguard Worker} 85*6236dae4SAndroid Build Coastguard Worker 86*6236dae4SAndroid Build Coastguard Workerint main(void) 87*6236dae4SAndroid Build Coastguard Worker{ 88*6236dae4SAndroid Build Coastguard Worker struct local rtp_data; 89*6236dae4SAndroid Build Coastguard Worker CURL *curl = curl_easy_init(); 90*6236dae4SAndroid Build Coastguard Worker if(curl) { 91*6236dae4SAndroid Build Coastguard Worker curl_easy_setopt(curl, CURLOPT_INTERLEAVEFUNCTION, rtp_write); 92*6236dae4SAndroid Build Coastguard Worker curl_easy_setopt(curl, CURLOPT_INTERLEAVEDATA, &rtp_data); 93*6236dae4SAndroid Build Coastguard Worker } 94*6236dae4SAndroid Build Coastguard Worker} 95*6236dae4SAndroid Build Coastguard Worker~~~ 96*6236dae4SAndroid Build Coastguard Worker 97*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY% 98*6236dae4SAndroid Build Coastguard Worker 99*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE 100*6236dae4SAndroid Build Coastguard Worker 101*6236dae4SAndroid Build Coastguard WorkerReturns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. 102