webrtc_m130/p2p/base/udptransport.h
Zhi Huang 942bc2e4b9 Reland: Replaced the SignalSelectedCandidatePairChanged with a new signal.
|packet_overhead| field is added to rtc::NetworkRoute structure.

In PackTransportInternal:
1. network_route() is added which returns the current network route.
2. debug_name() is removed.
3. transport_name() is moved from DtlsTransportInternal and
IceTransportInternal to PacketTransportInternal.

When the selected candidate pair is changed, the P2PTransportChannel
will fire the SignalNetworkRouteChanged instead of
SignalSelectedCandidatePairChanged to upper layers.

The Rtp/SrtpTransport takes the responsibility of calculating the
transport overhead from the BaseChannel so that the BaseChannel
doesn't need to depend on P2P layer transports.

TBR=pthatcher@webrtc.org

Bug: webrtc:7013
Change-Id: If9928b25a7259544c2d9c42048b53ab24292fc67
Reviewed-on: https://webrtc-review.googlesource.com/22767
Reviewed-by: Zhi Huang <zhihuang@webrtc.org>
Commit-Queue: Zhi Huang <zhihuang@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20664}
2017-11-13 22:50:11 +00:00

90 lines
2.8 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 P2P_BASE_UDPTRANSPORT_H_
#define P2P_BASE_UDPTRANSPORT_H_
#include <memory>
#include <string>
#include "api/optional.h"
#include "api/ortc/udptransportinterface.h"
#include "p2p/base/packettransportinternal.h"
#include "rtc_base/asyncpacketsocket.h" // For PacketOptions.
#include "rtc_base/thread_checker.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() override;
// 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.
const std::string& transport_name() const override;
bool receiving() const override;
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;
int GetError() override;
rtc::Optional<rtc::NetworkRoute> network_route() const override;
protected:
PacketTransportInternal* GetInternal() override;
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 // P2P_BASE_UDPTRANSPORT_H_