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.

136 lines
5.6KB

  1. /*
  2. * RTP definitions
  3. * Copyright (c) 2006 Ryan Martell <rdm4@martellventures.com>
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. // this is a bit of a misnomer, because rtp & rtsp internal structures and prototypes are in here.
  22. #ifndef AVFORMAT_RTP_INTERNAL_H
  23. #define AVFORMAT_RTP_INTERNAL_H
  24. #include <stdint.h>
  25. #include "libavcodec/avcodec.h"
  26. #include "rtp.h"
  27. // these statistics are used for rtcp receiver reports...
  28. typedef struct {
  29. uint16_t max_seq; ///< highest sequence number seen
  30. uint32_t cycles; ///< shifted count of sequence number cycles
  31. uint32_t base_seq; ///< base sequence number
  32. uint32_t bad_seq; ///< last bad sequence number + 1
  33. int probation; ///< sequence packets till source is valid
  34. int received; ///< packets received
  35. int expected_prior; ///< packets expected in last interval
  36. int received_prior; ///< packets received in last interval
  37. uint32_t transit; ///< relative transit time for previous packet
  38. uint32_t jitter; ///< estimated jitter.
  39. } RTPStatistics;
  40. /**
  41. * Packet parsing for "private" payloads in the RTP specs.
  42. *
  43. * @param s stream context
  44. * @param st stream that this packet belongs to
  45. * @param pkt packet in which to write the parsed data
  46. * @param timestamp pointer in which to write the timestamp of this RTP packet
  47. * @param buf pointer to raw RTP packet data
  48. * @param len length of buf
  49. * @param flags flags from the RTP packet header (PKT_FLAG_*)
  50. */
  51. typedef int (*DynamicPayloadPacketHandlerProc) (PayloadContext *s,
  52. AVStream *st,
  53. AVPacket * pkt,
  54. uint32_t *timestamp,
  55. const uint8_t * buf,
  56. int len, int flags);
  57. struct RTPDynamicProtocolHandler_s {
  58. // fields from AVRtpDynamicPayloadType_s
  59. const char enc_name[50]; /* XXX: still why 50 ? ;-) */
  60. enum CodecType codec_type;
  61. enum CodecID codec_id;
  62. // may be null
  63. int (*parse_sdp_a_line) (AVFormatContext *s,
  64. int st_index,
  65. PayloadContext *priv_data,
  66. const char *line); ///< Parse the a= line from the sdp field
  67. PayloadContext *(*open) (); ///< allocate any data needed by the rtp parsing for this dynamic data.
  68. void (*close)(PayloadContext *protocol_data); ///< free any data needed by the rtp parsing for this dynamic data.
  69. DynamicPayloadPacketHandlerProc parse_packet; ///< parse handler for this dynamic packet.
  70. struct RTPDynamicProtocolHandler_s *next;
  71. };
  72. // moved out of rtp.c, because the h264 decoder needs to know about this structure..
  73. struct RTPDemuxContext {
  74. AVFormatContext *ic;
  75. AVStream *st;
  76. int payload_type;
  77. uint32_t ssrc;
  78. uint16_t seq;
  79. uint32_t timestamp;
  80. uint32_t base_timestamp;
  81. uint32_t cur_timestamp;
  82. int max_payload_size;
  83. struct MpegTSContext *ts; /* only used for MP2T payloads */
  84. int read_buf_index;
  85. int read_buf_size;
  86. /* used to send back RTCP RR */
  87. URLContext *rtp_ctx;
  88. char hostname[256];
  89. RTPStatistics statistics; ///< Statistics for this stream (used by RTCP receiver reports)
  90. /* rtcp sender statistics receive */
  91. int64_t last_rtcp_ntp_time; // TODO: move into statistics
  92. int64_t first_rtcp_ntp_time; // TODO: move into statistics
  93. uint32_t last_rtcp_timestamp; // TODO: move into statistics
  94. /* rtcp sender statistics */
  95. unsigned int packet_count; // TODO: move into statistics (outgoing)
  96. unsigned int octet_count; // TODO: move into statistics (outgoing)
  97. unsigned int last_octet_count; // TODO: move into statistics (outgoing)
  98. int first_packet;
  99. /* buffer for output */
  100. uint8_t buf[RTP_MAX_PACKET_LENGTH];
  101. uint8_t *buf_ptr;
  102. /* special infos for au headers parsing */
  103. RTPPayloadData *rtp_payload_data; // TODO: Move into dynamic payload handlers
  104. /* dynamic payload stuff */
  105. DynamicPayloadPacketHandlerProc parse_packet; ///< This is also copied from the dynamic protocol handler structure
  106. PayloadContext *dynamic_protocol_context; ///< This is a copy from the values setup from the sdp parsing, in rtsp.c don't free me.
  107. int max_frames_per_packet;
  108. };
  109. extern RTPDynamicProtocolHandler *RTPFirstDynamicPayloadHandler;
  110. void ff_register_dynamic_payload_handler(RTPDynamicProtocolHandler *handler);
  111. 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.
  112. void ff_rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m);
  113. const char *ff_rtp_enc_name(int payload_type);
  114. enum CodecID ff_rtp_codec_id(const char *buf, enum CodecType codec_type);
  115. void av_register_rtp_dynamic_payload_handlers(void);
  116. #endif /* AVFORMAT_RTP_INTERNAL_H */