00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef AVFORMAT_RTPDEC_H
00023 #define AVFORMAT_RTPDEC_H
00024
00025 #include "libavcodec/avcodec.h"
00026 #include "avformat.h"
00027 #include "rtp.h"
00028 #include "url.h"
00029
00030 typedef struct PayloadContext PayloadContext;
00031 typedef struct RTPDynamicProtocolHandler_s RTPDynamicProtocolHandler;
00032
00033 #define RTP_MIN_PACKET_LENGTH 12
00034 #define RTP_MAX_PACKET_LENGTH 1500
00035
00036 #define RTP_REORDER_QUEUE_DEFAULT_SIZE 10
00037
00038 #define RTP_NOTS_VALUE ((uint32_t)-1)
00039
00040 typedef struct RTPDemuxContext RTPDemuxContext;
00041 RTPDemuxContext *rtp_parse_open(AVFormatContext *s1, AVStream *st, URLContext *rtpc, int payload_type, int queue_size);
00042 void rtp_parse_set_dynamic_protocol(RTPDemuxContext *s, PayloadContext *ctx,
00043 RTPDynamicProtocolHandler *handler);
00044 int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt,
00045 uint8_t **buf, int len);
00046 void rtp_parse_close(RTPDemuxContext *s);
00047 int64_t ff_rtp_queued_packet_time(RTPDemuxContext *s);
00048 void ff_rtp_reset_packet_queue(RTPDemuxContext *s);
00049 int rtp_get_local_rtp_port(URLContext *h);
00050 int rtp_get_local_rtcp_port(URLContext *h);
00051
00052 int rtp_set_remote_url(URLContext *h, const char *uri);
00053
00065 void rtp_send_punch_packets(URLContext* rtp_handle);
00066
00072 int rtp_check_and_send_back_rr(RTPDemuxContext *s, int count);
00073
00077 int rtp_get_rtcp_file_handle(URLContext *h);
00078
00079
00080 typedef struct {
00081 uint16_t max_seq;
00082 uint32_t cycles;
00083 uint32_t base_seq;
00084 uint32_t bad_seq;
00085 int probation;
00086 int received;
00087 int expected_prior;
00088 int received_prior;
00089 uint32_t transit;
00090 uint32_t jitter;
00091 } RTPStatistics;
00092
00093 #define RTP_FLAG_KEY 0x1
00094 #define RTP_FLAG_MARKER 0x2
00095
00107 typedef int (*DynamicPayloadPacketHandlerProc) (AVFormatContext *ctx,
00108 PayloadContext *s,
00109 AVStream *st,
00110 AVPacket * pkt,
00111 uint32_t *timestamp,
00112 const uint8_t * buf,
00113 int len, int flags);
00114
00115 struct RTPDynamicProtocolHandler_s {
00116
00117 const char enc_name[50];
00118 enum AVMediaType codec_type;
00119 enum CodecID codec_id;
00120 int static_payload_id;
00121
00122
00123
00124
00125 int (*parse_sdp_a_line) (AVFormatContext *s,
00126 int st_index,
00127 PayloadContext *priv_data,
00128 const char *line);
00129 PayloadContext *(*alloc) (void);
00130 void (*free)(PayloadContext *protocol_data);
00131 DynamicPayloadPacketHandlerProc parse_packet;
00132
00133 struct RTPDynamicProtocolHandler_s *next;
00134 };
00135
00136 typedef struct RTPPacket {
00137 uint16_t seq;
00138 uint8_t *buf;
00139 int len;
00140 int64_t recvtime;
00141 struct RTPPacket *next;
00142 } RTPPacket;
00143
00144
00145 struct RTPDemuxContext {
00146 AVFormatContext *ic;
00147 AVStream *st;
00148 int payload_type;
00149 uint32_t ssrc;
00150 uint16_t seq;
00151 uint32_t timestamp;
00152 uint32_t base_timestamp;
00153 uint32_t cur_timestamp;
00154 int64_t range_start_offset;
00155 int max_payload_size;
00156 struct MpegTSContext *ts;
00157 int read_buf_index;
00158 int read_buf_size;
00159
00160 URLContext *rtp_ctx;
00161 char hostname[256];
00162
00163 RTPStatistics statistics;
00164
00166 int prev_ret;
00167 RTPPacket* queue;
00168 int queue_len;
00169 int queue_size;
00170
00172
00173 int64_t last_rtcp_ntp_time;
00174 int64_t first_rtcp_ntp_time;
00175 uint32_t last_rtcp_timestamp;
00176 int64_t rtcp_ts_offset;
00177
00178
00179 unsigned int packet_count;
00180 unsigned int octet_count;
00181 unsigned int last_octet_count;
00182 int first_packet;
00183
00184 uint8_t buf[RTP_MAX_PACKET_LENGTH];
00185 uint8_t *buf_ptr;
00186
00187
00188 DynamicPayloadPacketHandlerProc parse_packet;
00189 PayloadContext *dynamic_protocol_context;
00190 int max_frames_per_packet;
00191 };
00192
00193 void ff_register_dynamic_payload_handler(RTPDynamicProtocolHandler *handler);
00194 RTPDynamicProtocolHandler *ff_rtp_handler_find_by_name(const char *name,
00195 enum AVMediaType codec_type);
00196 RTPDynamicProtocolHandler *ff_rtp_handler_find_by_id(int id,
00197 enum AVMediaType codec_type);
00198
00199 int ff_rtsp_next_attr_and_value(const char **p, char *attr, int attr_size, char *value, int value_size);
00200
00201 int ff_parse_fmtp(AVStream *stream, PayloadContext *data, const char *p,
00202 int (*parse_fmtp)(AVStream *stream,
00203 PayloadContext *data,
00204 char *attr, char *value));
00205
00206 void av_register_rtp_dynamic_payload_handlers(void);
00207
00208 #endif