CURLOPT_INTERLEAVEFUNCTION.3 3.0 KB

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