OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_MEDIA_BASE_RTPDATAENGINE_H_ | 11 #ifndef WEBRTC_MEDIA_BASE_RTPDATAENGINE_H_ |
12 #define WEBRTC_MEDIA_BASE_RTPDATAENGINE_H_ | 12 #define WEBRTC_MEDIA_BASE_RTPDATAENGINE_H_ |
13 | 13 |
14 #include <memory> | 14 #include <memory> |
15 #include <string> | 15 #include <string> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 #include "webrtc/base/timing.h" | |
19 #include "webrtc/media/base/mediachannel.h" | 18 #include "webrtc/media/base/mediachannel.h" |
20 #include "webrtc/media/base/mediaconstants.h" | 19 #include "webrtc/media/base/mediaconstants.h" |
21 #include "webrtc/media/base/mediaengine.h" | 20 #include "webrtc/media/base/mediaengine.h" |
22 | 21 |
23 namespace cricket { | 22 namespace cricket { |
24 | 23 |
25 struct DataCodec; | 24 struct DataCodec; |
26 | 25 |
27 class RtpDataEngine : public DataEngineInterface { | 26 class RtpDataEngine : public DataEngineInterface { |
28 public: | 27 public: |
29 RtpDataEngine(); | 28 RtpDataEngine(); |
30 | 29 |
31 virtual DataMediaChannel* CreateChannel(DataChannelType data_channel_type); | 30 virtual DataMediaChannel* CreateChannel(DataChannelType data_channel_type); |
32 | 31 |
33 virtual const std::vector<DataCodec>& data_codecs() { | 32 virtual const std::vector<DataCodec>& data_codecs() { |
34 return data_codecs_; | 33 return data_codecs_; |
35 } | 34 } |
36 | 35 |
37 // Mostly for testing with a fake clock. Ownership is passed in. | |
38 void SetTiming(rtc::Timing* timing) { | |
39 timing_.reset(timing); | |
40 } | |
41 | |
42 private: | 36 private: |
43 std::vector<DataCodec> data_codecs_; | 37 std::vector<DataCodec> data_codecs_; |
44 std::unique_ptr<rtc::Timing> timing_; | |
45 }; | 38 }; |
46 | 39 |
47 // Keep track of sequence number and timestamp of an RTP stream. The | 40 // Keep track of sequence number and timestamp of an RTP stream. The |
48 // sequence number starts with a "random" value and increments. The | 41 // sequence number starts with a "random" value and increments. The |
49 // timestamp starts with a "random" value and increases monotonically | 42 // timestamp starts with a "random" value and increases monotonically |
50 // according to the clockrate. | 43 // according to the clockrate. |
51 class RtpClock { | 44 class RtpClock { |
52 public: | 45 public: |
53 RtpClock(int clockrate, uint16_t first_seq_num, uint32_t timestamp_offset) | 46 RtpClock(int clockrate, uint16_t first_seq_num, uint32_t timestamp_offset) |
54 : clockrate_(clockrate), | 47 : clockrate_(clockrate), |
55 last_seq_num_(first_seq_num), | 48 last_seq_num_(first_seq_num), |
56 timestamp_offset_(timestamp_offset) {} | 49 timestamp_offset_(timestamp_offset) {} |
57 | 50 |
58 // Given the current time (in number of seconds which must be | 51 // Given the current time (in number of seconds which must be |
59 // monotonically increasing), Return the next sequence number and | 52 // monotonically increasing), Return the next sequence number and |
60 // timestamp. | 53 // timestamp. |
61 void Tick(double now, int* seq_num, uint32_t* timestamp); | 54 void Tick(double now, int* seq_num, uint32_t* timestamp); |
62 | 55 |
63 private: | 56 private: |
64 int clockrate_; | 57 int clockrate_; |
65 uint16_t last_seq_num_; | 58 uint16_t last_seq_num_; |
66 uint32_t timestamp_offset_; | 59 uint32_t timestamp_offset_; |
67 }; | 60 }; |
68 | 61 |
69 class RtpDataMediaChannel : public DataMediaChannel { | 62 class RtpDataMediaChannel : public DataMediaChannel { |
70 public: | 63 public: |
71 // Timing* Used for the RtpClock | |
72 explicit RtpDataMediaChannel(rtc::Timing* timing); | |
73 // Sets Timing == NULL, so you'll need to call set_timer() before | |
74 // using it. This is needed by FakeMediaEngine. | |
75 RtpDataMediaChannel(); | 64 RtpDataMediaChannel(); |
76 virtual ~RtpDataMediaChannel(); | 65 virtual ~RtpDataMediaChannel(); |
77 | 66 |
78 void set_timing(rtc::Timing* timing) { | |
79 timing_ = timing; | |
80 } | |
81 | |
82 virtual bool SetSendParameters(const DataSendParameters& params); | 67 virtual bool SetSendParameters(const DataSendParameters& params); |
83 virtual bool SetRecvParameters(const DataRecvParameters& params); | 68 virtual bool SetRecvParameters(const DataRecvParameters& params); |
84 virtual bool AddSendStream(const StreamParams& sp); | 69 virtual bool AddSendStream(const StreamParams& sp); |
85 virtual bool RemoveSendStream(uint32_t ssrc); | 70 virtual bool RemoveSendStream(uint32_t ssrc); |
86 virtual bool AddRecvStream(const StreamParams& sp); | 71 virtual bool AddRecvStream(const StreamParams& sp); |
87 virtual bool RemoveRecvStream(uint32_t ssrc); | 72 virtual bool RemoveRecvStream(uint32_t ssrc); |
88 virtual bool SetSend(bool send) { | 73 virtual bool SetSend(bool send) { |
89 sending_ = send; | 74 sending_ = send; |
90 return true; | 75 return true; |
91 } | 76 } |
92 virtual bool SetReceive(bool receive) { | 77 virtual bool SetReceive(bool receive) { |
93 receiving_ = receive; | 78 receiving_ = receive; |
94 return true; | 79 return true; |
95 } | 80 } |
96 virtual void OnPacketReceived(rtc::CopyOnWriteBuffer* packet, | 81 virtual void OnPacketReceived(rtc::CopyOnWriteBuffer* packet, |
97 const rtc::PacketTime& packet_time); | 82 const rtc::PacketTime& packet_time); |
98 virtual void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet, | 83 virtual void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet, |
99 const rtc::PacketTime& packet_time) {} | 84 const rtc::PacketTime& packet_time) {} |
100 virtual void OnReadyToSend(bool ready) {} | 85 virtual void OnReadyToSend(bool ready) {} |
101 virtual bool SendData( | 86 virtual bool SendData( |
102 const SendDataParams& params, | 87 const SendDataParams& params, |
103 const rtc::CopyOnWriteBuffer& payload, | 88 const rtc::CopyOnWriteBuffer& payload, |
104 SendDataResult* result); | 89 SendDataResult* result); |
105 | 90 |
106 private: | 91 private: |
107 void Construct(rtc::Timing* timing); | 92 void Construct(); |
108 bool SetMaxSendBandwidth(int bps); | 93 bool SetMaxSendBandwidth(int bps); |
109 bool SetSendCodecs(const std::vector<DataCodec>& codecs); | 94 bool SetSendCodecs(const std::vector<DataCodec>& codecs); |
110 bool SetRecvCodecs(const std::vector<DataCodec>& codecs); | 95 bool SetRecvCodecs(const std::vector<DataCodec>& codecs); |
111 | 96 |
112 bool sending_; | 97 bool sending_; |
113 bool receiving_; | 98 bool receiving_; |
114 rtc::Timing* timing_; | |
115 std::vector<DataCodec> send_codecs_; | 99 std::vector<DataCodec> send_codecs_; |
116 std::vector<DataCodec> recv_codecs_; | 100 std::vector<DataCodec> recv_codecs_; |
117 std::vector<StreamParams> send_streams_; | 101 std::vector<StreamParams> send_streams_; |
118 std::vector<StreamParams> recv_streams_; | 102 std::vector<StreamParams> recv_streams_; |
119 std::map<uint32_t, RtpClock*> rtp_clock_by_send_ssrc_; | 103 std::map<uint32_t, RtpClock*> rtp_clock_by_send_ssrc_; |
120 std::unique_ptr<rtc::RateLimiter> send_limiter_; | 104 std::unique_ptr<rtc::RateLimiter> send_limiter_; |
121 }; | 105 }; |
122 | 106 |
123 } // namespace cricket | 107 } // namespace cricket |
124 | 108 |
125 #endif // WEBRTC_MEDIA_BASE_RTPDATAENGINE_H_ | 109 #endif // WEBRTC_MEDIA_BASE_RTPDATAENGINE_H_ |
OLD | NEW |