Libav
|
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 FFmpeg. 00007 * 00008 * FFmpeg 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 * FFmpeg 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 FFmpeg; 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 00030 typedef struct rtp_payload_data 00031 { 00032 int sizelength; 00033 int indexlength; 00034 int indexdeltalength; 00035 int profile_level_id; 00036 int streamtype; 00037 int objecttype; 00038 char *mode; 00039 00041 struct AUHeaders { 00042 int size; 00043 int index; 00044 int cts_flag; 00045 int cts; 00046 int dts_flag; 00047 int dts; 00048 int rap_flag; 00049 int streamstate; 00050 } *au_headers; 00051 int au_headers_allocated; 00052 int nb_au_headers; 00053 int au_headers_length_bytes; 00054 int cur_au_index; 00055 } RTPPayloadData; 00056 00057 typedef struct PayloadContext PayloadContext; 00058 typedef struct RTPDynamicProtocolHandler_s RTPDynamicProtocolHandler; 00059 00060 #define RTP_MIN_PACKET_LENGTH 12 00061 #define RTP_MAX_PACKET_LENGTH 1500 /* XXX: suppress this define */ 00062 00063 typedef struct RTPDemuxContext RTPDemuxContext; 00064 RTPDemuxContext *rtp_parse_open(AVFormatContext *s1, AVStream *st, URLContext *rtpc, int payload_type, RTPPayloadData *rtp_payload_data); 00065 void rtp_parse_set_dynamic_protocol(RTPDemuxContext *s, PayloadContext *ctx, 00066 RTPDynamicProtocolHandler *handler); 00067 int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt, 00068 const uint8_t *buf, int len); 00069 void rtp_parse_close(RTPDemuxContext *s); 00070 #if (LIBAVFORMAT_VERSION_MAJOR <= 53) 00071 int rtp_get_local_port(URLContext *h); 00072 #endif 00073 int rtp_get_local_rtp_port(URLContext *h); 00074 int rtp_get_local_rtcp_port(URLContext *h); 00075 00076 int rtp_set_remote_url(URLContext *h, const char *uri); 00077 #if (LIBAVFORMAT_VERSION_MAJOR <= 52) 00078 void rtp_get_file_handles(URLContext *h, int *prtp_fd, int *prtcp_fd); 00079 #endif 00080 00092 void rtp_send_punch_packets(URLContext* rtp_handle); 00093 00099 int rtp_check_and_send_back_rr(RTPDemuxContext *s, int count); 00100 00101 // these statistics are used for rtcp receiver reports... 00102 typedef struct { 00103 uint16_t max_seq; 00104 uint32_t cycles; 00105 uint32_t base_seq; 00106 uint32_t bad_seq; 00107 int probation; 00108 int received; 00109 int expected_prior; 00110 int received_prior; 00111 uint32_t transit; 00112 uint32_t jitter; 00113 } RTPStatistics; 00114 00115 #define RTP_FLAG_KEY 0x1 ///< RTP packet contains a keyframe 00116 #define RTP_FLAG_MARKER 0x2 ///< RTP marker bit was set for this packet 00117 00129 typedef int (*DynamicPayloadPacketHandlerProc) (AVFormatContext *ctx, 00130 PayloadContext *s, 00131 AVStream *st, 00132 AVPacket * pkt, 00133 uint32_t *timestamp, 00134 const uint8_t * buf, 00135 int len, int flags); 00136 00137 struct RTPDynamicProtocolHandler_s { 00138 // fields from AVRtpDynamicPayloadType_s 00139 const char enc_name[50]; /* XXX: still why 50 ? ;-) */ 00140 enum AVMediaType codec_type; 00141 enum CodecID codec_id; 00142 00143 // may be null 00144 int (*parse_sdp_a_line) (AVFormatContext *s, 00145 int st_index, 00146 PayloadContext *priv_data, 00147 const char *line); 00148 PayloadContext *(*open) (void); 00149 void (*close)(PayloadContext *protocol_data); 00150 DynamicPayloadPacketHandlerProc parse_packet; 00151 00152 struct RTPDynamicProtocolHandler_s *next; 00153 }; 00154 00155 // moved out of rtp.c, because the h264 decoder needs to know about this structure.. 00156 struct RTPDemuxContext { 00157 AVFormatContext *ic; 00158 AVStream *st; 00159 int payload_type; 00160 uint32_t ssrc; 00161 uint16_t seq; 00162 uint32_t timestamp; 00163 uint32_t base_timestamp; 00164 uint32_t cur_timestamp; 00165 int64_t range_start_offset; 00166 int max_payload_size; 00167 struct MpegTSContext *ts; /* only used for MP2T payloads */ 00168 int read_buf_index; 00169 int read_buf_size; 00170 /* used to send back RTCP RR */ 00171 URLContext *rtp_ctx; 00172 char hostname[256]; 00173 00174 RTPStatistics statistics; 00175 00176 /* rtcp sender statistics receive */ 00177 int64_t last_rtcp_ntp_time; // TODO: move into statistics 00178 int64_t first_rtcp_ntp_time; // TODO: move into statistics 00179 uint32_t last_rtcp_timestamp; // TODO: move into statistics 00180 00181 /* rtcp sender statistics */ 00182 unsigned int packet_count; // TODO: move into statistics (outgoing) 00183 unsigned int octet_count; // TODO: move into statistics (outgoing) 00184 unsigned int last_octet_count; // TODO: move into statistics (outgoing) 00185 int first_packet; 00186 /* buffer for output */ 00187 uint8_t buf[RTP_MAX_PACKET_LENGTH]; 00188 uint8_t *buf_ptr; 00189 00190 /* special infos for au headers parsing */ 00191 RTPPayloadData *rtp_payload_data; // TODO: Move into dynamic payload handlers 00192 00193 /* dynamic payload stuff */ 00194 DynamicPayloadPacketHandlerProc parse_packet; 00195 PayloadContext *dynamic_protocol_context; 00196 int max_frames_per_packet; 00197 }; 00198 00199 extern RTPDynamicProtocolHandler *RTPFirstDynamicPayloadHandler; 00200 void ff_register_dynamic_payload_handler(RTPDynamicProtocolHandler *handler); 00201 00202 int ff_rtsp_next_attr_and_value(const char **p, char *attr, int attr_size, char *value, int value_size); 00203 00204 void av_register_rtp_dynamic_payload_handlers(void); 00205 00206 #endif /* AVFORMAT_RTPDEC_H */