Libav 0.7.1
|
00001 /* 00002 * RTP demuxer definitions 00003 * Copyright (c) 2002 Fabrice Bellard 00004 * Copyright (c) 2006 Ryan Martell <rdm4@martellventures.com> 00005 * 00006 * This file is part of Libav. 00007 * 00008 * Libav is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2.1 of the License, or (at your option) any later version. 00012 * 00013 * Libav is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with Libav; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 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 /* XXX: suppress this define */ 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 // these statistics are used for rtcp receiver reports... 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 ///< RTP packet contains a keyframe 00094 #define RTP_FLAG_MARKER 0x2 ///< RTP marker bit was set for this packet 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 // fields from AVRtpDynamicPayloadType_s 00117 const char enc_name[50]; /* XXX: still why 50 ? ;-) */ 00118 enum AVMediaType codec_type; 00119 enum CodecID codec_id; 00120 int static_payload_id; /* 0 means no payload id is set. 0 is a valid 00121 * payload ID (PCMU), too, but that format doesn't 00122 * require any custom depacketization code. */ 00123 00124 // may be null 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 // moved out of rtp.c, because the h264 decoder needs to know about this structure.. 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; /* only used for MP2T payloads */ 00157 int read_buf_index; 00158 int read_buf_size; 00159 /* used to send back RTCP RR */ 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 /* rtcp sender statistics receive */ 00173 int64_t last_rtcp_ntp_time; // TODO: move into statistics 00174 int64_t first_rtcp_ntp_time; // TODO: move into statistics 00175 uint32_t last_rtcp_timestamp; // TODO: move into statistics 00176 int64_t rtcp_ts_offset; 00177 00178 /* rtcp sender statistics */ 00179 unsigned int packet_count; // TODO: move into statistics (outgoing) 00180 unsigned int octet_count; // TODO: move into statistics (outgoing) 00181 unsigned int last_octet_count; // TODO: move into statistics (outgoing) 00182 int first_packet; 00183 /* buffer for output */ 00184 uint8_t buf[RTP_MAX_PACKET_LENGTH]; 00185 uint8_t *buf_ptr; 00186 00187 /* dynamic payload stuff */ 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 /* AVFORMAT_RTPDEC_H */