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