Files
platform-external-webrtc/api/test/loopback_media_transport.h
Bjorn Mellem eb2c6415a9 Delete the default implementations of MediaTransportInterface methods.
This change deletes the default implementations of state and data
channel methods (SetMediaTransportStateCallback, SendData, CloseChannel,
and SetDataSink).  It adds stub implementations to LoopbackMediaTransport
and FakeMediaTransport.

Bug: webrtc:9719
Change-Id: I49b7780c055b552330546b460c2e79ce8df81833
Reviewed-on: https://webrtc-review.googlesource.com/c/108940
Commit-Queue: Bjorn Mellem <mellem@webrtc.org>
Reviewed-by: Anton Sukhanov <sukhanov@webrtc.org>
Reviewed-by: Seth Hampson <shampson@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25457}
2018-11-01 00:15:52 +00:00

99 lines
2.9 KiB
C++

/*
* Copyright 2018 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 API_TEST_LOOPBACK_MEDIA_TRANSPORT_H_
#define API_TEST_LOOPBACK_MEDIA_TRANSPORT_H_
#include <utility>
#include "api/media_transport_interface.h"
namespace webrtc {
// Contains two MediaTransportsInterfaces that are connected to each other.
// Currently supports audio only.
class MediaTransportPair {
public:
MediaTransportPair()
: pipe_{LoopbackMediaTransport(&pipe_[1]),
LoopbackMediaTransport(&pipe_[0])} {}
// Ownership stays with MediaTransportPair
MediaTransportInterface* first() { return &pipe_[0]; }
MediaTransportInterface* second() { return &pipe_[1]; }
private:
class LoopbackMediaTransport : public MediaTransportInterface {
public:
explicit LoopbackMediaTransport(LoopbackMediaTransport* other)
: other_(other) {}
~LoopbackMediaTransport() { RTC_CHECK(sink_ == nullptr); }
RTCError SendAudioFrame(uint64_t channel_id,
MediaTransportEncodedAudioFrame frame) override {
other_->OnData(channel_id, std::move(frame));
return RTCError::OK();
};
RTCError SendVideoFrame(
uint64_t channel_id,
const MediaTransportEncodedVideoFrame& frame) override {
return RTCError::OK();
}
RTCError RequestKeyFrame(uint64_t channel_id) override {
return RTCError::OK();
}
void SetReceiveAudioSink(MediaTransportAudioSinkInterface* sink) override {
if (sink) {
RTC_CHECK(sink_ == nullptr);
}
sink_ = sink;
}
void SetReceiveVideoSink(MediaTransportVideoSinkInterface* sink) override {}
void SetTargetTransferRateObserver(
webrtc::TargetTransferRateObserver* observer) override {}
void SetMediaTransportStateCallback(
MediaTransportStateCallback* callback) override {}
RTCError SendData(int channel_id,
const SendDataParams& params,
const rtc::CopyOnWriteBuffer& buffer) override {
return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented");
}
RTCError CloseChannel(int channel_id) override {
return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented");
}
void SetDataSink(DataChannelSink* sink) override {}
private:
void OnData(uint64_t channel_id, MediaTransportEncodedAudioFrame frame) {
if (sink_) {
sink_->OnData(channel_id, frame);
}
}
MediaTransportAudioSinkInterface* sink_ = nullptr;
LoopbackMediaTransport* other_;
};
LoopbackMediaTransport pipe_[2];
};
} // namespace webrtc
#endif // API_TEST_LOOPBACK_MEDIA_TRANSPORT_H_