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 #include "webrtc/video/vie_encoder.h" | 11 #include "webrtc/video/vie_encoder.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <limits> | 14 #include <limits> |
| 15 #include <utility> |
15 | 16 |
16 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
17 #include "webrtc/base/logging.h" | 18 #include "webrtc/base/logging.h" |
18 #include "webrtc/base/trace_event.h" | 19 #include "webrtc/base/trace_event.h" |
19 #include "webrtc/base/timeutils.h" | 20 #include "webrtc/base/timeutils.h" |
20 #include "webrtc/modules/pacing/paced_sender.h" | 21 #include "webrtc/modules/pacing/paced_sender.h" |
21 #include "webrtc/modules/video_coding/include/video_coding.h" | 22 #include "webrtc/modules/video_coding/include/video_coding.h" |
22 #include "webrtc/modules/video_coding/include/video_coding_defines.h" | 23 #include "webrtc/modules/video_coding/include/video_coding_defines.h" |
23 #include "webrtc/video/overuse_frame_detector.h" | 24 #include "webrtc/video/overuse_frame_detector.h" |
24 #include "webrtc/video/send_statistics_proxy.h" | 25 #include "webrtc/video/send_statistics_proxy.h" |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 void ViEEncoder::DeRegisterProcessThread() { | 361 void ViEEncoder::DeRegisterProcessThread() { |
361 RTC_DCHECK_RUN_ON(&thread_checker_); | 362 RTC_DCHECK_RUN_ON(&thread_checker_); |
362 module_process_thread_->DeRegisterModule(&video_sender_); | 363 module_process_thread_->DeRegisterModule(&video_sender_); |
363 } | 364 } |
364 | 365 |
365 void ViEEncoder::SetSource(rtc::VideoSourceInterface<VideoFrame>* source) { | 366 void ViEEncoder::SetSource(rtc::VideoSourceInterface<VideoFrame>* source) { |
366 RTC_DCHECK_RUN_ON(&thread_checker_); | 367 RTC_DCHECK_RUN_ON(&thread_checker_); |
367 source_proxy_->SetSource(source); | 368 source_proxy_->SetSource(source); |
368 } | 369 } |
369 | 370 |
370 void ViEEncoder::SetSink(EncodedImageCallback* sink) { | 371 void ViEEncoder::SetSink(EncoderSink* sink) { |
371 encoder_queue_.PostTask([this, sink] { | 372 encoder_queue_.PostTask([this, sink] { |
372 RTC_DCHECK_RUN_ON(&encoder_queue_); | 373 RTC_DCHECK_RUN_ON(&encoder_queue_); |
373 sink_ = sink; | 374 sink_ = sink; |
374 }); | 375 }); |
375 } | 376 } |
376 | 377 |
377 void ViEEncoder::SetStartBitrate(int start_bitrate_bps) { | 378 void ViEEncoder::SetStartBitrate(int start_bitrate_bps) { |
378 encoder_queue_.PostTask([this, start_bitrate_bps] { | 379 encoder_queue_.PostTask([this, start_bitrate_bps] { |
379 RTC_DCHECK_RUN_ON(&encoder_queue_); | 380 RTC_DCHECK_RUN_ON(&encoder_queue_); |
380 encoder_start_bitrate_bps_ = start_bitrate_bps; | 381 encoder_start_bitrate_bps_ = start_bitrate_bps; |
381 }); | 382 }); |
382 } | 383 } |
383 | 384 |
384 void ViEEncoder::ConfigureEncoder(const VideoEncoderConfig& config, | 385 void ViEEncoder::ConfigureEncoder(VideoEncoderConfig config, |
385 size_t max_data_payload_length) { | 386 size_t max_data_payload_length) { |
386 VideoCodec video_codec = VideoEncoderConfigToVideoCodec( | 387 VideoCodec video_codec = VideoEncoderConfigToVideoCodec( |
387 config, settings_.payload_name, settings_.payload_type); | 388 config, settings_.payload_name, settings_.payload_type); |
388 encoder_queue_.PostTask([this, video_codec, max_data_payload_length] { | 389 LOG(LS_INFO) << "ConfigureEncoder: " << config.ToString(); |
389 ConfigureEncoderInternal(video_codec, max_data_payload_length); | 390 std::vector<VideoStream> stream = std::move(config.streams); |
| 391 int min_transmit_bitrate = config.min_transmit_bitrate_bps; |
| 392 encoder_queue_.PostTask([this, video_codec, max_data_payload_length, stream, |
| 393 min_transmit_bitrate] { |
| 394 ConfigureEncoderInternal(video_codec, max_data_payload_length, stream, |
| 395 min_transmit_bitrate); |
390 }); | 396 }); |
391 return; | 397 return; |
392 } | 398 } |
393 | 399 |
394 void ViEEncoder::ConfigureEncoderInternal(const VideoCodec& video_codec, | 400 void ViEEncoder::ConfigureEncoderInternal(const VideoCodec& video_codec, |
395 size_t max_data_payload_length) { | 401 size_t max_data_payload_length, |
| 402 std::vector<VideoStream> stream, |
| 403 int min_transmit_bitrate) { |
396 RTC_DCHECK_RUN_ON(&encoder_queue_); | 404 RTC_DCHECK_RUN_ON(&encoder_queue_); |
397 RTC_DCHECK_GE(encoder_start_bitrate_bps_, 0); | 405 RTC_DCHECK_GE(encoder_start_bitrate_bps_, 0); |
398 RTC_DCHECK(sink_); | 406 RTC_DCHECK(sink_); |
399 | 407 |
400 // Setting target width and height for VPM. | 408 // Setting target width and height for VPM. |
401 RTC_CHECK_EQ(VPM_OK, | 409 RTC_CHECK_EQ(VPM_OK, |
402 vp_->SetTargetResolution(video_codec.width, video_codec.height, | 410 vp_->SetTargetResolution(video_codec.width, video_codec.height, |
403 video_codec.maxFramerate)); | 411 video_codec.maxFramerate)); |
404 | 412 |
405 encoder_config_ = video_codec; | 413 encoder_config_ = video_codec; |
(...skipping 21 matching lines...) Expand all Loading... |
427 break; | 435 break; |
428 case kScreensharing: | 436 case kScreensharing: |
429 content_type = VideoEncoderConfig::ContentType::kScreen; | 437 content_type = VideoEncoderConfig::ContentType::kScreen; |
430 break; | 438 break; |
431 default: | 439 default: |
432 RTC_NOTREACHED(); | 440 RTC_NOTREACHED(); |
433 break; | 441 break; |
434 } | 442 } |
435 stats_proxy_->SetContentType(content_type); | 443 stats_proxy_->SetContentType(content_type); |
436 } | 444 } |
| 445 |
| 446 sink_->OnEncoderConfigurationChanged(stream, min_transmit_bitrate); |
437 } | 447 } |
438 | 448 |
439 void ViEEncoder::OnFrame(const VideoFrame& video_frame) { | 449 void ViEEncoder::OnFrame(const VideoFrame& video_frame) { |
440 RTC_DCHECK_RUNS_SERIALIZED(&incoming_frame_race_checker_); | 450 RTC_DCHECK_RUNS_SERIALIZED(&incoming_frame_race_checker_); |
441 stats_proxy_->OnIncomingFrame(video_frame.width(), video_frame.height()); | 451 stats_proxy_->OnIncomingFrame(video_frame.width(), video_frame.height()); |
442 | 452 |
443 VideoFrame incoming_frame = video_frame; | 453 VideoFrame incoming_frame = video_frame; |
444 | 454 |
445 // Local time in webrtc time base. | 455 // Local time in webrtc time base. |
446 int64_t current_time = clock_->TimeInMilliseconds(); | 456 int64_t current_time = clock_->TimeInMilliseconds(); |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 load_observer_->OnLoadUpdate(LoadObserver::kOveruse); | 681 load_observer_->OnLoadUpdate(LoadObserver::kOveruse); |
672 } | 682 } |
673 | 683 |
674 void ViEEncoder::NormalUsage() { | 684 void ViEEncoder::NormalUsage() { |
675 RTC_DCHECK_RUN_ON(&encoder_queue_); | 685 RTC_DCHECK_RUN_ON(&encoder_queue_); |
676 if (load_observer_) | 686 if (load_observer_) |
677 load_observer_->OnLoadUpdate(LoadObserver::kUnderuse); | 687 load_observer_->OnLoadUpdate(LoadObserver::kUnderuse); |
678 } | 688 } |
679 | 689 |
680 } // namespace webrtc | 690 } // namespace webrtc |
OLD | NEW |