call.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. // Allows injection of an externally created process thread.
  46. static rtc::scoped_refptr<SharedModuleThread> Create(
  47. std::unique_ptr<ProcessThread> process_thread,
  48. std::function<void()> on_one_ref_remaining);
  49. void EnsureStarted();
  50. ProcessThread* process_thread();
  51. private:
  52. void AddRef() const override;
  53. rtc::RefCountReleaseStatus Release() const override;
  54. class Impl;
  55. mutable std::unique_ptr<Impl> impl_;
  56. };
  57. // A Call instance can contain several send and/or receive streams. All streams
  58. // are assumed to have the same remote endpoint and will share bitrate estimates
  59. // etc.
  60. class Call {
  61. public:
  62. using Config = CallConfig;
  63. struct Stats {
  64. std::string ToString(int64_t time_ms) const;
  65. int send_bandwidth_bps = 0; // Estimated available send bandwidth.
  66. int max_padding_bitrate_bps = 0; // Cumulative configured max padding.
  67. int recv_bandwidth_bps = 0; // Estimated available receive bandwidth.
  68. int64_t pacer_delay_ms = 0;
  69. int64_t rtt_ms = -1;
  70. };
  71. static Call* Create(const Call::Config& config);
  72. static Call* Create(const Call::Config& config,
  73. rtc::scoped_refptr<SharedModuleThread> call_thread);
  74. static Call* Create(const Call::Config& config,
  75. Clock* clock,
  76. rtc::scoped_refptr<SharedModuleThread> call_thread,
  77. std::unique_ptr<ProcessThread> pacer_thread);
  78. virtual AudioSendStream* CreateAudioSendStream(
  79. const AudioSendStream::Config& config) = 0;
  80. virtual void DestroyAudioSendStream(AudioSendStream* send_stream) = 0;
  81. virtual AudioReceiveStream* CreateAudioReceiveStream(
  82. const AudioReceiveStream::Config& config) = 0;
  83. virtual void DestroyAudioReceiveStream(
  84. AudioReceiveStream* receive_stream) = 0;
  85. virtual VideoSendStream* CreateVideoSendStream(
  86. VideoSendStream::Config config,
  87. VideoEncoderConfig encoder_config) = 0;
  88. virtual VideoSendStream* CreateVideoSendStream(
  89. VideoSendStream::Config config,
  90. VideoEncoderConfig encoder_config,
  91. std::unique_ptr<FecController> fec_controller);
  92. virtual void DestroyVideoSendStream(VideoSendStream* send_stream) = 0;
  93. virtual VideoReceiveStream* CreateVideoReceiveStream(
  94. VideoReceiveStream::Config configuration) = 0;
  95. virtual void DestroyVideoReceiveStream(
  96. VideoReceiveStream* receive_stream) = 0;
  97. // In order for a created VideoReceiveStream to be aware that it is
  98. // protected by a FlexfecReceiveStream, the latter should be created before
  99. // the former.
  100. virtual FlexfecReceiveStream* CreateFlexfecReceiveStream(
  101. const FlexfecReceiveStream::Config& config) = 0;
  102. virtual void DestroyFlexfecReceiveStream(
  103. FlexfecReceiveStream* receive_stream) = 0;
  104. // When a resource is overused, the Call will try to reduce the load on the
  105. // sysem, for example by reducing the resolution or frame rate of encoded
  106. // streams.
  107. virtual void AddAdaptationResource(rtc::scoped_refptr<Resource> resource) = 0;
  108. // All received RTP and RTCP packets for the call should be inserted to this
  109. // PacketReceiver. The PacketReceiver pointer is valid as long as the
  110. // Call instance exists.
  111. virtual PacketReceiver* Receiver() = 0;
  112. // This is used to access the transport controller send instance owned by
  113. // Call. The send transport controller is currently owned by Call for legacy
  114. // reasons. (for instance variants of call tests are built on this assumtion)
  115. // TODO(srte): Move ownership of transport controller send out of Call and
  116. // remove this method interface.
  117. virtual RtpTransportControllerSendInterface* GetTransportControllerSend() = 0;
  118. // Returns the call statistics, such as estimated send and receive bandwidth,
  119. // pacing delay, etc.
  120. virtual Stats GetStats() const = 0;
  121. // TODO(skvlad): When the unbundled case with multiple streams for the same
  122. // media type going over different networks is supported, track the state
  123. // for each stream separately. Right now it's global per media type.
  124. virtual void SignalChannelNetworkState(MediaType media,
  125. NetworkState state) = 0;
  126. virtual void OnAudioTransportOverheadChanged(
  127. int transport_overhead_per_packet) = 0;
  128. virtual void OnSentPacket(const rtc::SentPacket& sent_packet) = 0;
  129. virtual void SetClientBitratePreferences(
  130. const BitrateSettings& preferences) = 0;
  131. virtual const WebRtcKeyValueConfig& trials() const = 0;
  132. virtual ~Call() {}
  133. };
  134. } // namespace webrtc
  135. #endif // CALL_CALL_H_