| 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" |
| 20 #include "webrtc/call.h" | 22 #include "webrtc/call.h" |
| 21 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 23 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
| 22 #include "webrtc/modules/video_coding/protection_bitrate_calculator.h" | 24 #include "webrtc/modules/video_coding/protection_bitrate_calculator.h" |
| 23 #include "webrtc/video/encoder_state_feedback.h" | 25 #include "webrtc/video/encoder_state_feedback.h" |
| 24 #include "webrtc/video/payload_router.h" | 26 #include "webrtc/video/payload_router.h" |
| 25 #include "webrtc/video/send_delay_stats.h" | 27 #include "webrtc/video/send_delay_stats.h" |
| 26 #include "webrtc/video/send_statistics_proxy.h" | 28 #include "webrtc/video/send_statistics_proxy.h" |
| 27 #include "webrtc/video/video_capture_input.h" | |
| 28 #include "webrtc/video/vie_encoder.h" | 29 #include "webrtc/video/vie_encoder.h" |
| 29 #include "webrtc/video_receive_stream.h" | 30 #include "webrtc/video_receive_stream.h" |
| 30 #include "webrtc/video_send_stream.h" | 31 #include "webrtc/video_send_stream.h" |
| 31 | 32 |
| 32 namespace webrtc { | 33 namespace webrtc { |
| 33 | 34 |
| 34 class BitrateAllocator; | 35 class BitrateAllocator; |
| 35 class CallStats; | 36 class CallStats; |
| 36 class CongestionController; | 37 class CongestionController; |
| 37 class IvfFileWriter; | 38 class IvfFileWriter; |
| 38 class ProcessThread; | 39 class ProcessThread; |
| 39 class RtpRtcp; | 40 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 | |
| 48 namespace internal { | 44 namespace internal { |
| 49 | 45 |
| 50 class VideoSendStream : public webrtc::VideoSendStream, | 46 class VideoSendStreamImpl; |
| 51 public webrtc::CpuOveruseObserver, | 47 |
| 52 public webrtc::BitrateAllocatorObserver, | 48 // VideoSendStream implements webrtc::VideoSendStream. |
| 53 public webrtc::VCMProtectionCallback, | 49 // Internally, it delegates all public methods to VideoSendStreamImpl and / or |
| 54 public EncodedImageCallback { | 50 // VieEncoder. VideoSendStreamInternal is created and deleted on |worker_queue|. |
| 51 class VideoSendStream : public webrtc::VideoSendStream { |
| 55 public: | 52 public: |
| 56 VideoSendStream(int num_cpu_cores, | 53 VideoSendStream(int num_cpu_cores, |
| 57 ProcessThread* module_process_thread, | 54 ProcessThread* module_process_thread, |
| 55 rtc::TaskQueue* worker_queue, |
| 58 CallStats* call_stats, | 56 CallStats* call_stats, |
| 59 CongestionController* congestion_controller, | 57 CongestionController* congestion_controller, |
| 60 BitrateAllocator* bitrate_allocator, | 58 BitrateAllocator* bitrate_allocator, |
| 61 SendDelayStats* send_delay_stats, | 59 SendDelayStats* send_delay_stats, |
| 62 VieRemb* remb, | 60 VieRemb* remb, |
| 63 RtcEventLog* event_log, | 61 RtcEventLog* event_log, |
| 64 const VideoSendStream::Config& config, | 62 VideoSendStream::Config config, |
| 65 const VideoEncoderConfig& encoder_config, | 63 VideoEncoderConfig encoder_config, |
| 66 const std::map<uint32_t, RtpState>& suspended_ssrcs); | 64 const std::map<uint32_t, RtpState>& suspended_ssrcs); |
| 67 | 65 |
| 68 ~VideoSendStream() override; | 66 ~VideoSendStream() override; |
| 69 | 67 |
| 70 void SignalNetworkState(NetworkState state); | 68 void SignalNetworkState(NetworkState state); |
| 71 bool DeliverRtcp(const uint8_t* packet, size_t length); | 69 bool DeliverRtcp(const uint8_t* packet, size_t length); |
| 72 | 70 |
| 73 // webrtc::VideoSendStream implementation. | 71 // webrtc::VideoSendStream implementation. |
| 74 void Start() override; | 72 void Start() override; |
| 75 void Stop() override; | 73 void Stop() override; |
| 76 VideoCaptureInput* Input() override; | 74 VideoCaptureInput* Input() override; |
| 77 void ReconfigureVideoEncoder(const VideoEncoderConfig& config) override; | 75 void ReconfigureVideoEncoder(VideoEncoderConfig) override; |
| 78 Stats GetStats() override; | 76 Stats GetStats() override; |
| 79 | 77 |
| 80 // webrtc::CpuOveruseObserver implementation. | |
| 81 void OveruseDetected() override; | |
| 82 void NormalUsage() override; | |
| 83 | |
| 84 typedef std::map<uint32_t, RtpState> RtpStateMap; | 78 typedef std::map<uint32_t, RtpState> RtpStateMap; |
| 85 RtpStateMap GetRtpStates() const; | 79 RtpStateMap StopPermanentlyAndGetRtpStates(); |
| 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; | |
| 101 | 80 |
| 102 private: | 81 private: |
| 103 struct EncoderSettings { | 82 class ConstructionTask; |
| 104 VideoCodec video_codec; | 83 class DestructAndGetRtpStateTask; |
| 105 VideoEncoderConfig config; | |
| 106 }; | |
| 107 | 84 |
| 108 // Implements EncodedImageCallback. The implementation routes encoded frames | 85 rtc::ThreadChecker thread_checker_; |
| 109 // to the |payload_router_| and |config.pre_encode_callback| if set. | 86 rtc::TaskQueue* const worker_queue_; |
| 110 // Called on an arbitrary encoder callback thread. | 87 rtc::Event thread_sync_event_; |
| 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(); | |
| 121 | 88 |
| 122 SendStatisticsProxy stats_proxy_; | 89 SendStatisticsProxy stats_proxy_; |
| 123 const VideoSendStream::Config config_; | 90 const VideoSendStream::Config config_; |
| 124 std::map<uint32_t, RtpState> suspended_ssrcs_; | 91 std::unique_ptr<VideoSendStreamImpl> send_stream_; |
| 92 std::unique_ptr<ViEEncoder> vie_encoder_; |
| 93 }; |
| 125 | 94 |
| 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_; | |
| 171 }; | |
| 172 } // namespace internal | 95 } // namespace internal |
| 173 } // namespace webrtc | 96 } // namespace webrtc |
| 174 | 97 |
| 175 #endif // WEBRTC_VIDEO_VIDEO_SEND_STREAM_H_ | 98 #endif // WEBRTC_VIDEO_VIDEO_SEND_STREAM_H_ |
| OLD | NEW |