blob: 9ce50a7c8c21637994ee88a1873c017483e37762 [file] [log] [blame]
Niels Möller2e47f7c2018-10-16 10:41:42 +02001/*
2 * Copyright 2018 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef API_TEST_LOOPBACK_MEDIA_TRANSPORT_H_
12#define API_TEST_LOOPBACK_MEDIA_TRANSPORT_H_
13
14#include <utility>
15
16#include "api/media_transport_interface.h"
17
18namespace webrtc {
19
20// Contains two MediaTransportsInterfaces that are connected to each other.
21// Currently supports audio only.
22class MediaTransportPair {
23 public:
24 MediaTransportPair()
25 : pipe_{LoopbackMediaTransport(&pipe_[1]),
26 LoopbackMediaTransport(&pipe_[0])} {}
27
28 // Ownership stays with MediaTransportPair
29 MediaTransportInterface* first() { return &pipe_[0]; }
30 MediaTransportInterface* second() { return &pipe_[1]; }
31
32 private:
33 class LoopbackMediaTransport : public MediaTransportInterface {
34 public:
35 explicit LoopbackMediaTransport(LoopbackMediaTransport* other)
36 : other_(other) {}
37 ~LoopbackMediaTransport() { RTC_CHECK(sink_ == nullptr); }
38
39 RTCError SendAudioFrame(uint64_t channel_id,
40 MediaTransportEncodedAudioFrame frame) override {
41 other_->OnData(channel_id, std::move(frame));
42 return RTCError::OK();
43 };
44
45 RTCError SendVideoFrame(
46 uint64_t channel_id,
47 const MediaTransportEncodedVideoFrame& frame) override {
48 return RTCError::OK();
49 }
50
51 RTCError RequestKeyFrame(uint64_t channel_id) override {
52 return RTCError::OK();
53 }
54
55 void SetReceiveAudioSink(MediaTransportAudioSinkInterface* sink) override {
56 if (sink) {
57 RTC_CHECK(sink_ == nullptr);
58 }
59 sink_ = sink;
60 }
61
62 void SetReceiveVideoSink(MediaTransportVideoSinkInterface* sink) override {}
63
Piotr (Peter) Slatala6b9d8232018-10-26 07:59:46 -070064 void SetTargetTransferRateObserver(
65 webrtc::TargetTransferRateObserver* observer) override {}
66
Bjorn Mellemeb2c6412018-10-31 15:25:32 -070067 void SetMediaTransportStateCallback(
68 MediaTransportStateCallback* callback) override {}
69
70 RTCError SendData(int channel_id,
71 const SendDataParams& params,
72 const rtc::CopyOnWriteBuffer& buffer) override {
73 return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented");
74 }
75
76 RTCError CloseChannel(int channel_id) override {
77 return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented");
78 }
79
80 void SetDataSink(DataChannelSink* sink) override {}
81
Niels Möller2e47f7c2018-10-16 10:41:42 +020082 private:
83 void OnData(uint64_t channel_id, MediaTransportEncodedAudioFrame frame) {
84 if (sink_) {
85 sink_->OnData(channel_id, frame);
86 }
87 }
88
89 MediaTransportAudioSinkInterface* sink_ = nullptr;
90 LoopbackMediaTransport* other_;
91 };
92
93 LoopbackMediaTransport pipe_[2];
94};
95
96} // namespace webrtc
97
98#endif // API_TEST_LOOPBACK_MEDIA_TRANSPORT_H_