blob: e5f071d5a9549be754a8a517361201959ce59011 [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
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020019#include "media/base/codec.h"
Steve Anton10542f22019-01-11 09:11:00 -080020#include "media/base/media_channel.h"
21#include "media/base/media_constants.h"
22#include "media/base/media_engine.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000023
Sebastian Janssonf9c5cf62018-02-28 16:04:26 +010024namespace rtc {
25class DataRateLimiter;
26}
27
henrike@webrtc.org28e20752013-07-10 00:45:36 +000028namespace cricket {
29
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030class RtpDataEngine : public DataEngineInterface {
31 public:
32 RtpDataEngine();
33
deadbeef953c2ce2017-01-09 14:53:41 -080034 virtual DataMediaChannel* CreateChannel(const MediaConfig& config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000035
Yves Gerey665174f2018-06-19 15:03:05 +020036 virtual const std::vector<DataCodec>& data_codecs() { return data_codecs_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000037
henrike@webrtc.org28e20752013-07-10 00:45:36 +000038 private:
39 std::vector<DataCodec> data_codecs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000040};
41
42// Keep track of sequence number and timestamp of an RTP stream. The
43// sequence number starts with a "random" value and increments. The
44// timestamp starts with a "random" value and increases monotonically
45// according to the clockrate.
46class RtpClock {
47 public:
Peter Boström0c4e06b2015-10-07 12:23:21 +020048 RtpClock(int clockrate, uint16_t first_seq_num, uint32_t timestamp_offset)
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049 : clockrate_(clockrate),
50 last_seq_num_(first_seq_num),
Peter Boström0c4e06b2015-10-07 12:23:21 +020051 timestamp_offset_(timestamp_offset) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +000052
53 // Given the current time (in number of seconds which must be
54 // monotonically increasing), Return the next sequence number and
55 // timestamp.
Peter Boström0c4e06b2015-10-07 12:23:21 +020056 void Tick(double now, int* seq_num, uint32_t* timestamp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057
58 private:
59 int clockrate_;
Peter Boström0c4e06b2015-10-07 12:23:21 +020060 uint16_t last_seq_num_;
61 uint32_t timestamp_offset_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062};
63
64class RtpDataMediaChannel : public DataMediaChannel {
65 public:
Steve Antone78bcb92017-10-31 09:53:08 -070066 explicit RtpDataMediaChannel(const MediaConfig& config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000067 virtual ~RtpDataMediaChannel();
68
Fredrik Solenbergb071a192015-09-17 16:42:56 +020069 virtual bool SetSendParameters(const DataSendParameters& params);
70 virtual bool SetRecvParameters(const DataRecvParameters& params);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071 virtual bool AddSendStream(const StreamParams& sp);
Peter Boström0c4e06b2015-10-07 12:23:21 +020072 virtual bool RemoveSendStream(uint32_t ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073 virtual bool AddRecvStream(const StreamParams& sp);
Peter Boström0c4e06b2015-10-07 12:23:21 +020074 virtual bool RemoveRecvStream(uint32_t ssrc);
Saurav Dasff27da52019-09-20 11:05:30 -070075 virtual void ResetUnsignaledRecvStream();
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 }
Amit Hilbuche7a5f7b2019-03-12 11:10:27 -070084 virtual void OnPacketReceived(rtc::CopyOnWriteBuffer packet,
Niels Möllere6933812018-11-05 13:01:41 +010085 int64_t packet_time_us);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000086 virtual void OnReadyToSend(bool ready) {}
Yves Gerey665174f2018-06-19 15:03:05 +020087 virtual bool SendData(const SendDataParams& params,
88 const rtc::CopyOnWriteBuffer& payload,
89 SendDataResult* result);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090
91 private:
nissecdf37a92016-09-13 23:41:47 -070092 void Construct();
Fredrik Solenbergb071a192015-09-17 16:42:56 +020093 bool SetMaxSendBandwidth(int bps);
94 bool SetSendCodecs(const std::vector<DataCodec>& codecs);
95 bool SetRecvCodecs(const std::vector<DataCodec>& codecs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000096
97 bool sending_;
98 bool receiving_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099 std::vector<DataCodec> send_codecs_;
100 std::vector<DataCodec> recv_codecs_;
101 std::vector<StreamParams> send_streams_;
102 std::vector<StreamParams> recv_streams_;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200103 std::map<uint32_t, RtpClock*> rtp_clock_by_send_ssrc_;
Sebastian Janssonf9c5cf62018-02-28 16:04:26 +0100104 std::unique_ptr<rtc::DataRateLimiter> send_limiter_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000105};
106
107} // namespace cricket
108
Steve Anton10542f22019-01-11 09:11:00 -0800109#endif // MEDIA_BASE_RTP_DATA_ENGINE_H_