You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

198 lines
7.6KB

  1. /*
  2. * RTP definitions
  3. * Copyright (c) 2002 Fabrice Bellard
  4. * Copyright (c) 2006 Ryan Martell <rdm4@martellventures.com>
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #ifndef AVFORMAT_RTP_H
  23. #define AVFORMAT_RTP_H
  24. #include "libavcodec/avcodec.h"
  25. #include "avformat.h"
  26. /** Structure listing useful vars to parse RTP packet payload*/
  27. typedef struct rtp_payload_data
  28. {
  29. int sizelength;
  30. int indexlength;
  31. int indexdeltalength;
  32. int profile_level_id;
  33. int streamtype;
  34. int objecttype;
  35. char *mode;
  36. /** mpeg 4 AU headers */
  37. struct AUHeaders {
  38. int size;
  39. int index;
  40. int cts_flag;
  41. int cts;
  42. int dts_flag;
  43. int dts;
  44. int rap_flag;
  45. int streamstate;
  46. } *au_headers;
  47. int nb_au_headers;
  48. int au_headers_length_bytes;
  49. int cur_au_index;
  50. } RTPPayloadData;
  51. typedef struct PayloadContext PayloadContext;
  52. typedef struct RTPDynamicProtocolHandler_s RTPDynamicProtocolHandler;
  53. #define RTP_MIN_PACKET_LENGTH 12
  54. #define RTP_MAX_PACKET_LENGTH 1500 /* XXX: suppress this define */
  55. int rtp_get_codec_info(AVCodecContext *codec, int payload_type);
  56. /** return < 0 if unknown payload type */
  57. int rtp_get_payload_type(AVCodecContext *codec);
  58. typedef struct RTPDemuxContext RTPDemuxContext;
  59. RTPDemuxContext *rtp_parse_open(AVFormatContext *s1, AVStream *st, URLContext *rtpc, int payload_type, RTPPayloadData *rtp_payload_data);
  60. void rtp_parse_set_dynamic_protocol(RTPDemuxContext *s, PayloadContext *ctx,
  61. RTPDynamicProtocolHandler *handler);
  62. int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt,
  63. const uint8_t *buf, int len);
  64. void rtp_parse_close(RTPDemuxContext *s);
  65. int rtp_get_local_port(URLContext *h);
  66. int rtp_set_remote_url(URLContext *h, const char *uri);
  67. void rtp_get_file_handles(URLContext *h, int *prtp_fd, int *prtcp_fd);
  68. /**
  69. * some rtp servers assume client is dead if they don't hear from them...
  70. * so we send a Receiver Report to the provided ByteIO context
  71. * (we don't have access to the rtcp handle from here)
  72. */
  73. int rtp_check_and_send_back_rr(RTPDemuxContext *s, int count);
  74. #define RTP_PT_PRIVATE 96
  75. #define RTP_VERSION 2
  76. #define RTP_MAX_SDES 256 /**< maximum text length for SDES */
  77. /* RTCP paquets use 0.5 % of the bandwidth */
  78. #define RTCP_TX_RATIO_NUM 5
  79. #define RTCP_TX_RATIO_DEN 1000
  80. // these statistics are used for rtcp receiver reports...
  81. typedef struct {
  82. uint16_t max_seq; ///< highest sequence number seen
  83. uint32_t cycles; ///< shifted count of sequence number cycles
  84. uint32_t base_seq; ///< base sequence number
  85. uint32_t bad_seq; ///< last bad sequence number + 1
  86. int probation; ///< sequence packets till source is valid
  87. int received; ///< packets received
  88. int expected_prior; ///< packets expected in last interval
  89. int received_prior; ///< packets received in last interval
  90. uint32_t transit; ///< relative transit time for previous packet
  91. uint32_t jitter; ///< estimated jitter.
  92. } RTPStatistics;
  93. /**
  94. * Packet parsing for "private" payloads in the RTP specs.
  95. *
  96. * @param s stream context
  97. * @param st stream that this packet belongs to
  98. * @param pkt packet in which to write the parsed data
  99. * @param timestamp pointer in which to write the timestamp of this RTP packet
  100. * @param buf pointer to raw RTP packet data
  101. * @param len length of buf
  102. * @param flags flags from the RTP packet header (PKT_FLAG_*)
  103. */
  104. typedef int (*DynamicPayloadPacketHandlerProc) (PayloadContext *s,
  105. AVStream *st,
  106. AVPacket * pkt,
  107. uint32_t *timestamp,
  108. const uint8_t * buf,
  109. int len, int flags);
  110. struct RTPDynamicProtocolHandler_s {
  111. // fields from AVRtpDynamicPayloadType_s
  112. const char enc_name[50]; /* XXX: still why 50 ? ;-) */
  113. enum CodecType codec_type;
  114. enum CodecID codec_id;
  115. // may be null
  116. int (*parse_sdp_a_line) (AVFormatContext *s,
  117. int st_index,
  118. PayloadContext *priv_data,
  119. const char *line); ///< Parse the a= line from the sdp field
  120. PayloadContext *(*open) (); ///< allocate any data needed by the rtp parsing for this dynamic data.
  121. void (*close)(PayloadContext *protocol_data); ///< free any data needed by the rtp parsing for this dynamic data.
  122. DynamicPayloadPacketHandlerProc parse_packet; ///< parse handler for this dynamic packet.
  123. struct RTPDynamicProtocolHandler_s *next;
  124. };
  125. // moved out of rtp.c, because the h264 decoder needs to know about this structure..
  126. struct RTPDemuxContext {
  127. AVFormatContext *ic;
  128. AVStream *st;
  129. int payload_type;
  130. uint32_t ssrc;
  131. uint16_t seq;
  132. uint32_t timestamp;
  133. uint32_t base_timestamp;
  134. uint32_t cur_timestamp;
  135. int max_payload_size;
  136. struct MpegTSContext *ts; /* only used for MP2T payloads */
  137. int read_buf_index;
  138. int read_buf_size;
  139. /* used to send back RTCP RR */
  140. URLContext *rtp_ctx;
  141. char hostname[256];
  142. RTPStatistics statistics; ///< Statistics for this stream (used by RTCP receiver reports)
  143. /* rtcp sender statistics receive */
  144. int64_t last_rtcp_ntp_time; // TODO: move into statistics
  145. int64_t first_rtcp_ntp_time; // TODO: move into statistics
  146. uint32_t last_rtcp_timestamp; // TODO: move into statistics
  147. /* rtcp sender statistics */
  148. unsigned int packet_count; // TODO: move into statistics (outgoing)
  149. unsigned int octet_count; // TODO: move into statistics (outgoing)
  150. unsigned int last_octet_count; // TODO: move into statistics (outgoing)
  151. int first_packet;
  152. /* buffer for output */
  153. uint8_t buf[RTP_MAX_PACKET_LENGTH];
  154. uint8_t *buf_ptr;
  155. /* special infos for au headers parsing */
  156. RTPPayloadData *rtp_payload_data; // TODO: Move into dynamic payload handlers
  157. /* dynamic payload stuff */
  158. DynamicPayloadPacketHandlerProc parse_packet; ///< This is also copied from the dynamic protocol handler structure
  159. PayloadContext *dynamic_protocol_context; ///< This is a copy from the values setup from the sdp parsing, in rtsp.c don't free me.
  160. int max_frames_per_packet;
  161. };
  162. extern RTPDynamicProtocolHandler *RTPFirstDynamicPayloadHandler;
  163. void ff_register_dynamic_payload_handler(RTPDynamicProtocolHandler *handler);
  164. int rtsp_next_attr_and_value(const char **p, char *attr, int attr_size, char *value, int value_size); ///< from rtsp.c, but used by rtp dynamic protocol handlers.
  165. void ff_rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m);
  166. const char *ff_rtp_enc_name(int payload_type);
  167. enum CodecID ff_rtp_codec_id(const char *buf, enum CodecType codec_type);
  168. void av_register_rtp_dynamic_payload_handlers(void);
  169. #endif /* AVFORMAT_RTP_H */