henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 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. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 11 | #ifndef MEDIA_BASE_RTP_DATA_ENGINE_H_ |
| 12 | #define MEDIA_BASE_RTP_DATA_ENGINE_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 13 | |
Steve Anton | e78bcb9 | 2017-10-31 09:53:08 -0700 | [diff] [blame] | 14 | #include <map> |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 15 | #include <memory> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 16 | #include <string> |
| 17 | #include <vector> |
| 18 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 19 | #include "media/base/media_channel.h" |
| 20 | #include "media/base/media_constants.h" |
| 21 | #include "media/base/media_engine.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 22 | |
Sebastian Jansson | f9c5cf6 | 2018-02-28 16:04:26 +0100 | [diff] [blame] | 23 | namespace rtc { |
| 24 | class DataRateLimiter; |
| 25 | } |
| 26 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 27 | namespace cricket { |
| 28 | |
| 29 | struct DataCodec; |
| 30 | |
| 31 | class RtpDataEngine : public DataEngineInterface { |
| 32 | public: |
| 33 | RtpDataEngine(); |
| 34 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 35 | virtual DataMediaChannel* CreateChannel(const MediaConfig& config); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 36 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 37 | virtual const std::vector<DataCodec>& data_codecs() { return data_codecs_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 38 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 39 | private: |
| 40 | std::vector<DataCodec> data_codecs_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | // Keep track of sequence number and timestamp of an RTP stream. The |
| 44 | // sequence number starts with a "random" value and increments. The |
| 45 | // timestamp starts with a "random" value and increases monotonically |
| 46 | // according to the clockrate. |
| 47 | class RtpClock { |
| 48 | public: |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 49 | RtpClock(int clockrate, uint16_t first_seq_num, uint32_t timestamp_offset) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 50 | : clockrate_(clockrate), |
| 51 | last_seq_num_(first_seq_num), |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 52 | timestamp_offset_(timestamp_offset) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 53 | |
| 54 | // Given the current time (in number of seconds which must be |
| 55 | // monotonically increasing), Return the next sequence number and |
| 56 | // timestamp. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 57 | void Tick(double now, int* seq_num, uint32_t* timestamp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 58 | |
| 59 | private: |
| 60 | int clockrate_; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 61 | uint16_t last_seq_num_; |
| 62 | uint32_t timestamp_offset_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | class RtpDataMediaChannel : public DataMediaChannel { |
| 66 | public: |
Steve Anton | e78bcb9 | 2017-10-31 09:53:08 -0700 | [diff] [blame] | 67 | explicit RtpDataMediaChannel(const MediaConfig& config); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 68 | virtual ~RtpDataMediaChannel(); |
| 69 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 70 | virtual bool SetSendParameters(const DataSendParameters& params); |
| 71 | virtual bool SetRecvParameters(const DataRecvParameters& params); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 72 | virtual bool AddSendStream(const StreamParams& sp); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 73 | virtual bool RemoveSendStream(uint32_t ssrc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 74 | virtual bool AddRecvStream(const StreamParams& sp); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 75 | virtual bool RemoveRecvStream(uint32_t ssrc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 76 | virtual bool SetSend(bool send) { |
| 77 | sending_ = send; |
| 78 | return true; |
| 79 | } |
| 80 | virtual bool SetReceive(bool receive) { |
| 81 | receiving_ = receive; |
| 82 | return true; |
| 83 | } |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 84 | virtual void OnPacketReceived(rtc::CopyOnWriteBuffer* packet, |
Niels Möller | e693381 | 2018-11-05 13:01:41 +0100 | [diff] [blame] | 85 | int64_t packet_time_us); |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 86 | virtual void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet, |
Niels Möller | e693381 | 2018-11-05 13:01:41 +0100 | [diff] [blame] | 87 | int64_t packet_time_us) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 88 | virtual void OnReadyToSend(bool ready) {} |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 89 | virtual bool SendData(const SendDataParams& params, |
| 90 | const rtc::CopyOnWriteBuffer& payload, |
| 91 | SendDataResult* result); |
zhihuang | ebbe4f2 | 2016-12-06 10:45:42 -0800 | [diff] [blame] | 92 | virtual rtc::DiffServCodePoint PreferredDscp() const; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 93 | |
| 94 | private: |
nisse | cdf37a9 | 2016-09-13 23:41:47 -0700 | [diff] [blame] | 95 | void Construct(); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 96 | bool SetMaxSendBandwidth(int bps); |
| 97 | bool SetSendCodecs(const std::vector<DataCodec>& codecs); |
| 98 | bool SetRecvCodecs(const std::vector<DataCodec>& codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 99 | |
| 100 | bool sending_; |
| 101 | bool receiving_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 102 | std::vector<DataCodec> send_codecs_; |
| 103 | std::vector<DataCodec> recv_codecs_; |
| 104 | std::vector<StreamParams> send_streams_; |
| 105 | std::vector<StreamParams> recv_streams_; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 106 | std::map<uint32_t, RtpClock*> rtp_clock_by_send_ssrc_; |
Sebastian Jansson | f9c5cf6 | 2018-02-28 16:04:26 +0100 | [diff] [blame] | 107 | std::unique_ptr<rtc::DataRateLimiter> send_limiter_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | } // namespace cricket |
| 111 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 112 | #endif // MEDIA_BASE_RTP_DATA_ENGINE_H_ |