Niels Möller | 2e47f7c | 2018-10-16 10:41:42 +0200 | [diff] [blame] | 1 | /* |
| 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 | |
| 18 | namespace webrtc { |
| 19 | |
| 20 | // Contains two MediaTransportsInterfaces that are connected to each other. |
| 21 | // Currently supports audio only. |
| 22 | class 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 | |
| 64 | private: |
| 65 | void OnData(uint64_t channel_id, MediaTransportEncodedAudioFrame frame) { |
| 66 | if (sink_) { |
| 67 | sink_->OnData(channel_id, frame); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | MediaTransportAudioSinkInterface* sink_ = nullptr; |
| 72 | LoopbackMediaTransport* other_; |
| 73 | }; |
| 74 | |
| 75 | LoopbackMediaTransport pipe_[2]; |
| 76 | }; |
| 77 | |
| 78 | } // namespace webrtc |
| 79 | |
| 80 | #endif // API_TEST_LOOPBACK_MEDIA_TRANSPORT_H_ |