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 *ff_rtp_parse_open(AVFormatContext *s1, AVStream *st, URLContext *rtpc, int payload_type, int queue_size);
00042 void ff_rtp_parse_set_dynamic_protocol(RTPDemuxContext *s, PayloadContext *ctx,
00043 RTPDynamicProtocolHandler *handler);
00044 int ff_rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt,
00045 uint8_t **buf, int len);
00046 void ff_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 ff_rtp_get_local_rtp_port(URLContext *h);
00050 int ff_rtp_get_local_rtcp_port(URLContext *h);
00051
00052 int ff_rtp_set_remote_url(URLContext *h, const char *uri);
00053
00065 void ff_rtp_send_punch_packets(URLContext* rtp_handle);
00066
00072 int ff_rtp_check_and_send_back_rr(RTPDemuxContext *s, int count);
00073
00077 int ff_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 (*init)(AVFormatContext *s, int st_index, PayloadContext *priv_data);
00126 int (*parse_sdp_a_line) (AVFormatContext *s,
00127 int st_index,
00128 PayloadContext *priv_data,
00129 const char *line);
00130 PayloadContext *(*alloc) (void);
00131 void (*free)(PayloadContext *protocol_data);
00132 DynamicPayloadPacketHandlerProc parse_packet;
00133
00134 struct RTPDynamicProtocolHandler_s *next;
00135 };
00136
00137 typedef struct RTPPacket {
00138 uint16_t seq;
00139 uint8_t *buf;
00140 int len;
00141 int64_t recvtime;
00142 struct RTPPacket *next;
00143 } RTPPacket;
00144
00145
00146 struct RTPDemuxContext {
00147 AVFormatContext *ic;
00148 AVStream *st;
00149 int payload_type;
00150 uint32_t ssrc;
00151 uint16_t seq;
00152 uint32_t timestamp;
00153 uint32_t base_timestamp;
00154 uint32_t cur_timestamp;
00155 int64_t unwrapped_timestamp;
00156 int64_t range_start_offset;
00157 int max_payload_size;
00158 struct MpegTSContext *ts;
00159 int read_buf_index;
00160 int read_buf_size;
00161
00162 URLContext *rtp_ctx;
00163 char hostname[256];
00164
00165 RTPStatistics statistics;
00166
00168 int prev_ret;
00169 RTPPacket* queue;
00170 int queue_len;
00171 int queue_size;
00172
00174
00175 int64_t last_rtcp_ntp_time;
00176 int64_t first_rtcp_ntp_time;
00177 uint32_t last_rtcp_timestamp;
00178 int64_t rtcp_ts_offset;
00179
00180
00181 unsigned int packet_count;
00182 unsigned int octet_count;
00183 unsigned int last_octet_count;
00184 int first_packet;
00185
00186 uint8_t buf[RTP_MAX_PACKET_LENGTH];
00187 uint8_t *buf_ptr;
00188
00189
00190 DynamicPayloadPacketHandlerProc parse_packet;
00191 PayloadContext *dynamic_protocol_context;
00192 int max_frames_per_packet;
00193 };
00194
00195 void ff_register_dynamic_payload_handler(RTPDynamicProtocolHandler *handler);
00196 RTPDynamicProtocolHandler *ff_rtp_handler_find_by_name(const char *name,
00197 enum AVMediaType codec_type);
00198 RTPDynamicProtocolHandler *ff_rtp_handler_find_by_id(int id,
00199 enum AVMediaType codec_type);
00200
00201 int ff_rtsp_next_attr_and_value(const char **p, char *attr, int attr_size, char *value, int value_size);
00202
00203 int ff_parse_fmtp(AVStream *stream, PayloadContext *data, const char *p,
00204 int (*parse_fmtp)(AVStream *stream,
00205 PayloadContext *data,
00206 char *attr, char *value));
00207
00208 void av_register_rtp_dynamic_payload_handlers(void);
00209
00210 #endif