Index: webrtc/video/video_send_stream.h |
diff --git a/webrtc/video/video_send_stream.h b/webrtc/video/video_send_stream.h |
index 1c66c1fe332ad9540343b2e01abc82668c4459a4..606961957d9a936d0f06fe3530835ebf2839fdaf 100644 |
--- a/webrtc/video/video_send_stream.h |
+++ b/webrtc/video/video_send_stream.h |
@@ -17,6 +17,8 @@ |
#include "webrtc/call/bitrate_allocator.h" |
#include "webrtc/base/criticalsection.h" |
+#include "webrtc/base/event.h" |
+#include "webrtc/base/task_queue.h" |
#include "webrtc/call.h" |
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
#include "webrtc/modules/video_coding/protection_bitrate_calculator.h" |
@@ -47,14 +49,16 @@ class VideoSender; |
namespace internal { |
-class VideoSendStream : public webrtc::VideoSendStream, |
- public webrtc::CpuOveruseObserver, |
- public webrtc::BitrateAllocatorObserver, |
- public webrtc::VCMProtectionCallback, |
- public EncodedImageCallback { |
+class VideoSendStreamInternal; |
+ |
+// VideoSendStream implements webrtc::VideoSendStream. |
+// Internally, it delegates all public methods to VideoSendStreamInternal. |
+// VideoSendStreamInternal in created and destructed on |worker_queu|. |
+class VideoSendStream : public webrtc::VideoSendStream { |
public: |
VideoSendStream(int num_cpu_cores, |
ProcessThread* module_process_thread, |
+ rtc::TaskQueue* worker_queu, |
CallStats* call_stats, |
CongestionController* congestion_controller, |
BitrateAllocator* bitrate_allocator, |
@@ -77,15 +81,61 @@ class VideoSendStream : public webrtc::VideoSendStream, |
void ReconfigureVideoEncoder(const VideoEncoderConfig& config) override; |
Stats GetStats() override; |
+ typedef std::map<uint32_t, RtpState> RtpStateMap; |
+ RtpStateMap StopPermanentlyAndGetRtpStates(); |
+ |
+ private: |
+ class ConstructionTask; |
+ class DestructAndGetRTPStateTask; |
+ |
+ rtc::ThreadChecker thread_checker_; |
+ rtc::TaskQueue* const worker_queu_; |
+ std::unique_ptr<VideoSendStreamInternal> send_stream_; |
+ rtc::Event thread_sync_event_; |
+}; |
+ |
+class VideoSendStreamInternal : public webrtc::CpuOveruseObserver, |
+ public webrtc::BitrateAllocatorObserver, |
+ public webrtc::VCMProtectionCallback, |
+ public EncodedImageCallback { |
+ public: |
+ VideoSendStreamInternal(int num_cpu_cores, |
+ rtc::TaskQueue* worker_queu, |
+ CallStats* call_stats, |
+ CongestionController* congestion_controller, |
+ BitrateAllocator* bitrate_allocator, |
+ SendDelayStats* send_delay_stats, |
+ VieRemb* remb, |
+ RtcEventLog* event_log, |
+ const VideoSendStream::Config& config, |
+ const VideoEncoderConfig& encoder_config, |
+ const std::map<uint32_t, RtpState>& suspended_ssrcs); |
+ |
+ ~VideoSendStreamInternal() override; |
+ |
+ // RegisterProcessThread register |module_process_thread| with those objects |
+ // that use it. Registration have to happen on the thread where |
+ // |module_process_thread| where created (libjingles worker thread). |
+ // TODO(perkj): Replace the use of |module_process_thread| with a TaskQueue, |
+ // maybe |worker_queu|. |
+ void RegisterProcessThread(ProcessThread* module_process_thread); |
+ void DeRegisterProcessThread(); |
+ |
+ void SignalNetworkState(NetworkState state); |
+ bool DeliverRtcp(const uint8_t* packet, size_t length); |
+ |
+ // webrtc::VideoSendStream implementation. |
+ void Start(); |
+ void Stop(); |
+ VideoCaptureInput* Input(); |
+ void ReconfigureVideoEncoder(const VideoEncoderConfig& config); |
+ VideoSendStream::Stats GetStats(); |
+ VideoSendStream::RtpStateMap GetRtpStates() const; |
+ |
// webrtc::CpuOveruseObserver implementation. |
void OveruseDetected() override; |
void NormalUsage() override; |
- typedef std::map<uint32_t, RtpState> RtpStateMap; |
- RtpStateMap GetRtpStates() const; |
- |
- int GetPaddingNeededBps() const; |
- |
// Implements BitrateAllocatorObserver. |
void OnBitrateUpdated(uint32_t bitrate_bps, |
uint8_t fraction_loss, |
@@ -100,10 +150,7 @@ class VideoSendStream : public webrtc::VideoSendStream, |
uint32_t* sent_fec_rate_bps) override; |
private: |
- struct EncoderSettings { |
- VideoCodec video_codec; |
- VideoEncoderConfig config; |
- }; |
+ class CheckEncoderActivityTask; |
// Implements EncodedImageCallback. The implementation routes encoded frames |
// to the |payload_router_| and |config.pre_encode_callback| if set. |
@@ -117,12 +164,18 @@ class VideoSendStream : public webrtc::VideoSendStream, |
void ConfigureProtection(); |
void ConfigureSsrcs(); |
+ void EncoderTimedOut(); |
+ void EncoderIsActive(); |
SendStatisticsProxy stats_proxy_; |
const VideoSendStream::Config config_; |
std::map<uint32_t, RtpState> suspended_ssrcs_; |
- ProcessThread* const module_process_thread_; |
+ ProcessThread* module_process_thread_; |
+ rtc::ThreadChecker module_process_thread_checker_; |
+ rtc::TaskQueue* const worker_queu_; |
+ CheckEncoderActivityTask* check_encoder_activity_task_ |
+ GUARDED_BY(encoder_settings_crit_); |
CallStats* const call_stats_; |
CongestionController* const congestion_controller_; |
BitrateAllocator* const bitrate_allocator_; |
@@ -133,25 +186,16 @@ class VideoSendStream : public webrtc::VideoSendStream, |
std::unique_ptr<IvfFileWriter> file_writers_[kMaxLayers]; |
rtc::PlatformThread encoder_thread_; |
+ rtc::ThreadChecker encoder_thread_checker_; |
rtc::Event encoder_wakeup_event_; |
volatile int stop_encoder_thread_; |
rtc::CriticalSection encoder_settings_crit_; |
- std::unique_ptr<EncoderSettings> pending_encoder_settings_ |
+ std::unique_ptr<VideoCodec> pending_encoder_settings_ |
GUARDED_BY(encoder_settings_crit_); |
- enum class State { |
- kStopped, // VideoSendStream::Start has not yet been called. |
- kStarted, // VideoSendStream::Start has been called. |
- // VideoSendStream::Start has been called but the encoder have timed out. |
- kEncoderTimedOut, |
- }; |
- rtc::Optional<State> pending_state_change_ GUARDED_BY(encoder_settings_crit_); |
- |
- // Only used on the encoder thread. |
- rtc::ThreadChecker encoder_thread_checker_; |
- State state_ ACCESS_ON(&encoder_thread_checker_); |
- std::unique_ptr<EncoderSettings> current_encoder_settings_ |
- ACCESS_ON(&encoder_thread_checker_); |
+ VideoCodec current_video_codec_; |
+ int max_padding_bitrate_; |
+ uint32_t encoder_target_rate_; |
OveruseFrameDetector overuse_detector_; |
ViEEncoder vie_encoder_; |