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
00074
00075 typedef struct {
00076 uint16_t max_seq;
00077 uint32_t cycles;
00078 uint32_t base_seq;
00079 uint32_t bad_seq;
00080 int probation;
00081 int received;
00082 int expected_prior;
00083 int received_prior;
00084 uint32_t transit;
00085 uint32_t jitter;
00086 } RTPStatistics;
00087
00088 #define RTP_FLAG_KEY 0x1
00089 #define RTP_FLAG_MARKER 0x2
00090
00102 typedef int (*DynamicPayloadPacketHandlerProc) (AVFormatContext *ctx,
00103 PayloadContext *s,
00104 AVStream *st,
00105 AVPacket * pkt,
00106 uint32_t *timestamp,
00107 const uint8_t * buf,
00108 int len, int flags);
00109
00110 struct RTPDynamicProtocolHandler_s {
00111
00112 const char enc_name[50];
00113 enum AVMediaType codec_type;
00114 enum AVCodecID codec_id;
00115 int static_payload_id;
00116
00117
00118
00119
00120 int (*init)(AVFormatContext *s, int st_index, PayloadContext *priv_data);
00121 int (*parse_sdp_a_line) (AVFormatContext *s,
00122 int st_index,
00123 PayloadContext *priv_data,
00124 const char *line);
00125 PayloadContext *(*alloc) (void);
00126 void (*free)(PayloadContext *protocol_data);
00127 DynamicPayloadPacketHandlerProc parse_packet;
00128
00129 struct RTPDynamicProtocolHandler_s *next;
00130 };
00131
00132 typedef struct RTPPacket {
00133 uint16_t seq;
00134 uint8_t *buf;
00135 int len;
00136 int64_t recvtime;
00137 struct RTPPacket *next;
00138 } RTPPacket;
00139
00140
00141 struct RTPDemuxContext {
00142 AVFormatContext *ic;
00143 AVStream *st;
00144 int payload_type;
00145 uint32_t ssrc;
00146 uint16_t seq;
00147 uint32_t timestamp;
00148 uint32_t base_timestamp;
00149 uint32_t cur_timestamp;
00150 int64_t unwrapped_timestamp;
00151 int64_t range_start_offset;
00152 int max_payload_size;
00153 struct MpegTSContext *ts;
00154 int read_buf_index;
00155 int read_buf_size;
00156
00157 URLContext *rtp_ctx;
00158 char hostname[256];
00159
00160 RTPStatistics statistics;
00161
00163 int prev_ret;
00164 RTPPacket* queue;
00165 int queue_len;
00166 int queue_size;
00167
00169
00170 int64_t last_rtcp_ntp_time;
00171 int64_t first_rtcp_ntp_time;
00172 uint32_t last_rtcp_timestamp;
00173 int64_t rtcp_ts_offset;
00174
00175
00176 unsigned int packet_count;
00177 unsigned int octet_count;
00178 unsigned int last_octet_count;
00179 int first_packet;
00180
00181 uint8_t buf[RTP_MAX_PACKET_LENGTH];
00182 uint8_t *buf_ptr;
00183
00184
00185 DynamicPayloadPacketHandlerProc parse_packet;
00186 PayloadContext *dynamic_protocol_context;
00187 int max_frames_per_packet;
00188 };
00189
00190 void ff_register_dynamic_payload_handler(RTPDynamicProtocolHandler *handler);
00191 RTPDynamicProtocolHandler *ff_rtp_handler_find_by_name(const char *name,
00192 enum AVMediaType codec_type);
00193 RTPDynamicProtocolHandler *ff_rtp_handler_find_by_id(int id,
00194 enum AVMediaType codec_type);
00195
00196 int ff_rtsp_next_attr_and_value(const char **p, char *attr, int attr_size, char *value, int value_size);
00197
00198 int ff_parse_fmtp(AVStream *stream, PayloadContext *data, const char *p,
00199 int (*parse_fmtp)(AVStream *stream,
00200 PayloadContext *data,
00201 char *attr, char *value));
00202
00203 void av_register_rtp_dynamic_payload_handlers(void);
00204
00205 #endif