OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_VIDEO_VIDEO_SEND_STREAM_H_ | 11 #ifndef WEBRTC_VIDEO_VIDEO_SEND_STREAM_H_ |
12 #define WEBRTC_VIDEO_VIDEO_SEND_STREAM_H_ | 12 #define WEBRTC_VIDEO_VIDEO_SEND_STREAM_H_ |
13 | 13 |
14 #include <map> | 14 #include <map> |
15 #include <memory> | 15 #include <memory> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 #include "webrtc/call/bitrate_allocator.h" | 18 #include "webrtc/call/bitrate_allocator.h" |
19 #include "webrtc/base/criticalsection.h" | 19 #include "webrtc/base/criticalsection.h" |
20 #include "webrtc/base/event.h" | |
21 #include "webrtc/base/task_queue.h" | |
22 #include "webrtc/call.h" | 20 #include "webrtc/call.h" |
23 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 21 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
24 #include "webrtc/modules/video_coding/protection_bitrate_calculator.h" | 22 #include "webrtc/modules/video_coding/protection_bitrate_calculator.h" |
25 #include "webrtc/video/encoder_state_feedback.h" | 23 #include "webrtc/video/encoder_state_feedback.h" |
26 #include "webrtc/video/payload_router.h" | 24 #include "webrtc/video/payload_router.h" |
27 #include "webrtc/video/send_delay_stats.h" | 25 #include "webrtc/video/send_delay_stats.h" |
28 #include "webrtc/video/send_statistics_proxy.h" | 26 #include "webrtc/video/send_statistics_proxy.h" |
| 27 #include "webrtc/video/video_capture_input.h" |
29 #include "webrtc/video/vie_encoder.h" | 28 #include "webrtc/video/vie_encoder.h" |
30 #include "webrtc/video_receive_stream.h" | 29 #include "webrtc/video_receive_stream.h" |
31 #include "webrtc/video_send_stream.h" | 30 #include "webrtc/video_send_stream.h" |
32 | 31 |
33 namespace webrtc { | 32 namespace webrtc { |
34 | 33 |
35 class BitrateAllocator; | 34 class BitrateAllocator; |
36 class CallStats; | 35 class CallStats; |
37 class CongestionController; | 36 class CongestionController; |
38 class IvfFileWriter; | 37 class IvfFileWriter; |
39 class ProcessThread; | 38 class ProcessThread; |
40 class RtpRtcp; | 39 class RtpRtcp; |
| 40 class ViEEncoder; |
41 class VieRemb; | 41 class VieRemb; |
42 class RtcEventLog; | 42 class RtcEventLog; |
43 | 43 |
| 44 namespace vcm { |
| 45 class VideoSender; |
| 46 } // namespace vcm |
| 47 |
44 namespace internal { | 48 namespace internal { |
45 | 49 |
46 class VideoSendStreamImpl; | 50 class VideoSendStream : public webrtc::VideoSendStream, |
47 | 51 public webrtc::CpuOveruseObserver, |
48 // VideoSendStream implements webrtc::VideoSendStream. | 52 public webrtc::BitrateAllocatorObserver, |
49 // Internally, it delegates all public methods to VideoSendStreamImpl and / or | 53 public webrtc::VCMProtectionCallback, |
50 // VieEncoder. VideoSendStreamInternal is created and deleted on |worker_queue|. | 54 public EncodedImageCallback { |
51 class VideoSendStream : public webrtc::VideoSendStream { | |
52 public: | 55 public: |
53 VideoSendStream(int num_cpu_cores, | 56 VideoSendStream(int num_cpu_cores, |
54 ProcessThread* module_process_thread, | 57 ProcessThread* module_process_thread, |
55 rtc::TaskQueue* worker_queue, | |
56 CallStats* call_stats, | 58 CallStats* call_stats, |
57 CongestionController* congestion_controller, | 59 CongestionController* congestion_controller, |
58 BitrateAllocator* bitrate_allocator, | 60 BitrateAllocator* bitrate_allocator, |
59 SendDelayStats* send_delay_stats, | 61 SendDelayStats* send_delay_stats, |
60 VieRemb* remb, | 62 VieRemb* remb, |
61 RtcEventLog* event_log, | 63 RtcEventLog* event_log, |
62 VideoSendStream::Config config, | 64 const VideoSendStream::Config& config, |
63 VideoEncoderConfig encoder_config, | 65 const VideoEncoderConfig& encoder_config, |
64 const std::map<uint32_t, RtpState>& suspended_ssrcs); | 66 const std::map<uint32_t, RtpState>& suspended_ssrcs); |
65 | 67 |
66 ~VideoSendStream() override; | 68 ~VideoSendStream() override; |
67 | 69 |
68 void SignalNetworkState(NetworkState state); | 70 void SignalNetworkState(NetworkState state); |
69 bool DeliverRtcp(const uint8_t* packet, size_t length); | 71 bool DeliverRtcp(const uint8_t* packet, size_t length); |
70 | 72 |
71 // webrtc::VideoSendStream implementation. | 73 // webrtc::VideoSendStream implementation. |
72 void Start() override; | 74 void Start() override; |
73 void Stop() override; | 75 void Stop() override; |
74 VideoCaptureInput* Input() override; | 76 VideoCaptureInput* Input() override; |
75 void ReconfigureVideoEncoder(VideoEncoderConfig) override; | 77 void ReconfigureVideoEncoder(const VideoEncoderConfig& config) override; |
76 Stats GetStats() override; | 78 Stats GetStats() override; |
77 | 79 |
| 80 // webrtc::CpuOveruseObserver implementation. |
| 81 void OveruseDetected() override; |
| 82 void NormalUsage() override; |
| 83 |
78 typedef std::map<uint32_t, RtpState> RtpStateMap; | 84 typedef std::map<uint32_t, RtpState> RtpStateMap; |
79 RtpStateMap StopPermanentlyAndGetRtpStates(); | 85 RtpStateMap GetRtpStates() const; |
| 86 |
| 87 int GetPaddingNeededBps() const; |
| 88 |
| 89 // Implements BitrateAllocatorObserver. |
| 90 uint32_t OnBitrateUpdated(uint32_t bitrate_bps, |
| 91 uint8_t fraction_loss, |
| 92 int64_t rtt) override; |
| 93 |
| 94 protected: |
| 95 // Implements webrtc::VCMProtectionCallback. |
| 96 int ProtectionRequest(const FecProtectionParams* delta_params, |
| 97 const FecProtectionParams* key_params, |
| 98 uint32_t* sent_video_rate_bps, |
| 99 uint32_t* sent_nack_rate_bps, |
| 100 uint32_t* sent_fec_rate_bps) override; |
80 | 101 |
81 private: | 102 private: |
82 class ConstructionTask; | 103 struct EncoderSettings { |
83 class DestructAndGetRtpStateTask; | 104 VideoCodec video_codec; |
| 105 VideoEncoderConfig config; |
| 106 }; |
84 | 107 |
85 rtc::ThreadChecker thread_checker_; | 108 // Implements EncodedImageCallback. The implementation routes encoded frames |
86 rtc::TaskQueue* const worker_queue_; | 109 // to the |payload_router_| and |config.pre_encode_callback| if set. |
87 rtc::Event thread_sync_event_; | 110 // Called on an arbitrary encoder callback thread. |
| 111 EncodedImageCallback::Result OnEncodedImage( |
| 112 const EncodedImage& encoded_image, |
| 113 const CodecSpecificInfo* codec_specific_info, |
| 114 const RTPFragmentationHeader* fragmentation) override; |
| 115 |
| 116 static bool EncoderThreadFunction(void* obj); |
| 117 void EncoderProcess(); |
| 118 |
| 119 void ConfigureProtection(); |
| 120 void ConfigureSsrcs(); |
88 | 121 |
89 SendStatisticsProxy stats_proxy_; | 122 SendStatisticsProxy stats_proxy_; |
90 const VideoSendStream::Config config_; | 123 const VideoSendStream::Config config_; |
91 std::unique_ptr<VideoSendStreamImpl> send_stream_; | 124 std::map<uint32_t, RtpState> suspended_ssrcs_; |
92 std::unique_ptr<ViEEncoder> vie_encoder_; | 125 |
| 126 ProcessThread* const module_process_thread_; |
| 127 CallStats* const call_stats_; |
| 128 CongestionController* const congestion_controller_; |
| 129 BitrateAllocator* const bitrate_allocator_; |
| 130 VieRemb* const remb_; |
| 131 |
| 132 static const bool kEnableFrameRecording = false; |
| 133 static const int kMaxLayers = 3; |
| 134 std::unique_ptr<IvfFileWriter> file_writers_[kMaxLayers]; |
| 135 |
| 136 rtc::PlatformThread encoder_thread_; |
| 137 rtc::Event encoder_wakeup_event_; |
| 138 volatile int stop_encoder_thread_; |
| 139 rtc::CriticalSection encoder_settings_crit_; |
| 140 std::unique_ptr<EncoderSettings> pending_encoder_settings_ |
| 141 GUARDED_BY(encoder_settings_crit_); |
| 142 uint32_t encoder_max_bitrate_bps_ GUARDED_BY(encoder_settings_crit_); |
| 143 uint32_t encoder_target_rate_bps_ GUARDED_BY(encoder_settings_crit_); |
| 144 |
| 145 enum class State { |
| 146 kStopped, // VideoSendStream::Start has not yet been called. |
| 147 kStarted, // VideoSendStream::Start has been called. |
| 148 // VideoSendStream::Start has been called but the encoder have timed out. |
| 149 kEncoderTimedOut, |
| 150 }; |
| 151 rtc::Optional<State> pending_state_change_ GUARDED_BY(encoder_settings_crit_); |
| 152 |
| 153 // Only used on the encoder thread. |
| 154 rtc::ThreadChecker encoder_thread_checker_; |
| 155 State state_ ACCESS_ON(&encoder_thread_checker_); |
| 156 std::unique_ptr<EncoderSettings> current_encoder_settings_ |
| 157 ACCESS_ON(&encoder_thread_checker_); |
| 158 |
| 159 OveruseFrameDetector overuse_detector_; |
| 160 ViEEncoder vie_encoder_; |
| 161 EncoderStateFeedback encoder_feedback_; |
| 162 ProtectionBitrateCalculator protection_bitrate_calculator_; |
| 163 |
| 164 vcm::VideoSender* const video_sender_; |
| 165 |
| 166 const std::unique_ptr<RtcpBandwidthObserver> bandwidth_observer_; |
| 167 // RtpRtcp modules, declared here as they use other members on construction. |
| 168 const std::vector<RtpRtcp*> rtp_rtcp_modules_; |
| 169 PayloadRouter payload_router_; |
| 170 VideoCaptureInput input_; |
93 }; | 171 }; |
94 | |
95 } // namespace internal | 172 } // namespace internal |
96 } // namespace webrtc | 173 } // namespace webrtc |
97 | 174 |
98 #endif // WEBRTC_VIDEO_VIDEO_SEND_STREAM_H_ | 175 #endif // WEBRTC_VIDEO_VIDEO_SEND_STREAM_H_ |
OLD | NEW |