blob: f24b224695dfa66e9e3fe2863d09bdfc8b887d6a [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellander1afca732016-02-07 20:46:45 -08002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellander1afca732016-02-07 20:46:45 -08004 * 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.org28e20752013-07-10 00:45:36 +00009 */
10
Steve Anton10542f22019-01-11 09:11:00 -080011#ifndef MEDIA_BASE_RTP_DATA_ENGINE_H_
12#define MEDIA_BASE_RTP_DATA_ENGINE_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000013
Steve Antone78bcb92017-10-31 09:53:08 -070014#include <map>
kwiberg686a8ef2016-02-26 03:00:35 -080015#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000016#include <string>
17#include <vector>
18
Steve Anton10542f22019-01-11 09:11:00 -080019#include "media/base/media_channel.h"
20#include "media/base/media_constants.h"
21#include "media/base/media_engine.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000022
Sebastian Janssonf9c5cf62018-02-28 16:04:26 +010023namespace rtc {
24class DataRateLimiter;
25}
26
henrike@webrtc.org28e20752013-07-10 00:45:36 +000027namespace cricket {
28
29struct DataCodec;
30
31class RtpDataEngine : public DataEngineInterface {
32 public:
33 RtpDataEngine();
34
deadbeef953c2ce2017-01-09 14:53:41 -080035 virtual DataMediaChannel* CreateChannel(const MediaConfig& config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000036
Yves Gerey665174f2018-06-19 15:03:05 +020037 virtual const std::vector<DataCodec>& data_codecs() { return data_codecs_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000038
henrike@webrtc.org28e20752013-07-10 00:45:36 +000039 private:
40 std::vector<DataCodec> data_codecs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000041};
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.
47class RtpClock {
48 public:
Peter Boström0c4e06b2015-10-07 12:23:21 +020049 RtpClock(int clockrate, uint16_t first_seq_num, uint32_t timestamp_offset)
henrike@webrtc.org28e20752013-07-10 00:45:36 +000050 : clockrate_(clockrate),
51 last_seq_num_(first_seq_num),
Peter Boström0c4e06b2015-10-07 12:23:21 +020052 timestamp_offset_(timestamp_offset) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +000053
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öm0c4e06b2015-10-07 12:23:21 +020057 void Tick(double now, int* seq_num, uint32_t* timestamp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058
59 private:
60 int clockrate_;
Peter Boström0c4e06b2015-10-07 12:23:21 +020061 uint16_t last_seq_num_;
62 uint32_t timestamp_offset_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063};
64
65class RtpDataMediaChannel : public DataMediaChannel {
66 public:
Steve Antone78bcb92017-10-31 09:53:08 -070067 explicit RtpDataMediaChannel(const MediaConfig& config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068 virtual ~RtpDataMediaChannel();
69
Fredrik Solenbergb071a192015-09-17 16:42:56 +020070 virtual bool SetSendParameters(const DataSendParameters& params);
71 virtual bool SetRecvParameters(const DataRecvParameters& params);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072 virtual bool AddSendStream(const StreamParams& sp);
Peter Boström0c4e06b2015-10-07 12:23:21 +020073 virtual bool RemoveSendStream(uint32_t ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074 virtual bool AddRecvStream(const StreamParams& sp);
Peter Boström0c4e06b2015-10-07 12:23:21 +020075 virtual bool RemoveRecvStream(uint32_t ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076 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 }
jbaucheec21bd2016-03-20 06:15:43 -070084 virtual void OnPacketReceived(rtc::CopyOnWriteBuffer* packet,
Niels Möllere6933812018-11-05 13:01:41 +010085 int64_t packet_time_us);
jbaucheec21bd2016-03-20 06:15:43 -070086 virtual void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet,
Niels Möllere6933812018-11-05 13:01:41 +010087 int64_t packet_time_us) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088 virtual void OnReadyToSend(bool ready) {}
Yves Gerey665174f2018-06-19 15:03:05 +020089 virtual bool SendData(const SendDataParams& params,
90 const rtc::CopyOnWriteBuffer& payload,
91 SendDataResult* result);
zhihuangebbe4f22016-12-06 10:45:42 -080092 virtual rtc::DiffServCodePoint PreferredDscp() const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000093
94 private:
nissecdf37a92016-09-13 23:41:47 -070095 void Construct();
Fredrik Solenbergb071a192015-09-17 16:42:56 +020096 bool SetMaxSendBandwidth(int bps);
97 bool SetSendCodecs(const std::vector<DataCodec>& codecs);
98 bool SetRecvCodecs(const std::vector<DataCodec>& codecs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099
100 bool sending_;
101 bool receiving_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102 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öm0c4e06b2015-10-07 12:23:21 +0200106 std::map<uint32_t, RtpClock*> rtp_clock_by_send_ssrc_;
Sebastian Janssonf9c5cf62018-02-28 16:04:26 +0100107 std::unique_ptr<rtc::DataRateLimiter> send_limiter_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000108};
109
110} // namespace cricket
111
Steve Anton10542f22019-01-11 09:11:00 -0800112#endif // MEDIA_BASE_RTP_DATA_ENGINE_H_