1 /*
2 *			GPAC - Multimedia Framework C SDK
3 *
4 *			Authors: Jean Le Feuvre
5 *			Copyright (c) Telecom ParisTech 2000-2012
6 *					All rights reserved
7 *
8 *  This file is part of GPAC / IETF RTP/RTSP/SDP sub-project
9 *
10 *  GPAC is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU Lesser General Public License as published by
12 *  the Free Software Foundation; either version 2, or (at your option)
13 *  any later version.
14 *
15 *  GPAC is distributed in the hope that it will be useful,
16 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 *  GNU Lesser General Public License for more details.
19 *
20 *  You should have received a copy of the GNU Lesser General Public
21 *  License along with this library; see the file COPYING.  If not, write to
22 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 */
25 
26 
27 #ifndef	_GF_IETF_H_
28 #define _GF_IETF_H_
29 
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 	/*!
36 	*	\file <gpac/ietf.h>
37 	*	\brief Tools for real-time streaming over IP using RTP/RTCP/RTSP/SDP .
38 	*/
39 
40 	/*!
41 	*	\addtogroup ietf_grp RTP Streaming
42 	*	\ingroup media_grp
43 	*	\brief  Tools for real-time streaming over IP using RTP/RTCP/RTSP/SDP.
44 	*
45 	*This section documents the tools used for real-time streaming over IP using RTP/RTCP/RTSP/SDP.
46 	*	@{
47 	*/
48 
49 #include <gpac/list.h>
50 
51 #ifndef GPAC_DISABLE_STREAMING
52 
53 #include <gpac/bitstream.h>
54 #include <gpac/sync_layer.h>
55 #include <gpac/network.h>
56 
57 
58 	/****************************************************************************
59 
60 	RTSP VERSION 1.0 LIBRARY EXPORTS
61 
62 	****************************************************************************/
63 
64 #define GF_RTSP_VERSION		"RTSP/1.0"
65 
66 
67 	/*
68 	*		RTSP NOTIF CODES
69 	*/
70 	enum
71 	{
72 		NC_RTSP_Continue = 100,
73 		NC_RTSP_OK = 200,
74 		NC_RTSP_Created = 201,
75 		NC_RTSP_Low_on_Storage_Space = 250,
76 
77 		NC_RTSP_Multiple_Choice = 300,
78 		NC_RTSP_Moved_Permanently = 301,
79 		NC_RTSP_Moved_Temporarily = 302,
80 		NC_RTSP_See_Other = 303,
81 		NC_RTSP_Use_Proxy = 305,
82 
83 		NC_RTSP_Bad_Request = 400,
84 		NC_RTSP_Unauthorized = 401,
85 		NC_RTSP_Payment_Required = 402,
86 		NC_RTSP_Forbidden = 403,
87 		NC_RTSP_Not_Found = 404,
88 		NC_RTSP_Method_Not_Allowed = 405,
89 		NC_RTSP_Not_Acceptable = 406,
90 		NC_RTSP_Proxy_Authentication_Required = 407,
91 		NC_RTSP_Request_Timeout = 408,
92 		NC_RTSP_Gone = 410,
93 		NC_RTSP_Length_Required = 411,
94 		NC_RTSP_Precondition_Failed = 412,
95 		NC_RTSP_Request_Entity_Too_Large = 413,
96 		NC_RTSP_Request_URI_Too_Long = 414,
97 		NC_RTSP_Unsupported_Media_Type = 415,
98 
99 		NC_RTSP_Invalid_parameter = 451,
100 		NC_RTSP_Illegal_Conference_Identifier = 452,
101 		NC_RTSP_Not_Enough_Bandwidth = 453,
102 		NC_RTSP_Session_Not_Found = 454,
103 		NC_RTSP_Method_Not_Valid_In_This_State = 455,
104 		NC_RTSP_Header_Field_Not_Valid = 456,
105 		NC_RTSP_Invalid_Range = 457,
106 		NC_RTSP_Parameter_Is_ReadOnly = 458,
107 		NC_RTSP_Aggregate_Operation_Not_Allowed = 459,
108 		NC_RTSP_Only_Aggregate_Operation_Allowed = 460,
109 		NC_RTSP_Unsupported_Transport = 461,
110 		NC_RTSP_Destination_Unreachable = 462,
111 
112 		NC_RTSP_Internal_Server_Error = 500,
113 		NC_RTSP_Not_Implemented = 501,
114 		NC_RTSP_Bad_Gateway = 502,
115 		NC_RTSP_Service_Unavailable = 503,
116 		NC_RTSP_Gateway_Timeout = 504,
117 		NC_RTSP_RTSP_Version_Not_Supported = 505,
118 
119 		NC_RTSP_Option_not_support = 551,
120 	};
121 
122 	const char *gf_rtsp_nc_to_string(u32 ErrCode);
123 
124 	/*
125 	Common structures between commands and responses
126 	*/
127 
128 	/*
129 	RTSP Range information - RTSP Session level only (though this is almost the same
130 	format as an SDP range, this is not used in the SDP lib as "a=range" is not part of SDP
131 	but part of RTSP
132 	*/
133 	typedef struct {
134 		/* start and end range. If end is -1, the range is open (from start to unknown) */
135 		Double start, end;
136 		/* use SMPTE range (Start and End specify the number of frames) (currently not supported) */
137 		u32 UseSMPTE;
138 		/* framerate for SMPTE range */
139 		Double FPS;
140 	} GF_RTSPRange;
141 
142 	/*
143 	parses a Range line and returns range header structure. can be used for RTSP extension of SDP
144 	NB: Only support for npt for now
145 	*/
146 	GF_RTSPRange *gf_rtsp_range_parse(char *range_buf);
147 
148 	GF_RTSPRange *gf_rtsp_range_new();
149 	void gf_rtsp_range_del(GF_RTSPRange *range);
150 
151 	/*
152 	Transport structure
153 	contains all network info for RTSP sessions (ports, uni/multi-cast, ...)
154 	*/
155 
156 	/*
157 	Transport Profiles as defined in RFC 2326
158 	*/
159 #define GF_RTSP_PROFILE_RTP_AVP			"RTP/AVP"
160 #define GF_RTSP_PROFILE_RTP_AVP_TCP		"RTP/AVP/TCP"
161 #define GF_RTSP_PROFILE_UDP				"udp"
162 
163 
164 	typedef struct
165 	{
166 		/* set to 1 if unicast */
167 		Bool IsUnicast;
168 		/* for multicast */
169 		char *destination;
170 		/* for redirections internal to servers */
171 		char *source;
172 		/*IsRecord is usually 0 (PLAY) . If set, Append specify that the stream should
173 		be concatenated to existing resources */
174 		Bool IsRecord, Append;
175 		/* in case transport is on TCP/RTSP, If only 1 ID is specified, it is stored in rtpID (this
176 		is not RTP interleaving) */
177 		Bool IsInterleaved;
178 		u32 rtpID, rtcpID;
179 		/* Multicast specific */
180 		u32 MulticastLayers;
181 		u8 TTL;
182 		/*RTP specific*/
183 
184 		/*port for multicast*/
185 		/*server port in unicast - RTP implies low is even , and last is low+1*/
186 		u16 port_first, port_last;
187 		/*client port in unicast - RTP implies low is even , and last is low+1*/
188 		u16 client_port_first, client_port_last;
189 		u32 SSRC;
190 
191 		/*Transport protocol. In this version we only support RTP/AVP, the following flag tells
192 		us if this is RTP/AVP/TCP or RTP/AVP (default)*/
193 		char *Profile;
194 	} GF_RTSPTransport;
195 
196 
197 	GF_RTSPTransport *gf_rtsp_transport_clone(GF_RTSPTransport *original);
198 	void gf_rtsp_transport_del(GF_RTSPTransport *transp);
199 
200 
201 	/*
202 	RTSP Command
203 	the RTSP Response is sent by a client / received by a server
204 	text Allocation is done by the lib when parsing a command, and
205 	is automatically freed when calling reset / delete. Therefore you must
206 	set/allocate the fields yourself when writing a command (client)
207 
208 	*/
209 
210 	/*ALL RTSP METHODS - all other methods will be ignored*/
211 #define GF_RTSP_DESCRIBE		"DESCRIBE"
212 #define GF_RTSP_SETUP			"SETUP"
213 #define GF_RTSP_PLAY			"PLAY"
214 #define GF_RTSP_PAUSE			"PAUSE"
215 #define GF_RTSP_RECORD			"RECORD"
216 #define GF_RTSP_TEARDOWN		"TEARDOWN"
217 #define GF_RTSP_GET_PARAMETER	"GET_PARAMETER"
218 #define GF_RTSP_SET_PARAMETER	"SET_PARAMETER"
219 #define GF_RTSP_OPTIONS		"OPTIONS"
220 #define GF_RTSP_ANNOUNCE		"ANNOUNCE"
221 #define GF_RTSP_REDIRECTE		"REDIRECT"
222 
223 
224 	typedef struct
225 	{
226 		char *Accept;
227 		char *Accept_Encoding;
228 		char *Accept_Language;
229 		char *Authorization;
230 		u32 Bandwidth;
231 		u32 Blocksize;
232 		char *Cache_Control;
233 		char *Conference;
234 		char *Connection;
235 		u32 Content_Length;
236 		u32 CSeq;
237 		char *From;
238 		char *Proxy_Authorization;
239 		char *Proxy_Require;
240 		GF_RTSPRange *Range;
241 		char *Referer;
242 		Double Scale;
243 		char *Session;
244 		Double Speed;
245 		/*nota : RTSP allows several configurations for a single channel (multicast and
246 		unicast , ...). Usually only 1*/
247 		GF_List *Transports;
248 		char *User_Agent;
249 
250 		/*type of the command, one of the described above*/
251 		char *method;
252 
253 		/*Header extensions*/
254 		GF_List *Xtensions;
255 
256 		/*body of the command, size is Content-Length (auto computed when sent). It is not
257 		terminated by a NULL char*/
258 		char *body;
259 
260 		/*
261 		Specify ControlString if your request targets
262 		a specific media stream in the service. If null, the service name only will be used
263 		for control (for ex, both A and V streams in a single file)
264 		If the request is GF_RTSP_OPTIONS, you must provide a control string containing the options
265 		you want to query
266 		*/
267 		char *ControlString;
268 
269 		/*user data: this is never touched by the lib, its intend is to help stacking
270 		RTSP commands in your app*/
271 		void *user_data;
272 
273 
274 		/*
275 		Server side Extensions
276 		*/
277 
278 		/*full URL of the command. Not used at client side, as the URL is ALWAYS relative
279 		to the server / service of the RTSP session
280 		On the server side however redirections are up to the server, so we cannot decide for it	*/
281 		char *service_name;
282 		/*RTSP status code of the command as parsed. One of the above RTSP StatusCode*/
283 		u32 StatusCode;
284 	} GF_RTSPCommand;
285 
286 
287 	GF_RTSPCommand *gf_rtsp_command_new();
288 	void gf_rtsp_command_del(GF_RTSPCommand *com);
289 	void gf_rtsp_command_reset(GF_RTSPCommand *com);
290 
291 
292 
293 	/*
294 	RTSP Response
295 	the RTSP Response is received by a client / sent by a server
296 	text Allocation is done by the lib when parsing a response, and
297 	is automatically freed when calling reset / delete. Therefore you must
298 	allocate the fields yourself when writing a response (server)
299 
300 	*/
301 
302 	/*
303 	RTP-Info for RTP channels. There may be several RTP-Infos in one response
304 	based on the server implementation (DSS/QTSS begaves this way)
305 	*/
306 	typedef struct
307 	{
308 		/*control string of the channel*/
309 		char *url;
310 		/*seq num for asociated rtp_time*/
311 		u32 seq;
312 		/*rtp TimeStamp corresponding to the Range start specified in the PLAY request*/
313 		u32 rtp_time;
314 		/*ssrc of sender if known, 0 otherwise*/
315 		u32 ssrc;
316 	} GF_RTPInfo;
317 
318 
319 
320 	/*
321 	RTSP Response
322 	*/
323 	typedef struct
324 	{
325 		/* response code*/
326 		u32 ResponseCode;
327 		/* comment from the server */
328 		char *ResponseInfo;
329 
330 		/*	Header Fields	*/
331 		char *Accept;
332 		char *Accept_Encoding;
333 		char *Accept_Language;
334 		char *Allow;
335 		char *Authorization;
336 		u32 Bandwidth;
337 		u32 Blocksize;
338 		char *Cache_Control;
339 		char *Conference;
340 		char *Connection;
341 		char *Content_Base;
342 		char *Content_Encoding;
343 		char *Content_Language;
344 		u32 Content_Length;
345 		char *Content_Location;
346 		char *Content_Type;
347 		u32 CSeq;
348 		char *Date;
349 		char *Expires;
350 		char *From;
351 		char *Host;
352 		char *If_Match;
353 		char *If_Modified_Since;
354 		char *Last_Modified;
355 		char *Location;
356 		char *Proxy_Authenticate;
357 		char *Proxy_Require;
358 		char *Public;
359 		GF_RTSPRange *Range;
360 		char *Referer;
361 		char *Require;
362 		char *Retry_After;
363 		GF_List *RTP_Infos;
364 		Double Scale;
365 		char *Server;
366 		char *Session;
367 		u32 SessionTimeOut;
368 		Double Speed;
369 		u32 StreamID; //only when sess->satip is true
370 		char *Timestamp;
371 		/*nota : RTSP allows several configurations for a single channel (multicast and
372 		unicast , ...). Usually only 1*/
373 		GF_List *Transports;
374 		char *Unsupported;
375 		char *User_Agent;
376 		char *Vary;
377 		char *Via;
378 		char *WWW_Authenticate;
379 
380 		/*Header extensions*/
381 		GF_List *Xtensions;
382 
383 		/*body of the response, size is Content-Length (auto computed when sent). It is not
384 		terminated by a NULL char when response is parsed but must be null-terminated when
385 		response is being sent*/
386 		char *body;
387 	} GF_RTSPResponse;
388 
389 
390 	GF_RTSPResponse *gf_rtsp_response_new();
391 	void gf_rtsp_response_del(GF_RTSPResponse *rsp);
392 	void gf_rtsp_response_reset(GF_RTSPResponse *rsp);
393 
394 
395 
396 	typedef struct _tag_rtsp_session GF_RTSPSession;
397 
398 	GF_RTSPSession *gf_rtsp_session_new(char *sURL, u16 DefaultPort);
399 	void gf_rtsp_session_del(GF_RTSPSession *sess);
400 
401 	GF_Err gf_rtsp_set_buffer_size(GF_RTSPSession *sess, u32 BufferSize);
402 
403 	/*force the IP address the client is using*/
404 	void gf_rtsp_set_mobile_ip(GF_RTSPSession *sess, char *MobileIP);
405 
406 
407 	/*Reset state machine, invalidate SessionID
408 	NOTE: RFC2326 requires that the session is reseted when all RTP streams
409 	are closed. As this lib doesn't maintain the number of valid streams
410 	you MUST call reset when all your streams are shutdown (either requested through
411 	TEARDOWN or signaled through RTCP BYE packets for RTP, or any other signaling means
412 	for other protocols)
413 	reset connection will destroy the socket - this is useful in case of timeouts, because
414 	some servers do not restart with the right CSeq...*/
415 	void gf_rtsp_session_reset(GF_RTSPSession *sess, Bool ResetConnection);
416 
417 	u32 gf_rtsp_is_my_session(GF_RTSPSession *sess, char *url);
418 	const char *gf_rtsp_get_last_session_id(GF_RTSPSession *sess);
419 	char *gf_rtsp_get_server_name(GF_RTSPSession *sess);
420 	char *gf_rtsp_get_service_name(GF_RTSPSession *sess);
421 	u16 gf_rtsp_get_session_port(GF_RTSPSession *sess);
422 
423 	/*Fetch an RTSP response from the server the GF_RTSPResponse will be reseted before fetch*/
424 	GF_Err gf_rtsp_get_response(GF_RTSPSession *sess, GF_RTSPResponse *rsp);
425 
426 
427 	/*RTSP State Machine. The only non blocking mode is GF_RTSP_STATE_WAIT_FOR_CONTROL*/
428 	enum
429 	{
430 		/*Initialized (connection might be off, but all structures are in place)
431 		This is the default state between # requests (aka, DESCRIBE and SETUP
432 		or SETUP and PLAY ...)*/
433 		GF_RTSP_STATE_INIT = 0,
434 		/*Waiting*/
435 		GF_RTSP_STATE_WAITING,
436 		/*PLAY, PAUSE, RECORD. Aggregation is allowed for the same type, you can send several command
437 		in a row. However the session will return GF_SERVICE_ERROR if you do not have
438 		a valid SessionID in the command
439 		You cannot issue a SETUP / DESCRIBE while in this state*/
440 		GF_RTSP_STATE_WAIT_FOR_CONTROL,
441 
442 		/*FATAL ERROR: session is invalidated by server. Call reset and restart from SETUP if needed*/
443 		GF_RTSP_STATE_INVALIDATED
444 	};
445 
446 	u32 gf_rtsp_get_session_state(GF_RTSPSession *sess);
447 	/*aggregate command state-machine: the PLAY/PAUSE can be aggregated
448 	(sent before the reply is received). This function gets the last command sent*/
449 	char *gf_rtsp_get_last_request(GF_RTSPSession *sess);
450 	/*foce a reset in case of pbs*/
451 	void gf_rtsp_reset_aggregation(GF_RTSPSession *sess);
452 
453 	/*
454 	Send an RTSP request to the server.
455 	*/
456 	GF_Err gf_rtsp_send_command(GF_RTSPSession *sess, GF_RTSPCommand *com);
457 
458 
459 	GF_Err gf_rtsp_set_interleave_callback(GF_RTSPSession *sess,
460 		GF_Err(*SignalData)(GF_RTSPSession *sess, void *cbk_ptr, char *buffer, u32 bufferSize, Bool IsRTCP)
461 	);
462 
463 
464 	GF_Err gf_rtsp_session_read(GF_RTSPSession *sess);
465 
466 	GF_Err gf_rtsp_register_interleave(GF_RTSPSession *sess, void *the_ch, u8 LowInterID, u8 HighInterID);
467 	u32 gf_rtsp_unregister_interleave(GF_RTSPSession *sess, u8 LowInterID);
468 
469 
470 
471 	/*
472 	Server side session constructor
473 	create a new RTSP session from an existing socket in listen state. If no pending connection
474 	is detected, return NULL
475 	*/
476 	GF_RTSPSession *gf_rtsp_session_new_server(GF_Socket *rtsp_listener);
477 
478 	/*fetch an RTSP request. The GF_RTSPCommand will be reseted before fetch*/
479 	GF_Err gf_rtsp_get_command(GF_RTSPSession *sess, GF_RTSPCommand *com);
480 
481 	/*unpack the URL, check the service name / server. Typically used when a client sends a
482 	DESCRIBE || SETUP url RTSP/1.0. Server / service name check must be performed by your app as redirection
483 	or services available are unknown here.*/
484 	GF_Err gf_rtsp_load_service_name(GF_RTSPSession *sess, char *URL);
485 
486 	/*geenrates a session ID fpor the given session*/
487 	char *gf_rtsp_generate_session_id(GF_RTSPSession *sess);
488 
489 	/*send the RTSP response*/
490 	GF_Err gf_rtsp_send_response(GF_RTSPSession *sess, GF_RTSPResponse *rsp);
491 
492 	/*gets the IP address of the local host running the session
493 	buffer shall be GF_MAX_IP_NAME_LEN long*/
494 	GF_Err gf_rtsp_get_session_ip(GF_RTSPSession *sess, char *buffer);
495 
496 	/*returns the next available ID for interleaving. It is recommended that you use 2
497 	consecutive IDs for RTP/RTCP interleaving*/
498 	u8 gf_rtsp_get_next_interleave_id(GF_RTSPSession *sess);
499 
500 	/*gets the IP address of the connected peer - buffer shall be GF_MAX_IP_NAME_LEN long*/
501 	GF_Err gf_rtsp_get_remote_address(GF_RTSPSession *sess, char *buffer);
502 
503 
504 	/*
505 	RTP LIB EXPORTS
506 	*/
507 
508 
509 	typedef struct tagRTP_HEADER {
510 		/*version, must be 2*/
511 		u8 Version;
512 		/*padding bits in the payload*/
513 		u8 Padding;
514 		/*header extension is defined*/
515 		u8 Extension;
516 		/*number of CSRC (<=15)*/
517 		u8 CSRCCount;
518 		/*Marker Bit*/
519 		u8 Marker;
520 		/*payload type on 7 bits*/
521 		u8 PayloadType;
522 		/*packet seq number*/
523 		u16 SequenceNumber;
524 		/*packet time stamp*/
525 		u32 TimeStamp;
526 		/*sync source identifier*/
527 		u32 SSRC;
528 		/*in our basic client, CSRC should always be NULL*/
529 		u32 CSRC[16];
530 
531 		/*internal to out lib*/
532 		u64 recomputed_ntp_ts;
533 	} GF_RTPHeader;
534 
535 
536 
537 
538 	/*
539 	structure containing the rtpmap information
540 	*/
541 	typedef struct
542 	{
543 		/*dynamic payload type of this map*/
544 		u32 PayloadType;
545 		/*registered payload name of this map*/
546 		char *payload_name;
547 		/*RTP clock rate (TS resolution) of this map*/
548 		u32 ClockRate;
549 		/*optional parameters for audio, specifying number of channels. Unused for other media types.*/
550 		u32 AudioChannels;
551 	} GF_RTPMap;
552 
553 
554 
555 	typedef struct __tag_rtp_channel GF_RTPChannel;
556 
557 	GF_RTPChannel *gf_rtp_new();
558 	void gf_rtp_del(GF_RTPChannel *ch);
559 
560 	/*you configure a server channel through the transport structure, with the same info as a
561 	client channel, the client_port_* info designing the REMOTE client and port_* designing
562 	your server channel*/
563 	GF_Err gf_rtp_setup_transport(GF_RTPChannel *ch, GF_RTSPTransport *trans_info, const char *remote_address);
564 
565 	/*auto-setup of rtp/rtcp transport ports - only effective in unicast, non interleaved cases.
566 	for multicast port setup MUST be done through the above gf_rtp_setup_transport function
567 	this will take care of port reuse*/
568 	GF_Err gf_rtp_set_ports(GF_RTPChannel *ch, u16 first_port);
569 
570 	/*init of payload information. only ONE payload per sync source is supported in this
571 	version of the library (a sender cannot switch payload types on a single media)*/
572 	GF_Err gf_rtp_setup_payload(GF_RTPChannel *ch, GF_RTPMap *map);
573 
574 	/*enables sending of NAT keep-alive packets for NAT traversal
575 	@nat_timeout: specifies the inactivity period in ms after which NAT keepalive packets are sent.
576 	If 0, disables NAT keep-alive packets
577 	*/
578 	void gf_rtp_enable_nat_keepalive(GF_RTPChannel *ch, u32 nat_timeout);
579 
580 
581 	/*initialize the RTP channel.
582 
583 	UDPBufferSize: UDP stack buffer size if configurable by OS/ISP - ignored otherwise
584 	NOTE: on WinCE devices, this is not configurable on an app bases but for the whole OS
585 	you must update the device registry with:
586 	[HKEY_LOCAL_MACHINE\Comm\Afd]
587 	DgramBuffer=dword:N
588 
589 	where N is the number of UDP datagrams a socket should be able to buffer. For multimedia
590 	app you should set N as large as possible. The device MUST be reseted for the param to take effect
591 
592 	ReorederingSize: max number of packets to queue for reordering. 0 means no reordering
593 	MaxReorderDelay: max time to wait in ms before releasing first packet in reoderer when only one packet is present.
594 	If 0 and reordering size is specified, defaults to 200 ms (usually enough).
595 	IsSource: if true, the channel is a sender (media data, sender report, Receiver report processing)
596 	if source, you must specify the Path MTU size. The RTP lib won't send any packet bigger than this size
597 	your application shall perform payload size splitting if needed
598 	local_interface_ip: local interface address to use for multicast. If NULL, default address is used
599 	*/
600 	GF_Err gf_rtp_initialize(GF_RTPChannel *ch, u32 UDPBufferSize, Bool IsSource, u32 PathMTU, u32 ReorederingSize, u32 MaxReorderDelay, char *local_interface_ip);
601 
602 	/* stop the RTP channel: destrpys RTP and RTCP sockets as well as packet reorderer*/
603 	GF_Err gf_rtp_stop(GF_RTPChannel *ch);
604 
605 	/*init the RTP info after a PLAY or PAUSE, rtp_time is the rtp TimeStamp of the RTP packet
606 	with seq_num sequence number. This info is needed to compute the CurrentTime of the RTP channel
607 	ssrc may not be known if sender hasn't indicated it (use 0 then)*/
608 	GF_Err gf_rtp_set_info_rtp(GF_RTPChannel *ch, u32 seq_num, u32 rtp_time, u32 ssrc);
609 
610 	/*retrieve current RTP time in sec. If rtp_time was unknown (not on demand media) the time is absolute.
611 	Otherwise this is the time in ms elapsed since the last PLAY range start value
612 	Not supported yet if played without RTSP (aka RTCP time not supported)*/
613 	Double gf_rtp_get_current_time(GF_RTPChannel *ch);
614 
615 
616 	void gf_rtp_reset_buffers(GF_RTPChannel *ch);
617 
618 	/*read any data on UDP only (not valid for TCP). Performs re-ordering if configured for it
619 	returns amount of data read (raw UDP packet size)*/
620 	u32 gf_rtp_read_rtp(GF_RTPChannel *ch, char *buffer, u32 buffer_size);
621 	u32 gf_rtp_read_rtcp(GF_RTPChannel *ch, char *buffer, u32 buffer_size);
622 
623 	/*decodes an RTP packet and gets the beginning of the RTP payload*/
624 	GF_Err gf_rtp_decode_rtp(GF_RTPChannel *ch, char *pck, u32 pck_size, GF_RTPHeader *rtp_hdr, u32 *PayloadStart);
625 
626 	/*decodes an RTCP packet and update timing info, send RR too*/
627 	GF_Err gf_rtp_decode_rtcp(GF_RTPChannel *ch, char *pck, u32 pck_size, Bool *has_sr);
628 
629 	/*computes and send Receiver report. If the channel is a TCP channel, you must specify
630 	the callback function. NOTE: many RTP implementation do NOT process RTCP info received on TCP...
631 	the lib will decide whether the report shall be sent or not, therefore you should call
632 	this function at regular times*/
633 	GF_Err gf_rtp_send_rtcp_report(GF_RTPChannel *ch,
634 		GF_Err(*RTP_TCPCallback)(void *cbk, char *pck, u32 pck_size),
635 		void *rtsp_cbk);
636 
637 	/*send a BYE info (leaving the session)*/
638 	GF_Err gf_rtp_send_bye(GF_RTPChannel *ch,
639 		GF_Err(*RTP_TCPCallback)(void *cbk, char *pck, u32 pck_size),
640 		void *rtsp_cbk);
641 
642 
643 	/*send RTP packet. In fast_send mode, user passes a pck pointer with 12 bytes available BEFORE pck to
644 	write the header in place*/
645 	GF_Err gf_rtp_send_packet(GF_RTPChannel *ch, GF_RTPHeader *rtp_hdr, char *pck, u32 pck_size, Bool fast_send);
646 
647 	enum
648 	{
649 		GF_RTCP_INFO_NAME = 0,
650 		GF_RTCP_INFO_EMAIL,
651 		GF_RTCP_INFO_PHONE,
652 		GF_RTCP_INFO_LOCATION,
653 		GF_RTCP_INFO_TOOL,
654 		GF_RTCP_INFO_NOTE,
655 		GF_RTCP_INFO_PRIV
656 	};
657 
658 	/*sets RTCP info sent in RTCP reports. info_string shall NOT exceed 255 chars*/
659 	GF_Err gf_rtp_set_info_rtcp(GF_RTPChannel *ch, u32 InfoCode, char *info_string);
660 
661 	u32 gf_rtp_is_unicast(GF_RTPChannel *ch);
662 	u32 gf_rtp_is_interleaved(GF_RTPChannel *ch);
663 	u32 gf_rtp_get_clockrate(GF_RTPChannel *ch);
664 	u32 gf_rtp_is_active(GF_RTPChannel *ch);
665 	u8 gf_rtp_get_low_interleave_id(GF_RTPChannel *ch);
666 	u8 gf_rtp_get_hight_interleave_id(GF_RTPChannel *ch);
667 	GF_RTSPTransport *gf_rtp_get_transport(GF_RTPChannel *ch);
668 	u32 gf_rtp_get_local_ssrc(GF_RTPChannel *ch);
669 
670 	Float gf_rtp_get_loss(GF_RTPChannel *ch);
671 	u32 gf_rtp_get_tcp_bytes_sent(GF_RTPChannel *ch);
672 	void gf_rtp_get_ports(GF_RTPChannel *ch, u16 *rtp_port, u16 *rtcp_port);
673 
674 
675 
676 
677 
678 	/****************************************************************************
679 
680 	SDP LIBRARY EXPORTS
681 
682 	Note: SDP is mainly a text protocol with
683 	well defined containers. The following structures are used to write / read
684 	SDP informations, and the library also provides consistency checking
685 
686 	When reading SDP, all text items/structures are allocated by the lib, and you
687 	must call gf_sdp_info_reset(GF_SDPInfo *sdp) or gf_sdp_info_del(GF_SDPInfo *sdp) to release the memory
688 
689 	When writing the SDP from a GF_SDPInfo, the output buffer is allocated by the library,
690 	and you must release it yourself
691 
692 	Some quick constructors are available for GF_SDPConnection and GF_SDPMedia in order to set up
693 	some specific parameters to their default value
694 
695 	An extra function gf_sdp_info_check(GF_SDPInfo *sdp) is provided for compliency check
696 	with RFC2327: all requested fields are checked as well as conflicting information forbidden
697 	in RFC 2327
698 	****************************************************************************/
699 
700 	/*
701 	All attributes x-ZZZZ are considered as extensions attributes. If no "x-" is found
702 	the attributes in the RTSP response is SKIPPED. The "x-" radical is removed in the structure
703 	when parsing commands / responses
704 	*/
705 	typedef struct
706 	{
707 		char *Name;
708 		char *Value;
709 	} GF_X_Attribute;
710 
711 
712 	/*
713 	Structure for bandwidth info
714 	*/
715 	typedef struct
716 	{
717 		/*"CT", "AS" are defined. Private extensions must be "X-*" ( * "are recommended to be short")*/
718 		char *name;
719 		/*in kBitsPerSec*/
720 		u32 value;
721 	} GF_SDPBandwidth;
722 
723 	/*
724 	Structure for Time info
725 	*/
726 	/*we do not support more than ... time offsets / zone adjustment
727 	if more are needed, RFC recommends to use several entries rather than a big*/
728 #define GF_SDP_MAX_TIMEOFFSET	10
729 
730 	typedef struct
731 	{
732 		/*NPT time in sec*/
733 		u32 StartTime;
734 		/*if 0, session is unbound. NPT time in sec*/
735 		u32 StopTime;
736 		/*if 0 session is not repeated. Expressed in sec.
737 		Session is signaled repeated every repeatInterval*/
738 		u32 RepeatInterval;
739 		/*active duration of the session in sec*/
740 		u32 ActiveDuration;
741 
742 		/*time offsets to use with repeat. Specify a non-regular repeat time from the Start time*/
743 		u32 OffsetFromStart[GF_SDP_MAX_TIMEOFFSET];
744 		/*Number of offsets*/
745 		u32 NbRepeatOffsets;
746 
747 		/*EX of repeat:
748 		a session happens 3 times a week, on mon 1PM, thu 3PM and fri 10AM
749 		1- StartTime should be NPT for the session on the very first monday, StopTime
750 		the end of this session
751 		2- the repeatInterval should be 1 week, ActiveDuration the length of the session
752 		3- 3 offsets: 0 (for monday) (3*24+2)*3600 for thu and (4*24-3) for fri
753 		*/
754 
755 
756 		/*timezone adjustments, to cope with #timezones, daylight saving countries and co ...
757 		Ex: adjTime = [2882844526 2898848070] adjOffset=[-1h 0]
758 		[0]: at 2882844526 the time base by which the session's repeat times are calculated
759 		is shifted back by 1 hour
760 		[1]: at time 2898848070 the session's original time base is restored
761 		*/
762 
763 		/*Adjustment time at which the corresponding time offset is to be applied to the
764 		session time line (time used to compute the "repeat session").
765 		All Expressed in NPT*/
766 		u32 AdjustmentTime[GF_SDP_MAX_TIMEOFFSET];
767 		/* Offset with the session time line, ALWAYS ABSOLUTE OFFSET TO the specified StartTime*/
768 		s32 AdjustmentOffset[GF_SDP_MAX_TIMEOFFSET];
769 		/*Number of offsets.*/
770 		u32 NbZoneOffsets;
771 	} GF_SDPTiming;
772 
773 
774 	typedef struct
775 	{
776 		/*only "IN" currently defined*/
777 		char *net_type;
778 		/*"IP4","IP6"*/
779 		char *add_type;
780 		/*hex IPv6 address or doted IPv4 address*/
781 		char *host;
782 		/*TTL - MUST BE PRESENT if IP is multicast - -1 otherwise*/
783 		s32 TTL;
784 		/*multiple address counts - ONLY in media descriptions if needed. This
785 		is used for content scaling, when # quality of the same media are multicasted on
786 		# IP addresses*/
787 		u32 add_count;
788 	} GF_SDPConnection;
789 
790 	/*
791 	FMTP: description of dynamic payload types. This is opaque at the SDP level.
792 	Each attributes is assumed to be formatted as <param_name=param_val; ...>
793 	If not the case the attribute will have an empty value string and only the
794 	parameter name.
795 	*/
796 	typedef struct
797 	{
798 		/*payload type of the format described*/
799 		u32 PayloadType;
800 		/*list of GF_X_Attribute elements. The Value field may be NULL*/
801 		GF_List *Attributes;
802 	} GF_SDP_FMTP;
803 
804 	typedef struct
805 	{
806 		/*m=
807 		0: application - 1:video - 2: audio - 3: text - 4:data - 5: control*/
808 		u32 Type;
809 		/*Port Number - For transports based on UDP, the value should be in the range 1024
810 		to 65535 inclusive. For RTP compliance it should be an even number*/
811 		u32 PortNumber;
812 		/*number of ports described. If >= 2, the next media(s) in the SDP will be configured
813 		to use the next tuple (for RTP). If 0 or 1, ignored
814 		Note: this is used for scalable media: PortNumber indicates the port of the base
815 		media and NumPorts the ports||total number of the upper layers*/
816 		u32 NumPorts;
817 		/*currently ony "RTP/AVP" and "udp" defined*/
818 		char *Profile;
819 
820 		/*list of GF_SDPConnection's. A media can have several connection in case of scalable content*/
821 		GF_List *Connections;
822 
823 		/*RTPMaps contains a list SDPRTPMaps*/
824 		GF_List *RTPMaps;
825 
826 		/*FMTP contains a list of FMTP structures*/
827 		GF_List *FMTP;
828 
829 		/*for RTP this is PayloadType, but can be opaque (string) depending on the app.
830 		Formated as XX WW QQ FF
831 		When reading the SDP, the payloads defined in RTPMap are removed from this list
832 		When writing the SDP for RTP, you should only specify static payload types here,
833 		as dynamic ones are stored in RTPMaps and automatically written*/
834 		char *fmt_list;
835 
836 		/*all attributes not defined in RFC 2327 for the media*/
837 		GF_List *Attributes;
838 
839 		/*Other SDP attributes for media desc*/
840 
841 		/*k=
842 		method is 'clear' (key follows), 'base64' (key in base64), 'uri' (key is the URI)
843 		or 'prompt' (key not included)*/
844 		char *k_method, *k_key;
845 
846 		GF_List *Bandwidths;
847 
848 		/*0 if not present*/
849 		u32 PacketTime;
850 		/*0: none - 1: recv, 2: send, 3 both*/
851 		u32 SendReceive;
852 		char *orientation, *sdplang, *lang;
853 		/*for video only, 0.0 if not present*/
854 		Double FrameRate;
855 		/*between 0 and 10, -1 if not present*/
856 		s32 Quality;
857 	} GF_SDPMedia;
858 
859 	typedef struct
860 	{
861 		/*v=*/
862 		u32 Version;
863 		/*o=*/
864 		char *o_username, *o_session_id, *o_version, *o_address;
865 		/*"IN" for Net, "IP4" or "IP6" for address are currently valid*/
866 		char *o_net_type, *o_add_type;
867 
868 		/*s=*/
869 		char *s_session_name;
870 		/*i=*/
871 		char *i_description;
872 		/*u=*/
873 		char *u_uri;
874 		/*e=*/
875 		char *e_email;
876 		/*p=*/
877 		char *p_phone;
878 		/*c= either 1 or 0 GF_SDPConnection */
879 		GF_SDPConnection *c_connection;
880 		/*b=*/
881 		GF_List *b_bandwidth;
882 		/*All time info (t, r, z)*/
883 		GF_List *Timing;
884 		/*k=
885 		method is 'clear' (key follows), 'base64' (key in base64), 'uri' (key is the URI)
886 		or 'prompt' (key not included)*/
887 		char *k_method, *k_key;
888 		/*all possible attributes (a=), session level*/
889 		char *a_cat, *a_keywds, *a_tool;
890 		/*0: none, 1: recv, 2: send, 3 both*/
891 		u32 a_SendReceive;
892 		/*should be `broadcast', `meeting', `moderated', `test' or `H332'*/
893 		char *a_type;
894 		char *a_charset;
895 		char *a_sdplang, *a_lang;
896 
897 		/*all attributes not defined in RFC 2327 for the presentation*/
898 		GF_List *Attributes;
899 
900 		/*list of media in the SDP*/
901 		GF_List *media_desc;
902 	} GF_SDPInfo;
903 
904 
905 	/*
906 	Memory Consideration: the destructors free all non-NULL string. You should therefore
907 	be carefull while (de-)assigning the strings. The function gf_sdp_info_parse() performs a complete
908 	reset of the GF_SDPInfo
909 	*/
910 	/*constructor*/
911 	GF_SDPInfo *gf_sdp_info_new();
912 	/*destructor*/
913 	void gf_sdp_info_del(GF_SDPInfo *sdp);
914 	/*reset all structures (destroys substructure too)*/
915 	void gf_sdp_info_reset(GF_SDPInfo *sdp);
916 	/*Parses a memory SDP buffer*/
917 	GF_Err gf_sdp_info_parse(GF_SDPInfo *sdp, char *sdp_text, u32 text_size);
918 	/*check the consistency of the GF_SDPInfo*/
919 	GF_Err gf_sdp_info_check(GF_SDPInfo *sdp);
920 	/*write the SDP to a new buffer and returns it. Automatically checks the SDP before calling*/
921 	GF_Err gf_sdp_info_write(GF_SDPInfo *sdp, char **out_str_buf);
922 
923 
924 	/*
925 	Const/dest for GF_SDPMedia
926 	*/
927 	GF_SDPMedia *gf_sdp_media_new();
928 	void gf_sdp_media_del(GF_SDPMedia *media);
929 
930 	/*
931 	Const/dest for GF_SDPConnection
932 	*/
933 	GF_SDPConnection *gf_sdp_conn_new();
934 	void gf_sdp_conn_del(GF_SDPConnection *conn);
935 
936 	/*
937 	Const/dest for SDP FMTP
938 	*/
939 	GF_SDP_FMTP *gf_sdp_fmtp_new();
940 	void gf_sdp_fmtp_del(GF_SDP_FMTP *fmtp);
941 
942 
943 
944 	/*
945 	RTP packetizer
946 	*/
947 
948 
949 	/*RTP<->SL mapping*/
950 	typedef struct
951 	{
952 		/*1 - required options*/
953 
954 		/*mode, or "" if no mode ("generic" should be used instead)*/
955 		char mode[30];
956 
957 		/*config of the stream if carried in SDP*/
958 		char *config;
959 		u32 configSize;
960 		/* Stream Type*/
961 		u8 StreamType;
962 		/* stream profile and level indication - for AVC/H264, 0xPPCCLL, with PP:profile, CC:compatibility, LL:level*/
963 		u32 PL_ID;
964 
965 		/*rvc config of the stream if carried in SDP*/
966 		u16 rvc_predef;
967 		char *rvc_config;
968 		u32 rvc_config_size;
969 
970 		/*2 - optional options*/
971 
972 		/*size of AUs if constant*/
973 		u32 ConstantSize;
974 		/*duration of AUs if constant, in RTP timescale*/
975 		u32 ConstantDuration;
976 
977 		/* Object Type Indication */
978 		u8 ObjectTypeIndication;
979 		/*audio max displacement when interleaving (eg, de-interleaving window buffer max length) in RTP timescale*/
980 		u32 maxDisplacement;
981 		/*de-interleaveBufferSize if not recomputable from maxDisplacement*/
982 		u32 deinterleaveBufferSize;
983 
984 		/*The number of bits on which the AU-size field is encoded in the AU-header*/
985 		u32 SizeLength;
986 		/*The number of bits on which the AU-Index is encoded in the first AU-header*/
987 		u32 IndexLength;
988 		/*The number of bits on which the AU-Index-delta field is encoded in any non-first AU-header*/
989 		u32 IndexDeltaLength;
990 
991 		/*The number of bits on which the DTS-delta field is encoded in the AU-header*/
992 		u32 DTSDeltaLength;
993 		/*The number of bits on which the CTS-delta field is encoded in the AU-header*/
994 		u32 CTSDeltaLength;
995 		/*random access point flag present*/
996 		Bool RandomAccessIndication;
997 
998 		/*The number of bits on which the Stream-state field is encoded in the AU-header (systems only)*/
999 		u32 StreamStateIndication;
1000 		/*The number of bits that is used to encode the auxiliary-data-size field
1001 		(no normative usage of this section)*/
1002 		u32 AuxiliaryDataSizeLength;
1003 
1004 		/*ISMACryp stuff*/
1005 		u8 IV_length, IV_delta_length;
1006 		u8 KI_length;
1007 
1008 		/*internal stuff*/
1009 		/*len of first AU header in an RTP payload*/
1010 		u32 auh_first_min_len;
1011 		u32 auh_min_len;
1012 	} GP_RTPSLMap;
1013 
1014 
1015 	/*packetizer config flags - some flags are dynamically re-assigned when detecting multiSL / B-Frames / ...*/
1016 	enum
1017 	{
1018 		/*forces MPEG-4 generic transport if MPEG-4 systems mapping is available*/
1019 		GP_RTP_PCK_FORCE_MPEG4 = (1),
1020 		/*Enables AUs concatenation in an RTP packet (if payload supports it) - this forces GP_RTP_PCK_SIGNAL_SIZE for MPEG-4*/
1021 		GP_RTP_PCK_USE_MULTI = (1 << 1),
1022 		/*if set, audio interleaving is used if payload supports it (forces GP_RTP_PCK_USE_MULTI flag)
1023 		THIS IS CURRENTLY NOT IMPLEMENTED*/
1024 		GP_RTP_PCK_USE_INTERLEAVING = (1 << 2),
1025 		/*uses static RTP payloadID if any defined*/
1026 		GP_RTP_PCK_USE_STATIC_ID = (1 << 3),
1027 
1028 		/*MPEG-4 generic transport option*/
1029 		/*if flag set, RAP flag is signaled in RTP payload*/
1030 		GP_RTP_PCK_SIGNAL_RAP = (1 << 4),
1031 		/*if flag set, AU indexes are signaled in RTP payload - only usable for AU interleaving (eg audio)*/
1032 		GP_RTP_PCK_SIGNAL_AU_IDX = (1 << 5),
1033 		/*if flag set, AU size is signaled in RTP payload*/
1034 		GP_RTP_PCK_SIGNAL_SIZE = (1 << 6),
1035 		/*if flag set, CTS is signaled in RTP payload - DTS is automatically set if needed*/
1036 		GP_RTP_PCK_SIGNAL_TS = (1 << 7),
1037 
1038 		/*setup payload for carouseling of systems streams*/
1039 		GP_RTP_PCK_SYSTEMS_CAROUSEL = (1 << 8),
1040 
1041 		/*use LATM payload for AAC-LC*/
1042 		GP_RTP_PCK_USE_LATM_AAC = (1 << 9),
1043 
1044 		/*ISMACryp options*/
1045 		/*signals that input data is selectively encrypted (eg not all input frames are encrypted)
1046 		- this is usually automatically set by hinter*/
1047 		GP_RTP_PCK_SELECTIVE_ENCRYPTION = (1 << 10),
1048 		/*signals that each sample will have its own key indicator - ignored in non-multi modes
1049 		if not set and key indicator changes, a new RTP packet will be forced*/
1050 		GP_RTP_PCK_KEY_IDX_PER_AU = (1 << 11),
1051 
1052 		/*is zip compression used in DIMS unit ?*/
1053 		GP_RTP_DIMS_COMPRESSED = (1 << 12),
1054 	};
1055 
1056 
1057 
1058 	/*
1059 	Generic packetization tools - used by track hinters and future live tools
1060 	*/
1061 
1062 	/*currently supported payload types*/
1063 	enum
1064 	{
1065 		/*not defined*/
1066 		GF_RTP_PAYT_UNKNOWN,
1067 		/*use generic MPEG-4 transport - RFC 3016 and RFC 3640*/
1068 		GF_RTP_PAYT_MPEG4,
1069 		/*use generic MPEG-1/2 video transport - RFC 2250*/
1070 		GF_RTP_PAYT_MPEG12_VIDEO,
1071 		/*use generic MPEG-1/2 audio transport - RFC 2250*/
1072 		GF_RTP_PAYT_MPEG12_AUDIO,
1073 		/*use H263 transport - RFC 2429*/
1074 		GF_RTP_PAYT_H263,
1075 		/*use AMR transport - RFC 3267*/
1076 		GF_RTP_PAYT_AMR,
1077 		/*use AMR-WB transport - RFC 3267*/
1078 		GF_RTP_PAYT_AMR_WB,
1079 		/*use QCELP transport - RFC 2658*/
1080 		GF_RTP_PAYT_QCELP,
1081 		/*use EVRC/SMV transport - RFC 3558*/
1082 		GF_RTP_PAYT_EVRC_SMV,
1083 		/*use 3GPP Text transport - no RFC yet, only draft*/
1084 		GF_RTP_PAYT_3GPP_TEXT,
1085 		/*use H264 transport - no RFC yet, only draft*/
1086 		GF_RTP_PAYT_H264_AVC,
1087 		/*use LATM for AAC-LC*/
1088 		GF_RTP_PAYT_LATM,
1089 		/*use 3GPP DIMS format*/
1090 		GF_RTP_PAYT_3GPP_DIMS,
1091 		/*use AC3 audio format*/
1092 		GF_RTP_PAYT_AC3,
1093 		/*use H264-SVC transport*/
1094 		GF_RTP_PAYT_H264_SVC,
1095 		/*use HEVC/H265 transport - no RFC yet, only draft*/
1096 		GF_RTP_PAYT_HEVC,
1097 		GF_RTP_PAYT_LHVC
1098 	};
1099 
1100 
1101 
1102 	/*
1103 	RTP packetizer
1104 	*/
1105 
1106 
1107 
1108 	/*
1109 	RTP -> SL packetization tool
1110 	You should ONLY modify the GF_SLHeader while packetizing, all the rest is private
1111 	to the tool.
1112 	Also note that AU start/end is automatically updated, therefore you should only
1113 	set CTS-DTS-OCR-sequenceNumber (which is automatically incremented when splitting a payload)
1114 	-padding-idle infos
1115 	SL flags are computed on the fly, but you may wish to modify them in case of
1116 	packet drop/... at the encoder side
1117 
1118 	*/
1119 	struct __tag_rtp_packetizer
1120 	{
1121 		/*input packet sl header cfg. modify only if needed*/
1122 		GF_SLHeader sl_header;
1123 
1124 		/*
1125 
1126 		PRIVATE _ DO NOT TOUCH
1127 		*/
1128 
1129 		/*RTP payload type (RFC type, NOT the RTP hdr payT)*/
1130 		u32 rtp_payt;
1131 		/*packetization flags*/
1132 		u32 flags;
1133 		/*Path MTU size without 12-bytes RTP header*/
1134 		u32 Path_MTU;
1135 		/*max packet duration in RTP TS*/
1136 		u32 max_ptime;
1137 
1138 		/*payload type of RTP packets - only one payload type can be used in GPAC*/
1139 		u8 PayloadType;
1140 
1141 		/*RTP header of current packet*/
1142 		GF_RTPHeader rtp_header;
1143 
1144 		/*RTP packet handling callbacks*/
1145 		void(*OnNewPacket)(void *cbk_obj, GF_RTPHeader *header);
1146 		void(*OnPacketDone)(void *cbk_obj, GF_RTPHeader *header);
1147 		void(*OnDataReference)(void *cbk_obj, u32 payload_size, u32 offset_from_orig);
1148 		void(*OnData)(void *cbk_obj, char *data, u32 data_size, Bool is_header);
1149 		void *cbk_obj;
1150 
1151 		/*********************************
1152 		MPEG-4 Generic hinting
1153 		*********************************/
1154 
1155 		/*SL to RTP map*/
1156 		GP_RTPSLMap slMap;
1157 		/*SL conf and state*/
1158 		GF_SLConfig sl_config;
1159 
1160 		/*set to 1 if firstSL in RTP packet*/
1161 		Bool first_sl_in_rtp;
1162 		Bool has_AU_header;
1163 		/*current info writers*/
1164 		GF_BitStream *pck_hdr, *payload;
1165 
1166 		/*AU SN of last au*/
1167 		u32 last_au_sn;
1168 
1169 		/*info for the current packet*/
1170 		u32 auh_size, bytesInPacket;
1171 
1172 		/*********************************
1173 		ISMACryp info
1174 		*********************************/
1175 		Bool force_flush, is_encrypted;
1176 		u64 IV, first_AU_IV;
1177 		char *key_indicator;
1178 
1179 		/*********************************
1180 		AVC-H264 info
1181 		*********************************/
1182 		/*AVC non-IDR flag: set if all NAL in current packet are non-IDR (disposable)*/
1183 		Bool avc_non_idr;
1184 
1185 		/*********************************
1186 		AC3 info
1187 		*********************************/
1188 		/*ac3 ft flags*/
1189 		u8 ac3_ft;
1190 
1191 		/*********************************
1192 		HEVC-H265 info
1193 		*********************************/
1194 		/*HEVC Payload Header. It will be use in case of Aggreation Packet where we must add payload header for packet after having added of NALU to AP*/
1195 		char hevc_payload_hdr[2];
1196 	};
1197 
1198 	/*generic rtp builder (packetizer)*/
1199 	typedef struct __tag_rtp_packetizer GP_RTPPacketizer;
1200 
1201 	/*creates a new builder
1202 	@rtp_payt: rtp payload format, one of the above GF_RTP_PAYT_*
1203 	@flags: packetizer flags, one of the above GP_RTP_PCK_*
1204 	@slc: user-given SL config to use. If none specified, default RFC config is used
1205 	@cbk_obj: callback object passed back in functions
1206 	@OnNewPacket: callback function starting new RTP packet
1207 	@header: rtp header for new packet - note that RTP header flags are not used until PacketDone is called
1208 	@OnPacketDone: callback function closing current RTP packet
1209 	@header: final rtp header for packet
1210 	@OnDataReference: optional, to call each time data from input buffer is added to current RTP packet.
1211 	If not set, data must be added through OnData
1212 	@payload_size: size of reference data
1213 	@offset_from_orig: start offset in input buffer
1214 	@OnData: to call each time data is added to current RTP packet (either extra data from payload or
1215 	data from input when not using referencing)
1216 	@is_head: signal the data added MUST be inserted at the beginning of the payload. Otherwise data
1217 	is concatenated as received
1218 	*/
1219 	GP_RTPPacketizer *gf_rtp_builder_new(u32 rtp_payt,
1220 		GF_SLConfig *slc,
1221 		u32 flags,
1222 		void *cbk_obj,
1223 		void(*OnNewPacket)(void *cbk, GF_RTPHeader *header),
1224 		void(*OnPacketDone)(void *cbk, GF_RTPHeader *header),
1225 		void(*OnDataReference)(void *cbk, u32 payload_size, u32 offset_from_orig),
1226 		void(*OnData)(void *cbk, char *data, u32 data_size, Bool is_head)
1227 	);
1228 
1229 	/*destroy builder*/
1230 	void gf_rtp_builder_del(GP_RTPPacketizer *builder);
1231 
1232 	/*
1233 	init the builder
1234 	@MaxPayloadSize: maximum payload size of RTP packets (eg MTU minus IP/UDP/RTP headers)
1235 	@max_ptime: maximum packet duration IN RTP TIMESCALE
1236 	@StreamType: MPEG-4 system stream type - MUST always be provided for payloads format specifying
1237 	audio or video streams
1238 	@OTI : MPEG-4 system objectTypeIndication - may be 0 if stream is not mpeg4 systems
1239 
1240 	*** all other params are for MultiSL draft ***
1241 
1242 	@avgSize: average size of an AU. This is not always known (real-time encoding).
1243 	In this case you should specify a rough compute indicating how many packets could be
1244 	stored per RTP packet. for ex AAC stereo at 44100 k / 64kbps , one AU ~= 380 bytes
1245 	so 3 AUs for 1500 MTU is ok - BE CAREFULL: MultiSL adds some SL info on top of the 12
1246 	byte RTP header so you should specify a smaller size
1247 	The packetizer will ALWAYS make sure there's no pb storing the packets so specifying
1248 	more will result in a slight overhead in the SL mapping but the gain to singleSL
1249 	will still be worth it.
1250 	-Nota: at init, the packetizer can decide to switch to SingleSL if the average size
1251 	specified is too close to the PathMTU
1252 
1253 	@maxSize: max size of an AU. If unknown (real-time) set to 0
1254 	@avgTS: average CTS progression (1000/FPS for video)
1255 	@maxDTS: maximum DTS offset in case of bidirectional coding.
1256 	@IV_length: size (in bytes) of IV when ISMACrypted
1257 	@KI_length: size (in bytes) of key indicator when ISMACrypted
1258 	@pref_mode: MPEG-4 generic only, specifies the payload mode - can be NULL (mode generic)
1259 	*/
1260 
1261 	void gf_rtp_builder_init(GP_RTPPacketizer *builder, u8 PayloadType, u32 MaxPayloadSize, u32 max_ptime,
1262 		u32 StreamType, u32 OTI, u32 PL_ID,
1263 		u32 avgSize, u32 maxSize,
1264 		u32 avgTS, u32 maxDTS,
1265 		u32 IV_length, u32 KI_length,
1266 		char *pref_mode);
1267 
1268 	/*set frame crypto info*/
1269 	void gp_rtp_builder_set_cryp_info(GP_RTPPacketizer *builder, u64 IV, char *key_indicator, Bool is_encrypted);
1270 	/*packetize input buffer
1271 	@data, @data_size: input buffer
1272 	@IsAUEnd: set to one if this buffer is the last of the AU
1273 	@FullAUSize: complete access unit size if known, 0 otherwise
1274 	@duration: sample duration in rtp timescale (only needed for 3GPP text streams)
1275 	@descIndex: sample description index (only needed for 3GPP text streams)
1276 	*/
1277 	GF_Err gf_rtp_builder_process(GP_RTPPacketizer *builder, char *data, u32 data_size, u8 IsAUEnd, u32 FullAUSize, u32 duration, u8 descIndex);
1278 
1279 	/*format the "fmtp: " attribute for the MPEG-4 generic packetizer. sdpline shall be at least 2000 char*/
1280 	GF_Err gf_rtp_builder_format_sdp(GP_RTPPacketizer *builder, char *payload_name, char *sdpLine, char *dsi, u32 dsi_size);
1281 	/*formats SDP payload name and media name - both MUST be at least 20 bytes*/
1282 	Bool gf_rtp_builder_get_payload_name(GP_RTPPacketizer *builder, char *szPayloadName, char *szMediaName);
1283 
1284 
1285 
1286 
1287 
1288 	/*rtp payload flags*/
1289 	enum
1290 	{
1291 		/*AU end was detected (eg next packet is AU start)*/
1292 		GF_RTP_NEW_AU = (1),
1293 		/*AMR config*/
1294 		GF_RTP_AMR_ALIGN = (1 << 1),
1295 		/*for RFC3016, signals bitstream inspection for RAP discovery*/
1296 		GF_RTP_M4V_CHECK_RAP = (1 << 2),
1297 		/*flag set when unreliable usage of the M bit is detected*/
1298 		GF_RTP_UNRELIABLE_M = (1 << 3),
1299 
1300 		/*AWFULL hack at rtp level to cope with ffmpeg h264 crashes when jumping in stream without IDR*/
1301 		GF_RTP_AVC_WAIT_RAP = (1 << 4),
1302 		/*ISMACryp stuff*/
1303 		GF_RTP_HAS_ISMACRYP = (1 << 5),
1304 		GF_RTP_ISMA_SEL_ENC = (1 << 6),
1305 		GF_RTP_ISMA_HAS_KEY_IDX = (1 << 7),
1306 
1307 		GF_RTP_AVC_USE_ANNEX_B = (1 << 8)
1308 	};
1309 
1310 	/*
1311 	SL -> RTP packetization tool
1312 
1313 	*/
1314 	struct __tag_rtp_depacketizer
1315 	{
1316 		/*depacketize routine*/
1317 		void(*depacketize)(struct __tag_rtp_depacketizer *rtp, GF_RTPHeader *hdr, char *payload, u32 size);
1318 
1319 		/*output packet sl header cfg*/
1320 		GF_SLHeader sl_hdr;
1321 
1322 		/*RTP payload type (RFC type, NOT the RTP hdr payT)*/
1323 		u32 payt;
1324 		/*depacketization flags*/
1325 		u32 flags;
1326 
1327 		/*callback routine*/
1328 		void(*on_sl_packet)(void *udta, char *payload, u32 size, GF_SLHeader *hdr, GF_Err e);
1329 		void *udta;
1330 
1331 		/*SL <-> RTP map*/
1332 		GP_RTPSLMap sl_map;
1333 		u32 clock_rate;
1334 
1335 		/*inter-packet reconstruction bitstream (for 3GP text and H264)*/
1336 		GF_BitStream *inter_bs;
1337 
1338 		/*H264/AVC config*/
1339 		u32 h264_pck_mode;
1340 
1341 		/*3GP text reassembler state*/
1342 		u8 nb_txt_frag, cur_txt_frag, sidx, txt_len, nb_mod_frag;
1343 
1344 		/*ISMACryp*/
1345 		u32 isma_scheme;
1346 		char *key;
1347 	};
1348 
1349 	/*generic rtp builder (packetizer)*/
1350 	typedef struct __tag_rtp_depacketizer GF_RTPDepacketizer;
1351 
1352 	GF_RTPDepacketizer *gf_rtp_depacketizer_new(GF_SDPMedia *media, void(*sl_packet_cbk)(void *udta, char *payload, u32 size, GF_SLHeader *hdr, GF_Err e), void *udta);
1353 	void gf_rtp_depacketizer_del(GF_RTPDepacketizer *rtp);
1354 	void gf_rtp_depacketizer_reset(GF_RTPDepacketizer *rtp, Bool full_reset);
1355 	void gf_rtp_depacketizer_process(GF_RTPDepacketizer *rtp, GF_RTPHeader *hdr, char *payload, u32 size);
1356 
1357 	void gf_rtp_depacketizer_get_slconfig(GF_RTPDepacketizer *rtp, GF_SLConfig *sl);
1358 
1359 
1360 #endif /*GPAC_DISABLE_STREAMING*/
1361 
1362 	/*! @} */
1363 
1364 #ifdef __cplusplus
1365 }
1366 #endif
1367 
1368 #endif		/*_GF_IETF_H_*/
1369 
1370