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

Side by Side Diff: webrtc/video/vie_encoder.cc

Issue 2936393002: Add cropping to VIEEncoder to match simulcast streams resolution (Closed)
Patch Set: Created 3 years, 6 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) 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 <numeric> 15 #include <numeric>
16 #include <utility> 16 #include <utility>
17 17
18 #include "webrtc/api/video/i420_buffer.h"
18 #include "webrtc/base/arraysize.h" 19 #include "webrtc/base/arraysize.h"
19 #include "webrtc/base/checks.h" 20 #include "webrtc/base/checks.h"
20 #include "webrtc/base/location.h" 21 #include "webrtc/base/location.h"
21 #include "webrtc/base/logging.h" 22 #include "webrtc/base/logging.h"
22 #include "webrtc/base/timeutils.h" 23 #include "webrtc/base/timeutils.h"
23 #include "webrtc/base/trace_event.h" 24 #include "webrtc/base/trace_event.h"
24 #include "webrtc/common_video/include/video_bitrate_allocator.h" 25 #include "webrtc/common_video/include/video_bitrate_allocator.h"
25 #include "webrtc/common_video/include/video_frame.h" 26 #include "webrtc/common_video/include/video_frame.h"
26 #include "webrtc/modules/pacing/paced_sender.h" 27 #include "webrtc/modules/pacing/paced_sender.h"
27 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" 28 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h"
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 } 569 }
569 } 570 }
570 571
571 void ViEEncoder::ReconfigureEncoder() { 572 void ViEEncoder::ReconfigureEncoder() {
572 RTC_DCHECK_RUN_ON(&encoder_queue_); 573 RTC_DCHECK_RUN_ON(&encoder_queue_);
573 RTC_DCHECK(pending_encoder_reconfiguration_); 574 RTC_DCHECK(pending_encoder_reconfiguration_);
574 std::vector<VideoStream> streams = 575 std::vector<VideoStream> streams =
575 encoder_config_.video_stream_factory->CreateEncoderStreams( 576 encoder_config_.video_stream_factory->CreateEncoderStreams(
576 last_frame_info_->width, last_frame_info_->height, encoder_config_); 577 last_frame_info_->width, last_frame_info_->height, encoder_config_);
577 578
579 // Stream dimensions may be not equal to given because of a simulcast
580 // restrictions.
581 int highest_stream_width = static_cast<int>(streams.back().width);
582 int highest_stream_height = static_cast<int>(streams.back().height);
583 // Dimension may be reduced to be, e.g. divisible by 4.
584 RTC_CHECK_GE(last_frame_info_->width, highest_stream_width);
585 RTC_CHECK_GE(last_frame_info_->height, highest_stream_height);
586 crop_width_ = last_frame_info_->width - highest_stream_width;
587 crop_height_ = last_frame_info_->height - highest_stream_height;
sprang_webrtc 2017/06/16 08:57:23 Hm, I'm not always cropping here is a good idea..
ilnik 2017/06/16 11:22:49 Before, that case wouldn't work in the same way, d
sprang_webrtc 2017/06/16 11:58:47 Yeah, maybe that's a working stopgap solution. Cro
ilnik 2017/06/16 12:53:30 Done.
588
sprang_webrtc 2017/06/16 08:57:23 The full stack test is great, but would probably b
ilnik 2017/06/16 11:22:48 Done.
578 VideoCodec codec; 589 VideoCodec codec;
579 if (!VideoCodecInitializer::SetupCodec(encoder_config_, settings_, streams, 590 if (!VideoCodecInitializer::SetupCodec(encoder_config_, settings_, streams,
580 nack_enabled_, &codec, 591 nack_enabled_, &codec,
581 &rate_allocator_)) { 592 &rate_allocator_)) {
582 LOG(LS_ERROR) << "Failed to create encoder configuration."; 593 LOG(LS_ERROR) << "Failed to create encoder configuration.";
583 } 594 }
584 595
585 codec.startBitrate = 596 codec.startBitrate =
586 std::max(encoder_start_bitrate_bps_ / 1000, codec.minBitrate); 597 std::max(encoder_start_bitrate_bps_ / 1000, codec.minBitrate);
587 codec.startBitrate = std::min(codec.startBitrate, codec.maxBitrate); 598 codec.startBitrate = std::min(codec.startBitrate, codec.maxBitrate);
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 bitrate_observer_); 774 bitrate_observer_);
764 } 775 }
765 last_parameters_update_ms_.emplace(now_ms); 776 last_parameters_update_ms_.emplace(now_ms);
766 777
767 if (EncoderPaused()) { 778 if (EncoderPaused()) {
768 TraceFrameDropStart(); 779 TraceFrameDropStart();
769 return; 780 return;
770 } 781 }
771 TraceFrameDropEnd(); 782 TraceFrameDropEnd();
772 783
784 VideoFrame out_frame(video_frame);
785 // Crop frame if needed.
786 if (crop_width_ > 0 || crop_height_ > 0) {
787 int cropped_width = video_frame.width() - crop_width_;
788 int cropped_height = video_frame.height() - crop_height_;
789 rtc::scoped_refptr<I420Buffer> cropped_buffer =
790 I420Buffer::Create(cropped_width, cropped_height);
791 cropped_buffer->CropAndScaleFrom(
792 *video_frame.video_frame_buffer()->ToI420(), crop_width_ / 2,
793 crop_height_ / 2, cropped_width, cropped_height);
794 out_frame =
795 VideoFrame(cropped_buffer, video_frame.timestamp(),
796 video_frame.render_time_ms(), video_frame.rotation());
797 }
798
773 TRACE_EVENT_ASYNC_STEP0("webrtc", "Video", video_frame.render_time_ms(), 799 TRACE_EVENT_ASYNC_STEP0("webrtc", "Video", video_frame.render_time_ms(),
774 "Encode"); 800 "Encode");
775 801
776 overuse_detector_->FrameCaptured(video_frame, time_when_posted_us); 802 overuse_detector_->FrameCaptured(out_frame, time_when_posted_us);
777 803
778 video_sender_.AddVideoFrame(video_frame, nullptr); 804 video_sender_.AddVideoFrame(out_frame, nullptr);
779 } 805 }
780 806
781 void ViEEncoder::SendKeyFrame() { 807 void ViEEncoder::SendKeyFrame() {
782 if (!encoder_queue_.IsCurrent()) { 808 if (!encoder_queue_.IsCurrent()) {
783 encoder_queue_.PostTask([this] { SendKeyFrame(); }); 809 encoder_queue_.PostTask([this] { SendKeyFrame(); });
784 return; 810 return;
785 } 811 }
786 RTC_DCHECK_RUN_ON(&encoder_queue_); 812 RTC_DCHECK_RUN_ON(&encoder_queue_);
787 video_sender_.IntraFrameRequest(0); 813 video_sender_.IntraFrameRequest(0);
788 } 814 }
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
1195 std::string ViEEncoder::AdaptCounter::ToString( 1221 std::string ViEEncoder::AdaptCounter::ToString(
1196 const std::vector<int>& counters) const { 1222 const std::vector<int>& counters) const {
1197 std::stringstream ss; 1223 std::stringstream ss;
1198 for (size_t reason = 0; reason < kScaleReasonSize; ++reason) { 1224 for (size_t reason = 0; reason < kScaleReasonSize; ++reason) {
1199 ss << (reason ? " cpu" : "quality") << ":" << counters[reason]; 1225 ss << (reason ? " cpu" : "quality") << ":" << counters[reason];
1200 } 1226 }
1201 return ss.str(); 1227 return ss.str();
1202 } 1228 }
1203 1229
1204 } // namespace webrtc 1230 } // namespace webrtc
OLDNEW
« webrtc/video/video_quality_test.cc ('K') | « webrtc/video/vie_encoder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698