#ifndef RTP_IN_H
#define RTP_IN_H
#include <gpac/modules/service.h>
#ifndef GPAC_DISABLE_STREAMING
#include <gpac/thread.h>
#include <gpac/constants.h>
#include <gpac/base_coding.h>
#include <gpac/ietf.h>
#define RTP_BUFFER_SIZE 0x100000ul
#define RTSP_BUFFER_SIZE 5000
#define RTSP_TCP_BUFFER_SIZE 0x100000ul
#define RTSP_LANGUAGE "English"
typedef struct
{
GF_ClientService *service;
GF_Descriptor *session_desc;
GF_List *sessions;
GF_List *channels;
GF_DownloadSession * dnload;
struct _sdp_fetch *sdp_temp;
GF_Mutex *mx;
GF_Thread *th;
u32 th_state;
u32 transport_mode;
u16 default_port;
u32 time_out;
u32 udp_time_out;
u32 first_packet_drop;
u32 frequency_drop;
u32 media_type;
char *session_state_data;
Double last_ntp;
Bool session_migration;
Bool is_scalable;
u32 cur_mid;
} RTPClient;
enum
{
RTSP_AGG_CONTROL = 1,
RTSP_TCP_FLUSH = 1<<1,
RTSP_FORCE_INTER = 1<<2,
RTSP_WAIT_REPLY = 1<<3,
RTSP_DSS_SERVER = 1<<4,
RTSP_AGG_ONLY = 1<<5,
};
typedef struct _rtp_session
{
u32 flags;
RTPClient *owner;
GF_RTSPSession *session;
char *session_id;
char *control;
GF_RTSPResponse *rtsp_rsp;
Double last_range;
u32 command_time;
GF_List *rtsp_commands;
GF_Err connect_error;
Bool satip;
char *satip_server;
} RTSPSession;
RTSPSession *RP_NewSession(RTPClient *rtp, char *session_control);
void RP_DelSession(RTSPSession *sess);
RTSPSession *RP_CheckSession(RTPClient *rtp, char *control);
void RP_SetupObjects(RTPClient *rtp);
void RP_ProcessCommands(RTSPSession *sess);
void RP_SendMessage(GF_ClientService *service, GF_Err e, const char *message);
enum
{
RTP_Setup,
RTP_WaitingForAck,
RTP_Connected,
RTP_Running,
RTP_Disconnected,
RTP_Unavailable,
RTP_SessionResume
};
enum
{
RTP_ENABLE_RTCP = 1,
RTP_HAS_RANGE = (1<<1),
RTP_INTERLEAVED = (1<<2),
RTP_FORCE_BROADCAST = (1<<3),
RTP_SKIP_NEXT_COM = (1<<4),
RTP_CONNECTED = (1<<5),
RTP_EOS = (1<<6),
RTP_MOBILEIP = (1<<7),
};
enum
{
RTP_SET_TIME_NONE = 0,
RTP_SET_TIME_RTP,
RTP_SET_TIME_RTP_SEEK,
};
#define RTCP_DEFAULT_TIMEOUT_MS 5000
typedef struct
{
RTPClient *owner;
u32 flags;
RTSPSession *rtsp;
char *session_id;
GF_RTPChannel *rtp_ch;
GF_RTPDepacketizer *depacketizer;
LPNETCHANNEL channel;
u32 status;
u32 ES_ID, OD_ID;
char *control;
char buffer[RTP_BUFFER_SIZE];
u32 check_rtp_time;
Double range_start, range_end;
Double current_start;
Bool paused;
Bool rtcp_init;
u32 last_udp_time;
u32 rtp_bytes, rtcp_bytes, stat_start_time, stat_stop_time;
u32 ts_res;
u32 mid;
u32 prev_stream;
u32 next_stream;
u32 base_stream;
u32 rtcp_check_start;
u64 ts_offset;
GF_InputService *satip_m2ts_ifce;
Bool satip_m2ts_service_connected;
} RTPStream;
GF_Err RP_ConnectServiceEx(GF_InputService *plug, GF_ClientService *serv, const char *url, Bool skip_migration);
RTPStream *RP_NewStream(RTPClient *rtp, GF_SDPMedia *media, GF_SDPInfo *sdp, RTPStream *input_stream);
RTPStream *RP_NewSatipStream(RTPClient *rtp, const char *server_ip);
void RP_DeleteStream(RTPStream *ch);
GF_Err RP_InitStream(RTPStream *ch, Bool ResetOnly);
GF_Err RP_DataOnTCP(GF_RTSPSession *sess, void *cbck, char *buffer, u32 bufferSize, Bool IsRTCP);
void RP_ConfirmChannelConnect(RTPStream *ch, GF_Err e);
void RP_FetchSDP(RTPClient *rtp, char *url, RTPStream *stream, char *original_url);
RTPStream *RP_FindChannel(RTPClient *rtp, LPNETCHANNEL ch, u32 ES_ID, char *es_control, Bool remove_stream);
GF_Err RP_AddStream(RTPClient *rtp, RTPStream *stream, char *session_control);
void RP_RemoveStream(RTPClient *rtp, RTPStream *ch);
void RP_ReadStream(RTPStream *ch);
void RP_ParsePayloadMPEG4(RTPStream *ch, GF_RTPHeader *hdr, char *payload, u32 size);
void RP_ParsePayloadMPEG12(RTPStream *ch, GF_RTPHeader *hdr, char *payload, u32 size);
void RP_ParsePayloadAMR(RTPStream *ch, GF_RTPHeader *hdr, char *payload, u32 size);
void RP_ParsePayloadH263(RTPStream *ch, GF_RTPHeader *hdr, char *payload, u32 size);
void RP_ParsePayloadText(RTPStream *ch, GF_RTPHeader *hdr, char *payload, u32 size);
void RP_ParsePayloadH264(RTPStream *ch, GF_RTPHeader *hdr, char *payload, u32 size);
void RP_ParsePayloadLATM(RTPStream *ch, GF_RTPHeader *hdr, char *payload, u32 size);
void RP_LoadSDP(RTPClient *rtp, char *sdp, u32 sdp_len, RTPStream *stream);
u32 payt_get_type(RTPClient *rtp, GF_RTPMap *map, GF_SDPMedia *media);
Bool payt_setup(RTPStream *st, GF_RTPMap *map, GF_SDPMedia *media);
typedef struct
{
u32 ES_ID;
LPNETCHANNEL channel;
char *esd_url;
} ChannelDescribe;
typedef struct
{
RTPStream *ch;
GF_NetworkCommand com;
} ChannelControl;
Bool RP_PreprocessDescribe(RTSPSession *sess, GF_RTSPCommand *com);
GF_Err RP_ProcessDescribe(RTSPSession *sess, GF_RTSPCommand *com, GF_Err e);
void RP_ProcessSetup(RTSPSession *sess, GF_RTSPCommand *com, GF_Err e);
void RP_ProcessTeardown(RTSPSession *sess, GF_RTSPCommand *com, GF_Err e);
Bool RP_PreprocessUserCom(RTSPSession *sess, GF_RTSPCommand *com);
void RP_ProcessUserCommand(RTSPSession *sess, GF_RTSPCommand *com, GF_Err e);
void RP_Describe(RTSPSession *sess, char *esd_url, LPNETCHANNEL channel);
void RP_Setup(RTPStream *ch);
GF_Err RP_SetupChannel(RTPStream *ch, ChannelDescribe *ch_desc);
void RP_UserCommand(RTSPSession *sess, RTPStream *ch, GF_NetworkCommand *command);
void RP_Teardown(RTSPSession *sess, RTPStream *ch);
GF_Descriptor *RP_EmulateIOD(RTPClient *rtp, const char *sub_url);
typedef struct _sdp_fetch
{
RTPClient *client;
RTPStream *chan;
char *remote_url;
char *original_url;
} SDPFetch;
void RP_SaveSessionState(RTPClient *rtp);
#endif
#endif