OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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_VIE_ENCODER_H_ | 11 #ifndef WEBRTC_VIDEO_VIE_ENCODER_H_ |
12 #define WEBRTC_VIDEO_VIE_ENCODER_H_ | 12 #define WEBRTC_VIDEO_VIE_ENCODER_H_ |
13 | 13 |
14 #include <memory> | 14 #include <memory> |
15 #include <string> | 15 #include <string> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 #include "webrtc/base/criticalsection.h" | 18 #include "webrtc/base/criticalsection.h" |
19 #include "webrtc/base/event.h" | 19 #include "webrtc/base/event.h" |
20 #include "webrtc/base/sequenced_task_checker.h" | 20 #include "webrtc/base/sequenced_task_checker.h" |
21 #include "webrtc/base/task_queue.h" | 21 #include "webrtc/base/task_queue.h" |
22 #include "webrtc/call.h" | 22 #include "webrtc/call.h" |
23 #include "webrtc/common_types.h" | 23 #include "webrtc/common_types.h" |
24 #include "webrtc/common_video/rotation.h" | |
25 #include "webrtc/media/base/videosinkinterface.h" | 24 #include "webrtc/media/base/videosinkinterface.h" |
26 #include "webrtc/modules/video_coding/include/video_coding_defines.h" | 25 #include "webrtc/modules/video_coding/include/video_coding_defines.h" |
27 #include "webrtc/modules/video_coding/utility/simulcast_rate_allocator.h" | 26 #include "webrtc/modules/video_coding/utility/simulcast_rate_allocator.h" |
28 #include "webrtc/modules/video_coding/video_coding_impl.h" | 27 #include "webrtc/modules/video_coding/video_coding_impl.h" |
29 #include "webrtc/modules/video_processing/include/video_processing.h" | 28 #include "webrtc/modules/video_processing/include/video_processing.h" |
30 #include "webrtc/system_wrappers/include/atomic32.h" | 29 #include "webrtc/system_wrappers/include/atomic32.h" |
31 #include "webrtc/video/overuse_frame_detector.h" | 30 #include "webrtc/video/overuse_frame_detector.h" |
32 #include "webrtc/video_encoder.h" | 31 #include "webrtc/video_encoder.h" |
33 #include "webrtc/video_send_stream.h" | 32 #include "webrtc/video_send_stream.h" |
34 #include "webrtc/typedefs.h" | 33 #include "webrtc/typedefs.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 | 95 |
97 void OnBitrateUpdated(uint32_t bitrate_bps, | 96 void OnBitrateUpdated(uint32_t bitrate_bps, |
98 uint8_t fraction_lost, | 97 uint8_t fraction_lost, |
99 int64_t round_trip_time_ms); | 98 int64_t round_trip_time_ms); |
100 | 99 |
101 private: | 100 private: |
102 class ConfigureEncoderTask; | 101 class ConfigureEncoderTask; |
103 class EncodeTask; | 102 class EncodeTask; |
104 class VideoSourceProxy; | 103 class VideoSourceProxy; |
105 | 104 |
106 struct VideoFrameInfo { | |
107 VideoFrameInfo(int width, | |
108 int height, | |
109 VideoRotation rotation, | |
110 bool is_texture) | |
111 : width(width), | |
112 height(height), | |
113 rotation(rotation), | |
114 is_texture(is_texture) {} | |
115 int width; | |
116 int height; | |
117 webrtc::VideoRotation rotation; | |
118 bool is_texture; | |
119 }; | |
120 | |
121 void ConfigureEncoderOnTaskQueue(VideoEncoderConfig config, | 105 void ConfigureEncoderOnTaskQueue(VideoEncoderConfig config, |
122 size_t max_data_payload_length); | 106 size_t max_data_payload_length); |
123 void ReconfigureEncoder(); | |
124 | 107 |
125 // Implements VideoSinkInterface. | 108 // Implements VideoSinkInterface. |
126 void OnFrame(const VideoFrame& video_frame) override; | 109 void OnFrame(const VideoFrame& video_frame) override; |
127 | 110 |
128 // Implements VideoSendStatisticsCallback. | 111 // Implements VideoSendStatisticsCallback. |
129 void SendStatistics(uint32_t bit_rate, | 112 void SendStatistics(uint32_t bit_rate, |
130 uint32_t frame_rate) override; | 113 uint32_t frame_rate) override; |
131 | 114 |
132 void EncodeVideoFrame(const VideoFrame& frame, | 115 void EncodeVideoFrame(const VideoFrame& frame, |
133 int64_t time_when_posted_in_ms); | 116 int64_t time_when_posted_in_ms); |
(...skipping 14 matching lines...) Expand all Loading... |
148 | 131 |
149 rtc::Event shutdown_event_; | 132 rtc::Event shutdown_event_; |
150 | 133 |
151 const uint32_t number_of_cores_; | 134 const uint32_t number_of_cores_; |
152 | 135 |
153 const std::unique_ptr<VideoSourceProxy> source_proxy_; | 136 const std::unique_ptr<VideoSourceProxy> source_proxy_; |
154 EncoderSink* sink_; | 137 EncoderSink* sink_; |
155 const VideoSendStream::Config::EncoderSettings settings_; | 138 const VideoSendStream::Config::EncoderSettings settings_; |
156 const VideoCodecType codec_type_; | 139 const VideoCodecType codec_type_; |
157 | 140 |
| 141 const std::unique_ptr<VideoProcessing> vp_; |
158 vcm::VideoSender video_sender_ ACCESS_ON(&encoder_queue_); | 142 vcm::VideoSender video_sender_ ACCESS_ON(&encoder_queue_); |
159 | 143 |
160 OveruseFrameDetector overuse_detector_ ACCESS_ON(&encoder_queue_); | 144 OveruseFrameDetector overuse_detector_ ACCESS_ON(&encoder_queue_); |
161 LoadObserver* const load_observer_ ACCESS_ON(&encoder_queue_); | 145 LoadObserver* const load_observer_ ACCESS_ON(&encoder_queue_); |
162 | 146 |
163 SendStatisticsProxy* const stats_proxy_; | 147 SendStatisticsProxy* const stats_proxy_; |
164 rtc::VideoSinkInterface<VideoFrame>* const pre_encode_callback_; | 148 rtc::VideoSinkInterface<VideoFrame>* const pre_encode_callback_; |
165 ProcessThread* module_process_thread_; | 149 ProcessThread* module_process_thread_; |
166 rtc::ThreadChecker module_process_thread_checker_; | 150 rtc::ThreadChecker module_process_thread_checker_; |
167 // |thread_checker_| checks that public methods that are related to lifetime | 151 // |thread_checker_| checks that public methods that are related to lifetime |
168 // of ViEEncoder are called on the same thread. | 152 // of ViEEncoder are called on the same thread. |
169 rtc::ThreadChecker thread_checker_; | 153 rtc::ThreadChecker thread_checker_; |
170 | 154 |
171 VideoEncoderConfig encoder_config_ ACCESS_ON(&encoder_queue_); | 155 VideoEncoderConfig encoder_config_ ACCESS_ON(&encoder_queue_); |
172 // TODO(sprang): Change |rate_allocator_| to be a codec type | 156 // TODO(sprang): Change |rate_allocator_| to be a codec type |
173 // agnostic interface. It is currently VP8 simulcast specific if more than | 157 // agnostic interface. It is currently VP8 simulcast specific if more than |
174 // one layer is specified. | 158 // one layer is specified. |
175 std::unique_ptr<SimulcastRateAllocator> rate_allocator_ | 159 std::unique_ptr<SimulcastRateAllocator> rate_allocator_ |
176 ACCESS_ON(&encoder_queue_); | 160 ACCESS_ON(&encoder_queue_); |
177 | 161 |
178 // Set when ConfigureEncoder has been called in order to lazy reconfigure the | |
179 // encoder on the next frame. | |
180 bool pending_encoder_reconfiguration_ ACCESS_ON(&encoder_queue_); | |
181 rtc::Optional<VideoFrameInfo> last_frame_info_ ACCESS_ON(&encoder_queue_); | |
182 uint32_t encoder_start_bitrate_bps_ ACCESS_ON(&encoder_queue_); | 162 uint32_t encoder_start_bitrate_bps_ ACCESS_ON(&encoder_queue_); |
183 size_t max_data_payload_length_ ACCESS_ON(&encoder_queue_); | 163 size_t max_data_payload_length_ ACCESS_ON(&encoder_queue_); |
184 uint32_t last_observed_bitrate_bps_ ACCESS_ON(&encoder_queue_); | 164 uint32_t last_observed_bitrate_bps_ ACCESS_ON(&encoder_queue_); |
185 bool encoder_paused_and_dropped_frame_ ACCESS_ON(&encoder_queue_); | 165 bool encoder_paused_and_dropped_frame_ ACCESS_ON(&encoder_queue_); |
186 bool has_received_sli_ ACCESS_ON(&encoder_queue_); | 166 bool has_received_sli_ ACCESS_ON(&encoder_queue_); |
187 uint8_t picture_id_sli_ ACCESS_ON(&encoder_queue_); | 167 uint8_t picture_id_sli_ ACCESS_ON(&encoder_queue_); |
188 bool has_received_rpsi_ ACCESS_ON(&encoder_queue_); | 168 bool has_received_rpsi_ ACCESS_ON(&encoder_queue_); |
189 uint64_t picture_id_rpsi_ ACCESS_ON(&encoder_queue_); | 169 uint64_t picture_id_rpsi_ ACCESS_ON(&encoder_queue_); |
190 Clock* const clock_; | 170 Clock* const clock_; |
191 | 171 |
(...skipping 11 matching lines...) Expand all Loading... |
203 // All public methods are proxied to |encoder_queue_|. It must must be | 183 // All public methods are proxied to |encoder_queue_|. It must must be |
204 // destroyed first to make sure no tasks are run that use other members. | 184 // destroyed first to make sure no tasks are run that use other members. |
205 rtc::TaskQueue encoder_queue_; | 185 rtc::TaskQueue encoder_queue_; |
206 | 186 |
207 RTC_DISALLOW_COPY_AND_ASSIGN(ViEEncoder); | 187 RTC_DISALLOW_COPY_AND_ASSIGN(ViEEncoder); |
208 }; | 188 }; |
209 | 189 |
210 } // namespace webrtc | 190 } // namespace webrtc |
211 | 191 |
212 #endif // WEBRTC_VIDEO_VIE_ENCODER_H_ | 192 #endif // WEBRTC_VIDEO_VIE_ENCODER_H_ |
OLD | NEW |