Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +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 | #ifndef TEST_SCENARIO_AUDIO_STREAM_H_ |
| 11 | #define TEST_SCENARIO_AUDIO_STREAM_H_ |
| 12 | #include <memory> |
| 13 | #include <string> |
| 14 | #include <vector> |
| 15 | |
| 16 | #include "rtc_base/constructormagic.h" |
| 17 | #include "test/scenario/call_client.h" |
| 18 | #include "test/scenario/column_printer.h" |
| 19 | #include "test/scenario/network_node.h" |
| 20 | #include "test/scenario/scenario_config.h" |
| 21 | |
| 22 | namespace webrtc { |
| 23 | namespace test { |
| 24 | |
| 25 | // SendAudioStream represents sending of audio. It can be used for starting the |
| 26 | // stream if neccessary. |
| 27 | class SendAudioStream : public NetworkReceiverInterface { |
| 28 | public: |
| 29 | RTC_DISALLOW_COPY_AND_ASSIGN(SendAudioStream); |
| 30 | ~SendAudioStream(); |
| 31 | void Start(); |
| 32 | |
| 33 | private: |
| 34 | friend class Scenario; |
| 35 | friend class AudioStreamPair; |
| 36 | friend class ReceiveAudioStream; |
| 37 | SendAudioStream(CallClient* sender, |
| 38 | AudioStreamConfig config, |
| 39 | rtc::scoped_refptr<AudioEncoderFactory> encoder_factory, |
| 40 | Transport* send_transport); |
| 41 | // Handles RTCP feedback for this stream. |
| 42 | bool TryDeliverPacket(rtc::CopyOnWriteBuffer packet, |
| 43 | uint64_t receiver, |
| 44 | Timestamp at_time) override; |
| 45 | |
| 46 | AudioSendStream* send_stream_ = nullptr; |
| 47 | CallClient* const sender_; |
| 48 | const AudioStreamConfig config_; |
| 49 | uint32_t ssrc_; |
| 50 | }; |
| 51 | |
| 52 | // ReceiveAudioStream represents an audio receiver. It can't be used directly. |
| 53 | class ReceiveAudioStream : public NetworkReceiverInterface { |
| 54 | public: |
| 55 | RTC_DISALLOW_COPY_AND_ASSIGN(ReceiveAudioStream); |
| 56 | ~ReceiveAudioStream(); |
| 57 | |
| 58 | private: |
| 59 | friend class Scenario; |
| 60 | friend class AudioStreamPair; |
| 61 | ReceiveAudioStream(CallClient* receiver, |
| 62 | AudioStreamConfig config, |
| 63 | SendAudioStream* send_stream, |
| 64 | rtc::scoped_refptr<AudioDecoderFactory> decoder_factory, |
| 65 | Transport* feedback_transport); |
| 66 | bool TryDeliverPacket(rtc::CopyOnWriteBuffer packet, |
| 67 | uint64_t receiver, |
| 68 | Timestamp at_time) override; |
| 69 | AudioReceiveStream* receive_stream_ = nullptr; |
| 70 | CallClient* const receiver_; |
| 71 | const AudioStreamConfig config_; |
| 72 | }; |
| 73 | |
| 74 | // AudioStreamPair represents an audio streaming session. It can be used to |
| 75 | // access underlying send and receive classes. It can also be used in calls to |
| 76 | // the Scenario class. |
| 77 | class AudioStreamPair { |
| 78 | public: |
| 79 | RTC_DISALLOW_COPY_AND_ASSIGN(AudioStreamPair); |
| 80 | ~AudioStreamPair(); |
| 81 | SendAudioStream* send() { return &send_stream_; } |
| 82 | ReceiveAudioStream* receive() { return &receive_stream_; } |
| 83 | |
| 84 | private: |
| 85 | friend class Scenario; |
| 86 | AudioStreamPair(CallClient* sender, |
| 87 | std::vector<NetworkNode*> send_link, |
| 88 | uint64_t send_receiver_id, |
| 89 | rtc::scoped_refptr<AudioEncoderFactory> encoder_factory, |
| 90 | |
| 91 | CallClient* receiver, |
| 92 | std::vector<NetworkNode*> return_link, |
| 93 | uint64_t return_receiver_id, |
| 94 | rtc::scoped_refptr<AudioDecoderFactory> decoder_factory, |
| 95 | AudioStreamConfig config); |
| 96 | |
| 97 | private: |
| 98 | const AudioStreamConfig config_; |
| 99 | std::vector<NetworkNode*> send_link_; |
| 100 | std::vector<NetworkNode*> return_link_; |
| 101 | NetworkNodeTransport send_transport_; |
| 102 | NetworkNodeTransport return_transport_; |
| 103 | |
| 104 | SendAudioStream send_stream_; |
| 105 | ReceiveAudioStream receive_stream_; |
| 106 | }; |
| 107 | } // namespace test |
| 108 | } // namespace webrtc |
| 109 | |
| 110 | #endif // TEST_SCENARIO_AUDIO_STREAM_H_ |