webrtc_m130/api/test/loopback_media_transport.h
Niels Möller 2e47f7c4ee Implement test class LoopbackMediaTransport
Bug: webrtc:9719
Change-Id: I82aa962d1cb8f2c8f56f766cb12562690e595045
Reviewed-on: https://webrtc-review.googlesource.com/c/105661
Commit-Queue: Niels Moller <nisse@webrtc.org>
Reviewed-by: Peter Slatala <psla@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Anton Sukhanov <sukhanov@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25196}
2018-10-16 09:21:28 +00:00

81 lines
2.3 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 {}
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_