xref: /aosp_15_r20/external/webrtc/test/scenario/audio_stream.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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 "test/scenario/call_client.h"
17 #include "test/scenario/column_printer.h"
18 #include "test/scenario/network_node.h"
19 #include "test/scenario/scenario_config.h"
20 
21 namespace webrtc {
22 namespace test {
23 
24 // SendAudioStream represents sending of audio. It can be used for starting the
25 // stream if neccessary.
26 class SendAudioStream {
27  public:
28   ~SendAudioStream();
29 
30   SendAudioStream(const SendAudioStream&) = delete;
31   SendAudioStream& operator=(const SendAudioStream&) = delete;
32 
33   void Start();
34   void Stop();
35   void SetMuted(bool mute);
36   ColumnPrinter StatsPrinter();
37 
38  private:
39   friend class Scenario;
40   friend class AudioStreamPair;
41   friend class ReceiveAudioStream;
42   SendAudioStream(CallClient* sender,
43                   AudioStreamConfig config,
44                   rtc::scoped_refptr<AudioEncoderFactory> encoder_factory,
45                   Transport* send_transport);
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 {
54  public:
55   ~ReceiveAudioStream();
56 
57   ReceiveAudioStream(const ReceiveAudioStream&) = delete;
58   ReceiveAudioStream& operator=(const ReceiveAudioStream&) = delete;
59 
60   void Start();
61   void Stop();
62   AudioReceiveStreamInterface::Stats GetStats() const;
63 
64  private:
65   friend class Scenario;
66   friend class AudioStreamPair;
67   ReceiveAudioStream(CallClient* receiver,
68                      AudioStreamConfig config,
69                      SendAudioStream* send_stream,
70                      rtc::scoped_refptr<AudioDecoderFactory> decoder_factory,
71                      Transport* feedback_transport);
72   AudioReceiveStreamInterface* receive_stream_ = nullptr;
73   CallClient* const receiver_;
74   const AudioStreamConfig config_;
75 };
76 
77 // AudioStreamPair represents an audio streaming session. It can be used to
78 // access underlying send and receive classes. It can also be used in calls to
79 // the Scenario class.
80 class AudioStreamPair {
81  public:
82   ~AudioStreamPair();
83 
84   AudioStreamPair(const AudioStreamPair&) = delete;
85   AudioStreamPair& operator=(const AudioStreamPair&) = delete;
86 
send()87   SendAudioStream* send() { return &send_stream_; }
receive()88   ReceiveAudioStream* receive() { return &receive_stream_; }
89 
90  private:
91   friend class Scenario;
92   AudioStreamPair(CallClient* sender,
93                   rtc::scoped_refptr<AudioEncoderFactory> encoder_factory,
94                   CallClient* receiver,
95                   rtc::scoped_refptr<AudioDecoderFactory> decoder_factory,
96                   AudioStreamConfig config);
97 
98  private:
99   const AudioStreamConfig config_;
100   SendAudioStream send_stream_;
101   ReceiveAudioStream receive_stream_;
102 };
103 }  // namespace test
104 }  // namespace webrtc
105 
106 #endif  // TEST_SCENARIO_AUDIO_STREAM_H_
107