blob: 64e083b0fd9404976729d07c28cffa4d0cb5adbc [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
23namespace cricket {
24
25struct DataCodec;
26
27class RtpDataEngine : public DataEngineInterface {
28 public:
29 RtpDataEngine();
30
deadbeef953c2ce2017-01-09 14:53:41 -080031 virtual DataMediaChannel* CreateChannel(const MediaConfig& config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000032
33 virtual const std::vector<DataCodec>& data_codecs() {
34 return data_codecs_;
35 }
36
henrike@webrtc.org28e20752013-07-10 00:45:36 +000037 private:
38 std::vector<DataCodec> data_codecs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000039};
40
41// Keep track of sequence number and timestamp of an RTP stream. The
42// sequence number starts with a "random" value and increments. The
43// timestamp starts with a "random" value and increases monotonically
44// according to the clockrate.
45class RtpClock {
46 public:
Peter Boström0c4e06b2015-10-07 12:23:21 +020047 RtpClock(int clockrate, uint16_t first_seq_num, uint32_t timestamp_offset)
henrike@webrtc.org28e20752013-07-10 00:45:36 +000048 : clockrate_(clockrate),
49 last_seq_num_(first_seq_num),
Peter Boström0c4e06b2015-10-07 12:23:21 +020050 timestamp_offset_(timestamp_offset) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +000051
52 // Given the current time (in number of seconds which must be
53 // monotonically increasing), Return the next sequence number and
54 // timestamp.
Peter Boström0c4e06b2015-10-07 12:23:21 +020055 void Tick(double now, int* seq_num, uint32_t* timestamp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056
57 private:
58 int clockrate_;
Peter Boström0c4e06b2015-10-07 12:23:21 +020059 uint16_t last_seq_num_;
60 uint32_t timestamp_offset_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061};
62
63class RtpDataMediaChannel : public DataMediaChannel {
64 public:
Steve Antone78bcb92017-10-31 09:53:08 -070065 explicit RtpDataMediaChannel(const MediaConfig& config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066 virtual ~RtpDataMediaChannel();
67
Fredrik Solenbergb071a192015-09-17 16:42:56 +020068 virtual bool SetSendParameters(const DataSendParameters& params);
69 virtual bool SetRecvParameters(const DataRecvParameters& params);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070 virtual bool AddSendStream(const StreamParams& sp);
Peter Boström0c4e06b2015-10-07 12:23:21 +020071 virtual bool RemoveSendStream(uint32_t ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072 virtual bool AddRecvStream(const StreamParams& sp);
Peter Boström0c4e06b2015-10-07 12:23:21 +020073 virtual bool RemoveRecvStream(uint32_t ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074 virtual bool SetSend(bool send) {
75 sending_ = send;
76 return true;
77 }
78 virtual bool SetReceive(bool receive) {
79 receiving_ = receive;
80 return true;
81 }
jbaucheec21bd2016-03-20 06:15:43 -070082 virtual void OnPacketReceived(rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000083 const rtc::PacketTime& packet_time);
jbaucheec21bd2016-03-20 06:15:43 -070084 virtual void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000085 const rtc::PacketTime& packet_time) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +000086 virtual void OnReadyToSend(bool ready) {}
87 virtual bool SendData(
88 const SendDataParams& params,
jbaucheec21bd2016-03-20 06:15:43 -070089 const rtc::CopyOnWriteBuffer& payload,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090 SendDataResult* result);
zhihuangebbe4f22016-12-06 10:45:42 -080091 virtual rtc::DiffServCodePoint PreferredDscp() const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092
93 private:
nissecdf37a92016-09-13 23:41:47 -070094 void Construct();
Fredrik Solenbergb071a192015-09-17 16:42:56 +020095 bool SetMaxSendBandwidth(int bps);
96 bool SetSendCodecs(const std::vector<DataCodec>& codecs);
97 bool SetRecvCodecs(const std::vector<DataCodec>& codecs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000098
99 bool sending_;
100 bool receiving_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000101 std::vector<DataCodec> send_codecs_;
102 std::vector<DataCodec> recv_codecs_;
103 std::vector<StreamParams> send_streams_;
104 std::vector<StreamParams> recv_streams_;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200105 std::map<uint32_t, RtpClock*> rtp_clock_by_send_ssrc_;
kwiberg686a8ef2016-02-26 03:00:35 -0800106 std::unique_ptr<rtc::RateLimiter> send_limiter_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107};
108
109} // namespace cricket
110
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200111#endif // MEDIA_BASE_RTPDATAENGINE_H_