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.

141 lines
4.8 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * libjingle
  3. * Copyright 2012 Google Inc.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. * 3. The name of the author may not be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  19. * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  22. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  23. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  24. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  25. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #ifndef TALK_MEDIA_BASE_RTPDATAENGINE_H_
  28. #define TALK_MEDIA_BASE_RTPDATAENGINE_H_
  29. #include <string>
  30. #include <vector>
  31. #include "talk/base/timing.h"
  32. #include "talk/media/base/mediachannel.h"
  33. #include "talk/media/base/mediaengine.h"
  34. namespace cricket {
  35. static const int kGoogleDataCodecId = 101;
  36. static const char kGoogleDataCodecName[] = "google-data";
  37. struct DataCodec;
  38. class RtpDataEngine : public DataEngineInterface {
  39. public:
  40. RtpDataEngine();
  41. virtual DataMediaChannel* CreateChannel();
  42. virtual const std::vector<DataCodec>& data_codecs() {
  43. return data_codecs_;
  44. }
  45. // Mostly for testing with a fake clock. Ownership is passed in.
  46. void SetTiming(talk_base::Timing* timing) {
  47. timing_.reset(timing);
  48. }
  49. private:
  50. std::vector<DataCodec> data_codecs_;
  51. talk_base::scoped_ptr<talk_base::Timing> timing_;
  52. };
  53. // Keep track of sequence number and timestamp of an RTP stream. The
  54. // sequence number starts with a "random" value and increments. The
  55. // timestamp starts with a "random" value and increases monotonically
  56. // according to the clockrate.
  57. class RtpClock {
  58. public:
  59. RtpClock(int clockrate, uint16 first_seq_num, uint32 timestamp_offset)
  60. : clockrate_(clockrate),
  61. last_seq_num_(first_seq_num),
  62. timestamp_offset_(timestamp_offset) {
  63. }
  64. // Given the current time (in number of seconds which must be
  65. // monotonically increasing), Return the next sequence number and
  66. // timestamp.
  67. void Tick(double now, int* seq_num, uint32* timestamp);
  68. private:
  69. int clockrate_;
  70. uint16 last_seq_num_;
  71. uint32 timestamp_offset_;
  72. };
  73. class RtpDataMediaChannel : public DataMediaChannel {
  74. public:
  75. // Timing* Used for the RtpClock
  76. explicit RtpDataMediaChannel(talk_base::Timing* timing);
  77. // Sets Timing == NULL, so you'll need to call set_timer() before
  78. // using it. This is needed by FakeMediaEngine.
  79. RtpDataMediaChannel();
  80. virtual ~RtpDataMediaChannel();
  81. void set_timing(talk_base::Timing* timing) {
  82. timing_ = timing;
  83. }
  84. virtual bool SetSendBandwidth(bool autobw, int bps);
  85. virtual bool SetRecvRtpHeaderExtensions(
  86. const std::vector<RtpHeaderExtension>& extensions) { return true; }
  87. virtual bool SetSendRtpHeaderExtensions(
  88. const std::vector<RtpHeaderExtension>& extensions) { return true; }
  89. virtual bool SetSendCodecs(const std::vector<DataCodec>& codecs);
  90. virtual bool SetRecvCodecs(const std::vector<DataCodec>& codecs);
  91. virtual bool AddSendStream(const StreamParams& sp);
  92. virtual bool RemoveSendStream(uint32 ssrc);
  93. virtual bool AddRecvStream(const StreamParams& sp);
  94. virtual bool RemoveRecvStream(uint32 ssrc);
  95. virtual bool SetSend(bool send) {
  96. sending_ = send;
  97. return true;
  98. }
  99. virtual bool SetReceive(bool receive) {
  100. receiving_ = receive;
  101. return true;
  102. }
  103. virtual void OnPacketReceived(talk_base::Buffer* packet);
  104. virtual void OnRtcpReceived(talk_base::Buffer* packet) {}
  105. virtual bool SendData(
  106. const SendDataParams& params, const std::string& data);
  107. private:
  108. void Construct(talk_base::Timing* timing);
  109. bool sending_;
  110. bool receiving_;
  111. talk_base::Timing* timing_;
  112. std::vector<DataCodec> send_codecs_;
  113. std::vector<DataCodec> recv_codecs_;
  114. std::vector<StreamParams> send_streams_;
  115. std::vector<StreamParams> recv_streams_;
  116. std::map<uint32, RtpClock*> rtp_clock_by_send_ssrc_;
  117. talk_base::scoped_ptr<talk_base::RateLimiter> send_limiter_;
  118. };
  119. } // namespace cricket
  120. #endif // TALK_MEDIA_BASE_RTPDATAENGINE_H_