| 
									
										
										
										
											2020-02-07 10:22:58 +00:00
										 |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "util.hh"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-01 07:54:23 +00:00
										 |  |  | #include <unordered_map>
 | 
					
						
							|  |  |  | #include <memory>
 | 
					
						
							| 
									
										
										
										
											2021-06-02 07:25:40 +00:00
										 |  |  | #include <string>
 | 
					
						
							| 
									
										
										
										
											2022-12-07 19:32:28 +00:00
										 |  |  | #include <atomic>
 | 
					
						
							| 
									
										
										
										
											2021-06-01 07:54:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-02 11:02:15 +00:00
										 |  |  | #ifndef _WIN32
 | 
					
						
							|  |  |  | #include <sys/socket.h>
 | 
					
						
							|  |  |  | #include <netinet/in.h>
 | 
					
						
							| 
									
										
										
										
											2023-03-13 08:39:25 +00:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2023-03-06 08:21:56 +00:00
										 |  |  | #include <ws2ipdef.h>
 | 
					
						
							| 
									
										
										
										
											2021-06-02 11:02:15 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2021-02-19 01:13:43 +00:00
										 |  |  | namespace uvgrtp { | 
					
						
							| 
									
										
										
										
											2020-02-07 10:22:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-02 07:25:40 +00:00
										 |  |  |     // forward declarations
 | 
					
						
							|  |  |  |     class rtp; | 
					
						
							|  |  |  |     class rtcp; | 
					
						
							| 
									
										
										
										
											2021-06-17 09:55:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     class zrtp; | 
					
						
							|  |  |  |     class base_srtp; | 
					
						
							| 
									
										
										
										
											2021-06-02 07:25:40 +00:00
										 |  |  |     class srtp; | 
					
						
							|  |  |  |     class srtcp; | 
					
						
							| 
									
										
										
										
											2021-06-17 09:55:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-03 06:57:49 +00:00
										 |  |  |     class reception_flow; | 
					
						
							| 
									
										
										
										
											2021-06-02 07:25:40 +00:00
										 |  |  |     class holepuncher; | 
					
						
							|  |  |  |     class socket; | 
					
						
							| 
									
										
										
										
											2023-04-05 09:18:50 +00:00
										 |  |  |     class socketfactory; | 
					
						
							| 
									
										
										
										
											2023-05-10 11:22:15 +00:00
										 |  |  |     class rtcp_reader; | 
					
						
							| 
									
										
										
										
											2021-06-02 07:25:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     namespace frame { | 
					
						
							|  |  |  |         struct rtp_frame; | 
					
						
							| 
									
										
										
										
											2022-02-28 06:46:04 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-06-02 07:25:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     namespace formats { | 
					
						
							|  |  |  |         class media; | 
					
						
							| 
									
										
										
										
											2022-02-28 06:46:04 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-06-02 07:25:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-15 04:53:59 +00:00
										 |  |  |     /**
 | 
					
						
							|  |  |  |      * \brief The media_stream is an entity which represents one RTP stream. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * \details media_stream is defined by the ports which are used for sending and/or receiving media.  | 
					
						
							|  |  |  |      * It is possible for media_stream to be bi- or unidirectional. The unidirectionality  | 
					
						
							|  |  |  |      * is achieved by specifying RCE_SEND_ONLY or RCE_RECEIVE_ONLY flag when creating media_stream.  | 
					
						
							|  |  |  |      *  | 
					
						
							|  |  |  |      * If RCE_RTCP was given when creating media_stream, you can get the uvgrtp::rtcp object with get_rtcp()-function. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * media_stream corresponds to one RTP session in <a href="https://www.rfc-editor.org/rfc/rfc3550">RFC 3550</a>. | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2020-02-07 10:22:58 +00:00
										 |  |  |     class media_stream { | 
					
						
							|  |  |  |         public: | 
					
						
							| 
									
										
										
										
											2021-02-14 07:35:31 +00:00
										 |  |  |             /// \cond DO_NOT_DOCUMENT
 | 
					
						
							| 
									
										
										
										
											2022-08-25 09:11:12 +00:00
										 |  |  |             media_stream(std::string cname, std::string remote_addr, std::string local_addr, uint16_t src_port, uint16_t dst_port, | 
					
						
							| 
									
										
										
										
											2023-04-05 09:18:50 +00:00
										 |  |  |                 rtp_format_t fmt, std::shared_ptr<uvgrtp::socketfactory> sfp, int rce_flags); | 
					
						
							| 
									
										
										
										
											2020-02-07 10:22:58 +00:00
										 |  |  |             ~media_stream(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             /* Initialize traditional RTP session
 | 
					
						
							|  |  |  |              * Allocate Connection/Reader/Writer objects and initialize them | 
					
						
							|  |  |  |              * | 
					
						
							|  |  |  |              * Return RTP_OK on success | 
					
						
							|  |  |  |              * Return RTP_MEMORY_ERROR if allocation failed | 
					
						
							|  |  |  |              * | 
					
						
							|  |  |  |              * Other error return codes are defined in {conn,writer,reader}.hh */ | 
					
						
							|  |  |  |             rtp_error_t init(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             /* Initialize Secure RTP session
 | 
					
						
							|  |  |  |              * Allocate Connection/Reader/Writer objects and initialize them | 
					
						
							|  |  |  |              * | 
					
						
							|  |  |  |              * Return RTP_OK on success | 
					
						
							|  |  |  |              * Return RTP_MEMORY_ERROR if allocation failed | 
					
						
							|  |  |  |              * | 
					
						
							| 
									
										
										
										
											2020-02-25 07:48:02 +00:00
										 |  |  |              * TODO document all error codes! | 
					
						
							|  |  |  |              * | 
					
						
							| 
									
										
										
										
											2020-02-07 10:22:58 +00:00
										 |  |  |              * Other error return codes are defined in {conn,writer,reader,srtp}.hh */ | 
					
						
							| 
									
										
										
										
											2022-02-04 06:35:56 +00:00
										 |  |  |             rtp_error_t init(std::shared_ptr<uvgrtp::zrtp> zrtp); | 
					
						
							| 
									
										
										
										
											2021-02-14 07:35:31 +00:00
										 |  |  |             /// \endcond
 | 
					
						
							| 
									
										
										
										
											2023-06-16 06:37:21 +00:00
										 |  |  |             rtp_error_t add_zrtp_ctx(); | 
					
						
							| 
									
										
										
										
											2021-02-23 12:29:06 +00:00
										 |  |  |             /**
 | 
					
						
							|  |  |  |              * | 
					
						
							|  |  |  |              * \brief Add keying information for user-managed SRTP session | 
					
						
							| 
									
										
										
										
											2020-04-29 22:45:28 +00:00
										 |  |  |              * | 
					
						
							| 
									
										
										
										
											2022-09-15 04:53:59 +00:00
										 |  |  |              * \details For user-managed SRTP session (flag RCE_SRTP_KMNGMNT_USER),  | 
					
						
							|  |  |  |              * the media stream is not started until SRTP key has been added and all calls  | 
					
						
							|  |  |  |              * to push_frame() will fail. | 
					
						
							| 
									
										
										
										
											2021-02-23 12:29:06 +00:00
										 |  |  |              * | 
					
						
							| 
									
										
										
										
											2021-04-22 09:39:07 +00:00
										 |  |  |              * \param key SRTP master key, default is 128-bit long | 
					
						
							| 
									
										
										
										
											2021-02-23 12:29:06 +00:00
										 |  |  |              * \param salt 112-bit long salt | 
					
						
							|  |  |  |              * | 
					
						
							|  |  |  |              * \return RTP error code | 
					
						
							|  |  |  |              * | 
					
						
							|  |  |  |              * \retval  RTP_OK On success | 
					
						
							|  |  |  |              * \retval  RTP_INVALID_VALUE If key or salt is invalid | 
					
						
							|  |  |  |              * \retval  RTP_NOT_SUPPORTED If user-managed SRTP was not specified in create_stream() */ | 
					
						
							| 
									
										
										
										
											2020-04-29 22:45:28 +00:00
										 |  |  |             rtp_error_t add_srtp_ctx(uint8_t *key, uint8_t *salt); | 
					
						
							| 
									
										
										
										
											2020-02-07 10:22:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-23 12:19:32 +00:00
										 |  |  |             /**
 | 
					
						
							|  |  |  |              * \brief Send data to remote participant with a custom timestamp | 
					
						
							| 
									
										
										
										
											2020-02-13 05:47:51 +00:00
										 |  |  |              * | 
					
						
							| 
									
										
										
										
											2021-02-23 12:19:32 +00:00
										 |  |  |              * \details If so specified either by the selected media format and/or given | 
					
						
							| 
									
										
										
										
											2022-09-16 13:31:19 +00:00
										 |  |  |              * ::RTP_CTX_ENABLE_FLAGS, uvgRTP fragments the input data into RTP packets of 1492 bytes, | 
					
						
							| 
									
										
										
										
											2021-02-23 12:19:32 +00:00
										 |  |  |              * or to any other size defined by the application using ::RCC_MTU_SIZE | 
					
						
							| 
									
										
										
										
											2020-02-13 05:47:51 +00:00
										 |  |  |              * | 
					
						
							| 
									
										
										
										
											2021-02-23 12:19:32 +00:00
										 |  |  |              * The frame is automatically reconstructed by the receiver if all fragments have been | 
					
						
							|  |  |  |              * received successfully. | 
					
						
							| 
									
										
										
										
											2020-02-13 05:47:51 +00:00
										 |  |  |              * | 
					
						
							| 
									
										
										
										
											2022-09-15 08:56:22 +00:00
										 |  |  |              * \param data Pointer to data the that should be sent, uvgRTP does not take ownership of the memory | 
					
						
							| 
									
										
										
										
											2021-02-23 12:19:32 +00:00
										 |  |  |              * \param data_len Length of data | 
					
						
							| 
									
										
										
										
											2022-08-23 06:47:07 +00:00
										 |  |  |              * \param rtp_flags Optional flags, see ::RTP_FLAGS for more details | 
					
						
							| 
									
										
										
										
											2020-02-13 05:47:51 +00:00
										 |  |  |              * | 
					
						
							| 
									
										
										
										
											2021-02-23 12:19:32 +00:00
										 |  |  |              * \return RTP error code | 
					
						
							| 
									
										
										
										
											2020-06-01 10:18:11 +00:00
										 |  |  |              * | 
					
						
							| 
									
										
										
										
											2021-02-23 12:19:32 +00:00
										 |  |  |              * \retval  RTP_OK            On success | 
					
						
							|  |  |  |              * \retval  RTP_INVALID_VALUE If one of the parameters are invalid | 
					
						
							|  |  |  |              * \retval  RTP_MEMORY_ERROR  If the data chunk is too large to be processed | 
					
						
							|  |  |  |              * \retval  RTP_SEND_ERROR    If uvgRTP failed to send the data to remote | 
					
						
							|  |  |  |              * \retval  RTP_GENERIC_ERROR If an unspecified error occurred | 
					
						
							|  |  |  |              */ | 
					
						
							| 
									
										
										
										
											2022-08-23 06:47:07 +00:00
										 |  |  |             rtp_error_t push_frame(uint8_t *data, size_t data_len, int rtp_flags); | 
					
						
							| 
									
										
										
										
											2021-02-23 12:19:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             /**
 | 
					
						
							|  |  |  |              * \brief Send data to remote participant with a custom timestamp | 
					
						
							|  |  |  |              * | 
					
						
							|  |  |  |              * \details If so specified either by the selected media format and/or given | 
					
						
							| 
									
										
										
										
											2022-09-16 13:31:19 +00:00
										 |  |  |              * ::RTP_CTX_ENABLE_FLAGS, uvgRTP fragments the input data into RTP packets of 1492 bytes, | 
					
						
							| 
									
										
										
										
											2021-02-23 12:19:32 +00:00
										 |  |  |              * or to any other size defined by the application using ::RCC_MTU_SIZE | 
					
						
							|  |  |  |              * | 
					
						
							|  |  |  |              * The frame is automatically reconstructed by the receiver if all fragments have been | 
					
						
							|  |  |  |              * received successfully. | 
					
						
							|  |  |  |              * | 
					
						
							|  |  |  |              * \param data Smart pointer to data the that should be sent | 
					
						
							|  |  |  |              * \param data_len Length of data | 
					
						
							| 
									
										
										
										
											2022-08-23 06:47:07 +00:00
										 |  |  |              * \param rtp_flags Optional flags, see ::RTP_FLAGS for more details | 
					
						
							| 
									
										
										
										
											2021-02-23 12:19:32 +00:00
										 |  |  |              * | 
					
						
							|  |  |  |              * \return RTP error code | 
					
						
							|  |  |  |              * | 
					
						
							|  |  |  |              * \retval  RTP_OK            On success | 
					
						
							|  |  |  |              * \retval  RTP_INVALID_VALUE If one of the parameters are invalid | 
					
						
							|  |  |  |              * \retval  RTP_MEMORY_ERROR  If the data chunk is too large to be processed | 
					
						
							|  |  |  |              * \retval  RTP_SEND_ERROR    If uvgRTP failed to send the data to remote | 
					
						
							|  |  |  |              * \retval  RTP_GENERIC_ERROR If an unspecified error occurred | 
					
						
							|  |  |  |              */ | 
					
						
							| 
									
										
										
										
											2022-08-23 06:47:07 +00:00
										 |  |  |             rtp_error_t push_frame(std::unique_ptr<uint8_t[]> data, size_t data_len, int rtp_flags); | 
					
						
							| 
									
										
										
										
											2021-02-23 12:19:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             /**
 | 
					
						
							|  |  |  |              * \brief Send data to remote participant with a custom timestamp | 
					
						
							|  |  |  |              * | 
					
						
							|  |  |  |              * \details If so specified either by the selected media format and/or given | 
					
						
							| 
									
										
										
										
											2022-09-16 13:31:19 +00:00
										 |  |  |              * ::RTP_CTX_ENABLE_FLAGS, uvgRTP fragments the input data into RTP packets of 1492 bytes, | 
					
						
							| 
									
										
										
										
											2021-02-23 12:19:32 +00:00
										 |  |  |              * or to any other size defined by the application using ::RCC_MTU_SIZE | 
					
						
							|  |  |  |              * | 
					
						
							|  |  |  |              * The frame is automatically reconstructed by the receiver if all fragments have been | 
					
						
							|  |  |  |              * received successfully. | 
					
						
							|  |  |  |              * | 
					
						
							|  |  |  |              * If application so wishes, it may override uvgRTP's own timestamp | 
					
						
							|  |  |  |              * calculations and provide timestamping information for the stream itself. | 
					
						
							|  |  |  |              * This requires that the application provides a sensible value for the ts | 
					
						
							|  |  |  |              * parameter. If RTCP has been enabled, uvgrtp::rtcp::set_ts_info() should have | 
					
						
							|  |  |  |              * been called. | 
					
						
							|  |  |  |              * | 
					
						
							| 
									
										
										
										
											2022-09-15 08:56:22 +00:00
										 |  |  |              * \param data Pointer to data the that should be sent, uvgRTP does not take ownership of the memory | 
					
						
							| 
									
										
										
										
											2021-02-23 12:19:32 +00:00
										 |  |  |              * \param data_len Length of data | 
					
						
							|  |  |  |              * \param ts 32-bit timestamp value for the data | 
					
						
							| 
									
										
										
										
											2022-08-23 06:47:07 +00:00
										 |  |  |              * \param rtp_flags Optional flags, see ::RTP_FLAGS for more details | 
					
						
							| 
									
										
										
										
											2021-02-23 12:19:32 +00:00
										 |  |  |              * | 
					
						
							|  |  |  |              * \return RTP error code | 
					
						
							|  |  |  |              * | 
					
						
							|  |  |  |              * \retval  RTP_OK            On success | 
					
						
							|  |  |  |              * \retval  RTP_INVALID_VALUE If one of the parameters are invalid | 
					
						
							|  |  |  |              * \retval  RTP_MEMORY_ERROR  If the data chunk is too large to be processed | 
					
						
							|  |  |  |              * \retval  RTP_SEND_ERROR    If uvgRTP failed to send the data to remote | 
					
						
							|  |  |  |              * \retval  RTP_GENERIC_ERROR If an unspecified error occurred | 
					
						
							|  |  |  |              */ | 
					
						
							| 
									
										
										
										
											2022-08-23 06:47:07 +00:00
										 |  |  |             rtp_error_t push_frame(uint8_t *data, size_t data_len, uint32_t ts, int rtp_flags); | 
					
						
							| 
									
										
										
										
											2021-02-23 12:19:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-06 12:26:39 +00:00
										 |  |  |             /**
 | 
					
						
							| 
									
										
										
										
											2023-03-13 12:35:11 +00:00
										 |  |  |             * \brief Send data to remote participant with custom RTP and NTP timestamps | 
					
						
							| 
									
										
										
										
											2023-02-06 12:26:39 +00:00
										 |  |  |             * | 
					
						
							|  |  |  |             * \details If so specified either by the selected media format and/or given | 
					
						
							|  |  |  |             * ::RTP_CTX_ENABLE_FLAGS, uvgRTP fragments the input data into RTP packets of 1492 bytes, | 
					
						
							|  |  |  |             * or to any other size defined by the application using ::RCC_MTU_SIZE | 
					
						
							|  |  |  |             * | 
					
						
							|  |  |  |             * The frame is automatically reconstructed by the receiver if all fragments have been | 
					
						
							|  |  |  |             * received successfully. | 
					
						
							|  |  |  |             * | 
					
						
							|  |  |  |             * If application so wishes, it may override uvgRTP's own timestamp | 
					
						
							|  |  |  |             * calculations and provide timestamping information for the stream itself. | 
					
						
							|  |  |  |             * This requires that the application provides a sensible value for the ts | 
					
						
							|  |  |  |             * parameter. If RTCP has been enabled, uvgrtp::rtcp::set_ts_info() should have | 
					
						
							|  |  |  |             * been called. | 
					
						
							|  |  |  |             * | 
					
						
							|  |  |  |             * \param data Pointer to data the that should be sent, uvgRTP does not take ownership of the memory | 
					
						
							|  |  |  |             * \param data_len Length of data | 
					
						
							| 
									
										
										
										
											2023-03-13 12:35:11 +00:00
										 |  |  |             * \param ts 32-bit RTP timestamp for the packet | 
					
						
							|  |  |  |             * \param ntp_ts 64-bit NTP timestamp value of when the packets data was sampled. NTP timestamp is a | 
					
						
							|  |  |  |             *  64-bit unsigned fixed-point number with the integer part (seconds) in the first 32 bits and the | 
					
						
							|  |  |  |             *  fractional part (fractional seconds) in the last 32 bits. Used for synchronizing multiple streams. | 
					
						
							| 
									
										
										
										
											2023-02-06 12:26:39 +00:00
										 |  |  |             * \param rtp_flags Optional flags, see ::RTP_FLAGS for more details | 
					
						
							|  |  |  |             * | 
					
						
							|  |  |  |             * \return RTP error code | 
					
						
							|  |  |  |             * | 
					
						
							|  |  |  |             * \retval  RTP_OK            On success | 
					
						
							|  |  |  |             * \retval  RTP_INVALID_VALUE If one of the parameters are invalid | 
					
						
							|  |  |  |             * \retval  RTP_MEMORY_ERROR  If the data chunk is too large to be processed | 
					
						
							|  |  |  |             * \retval  RTP_SEND_ERROR    If uvgRTP failed to send the data to remote | 
					
						
							|  |  |  |             * \retval  RTP_GENERIC_ERROR If an unspecified error occurred | 
					
						
							|  |  |  |             */ | 
					
						
							| 
									
										
										
										
											2023-03-13 12:35:11 +00:00
										 |  |  |             rtp_error_t push_frame(uint8_t* data, size_t data_len, uint32_t ts, uint64_t ntp_ts, int rtp_flags); | 
					
						
							| 
									
										
										
										
											2023-02-06 12:26:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-23 12:19:32 +00:00
										 |  |  |             /**
 | 
					
						
							|  |  |  |              * \brief Send data to remote participant with a custom timestamp | 
					
						
							|  |  |  |              * | 
					
						
							|  |  |  |              * \details If so specified either by the selected media format and/or given | 
					
						
							| 
									
										
										
										
											2022-09-16 13:31:19 +00:00
										 |  |  |              * ::RTP_CTX_ENABLE_FLAGS, uvgRTP fragments the input data into RTP packets of 1492 bytes, | 
					
						
							| 
									
										
										
										
											2021-02-23 12:19:32 +00:00
										 |  |  |              * or to any other size defined by the application using ::RCC_MTU_SIZE | 
					
						
							|  |  |  |              * | 
					
						
							|  |  |  |              * The frame is automatically reconstructed by the receiver if all fragments have been | 
					
						
							|  |  |  |              * received successfully. | 
					
						
							|  |  |  |              * | 
					
						
							|  |  |  |              * If application so wishes, it may override uvgRTP's own timestamp | 
					
						
							|  |  |  |              * calculations and provide timestamping information for the stream itself. | 
					
						
							|  |  |  |              * This requires that the application provides a sensible value for the ts | 
					
						
							|  |  |  |              * parameter. If RTCP has been enabled, uvgrtp::rtcp::set_ts_info() should have | 
					
						
							|  |  |  |              * been called. | 
					
						
							|  |  |  |              * | 
					
						
							|  |  |  |              * \param data Smart pointer to data the that should be sent | 
					
						
							|  |  |  |              * \param data_len Length of data | 
					
						
							|  |  |  |              * \param ts 32-bit timestamp value for the data | 
					
						
							| 
									
										
										
										
											2022-08-23 06:47:07 +00:00
										 |  |  |              * \param rtp_flags Optional flags, see ::RTP_FLAGS for more details | 
					
						
							| 
									
										
										
										
											2021-02-23 12:19:32 +00:00
										 |  |  |              * | 
					
						
							|  |  |  |              * \return RTP error code | 
					
						
							|  |  |  |              * | 
					
						
							|  |  |  |              * \retval  RTP_OK            On success | 
					
						
							|  |  |  |              * \retval  RTP_INVALID_VALUE If one of the parameters are invalid | 
					
						
							|  |  |  |              * \retval  RTP_MEMORY_ERROR  If the data chunk is too large to be processed | 
					
						
							|  |  |  |              * \retval  RTP_SEND_ERROR    If uvgRTP failed to send the data to remote | 
					
						
							| 
									
										
										
										
											2021-02-23 12:23:50 +00:00
										 |  |  |              * \retval  RTP_GENERIC_ERROR If an unspecified error occurred | 
					
						
							|  |  |  |              */ | 
					
						
							| 
									
										
										
										
											2022-08-23 06:47:07 +00:00
										 |  |  |             rtp_error_t push_frame(std::unique_ptr<uint8_t[]> data, size_t data_len, uint32_t ts, int rtp_flags); | 
					
						
							| 
									
										
										
										
											2020-02-07 10:22:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-06 12:26:39 +00:00
										 |  |  |             /**
 | 
					
						
							| 
									
										
										
										
											2023-03-13 12:35:11 +00:00
										 |  |  |              * \brief Send data to remote participant with custom RTP and NTP timestamps | 
					
						
							| 
									
										
										
										
											2023-02-06 12:26:39 +00:00
										 |  |  |              * | 
					
						
							|  |  |  |              * \details If so specified either by the selected media format and/or given | 
					
						
							|  |  |  |              * ::RTP_CTX_ENABLE_FLAGS, uvgRTP fragments the input data into RTP packets of 1492 bytes, | 
					
						
							|  |  |  |              * or to any other size defined by the application using ::RCC_MTU_SIZE | 
					
						
							|  |  |  |              * | 
					
						
							|  |  |  |              * The frame is automatically reconstructed by the receiver if all fragments have been | 
					
						
							|  |  |  |              * received successfully. | 
					
						
							|  |  |  |              * | 
					
						
							|  |  |  |              * If application so wishes, it may override uvgRTP's own timestamp | 
					
						
							|  |  |  |              * calculations and provide timestamping information for the stream itself. | 
					
						
							|  |  |  |              * This requires that the application provides a sensible value for the ts | 
					
						
							|  |  |  |              * parameter. If RTCP has been enabled, uvgrtp::rtcp::set_ts_info() should have | 
					
						
							|  |  |  |              * been called. | 
					
						
							|  |  |  |              * | 
					
						
							|  |  |  |              * \param data Smart pointer to data the that should be sent | 
					
						
							|  |  |  |              * \param data_len Length of data | 
					
						
							| 
									
										
										
										
											2023-03-13 12:35:11 +00:00
										 |  |  |              * \param ts 32-bit RTP timestamp for the packet | 
					
						
							|  |  |  |              * \param ntp_ts 64-bit NTP timestamp value of when the packets data was sampled. NTP timestamp is a | 
					
						
							|  |  |  |              *  64-bit unsigned fixed-point number with the integer part (seconds) in the first 32 bits and the | 
					
						
							|  |  |  |              *  fractional part (fractional seconds) in the last 32 bits. Used for synchronizing multiple streams. | 
					
						
							| 
									
										
										
										
											2023-02-06 12:26:39 +00:00
										 |  |  |              * \param rtp_flags Optional flags, see ::RTP_FLAGS for more details | 
					
						
							|  |  |  |              * | 
					
						
							|  |  |  |              * \return RTP error code | 
					
						
							|  |  |  |              * | 
					
						
							|  |  |  |              * \retval  RTP_OK            On success | 
					
						
							|  |  |  |              * \retval  RTP_INVALID_VALUE If one of the parameters are invalid | 
					
						
							|  |  |  |              * \retval  RTP_MEMORY_ERROR  If the data chunk is too large to be processed | 
					
						
							|  |  |  |              * \retval  RTP_SEND_ERROR    If uvgRTP failed to send the data to remote | 
					
						
							|  |  |  |              * \retval  RTP_GENERIC_ERROR If an unspecified error occurred | 
					
						
							|  |  |  |              */ | 
					
						
							| 
									
										
										
										
											2023-03-13 12:35:11 +00:00
										 |  |  |             rtp_error_t push_frame(std::unique_ptr<uint8_t[]> data, size_t data_len, uint32_t ts, uint64_t ntp_ts, int rtp_flags); | 
					
						
							| 
									
										
										
										
											2023-02-06 12:26:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-29 11:06:44 +00:00
										 |  |  |             /* ----------- User packets not yet supported -----------
 | 
					
						
							| 
									
										
										
										
											2023-06-16 09:46:27 +00:00
										 |  |  |             rtp_error_t push_user_frame(uint8_t* data, uint32_t payload_size, | 
					
						
							| 
									
										
										
										
											2023-05-12 10:25:26 +00:00
										 |  |  |                 std::string remote_address, uint16_t port); | 
					
						
							|  |  |  |             rtp_error_t install_user_hook(void* arg, void (*hook)(void*, uint8_t* payload)); | 
					
						
							| 
									
										
										
										
											2023-05-29 11:06:44 +00:00
										 |  |  |             */ | 
					
						
							| 
									
										
										
										
											2023-05-12 10:25:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-14 07:35:31 +00:00
										 |  |  |             /**
 | 
					
						
							| 
									
										
										
										
											2021-02-23 12:23:50 +00:00
										 |  |  |              * \brief Poll a frame indefinitely from the media stream object | 
					
						
							| 
									
										
										
										
											2020-02-13 05:47:51 +00:00
										 |  |  |              * | 
					
						
							| 
									
										
										
										
											2021-02-23 12:23:50 +00:00
										 |  |  |              * \return RTP frame | 
					
						
							| 
									
										
										
										
											2020-05-11 14:36:13 +00:00
										 |  |  |              * | 
					
						
							| 
									
										
										
										
											2021-02-23 12:23:50 +00:00
										 |  |  |              * \retval uvgrtp::frame::rtp_frame* On success | 
					
						
							|  |  |  |              * \retval nullptr If an unrecoverable error happened | 
					
						
							|  |  |  |              */ | 
					
						
							| 
									
										
										
										
											2021-02-19 01:13:43 +00:00
										 |  |  |             uvgrtp::frame::rtp_frame *pull_frame(); | 
					
						
							| 
									
										
										
										
											2021-02-14 07:35:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             /**
 | 
					
						
							|  |  |  |              * \brief Poll a frame for a specified time from the media stream object | 
					
						
							|  |  |  |              * | 
					
						
							| 
									
										
										
										
											2021-09-16 09:04:38 +00:00
										 |  |  |              * \param timeout_ms How long is a frame waited, in milliseconds | 
					
						
							| 
									
										
										
										
											2021-02-24 01:31:43 +00:00
										 |  |  |              * | 
					
						
							|  |  |  |              * \return RTP frame | 
					
						
							| 
									
										
										
										
											2021-02-14 07:35:31 +00:00
										 |  |  |              * | 
					
						
							| 
									
										
										
										
											2021-02-23 12:23:50 +00:00
										 |  |  |              * \retval uvgrtp::frame::rtp_frame* On success | 
					
						
							| 
									
										
										
										
											2022-09-15 04:53:59 +00:00
										 |  |  |              * \retval nullptr If a frame was not received within the specified time limit or in case of an error | 
					
						
							| 
									
										
										
										
											2021-02-23 12:23:50 +00:00
										 |  |  |              */ | 
					
						
							| 
									
										
										
										
											2021-09-16 09:04:38 +00:00
										 |  |  |             uvgrtp::frame::rtp_frame *pull_frame(size_t timeout_ms); | 
					
						
							| 
									
										
										
										
											2020-02-07 10:22:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-23 11:57:55 +00:00
										 |  |  |             /**
 | 
					
						
							|  |  |  |              * \brief Asynchronous way of getting frames | 
					
						
							| 
									
										
										
										
											2020-02-13 05:47:51 +00:00
										 |  |  |              * | 
					
						
							| 
									
										
										
										
											2021-02-23 11:57:55 +00:00
										 |  |  |              * \details Receive hook is an alternative to polling frames using uvgrtp::media_stream::pull_frame(). | 
					
						
							|  |  |  |              * Instead of application asking from uvgRTP if there are any new frames available, uvgRTP will notify | 
					
						
							|  |  |  |              * the application when a frame has been received | 
					
						
							| 
									
										
										
										
											2020-02-13 05:47:51 +00:00
										 |  |  |              * | 
					
						
							| 
									
										
										
										
											2021-02-23 11:57:55 +00:00
										 |  |  |              * The hook should not be used for media processing as it will block the receiver from | 
					
						
							|  |  |  |              * reading more frames. Instead, it should only be used as an interface between uvgRTP and | 
					
						
							|  |  |  |              * the calling application where the frame hand-off happens. | 
					
						
							| 
									
										
										
										
											2020-02-13 05:47:51 +00:00
										 |  |  |              * | 
					
						
							| 
									
										
										
										
											2021-02-23 11:57:55 +00:00
										 |  |  |              * \param arg Optional argument that is passed to the hook when it is called, can be set to nullptr | 
					
						
							|  |  |  |              * \param hook Function pointer to the receive hook that uvgRTP should call | 
					
						
							|  |  |  |              * | 
					
						
							|  |  |  |              * \return RTP error code | 
					
						
							|  |  |  |              * | 
					
						
							|  |  |  |              * \retval RTP_OK On success | 
					
						
							|  |  |  |              * \retval RTP_INVALID_VALUE If hook is nullptr */ | 
					
						
							| 
									
										
										
										
											2021-02-19 01:13:43 +00:00
										 |  |  |             rtp_error_t install_receive_hook(void *arg, void (*hook)(void *, uvgrtp::frame::rtp_frame *)); | 
					
						
							| 
									
										
										
										
											2020-02-07 10:22:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-14 07:35:31 +00:00
										 |  |  |             /**
 | 
					
						
							|  |  |  |              * \brief Configure the media stream, see ::RTP_CTX_CONFIGURATION_FLAGS for more details | 
					
						
							| 
									
										
										
										
											2020-02-13 05:47:51 +00:00
										 |  |  |              * | 
					
						
							| 
									
										
										
										
											2021-02-14 07:35:31 +00:00
										 |  |  |              * \return RTP error code | 
					
						
							| 
									
										
										
										
											2020-02-13 05:47:51 +00:00
										 |  |  |              * | 
					
						
							| 
									
										
										
										
											2021-02-14 07:35:31 +00:00
										 |  |  |              * \retval RTP_OK On success | 
					
						
							|  |  |  |              * \retval RTP_INVALID_VALUE If the provided value is not valid for a given configuration flag | 
					
						
							|  |  |  |              * \retval RTP_GENERIC_ERROR If setsockopt(2) failed | 
					
						
							|  |  |  |              */ | 
					
						
							| 
									
										
										
										
											2022-08-23 06:47:07 +00:00
										 |  |  |             rtp_error_t configure_ctx(int rcc_flag, ssize_t value); | 
					
						
							| 
									
										
										
										
											2020-02-10 07:04:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-10 13:18:25 +00:00
										 |  |  |             /**
 | 
					
						
							| 
									
										
										
										
											2023-05-11 09:31:46 +00:00
										 |  |  |              * \brief Get the values associated with configuration flags, see ::RTP_CTX_CONFIGURATION_FLAGS for more details | 
					
						
							| 
									
										
										
										
											2023-05-10 13:18:25 +00:00
										 |  |  |              * | 
					
						
							|  |  |  |              * \return Value of the configuration flag | 
					
						
							|  |  |  |              * | 
					
						
							|  |  |  |              * \retval int value on success | 
					
						
							| 
									
										
										
										
											2023-06-15 10:48:50 +00:00
										 |  |  |              * \retval -1 on error | 
					
						
							| 
									
										
										
										
											2023-05-10 13:18:25 +00:00
										 |  |  |              */ | 
					
						
							|  |  |  |             int get_configuration_value(int rcc_flag); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-14 07:35:31 +00:00
										 |  |  |             /// \cond DO_NOT_DOCUMENT
 | 
					
						
							| 
									
										
										
										
											2020-02-10 07:04:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-25 07:48:02 +00:00
										 |  |  |             /* Get unique key of the media stream
 | 
					
						
							|  |  |  |              * Used by session to index media streams */ | 
					
						
							| 
									
										
										
										
											2022-05-16 09:02:37 +00:00
										 |  |  |             uint32_t get_key() const; | 
					
						
							| 
									
										
										
										
											2023-04-05 06:43:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-14 07:35:31 +00:00
										 |  |  |             /// \endcond
 | 
					
						
							| 
									
										
										
										
											2020-02-21 07:20:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-14 07:35:31 +00:00
										 |  |  |             /**
 | 
					
						
							|  |  |  |              * \brief Get pointer to the RTCP object of the media stream | 
					
						
							|  |  |  |              * | 
					
						
							|  |  |  |              * \details This object is used to control all RTCP-related functionality | 
					
						
							| 
									
										
										
										
											2021-02-19 01:13:43 +00:00
										 |  |  |              * and RTCP documentation can be found from \ref uvgrtp::rtcp | 
					
						
							| 
									
										
										
										
											2020-06-17 04:55:47 +00:00
										 |  |  |              * | 
					
						
							| 
									
										
										
										
											2021-02-14 07:35:31 +00:00
										 |  |  |              * \return Pointer to RTCP object | 
					
						
							| 
									
										
										
										
											2020-06-17 04:55:47 +00:00
										 |  |  |              * | 
					
						
							| 
									
										
										
										
											2021-02-19 01:13:43 +00:00
										 |  |  |              * \retval uvgrtp::rtcp* If RTCP has been enabled (RCE_RTCP has been given to uvgrtp::session::create_stream()) | 
					
						
							| 
									
										
										
										
											2021-02-14 07:35:31 +00:00
										 |  |  |              * \retval nullptr        If RTCP has not been enabled | 
					
						
							|  |  |  |              */ | 
					
						
							| 
									
										
										
										
											2021-02-19 01:13:43 +00:00
										 |  |  |             uvgrtp::rtcp *get_rtcp(); | 
					
						
							| 
									
										
										
										
											2020-06-17 04:55:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-15 04:53:59 +00:00
										 |  |  |             /**
 | 
					
						
							|  |  |  |              * \brief Get SSRC identifier. You can use the SSRC value for example to find the report  | 
					
						
							|  |  |  |              * block belonging to this media_stream in RTCP sender/receiver report. | 
					
						
							|  |  |  |              * | 
					
						
							|  |  |  |              * \return SSRC value | 
					
						
							|  |  |  |              */ | 
					
						
							| 
									
										
										
										
											2022-05-16 07:52:55 +00:00
										 |  |  |             uint32_t get_ssrc() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-07 10:22:58 +00:00
										 |  |  |         private: | 
					
						
							| 
									
										
										
										
											2020-02-10 07:13:31 +00:00
										 |  |  |             /* Initialize the connection by initializing the socket
 | 
					
						
							|  |  |  |              * and binding ourselves to specified interface and creating | 
					
						
							|  |  |  |              * an outgoing address */ | 
					
						
							|  |  |  |             rtp_error_t init_connection(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-25 00:47:18 +00:00
										 |  |  |             /* Create the media object for the stream */ | 
					
						
							|  |  |  |             rtp_error_t create_media(rtp_format_t fmt); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-25 22:30:22 +00:00
										 |  |  |             /* free all allocated resources */ | 
					
						
							|  |  |  |             rtp_error_t free_resources(rtp_error_t ret); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-23 06:47:07 +00:00
										 |  |  |             rtp_error_t init_srtp_with_zrtp(int rce_flags, int type, std::shared_ptr<uvgrtp::base_srtp> srtp, | 
					
						
							| 
									
										
										
										
											2022-02-04 06:35:56 +00:00
										 |  |  |                                             std::shared_ptr<uvgrtp::zrtp> zrtp); | 
					
						
							| 
									
										
										
										
											2021-06-17 09:55:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-03 09:39:12 +00:00
										 |  |  |             rtp_error_t start_components(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 12:32:20 +00:00
										 |  |  |             rtp_error_t install_packet_handlers(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-25 15:02:51 +00:00
										 |  |  |             uint32_t get_default_bandwidth_kbps(rtp_format_t fmt); | 
					
						
							| 
									
										
										
										
											2022-05-27 08:33:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-06 07:45:19 +00:00
										 |  |  |             bool check_pull_preconditions(); | 
					
						
							| 
									
										
										
										
											2022-09-09 10:29:50 +00:00
										 |  |  |             rtp_error_t check_push_preconditions(int rtp_flags, bool smart_pointer); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-15 08:56:22 +00:00
										 |  |  |             inline uint8_t* copy_frame(uint8_t* original, size_t data_len); | 
					
						
							| 
									
										
										
										
											2022-09-06 07:45:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-07 10:22:58 +00:00
										 |  |  |             uint32_t key_; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-03 08:44:04 +00:00
										 |  |  |             std::shared_ptr<uvgrtp::srtp>   srtp_; | 
					
						
							|  |  |  |             std::shared_ptr<uvgrtp::srtcp>  srtcp_; | 
					
						
							| 
									
										
										
										
											2022-03-03 08:31:36 +00:00
										 |  |  |             std::shared_ptr<uvgrtp::socket> socket_; | 
					
						
							| 
									
										
										
										
											2022-03-03 08:44:04 +00:00
										 |  |  |             std::shared_ptr<uvgrtp::rtp>    rtp_; | 
					
						
							| 
									
										
										
										
											2022-03-03 08:48:51 +00:00
										 |  |  |             std::shared_ptr<uvgrtp::rtcp>   rtcp_; | 
					
						
							| 
									
										
										
										
											2023-06-16 09:46:27 +00:00
										 |  |  |             std::shared_ptr<uvgrtp::zrtp>   zrtp_; | 
					
						
							| 
									
										
										
										
											2020-02-07 10:22:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-05 09:18:50 +00:00
										 |  |  |             std::shared_ptr<uvgrtp::socketfactory> sfp_; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-23 08:32:21 +00:00
										 |  |  |             sockaddr_in remote_sockaddr_; | 
					
						
							| 
									
										
										
										
											2023-03-06 08:21:56 +00:00
										 |  |  |             sockaddr_in6 remote_sockaddr_ip6_; | 
					
						
							| 
									
										
										
										
											2022-08-23 08:32:21 +00:00
										 |  |  |             std::string remote_address_; | 
					
						
							|  |  |  |             std::string local_address_; | 
					
						
							| 
									
										
										
										
											2022-08-25 09:11:12 +00:00
										 |  |  |             uint16_t src_port_; | 
					
						
							|  |  |  |             uint16_t dst_port_; | 
					
						
							| 
									
										
										
										
											2023-03-06 08:21:56 +00:00
										 |  |  |             bool ipv6_; | 
					
						
							| 
									
										
										
										
											2020-02-07 10:22:58 +00:00
										 |  |  |             rtp_format_t fmt_; | 
					
						
							| 
									
										
										
										
											2023-04-19 12:19:50 +00:00
										 |  |  |             bool new_socket_; | 
					
						
							| 
									
										
										
										
											2020-02-10 07:04:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-03 06:57:49 +00:00
										 |  |  |             /* Media context config */ | 
					
						
							| 
									
										
										
										
											2022-08-25 09:11:12 +00:00
										 |  |  |             int rce_flags_ = 0; | 
					
						
							| 
									
										
										
										
											2020-02-10 07:04:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-29 22:45:28 +00:00
										 |  |  |             /* Has the media stream been initialized */ | 
					
						
							|  |  |  |             bool initialized_; | 
					
						
							| 
									
										
										
										
											2020-06-17 05:23:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-03 09:43:26 +00:00
										 |  |  |             /* RTP packet reception flow. Dispatches packets to other components */ | 
					
						
							| 
									
										
										
										
											2023-04-25 10:51:45 +00:00
										 |  |  |             std::shared_ptr<uvgrtp::reception_flow> reception_flow_; | 
					
						
							| 
									
										
										
										
											2020-08-04 05:53:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             /* Media object associated with this media stream. */ | 
					
						
							| 
									
										
										
										
											2022-03-03 09:48:50 +00:00
										 |  |  |             std::unique_ptr<uvgrtp::formats::media> media_; | 
					
						
							| 
									
										
										
										
											2021-02-14 01:36:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             /* Thread that keeps the holepunched connection open for unidirectional streams */ | 
					
						
							| 
									
										
										
										
											2022-03-03 09:52:15 +00:00
										 |  |  |             std::unique_ptr<uvgrtp::holepuncher> holepuncher_; | 
					
						
							| 
									
										
										
										
											2022-07-07 16:29:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             std::string cname_; | 
					
						
							| 
									
										
										
										
											2022-08-19 12:22:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-19 11:43:08 +00:00
										 |  |  |             ssize_t fps_numerator_ = 30; | 
					
						
							| 
									
										
										
										
											2022-08-25 09:11:12 +00:00
										 |  |  |             ssize_t fps_denominator_ = 1; | 
					
						
							| 
									
										
										
										
											2022-12-19 11:35:06 +00:00
										 |  |  |             uint32_t bandwidth_ = 0; | 
					
						
							| 
									
										
										
										
											2022-12-07 19:32:28 +00:00
										 |  |  |             std::shared_ptr<std::atomic<std::uint32_t>> ssrc_; | 
					
						
							| 
									
										
										
										
											2023-04-19 09:47:36 +00:00
										 |  |  |             std::shared_ptr<std::atomic<std::uint32_t>> remote_ssrc_; | 
					
						
							| 
									
										
										
										
											2023-05-11 09:31:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             // Save values associated with context flags, to be returned with get_configuration_value
 | 
					
						
							|  |  |  |             // Values are initialized to -2, which means value not set
 | 
					
						
							|  |  |  |             int snd_buf_size_; | 
					
						
							|  |  |  |             int rcv_buf_size_; | 
					
						
							| 
									
										
										
										
											2020-02-07 10:22:58 +00:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2022-02-28 06:46:04 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2021-02-19 01:13:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace uvg_rtp = uvgrtp; |