webrtc_m130/media/base/rtp_data_engine.h
Harald Alvestrand 5fc28b11a0 Reland "Reland "Version 2 "Refactoring DataContentDescription class"""
This reverts commit 46afbf9481fbcc939c998c898ca1031ce41cc6b1.

Reason for revert: Tightened protocol name handling.

Original change's description:
> Revert "Reland "Version 2 "Refactoring DataContentDescription class"""
>
> This reverts commit 37f2b43274a0d718de53a4cfcf02226356edcf6e.
>
> Reason for revert: fuzzer failures
>
> Original change's description:
> > Reland "Version 2 "Refactoring DataContentDescription class""
> >
> > This is a reland of 14b2758726879d21671a21291dfed8fb4fd5c21c
> >
> > Original change's description:
> > > Version 2 "Refactoring DataContentDescription class"
> > >
> > > (substantial changes since version 1)
> > >
> > > This CL splits the cricket::DataContentDescription class into
> > > two classes: cricket::RtpDataContentDescription (used for RTP data)
> > > and cricket::SctpDataContentDescription (used for SCTP only).
> > >
> > > SctpDataContentDescription no longer inherits from
> > > MediaContentDescriptionImpl, and no longer contains "codecs".
> > >
> > > Due to usage of internal interfaces by consumers, shimming the old
> > > DataContentDescription API is needed.
> > >
> > > A new cricket::DataContentDescription class is defined, which is
> > > a shim over RtpDataContentDescription and SctpDataContentDescription.
> > > It exposes as little functionality as possible, but supports the
> > > concerned consumer's usage
> > >
> > > Design document:
> > > https://docs.google.com/document/d/1H5LfQxJA2ikMWTQ8FZ3_GAmaXM7knfVQWiSz6ph8VQ0/edit#
> > >
> > > Version 1 reviewed-on: https://webrtc-review.googlesource.com/c/src/+/132700
> > >

Bug: webrtc:10358
Change-Id: Ia9fb8f4679e082e3d18fbbb6b03fc13a08e06110
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/136581
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Steve Anton <steveanton@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27933}
2019-05-13 18:37:47 +00:00

111 lines
3.4 KiB
C++

/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef MEDIA_BASE_RTP_DATA_ENGINE_H_
#define MEDIA_BASE_RTP_DATA_ENGINE_H_
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "media/base/codec.h"
#include "media/base/media_channel.h"
#include "media/base/media_constants.h"
#include "media/base/media_engine.h"
namespace rtc {
class DataRateLimiter;
}
namespace cricket {
class RtpDataEngine : public DataEngineInterface {
public:
RtpDataEngine();
virtual DataMediaChannel* CreateChannel(const MediaConfig& config);
virtual const std::vector<DataCodec>& data_codecs() { return data_codecs_; }
private:
std::vector<DataCodec> data_codecs_;
};
// Keep track of sequence number and timestamp of an RTP stream. The
// sequence number starts with a "random" value and increments. The
// timestamp starts with a "random" value and increases monotonically
// according to the clockrate.
class RtpClock {
public:
RtpClock(int clockrate, uint16_t first_seq_num, uint32_t timestamp_offset)
: clockrate_(clockrate),
last_seq_num_(first_seq_num),
timestamp_offset_(timestamp_offset) {}
// Given the current time (in number of seconds which must be
// monotonically increasing), Return the next sequence number and
// timestamp.
void Tick(double now, int* seq_num, uint32_t* timestamp);
private:
int clockrate_;
uint16_t last_seq_num_;
uint32_t timestamp_offset_;
};
class RtpDataMediaChannel : public DataMediaChannel {
public:
explicit RtpDataMediaChannel(const MediaConfig& config);
virtual ~RtpDataMediaChannel();
virtual bool SetSendParameters(const DataSendParameters& params);
virtual bool SetRecvParameters(const DataRecvParameters& params);
virtual bool AddSendStream(const StreamParams& sp);
virtual bool RemoveSendStream(uint32_t ssrc);
virtual bool AddRecvStream(const StreamParams& sp);
virtual bool RemoveRecvStream(uint32_t ssrc);
virtual bool SetSend(bool send) {
sending_ = send;
return true;
}
virtual bool SetReceive(bool receive) {
receiving_ = receive;
return true;
}
virtual void OnPacketReceived(rtc::CopyOnWriteBuffer packet,
int64_t packet_time_us);
virtual void OnRtcpReceived(rtc::CopyOnWriteBuffer packet,
int64_t packet_time_us) {}
virtual void OnReadyToSend(bool ready) {}
virtual bool SendData(const SendDataParams& params,
const rtc::CopyOnWriteBuffer& payload,
SendDataResult* result);
private:
void Construct();
bool SetMaxSendBandwidth(int bps);
bool SetSendCodecs(const std::vector<DataCodec>& codecs);
bool SetRecvCodecs(const std::vector<DataCodec>& codecs);
bool sending_;
bool receiving_;
std::vector<DataCodec> send_codecs_;
std::vector<DataCodec> recv_codecs_;
std::vector<StreamParams> send_streams_;
std::vector<StreamParams> recv_streams_;
std::map<uint32_t, RtpClock*> rtp_clock_by_send_ssrc_;
std::unique_ptr<rtc::DataRateLimiter> send_limiter_;
};
} // namespace cricket
#endif // MEDIA_BASE_RTP_DATA_ENGINE_H_