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 11 #ifndef VIDEO_VIDEO_SEND_STREAM_H_ 12 #define VIDEO_VIDEO_SEND_STREAM_H_ 13 14 #include <map> 15 #include <memory> 16 #include <string> 17 #include <vector> 18 19 #include "api/fec_controller.h" 20 #include "api/field_trials_view.h" 21 #include "api/sequence_checker.h" 22 #include "api/task_queue/pending_task_safety_flag.h" 23 #include "call/bitrate_allocator.h" 24 #include "call/video_receive_stream.h" 25 #include "call/video_send_stream.h" 26 #include "modules/utility/maybe_worker_thread.h" 27 #include "rtc_base/event.h" 28 #include "rtc_base/system/no_unique_address.h" 29 #include "video/encoder_rtcp_feedback.h" 30 #include "video/send_delay_stats.h" 31 #include "video/send_statistics_proxy.h" 32 #include "video/video_send_stream_impl.h" 33 #include "video/video_stream_encoder_interface.h" 34 35 namespace webrtc { 36 namespace test { 37 class VideoSendStreamPeer; 38 } // namespace test 39 40 class CallStats; 41 class IvfFileWriter; 42 class RateLimiter; 43 class RtpRtcp; 44 class RtpTransportControllerSendInterface; 45 class RtcEventLog; 46 47 namespace internal { 48 49 class VideoSendStreamImpl; 50 51 // VideoSendStream implements webrtc::VideoSendStream. 52 // Internally, it delegates all public methods to VideoSendStreamImpl and / or 53 // VideoStreamEncoder. 54 class VideoSendStream : public webrtc::VideoSendStream { 55 public: 56 using RtpStateMap = std::map<uint32_t, RtpState>; 57 using RtpPayloadStateMap = std::map<uint32_t, RtpPayloadState>; 58 59 VideoSendStream( 60 Clock* clock, 61 int num_cpu_cores, 62 TaskQueueFactory* task_queue_factory, 63 TaskQueueBase* network_queue, 64 RtcpRttStats* call_stats, 65 RtpTransportControllerSendInterface* transport, 66 BitrateAllocatorInterface* bitrate_allocator, 67 SendDelayStats* send_delay_stats, 68 RtcEventLog* event_log, 69 VideoSendStream::Config config, 70 VideoEncoderConfig encoder_config, 71 const std::map<uint32_t, RtpState>& suspended_ssrcs, 72 const std::map<uint32_t, RtpPayloadState>& suspended_payload_states, 73 std::unique_ptr<FecController> fec_controller, 74 const FieldTrialsView& field_trials); 75 76 ~VideoSendStream() override; 77 78 void DeliverRtcp(const uint8_t* packet, size_t length); 79 80 // webrtc::VideoSendStream implementation. 81 void Start() override; 82 void StartPerRtpStream(std::vector<bool> active_layers) override; 83 void Stop() override; 84 bool started() override; 85 86 void AddAdaptationResource(rtc::scoped_refptr<Resource> resource) override; 87 std::vector<rtc::scoped_refptr<Resource>> GetAdaptationResources() override; 88 89 void SetSource(rtc::VideoSourceInterface<webrtc::VideoFrame>* source, 90 const DegradationPreference& degradation_preference) override; 91 92 void ReconfigureVideoEncoder(VideoEncoderConfig config) override; 93 void ReconfigureVideoEncoder(VideoEncoderConfig config, 94 SetParametersCallback callback) override; 95 Stats GetStats() override; 96 97 void StopPermanentlyAndGetRtpStates(RtpStateMap* rtp_state_map, 98 RtpPayloadStateMap* payload_state_map); 99 void GenerateKeyFrame(const std::vector<std::string>& rids) override; 100 101 private: 102 friend class test::VideoSendStreamPeer; 103 104 absl::optional<float> GetPacingFactorOverride() const; 105 106 RTC_NO_UNIQUE_ADDRESS SequenceChecker thread_checker_; 107 MaybeWorkerThread* const rtp_transport_queue_; 108 RtpTransportControllerSendInterface* const transport_; 109 rtc::Event thread_sync_event_; 110 rtc::scoped_refptr<PendingTaskSafetyFlag> transport_queue_safety_ = 111 PendingTaskSafetyFlag::CreateDetached(); 112 113 SendStatisticsProxy stats_proxy_; 114 const VideoSendStream::Config config_; 115 const VideoEncoderConfig::ContentType content_type_; 116 std::unique_ptr<VideoStreamEncoderInterface> video_stream_encoder_; 117 EncoderRtcpFeedback encoder_feedback_; 118 RtpVideoSenderInterface* const rtp_video_sender_; 119 VideoSendStreamImpl send_stream_; 120 bool running_ RTC_GUARDED_BY(thread_checker_) = false; 121 }; 122 123 } // namespace internal 124 } // namespace webrtc 125 126 #endif // VIDEO_VIDEO_SEND_STREAM_H_ 127