/
ietf.h
1614 lines (1389 loc) · 51.4 KB
/
ietf.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* GPAC - Multimedia Framework C SDK
*
* Authors: Jean Le Feuvre
* Copyright (c) Telecom ParisTech 2000-2022
* All rights reserved
*
* This file is part of GPAC / IETF RTP/RTSP/SDP sub-project
*
* GPAC is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* GPAC is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#ifndef _GF_IETF_H_
#define _GF_IETF_H_
#ifdef __cplusplus
extern "C" {
#endif
/*!
\file <gpac/ietf.h>
\brief Tools for real-time streaming over IP using RTP/RTCP/RTSP/SDP .
*/
/*!
\addtogroup ietf_grp RTP Streaming
\ingroup media_grp
\brief Tools for real-time streaming over IP using RTP/RTCP/RTSP/SDP.
This section documents the tools used for real-time streaming over IP using RTP/RTCP/RTSP/SDP.
@{
*/
#include <gpac/list.h>
#ifndef GPAC_DISABLE_STREAMING
#include <gpac/bitstream.h>
#include <gpac/sync_layer.h>
#include <gpac/network.h>
/*! RTSP version supported by GPAC*/
#define GF_RTSP_VERSION "RTSP/1.0"
/*! RTSP NOTIF CODES */
enum
{
NC_RTSP_Continue = 100,
NC_RTSP_OK = 200,
NC_RTSP_Created = 201,
NC_RTSP_Low_on_Storage_Space = 250,
NC_RTSP_Multiple_Choice = 300,
NC_RTSP_Moved_Permanently = 301,
NC_RTSP_Moved_Temporarily = 302,
NC_RTSP_See_Other = 303,
NC_RTSP_Use_Proxy = 305,
NC_RTSP_Bad_Request = 400,
NC_RTSP_Unauthorized = 401,
NC_RTSP_Payment_Required = 402,
NC_RTSP_Forbidden = 403,
NC_RTSP_Not_Found = 404,
NC_RTSP_Method_Not_Allowed = 405,
NC_RTSP_Not_Acceptable = 406,
NC_RTSP_Proxy_Authentication_Required = 407,
NC_RTSP_Request_Timeout = 408,
NC_RTSP_Gone = 410,
NC_RTSP_Length_Required = 411,
NC_RTSP_Precondition_Failed = 412,
NC_RTSP_Request_Entity_Too_Large = 413,
NC_RTSP_Request_URI_Too_Long = 414,
NC_RTSP_Unsupported_Media_Type = 415,
NC_RTSP_Invalid_parameter = 451,
NC_RTSP_Illegal_Conference_Identifier = 452,
NC_RTSP_Not_Enough_Bandwidth = 453,
NC_RTSP_Session_Not_Found = 454,
NC_RTSP_Method_Not_Valid_In_This_State = 455,
NC_RTSP_Header_Field_Not_Valid = 456,
NC_RTSP_Invalid_Range = 457,
NC_RTSP_Parameter_Is_ReadOnly = 458,
NC_RTSP_Aggregate_Operation_Not_Allowed = 459,
NC_RTSP_Only_Aggregate_Operation_Allowed = 460,
NC_RTSP_Unsupported_Transport = 461,
NC_RTSP_Destination_Unreachable = 462,
NC_RTSP_Internal_Server_Error = 500,
NC_RTSP_Not_Implemented = 501,
NC_RTSP_Bad_Gateway = 502,
NC_RTSP_Service_Unavailable = 503,
NC_RTSP_Gateway_Timeout = 504,
NC_RTSP_RTSP_Version_Not_Supported = 505,
NC_RTSP_Option_not_support = 551,
};
/*! Gives string description of error code
\param ErrCode the RTSP error code
\return the description of the RTSP error code
*/
const char *gf_rtsp_nc_to_string(u32 ErrCode);
/*
Common structures between commands and responses
*/
/*! RTSP Range information
RTSP Session level only, although this is almost the same
format as an SDP range, this is not used in the SDP lib as "a=range" is not part of SDP
but part of RTSP
*/
typedef struct {
/* start and end range. If end is -1, the range is open (from start to unknown) */
Double start, end;
/* use SMPTE range (Start and End specify the number of frames) (currently not supported) */
u32 UseSMPTE;
/* framerate for SMPTE range */
Double FPS;
} GF_RTSPRange;
/*! parses a Range line and returns range header structure. This can be used for RTSP extension of SDP
\note Only support for npt for now
\param range_buf the range string
\return a newly allocated RTSP range
*/
GF_RTSPRange *gf_rtsp_range_parse(char *range_buf);
/*! creates a new RTSP range
\return a newly allocated RTSP range
*/
GF_RTSPRange *gf_rtsp_range_new();
/*! destroys a RTSP range
\param range the target RTSP range
*/
void gf_rtsp_range_del(GF_RTSPRange *range);
/*
Transport structure
contains all network info for RTSP sessions (ports, uni/multi-cast, ...)
*/
/*! RTSP AVP Transport Profile */
#define GF_RTSP_PROFILE_RTP_AVP "RTP/AVP"
/*! RTSP AVP + TCP Transport Profile */
#define GF_RTSP_PROFILE_RTP_AVP_TCP "RTP/AVP/TCP"
/*! RTSP UDP Transport Profile */
#define GF_RTSP_PROFILE_UDP "udp"
/*! RTSP transport structure*/
typedef struct
{
/* set to 1 if unicast */
Bool IsUnicast;
/* for multicast */
char *destination;
/* for redirections internal to servers */
char *source;
/*IsRecord is usually 0 (PLAY) . If set, Append specify that the stream should
be concatenated to existing resources */
Bool IsRecord, Append;
/* in case transport is on TCP/RTSP, If only 1 ID is specified, it is stored in rtpID (this
is not RTP interleaving) */
Bool IsInterleaved;
u32 rtpID, rtcpID;
/* Multicast specific */
u32 MulticastLayers;
u8 TTL;
/*RTP specific*/
/*port for multicast*/
/*server port in unicast - RTP implies low is even , and last is low+1*/
u16 port_first, port_last;
/*client port in unicast - RTP implies low is even , and last is low+1*/
u16 client_port_first, client_port_last;
u32 SSRC;
/*Transport protocol. In this version we only support RTP/AVP, the following flag tells
us if this is RTP/AVP/TCP or RTP/AVP (default)*/
char *Profile;
Bool is_sender;
} GF_RTSPTransport;
/*! clones a RTSP transport
\param transp the target RTSP transport
\return an allocated copy RTSP transport
*/
GF_RTSPTransport *gf_rtsp_transport_clone(GF_RTSPTransport *transp);
/*! destroys a RTSP transport
\param transp the target RTSP transport
*/
void gf_rtsp_transport_del(GF_RTSPTransport *transp);
/*
RTSP Command
the RTSP Response is sent by a client / received by a server
text Allocation is done by the lib when parsing a command, and
is automatically freed when calling reset / delete. Therefore you must
set/allocate the fields yourself when writing a command (client)
*/
/*ALL RTSP METHODS - all other methods will be ignored*/
/*! RTSP DESCRIBE method*/
#define GF_RTSP_DESCRIBE "DESCRIBE"
/*! RTSP SETUP method*/
#define GF_RTSP_SETUP "SETUP"
/*! RTSP PLAY method*/
#define GF_RTSP_PLAY "PLAY"
/*! RTSP PAUSE method*/
#define GF_RTSP_PAUSE "PAUSE"
/*! RTSP RECORD method*/
#define GF_RTSP_RECORD "RECORD"
/*! RTSP TEARDOWN method*/
#define GF_RTSP_TEARDOWN "TEARDOWN"
/*! RTSP GET_PARAMETER method*/
#define GF_RTSP_GET_PARAMETER "GET_PARAMETER"
/*! RTSP SET_PARAMETER method*/
#define GF_RTSP_SET_PARAMETER "SET_PARAMETER"
/*! RTSP OPTIONS method*/
#define GF_RTSP_OPTIONS "OPTIONS"
/*! RTSP ANNOUCE method*/
#define GF_RTSP_ANNOUNCE "ANNOUNCE"
/*! RTSP REDIRECT method*/
#define GF_RTSP_REDIRECT "REDIRECT"
/*! RTSP command structure*/
typedef struct
{
char *Accept;
char *Accept_Encoding;
char *Accept_Language;
char *Authorization;
u32 Bandwidth;
u32 Blocksize;
char *Cache_Control;
char *Conference;
char *Connection;
u32 Content_Length;
u32 CSeq;
char *From;
char *Proxy_Authorization;
char *Proxy_Require;
GF_RTSPRange *Range;
char *Referer;
Double Scale;
char *Session;
Double Speed;
/*nota : RTSP allows several configurations for a single channel (multicast and
unicast , ...). Usually only 1*/
GF_List *Transports;
char *User_Agent;
/*type of the command, one of the described above*/
char *method;
/*Header extensions*/
GF_List *Xtensions;
/*body of the command, size is Content-Length (auto computed when sent). It is not
terminated by a NULL char*/
char *body;
/*
Specify ControlString if your request targets
a specific media stream in the service. If null, the service name only will be used
for control (for ex, both A and V streams in a single file)
If the request is GF_RTSP_OPTIONS, you must provide a control string containing the options
you want to query
*/
char *ControlString;
/*user data: this is never touched by the lib, its intend is to help stacking
RTSP commands in your app*/
void *user_data;
/*user flags: this is never touched by the lib, its intend is to help stacking
RTSP commands in your app*/
u32 user_flags;
/*
Server side Extensions
*/
/*full URL of the command. Not used at client side, as the URL is ALWAYS relative
to the server / service of the RTSP session
On the server side however redirections are up to the server, so we cannot decide for it */
char *service_name;
/*RTSP status code of the command as parsed. One of the above RTSP StatusCode*/
u32 StatusCode;
} GF_RTSPCommand;
/*! creates an RTSP command
\return the newly allocated RTSP command
*/
GF_RTSPCommand *gf_rtsp_command_new();
/*! destroys an RTSP command
\param com the target RTSP command
*/
void gf_rtsp_command_del(GF_RTSPCommand *com);
/*! resets an RTSP command
\param com the target RTSP command
*/
void gf_rtsp_command_reset(GF_RTSPCommand *com);
/*
RTSP Response
the RTSP Response is received by a client / sent by a server
text Allocation is done by the lib when parsing a response, and
is automatically freed when calling reset / delete. Therefore you must
allocate the fields yourself when writing a response (server)
*/
/*! RTP-Info for RTP channels.
There may be several RTP-Infos in one response
based on the server implementation (DSS/QTSS begaves this way)
*/
typedef struct
{
/*control string of the channel*/
char *url;
/*seq num for asociated rtp_time*/
u32 seq;
/*rtp TimeStamp corresponding to the Range start specified in the PLAY request*/
u32 rtp_time;
/*ssrc of sender if known, 0 otherwise*/
u32 ssrc;
} GF_RTPInfo;
/*! RTSP Response */
typedef struct
{
/* response code*/
u32 ResponseCode;
/* comment from the server */
char *ResponseInfo;
/* Header Fields */
char *Accept;
char *Accept_Encoding;
char *Accept_Language;
char *Allow;
char *Authorization;
u32 Bandwidth;
u32 Blocksize;
char *Cache_Control;
char *Conference;
char *Connection;
char *Content_Base;
char *Content_Encoding;
char *Content_Language;
u32 Content_Length;
char *Content_Location;
char *Content_Type;
u32 CSeq;
char *Date;
char *Expires;
char *From;
char *Host;
char *If_Match;
char *If_Modified_Since;
char *Last_Modified;
char *Location;
char *Proxy_Authenticate;
char *Proxy_Require;
char *Public;
GF_RTSPRange *Range;
char *Referer;
char *Require;
char *Retry_After;
GF_List *RTP_Infos;
Double Scale;
char *Server;
char *Session;
u32 SessionTimeOut;
Double Speed;
u32 StreamID; //only when sess->satip is true
char *Timestamp;
/*nota : RTSP allows several configurations for a single channel (multicast and
unicast , ...). Usually only 1*/
GF_List *Transports;
char *Unsupported;
char *User_Agent;
char *Vary;
char *Via;
char *WWW_Authenticate;
/*Header extensions*/
GF_List *Xtensions;
/*body of the response, size is Content-Length (auto computed when sent). It is not
terminated by a NULL char when response is parsed but must be null-terminated when
response is being sent*/
char *body;
} GF_RTSPResponse;
/*! creates an RTSP response
\return the newly allocated RTSP response
*/
GF_RTSPResponse *gf_rtsp_response_new();
/*! deletes an RTSP response
\param rsp the target RTSP response
*/
void gf_rtsp_response_del(GF_RTSPResponse *rsp);
/*! resets an RTSP response
\param rsp the target RTSP response
*/
void gf_rtsp_response_reset(GF_RTSPResponse *rsp);
/*! RTSP session*/
typedef struct _tag_rtsp_session GF_RTSPSession;
/*! creates a new RTSP session
\param sURL the target RTSP session URL
\param DefaultPort the target RTSP session port
\return a newly allocated RTSP session
*/
GF_RTSPSession *gf_rtsp_session_new(char *sURL, u16 DefaultPort);
/*! destroys an RTSP session
\param sess the target RTSP session
*/
void gf_rtsp_session_del(GF_RTSPSession *sess);
/*! sets TCP buffer size of an RTSP session
\param sess the target RTSP session
\param BufferSize desired buffer size in bytes
\return error if any
*/
GF_Err gf_rtsp_set_buffer_size(GF_RTSPSession *sess, u32 BufferSize);
/*! resets state machine, invalidate SessionID
\note RFC2326 requires that the session is reseted when all RTP streams
are closed. As this lib doesn't maintain the number of valid streams
you MUST call reset when all your streams are shutdown (either requested through
TEARDOWN or signaled through RTCP BYE packets for RTP, or any other signaling means
for other protocols)
\param sess the target RTSP session
\param ResetConnection if set, this will destroy the associated TCP socket. This is useful in case of timeouts, because
some servers do not restart with the right CSeq.
*/
void gf_rtsp_session_reset(GF_RTSPSession *sess, Bool ResetConnection);
/*! checks if an RTSP session matches an RTSP URL
\param sess the target RTSP session
\param url the URL to test
\return GF_TRUE if the session matches the URL, GF_FALSE otherwise
*/
Bool gf_rtsp_is_my_session(GF_RTSPSession *sess, char *url);
/*! gets server name of an RTSP session
\param sess the target RTSP session
\return the server name
*/
char *gf_rtsp_get_server_name(GF_RTSPSession *sess);
/*! gets server port of an RTSP session
\param sess the target RTSP session
\return the server port
*/
u16 gf_rtsp_get_session_port(GF_RTSPSession *sess);
/*! fetches an RTSP response from the server. the GF_RTSPResponse will be reseted before fetch
\param sess the target RTSP session
\param rsp the response object to fill with the response. This will be reseted before TCP fetch
\return error if any
*/
GF_Err gf_rtsp_get_response(GF_RTSPSession *sess, GF_RTSPResponse *rsp);
/*! RTSP States. The only non blocking mode is GF_RTSP_STATE_WAIT_FOR_CONTROL*/
enum
{
/*! Initialized (connection might be off, but all structures are in place)
This is the default state between # requests (aka, DESCRIBE and SETUP
or SETUP and PLAY ...)*/
GF_RTSP_STATE_INIT = 0,
/*! Waiting*/
GF_RTSP_STATE_WAITING,
/*! PLAY, PAUSE, RECORD. Aggregation is allowed for the same type, you can send several command
in a row. However the session will return GF_SERVICE_ERROR if you do not have
a valid SessionID in the command
You cannot issue a SETUP / DESCRIBE while in this state*/
GF_RTSP_STATE_WAIT_FOR_CONTROL,
/*! FATAL ERROR: session is invalidated by server. Call reset and restart from SETUP if needed*/
GF_RTSP_STATE_INVALIDATED
};
/*! gets the RTSP session state
\param sess the target RTSP session
\return the session state
*/
u32 gf_rtsp_get_session_state(GF_RTSPSession *sess);
/*! forces a reset of the state to GF_RTSP_STATE_INIT
\param sess the target RTSP session
*/
void gf_rtsp_reset_aggregation(GF_RTSPSession *sess);
/*! sends an RTSP request to the server.
\param sess the target RTSP session
\param com the RTSP command to send
\return error if any
*/
GF_Err gf_rtsp_send_command(GF_RTSPSession *sess, GF_RTSPCommand *com);
/*! callback function for interleaved RTSP/TCP transport
\param sess the target RTSP session
\param cbk_ptr opaque data
\param buffer RTP or RTCP packet
\param bufferSize packet size in bytes
\param IsRTCP set to GF_TRUE if the packet is an RTCP packet, GF_FALSE otherwise
\return error if any
*/
typedef GF_Err (*gf_rtsp_interleave_callback)(GF_RTSPSession *sess, void *cbk_ptr, u8 *buffer, u32 bufferSize, Bool IsRTCP);
/*! assigns the callback function for interleaved RTSP/TCP transport
\param sess the target RTSP session
\param SignalData the callback function on each interleaved packet
\return error if any
*/
GF_Err gf_rtsp_set_interleave_callback(GF_RTSPSession *sess, gf_rtsp_interleave_callback SignalData);
/*! reads RTSP session (response fetch and interleaved RTSP/TCP transport)
\param sess the target RTSP session
\return error if any
*/
GF_Err gf_rtsp_session_read(GF_RTSPSession *sess);
/*! registers a new interleaved RTP channel over an RTSP connection
\param sess the target RTSP session
\param the_ch opaque data passed to \ref gf_rtsp_interleave_callback
\param LowInterID ID of the RTP interleave channel
\param HighInterID ID of the RCTP interleave channel
\return error if any
*/
GF_Err gf_rtsp_register_interleave(GF_RTSPSession *sess, void *the_ch, u8 LowInterID, u8 HighInterID);
/*! unregisters a new interleaved RTP channel over an RTSP connection
\param sess the target RTSP session
\param LowInterID ID of the RTP interleave channel
\return the numbers of registered interleaved channels remaining
*/
u32 gf_rtsp_unregister_interleave(GF_RTSPSession *sess, u8 LowInterID);
/*! creates a new RTSP session from an existing socket in listen state. If no pending connection
is detected, return NULL
\param rtsp_listener the listening server socket
\return the newly allocated RTSP session if any, NULL otherwise
*/
GF_RTSPSession *gf_rtsp_session_new_server(GF_Socket *rtsp_listener);
/*! fetches an RTSP request
\param sess the target RTSP session
\param com the RTSP command to fill with the command. This will be reseted before fetch
\return error if any
*/
GF_Err gf_rtsp_get_command(GF_RTSPSession *sess, GF_RTSPCommand *com);
/*! generates a session ID for the given session
\param sess the target RTSP session
\return an allocated string containing a session ID
*/
char *gf_rtsp_generate_session_id(GF_RTSPSession *sess);
/*! sends an RTSP response
\param sess the target RTSP session
\param rsp the response to send
\return error if any
*/
GF_Err gf_rtsp_send_response(GF_RTSPSession *sess, GF_RTSPResponse *rsp);
/*! gets the IP address of the local host running the session
\param sess the target RTSP session
\param buffer buffer to store the local host name
\return error if any
*/
GF_Err gf_rtsp_get_session_ip(GF_RTSPSession *sess, char buffer[GF_MAX_IP_NAME_LEN]);
/*! gets the IP address of the connected peer
\param sess the target RTSP session
\param buffer buffer to store the connected peer name
\return error if any
*/
GF_Err gf_rtsp_get_remote_address(GF_RTSPSession *sess, char *buffer);
/*! writes a packet on an interleaved channel over RTSP
\param sess the target RTSP session
\param idx ID (RTP or RTCP) of the interleaved channel
\param pck packet data (RTP or RTCP packet) to write
\param pck_size packet size in bytes
\return error if any
*/
GF_Err gf_rtsp_session_write_interleaved(GF_RTSPSession *sess, u32 idx, u8 *pck, u32 pck_size);
/*
RTP LIB EXPORTS
*/
/*! RTP header */
typedef struct tagRTP_HEADER {
/*version, must be 2*/
u8 Version;
/*padding bits in the payload*/
u8 Padding;
/*header extension is defined*/
u8 Extension;
/*number of CSRC (<=15)*/
u8 CSRCCount;
/*Marker Bit*/
u8 Marker;
/*payload type on 7 bits*/
u8 PayloadType;
/*packet seq number*/
u16 SequenceNumber;
/*packet time stamp*/
u32 TimeStamp;
/*sync source identifier*/
u32 SSRC;
/*in our basic client, CSRC should always be NULL*/
u32 CSRC[16];
/*internal to out lib*/
u64 recomputed_ntp_ts;
} GF_RTPHeader;
/*! RTPMap information*/
typedef struct
{
/*dynamic payload type of this map*/
u32 PayloadType;
/*registered payload name of this map*/
char *payload_name;
/*RTP clock rate (TS resolution) of this map*/
u32 ClockRate;
/*optional parameters for audio, specifying number of channels. Unused for other media types.*/
u32 AudioChannels;
} GF_RTPMap;
/*! RTP channel*/
typedef struct __tag_rtp_channel GF_RTPChannel;
/*! creates a new RTP channel
\return a newly allocated RTP channel
*/
GF_RTPChannel *gf_rtp_new();
/*! destroys an RTP channel
\param ch the target RTP channel
*/
void gf_rtp_del(GF_RTPChannel *ch);
/*! setup transport for an RTP channel
A server channelis configured through the transport structure, with the same info as a
client channel, the client_port_* info designing the REMOTE client and port_* designing
the server channel
\param ch the target RTP channel
\param trans_info the transport info for this channel
\param remote_address the remote / destination address of the channel
\return error if any
*/
GF_Err gf_rtp_setup_transport(GF_RTPChannel *ch, GF_RTSPTransport *trans_info, const char *remote_address);
/*! setup of rtp/rtcp transport ports
This only applies in unicast, non interleaved cases.
For multicast port setup MUST be done through the above gf_rtp_setup_transport function
This will take care of port reuse
\param ch the target RTP channel
\param first_port RTP port number of the RTP channel
\return error if any
*/
GF_Err gf_rtp_set_ports(GF_RTPChannel *ch, u16 first_port);
/*! init of RTP payload information. Only ONE payload per sync source is supported in this
version of the library (a sender cannot switch payload types on a single media)
\param ch the target RTP channel
\param PayloadType identifier of RTP payload
\param ClockRate clock rate in (1/Hz) of RTP channel
\return error if any
*/
GF_Err gf_rtp_setup_payload(GF_RTPChannel *ch, u32 PayloadType, u32 ClockRate);
/*! enables sending of NAT keep-alive packets for NAT traversal
\param ch the target RTP channel
\param nat_timeout specifies the inactivity period in ms after which NAT keepalive packets are sent. If 0, disables NAT keep-alive packets
*/
void gf_rtp_enable_nat_keepalive(GF_RTPChannel *ch, u32 nat_timeout);
/*! initializes the RTP channel.
\param ch the target RTP channel
\param UDPBufferSize UDP stack buffer size if configurable by OS/ISP - ignored otherwise
\note On WinCE devices, this is not configurable on an app bases but for the whole OS
you must update the device registry with:
\code
[HKEY_LOCAL_MACHINE\Comm\Afd]
DgramBuffer=dword:N
\endcode
where N is the number of UDP datagrams a socket should be able to buffer. For multimedia
app you should set N as large as possible. The device MUST be reseted for the param to take effect
\param IsSource if true, the channel is a sender (media data, sender report, Receiver report processing)
if source, you must specify the Path MTU size. The RTP lib won't send any packet bigger than this size
your application shall perform payload size splitting if needed
\param PathMTU desired path MTU (max packet size) in bytes
\param ReorederingSize max number of packets to queue for reordering. 0 means no reordering
\param MaxReorderDelay max time to wait in ms before releasing first packet in reoderer when only one packet is present.
If 0 and reordering size is specified, defaults to 200 ms (usually enough).
\param local_interface_ip local interface address to use for multicast. If NULL, default address is used
\return error if any
*/
GF_Err gf_rtp_initialize(GF_RTPChannel *ch, u32 UDPBufferSize, Bool IsSource, u32 PathMTU, u32 ReorederingSize, u32 MaxReorderDelay, char *local_interface_ip);
/*! stops the RTP channel. This destrpys RTP and RTCP sockets as well as packet reorderer
\param ch the target RTP channel
\return error if any
*/
GF_Err gf_rtp_stop(GF_RTPChannel *ch);
/*! inits the RTP info after a PLAY or PAUSE, rtp_time is the rtp TimeStamp of the RTP packet
with seq_num sequence number. This info is needed to compute the CurrentTime of the RTP channel
ssrc may not be known if sender hasn't indicated it (use 0 then)
\param ch the target RTP channel
\param seq_num the seq num of the next packet to be received
\param rtp_time the time in RTP timescale of the next packet to be received
\param ssrc the SSRC identifier of the next packet to be received
\return error if any
*/
GF_Err gf_rtp_set_info_rtp(GF_RTPChannel *ch, u32 seq_num, u32 rtp_time, u32 ssrc);
/*! retrieves current RTP time in sec. If rtp_time was unknown (not on demand media) the time is absolute.
Otherwise this is the time in ms elapsed since the last PLAY range start value
Not supported yet if played without RTSP (aka RTCP time not supported)
\param ch the target RTP channel
\return NTP clock in seconds
*/
Double gf_rtp_get_current_time(GF_RTPChannel *ch);
/*! resets both sockets and packet reorderer
\param ch the target RTP channel
*/
void gf_rtp_reset_buffers(GF_RTPChannel *ch);
/*! resets sender SSRC
\param ch the target RTP channel
*/
void gf_rtp_reset_ssrc(GF_RTPChannel *ch);
/*! reads any RTP data on UDP only (not valid for TCP). Performs re-ordering if configured for it
\param ch the target RTP channel
\param buffer the buffer where to store the RTP packet
\param buffer_size the size of the buffer
\return amount of data read in bytes
*/
u32 gf_rtp_read_rtp(GF_RTPChannel *ch, u8 *buffer, u32 buffer_size);
/*! flushes any pending data in packet reorderer, but does not flush packet reorderer if reorderer timeout is not exceeded
\param ch the target RTP channel
\param buffer the buffer where to store the data
\param buffer_size the size of the buffer
\return amount of data read in bytes
*/
u32 gf_rtp_flush_rtp(GF_RTPChannel *ch, u8 *buffer, u32 buffer_size);
/*! reads any RTCP data on UDP only (not valid for TCP). Performs re-ordering if configured for it
\param ch the target RTP channel
\param buffer the buffer where to store the RTCP packet
\param buffer_size the size of the buffer
\return amount of data read in bytes
*/
u32 gf_rtp_read_rtcp(GF_RTPChannel *ch, u8 *buffer, u32 buffer_size);
/*! flushes any pending data in packet reorderer, and flushes packet reorderer if reorderer timeout is not exceeded. Typically called several times until returning 0.
\param ch the target RTP channel
\param buffer the buffer where to store the data
\param buffer_size the size of the buffer
\return amount of data read in bytes
*/
u32 gf_rtp_read_flush(GF_RTPChannel *ch, u8 *buffer, u32 buffer_size);
/*! decodes an RTP packet and gets the beginning of the RTP payload
\param ch the target RTP channel
\param pck the RTP packet buffer
\param pck_size the size of the RTP packet
\param rtp_hdr filled with decoded RTP header information
\param PayloadStart set to the offset in bytes of the start of the payload in the RTP packet
\return error if any
*/
GF_Err gf_rtp_decode_rtp(GF_RTPChannel *ch, u8 *pck, u32 pck_size, GF_RTPHeader *rtp_hdr, u32 *PayloadStart);
/*! decodes an RTCP packet and update timing info, send ReceiverReport too
\param ch the target RTP channel
\param pck the RTP packet buffer
\param pck_size the size of the RTP packet
\param has_sr set to GF_TRUE if the RTCP packet contained an SenderReport
\return error if any
*/
GF_Err gf_rtp_decode_rtcp(GF_RTPChannel *ch, u8 *pck, u32 pck_size, Bool *has_sr);
/*! computes and send Receiver report.
If the channel is a TCP channel, you must specify
the callback function.
\note Many RTP implementation do NOT process RTCP info received on TCP...
the lib will decide whether the report shall be sent or not, therefore you should call
this function at regular times
\param ch the target RTP channel
\return error if any
*/
GF_Err gf_rtp_send_rtcp_report(GF_RTPChannel *ch);
/*! sends a BYE info (leaving the session)
\param ch the target RTP channel
\return error if any
*/
GF_Err gf_rtp_send_bye(GF_RTPChannel *ch);
/*! sends an RTP packet. In fast_send mode,
\param ch the target RTP channel
\param rtp_hdr the RTP header of the packet
\param pck the RTP payload buffer
\param pck_size the RTP payload size
\param fast_send if set, the payload buffer contains 12 bytes available BEFORE its indicated start where the RTP header is written in place
\return error if any
*/
GF_Err gf_rtp_send_packet(GF_RTPChannel *ch, GF_RTPHeader *rtp_hdr, u8 *pck, u32 pck_size, Bool fast_send);
/*! callback used for writing rtp over TCP
\param cbk1 opaque user data
\param cbk2 opaque user data
\param is_rtcp indicates the data is an RTCP packet
\param pck the RTP/RTCP buffer
\param pck_size the RTP/RTCP size
\return error if any
*/
typedef GF_Err (*gf_rtp_tcp_callback)(void *cbk1, void *cbk2, Bool is_rtcp, u8 *pck, u32 pck_size);
/*! sets RTP interleaved callback on the RTP channel
\param ch the target RTP channel
\param tcp_callback the callback function
\param cbk1 user data for the callback function
\param cbk2 user data for the callback function
\return error if any
*/
GF_Err gf_rtp_set_interleave_callbacks(GF_RTPChannel *ch, gf_rtp_tcp_callback tcp_callback, void *cbk1, void *cbk2);
/*! checks if an RTP channel is unicast
\param ch the target RTP channel
\return GF_TRUE if unicast, GF_FALSE otherwise
*/
u32 gf_rtp_is_unicast(GF_RTPChannel *ch);
/*! checks if an RTP channel is interleaved
\param ch the target RTP channel
\return GF_TRUE if interleaved, GF_FALSE otherwise
*/
u32 gf_rtp_is_interleaved(GF_RTPChannel *ch);
/*! gets clockrate/timescale of an RTP channel
\param ch the target RTP channel
\return the RTP clock rate
*/
u32 gf_rtp_get_clockrate(GF_RTPChannel *ch);
/*! gets the low interleave ID of an RTP channel
\param ch the target RTP channel
\return the low (RTP) interleave ID of the channel, or 0 if not interleaved
*/
u8 gf_rtp_get_low_interleave_id(GF_RTPChannel *ch);
/*! gets the high interleave ID of an RTP channel
\param ch the target RTP channel
\return the high (RTCP) interleave ID of the channel, or 0 if not interleaved
*/
u8 gf_rtp_get_hight_interleave_id(GF_RTPChannel *ch);
/*! gets the transport associated with an RTP channel
\param ch the target RTP channel
\return the RTSP transport information
*/
const GF_RTSPTransport *gf_rtp_get_transport(GF_RTPChannel *ch);
/*! gets loss rate of the RTP channel
\param ch the target RTP channel
\return the loss rate of the channel, between 0 and 100 %
*/
Float gf_rtp_get_loss(GF_RTPChannel *ch);
/*! gets number of TCP bytes send for an interleaved channel
\param ch the target RTP channel
\return the number of bytes sent
*/
u32 gf_rtp_get_tcp_bytes_sent(GF_RTPChannel *ch);
/*! gets ports of an non-interleaved RTP channel
\param ch the target RTP channel
\param rtp_port the RTP port number
\param rtcp_port the RCTP port number
*/
void gf_rtp_get_ports(GF_RTPChannel *ch, u16 *rtp_port, u16 *rtcp_port);
/****************************************************************************
SDP LIBRARY EXPORTS
SDP is mainly a text protocol with
well defined containers. The following structures are used to write / read
SDP informations, and the library also provides consistency checking
When reading SDP, all text items/structures are allocated by the lib, and you
must call gf_sdp_info_reset(GF_SDPInfo *sdp) or gf_sdp_info_del(GF_SDPInfo *sdp) to release the memory
When writing the SDP from a GF_SDPInfo, the output buffer is allocated by the library,
and you must release it yourself
Some quick constructors are available for GF_SDPConnection and GF_SDPMedia in order to set up
some specific parameters to their default value
****************************************************************************/
/*! Extension Attribute
All attributes x-ZZZZ are considered as extensions attributes. If no "x-" is found
the attributes in the RTSP response is SKIPPED. The "x-" radical is removed in the structure
when parsing commands / responses
*/
typedef struct
{
char *Name;
char *Value;
} GF_X_Attribute;
/*! SDP bandwidth info*/
typedef struct
{
/*"CT", "AS" are defined. Private extensions must be "X-*" ( * "are recommended to be short")*/
char *name;
/*in kBitsPerSec*/
u32 value;
} GF_SDPBandwidth;
/*! SDP maximum time offset
We do not support more than this offset / zone adjustment
if more are needed, RFC recommends to use several entries rather than a big offset*/
#define GF_SDP_MAX_TIMEOFFSET 10
/*! SDP Timing information*/
typedef struct
{
/*NPT time in sec*/
u32 StartTime;
/*if 0, session is unbound. NPT time in sec*/
u32 StopTime;
/*if 0 session is not repeated. Expressed in sec.
Session is signaled repeated every repeatInterval*/
u32 RepeatInterval;
/*active duration of the session in sec*/
u32 ActiveDuration;
/*time offsets to use with repeat. Specify a non-regular repeat time from the Start time*/
u32 OffsetFromStart[GF_SDP_MAX_TIMEOFFSET];
/*Number of offsets*/
u32 NbRepeatOffsets;
/*EX of repeat:
a session happens 3 times a week, on mon 1PM, thu 3PM and fri 10AM
1- StartTime should be NPT for the session on the very first monday, StopTime
the end of this session
2- the repeatInterval should be 1 week, ActiveDuration the length of the session
3- 3 offsets: 0 (for monday) (3*24+2)*3600 for thu and (4*24-3) for fri
*/
/*timezone adjustments, to cope with #timezones, daylight saving countries and co ...