call.h 6.3 KB

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