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