• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2013 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 CALL_CALL_H_
11 #define CALL_CALL_H_
12 
13 #include <algorithm>
14 #include <memory>
15 #include <string>
16 #include <vector>
17 
18 #include "api/adaptation/resource.h"
19 #include "api/media_types.h"
20 #include "call/audio_receive_stream.h"
21 #include "call/audio_send_stream.h"
22 #include "call/call_config.h"
23 #include "call/flexfec_receive_stream.h"
24 #include "call/packet_receiver.h"
25 #include "call/rtp_transport_controller_send_interface.h"
26 #include "call/video_receive_stream.h"
27 #include "call/video_send_stream.h"
28 #include "modules/utility/include/process_thread.h"
29 #include "rtc_base/copy_on_write_buffer.h"
30 #include "rtc_base/network/sent_packet.h"
31 #include "rtc_base/network_route.h"
32 #include "rtc_base/ref_count.h"
33 
34 namespace webrtc {
35 
36 // A restricted way to share the module process thread across multiple instances
37 // of Call that are constructed on the same worker thread (which is what the
38 // peer connection factory guarantees).
39 // SharedModuleThread supports a callback that is issued when only one reference
40 // remains, which is used to indicate to the original owner that the thread may
41 // be discarded.
42 class SharedModuleThread : public rtc::RefCountInterface {
43  protected:
44   SharedModuleThread(std::unique_ptr<ProcessThread> process_thread,
45                      std::function<void()> on_one_ref_remaining);
46   friend class rtc::scoped_refptr<SharedModuleThread>;
47   ~SharedModuleThread() override;
48 
49  public:
50   // Allows injection of an externally created process thread.
51   static rtc::scoped_refptr<SharedModuleThread> Create(
52       std::unique_ptr<ProcessThread> process_thread,
53       std::function<void()> on_one_ref_remaining);
54 
55   void EnsureStarted();
56 
57   ProcessThread* process_thread();
58 
59  private:
60   void AddRef() const override;
61   rtc::RefCountReleaseStatus Release() const override;
62 
63   class Impl;
64   mutable std::unique_ptr<Impl> impl_;
65 };
66 
67 // A Call instance can contain several send and/or receive streams. All streams
68 // are assumed to have the same remote endpoint and will share bitrate estimates
69 // etc.
70 class Call {
71  public:
72   using Config = CallConfig;
73 
74   struct Stats {
75     std::string ToString(int64_t time_ms) const;
76 
77     int send_bandwidth_bps = 0;       // Estimated available send bandwidth.
78     int max_padding_bitrate_bps = 0;  // Cumulative configured max padding.
79     int recv_bandwidth_bps = 0;       // Estimated available receive bandwidth.
80     int64_t pacer_delay_ms = 0;
81     int64_t rtt_ms = -1;
82   };
83 
84   static Call* Create(const Call::Config& config);
85   static Call* Create(const Call::Config& config,
86                       rtc::scoped_refptr<SharedModuleThread> call_thread);
87   static Call* Create(const Call::Config& config,
88                       Clock* clock,
89                       rtc::scoped_refptr<SharedModuleThread> call_thread,
90                       std::unique_ptr<ProcessThread> pacer_thread);
91 
92   virtual AudioSendStream* CreateAudioSendStream(
93       const AudioSendStream::Config& config) = 0;
94 
95   virtual void DestroyAudioSendStream(AudioSendStream* send_stream) = 0;
96 
97   virtual AudioReceiveStream* CreateAudioReceiveStream(
98       const AudioReceiveStream::Config& config) = 0;
99   virtual void DestroyAudioReceiveStream(
100       AudioReceiveStream* receive_stream) = 0;
101 
102   virtual VideoSendStream* CreateVideoSendStream(
103       VideoSendStream::Config config,
104       VideoEncoderConfig encoder_config) = 0;
105   virtual VideoSendStream* CreateVideoSendStream(
106       VideoSendStream::Config config,
107       VideoEncoderConfig encoder_config,
108       std::unique_ptr<FecController> fec_controller);
109   virtual void DestroyVideoSendStream(VideoSendStream* send_stream) = 0;
110 
111   virtual VideoReceiveStream* CreateVideoReceiveStream(
112       VideoReceiveStream::Config configuration) = 0;
113   virtual void DestroyVideoReceiveStream(
114       VideoReceiveStream* receive_stream) = 0;
115 
116   // In order for a created VideoReceiveStream to be aware that it is
117   // protected by a FlexfecReceiveStream, the latter should be created before
118   // the former.
119   virtual FlexfecReceiveStream* CreateFlexfecReceiveStream(
120       const FlexfecReceiveStream::Config& config) = 0;
121   virtual void DestroyFlexfecReceiveStream(
122       FlexfecReceiveStream* receive_stream) = 0;
123 
124   // When a resource is overused, the Call will try to reduce the load on the
125   // sysem, for example by reducing the resolution or frame rate of encoded
126   // streams.
127   virtual void AddAdaptationResource(rtc::scoped_refptr<Resource> resource) = 0;
128 
129   // All received RTP and RTCP packets for the call should be inserted to this
130   // PacketReceiver. The PacketReceiver pointer is valid as long as the
131   // Call instance exists.
132   virtual PacketReceiver* Receiver() = 0;
133 
134   // This is used to access the transport controller send instance owned by
135   // Call. The send transport controller is currently owned by Call for legacy
136   // reasons. (for instance  variants of call tests are built on this assumtion)
137   // TODO(srte): Move ownership of transport controller send out of Call and
138   // remove this method interface.
139   virtual RtpTransportControllerSendInterface* GetTransportControllerSend() = 0;
140 
141   // Returns the call statistics, such as estimated send and receive bandwidth,
142   // pacing delay, etc.
143   virtual Stats GetStats() const = 0;
144 
145   // TODO(skvlad): When the unbundled case with multiple streams for the same
146   // media type going over different networks is supported, track the state
147   // for each stream separately. Right now it's global per media type.
148   virtual void SignalChannelNetworkState(MediaType media,
149                                          NetworkState state) = 0;
150 
151   virtual void OnAudioTransportOverheadChanged(
152       int transport_overhead_per_packet) = 0;
153 
154   virtual void OnSentPacket(const rtc::SentPacket& sent_packet) = 0;
155 
156   virtual void SetClientBitratePreferences(
157       const BitrateSettings& preferences) = 0;
158 
~Call()159   virtual ~Call() {}
160 };
161 
162 }  // namespace webrtc
163 
164 #endif  // CALL_CALL_H_
165