rtp_data_engine.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef MEDIA_BASE_RTP_DATA_ENGINE_H_
  11. #define MEDIA_BASE_RTP_DATA_ENGINE_H_
  12. #include <map>
  13. #include <memory>
  14. #include <string>
  15. #include <vector>
  16. #include "media/base/codec.h"
  17. #include "media/base/media_channel.h"
  18. #include "media/base/media_constants.h"
  19. #include "media/base/media_engine.h"
  20. namespace rtc {
  21. class DataRateLimiter;
  22. }
  23. namespace cricket {
  24. class RtpDataEngine : public DataEngineInterface {
  25. public:
  26. RtpDataEngine();
  27. virtual DataMediaChannel* CreateChannel(const MediaConfig& config);
  28. virtual const std::vector<DataCodec>& data_codecs() { return data_codecs_; }
  29. private:
  30. std::vector<DataCodec> data_codecs_;
  31. };
  32. // Keep track of sequence number and timestamp of an RTP stream. The
  33. // sequence number starts with a "random" value and increments. The
  34. // timestamp starts with a "random" value and increases monotonically
  35. // according to the clockrate.
  36. class RtpClock {
  37. public:
  38. RtpClock(int clockrate, uint16_t first_seq_num, uint32_t timestamp_offset)
  39. : clockrate_(clockrate),
  40. last_seq_num_(first_seq_num),
  41. timestamp_offset_(timestamp_offset) {}
  42. // Given the current time (in number of seconds which must be
  43. // monotonically increasing), Return the next sequence number and
  44. // timestamp.
  45. void Tick(double now, int* seq_num, uint32_t* timestamp);
  46. private:
  47. int clockrate_;
  48. uint16_t last_seq_num_;
  49. uint32_t timestamp_offset_;
  50. };
  51. class RtpDataMediaChannel : public DataMediaChannel {
  52. public:
  53. explicit RtpDataMediaChannel(const MediaConfig& config);
  54. virtual ~RtpDataMediaChannel();
  55. virtual bool SetSendParameters(const DataSendParameters& params);
  56. virtual bool SetRecvParameters(const DataRecvParameters& params);
  57. virtual bool AddSendStream(const StreamParams& sp);
  58. virtual bool RemoveSendStream(uint32_t ssrc);
  59. virtual bool AddRecvStream(const StreamParams& sp);
  60. virtual bool RemoveRecvStream(uint32_t ssrc);
  61. virtual void ResetUnsignaledRecvStream();
  62. virtual bool SetSend(bool send) {
  63. sending_ = send;
  64. return true;
  65. }
  66. virtual bool SetReceive(bool receive) {
  67. receiving_ = receive;
  68. return true;
  69. }
  70. virtual void OnPacketReceived(rtc::CopyOnWriteBuffer packet,
  71. int64_t packet_time_us);
  72. virtual void OnReadyToSend(bool ready) {}
  73. virtual bool SendData(const SendDataParams& params,
  74. const rtc::CopyOnWriteBuffer& payload,
  75. SendDataResult* result);
  76. private:
  77. void Construct();
  78. bool SetMaxSendBandwidth(int bps);
  79. bool SetSendCodecs(const std::vector<DataCodec>& codecs);
  80. bool SetRecvCodecs(const std::vector<DataCodec>& codecs);
  81. bool sending_;
  82. bool receiving_;
  83. std::vector<DataCodec> send_codecs_;
  84. std::vector<DataCodec> recv_codecs_;
  85. std::vector<StreamParams> send_streams_;
  86. std::vector<StreamParams> recv_streams_;
  87. std::map<uint32_t, RtpClock*> rtp_clock_by_send_ssrc_;
  88. std::unique_ptr<rtc::DataRateLimiter> send_limiter_;
  89. };
  90. } // namespace cricket
  91. #endif // MEDIA_BASE_RTP_DATA_ENGINE_H_