| 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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 bool ValidateSendSsrcAvailability(const StreamParams& sp) const | 227 bool ValidateSendSsrcAvailability(const StreamParams& sp) const |
| 228 EXCLUSIVE_LOCKS_REQUIRED(stream_crit_); | 228 EXCLUSIVE_LOCKS_REQUIRED(stream_crit_); |
| 229 bool ValidateReceiveSsrcAvailability(const StreamParams& sp) const | 229 bool ValidateReceiveSsrcAvailability(const StreamParams& sp) const |
| 230 EXCLUSIVE_LOCKS_REQUIRED(stream_crit_); | 230 EXCLUSIVE_LOCKS_REQUIRED(stream_crit_); |
| 231 void DeleteReceiveStream(WebRtcVideoReceiveStream* stream) | 231 void DeleteReceiveStream(WebRtcVideoReceiveStream* stream) |
| 232 EXCLUSIVE_LOCKS_REQUIRED(stream_crit_); | 232 EXCLUSIVE_LOCKS_REQUIRED(stream_crit_); |
| 233 | 233 |
| 234 static std::string CodecSettingsVectorToString( | 234 static std::string CodecSettingsVectorToString( |
| 235 const std::vector<VideoCodecSettings>& codecs); | 235 const std::vector<VideoCodecSettings>& codecs); |
| 236 | 236 |
| 237 // Wrapper for the sender part, this is where the source is connected and | 237 // Wrapper for the sender part. |
| 238 // frames are then converted from cricket frames to webrtc frames. | |
| 239 class WebRtcVideoSendStream | 238 class WebRtcVideoSendStream |
| 240 : public rtc::VideoSinkInterface<cricket::VideoFrame>, | 239 : public rtc::VideoSourceInterface<webrtc::VideoFrame> { |
| 241 public rtc::VideoSourceInterface<webrtc::VideoFrame> { | |
| 242 public: | 240 public: |
| 243 WebRtcVideoSendStream( | 241 WebRtcVideoSendStream( |
| 244 webrtc::Call* call, | 242 webrtc::Call* call, |
| 245 const StreamParams& sp, | 243 const StreamParams& sp, |
| 246 webrtc::VideoSendStream::Config config, | 244 webrtc::VideoSendStream::Config config, |
| 247 const VideoOptions& options, | 245 const VideoOptions& options, |
| 248 WebRtcVideoEncoderFactory* external_encoder_factory, | 246 WebRtcVideoEncoderFactory* external_encoder_factory, |
| 249 bool enable_cpu_overuse_detection, | 247 bool enable_cpu_overuse_detection, |
| 250 int max_bitrate_bps, | 248 int max_bitrate_bps, |
| 251 const rtc::Optional<VideoCodecSettings>& codec_settings, | 249 const rtc::Optional<VideoCodecSettings>& codec_settings, |
| 252 const rtc::Optional<std::vector<webrtc::RtpExtension>>& rtp_extensions, | 250 const rtc::Optional<std::vector<webrtc::RtpExtension>>& rtp_extensions, |
| 253 const VideoSendParameters& send_params); | 251 const VideoSendParameters& send_params); |
| 254 virtual ~WebRtcVideoSendStream(); | 252 virtual ~WebRtcVideoSendStream(); |
| 255 | 253 |
| 256 void SetSendParameters(const ChangedSendParameters& send_params); | 254 void SetSendParameters(const ChangedSendParameters& send_params); |
| 257 bool SetRtpParameters(const webrtc::RtpParameters& parameters); | 255 bool SetRtpParameters(const webrtc::RtpParameters& parameters); |
| 258 webrtc::RtpParameters GetRtpParameters() const; | 256 webrtc::RtpParameters GetRtpParameters() const; |
| 259 | 257 |
| 260 // Implements rtc::VideoSourceInterface<webrtc::VideoFrame>. | 258 // Implements rtc::VideoSourceInterface<webrtc::VideoFrame>. |
| 261 // WebRtcVideoSendStream acts as a source to the webrtc::VideoSendStream | 259 // WebRtcVideoSendStream acts as a source to the webrtc::VideoSendStream |
| 262 // in |stream_|. The reason is that WebRtcVideoSendStream receives | 260 // in |stream_|. This is done to proxy VideoSinkWants from the encoder to |
| 263 // cricket::VideoFrames and forwards webrtc::VideoFrames to |source_|. | 261 // the worker thread. |
| 264 // TODO(perkj, nisse): Refactor WebRtcVideoSendStream to directly connect | 262 void AddOrUpdateSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink, |
| 265 // the camera input |source_| | |
| 266 void AddOrUpdateSink(VideoSinkInterface<webrtc::VideoFrame>* sink, | |
| 267 const rtc::VideoSinkWants& wants) override; | 263 const rtc::VideoSinkWants& wants) override; |
| 268 void RemoveSink(VideoSinkInterface<webrtc::VideoFrame>* sink) override; | 264 void RemoveSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override; |
| 269 | 265 |
| 270 void OnFrame(const cricket::VideoFrame& frame) override; | |
| 271 bool SetVideoSend(bool mute, | 266 bool SetVideoSend(bool mute, |
| 272 const VideoOptions* options, | 267 const VideoOptions* options, |
| 273 rtc::VideoSourceInterface<cricket::VideoFrame>* source); | 268 rtc::VideoSourceInterface<cricket::VideoFrame>* source); |
| 274 | 269 |
| 275 void SetSend(bool send); | 270 void SetSend(bool send); |
| 276 | 271 |
| 277 const std::vector<uint32_t>& GetSsrcs() const; | 272 const std::vector<uint32_t>& GetSsrcs() const; |
| 278 VideoSenderInfo GetVideoSenderInfo(bool log_stats); | 273 VideoSenderInfo GetVideoSenderInfo(bool log_stats); |
| 279 void FillBandwidthEstimationInfo(BandwidthEstimationInfo* bwe_info); | 274 void FillBandwidthEstimationInfo(BandwidthEstimationInfo* bwe_info); |
| 280 | 275 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 303 struct AllocatedEncoder { | 298 struct AllocatedEncoder { |
| 304 AllocatedEncoder(webrtc::VideoEncoder* encoder, | 299 AllocatedEncoder(webrtc::VideoEncoder* encoder, |
| 305 webrtc::VideoCodecType type, | 300 webrtc::VideoCodecType type, |
| 306 bool external); | 301 bool external); |
| 307 webrtc::VideoEncoder* encoder; | 302 webrtc::VideoEncoder* encoder; |
| 308 webrtc::VideoEncoder* external_encoder; | 303 webrtc::VideoEncoder* external_encoder; |
| 309 webrtc::VideoCodecType type; | 304 webrtc::VideoCodecType type; |
| 310 bool external; | 305 bool external; |
| 311 }; | 306 }; |
| 312 | 307 |
| 313 // TODO(perkj): VideoFrameInfo is currently used for sending a black frame | |
| 314 // when the video source is removed. Consider moving that logic to | |
| 315 // VieEncoder or remove it. | |
| 316 struct VideoFrameInfo { | |
| 317 VideoFrameInfo() | |
| 318 : width(0), | |
| 319 height(0), | |
| 320 rotation(webrtc::kVideoRotation_0), | |
| 321 is_texture(false) {} | |
| 322 int width; | |
| 323 int height; | |
| 324 webrtc::VideoRotation rotation; | |
| 325 bool is_texture; | |
| 326 }; | |
| 327 | |
| 328 rtc::scoped_refptr<webrtc::VideoEncoderConfig::EncoderSpecificSettings> | 308 rtc::scoped_refptr<webrtc::VideoEncoderConfig::EncoderSpecificSettings> |
| 329 ConfigureVideoEncoderSettings(const VideoCodec& codec); | 309 ConfigureVideoEncoderSettings(const VideoCodec& codec); |
| 330 AllocatedEncoder CreateVideoEncoder(const VideoCodec& codec); | 310 AllocatedEncoder CreateVideoEncoder(const VideoCodec& codec); |
| 331 void DestroyVideoEncoder(AllocatedEncoder* encoder); | 311 void DestroyVideoEncoder(AllocatedEncoder* encoder); |
| 332 void SetCodec(const VideoCodecSettings& codec); | 312 void SetCodec(const VideoCodecSettings& codec); |
| 333 void RecreateWebRtcStream(); | 313 void RecreateWebRtcStream(); |
| 334 webrtc::VideoEncoderConfig CreateVideoEncoderConfig( | 314 webrtc::VideoEncoderConfig CreateVideoEncoderConfig( |
| 335 const VideoCodec& codec) const; | 315 const VideoCodec& codec) const; |
| 336 void ReconfigureEncoder(); | 316 void ReconfigureEncoder(); |
| 337 bool ValidateRtpParameters(const webrtc::RtpParameters& parameters); | 317 bool ValidateRtpParameters(const webrtc::RtpParameters& parameters); |
| 338 | 318 |
| 339 // Calls Start or Stop according to whether or not |sending_| is true, | 319 // Calls Start or Stop according to whether or not |sending_| is true, |
| 340 // and whether or not the encoding in |rtp_parameters_| is active. | 320 // and whether or not the encoding in |rtp_parameters_| is active. |
| 341 void UpdateSendState(); | 321 void UpdateSendState(); |
| 342 | 322 |
| 343 rtc::ThreadChecker thread_checker_; | 323 rtc::ThreadChecker thread_checker_; |
| 344 rtc::AsyncInvoker invoker_; | 324 rtc::AsyncInvoker invoker_; |
| 345 rtc::Thread* worker_thread_; | 325 rtc::Thread* worker_thread_; |
| 346 const std::vector<uint32_t> ssrcs_ ACCESS_ON(&thread_checker_); | 326 const std::vector<uint32_t> ssrcs_ ACCESS_ON(&thread_checker_); |
| 347 const std::vector<SsrcGroup> ssrc_groups_ ACCESS_ON(&thread_checker_); | 327 const std::vector<SsrcGroup> ssrc_groups_ ACCESS_ON(&thread_checker_); |
| 348 webrtc::Call* const call_; | 328 webrtc::Call* const call_; |
| 349 const bool enable_cpu_overuse_detection_; | 329 const bool enable_cpu_overuse_detection_; |
| 350 rtc::VideoSourceInterface<cricket::VideoFrame>* source_ | 330 rtc::VideoSourceInterface<cricket::VideoFrame>* source_ |
| 351 ACCESS_ON(&thread_checker_); | 331 ACCESS_ON(&thread_checker_); |
| 352 WebRtcVideoEncoderFactory* const external_encoder_factory_ | 332 WebRtcVideoEncoderFactory* const external_encoder_factory_ |
| 353 ACCESS_ON(&thread_checker_); | 333 ACCESS_ON(&thread_checker_); |
| 354 | 334 |
| 355 rtc::CriticalSection lock_; | |
| 356 webrtc::VideoSendStream* stream_ ACCESS_ON(&thread_checker_); | 335 webrtc::VideoSendStream* stream_ ACCESS_ON(&thread_checker_); |
| 357 rtc::VideoSinkInterface<webrtc::VideoFrame>* encoder_sink_ | 336 rtc::VideoSinkInterface<webrtc::VideoFrame>* encoder_sink_ |
| 358 GUARDED_BY(lock_); | 337 ACCESS_ON(&thread_checker_); |
| 359 // Contains settings that are the same for all streams in the MediaChannel, | 338 // Contains settings that are the same for all streams in the MediaChannel, |
| 360 // such as codecs, header extensions, and the global bitrate limit for the | 339 // such as codecs, header extensions, and the global bitrate limit for the |
| 361 // entire channel. | 340 // entire channel. |
| 362 VideoSendStreamParameters parameters_ ACCESS_ON(&thread_checker_); | 341 VideoSendStreamParameters parameters_ ACCESS_ON(&thread_checker_); |
| 363 // Contains settings that are unique for each stream, such as max_bitrate. | 342 // Contains settings that are unique for each stream, such as max_bitrate. |
| 364 // Does *not* contain codecs, however. | 343 // Does *not* contain codecs, however. |
| 365 // TODO(skvlad): Move ssrcs_ and ssrc_groups_ into rtp_parameters_. | 344 // TODO(skvlad): Move ssrcs_ and ssrc_groups_ into rtp_parameters_. |
| 366 // TODO(skvlad): Combine parameters_ and rtp_parameters_ once we have only | 345 // TODO(skvlad): Combine parameters_ and rtp_parameters_ once we have only |
| 367 // one stream per MediaChannel. | 346 // one stream per MediaChannel. |
| 368 webrtc::RtpParameters rtp_parameters_ ACCESS_ON(&thread_checker_); | 347 webrtc::RtpParameters rtp_parameters_ ACCESS_ON(&thread_checker_); |
| 369 AllocatedEncoder allocated_encoder_ ACCESS_ON(&thread_checker_); | 348 AllocatedEncoder allocated_encoder_ ACCESS_ON(&thread_checker_); |
| 370 VideoFrameInfo last_frame_info_ GUARDED_BY(lock_); | |
| 371 | 349 |
| 372 bool sending_ ACCESS_ON(&thread_checker_); | 350 bool sending_ ACCESS_ON(&thread_checker_); |
| 373 | |
| 374 // The timestamp of the last frame received | |
| 375 // Used to generate timestamp for the black frame when source is removed | |
| 376 int64_t last_frame_timestamp_us_ GUARDED_BY(lock_); | |
| 377 }; | 351 }; |
| 378 | 352 |
| 379 // Wrapper for the receiver part, contains configs etc. that are needed to | 353 // Wrapper for the receiver part, contains configs etc. that are needed to |
| 380 // reconstruct the underlying VideoReceiveStream. Also serves as a wrapper | 354 // reconstruct the underlying VideoReceiveStream. Also serves as a wrapper |
| 381 // between rtc::VideoSinkInterface<webrtc::VideoFrame> and | 355 // between rtc::VideoSinkInterface<webrtc::VideoFrame> and |
| 382 // rtc::VideoSinkInterface<cricket::VideoFrame>. | 356 // rtc::VideoSinkInterface<cricket::VideoFrame>. |
| 383 class WebRtcVideoReceiveStream | 357 class WebRtcVideoReceiveStream |
| 384 : public rtc::VideoSinkInterface<webrtc::VideoFrame> { | 358 : public rtc::VideoSinkInterface<webrtc::VideoFrame> { |
| 385 public: | 359 public: |
| 386 WebRtcVideoReceiveStream( | 360 WebRtcVideoReceiveStream( |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 VideoSendParameters send_params_; | 491 VideoSendParameters send_params_; |
| 518 VideoOptions default_send_options_; | 492 VideoOptions default_send_options_; |
| 519 VideoRecvParameters recv_params_; | 493 VideoRecvParameters recv_params_; |
| 520 bool red_disabled_by_remote_side_; | 494 bool red_disabled_by_remote_side_; |
| 521 int64_t last_stats_log_ms_; | 495 int64_t last_stats_log_ms_; |
| 522 }; | 496 }; |
| 523 | 497 |
| 524 } // namespace cricket | 498 } // namespace cricket |
| 525 | 499 |
| 526 #endif // WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE2_H_ | 500 #endif // WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE2_H_ |
| OLD | NEW |