OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 bool mute, | 154 bool mute, |
155 const VideoOptions* options) override; | 155 const VideoOptions* options) override; |
156 bool AddSendStream(const StreamParams& sp) override; | 156 bool AddSendStream(const StreamParams& sp) override; |
157 bool RemoveSendStream(uint32_t ssrc) override; | 157 bool RemoveSendStream(uint32_t ssrc) override; |
158 bool AddRecvStream(const StreamParams& sp) override; | 158 bool AddRecvStream(const StreamParams& sp) override; |
159 bool AddRecvStream(const StreamParams& sp, bool default_stream); | 159 bool AddRecvStream(const StreamParams& sp, bool default_stream); |
160 bool RemoveRecvStream(uint32_t ssrc) override; | 160 bool RemoveRecvStream(uint32_t ssrc) override; |
161 bool SetSink(uint32_t ssrc, | 161 bool SetSink(uint32_t ssrc, |
162 rtc::VideoSinkInterface<VideoFrame>* sink) override; | 162 rtc::VideoSinkInterface<VideoFrame>* sink) override; |
163 bool GetStats(VideoMediaInfo* info) override; | 163 bool GetStats(VideoMediaInfo* info) override; |
164 bool SetCapturer(uint32_t ssrc, VideoCapturer* capturer) override; | 164 void SetSource( |
| 165 uint32_t ssrc, |
| 166 rtc::VideoSourceInterface<cricket::VideoFrame>* source) override; |
165 | 167 |
166 void OnPacketReceived(rtc::CopyOnWriteBuffer* packet, | 168 void OnPacketReceived(rtc::CopyOnWriteBuffer* packet, |
167 const rtc::PacketTime& packet_time) override; | 169 const rtc::PacketTime& packet_time) override; |
168 void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet, | 170 void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet, |
169 const rtc::PacketTime& packet_time) override; | 171 const rtc::PacketTime& packet_time) override; |
170 void OnReadyToSend(bool ready) override; | 172 void OnReadyToSend(bool ready) override; |
171 void SetInterface(NetworkInterface* iface) override; | 173 void SetInterface(NetworkInterface* iface) override; |
172 | 174 |
173 // Implemented for VideoMediaChannelTest. | 175 // Implemented for VideoMediaChannelTest. |
174 bool sending() const { return sending_; } | 176 bool sending() const { return sending_; } |
(...skipping 25 matching lines...) Expand all Loading... |
200 // These optionals are unset if not changed. | 202 // These optionals are unset if not changed. |
201 rtc::Optional<std::vector<VideoCodecSettings>> codec_settings; | 203 rtc::Optional<std::vector<VideoCodecSettings>> codec_settings; |
202 rtc::Optional<std::vector<webrtc::RtpExtension>> rtp_header_extensions; | 204 rtc::Optional<std::vector<webrtc::RtpExtension>> rtp_header_extensions; |
203 }; | 205 }; |
204 | 206 |
205 bool GetChangedSendParameters(const VideoSendParameters& params, | 207 bool GetChangedSendParameters(const VideoSendParameters& params, |
206 ChangedSendParameters* changed_params) const; | 208 ChangedSendParameters* changed_params) const; |
207 bool GetChangedRecvParameters(const VideoRecvParameters& params, | 209 bool GetChangedRecvParameters(const VideoRecvParameters& params, |
208 ChangedRecvParameters* changed_params) const; | 210 ChangedRecvParameters* changed_params) const; |
209 | 211 |
210 bool MuteStream(uint32_t ssrc, bool mute); | |
211 | |
212 void SetMaxSendBandwidth(int bps); | 212 void SetMaxSendBandwidth(int bps); |
213 void SetOptions(uint32_t ssrc, const VideoOptions& options); | 213 void SetOptions(uint32_t ssrc, const VideoOptions& options); |
214 | 214 |
215 void ConfigureReceiverRtp(webrtc::VideoReceiveStream::Config* config, | 215 void ConfigureReceiverRtp(webrtc::VideoReceiveStream::Config* config, |
216 const StreamParams& sp) const; | 216 const StreamParams& sp) const; |
217 bool CodecIsExternallySupported(const std::string& name) const; | 217 bool CodecIsExternallySupported(const std::string& name) const; |
218 bool ValidateSendSsrcAvailability(const StreamParams& sp) const | 218 bool ValidateSendSsrcAvailability(const StreamParams& sp) const |
219 EXCLUSIVE_LOCKS_REQUIRED(stream_crit_); | 219 EXCLUSIVE_LOCKS_REQUIRED(stream_crit_); |
220 bool ValidateReceiveSsrcAvailability(const StreamParams& sp) const | 220 bool ValidateReceiveSsrcAvailability(const StreamParams& sp) const |
221 EXCLUSIVE_LOCKS_REQUIRED(stream_crit_); | 221 EXCLUSIVE_LOCKS_REQUIRED(stream_crit_); |
222 void DeleteReceiveStream(WebRtcVideoReceiveStream* stream) | 222 void DeleteReceiveStream(WebRtcVideoReceiveStream* stream) |
223 EXCLUSIVE_LOCKS_REQUIRED(stream_crit_); | 223 EXCLUSIVE_LOCKS_REQUIRED(stream_crit_); |
224 | 224 |
225 static std::string CodecSettingsVectorToString( | 225 static std::string CodecSettingsVectorToString( |
226 const std::vector<VideoCodecSettings>& codecs); | 226 const std::vector<VideoCodecSettings>& codecs); |
227 | 227 |
228 // Wrapper for the sender part, this is where the capturer is connected and | 228 // Wrapper for the sender part, this is where the source is connected and |
229 // frames are then converted from cricket frames to webrtc frames. | 229 // frames are then converted from cricket frames to webrtc frames. |
230 class WebRtcVideoSendStream | 230 class WebRtcVideoSendStream |
231 : public rtc::VideoSinkInterface<cricket::VideoFrame>, | 231 : public rtc::VideoSinkInterface<cricket::VideoFrame>, |
232 public webrtc::LoadObserver { | 232 public webrtc::LoadObserver { |
233 public: | 233 public: |
234 WebRtcVideoSendStream( | 234 WebRtcVideoSendStream( |
235 webrtc::Call* call, | 235 webrtc::Call* call, |
236 const StreamParams& sp, | 236 const StreamParams& sp, |
237 const webrtc::VideoSendStream::Config& config, | 237 const webrtc::VideoSendStream::Config& config, |
238 const VideoOptions& options, | 238 const VideoOptions& options, |
239 WebRtcVideoEncoderFactory* external_encoder_factory, | 239 WebRtcVideoEncoderFactory* external_encoder_factory, |
240 bool enable_cpu_overuse_detection, | 240 bool enable_cpu_overuse_detection, |
241 int max_bitrate_bps, | 241 int max_bitrate_bps, |
242 const rtc::Optional<VideoCodecSettings>& codec_settings, | 242 const rtc::Optional<VideoCodecSettings>& codec_settings, |
243 const std::vector<webrtc::RtpExtension>& rtp_extensions, | 243 const std::vector<webrtc::RtpExtension>& rtp_extensions, |
244 const VideoSendParameters& send_params); | 244 const VideoSendParameters& send_params); |
245 virtual ~WebRtcVideoSendStream(); | 245 virtual ~WebRtcVideoSendStream(); |
246 | 246 |
247 void SetOptions(const VideoOptions& options); | 247 void SetOptions(const VideoOptions& options); |
248 // TODO(pbos): Move logic from SetOptions into this method. | 248 // TODO(pbos): Move logic from SetOptions into this method. |
249 void SetSendParameters(const ChangedSendParameters& send_params); | 249 void SetSendParameters(const ChangedSendParameters& send_params); |
250 bool SetRtpParameters(const webrtc::RtpParameters& parameters); | 250 bool SetRtpParameters(const webrtc::RtpParameters& parameters); |
251 | 251 |
252 void OnFrame(const cricket::VideoFrame& frame) override; | 252 void OnFrame(const cricket::VideoFrame& frame) override; |
253 bool SetCapturer(VideoCapturer* capturer); | 253 void SetSource(rtc::VideoSourceInterface<cricket::VideoFrame>* source); |
254 void MuteStream(bool mute); | 254 void DisconnectSource(); |
255 bool DisconnectCapturer(); | |
256 | 255 |
257 void Start(); | 256 void Start(); |
258 void Stop(); | 257 void Stop(); |
259 | 258 |
260 webrtc::RtpParameters rtp_parameters() const { return rtp_parameters_; } | 259 webrtc::RtpParameters rtp_parameters() const { return rtp_parameters_; } |
261 | 260 |
262 // Implements webrtc::LoadObserver. | 261 // Implements webrtc::LoadObserver. |
263 void OnLoadUpdate(Load load) override; | 262 void OnLoadUpdate(Load load) override; |
264 | 263 |
265 const std::vector<uint32_t>& GetSsrcs() const; | 264 const std::vector<uint32_t>& GetSsrcs() const; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 bool ValidateRtpParameters(const webrtc::RtpParameters& parameters); | 345 bool ValidateRtpParameters(const webrtc::RtpParameters& parameters); |
347 | 346 |
348 rtc::ThreadChecker thread_checker_; | 347 rtc::ThreadChecker thread_checker_; |
349 rtc::AsyncInvoker invoker_; | 348 rtc::AsyncInvoker invoker_; |
350 rtc::Thread* worker_thread_; | 349 rtc::Thread* worker_thread_; |
351 const std::vector<uint32_t> ssrcs_; | 350 const std::vector<uint32_t> ssrcs_; |
352 const std::vector<SsrcGroup> ssrc_groups_; | 351 const std::vector<SsrcGroup> ssrc_groups_; |
353 webrtc::Call* const call_; | 352 webrtc::Call* const call_; |
354 rtc::VideoSinkWants sink_wants_; | 353 rtc::VideoSinkWants sink_wants_; |
355 // Counter used for deciding if the video resolution is currently | 354 // Counter used for deciding if the video resolution is currently |
356 // restricted by CPU usage. It is reset if |capturer_| is changed. | 355 // restricted by CPU usage. It is reset if |source_| is changed. |
357 int cpu_restricted_counter_; | 356 int cpu_restricted_counter_; |
358 // Total number of times resolution as been requested to be changed due to | 357 // Total number of times resolution as been requested to be changed due to |
359 // CPU adaptation. | 358 // CPU adaptation. |
360 int number_of_cpu_adapt_changes_; | 359 int number_of_cpu_adapt_changes_; |
361 VideoCapturer* capturer_; | 360 rtc::VideoSourceInterface<cricket::VideoFrame>* source_; |
362 WebRtcVideoEncoderFactory* const external_encoder_factory_ | 361 WebRtcVideoEncoderFactory* const external_encoder_factory_ |
363 GUARDED_BY(lock_); | 362 GUARDED_BY(lock_); |
364 | 363 |
365 rtc::CriticalSection lock_; | 364 rtc::CriticalSection lock_; |
366 webrtc::VideoSendStream* stream_ GUARDED_BY(lock_); | 365 webrtc::VideoSendStream* stream_ GUARDED_BY(lock_); |
367 // Contains settings that are the same for all streams in the MediaChannel, | 366 // Contains settings that are the same for all streams in the MediaChannel, |
368 // such as codecs, header extensions, and the global bitrate limit for the | 367 // such as codecs, header extensions, and the global bitrate limit for the |
369 // entire channel. | 368 // entire channel. |
370 VideoSendStreamParameters parameters_ GUARDED_BY(lock_); | 369 VideoSendStreamParameters parameters_ GUARDED_BY(lock_); |
371 // Contains settings that are unique for each stream, such as max_bitrate. | 370 // Contains settings that are unique for each stream, such as max_bitrate. |
372 // TODO(skvlad): Move ssrcs_ and ssrc_groups_ into rtp_parameters_. | 371 // TODO(skvlad): Move ssrcs_ and ssrc_groups_ into rtp_parameters_. |
373 // TODO(skvlad): Combine parameters_ and rtp_parameters_ once we have only | 372 // TODO(skvlad): Combine parameters_ and rtp_parameters_ once we have only |
374 // one stream per MediaChannel. | 373 // one stream per MediaChannel. |
375 webrtc::RtpParameters rtp_parameters_; | 374 webrtc::RtpParameters rtp_parameters_; |
376 bool pending_encoder_reconfiguration_ GUARDED_BY(lock_); | 375 bool pending_encoder_reconfiguration_ GUARDED_BY(lock_); |
377 VideoEncoderSettings encoder_settings_ GUARDED_BY(lock_); | 376 VideoEncoderSettings encoder_settings_ GUARDED_BY(lock_); |
378 AllocatedEncoder allocated_encoder_ GUARDED_BY(lock_); | 377 AllocatedEncoder allocated_encoder_ GUARDED_BY(lock_); |
| 378 // Original frame dimension, before adaptation due to cpu or |
| 379 // network bottlenecks. |
| 380 Dimensions input_dimensions_ GUARDED_BY(lock_); |
379 Dimensions last_dimensions_ GUARDED_BY(lock_); | 381 Dimensions last_dimensions_ GUARDED_BY(lock_); |
380 webrtc::VideoRotation last_rotation_ GUARDED_BY(lock_) = | 382 webrtc::VideoRotation last_rotation_ GUARDED_BY(lock_) = |
381 webrtc::kVideoRotation_0; | 383 webrtc::kVideoRotation_0; |
382 | 384 |
383 bool sending_ GUARDED_BY(lock_); | 385 bool sending_ GUARDED_BY(lock_); |
384 bool muted_ GUARDED_BY(lock_); | |
385 | 386 |
386 // The timestamp of the first frame received | 387 // The timestamp of the first frame received |
387 // Used to generate the timestamps of subsequent frames | 388 // Used to generate the timestamps of subsequent frames |
388 int64_t first_frame_timestamp_ms_ GUARDED_BY(lock_); | 389 int64_t first_frame_timestamp_ms_ GUARDED_BY(lock_); |
389 | 390 |
390 // The timestamp of the last frame received | 391 // The timestamp of the last frame received |
391 // Used to generate timestamp for the black frame when capturer is removed | 392 // Used to generate timestamp for the black frame when source is removed |
392 int64_t last_frame_timestamp_ms_ GUARDED_BY(lock_); | 393 int64_t last_frame_timestamp_ms_ GUARDED_BY(lock_); |
393 }; | 394 }; |
394 | 395 |
395 // Wrapper for the receiver part, contains configs etc. that are needed to | 396 // Wrapper for the receiver part, contains configs etc. that are needed to |
396 // reconstruct the underlying VideoReceiveStream. Also serves as a wrapper | 397 // reconstruct the underlying VideoReceiveStream. Also serves as a wrapper |
397 // between webrtc::VideoRenderer and cricket::VideoRenderer. | 398 // between webrtc::VideoRenderer and cricket::VideoRenderer. |
398 class WebRtcVideoReceiveStream : public webrtc::VideoRenderer { | 399 class WebRtcVideoReceiveStream : public webrtc::VideoRenderer { |
399 public: | 400 public: |
400 WebRtcVideoReceiveStream( | 401 WebRtcVideoReceiveStream( |
401 webrtc::Call* call, | 402 webrtc::Call* call, |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 // TODO(deadbeef): Don't duplicate information between | 531 // TODO(deadbeef): Don't duplicate information between |
531 // send_params/recv_params, rtp_extensions, options, etc. | 532 // send_params/recv_params, rtp_extensions, options, etc. |
532 VideoSendParameters send_params_; | 533 VideoSendParameters send_params_; |
533 VideoOptions default_send_options_; | 534 VideoOptions default_send_options_; |
534 VideoRecvParameters recv_params_; | 535 VideoRecvParameters recv_params_; |
535 }; | 536 }; |
536 | 537 |
537 } // namespace cricket | 538 } // namespace cricket |
538 | 539 |
539 #endif // WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE2_H_ | 540 #endif // WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE2_H_ |
OLD | NEW |