blob: 3195f979bad790af063c91dc4fdb3e2127c8b4d8 [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
Niels Möller2e47f7c2018-10-16 10:41:42 +020067 private:
68 void OnData(uint64_t channel_id, MediaTransportEncodedAudioFrame frame) {
69 if (sink_) {
70 sink_->OnData(channel_id, frame);
71 }
72 }
73
74 MediaTransportAudioSinkInterface* sink_ = nullptr;
75 LoopbackMediaTransport* other_;
76 };
77
78 LoopbackMediaTransport pipe_[2];
79};
80
81} // namespace webrtc
82
83#endif // API_TEST_LOOPBACK_MEDIA_TRANSPORT_H_