Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: webrtc/video/video_send_stream.h

Issue 2060403002: Add task queue to Call. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@move_getpadding
Patch Set: Use SequencedTaskChecker in i420_buffer_pool.cc Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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;
pbos-webrtc 2016/07/13 12:35:39 Should this be named something related to RTP or o
perkj_webrtc 2016/07/14 10:11:28 I would like to wait until dust has settled. It is
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.
pbos-webrtc 2016/07/13 12:35:39 or ViEEncoder?
perkj_webrtc 2016/07/14 10:11:28 Done.
54 public EncodedImageCallback { 50 // 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 int32_t Encoded(const EncodedImage& encoded_image,
112 const CodecSpecificInfo* codec_specific_info,
113 const RTPFragmentationHeader* fragmentation) override;
114
115 static bool EncoderThreadFunction(void* obj);
116 void EncoderProcess();
117
118 void ConfigureProtection();
119 void ConfigureSsrcs();
120 88
121 SendStatisticsProxy stats_proxy_; 89 SendStatisticsProxy stats_proxy_;
122 const VideoSendStream::Config config_; 90 const VideoSendStream::Config config_;
123 std::map<uint32_t, RtpState> suspended_ssrcs_; 91 std::unique_ptr<VideoSendStreamImpl> send_stream_;
92 std::unique_ptr<ViEEncoder> vie_encoder_;
93 };
124 94
125 ProcessThread* const module_process_thread_;
126 CallStats* const call_stats_;
127 CongestionController* const congestion_controller_;
128 BitrateAllocator* const bitrate_allocator_;
129 VieRemb* const remb_;
130
131 static const bool kEnableFrameRecording = false;
132 static const int kMaxLayers = 3;
133 std::unique_ptr<IvfFileWriter> file_writers_[kMaxLayers];
134
135 rtc::PlatformThread encoder_thread_;
136 rtc::Event encoder_wakeup_event_;
137 volatile int stop_encoder_thread_;
138 rtc::CriticalSection encoder_settings_crit_;
139 std::unique_ptr<EncoderSettings> pending_encoder_settings_
140 GUARDED_BY(encoder_settings_crit_);
141 uint32_t encoder_max_bitrate_bps_ GUARDED_BY(encoder_settings_crit_);
142 uint32_t encoder_target_rate_bps_ GUARDED_BY(encoder_settings_crit_);
143
144 enum class State {
145 kStopped, // VideoSendStream::Start has not yet been called.
146 kStarted, // VideoSendStream::Start has been called.
147 // VideoSendStream::Start has been called but the encoder have timed out.
148 kEncoderTimedOut,
149 };
150 rtc::Optional<State> pending_state_change_ GUARDED_BY(encoder_settings_crit_);
151
152 // Only used on the encoder thread.
153 rtc::ThreadChecker encoder_thread_checker_;
154 State state_ ACCESS_ON(&encoder_thread_checker_);
155 std::unique_ptr<EncoderSettings> current_encoder_settings_
156 ACCESS_ON(&encoder_thread_checker_);
157
158 OveruseFrameDetector overuse_detector_;
159 ViEEncoder vie_encoder_;
160 EncoderStateFeedback encoder_feedback_;
161 ProtectionBitrateCalculator protection_bitrate_calculator_;
162
163 vcm::VideoSender* const video_sender_;
164
165 const std::unique_ptr<RtcpBandwidthObserver> bandwidth_observer_;
166 // RtpRtcp modules, declared here as they use other members on construction.
167 const std::vector<RtpRtcp*> rtp_rtcp_modules_;
168 PayloadRouter payload_router_;
169 VideoCaptureInput input_;
170 };
171 } // namespace internal 95 } // namespace internal
172 } // namespace webrtc 96 } // namespace webrtc
173 97
174 #endif // WEBRTC_VIDEO_VIDEO_SEND_STREAM_H_ 98 #endif // WEBRTC_VIDEO_VIDEO_SEND_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698