blob: 52d43253dc2d35b49c00c3d76c43525255b2c527 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MEDIA_BASE_RTPDATAENGINE_H_
12#define MEDIA_BASE_RTPDATAENGINE_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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "media/base/mediachannel.h"
20#include "media/base/mediaconstants.h"
21#include "media/base/mediaengine.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
37 virtual const std::vector<DataCodec>& data_codecs() {
38 return data_codecs_;
39 }
40
henrike@webrtc.org28e20752013-07-10 00:45:36 +000041 private:
42 std::vector<DataCodec> data_codecs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000043};
44
45// Keep track of sequence number and timestamp of an RTP stream. The
46// sequence number starts with a "random" value and increments. The
47// timestamp starts with a "random" value and increases monotonically
48// according to the clockrate.
49class RtpClock {
50 public:
Peter Boström0c4e06b2015-10-07 12:23:21 +020051 RtpClock(int clockrate, uint16_t first_seq_num, uint32_t timestamp_offset)
henrike@webrtc.org28e20752013-07-10 00:45:36 +000052 : clockrate_(clockrate),
53 last_seq_num_(first_seq_num),
Peter Boström0c4e06b2015-10-07 12:23:21 +020054 timestamp_offset_(timestamp_offset) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +000055
56 // Given the current time (in number of seconds which must be
57 // monotonically increasing), Return the next sequence number and
58 // timestamp.
Peter Boström0c4e06b2015-10-07 12:23:21 +020059 void Tick(double now, int* seq_num, uint32_t* timestamp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060
61 private:
62 int clockrate_;
Peter Boström0c4e06b2015-10-07 12:23:21 +020063 uint16_t last_seq_num_;
64 uint32_t timestamp_offset_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000065};
66
67class RtpDataMediaChannel : public DataMediaChannel {
68 public:
Steve Antone78bcb92017-10-31 09:53:08 -070069 explicit RtpDataMediaChannel(const MediaConfig& config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070 virtual ~RtpDataMediaChannel();
71
Fredrik Solenbergb071a192015-09-17 16:42:56 +020072 virtual bool SetSendParameters(const DataSendParameters& params);
73 virtual bool SetRecvParameters(const DataRecvParameters& params);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074 virtual bool AddSendStream(const StreamParams& sp);
Peter Boström0c4e06b2015-10-07 12:23:21 +020075 virtual bool RemoveSendStream(uint32_t ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076 virtual bool AddRecvStream(const StreamParams& sp);
Peter Boström0c4e06b2015-10-07 12:23:21 +020077 virtual bool RemoveRecvStream(uint32_t ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078 virtual bool SetSend(bool send) {
79 sending_ = send;
80 return true;
81 }
82 virtual bool SetReceive(bool receive) {
83 receiving_ = receive;
84 return true;
85 }
jbaucheec21bd2016-03-20 06:15:43 -070086 virtual void OnPacketReceived(rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000087 const rtc::PacketTime& packet_time);
jbaucheec21bd2016-03-20 06:15:43 -070088 virtual void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000089 const rtc::PacketTime& packet_time) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090 virtual void OnReadyToSend(bool ready) {}
91 virtual bool SendData(
92 const SendDataParams& params,
jbaucheec21bd2016-03-20 06:15:43 -070093 const rtc::CopyOnWriteBuffer& payload,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094 SendDataResult* result);
zhihuangebbe4f22016-12-06 10:45:42 -080095 virtual rtc::DiffServCodePoint PreferredDscp() const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000096
97 private:
nissecdf37a92016-09-13 23:41:47 -070098 void Construct();
Fredrik Solenbergb071a192015-09-17 16:42:56 +020099 bool SetMaxSendBandwidth(int bps);
100 bool SetSendCodecs(const std::vector<DataCodec>& codecs);
101 bool SetRecvCodecs(const std::vector<DataCodec>& codecs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102
103 bool sending_;
104 bool receiving_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000105 std::vector<DataCodec> send_codecs_;
106 std::vector<DataCodec> recv_codecs_;
107 std::vector<StreamParams> send_streams_;
108 std::vector<StreamParams> recv_streams_;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200109 std::map<uint32_t, RtpClock*> rtp_clock_by_send_ssrc_;
Sebastian Janssonf9c5cf62018-02-28 16:04:26 +0100110 std::unique_ptr<rtc::DataRateLimiter> send_limiter_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000111};
112
113} // namespace cricket
114
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200115#endif // MEDIA_BASE_RTPDATAENGINE_H_