webrtc_m130/webrtc/p2p/base/udptransport.h
deadbeef e814a0dee0 Adding "adapter" ORTC objects on top of ChannelManager/BaseChannel/etc.
This CL adds the following interfaces:
* RtpTransportController
* RtpTransport
* RtpSender
* RtpReceiver

They're implemented on top of the "BaseChannel" object, which is normally used
in a PeerConnection, and roughly corresponds to an SDP "m=" section. As a result
of this, there are several limitations:

* You can only have one of each type of sender and receiver (audio/video) on top
  of the same transport controller.
* The sender/receiver with the same media type must use the same RTP transport.
* You can't change the transport after creating the sender or receiver.
* Some of the parameters aren't supported.

Later, these "adapter" objects will be gradually replaced by real objects that don't
have these limitations, as "BaseChannel", "MediaChannel" and related code is
restructured. In this CL, we essentially have:

ORTC adapter objects -> BaseChannel -> Media engine
PeerConnection -> BaseChannel -> Media engine

And later we hope to have simply:

PeerConnection -> "Real" ORTC objects -> Media engine

See the linked bug for more context.

BUG=webrtc:7013
TBR=stefan@webrtc.org

Review-Url: https://codereview.webrtc.org/2675173003
Cr-Commit-Position: refs/heads/master@{#16842}
2017-02-26 02:15:09 +00:00

90 lines
2.9 KiB
C++

/*
* Copyright 2016 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 WEBRTC_P2P_BASE_UDPTRANSPORT_H_
#define WEBRTC_P2P_BASE_UDPTRANSPORT_H_
#include <memory>
#include <string>
#include "webrtc/api/ortc/udptransportinterface.h"
#include "webrtc/base/asyncpacketsocket.h" // For PacketOptions.
#include "webrtc/base/optional.h"
#include "webrtc/base/thread_checker.h"
#include "webrtc/p2p/base/packettransportinternal.h"
namespace rtc {
class AsyncPacketSocket;
struct PacketTime;
struct SentPacket;
class SocketAddress;
}
namespace cricket {
// Implementation of UdpTransportInterface.
// Used by OrtcFactory.
class UdpTransport : public rtc::PacketTransportInternal,
public webrtc::UdpTransportInterface {
public:
// |transport_name| is only used for identification/logging.
// |socket| must be non-null.
UdpTransport(const std::string& transport_name,
std::unique_ptr<rtc::AsyncPacketSocket> socket);
~UdpTransport();
// Overrides of UdpTransportInterface, used by the API consumer.
rtc::SocketAddress GetLocalAddress() const override;
bool SetRemoteAddress(const rtc::SocketAddress& addr) override;
rtc::SocketAddress GetRemoteAddress() const override;
// Overrides of PacketTransportInternal, used by webrtc internally.
std::string debug_name() const override { return transport_name_; }
bool receiving() const override {
// TODO(johan): Implement method and signal.
return true;
}
bool writable() const override;
int SendPacket(const char* data,
size_t len,
const rtc::PacketOptions& options,
int flags) override;
int SetOption(rtc::Socket::Option opt, int value) override { return 0; }
int GetError() override { return send_error_; }
protected:
PacketTransportInternal* GetInternal() override { return this; }
private:
void OnSocketReadPacket(rtc::AsyncPacketSocket* socket,
const char* data,
size_t len,
const rtc::SocketAddress& remote_addr,
const rtc::PacketTime& packet_time);
void OnSocketSentPacket(rtc::AsyncPacketSocket* socket,
const rtc::SentPacket& packet);
bool IsLocalConsistent();
std::string transport_name_;
int send_error_ = 0;
std::unique_ptr<rtc::AsyncPacketSocket> socket_;
// If not set, will be an "nil" address ("IsNil" returns true).
rtc::SocketAddress remote_address_;
rtc::ThreadChecker network_thread_checker_;
};
} // namespace cricket
#endif // WEBRTC_P2P_BASE_UDPTRANSPORT_H_