2 * GPAC - Multimedia Framework C SDK
\r
4 * Copyright (c) Jean Le Feuvre 2000-2005
\r
5 * All rights reserved
\r
7 * This file is part of GPAC / IETF RTP/RTSP/SDP sub-project
\r
9 * GPAC is free software; you can redistribute it and/or modify
\r
10 * it under the terms of the GNU Lesser General Public License as published by
\r
11 * the Free Software Foundation; either version 2, or (at your option)
\r
12 * any later version.
\r
14 * GPAC is distributed in the hope that it will be useful,
\r
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
17 * GNU Lesser General Public License for more details.
\r
19 * You should have received a copy of the GNU Lesser General Public
\r
20 * License along with this library; see the file COPYING. If not, write to
\r
21 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
\r
25 #ifndef _GF_IETF_DEV_H_
\r
26 #define _GF_IETF_DEV_H_
\r
28 #include <gpac/ietf.h>
\r
29 #include <gpac/thread.h>
\r
37 /*version of the packet. Must be 2*/
\r
39 /*padding bits at the end of the payload*/
\r
41 /*number of reports*/
\r
43 /*payload type of RTCP pck*/
\r
45 /*The length of this RTCP packet in 32-bit words minus one including the header and any padding*/
\r
47 /*sync source identifier*/
\r
52 typedef struct __PRO_item
\r
54 struct __PRO_item *next;
\r
62 struct __PRO_item *in;
\r
67 u32 MaxDelay, LastTime;
\r
70 /* creates new RTP reorderer
\r
71 @MaxCount: forces automatic packet flush. 0 means no flush
\r
72 @MaxDelay: is the max time in ms the queue will wait for a missing packet
\r
74 GF_RTPReorder *gf_rtp_reorderer_new(u32 MaxCount, u32 MaxDelay);
\r
75 void gf_rtp_reorderer_del(GF_RTPReorder *po);
\r
77 void gf_rtp_reorderer_reset(GF_RTPReorder *po);
\r
79 /*Adds a packet to the queue. Packet Data is memcopied*/
\r
80 GF_Err gf_rtp_reorderer_add(GF_RTPReorder *po, void *pck, u32 pck_size, u32 pck_seqnum);
\r
81 /*gets the output of the queue. Packet Data IS YOURS to delete*/
\r
82 void *gf_rtp_reorderer_get(GF_RTPReorder *po, u32 *pck_size);
\r
85 /*the RTP channel with both RTP and RTCP sockets and buffers
\r
86 each channel is identified by a control string given in RTSP Describe
\r
87 this control string is used with Darwin
\r
89 struct __tag_rtp_channel
\r
91 /*global transport info for the session*/
\r
92 GF_RTSPTransport net_info;
\r
99 /*RTP Packet reordering. Turned on/off during initialization. The library forces a 200 ms
\r
100 max latency at the reordering queue*/
\r
103 /*RTCP report times*/
\r
104 u32 last_report_time;
\r
105 u32 next_report_time;
\r
108 u32 last_nat_keepalive_time, nat_keepalive_time_period;
\r
111 /*the seq number of the first packet as signaled by the server if any, or first
\r
112 RTP SN received (RTP multicast)*/
\r
114 /*the TS of the associated first packet as signaled by the server if any, or first
\r
115 RTP TS received (RTP multicast)*/
\r
117 /*NPT from the rtp_time*/
\r
119 /*num loops of pck sn*/
\r
121 /*some mapping info - we should support # payloads*/
\r
125 /*static buffer for RTP sending*/
\r
127 u32 send_buffer_size;
\r
128 u32 pck_sent_since_last_sr;
\r
130 u32 last_pck_ntp_sec, last_pck_ntp_frac;
\r
131 u32 num_pck_sent, num_payload_bytes;
\r
134 char *s_name, *s_email, *s_location, *s_phone, *s_tool, *s_note, *s_priv;
\r
135 // s8 first_rtp_pck;
\r
144 u32 rtcp_bytes_sent;
\r
146 u32 tot_num_pck_rcv, tot_num_pck_expected;
\r
147 /*stats since last SR*/
\r
148 u32 last_num_pck_rcv, last_num_pck_expected, last_num_pck_loss;
\r
150 u32 Jitter, ntp_init;
\r
151 s32 last_deviance;
\r
153 u32 last_SR_NTP_sec, last_SR_NTP_frac;
\r
154 /*RTP time at last SR as indicated in SR*/
\r
155 u32 last_SR_rtp_time;
\r
157 u32 total_pck, total_bytes;
\r
160 /*gets UTC in the channel RTP timescale*/
\r
161 u32 gf_rtp_channel_time(GF_RTPChannel *ch);
\r
162 /*gets time in 1/65536 seconds (for reports)*/
\r
163 u32 gf_rtp_get_report_time();
\r
164 /*updates the time for the next report (SR, RR)*/
\r
165 void gf_rtp_get_next_report_time(GF_RTPChannel *ch);
\r
172 #define GF_RTSP_DEFAULT_BUFFER 2048
\r
173 #define GF_RTSP_VERSION "RTSP/1.0"
\r
175 /*macros for RTSP command and response formmating*/
\r
176 #define RTSP_WRITE_STEPALLOC 250
\r
178 #define RTSP_WRITE_ALLOC_STR(buf, buf_size, pos, str) \
\r
180 if (strlen((const char *) str)+pos >= buf_size) { \
\r
181 buf_size += RTSP_WRITE_STEPALLOC; \
\r
182 buf = (char *) realloc(buf, buf_size); \
\r
184 strcpy(buf+pos, (const char *) str); \
\r
185 pos += strlen((const char *) str); \
\r
188 #define RTSP_WRITE_HEADER(buf, buf_size, pos, type, str) \
\r
190 RTSP_WRITE_ALLOC_STR(buf, buf_size, pos, type); \
\r
191 RTSP_WRITE_ALLOC_STR(buf, buf_size, pos, ": "); \
\r
192 RTSP_WRITE_ALLOC_STR(buf, buf_size, pos, str); \
\r
193 RTSP_WRITE_ALLOC_STR(buf, buf_size, pos, "\r\n"); \
\r
196 #define RTSP_WRITE_INT(buf, buf_size, pos, d, sig) \
\r
198 sprintf(temp, "%d", d); \
\r
200 sprintf(temp, "%u", d); \
\r
202 RTSP_WRITE_ALLOC_STR(buf, buf_size, pos, temp);
\r
204 #define RTSP_WRITE_FLOAT(buf, buf_size, pos, d) \
\r
205 sprintf(temp, "%.4f", d); \
\r
206 RTSP_WRITE_ALLOC_STR(buf, buf_size, pos, temp);
\r
208 /*default packet size, but resize on the fly if needed*/
\r
209 #define RTSP_PCK_SIZE 6000
\r
210 #define RTSP_TCP_BUF_SIZE 0x10000ul
\r
220 /**************************************
\r
222 ***************************************/
\r
223 struct _tag_rtsp_session
\r
225 /*service name (extracted from URL) ex: news/latenight.mp4, vod.mp4 ...*/
\r
227 /*server name (extracted from URL)*/
\r
229 /*server port (extracted from URL)*/
\r
232 /*if RTSP is on UDP*/
\r
234 /*TCP interleaving ID*/
\r
239 char HTTP_Cookie[30];
\r
243 GF_Socket *connection;
\r
244 u32 SockBufferSize;
\r
245 /*needs connection*/
\r
246 u32 NeedConnection;
\r
248 /*the RTSP sequence number*/
\r
250 /*this is for aggregated request in order to check SeqNum*/
\r
253 /*RTSP sessionID, arbitrary length, alpha-numeric*/
\r
254 const char *last_session_id;
\r
256 /*RTSP STATE machine*/
\r
258 char RTSPLastRequest[40];
\r
260 /*current buffer from TCP if any*/
\r
261 char TCPBuffer[RTSP_TCP_BUF_SIZE];
\r
262 u32 CurrentSize, CurrentPos;
\r
264 /*RTSP interleaving*/
\r
265 GF_Err (*RTSP_SignalData)(GF_RTSPSession *sess, void *chan, char *buffer, u32 bufferSize, Bool IsRTCP);
\r
267 /*buffer for pck reconstruction*/
\r
268 char *rtsp_pck_buf;
\r
270 u32 pck_start, payloadSize;
\r
272 /*all RTP channels in an interleaved RTP on RTSP session*/
\r
273 GF_List *TCPChannels;
\r
274 /*thread-safe, full duplex library for PLAY and RECORD*/
\r
280 GF_RTSPSession *gf_rtsp_session_new(char *sURL, u16 DefaultPort);
\r
282 /*check connection status*/
\r
283 GF_Err gf_rtsp_check_connection(GF_RTSPSession *sess);
\r
284 /*send data on RTSP*/
\r
285 GF_Err gf_rtsp_send_data(GF_RTSPSession *sess, char *buffer, u32 Size);
\r
291 /*locate body-start and body size in response/commands*/
\r
292 void gf_rtsp_get_body_info(GF_RTSPSession *sess, u32 *body_start, u32 *body_size);
\r
293 /*read TCP until a full command/response is received*/
\r
294 GF_Err gf_rtsp_read_reply(GF_RTSPSession *sess);
\r
295 /*fill the TCP buffer*/
\r
296 GF_Err gf_rtsp_fill_buffer(GF_RTSPSession *sess);
\r
297 /*force a fill on TCP buffer - used for de-interleaving and TCP-fragmented RTSP messages*/
\r
298 GF_Err gf_rtsp_refill_buffer(GF_RTSPSession *sess);
\r
299 /*parses a transport string and returns a transport structure*/
\r
300 GF_RTSPTransport *gf_rtsp_transport_parse(char *buffer);
\r
301 /*parsing of header for com and rsp*/
\r
302 GF_Err gf_rtsp_parse_header(char *buffer, u32 BufferSize, u32 BodyStart, GF_RTSPCommand *com, GF_RTSPResponse *rsp);
\r
303 void gf_rtsp_set_command_value(GF_RTSPCommand *com, char *Header, char *Value);
\r
304 void gf_rtsp_set_response_value(GF_RTSPResponse *rsp, char *Header, char *Value);
\r
305 /*deinterleave a data packet*/
\r
306 GF_Err gf_rtsp_set_deinterleave(GF_RTSPSession *sess);
\r
307 /*start session through HTTP tunnel (QTSS)*/
\r
308 GF_Err gf_rtsp_http_tunnel_start(GF_RTSPSession *sess, char *UserAgent);
\r
311 /*packetization routines*/
\r
312 GF_Err gp_rtp_builder_do_mpeg4(GP_RTPPacketizer *builder, char *data, u32 data_size, u8 IsAUEnd, u32 FullAUSize);
\r
313 GF_Err gp_rtp_builder_do_h263(GP_RTPPacketizer *builder, char *data, u32 data_size, u8 IsAUEnd, u32 FullAUSize);
\r
314 GF_Err gp_rtp_builder_do_amr(GP_RTPPacketizer *builder, char *data, u32 data_size, u8 IsAUEnd, u32 FullAUSize);
\r
315 GF_Err gp_rtp_builder_do_mpeg12_video(GP_RTPPacketizer *builder, char *data, u32 data_size, u8 IsAUEnd, u32 FullAUSize);
\r
316 GF_Err gp_rtp_builder_do_mpeg12_audio(GP_RTPPacketizer *builder, char *data, u32 data_size, u8 IsAUEnd, u32 FullAUSize);
\r
317 GF_Err gp_rtp_builder_do_tx3g(GP_RTPPacketizer *builder, char *data, u32 data_size, u8 IsAUEnd, u32 FullAUSize, u32 duration, u8 descIndex);
\r
318 GF_Err gp_rtp_builder_do_avc(GP_RTPPacketizer *builder, char *data, u32 data_size, u8 IsAUEnd, u32 FullAUSize);
\r
319 GF_Err gp_rtp_builder_do_qcelp(GP_RTPPacketizer *builder, char *data, u32 data_size, u8 IsAUEnd, u32 FullAUSize);
\r
320 GF_Err gp_rtp_builder_do_smv(GP_RTPPacketizer *builder, char *data, u32 data_size, u8 IsAUEnd, u32 FullAUSize);
\r
321 GF_Err gp_rtp_builder_do_latm(GP_RTPPacketizer *builder, char *data, u32 data_size, u8 IsAUEnd, u32 FullAUSize, u32 duration);
\r
322 GF_Err gp_rtp_builder_do_dims(GP_RTPPacketizer *builder, char *data, u32 data_size, u8 IsAUEnd, u32 FullAUSize, u32 duration);
\r
323 GF_Err gp_rtp_builder_do_ac3(GP_RTPPacketizer *builder, char *data, u32 data_size, u8 IsAUEnd, u32 FullAUSize);
\r
326 #endif /*_GF_IETF_DEV_H_*/
\r