|
|
Created:
4 years, 2 months ago by kthelgason Modified:
4 years ago Reviewers:
magjed_webrtc, sprang_webrtc, perkj_webrtc, stefan-webrtc CC:
interface-changes_webrtc.org, mflodman, niklas.enbom, peah-webrtc, perkj_webrtc, qiang.lu, tterriberry_mozilla.com, video-team_agora.io, webrtc-reviews_webrtc.org, yujie_mao (webrtc), zhengzhonghou_agora.io Target Ref:
refs/pending/heads/master Project:
webrtc Visibility:
Public. |
DescriptionMove usage of QualityScaler to ViEEncoder.
This brings QualityScaler much more in line with OveruseFrameDetector.
The two classes are conceptually similar, and should be used in the
same way. The biggest changes in this CL are:
- Quality scaling is now only done in ViEEncoder and not in each
encoder implementation separately.
- QualityScaler now checks the average QP asynchronously, instead of
having to be polled on each frame.
- QualityScaler is no longer responsible for actually scaling the frames,
but has a callback to ViEEncoder that it uses to express it's desire
for lower resolution.
BUG=webrtc:6495
Committed: https://crrev.com/876222f77dfc640c852d5bb14f0aacf0f74e5690
Cr-Commit-Position: refs/heads/master@{#15286}
Patch Set 1 #
Total comments: 3
Patch Set 2 : fix strange bug #Patch Set 3 : delete log statement #Patch Set 4 : re-add QP parsing to the MediaCodec implementation #Patch Set 5 : fix videotoolbox overridden QP thresholds #
Total comments: 27
Patch Set 6 : Code review comments #
Total comments: 18
Patch Set 7 : code review #Patch Set 8 : Make no scaling the default #Patch Set 9 : Add back important stuff for videotoolbox encoder #Patch Set 10 : implement getQPThresholds for various wrappers #
Total comments: 14
Patch Set 11 : Add back some logic to disable scaling in some cases #Patch Set 12 : Refactor QualityScaler::Settings #Patch Set 13 : tie qualityscaler lifetime to vieencoder #Patch Set 14 : Stats now properly reflect scaling status #
Total comments: 23
Patch Set 15 : Code review #
Total comments: 57
Patch Set 16 : Code review round II #Patch Set 17 : Rebase onto master #Patch Set 18 : rebase more #Patch Set 19 : remove nonexistant include #Patch Set 20 : Fix rebase-introduced errors #Patch Set 21 : rebase even more #Patch Set 22 : fix build errors #Patch Set 23 : Fix failing tests #Patch Set 24 : Fix flaky test #
Total comments: 30
Patch Set 25 : Code review #Patch Set 26 : rebase #
Total comments: 25
Patch Set 27 : Code review #Patch Set 28 : code review and rebase #Patch Set 29 : fix android build #
Total comments: 3
Patch Set 30 : Don't scale if source does not support it #Patch Set 31 : rebase and fix issues #Patch Set 32 : prevent data race #
Total comments: 49
Patch Set 33 : Code review #
Total comments: 4
Patch Set 34 : Actually test something sensible #
Total comments: 2
Patch Set 35 : Report dropped frames to ViEEncoder #
Total comments: 4
Patch Set 36 : Code review nit #Patch Set 37 : rebase #
Created: 4 years ago
Messages
Total messages: 113 (61 generated)
https://codereview.webrtc.org/2398963003/diff/1/webrtc/modules/video_coding/u... File webrtc/modules/video_coding/utility/quality_scaler.cc (left): https://codereview.webrtc.org/2398963003/diff/1/webrtc/modules/video_coding/u... webrtc/modules/video_coding/utility/quality_scaler.cc:31: static const int kMeasureSecondsDownscale = 5; Note that there is a behaviour change here. We no longer have different intervals for scaling up and down. This seemed needlessly complex. https://codereview.webrtc.org/2398963003/diff/1/webrtc/modules/video_coding/u... File webrtc/modules/video_coding/utility/quality_scaler.h (right): https://codereview.webrtc.org/2398963003/diff/1/webrtc/modules/video_coding/u... webrtc/modules/video_coding/utility/quality_scaler.h:23: class ScalingInterface { It may make sense to place this somewhere else. Soliciting feedback! https://codereview.webrtc.org/2398963003/diff/1/webrtc/video/overuse_frame_de... File webrtc/video/overuse_frame_detector.h (left): https://codereview.webrtc.org/2398963003/diff/1/webrtc/video/overuse_frame_de... webrtc/video/overuse_frame_detector.h:32: class CpuOveruseObserver { This has been replaced by ScalingInterface in //webrtc/video_coding/utility/quality_scaler.h
Description was changed from ========== Move usage of QualityScaler to ViEEncoder. This brings QualityScaler much more in line with OveruseFrameDetector. The two classes are conceptually similar, and should be used in the same way. The biggest changes in this CL are: - Quality scaling is now only done in ViEEncoder and not in each encoder implementation separately. - QualityScaler now checks the average QP asynchronously, instead of having to be polled on each frame. - QualityScaler is no longer responsible for actually scaling the frames, but has a callback to ViEEncoder that it uses to express it's desire for lower resolution. TODO: Disable quality scaling for VP9 BUG=webrtc:6495 ========== to ========== Move usage of QualityScaler to ViEEncoder. This brings QualityScaler much more in line with OveruseFrameDetector. The two classes are conceptually similar, and should be used in the same way. The biggest changes in this CL are: - Quality scaling is now only done in ViEEncoder and not in each encoder implementation separately. - QualityScaler now checks the average QP asynchronously, instead of having to be polled on each frame. - QualityScaler is no longer responsible for actually scaling the frames, but has a callback to ViEEncoder that it uses to express it's desire for lower resolution. TODO: Disable quality scaling for VP9 BUG=webrtc:6495 ==========
kthelgason@webrtc.org changed reviewers: + magjed@webrtc.org, perkj@webrtc.org
https://codereview.webrtc.org/2398963003/diff/80001/webrtc/modules/video_codi... File webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.h (left): https://codereview.webrtc.org/2398963003/diff/80001/webrtc/modules/video_codi... webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.h:91: bool enable_scaling_; TODO: remove
https://codereview.webrtc.org/2398963003/diff/80001/webrtc/api/android/jni/an... File webrtc/api/android/jni/androidmediaencoder_jni.cc (left): https://codereview.webrtc.org/2398963003/diff/80001/webrtc/api/android/jni/an... webrtc/api/android/jni/androidmediaencoder_jni.cc:990: image->adapt_reason_.quality_resolution_downscales = does this cl take stats into account? https://codereview.webrtc.org/2398963003/diff/80001/webrtc/modules/video_codi... File webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.h (right): https://codereview.webrtc.org/2398963003/diff/80001/webrtc/modules/video_codi... webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.h:33: using QPThresholds = VideoEncoder::QPThresholds; nit: prefer VideoEncoder::QPThresholds on line 71. Avoid "using" in a large scope. You may if you wish have using inside the class definitions but not at top level in a header. https://codereview.webrtc.org/2398963003/diff/80001/webrtc/modules/video_codi... File webrtc/modules/video_coding/utility/quality_scaler.cc (right): https://codereview.webrtc.org/2398963003/diff/80001/webrtc/modules/video_codi... webrtc/modules/video_coding/utility/quality_scaler.cc:47: RTC_DCHECK(scaler != nullptr); nit- this dcheck is fine, but since you do scaler_-> below it does not really add anything. https://codereview.webrtc.org/2398963003/diff/80001/webrtc/modules/video_codi... webrtc/modules/video_coding/utility/quality_scaler.cc:55: void Stop() { stop_ = true; } stop is not initialized in the ctor. https://codereview.webrtc.org/2398963003/diff/80001/webrtc/modules/video_codi... webrtc/modules/video_coding/utility/quality_scaler.cc:64: Add a SequencedTaskChecker to check that Stop is called on the same tq as Run https://codereview.webrtc.org/2398963003/diff/80001/webrtc/modules/video_codi... File webrtc/modules/video_coding/utility/quality_scaler.h (right): https://codereview.webrtc.org/2398963003/diff/80001/webrtc/modules/video_codi... webrtc/modules/video_coding/utility/quality_scaler.h:23: class ScalingInterface { This type of interfaces are very often called Observer in the webrtc code base. You can but it inside QualityScaler if you want like class QualityScaler class Observer {... } or in the cpu adapter case it is called CpuOveruseObserver https://codereview.webrtc.org/2398963003/diff/80001/webrtc/modules/video_codi... webrtc/modules/video_coding/utility/quality_scaler.h:25: // Called as soon as an overuse is detected. overuse? Can this be rephrased. https://codereview.webrtc.org/2398963003/diff/80001/webrtc/modules/video_codi... webrtc/modules/video_coding/utility/quality_scaler.h:34: class QualityScaler { Can you document how this class is supposed? https://codereview.webrtc.org/2398963003/diff/80001/webrtc/modules/video_codi... webrtc/modules/video_coding/utility/quality_scaler.h:49: void ReportFramerate(int framerate); Document the public methods. Do they all need to be public? Do we need two Init methods? https://codereview.webrtc.org/2398963003/diff/80001/webrtc/modules/video_codi... webrtc/modules/video_coding/utility/quality_scaler.h:66: bool fast_rampup_; please use GUARDED_BY(&task_checker_) on all members. https://codereview.webrtc.org/2398963003/diff/80001/webrtc/modules/video_codi... File webrtc/modules/video_coding/utility/quality_scaler_unittest.cc (right): https://codereview.webrtc.org/2398963003/diff/80001/webrtc/modules/video_codi... webrtc/modules/video_coding/utility/quality_scaler_unittest.cc:82: qs_->ReportDroppedFrame(); Didn't you remove use of ReportDroppedFrame? https://codereview.webrtc.org/2398963003/diff/80001/webrtc/video/overuse_fram... File webrtc/video/overuse_frame_detector.cc (right): https://codereview.webrtc.org/2398963003/diff/80001/webrtc/video/overuse_fram... webrtc/video/overuse_frame_detector.cc:207: ScalingInterface* observer, ? https://codereview.webrtc.org/2398963003/diff/80001/webrtc/video/vie_encoder.cc File webrtc/video/vie_encoder.cc (right): https://codereview.webrtc.org/2398963003/diff/80001/webrtc/video/vie_encoder.... webrtc/video/vie_encoder.cc:240: vie_encoder_->quality_scaler_.ReportDroppedFrame(); note- this is not the same ReportDroppedFrame as previously. This are frames dropped in the capture pipeline before beeing send to the encoder because the encoder is not fast enough. ReportDroppedFrame was used when an encoder dropped a frame because either bitrate was not enough, or probably also in the VideoSender when the encoder used a too high bitrate. https://codereview.webrtc.org/2398963003/diff/80001/webrtc/video/vie_encoder.... webrtc/video/vie_encoder.cc:514: if (thresholds) nit: {} https://codereview.webrtc.org/2398963003/diff/80001/webrtc/video/vie_encoder.... webrtc/video/vie_encoder.cc:518: quality_scaler_.Init(this, codec_type_, streams[0].max_framerate); {} https://codereview.webrtc.org/2398963003/diff/80001/webrtc/video/vie_encoder.... webrtc/video/vie_encoder.cc:786: if (cpu_restricted_counter_ >= kMaxCpuDowngrades) { This is a behavior change. Previously we did not adapt down more than kMaxCpuDowngrades due to CPU adaptation. But with this change we will not adapt down more than kMaxCpuDowngrades regardless if it is CPU adaptation or quality. Also, what happens in ScaleUp if the CPU adapter requests scaling up but the quality scaler does not want that due to that quality is too bad. I think you need to keep two separate sets of callbacks to VieEncoder so that you can treat them separately and take a combined decision. Ie, do not adapt up until both CPU and Quality is ok with that.
https://codereview.webrtc.org/2398963003/diff/80001/webrtc/api/android/jni/an... File webrtc/api/android/jni/androidmediaencoder_jni.cc (left): https://codereview.webrtc.org/2398963003/diff/80001/webrtc/api/android/jni/an... webrtc/api/android/jni/androidmediaencoder_jni.cc:990: image->adapt_reason_.quality_resolution_downscales = On 2016/10/07 07:41:15, perkj_webrtc wrote: > does this cl take stats into account? Nope, that's still to be addressed. In any case this has to be set at the ViEEncoder layer now. https://codereview.webrtc.org/2398963003/diff/80001/webrtc/modules/video_codi... File webrtc/modules/video_coding/utility/quality_scaler.cc (right): https://codereview.webrtc.org/2398963003/diff/80001/webrtc/modules/video_codi... webrtc/modules/video_coding/utility/quality_scaler.cc:47: RTC_DCHECK(scaler != nullptr); On 2016/10/07 07:41:15, perkj_webrtc wrote: > nit- this dcheck is fine, but since you do scaler_-> below it does not really > add anything. Acknowledged. https://codereview.webrtc.org/2398963003/diff/80001/webrtc/modules/video_codi... webrtc/modules/video_coding/utility/quality_scaler.cc:55: void Stop() { stop_ = true; } On 2016/10/07 07:41:15, perkj_webrtc wrote: > stop is not initialized in the ctor. Acknowledged. https://codereview.webrtc.org/2398963003/diff/80001/webrtc/modules/video_codi... webrtc/modules/video_coding/utility/quality_scaler.cc:64: On 2016/10/07 07:41:15, perkj_webrtc wrote: > Add a SequencedTaskChecker to check that Stop is called on the same tq as Run Acknowledged. https://codereview.webrtc.org/2398963003/diff/80001/webrtc/modules/video_codi... File webrtc/modules/video_coding/utility/quality_scaler.h (right): https://codereview.webrtc.org/2398963003/diff/80001/webrtc/modules/video_codi... webrtc/modules/video_coding/utility/quality_scaler.h:23: class ScalingInterface { On 2016/10/07 07:41:15, perkj_webrtc wrote: > This type of interfaces are very often called Observer in the webrtc code base. > > You can but it inside QualityScaler if you want like > > class QualityScaler > class Observer {... > } > > > or in the cpu adapter case it is called CpuOveruseObserver This replaces CpuOveruseObserver. The same interface is now used for both. I agree that it could be better named, and I kind of want to move this somewhere else. Suggestions welcome! https://codereview.webrtc.org/2398963003/diff/80001/webrtc/modules/video_codi... webrtc/modules/video_coding/utility/quality_scaler.h:25: // Called as soon as an overuse is detected. On 2016/10/07 07:41:15, perkj_webrtc wrote: > overuse? Can this be rephrased. Acknowledged. https://codereview.webrtc.org/2398963003/diff/80001/webrtc/modules/video_codi... webrtc/modules/video_coding/utility/quality_scaler.h:49: void ReportFramerate(int framerate); On 2016/10/07 07:41:15, perkj_webrtc wrote: > Document the public methods. > Do they all need to be public? > Do we need two Init methods? Acknowledged. https://codereview.webrtc.org/2398963003/diff/80001/webrtc/modules/video_codi... webrtc/modules/video_coding/utility/quality_scaler.h:66: bool fast_rampup_; On 2016/10/07 07:41:16, perkj_webrtc wrote: > please use GUARDED_BY(&task_checker_) on all members. Acknowledged. https://codereview.webrtc.org/2398963003/diff/80001/webrtc/modules/video_codi... File webrtc/modules/video_coding/utility/quality_scaler_unittest.cc (right): https://codereview.webrtc.org/2398963003/diff/80001/webrtc/modules/video_codi... webrtc/modules/video_coding/utility/quality_scaler_unittest.cc:82: qs_->ReportDroppedFrame(); On 2016/10/07 07:41:16, perkj_webrtc wrote: > Didn't you remove use of ReportDroppedFrame? No, at least that was not the intention. https://codereview.webrtc.org/2398963003/diff/80001/webrtc/video/vie_encoder.cc File webrtc/video/vie_encoder.cc (right): https://codereview.webrtc.org/2398963003/diff/80001/webrtc/video/vie_encoder.... webrtc/video/vie_encoder.cc:240: vie_encoder_->quality_scaler_.ReportDroppedFrame(); On 2016/10/07 07:41:16, perkj_webrtc wrote: > note- this is not the same ReportDroppedFrame as previously. This are frames > dropped in the capture pipeline before beeing send to the encoder because the > encoder is not fast enough. > > ReportDroppedFrame was used when an encoder dropped a frame because either > bitrate was not enough, or probably also in the VideoSender when the encoder > used a too high bitrate. Ok, that's good to know. At what point does ViEEncoder know that an encoder has dropped a frame?
Patchset #6 (id:100001) has been deleted
First pass. It looks like this will be a nice cleanup! https://codereview.webrtc.org/2398963003/diff/120001/webrtc/api/android/jni/a... File webrtc/api/android/jni/androidmediaencoder_jni.cc (left): https://codereview.webrtc.org/2398963003/diff/120001/webrtc/api/android/jni/a... webrtc/api/android/jni/androidmediaencoder_jni.cc:264: bool scale_; I don't think you can/should remove |scale_| in this CL? I think you should keep it and set it as we currently do and this class should implement GetQPThresholds() like this: rtc::Optional<QPThresholds> GetQPThresholds() override { return scale_ ? QPThresholds::Default(codecType_) : rtc::Optional<QPThresholds>(); } https://codereview.webrtc.org/2398963003/diff/120001/webrtc/modules/video_cod... File webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.cc (left): https://codereview.webrtc.org/2398963003/diff/120001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.cc:290: quality_scaler_.OnEncodeFrame(input_frame.width(), input_frame.height()); Can this class handle that the resolution of |input_frame| changes dynamically? Maybe you need the same same logic as below for detecting resolution changes? https://codereview.webrtc.org/2398963003/diff/120001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.cc:375: int qp = -1; You still need to parse the qp and put it in encoded_image_.qp_. You need to do this before calling the Encoded() function above. https://codereview.webrtc.org/2398963003/diff/120001/webrtc/modules/video_cod... File webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.h (left): https://codereview.webrtc.org/2398963003/diff/120001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.h:28: class H264EncoderImpl : public H264Encoder { Implement GetQPThresholds() for this class: rtc::Optional<QPThresholds> GetQPThresholds() override { return QPThresholds::Default(kVideoCodecH264); } https://codereview.webrtc.org/2398963003/diff/120001/webrtc/modules/video_cod... File webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.mm (left): https://codereview.webrtc.org/2398963003/diff/120001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.mm:276: quality_scaler_.OnEncodeFrame(frame.width(), frame.height()); ditto: I don't think this class can handle dynamic resolution changes in the incoming |frame|. You need to compare |frame| width/height against width_/height and call ResetCompressionSession() if it changes. This is probably the cause of the green image you get. https://codereview.webrtc.org/2398963003/diff/120001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.mm:627: quality_scaler_.ReportQP(qp); ditto: You need to set qp_ in |frame| in order for quality scaling to work. https://codereview.webrtc.org/2398963003/diff/120001/webrtc/modules/video_cod... File webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc (left): https://codereview.webrtc.org/2398963003/diff/120001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc:705: if (input_image->width() != codec_.width || ditto: Need to keep the check and UpdateCodecFrameSize logic. https://codereview.webrtc.org/2398963003/diff/120001/webrtc/modules/video_cod... File webrtc/modules/video_coding/codecs/vp8/vp8_impl.h (left): https://codereview.webrtc.org/2398963003/diff/120001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/vp8/vp8_impl.h:120: bool quality_scaler_enabled_; ditto: We need to keep the quality_scaler_enabled_ logic. https://codereview.webrtc.org/2398963003/diff/120001/webrtc/modules/video_cod... File webrtc/modules/video_coding/utility/quality_scaler.cc (right): https://codereview.webrtc.org/2398963003/diff/120001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:49: q->PostDelayedTask(std::unique_ptr<rtc::QueuedTask>(this), Putting |this| in a std::unique_ptr looks strange for me. We also have a lot of raw pointers in this class, I will take a closer look in the next review cycle. https://codereview.webrtc.org/2398963003/diff/120001/webrtc/modules/video_cod... File webrtc/modules/video_coding/utility/quality_scaler.h (right): https://codereview.webrtc.org/2398963003/diff/120001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:23: class ScalingInterface { Put 'observer' somewhere in the name, e.g. ScalingObserverInterface. https://codereview.webrtc.org/2398963003/diff/120001/webrtc/video/vie_encoder.cc File webrtc/video/vie_encoder.cc (right): https://codereview.webrtc.org/2398963003/diff/120001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:517: quality_scaler_.Init(this, codec_type_); No thresholds should mean no quality scaling, not default quality scaling. https://codereview.webrtc.org/2398963003/diff/120001/webrtc/video/vie_encoder.h File webrtc/video/vie_encoder.h (right): https://codereview.webrtc.org/2398963003/diff/120001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.h:178: QualityScaler quality_scaler_ ACCESS_ON(&encoder_queue_); Is this the only QualityScaler instance now? Can you put it in a std::unique_pointer<QualityScaler> and change QualityScaler::Init to be the QualityScaler ctor instead? That should simplify the QualityScaler code and make more variables const. Also, we need a way to represent that quality scaling is disabled anyway and then we can use quality_scaler_==nullptr. https://codereview.webrtc.org/2398963003/diff/120001/webrtc/video_encoder.h File webrtc/video_encoder.h (right): https://codereview.webrtc.org/2398963003/diff/120001/webrtc/video_encoder.h#n... webrtc/video_encoder.h:85: typedef std::pair<int, int> QPThresholds; I think it would be better to make this a real class instead and add a static factory function for the default values. The default values can then be moved from the quality scaler to that function. Something like: class QPThresholds { public: static rtc::Optional<QPThresholds> Default(EncoderType encoderType); QPThresholds(int lower_bound, int upper_bound); int GetLowerBound(); int GetUpperBound(); private: const int lower_bound_; const int upper_bound_; };
https://codereview.webrtc.org/2398963003/diff/120001/webrtc/modules/video_cod... File webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.cc (left): https://codereview.webrtc.org/2398963003/diff/120001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.cc:375: int qp = -1; On 2016/10/07 12:02:54, magjed_webrtc wrote: > You still need to parse the qp and put it in encoded_image_.qp_. You need to do > this before calling the Encoded() function above. Acknowledged. https://codereview.webrtc.org/2398963003/diff/120001/webrtc/modules/video_cod... File webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.mm (left): https://codereview.webrtc.org/2398963003/diff/120001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.mm:276: quality_scaler_.OnEncodeFrame(frame.width(), frame.height()); On 2016/10/07 12:02:54, magjed_webrtc wrote: > ditto: I don't think this class can handle dynamic resolution changes in the > incoming |frame|. You need to compare |frame| width/height against width_/height > and call ResetCompressionSession() if it changes. This is probably the cause of > the green image you get. It looks like the case that frame.width() != width_ will never be true, as if the resolution changes we destroy and reset the encoder anyway. https://codereview.webrtc.org/2398963003/diff/120001/webrtc/modules/video_cod... File webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc (left): https://codereview.webrtc.org/2398963003/diff/120001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc:705: if (input_image->width() != codec_.width || On 2016/10/07 12:02:54, magjed_webrtc wrote: > ditto: Need to keep the check and UpdateCodecFrameSize logic. Acknowledged. https://codereview.webrtc.org/2398963003/diff/120001/webrtc/modules/video_cod... File webrtc/modules/video_coding/utility/quality_scaler.h (right): https://codereview.webrtc.org/2398963003/diff/120001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:23: class ScalingInterface { On 2016/10/07 12:02:54, magjed_webrtc wrote: > Put 'observer' somewhere in the name, e.g. ScalingObserverInterface. Done. https://codereview.webrtc.org/2398963003/diff/120001/webrtc/video/vie_encoder.h File webrtc/video/vie_encoder.h (right): https://codereview.webrtc.org/2398963003/diff/120001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.h:178: QualityScaler quality_scaler_ ACCESS_ON(&encoder_queue_); On 2016/10/07 12:02:54, magjed_webrtc wrote: > Is this the only QualityScaler instance now? Yes. > Can you put it in a > std::unique_pointer<QualityScaler> and change QualityScaler::Init to be the > QualityScaler ctor instead? That should simplify the QualityScaler code and make > more variables const. Also, we need a way to represent that quality scaling is > disabled anyway and then we can use quality_scaler_==nullptr. Ok, Thats certainly doable. Will keep that in mind.
Description was changed from ========== Move usage of QualityScaler to ViEEncoder. This brings QualityScaler much more in line with OveruseFrameDetector. The two classes are conceptually similar, and should be used in the same way. The biggest changes in this CL are: - Quality scaling is now only done in ViEEncoder and not in each encoder implementation separately. - QualityScaler now checks the average QP asynchronously, instead of having to be polled on each frame. - QualityScaler is no longer responsible for actually scaling the frames, but has a callback to ViEEncoder that it uses to express it's desire for lower resolution. TODO: Disable quality scaling for VP9 BUG=webrtc:6495 ========== to ========== Move usage of QualityScaler to ViEEncoder. This brings QualityScaler much more in line with OveruseFrameDetector. The two classes are conceptually similar, and should be used in the same way. The biggest changes in this CL are: - Quality scaling is now only done in ViEEncoder and not in each encoder implementation separately. - QualityScaler now checks the average QP asynchronously, instead of having to be polled on each frame. - QualityScaler is no longer responsible for actually scaling the frames, but has a callback to ViEEncoder that it uses to express it's desire for lower resolution. This is still not completely done, the questions that remain are: - Where to report dropped frames to the quality scaler - Some encoders want to have scaling disabled in certain cases - what to do about stats? Do we want to include a scaling reason in the callback - What to do in the case of simulcast? Right now I turned scaling off unless there is just one stream BUG=webrtc:6495 ==========
I think this is ready for review. I updated the description with some points that are still not completely thought through, so any input there is much appreciated.
https://codereview.webrtc.org/2398963003/diff/200001/webrtc/api/android/jni/a... File webrtc/api/android/jni/androidmediaencoder_jni.cc (left): https://codereview.webrtc.org/2398963003/diff/200001/webrtc/api/android/jni/a... webrtc/api/android/jni/androidmediaencoder_jni.cc:389: scale_ = codec_settings->codecSpecific.VP8.automaticResizeOn; I don't see that you have preserved this logic. If you can't easily move it to e.g. vie_encoder.cc then keep the logic in this CL. It's easier for everyone the more you split up a big refactoring into separate self contained changes. https://codereview.webrtc.org/2398963003/diff/200001/webrtc/modules/video_cod... File webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc (left): https://codereview.webrtc.org/2398963003/diff/200001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc:564: quality_scaler_enabled_ = encoders_.size() == 1 && ditto: This logic seems to be gone? https://codereview.webrtc.org/2398963003/diff/200001/webrtc/modules/video_cod... File webrtc/modules/video_coding/utility/quality_scaler.h (right): https://codereview.webrtc.org/2398963003/diff/200001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:48: thresholds = std::unique_ptr<QPThresholds>(); Remove this line, it's unnecessary. https://codereview.webrtc.org/2398963003/diff/200001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:50: bool enabled; Make this const. https://codereview.webrtc.org/2398963003/diff/200001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:51: std::unique_ptr<QPThresholds> thresholds; Use rtc::Optional instead to avoid an extra heap allocation. I also think the intent will be clearer that way. https://codereview.webrtc.org/2398963003/diff/200001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:51: std::unique_ptr<QPThresholds> thresholds; Make this const. https://codereview.webrtc.org/2398963003/diff/200001/webrtc/video/vie_encoder.h File webrtc/video/vie_encoder.h (right): https://codereview.webrtc.org/2398963003/diff/200001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.h:177: bool disable_quality_scaling_ ACCESS_ON(&encoder_queue_); I still want the quality scaler to be in an unique_ptr instead and change QualityScaler::Init to a ctor in order to reduce the amount of mutable state.
https://codereview.webrtc.org/2398963003/diff/200001/webrtc/api/android/jni/a... File webrtc/api/android/jni/androidmediaencoder_jni.cc (left): https://codereview.webrtc.org/2398963003/diff/200001/webrtc/api/android/jni/a... webrtc/api/android/jni/androidmediaencoder_jni.cc:389: scale_ = codec_settings->codecSpecific.VP8.automaticResizeOn; On 2016/10/19 13:00:12, magjed_webrtc wrote: > I don't see that you have preserved this logic. If you can't easily move it to > e.g. vie_encoder.cc then keep the logic in this CL. It's easier for everyone the > more you split up a big refactoring into separate self contained changes. You're right. This is one of the items mentioned as to TODO in the description. I think for now I will just keep this evaluation in the encoder and modify the value returned in GetQPThresholds. https://codereview.webrtc.org/2398963003/diff/200001/webrtc/modules/video_cod... File webrtc/modules/video_coding/utility/quality_scaler.h (right): https://codereview.webrtc.org/2398963003/diff/200001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:48: thresholds = std::unique_ptr<QPThresholds>(); On 2016/10/19 13:00:12, magjed_webrtc wrote: > Remove this line, it's unnecessary. Acknowledged. https://codereview.webrtc.org/2398963003/diff/200001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:50: bool enabled; On 2016/10/19 13:00:12, magjed_webrtc wrote: > Make this const. Acknowledged. https://codereview.webrtc.org/2398963003/diff/200001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:51: std::unique_ptr<QPThresholds> thresholds; On 2016/10/19 13:00:12, magjed_webrtc wrote: > Make this const. Good point, thanks. https://codereview.webrtc.org/2398963003/diff/200001/webrtc/video/vie_encoder.h File webrtc/video/vie_encoder.h (right): https://codereview.webrtc.org/2398963003/diff/200001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.h:177: bool disable_quality_scaling_ ACCESS_ON(&encoder_queue_); On 2016/10/19 13:00:12, magjed_webrtc wrote: > I still want the quality scaler to be in an unique_ptr instead and change > QualityScaler::Init to a ctor in order to reduce the amount of mutable state. Allright. My reasoning here is just keeping the implementation as similar to the overuse detector as possible. Perhaps this could be done in a follow-up CL where we change both of them?
https://codereview.webrtc.org/2398963003/diff/200001/webrtc/api/android/jni/a... File webrtc/api/android/jni/androidmediaencoder_jni.cc (left): https://codereview.webrtc.org/2398963003/diff/200001/webrtc/api/android/jni/a... webrtc/api/android/jni/androidmediaencoder_jni.cc:389: scale_ = codec_settings->codecSpecific.VP8.automaticResizeOn; On 2016/10/19 13:07:27, kthelgason wrote: > On 2016/10/19 13:00:12, magjed_webrtc wrote: > > I don't see that you have preserved this logic. If you can't easily move it to > > e.g. vie_encoder.cc then keep the logic in this CL. It's easier for everyone > the > > more you split up a big refactoring into separate self contained changes. > > You're right. This is one of the items mentioned as to TODO in the description. > I think for now I will just keep this evaluation in the encoder and modify the > value returned in GetQPThresholds. Sorry, I didn't see that comment in the description. https://codereview.webrtc.org/2398963003/diff/200001/webrtc/video/vie_encoder.h File webrtc/video/vie_encoder.h (right): https://codereview.webrtc.org/2398963003/diff/200001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.h:177: bool disable_quality_scaling_ ACCESS_ON(&encoder_queue_); On 2016/10/19 13:07:27, kthelgason wrote: > On 2016/10/19 13:00:12, magjed_webrtc wrote: > > I still want the quality scaler to be in an unique_ptr instead and change > > QualityScaler::Init to a ctor in order to reduce the amount of mutable state. > > Allright. My reasoning here is just keeping the implementation as similar to the > overuse detector as possible. Perhaps this could be done in a follow-up CL where > we change both of them? I wouldn't ask you to do this if you hadn't already rewritten QualityScaler::Init() and QualityScaler::Stop(). But since you have, I think we should take the opportunity and make QualityScaler RAII instead. I don't see any reason for mimicking the way overuse detector splits up lifetime management in two variables. It will still be conceptually similar to overuse detector, just cleaner. Negating the boolean variable name is also a bad practice.
The CQ bit was checked by kthelgason@webrtc.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.webrtc.org/...
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: Try jobs failed on following builders: ios32_sim_dbg on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/ios32_sim_dbg/builds/11783) ios64_gyp_dbg on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/ios64_gyp_dbg/builds/1684) ios64_sim_dbg on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/ios64_sim_dbg/builds/11805) ios_arm64_dbg on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/ios_arm64_dbg/builds/14132) ios_arm64_rel on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/ios_arm64_rel/builds/14025) ios_rel on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/ios_rel/builds/18049) mac_compile_dbg on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/mac_compile_dbg/builds/...)
Updated. PTAL. FYI the bots are unhappy because the patch fails to apply, not because the tests are failing!
Description was changed from ========== Move usage of QualityScaler to ViEEncoder. This brings QualityScaler much more in line with OveruseFrameDetector. The two classes are conceptually similar, and should be used in the same way. The biggest changes in this CL are: - Quality scaling is now only done in ViEEncoder and not in each encoder implementation separately. - QualityScaler now checks the average QP asynchronously, instead of having to be polled on each frame. - QualityScaler is no longer responsible for actually scaling the frames, but has a callback to ViEEncoder that it uses to express it's desire for lower resolution. This is still not completely done, the questions that remain are: - Where to report dropped frames to the quality scaler - Some encoders want to have scaling disabled in certain cases - what to do about stats? Do we want to include a scaling reason in the callback - What to do in the case of simulcast? Right now I turned scaling off unless there is just one stream BUG=webrtc:6495 ========== to ========== Move usage of QualityScaler to ViEEncoder. This brings QualityScaler much more in line with OveruseFrameDetector. The two classes are conceptually similar, and should be used in the same way. The biggest changes in this CL are: - Quality scaling is now only done in ViEEncoder and not in each encoder implementation separately. - QualityScaler now checks the average QP asynchronously, instead of having to be polled on each frame. - QualityScaler is no longer responsible for actually scaling the frames, but has a callback to ViEEncoder that it uses to express it's desire for lower resolution. This is still not completely done, the questions that remain are: - Where to report dropped frames to the quality scaler - ~Some encoders want to have scaling disabled in certain cases~ + DONE - ~what to do about stats? Do we want to include a scaling reason in the callback~ + DONE - What to do in the case of simulcast? Right now I turned scaling off unless there is just one stream BUG=webrtc:6495 ==========
https://codereview.webrtc.org/2398963003/diff/280001/webrtc/api/android/jni/a... File webrtc/api/android/jni/androidmediaencoder_jni.cc (right): https://codereview.webrtc.org/2398963003/diff/280001/webrtc/api/android/jni/a... webrtc/api/android/jni/androidmediaencoder_jni.cc:34: #include "webrtc/modules/video_coding/utility/vp8_header_parser.h" nit: revert this change. It was right before. https://codereview.webrtc.org/2398963003/diff/280001/webrtc/api/android/jni/a... webrtc/api/android/jni/androidmediaencoder_jni.cc:381: codecType_ == (kVideoCodecVP8 && The parentheses are misplaced so it's doing something crazy right now. It's also conecptually wrong because '|| codecType_ != kVideoCodecVP9' will always be true for VP8. I would recommend keeping exactly the same code for now and not touch this logic. https://codereview.webrtc.org/2398963003/diff/280001/webrtc/modules/video_cod... File webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.cc (left): https://codereview.webrtc.org/2398963003/diff/280001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.cc:290: quality_scaler_.OnEncodeFrame(input_frame.width(), input_frame.height()); I would like to document the condition that the input frame resolution always match codec_settings_, so please add: RTC_DCHECK_EQ(input_frame.width(), codec_settings_.width); RTC_DCHECK_EQ(input_frame.height(), codec_settings_.height); https://codereview.webrtc.org/2398963003/diff/280001/webrtc/modules/video_cod... File webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.mm (left): https://codereview.webrtc.org/2398963003/diff/280001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.mm:276: quality_scaler_.OnEncodeFrame(frame.width(), frame.height()); ditto: Please add: RTC_DCHECK_EQ(frame.width(), width_); RTC_DCHECK_EQ(frame.height(), height_); https://codereview.webrtc.org/2398963003/diff/280001/webrtc/modules/video_cod... File webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.cc (right): https://codereview.webrtc.org/2398963003/diff/280001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.cc:476: RTC_DCHECK(!streaminfos_.empty()) << "Encoder must be initialized first."; Is it a security risk if we execute streaminfos_[0].encoder->GetQPThresholds() when it's empty? Then this should be a CHECK. Or you can just handle the empty case like: return NumberOfStreams(codec_) == 1 ? streaminfos_[0].encoder->GetQPThresholds() : QualityScaler::Settings(false); https://codereview.webrtc.org/2398963003/diff/280001/webrtc/modules/video_cod... File webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc (right): https://codereview.webrtc.org/2398963003/diff/280001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc:687: if (input_image->width() != codec_.width || Can this ever happen? You haven't kept this check for the other encoders. https://codereview.webrtc.org/2398963003/diff/280001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc:1007: const bool enable_scaling = configurations_[0].rc_dropframe_thresh > 0 && You have changed the order of the checks. I think it's safest to start with 'encoders_.size() == 1' like before so you don't segfault if configurations_ is empty. https://codereview.webrtc.org/2398963003/diff/280001/webrtc/video/overuse_fra... File webrtc/video/overuse_frame_detector.h (right): https://codereview.webrtc.org/2398963003/diff/280001/webrtc/video/overuse_fra... webrtc/video/overuse_frame_detector.h:149: static const auto scale_reason_ = ScalingObserverInterface::kCpu; Why do you need this as a const class static constant? Why not use ScalingObserverInterface::kCpu directly? https://codereview.webrtc.org/2398963003/diff/280001/webrtc/video/vie_encoder.h File webrtc/video/vie_encoder.h (right): https://codereview.webrtc.org/2398963003/diff/280001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.h:176: bool enable_quality_scaling_ ACCESS_ON(&encoder_queue_); I think you misunderstood me about the RAII change. The changes I wanted from patch set 10 was this: * Make QualityScaler::Init be the ctor, i.e. QualityScaler::QualityScaler. * Make QualityScaler::Stop be the dtor, i.e .QualityScaler::~QualityScaler. * Remove disable_quality_scaling_ and replace: void ViEEncoder::Stop() { - if (!disable_quality_scaling_) - quality_scaler_.Stop(); + quality_scaler_ = nullptr; and EncodedImageCallback::Result ViEEncoder::OnEncodedImage() { - if (!disable_quality_scaling_) - quality_scaler_.ReportQP(encoded_image.qp_); + if (quality_scaler_) + quality_scaler_->ReportQP(encoded_image.qp_); * Replace - quality_scaler_.Init(...); + quality_scaler_.reset(new QualityScaler(...));
https://codereview.webrtc.org/2398963003/diff/280001/webrtc/video/vie_encoder.cc File webrtc/video/vie_encoder.cc (right): https://codereview.webrtc.org/2398963003/diff/280001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:701: encoder_queue_.PostTask([this, timestamp, time_sent, encoded_image] { This may contain invalid pointers. Copy only the value you need. encoded_image. https://codereview.webrtc.org/2398963003/diff/280001/webrtc/video/vie_encoder.h File webrtc/video/vie_encoder.h (right): https://codereview.webrtc.org/2398963003/diff/280001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.h:119: void ScaleUp(ScaleReason reason) override; This seems racy to me. I think we want something like have something like ScalyUp(ScaleReason reason, int pixel_count) so that we can now what the decision is based on. ie- cpu say go down but quality say go up. Then you may only go up if both CPU adapter and Quality scaler agree. And to agree you will want to now what resolution the callback is based on. The logic for choosing what to do when there are different resolution wants exist in VideoBroadcaster and can be copied from there. I am not convinced that a common interface for OveruseFrameDetector and the quality scaler is needed. But ok.
perkj@webrtc.org changed reviewers: + sprang@google.com
+sprang
https://codereview.webrtc.org/2398963003/diff/280001/webrtc/api/android/jni/a... File webrtc/api/android/jni/androidmediaencoder_jni.cc (right): https://codereview.webrtc.org/2398963003/diff/280001/webrtc/api/android/jni/a... webrtc/api/android/jni/androidmediaencoder_jni.cc:34: #include "webrtc/modules/video_coding/utility/vp8_header_parser.h" On 2016/10/26 14:28:36, magjed_webrtc wrote: > nit: revert this change. It was right before. Alphabet is hard :( https://codereview.webrtc.org/2398963003/diff/280001/webrtc/api/android/jni/a... webrtc/api/android/jni/androidmediaencoder_jni.cc:381: codecType_ == (kVideoCodecVP8 && On 2016/10/26 14:28:36, magjed_webrtc wrote: > The parentheses are misplaced so it's doing something crazy right now. It's also > conecptually wrong because '|| codecType_ != kVideoCodecVP9' will always be true > for VP8. I would recommend keeping exactly the same code for now and not touch > this logic. Oops. good catch, thanks. I've replaced it to the way it was. https://codereview.webrtc.org/2398963003/diff/280001/webrtc/modules/video_cod... File webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.cc (left): https://codereview.webrtc.org/2398963003/diff/280001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.cc:290: quality_scaler_.OnEncodeFrame(input_frame.width(), input_frame.height()); On 2016/10/26 14:28:36, magjed_webrtc wrote: > I would like to document the condition that the input frame resolution always > match codec_settings_, so please add: > RTC_DCHECK_EQ(input_frame.width(), codec_settings_.width); > RTC_DCHECK_EQ(input_frame.height(), codec_settings_.height); I agree, good call. Done. https://codereview.webrtc.org/2398963003/diff/280001/webrtc/modules/video_cod... File webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.mm (left): https://codereview.webrtc.org/2398963003/diff/280001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.mm:276: quality_scaler_.OnEncodeFrame(frame.width(), frame.height()); On 2016/10/26 14:28:36, magjed_webrtc wrote: > ditto: Please add: > RTC_DCHECK_EQ(frame.width(), width_); > RTC_DCHECK_EQ(frame.height(), height_); Done. https://codereview.webrtc.org/2398963003/diff/280001/webrtc/modules/video_cod... File webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.cc (right): https://codereview.webrtc.org/2398963003/diff/280001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.cc:476: RTC_DCHECK(!streaminfos_.empty()) << "Encoder must be initialized first."; On 2016/10/26 14:28:36, magjed_webrtc wrote: > Is it a security risk if we execute streaminfos_[0].encoder->GetQPThresholds() > when it's empty? Then this should be a CHECK. Or you can just handle the empty > case like: > return NumberOfStreams(codec_) == 1 ? streaminfos_[0].encoder->GetQPThresholds() > : QualityScaler::Settings(false); Done. https://codereview.webrtc.org/2398963003/diff/280001/webrtc/modules/video_cod... File webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc (right): https://codereview.webrtc.org/2398963003/diff/280001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc:687: if (input_image->width() != codec_.width || On 2016/10/26 14:28:37, magjed_webrtc wrote: > Can this ever happen? You haven't kept this check for the other encoders. I don't think so. There was no specific reason for keeping this. I've removed it and added a DCHECK as with the other encoders. https://codereview.webrtc.org/2398963003/diff/280001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/vp8/vp8_impl.cc:1007: const bool enable_scaling = configurations_[0].rc_dropframe_thresh > 0 && On 2016/10/26 14:28:37, magjed_webrtc wrote: > You have changed the order of the checks. I think it's safest to start with > 'encoders_.size() == 1' like before so you don't segfault if configurations_ is > empty. Done. https://codereview.webrtc.org/2398963003/diff/280001/webrtc/video/overuse_fra... File webrtc/video/overuse_frame_detector.h (right): https://codereview.webrtc.org/2398963003/diff/280001/webrtc/video/overuse_fra... webrtc/video/overuse_frame_detector.h:149: static const auto scale_reason_ = ScalingObserverInterface::kCpu; On 2016/10/26 14:28:37, magjed_webrtc wrote: > Why do you need this as a const class static constant? Why not use > ScalingObserverInterface::kCpu directly? We don't need to, I just prefer it over using the constant all over the place. Seemed easier to change by doing it like this. https://codereview.webrtc.org/2398963003/diff/280001/webrtc/video/vie_encoder.cc File webrtc/video/vie_encoder.cc (right): https://codereview.webrtc.org/2398963003/diff/280001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:701: encoder_queue_.PostTask([this, timestamp, time_sent, encoded_image] { On 2016/10/26 15:53:50, perkj_webrtc wrote: > This may contain invalid pointers. Copy only the value you need. encoded_image. Sorry, I'm not following. Can you elaborate? https://codereview.webrtc.org/2398963003/diff/280001/webrtc/video/vie_encoder.h File webrtc/video/vie_encoder.h (right): https://codereview.webrtc.org/2398963003/diff/280001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.h:176: bool enable_quality_scaling_ ACCESS_ON(&encoder_queue_); On 2016/10/26 14:28:37, magjed_webrtc wrote: > I think you misunderstood me about the RAII change. So the issue with doing what you describe comes down to task queue usage. In order for this to work without needing to guard access to members with a lock all methods must be called sequentially. If the dtor is responsible for deinitialisation we can't make that guarantee.
https://codereview.webrtc.org/2398963003/diff/280001/webrtc/video/overuse_fra... File webrtc/video/overuse_frame_detector.h (right): https://codereview.webrtc.org/2398963003/diff/280001/webrtc/video/overuse_fra... webrtc/video/overuse_frame_detector.h:149: static const auto scale_reason_ = ScalingObserverInterface::kCpu; On 2016/10/26 19:02:50, kthelgason wrote: > On 2016/10/26 14:28:37, magjed_webrtc wrote: > > Why do you need this as a const class static constant? Why not use > > ScalingObserverInterface::kCpu directly? > > We don't need to, I just prefer it over using the constant all over the place. > Seemed easier to change by doing it like this. Ok. I would go with ScalingObserverInterface::kCpu directly, but if you want to use a constant for this, then you should name it kScaleReason, make it a non-class variable, and move the declaration to the cc file in an anonymous namespace. https://codereview.webrtc.org/2398963003/diff/280001/webrtc/video/vie_encoder.h File webrtc/video/vie_encoder.h (right): https://codereview.webrtc.org/2398963003/diff/280001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.h:176: bool enable_quality_scaling_ ACCESS_ON(&encoder_queue_); On 2016/10/26 19:02:50, kthelgason wrote: > On 2016/10/26 14:28:37, magjed_webrtc wrote: > > I think you misunderstood me about the RAII change. > > So the issue with doing what you describe comes down to task queue usage. In > order for this to work without needing to guard access to members with a lock > all methods must be called sequentially. If the dtor is responsible for > deinitialisation we can't make that guarantee. I don't follow, for me it looks perfectly fine to remove QualityScaler::Stop() and move that code to QualityScaler::~QualityScaler() instead. All methods will still be called sequentially on the task queue, including the dtor. Can you elaborate why this would be a problem? https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... File webrtc/modules/video_coding/utility/quality_scaler.cc (right): https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:48: const auto q = rtc::TaskQueue::Current(); nit: I would not use auto here and the style guide says: "Use auto to avoid type names that are noisy, obvious, or unimportant - cases where the type doesn't aid in clarity for the reader." and at least for me the return type of rtc::TaskQueue::Current() is not obvious or unimportant, and the type rtc::TaskQueue* is not noisy. For example, I was concerned if you were making an unintentional copy-by-value of something expensive since you are not capturing by-ref, so I had to look the specific type up in task_queue.h. Let's keep the use of auto to the specific cases where it's allowed or encouraged according to the style guide. For this case, you can also just inline q, i.e. write rtc::TaskQueue::Current()->PostDelayedTask(...). https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:54: friend class QualityScaler; Why is QualityScaler a friend? Can't you just make Stop() public instead? https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:95: int low, high; nit: You should only have one declaration per line. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... File webrtc/modules/video_coding/utility/quality_scaler.h (right): https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:17: #include "webrtc/video_frame.h" Remove this unused include as well as the i420_buffer_pool.h include. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:71: virtual int64_t GetTimeoutMs(); nit: I don't think the name 'Timeout' is appropriate. Can you rename it something like GetSamplingPeriodMs()? As a sidenote, I think it would have been better to be able to pass in an explicit TaskQueue to QualityScaler as an argument, so that we can pass in a fake/mock TaskQueue when testing, so that the tests become completely deterministic and we don't have to make virtual functions like this. That would require TaskQueue to be an interface, which is not the case, so I think this is an ok approach for now. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:85: int64_t measure_interval_ GUARDED_BY(&task_checker_); nit: I would like to add a 'sec' suffix to the variable name to document the time unit. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... File webrtc/modules/video_coding/utility/quality_scaler_unittest.cc (right): https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler_unittest.cc:17: #include "webrtc/common_video/rotation.h" This include looks unused. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler_unittest.cc:18: #include "webrtc/video_frame.h" This include looks unused as well. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler_unittest.cc:105: do { \ Why a do-while block and not just a block? { rtc::Event ev(false, false); ev.Wait(x); } https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler_unittest.cc:111: EXPECT_CALL(*observer_, ScaleDown(reason_)).Times(1); How do we know that it will be called exactly once? Is that determined by 'kFramerate * 5' in TriggerScale? Then maybe this test is overspecified and we should use Times(AtLeast(1)) instead. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler_unittest.cc:113: WAIT_FOR_MS(50); Will this sleep for 50ms unconditionally? Can't we use gmock to wait for events somehow? If it's not possible to wait for events with gmock, then I think it's better to mock manually with events that we wait for.
sprang@webrtc.org changed reviewers: + sprang@webrtc.org
mostly some style nits https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... File webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.mm (right): https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.mm:254: // input_frame size should always match codec settings nit: // Input_frame size should always match codec settings. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... File webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.cc (right): https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.cc:475: // Turn off quality scaling for simulcast nit: End comments with a period. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.cc:479: return QualityScaler::Settings(false); nit: use {} brackets with if+else even if single line statements. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... File webrtc/modules/video_coding/utility/quality_scaler.cc (right): https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:33: static const int kMeasureSeconds = 5; I think this is the first time I've seen seconds used as a unit in out code. I'm afraid of change, so would like this to be in ms too :) https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:58: } nit: \n https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:156: const auto avg_qp = average_qp_.GetAverage(); Would prefer the actual type here. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... File webrtc/modules/video_coding/utility/quality_scaler.h (right): https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:28: enum ScaleReason { kQuality, kCpu }; prefer enum class https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:29: static const size_t ScaleReasonSize = 2; nit: kScaleReasonSize or SCALE_REASON_SIZE https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:44: typedef std::pair<int, int> QPThresholds; I'd prefer a simple struct, just because threshold.high is more explicit than threshold.second. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:80: ScalingObserverInterface* observer_ GUARDED_BY(&task_checker_); ScalingObserverInterface* const observer_ https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:90: int high_qp_threshold_ GUARDED_BY(&task_checker_); Maybe a single QPThresholds member? https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:92: static const auto scale_reason_ = ScalingObserverInterface::kQuality; Prefer not to use auto here. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... File webrtc/modules/video_coding/utility/quality_scaler_unittest.cc (right): https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler_unittest.cc:66: EXPECT_TRUE(event.Wait(1000)); Perhaps a kDefaultTimeoutMs constant somewhere? https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler_unittest.cc:105: do { \ On 2016/10/27 11:45:58, magjed_webrtc wrote: > Why a do-while block and not just a block? > { > rtc::Event ev(false, false); > ev.Wait(x); > } This is good practice. See for instance: http://stackoverflow.com/questions/1067226/c-multi-line-macro-do-while0-vs-sc... That said, macros aren't generally good practice in themselves and I'm not sure it's really needed here?
https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... File webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.mm (right): https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.mm:254: // input_frame size should always match codec settings On 2016/10/27 13:43:48, språng wrote: > nit: // Input_frame size should always match codec settings. I feel weird capitalizing a variable name that is not capitalized in the code. I added || around it to make it clearer that it's a variable. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... File webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.cc (right): https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.cc:475: // Turn off quality scaling for simulcast On 2016/10/27 13:43:48, språng wrote: > nit: End comments with a period. Done. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.cc:479: return QualityScaler::Settings(false); On 2016/10/27 13:43:48, språng wrote: > nit: use {} brackets with if+else even if single line statements. Done. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... File webrtc/modules/video_coding/utility/quality_scaler.cc (right): https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:33: static const int kMeasureSeconds = 5; On 2016/10/27 13:43:48, språng wrote: > I think this is the first time I've seen seconds used as a unit in out code. I'm > afraid of change, so would like this to be in ms too :) That sounds good to me. This is in seconds because the previous code had it specified in seconds, but I can of course change it. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:48: const auto q = rtc::TaskQueue::Current(); On 2016/10/27 11:45:57, magjed_webrtc wrote: > nit: I would not use auto here and the style guide says: "Use auto to avoid type > names that are noisy, obvious, or unimportant - cases where the type doesn't aid > in clarity for the reader." and at least for me the return type of > rtc::TaskQueue::Current() is not obvious or unimportant, and the type > rtc::TaskQueue* is not noisy. For example, I was concerned if you were making an > unintentional copy-by-value of something expensive since you are not capturing > by-ref, so I had to look the specific type up in task_queue.h. Let's keep the > use of auto to the specific cases where it's allowed or encouraged according to > the style guide. For this case, you can also just inline q, i.e. write > rtc::TaskQueue::Current()->PostDelayedTask(...). Done. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:54: friend class QualityScaler; On 2016/10/27 11:45:57, magjed_webrtc wrote: > Why is QualityScaler a friend? Can't you just make Stop() public instead? I think it's cleaner to enforce the fact that this method should only ever be called by QualityScaler this way. Maybe that's stupid since the class is not declared in a header, but that is my reasoning at least :) https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:58: } On 2016/10/27 13:43:48, språng wrote: > nit: \n Done. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:95: int low, high; On 2016/10/27 11:45:57, magjed_webrtc wrote: > nit: You should only have one declaration per line. Done. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:156: const auto avg_qp = average_qp_.GetAverage(); On 2016/10/27 13:43:48, språng wrote: > Would prefer the actual type here. I'm not sure I agree. The type is rtc::Optional<int>, and typing that out does not add much clarity, at least for me. But my preference is always towards more auto, not less. Feel free to reiterate this comment if you feel strongly about it. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... File webrtc/modules/video_coding/utility/quality_scaler.h (right): https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:17: #include "webrtc/video_frame.h" On 2016/10/27 11:45:57, magjed_webrtc wrote: > Remove this unused include as well as the i420_buffer_pool.h include. Done. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:28: enum ScaleReason { kQuality, kCpu }; On 2016/10/27 13:43:48, språng wrote: > prefer enum class I get that strongly-typed enums have several benefits, however I'm using this enum as an array index and thus the implicit integer conversion is actually desired behaviour. I can change that of course, if you think it's unsafe. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:29: static const size_t ScaleReasonSize = 2; On 2016/10/27 13:43:48, språng wrote: > nit: kScaleReasonSize or SCALE_REASON_SIZE Done. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:44: typedef std::pair<int, int> QPThresholds; On 2016/10/27 13:43:48, språng wrote: > I'd prefer a simple struct, just because threshold.high is more explicit than > threshold.second. Done. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:71: virtual int64_t GetTimeoutMs(); On 2016/10/27 11:45:57, magjed_webrtc wrote: > nit: I don't think the name 'Timeout' is appropriate. Can you rename it > something like GetSamplingPeriodMs()? > > As a sidenote, I think it would have been better to be able to pass in an > explicit TaskQueue to QualityScaler as an argument, so that we can pass in a > fake/mock TaskQueue when testing, so that the tests become completely > deterministic and we don't have to make virtual functions like this. That would > require TaskQueue to be an interface, which is not the case, so I think this is > an ok approach for now. I agree that is a better approach. I didn't see a way to make it work though. Changed the name of the method in line with your suggestion. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:80: ScalingObserverInterface* observer_ GUARDED_BY(&task_checker_); On 2016/10/27 13:43:48, språng wrote: > ScalingObserverInterface* const observer_ Done. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:85: int64_t measure_interval_ GUARDED_BY(&task_checker_); On 2016/10/27 11:45:57, magjed_webrtc wrote: > nit: I would like to add a 'sec' suffix to the variable name to document the > time unit. Done. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:90: int high_qp_threshold_ GUARDED_BY(&task_checker_); On 2016/10/27 13:43:48, språng wrote: > Maybe a single QPThresholds member? Done. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:92: static const auto scale_reason_ = ScalingObserverInterface::kQuality; On 2016/10/27 13:43:48, språng wrote: > Prefer not to use auto here. Why? the type should be completely obvious from the rhs of the assignment. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... File webrtc/modules/video_coding/utility/quality_scaler_unittest.cc (right): https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler_unittest.cc:17: #include "webrtc/common_video/rotation.h" On 2016/10/27 11:45:58, magjed_webrtc wrote: > This include looks unused. Acknowledged. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler_unittest.cc:18: #include "webrtc/video_frame.h" On 2016/10/27 11:45:58, magjed_webrtc wrote: > This include looks unused as well. Acknowledged. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler_unittest.cc:66: EXPECT_TRUE(event.Wait(1000)); On 2016/10/27 13:43:48, språng wrote: > Perhaps a kDefaultTimeoutMs constant somewhere? Done. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler_unittest.cc:105: do { \ On 2016/10/27 13:43:48, språng wrote: > On 2016/10/27 11:45:58, magjed_webrtc wrote: > > Why a do-while block and not just a block? > > { > > rtc::Event ev(false, false); > > ev.Wait(x); > > } > > This is good practice. See for instance: > http://stackoverflow.com/questions/1067226/c-multi-line-macro-do-while0-vs-sc... > > That said, macros aren't generally good practice in themselves and I'm not sure > it's really needed here? Sure, I would not use this in production code, but for a test I think it's fine. It saves a little typing and adds a little clarity IMO. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler_unittest.cc:111: EXPECT_CALL(*observer_, ScaleDown(reason_)).Times(1); On 2016/10/27 11:45:58, magjed_webrtc wrote: > How do we know that it will be called exactly once? Is that determined by > 'kFramerate * 5' in TriggerScale? Then maybe this test is overspecified and we > should use Times(AtLeast(1)) instead. After a scaledown event stats get flushed. If ScaleDown were called more than once that indicates a bug. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler_unittest.cc:113: WAIT_FOR_MS(50); On 2016/10/27 11:45:58, magjed_webrtc wrote: > Will this sleep for 50ms unconditionally? Can't we use gmock to wait for events > somehow? If it's not possible to wait for events with gmock, then I think it's > better to mock manually with events that we wait for. Yes, for now this is an unconditional wait. I don't have any experience with gmock, but I did try to find a way to do this and came up with nothing. I will just mock these manually to fix this.
https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... File webrtc/modules/video_coding/utility/quality_scaler.cc (right): https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:54: friend class QualityScaler; On 2016/10/28 13:20:15, kthelgason wrote: > On 2016/10/27 11:45:57, magjed_webrtc wrote: > > Why is QualityScaler a friend? Can't you just make Stop() public instead? > > I think it's cleaner to enforce the fact that this method should only ever be > called by QualityScaler this way. Maybe that's stupid since the class is not > declared in a header, but that is my reasoning at least :) But the class is unusable without access to the Stop function and it's impossible to kill it. I don't feel strongly about one way over the other so do what you see fit. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:156: const auto avg_qp = average_qp_.GetAverage(); On 2016/10/27 13:43:48, språng wrote: > Would prefer the actual type here. +1. rtc::Optional<int> adds clarity for me. It's not possible to know the type from the local context and it's necessary to look up the declaration of GetAverage. The type declarations add more clarity for me than comments. Please only use auto in these cases according to the style guide: * (Encouraged) For iterators and other long/cluttery type names, particularly when the type is clear from context (calls to find, begin, or end for instance). * (Allowed) When the type is clear from local context (in the same expression or within a few lines). Initialization of a pointer or smart pointer with calls to new commonly falls into this category, as does use of auto in a range-based loop over a container whose type is spelled out nearby. * (Allowed) When the type doesn't matter because it isn't being used for anything other than equality comparison. * (Encouraged) When iterating over a map with a range-based loop (because it is often assumed that the correct type is pair<KeyType,ValueType> whereas it is actually pair<const KeyType,ValueType>). This is particularly well paired with local key and value aliases for .first and .second (often const-ref).
https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... File webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.mm (right): https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.mm:254: // input_frame size should always match codec settings On 2016/10/28 13:20:14, kthelgason wrote: > On 2016/10/27 13:43:48, språng wrote: > > nit: // Input_frame size should always match codec settings. > > I feel weird capitalizing a variable name that is not capitalized in the code. I > added || around it to make it clearer that it's a variable. Right, I missed the '_' so didn't notice it was the variable name. :D |input_frame| sounds good to me. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... File webrtc/modules/video_coding/utility/quality_scaler.h (right): https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:28: enum ScaleReason { kQuality, kCpu }; On 2016/10/28 13:20:15, kthelgason wrote: > On 2016/10/27 13:43:48, språng wrote: > > prefer enum class > > I get that strongly-typed enums have several benefits, however I'm using this > enum as an array index and thus the implicit integer conversion is actually > desired behaviour. > I can change that of course, if you think it's unsafe. I'd still go with an enum class, and be more explicit. Something like: enum class ScaleReason : size_t { kQuality = 0, kCpu = 1 }; If you really want to use them as index then just static_cast<size_t>() https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:92: static const auto scale_reason_ = ScalingObserverInterface::kQuality; On 2016/10/28 13:20:15, kthelgason wrote: > On 2016/10/27 13:43:48, språng wrote: > > Prefer not to use auto here. > > Why? the type should be completely obvious from the rhs of the assignment. If you change to an enum class, maybe. Otherwise some glancing at the code for the first time will have to scroll up and read again to realize kQuality is a part of ScaleReason. I personally prefer using auto only for ridiculously long std container iterator types and the like...
The CQ bit was checked by kthelgason@webrtc.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.webrtc.org/...
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: Try jobs failed on following builders: ios64_sim_dbg on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/ios64_sim_dbg/builds/12256) ios_arm64_dbg on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/ios_arm64_dbg/builds/14596) ios_arm64_rel on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/ios_arm64_rel/builds/14474) ios_dbg on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/ios_dbg/builds/19826)
The CQ bit was checked by kthelgason@webrtc.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.webrtc.org/...
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: Try jobs failed on following builders: ios32_sim_dbg on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/ios32_sim_dbg/builds/12240) ios_arm64_dbg on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/ios_arm64_dbg/builds/14599) linux_libfuzzer_rel on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/linux_libfuzzer_rel/bui...)
The CQ bit was checked by kthelgason@webrtc.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.webrtc.org/...
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: Try jobs failed on following builders: android_compile_x86_dbg on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/android_compile_x86_dbg...) ios32_sim_dbg on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/ios32_sim_dbg/builds/12242) linux_baremetal on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/linux_baremetal/builds/...) linux_compile_dbg on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/linux_compile_dbg/build...) linux_rel on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/linux_rel/builds/19921) mac_baremetal on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/mac_baremetal/builds/15914) mac_compile_dbg on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/mac_compile_dbg/builds/...)
Patchset #21 (id:420001) has been deleted
The CQ bit was checked by kthelgason@webrtc.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.webrtc.org/...
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: Try jobs failed on following builders: android_arm64_rel on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/android_arm64_rel/build...) android_compile_mips_dbg on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/android_compile_mips_db...) android_compile_x86_dbg on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/android_compile_x86_dbg...) android_dbg on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/android_dbg/builds/18348) linux_rel on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/linux_rel/builds/19925)
The CQ bit was checked by kthelgason@webrtc.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.webrtc.org/...
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: Try jobs failed on following builders: ios32_sim_dbg on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/ios32_sim_dbg/builds/12246) ios64_sim_dbg on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/ios64_sim_dbg/builds/12265) ios_arm64_dbg on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/ios_arm64_dbg/builds/14606) ios_arm64_rel on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/ios_arm64_rel/builds/14483) ios_dbg on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/ios_dbg/builds/19835) linux_libfuzzer_rel on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/linux_libfuzzer_rel/bui...) mac_baremetal on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/mac_baremetal/builds/15918) mac_rel on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/mac_rel/builds/19887)
Patchset #22 (id:460001) has been deleted
The CQ bit was checked by kthelgason@webrtc.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.webrtc.org/...
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: Try jobs failed on following builders: linux_asan on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/linux_asan/builds/19260) linux_ubsan_vptr on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/linux_ubsan_vptr/builds...)
The CQ bit was checked by kthelgason@webrtc.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.webrtc.org/...
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: Try jobs failed on following builders: android_rel on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/android_rel/builds/18194)
The CQ bit was checked by kthelgason@webrtc.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.webrtc.org/...
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: Try jobs failed on following builders: android_dbg on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/android_dbg/builds/18380)
https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... File webrtc/modules/video_coding/utility/quality_scaler.cc (right): https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:48: const auto q = rtc::TaskQueue::Current(); On 2016/10/28 13:20:15, kthelgason wrote: > On 2016/10/27 11:45:57, magjed_webrtc wrote: > > nit: I would not use auto here and the style guide says: "Use auto to avoid > type > > names that are noisy, obvious, or unimportant - cases where the type doesn't > aid > > in clarity for the reader." and at least for me the return type of > > rtc::TaskQueue::Current() is not obvious or unimportant, and the type > > rtc::TaskQueue* is not noisy. For example, I was concerned if you were making > an > > unintentional copy-by-value of something expensive since you are not capturing > > by-ref, so I had to look the specific type up in task_queue.h. Let's keep the > > use of auto to the specific cases where it's allowed or encouraged according > to > > the style guide. For this case, you can also just inline q, i.e. write > > rtc::TaskQueue::Current()->PostDelayedTask(...). > > Done. It's not done (in the latest patch set at least). https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... File webrtc/modules/video_coding/utility/quality_scaler.h (right): https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:92: static const auto scale_reason_ = ScalingObserverInterface::kQuality; On 2016/10/31 10:24:31, språng wrote: > On 2016/10/28 13:20:15, kthelgason wrote: > > On 2016/10/27 13:43:48, språng wrote: > > > Prefer not to use auto here. > > > > Why? the type should be completely obvious from the rhs of the assignment. > > If you change to an enum class, maybe. Otherwise some glancing at the code for > the first time will have to scroll up and read again to realize kQuality is a > part of ScaleReason. > I personally prefer using auto only for ridiculously long std container iterator > types and the like... It's not allowed to use auto for non-local variables. https://codereview.webrtc.org/2398963003/diff/520001/webrtc/DEPS File webrtc/DEPS (right): https://codereview.webrtc.org/2398963003/diff/520001/webrtc/DEPS#newcode31 webrtc/DEPS:31: "+webrtc/modules/video_coding/utility", # TODO(kthelgason): move this In what file is this used? Can't you move this to a DEPS file close to where it's used? https://codereview.webrtc.org/2398963003/diff/520001/webrtc/modules/video_cod... File webrtc/modules/video_coding/utility/quality_scaler.cc (right): https://codereview.webrtc.org/2398963003/diff/520001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:42: const auto scale_reason_ = ScalingObserverInterface::ScaleReason::kQuality; Not allowed to use auto for non-local variables https://codereview.webrtc.org/2398963003/diff/520001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:103: check_qp_task_->Stop(); I would like to avoid the 'check_qp_task_->Stop()' and reset here. It's better if you turn this around, i.e. call this ctor from the other ctor with QualityScaler(observer, thresholds, kMeasureMs) and make this ctor where you explicitly set all members. Also, move |check_qp_task_| to the ctor initialization list and make the pointer const, i.e. 'CheckQPTask*const'. https://codereview.webrtc.org/2398963003/diff/520001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:125: check_qp_task_ = nullptr; no need to set it to nullptr in the dtor. https://codereview.webrtc.org/2398963003/diff/520001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:130: return sampling_period_ms_; Can you make |sampling_period_ms_| const and return 'fast_rampup_ ? sampling_period_ms_ : (sampling_period_ms_ * kSamplePeriodScaleFactor)' here? https://codereview.webrtc.org/2398963003/diff/520001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:150: const auto drop_rate = framedrop_percent_.GetAverage(); Don't use auto here. https://codereview.webrtc.org/2398963003/diff/520001/webrtc/modules/video_cod... File webrtc/modules/video_coding/utility/quality_scaler.h (right): https://codereview.webrtc.org/2398963003/diff/520001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:65: void ReportDroppedFrame() const; I don't think this function or ReportQP should be const. https://codereview.webrtc.org/2398963003/diff/520001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:69: // This method declared virtual to help with testing. It's not virtual anymore and not used for testing, so make it private. https://codereview.webrtc.org/2398963003/diff/520001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:91: mutable MovingAverage average_qp_ GUARDED_BY(&task_checker_); I don't think these should be mutable unless you have a really good reason. https://codereview.webrtc.org/2398963003/diff/520001/webrtc/modules/video_cod... File webrtc/modules/video_coding/utility/quality_scaler_unittest.cc (right): https://codereview.webrtc.org/2398963003/diff/520001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler_unittest.cc:48: // Override GetSamplingPeriodMs to speed up the tests. Update comment, you pass it in the ctor instead. https://codereview.webrtc.org/2398963003/diff/520001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler_unittest.cc:106: std::unique_ptr<rtc::TaskQueue> q; Can't this be a 'rtc::TaskQueue q;' instead? I.e. do you need the unique_ptr for something? https://codereview.webrtc.org/2398963003/diff/520001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler_unittest.cc:106: std::unique_ptr<rtc::TaskQueue> q; nit: I guess this should be called 'q_'. https://codereview.webrtc.org/2398963003/diff/520001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler_unittest.cc:114: EXPECT_EQ(observer_->scaled_down, 1); It should be the expected value first when using EXPECT_EQ (don't ask me why), i.e. EXPECT_EQ(1, ...). https://codereview.webrtc.org/2398963003/diff/520001/webrtc/video/vie_encoder.cc File webrtc/video/vie_encoder.cc (right): https://codereview.webrtc.org/2398963003/diff/520001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:800: void ViEEncoder::ScaleDown(ScaleReason reason) { Wouldn't it be easier to send |current_pixel_count| as an argument? Wouldn't that make Quality and CPU scaling more independent and avoid races?
https://codereview.webrtc.org/2398963003/diff/520001/webrtc/DEPS File webrtc/DEPS (right): https://codereview.webrtc.org/2398963003/diff/520001/webrtc/DEPS#newcode31 webrtc/DEPS:31: "+webrtc/modules/video_coding/utility", # TODO(kthelgason): move this On 2016/11/10 13:06:59, magjed_webrtc wrote: > In what file is this used? Can't you move this to a DEPS file close to where > it's used? This is used in webrtc/video_encoder.h so unfortunately it can't really be any closer. https://codereview.webrtc.org/2398963003/diff/520001/webrtc/modules/video_cod... File webrtc/modules/video_coding/utility/quality_scaler.cc (right): https://codereview.webrtc.org/2398963003/diff/520001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:42: const auto scale_reason_ = ScalingObserverInterface::ScaleReason::kQuality; On 2016/11/10 13:07:00, magjed_webrtc wrote: > Not allowed to use auto for non-local variables Done. https://codereview.webrtc.org/2398963003/diff/520001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:103: check_qp_task_->Stop(); On 2016/11/10 13:07:00, magjed_webrtc wrote: > I would like to avoid the 'check_qp_task_->Stop()' and reset here. It's better > if you turn this around, i.e. call this ctor from the other ctor with > QualityScaler(observer, thresholds, kMeasureMs) and make this ctor where you > explicitly set all members. > > Also, move |check_qp_task_| to the ctor initialization list and make the pointer > const, i.e. 'CheckQPTask*const'. Thanks, good point. Done. https://codereview.webrtc.org/2398963003/diff/520001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:125: check_qp_task_ = nullptr; On 2016/11/10 13:07:00, magjed_webrtc wrote: > no need to set it to nullptr in the dtor. Done. https://codereview.webrtc.org/2398963003/diff/520001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:130: return sampling_period_ms_; On 2016/11/10 13:07:00, magjed_webrtc wrote: > Can you make |sampling_period_ms_| const and return 'fast_rampup_ ? > sampling_period_ms_ : (sampling_period_ms_ * kSamplePeriodScaleFactor)' here? Done. https://codereview.webrtc.org/2398963003/diff/520001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:150: const auto drop_rate = framedrop_percent_.GetAverage(); On 2016/11/10 13:07:00, magjed_webrtc wrote: > Don't use auto here. Done. https://codereview.webrtc.org/2398963003/diff/520001/webrtc/modules/video_cod... File webrtc/modules/video_coding/utility/quality_scaler.h (right): https://codereview.webrtc.org/2398963003/diff/520001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:65: void ReportDroppedFrame() const; On 2016/11/10 13:07:00, magjed_webrtc wrote: > I don't think this function or ReportQP should be const. Acknowledged. https://codereview.webrtc.org/2398963003/diff/520001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:69: // This method declared virtual to help with testing. On 2016/11/10 13:07:00, magjed_webrtc wrote: > It's not virtual anymore and not used for testing, so make it private. Done. https://codereview.webrtc.org/2398963003/diff/520001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:91: mutable MovingAverage average_qp_ GUARDED_BY(&task_checker_); On 2016/11/10 13:07:00, magjed_webrtc wrote: > I don't think these should be mutable unless you have a really good reason. I made these mutable and the report{QP, DroppedFrame} functions const because I thought of the MovingAverage as an implementation detail, and the fact that those functions don't actually change the _observable_ state of the class. I've changed it back and dropped const from the methods as per your comments, as I guess it's a matter of interpretation whether they really are const. https://codereview.webrtc.org/2398963003/diff/520001/webrtc/modules/video_cod... File webrtc/modules/video_coding/utility/quality_scaler_unittest.cc (right): https://codereview.webrtc.org/2398963003/diff/520001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler_unittest.cc:48: // Override GetSamplingPeriodMs to speed up the tests. On 2016/11/10 13:07:00, magjed_webrtc wrote: > Update comment, you pass it in the ctor instead. Done. https://codereview.webrtc.org/2398963003/diff/520001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler_unittest.cc:106: std::unique_ptr<rtc::TaskQueue> q; On 2016/11/10 13:07:00, magjed_webrtc wrote: > Can't this be a 'rtc::TaskQueue q;' instead? I.e. do you need the unique_ptr for > something? Sure, Just done for symmetry with other ivars. https://codereview.webrtc.org/2398963003/diff/520001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler_unittest.cc:106: std::unique_ptr<rtc::TaskQueue> q; On 2016/11/10 13:07:00, magjed_webrtc wrote: > nit: I guess this should be called 'q_'. Done. https://codereview.webrtc.org/2398963003/diff/520001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler_unittest.cc:114: EXPECT_EQ(observer_->scaled_down, 1); On 2016/11/10 13:07:00, magjed_webrtc wrote: > It should be the expected value first when using EXPECT_EQ (don't ask me why), > i.e. EXPECT_EQ(1, ...). 😫 https://codereview.webrtc.org/2398963003/diff/520001/webrtc/video/vie_encoder.cc File webrtc/video/vie_encoder.cc (right): https://codereview.webrtc.org/2398963003/diff/520001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:800: void ViEEncoder::ScaleDown(ScaleReason reason) { On 2016/11/10 13:07:00, magjed_webrtc wrote: > Wouldn't it be easier to send |current_pixel_count| as an argument? Wouldn't > that make Quality and CPU scaling more independent and avoid races? The QualityScaler and CpuOveruseDetector don't know (and probably shouldn't know) the current_pixel_count. Also, They aren't independent, as we maintain different counters, so even though we have scaled down for quality reasons we might still let the cpu adapter scale down further. The stats also have to be updated depending on the scale reason.
lgtm Please update the CL description. It looks like you need to rebase again... https://codereview.webrtc.org/2398963003/diff/520001/webrtc/DEPS File webrtc/DEPS (right): https://codereview.webrtc.org/2398963003/diff/520001/webrtc/DEPS#newcode31 webrtc/DEPS:31: "+webrtc/modules/video_coding/utility", # TODO(kthelgason): move this On 2016/11/10 15:38:27, kthelgason wrote: > On 2016/11/10 13:06:59, magjed_webrtc wrote: > > In what file is this used? Can't you move this to a DEPS file close to where > > it's used? > This is used in webrtc/video_encoder.h so unfortunately it can't really be any > closer. Then it might be better to put the QPThresholds in webrtc/video_encoder.h and update the DEPS for quality scaler instead. But you have a TODO so I'm willing to leave this. https://codereview.webrtc.org/2398963003/diff/520001/webrtc/video/vie_encoder.cc File webrtc/video/vie_encoder.cc (right): https://codereview.webrtc.org/2398963003/diff/520001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:800: void ViEEncoder::ScaleDown(ScaleReason reason) { On 2016/11/10 15:38:28, kthelgason wrote: > On 2016/11/10 13:07:00, magjed_webrtc wrote: > > Wouldn't it be easier to send |current_pixel_count| as an argument? Wouldn't > > that make Quality and CPU scaling more independent and avoid races? > > The QualityScaler and CpuOveruseDetector don't know (and probably shouldn't > know) the current_pixel_count. > Also, They aren't independent, as we maintain different counters, so even though > we have scaled down for quality reasons we might still let the cpu adapter scale > down further. > The stats also have to be updated depending on the scale reason. QualityScaler used to store the resolution in 'Resolution target_res_' and OveruseDetector stores it in |int num_pixels_| so it should be possible for them to know what pixel count they are on. My point is that those pixel counts might be out of sync with the pixel count here (last_frame_width_/last_frame_height_) since these are asynchronous events that take a few ms to propagate. What happens if e.g. QP scaler decides to call ScaleDown one frame after CPU scaler has called ScaleDown? It looks like we will scale down twice then, if the |last_frame_| resolution was updated between. I don't think this is a problem in practice, so I'm willing to leave this code as is.
Description was changed from ========== Move usage of QualityScaler to ViEEncoder. This brings QualityScaler much more in line with OveruseFrameDetector. The two classes are conceptually similar, and should be used in the same way. The biggest changes in this CL are: - Quality scaling is now only done in ViEEncoder and not in each encoder implementation separately. - QualityScaler now checks the average QP asynchronously, instead of having to be polled on each frame. - QualityScaler is no longer responsible for actually scaling the frames, but has a callback to ViEEncoder that it uses to express it's desire for lower resolution. This is still not completely done, the questions that remain are: - Where to report dropped frames to the quality scaler - ~Some encoders want to have scaling disabled in certain cases~ + DONE - ~what to do about stats? Do we want to include a scaling reason in the callback~ + DONE - What to do in the case of simulcast? Right now I turned scaling off unless there is just one stream BUG=webrtc:6495 ========== to ========== Move usage of QualityScaler to ViEEncoder. This brings QualityScaler much more in line with OveruseFrameDetector. The two classes are conceptually similar, and should be used in the same way. The biggest changes in this CL are: - Quality scaling is now only done in ViEEncoder and not in each encoder implementation separately. - QualityScaler now checks the average QP asynchronously, instead of having to be polled on each frame. - QualityScaler is no longer responsible for actually scaling the frames, but has a callback to ViEEncoder that it uses to express it's desire for lower resolution. BUG=webrtc:6495 ==========
ping perkj & sprang. Care to take another look? I want to try and land this as rebasing multiple times per day is getting tedious.
This looks like an improvement. I just looked at ViEEncoder and the StatsProxy. Note that you will need an owners approval as well. https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/overuse_fra... File webrtc/video/overuse_frame_detector.cc (right): https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/overuse_fra... webrtc/video/overuse_frame_detector.cc:52: const auto scale_reason_ = ScalingObserverInterface::ScaleReason::kCpu; nit: / / This is not a member, just a const so name accordingly. https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/send_statis... File webrtc/video/send_statistics_proxy_unittest.cc (left): https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/send_statis... webrtc/video/send_statistics_proxy_unittest.cc:621: encoded_image.adapt_reason_.quality_resolution_downscales = 1; So GetStats previously reported bw_limited_resolution when quality scaling kicked in. I guess that make sense since if bw had been enough the quality should be good enough. So please make sure this behaviour is not changed or start a discussion with Ã…sa, Stefan and Pbos. https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/vie_encoder.cc File webrtc/video/vie_encoder.cc (right): https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:550: if (scaling_settings.enabled && source_proxy_->IsResolutionScalingEnabled()) { should you delete the quality scaler if this is not true? ie- switching from camera to screen share? https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:721: if (quality_scaler_) quality_scaler is still set here if you switch from camera to screen share. https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:824: ++scale_counter_[reason]; Please add a LOG(LS_INFO) with the info about why we go up/down in resolution and include the value of both reasons. https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:833: // Request higher resolution if we are cpu restricted and the the current cpu ? https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:852: source_proxy_->RequestHigherResolutionThan(current_pixel_count); And a log here too please. https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/vie_encoder.h File webrtc/video/vie_encoder.h (right): https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.h:206: // restricted by CPU usage. It is reset if |source_| is changed. This comment does not seem to be correct which is good. ie, camera - > cPU restricted -> switch to screen share -> not cpu restricted -> switch back to the camera -> should still be cpu restricted. https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/vie_encoder... File webrtc/video/vie_encoder_unittest.cc (right): https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/vie_encoder... webrtc/video/vie_encoder_unittest.cc:29: static const int kMaxCpuDowngrades = 2; Why not keep this in ViEEncoder then? You can even make it protected if you want. https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/vie_encoder... webrtc/video/vie_encoder_unittest.cc:544: TEST_F(ViEEncoderTest, SwitchingSourceKeepsAdaptation) { This looks like the same test as StatsTracksAdaptationStatsWhenSwitchingSource and StatsTracksQualityAdaptationStatsWhenSwitchingSource except that you also check that EXPECT_FALSE(stats.cpu_limited_resolution) is always false ? Can you just add that check to StatsTracksQualityAdaptationStatsWhenSwitchingSource instead?
looks good, but please address the video to screenshare and back switched that perkj@ mentioned. Can you add a test case for that? Also, if you expected any changes in how stats are reported, notify people and/or include a not in the cl so that perf sheriffs don't blindly revert. https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... File webrtc/modules/video_coding/utility/quality_scaler.h (right): https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.h:28: enum ScaleReason { kQuality, kCpu }; On 2016/10/31 10:24:31, språng wrote: > On 2016/10/28 13:20:15, kthelgason wrote: > > On 2016/10/27 13:43:48, språng wrote: > > > prefer enum class > > > > I get that strongly-typed enums have several benefits, however I'm using this > > enum as an array index and thus the implicit integer conversion is actually > > desired behaviour. > > I can change that of course, if you think it's unsafe. > > I'd still go with an enum class, and be more explicit. Something like: > enum class ScaleReason : size_t { kQuality = 0, kCpu = 1 }; > If you really want to use them as index then just static_cast<size_t>() No? https://codereview.webrtc.org/2398963003/diff/560001/webrtc/modules/video_cod... File webrtc/modules/video_coding/utility/quality_scaler_unittest.cc (right): https://codereview.webrtc.org/2398963003/diff/560001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler_unittest.cc:26: static const size_t kDefaultTimeout = 1000; nit: kDefaultTimeoutMs (I guess?) https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/send_statis... File webrtc/video/send_statistics_proxy_unittest.cc (left): https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/send_statis... webrtc/video/send_statistics_proxy_unittest.cc:621: encoded_image.adapt_reason_.quality_resolution_downscales = 1; On 2016/11/14 07:21:16, perkj_webrtc wrote: > So GetStats previously reported bw_limited_resolution when quality scaling > kicked in. I guess that make sense since if bw had been enough the quality > should be good enough. > So please make sure this behaviour is not changed or start a discussion with > Åsa, Stefan and Pbos. +1, so you don't get this reverted because of a perceived stats regression.
https://codereview.webrtc.org/2398963003/diff/560001/webrtc/modules/video_cod... File webrtc/modules/video_coding/utility/quality_scaler_unittest.cc (right): https://codereview.webrtc.org/2398963003/diff/560001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler_unittest.cc:26: static const size_t kDefaultTimeout = 1000; On 2016/11/14 10:25:38, språng wrote: > nit: kDefaultTimeoutMs (I guess?) Done. https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/overuse_fra... File webrtc/video/overuse_frame_detector.cc (right): https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/overuse_fra... webrtc/video/overuse_frame_detector.cc:52: const auto scale_reason_ = ScalingObserverInterface::ScaleReason::kCpu; On 2016/11/14 07:21:16, perkj_webrtc wrote: > nit: / / This is not a member, just a const so name accordingly. done. Used to be a member, that's why it's named like that. https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/send_statis... File webrtc/video/send_statistics_proxy_unittest.cc (left): https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/send_statis... webrtc/video/send_statistics_proxy_unittest.cc:621: encoded_image.adapt_reason_.quality_resolution_downscales = 1; On 2016/11/14 10:25:39, språng wrote: > On 2016/11/14 07:21:16, perkj_webrtc wrote: > > So GetStats previously reported bw_limited_resolution when quality scaling > > kicked in. I guess that make sense since if bw had been enough the quality > > should be good enough. > > So please make sure this behaviour is not changed or start a discussion with > > Åsa, Stefan and Pbos. > > +1, so you don't get this reverted because of a perceived stats regression. This behaviour has not changed, only how it's reported. This used to be done via a hack, setting this property on the |encoded_image| that eventually finds it's way to the stats proxy. This was necessary because scaling happened all the way down in the encoders. Now we can just report this directly to the stats_proxy without having to stick a note on the frame. https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/vie_encoder.cc File webrtc/video/vie_encoder.cc (right): https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:550: if (scaling_settings.enabled && source_proxy_->IsResolutionScalingEnabled()) { On 2016/11/14 07:21:16, perkj_webrtc wrote: > should you delete the quality scaler if this is not true? > > ie- switching from camera to screen share? Good catch, thanks. It would not have actually scaled, as we check that scaling is enabled for the current source before scaling, but it's a waste of CPU cycles. https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:721: if (quality_scaler_) On 2016/11/14 07:21:16, perkj_webrtc wrote: > quality_scaler is still set here if you switch from camera to screen share. Acknowledged. https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:824: ++scale_counter_[reason]; On 2016/11/14 07:21:16, perkj_webrtc wrote: > Please add a LOG(LS_INFO) with the info about why we go up/down in resolution > and include the value of both reasons. Done. https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:833: // Request higher resolution if we are cpu restricted and the the current On 2016/11/14 07:21:16, perkj_webrtc wrote: > cpu ? Done. https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:852: source_proxy_->RequestHigherResolutionThan(current_pixel_count); On 2016/11/14 07:21:16, perkj_webrtc wrote: > And a log here too please. Done. https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/vie_encoder.h File webrtc/video/vie_encoder.h (right): https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.h:206: // restricted by CPU usage. It is reset if |source_| is changed. On 2016/11/14 07:21:16, perkj_webrtc wrote: > This comment does not seem to be correct which is good. ie, camera - > cPU > restricted -> switch to screen share -> not cpu restricted -> switch back to the > camera -> should still be cpu restricted. Done. https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/vie_encoder... File webrtc/video/vie_encoder_unittest.cc (right): https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/vie_encoder... webrtc/video/vie_encoder_unittest.cc:29: static const int kMaxCpuDowngrades = 2; On 2016/11/14 07:21:16, perkj_webrtc wrote: > Why not keep this in ViEEncoder then? You can even make it protected if you > want. For some reason I did this because I had seen it done in another file. I actually hate this, and I'm very glad you commented on it! https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/vie_encoder... webrtc/video/vie_encoder_unittest.cc:544: TEST_F(ViEEncoderTest, SwitchingSourceKeepsAdaptation) { On 2016/11/14 07:21:16, perkj_webrtc wrote: > This looks like the same test as StatsTracksAdaptationStatsWhenSwitchingSource > and StatsTracksQualityAdaptationStatsWhenSwitchingSource except that you also > check that > EXPECT_FALSE(stats.cpu_limited_resolution) is always false ? Can you just add > that check to StatsTracksQualityAdaptationStatsWhenSwitchingSource instead? Ah, that's a rebase artifact. The test got duplicated for some reason. Thanks!
Thanks for taking a look sprang@! On 2016/11/14 10:25:39, språng wrote: > https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... > webrtc/modules/video_coding/utility/quality_scaler.h:28: enum ScaleReason { > kQuality, kCpu }; > On 2016/10/31 10:24:31, språng wrote: > > On 2016/10/28 13:20:15, kthelgason wrote: > > > On 2016/10/27 13:43:48, språng wrote: > > > > prefer enum class > > > > > > I get that strongly-typed enums have several benefits, however I'm using > this > > > enum as an array index and thus the implicit integer conversion is actually > > > desired behaviour. > > > I can change that of course, if you think it's unsafe. > > > > I'd still go with an enum class, and be more explicit. Something like: > > enum class ScaleReason : size_t { kQuality = 0, kCpu = 1 }; > > If you really want to use them as index then just static_cast<size_t>() > > No? Sorry, I feel pretty strongly against this. I did implement your suggestion but I feel that it clutters up the code in several places quite a bit. I'm not sold that the benefits in this case make up for it. I don't expect this to be used anywhere else. > https://codereview.webrtc.org/2398963003/diff/560001/webrtc/modules/video_cod... > File webrtc/modules/video_coding/utility/quality_scaler_unittest.cc (right): > > https://codereview.webrtc.org/2398963003/diff/560001/webrtc/modules/video_cod... > webrtc/modules/video_coding/utility/quality_scaler_unittest.cc:26: static const > size_t kDefaultTimeout = 1000; > nit: kDefaultTimeoutMs (I guess?) > > https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/send_statis... > File webrtc/video/send_statistics_proxy_unittest.cc (left): > > https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video/send_statis... > webrtc/video/send_statistics_proxy_unittest.cc:621: > encoded_image.adapt_reason_.quality_resolution_downscales = 1; > On 2016/11/14 07:21:16, perkj_webrtc wrote: > > So GetStats previously reported bw_limited_resolution when quality scaling > > kicked in. I guess that make sense since if bw had been enough the quality > > should be good enough. > > So please make sure this behaviour is not changed or start a discussion with > > Åsa, Stefan and Pbos. > > +1, so you don't get this reverted because of a perceived stats regression. Good point. Most of the behaviour will be kept the same, but we should sync anyway, as there is probably something I've missed there.
kthelgason@webrtc.org changed reviewers: + stefan@webrtc.org
Added stefan@ as a reviewer.
On 2016/11/14 14:39:51, kthelgason wrote: > Thanks for taking a look sprang@! > > On 2016/11/14 10:25:39, språng wrote: > > > https://codereview.webrtc.org/2398963003/diff/300001/webrtc/modules/video_cod... > > webrtc/modules/video_coding/utility/quality_scaler.h:28: enum ScaleReason { > > kQuality, kCpu }; > > On 2016/10/31 10:24:31, språng wrote: > > > On 2016/10/28 13:20:15, kthelgason wrote: > > > > On 2016/10/27 13:43:48, språng wrote: > > > > > prefer enum class > > > > > > > > I get that strongly-typed enums have several benefits, however I'm using > > this > > > > enum as an array index and thus the implicit integer conversion is > actually > > > > desired behaviour. > > > > I can change that of course, if you think it's unsafe. > > > > > > I'd still go with an enum class, and be more explicit. Something like: > > > enum class ScaleReason : size_t { kQuality = 0, kCpu = 1 }; > > > If you really want to use them as index then just static_cast<size_t>() > > > > No? > > Sorry, I feel pretty strongly against this. I did implement your suggestion but > I feel that it clutters up the code in several places quite a bit. I'm not sold > that the benefits in this case make up for it. I don't expect this to be used > anywhere else. > I don't agree, but am not religious about it. Could you at least explicitly define the base type and values?
https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video_encoder.h File webrtc/video_encoder.h (right): https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video_encoder.h#n... webrtc/video_encoder.h:156: virtual QualityScaler::Settings GetQPThresholds() const { Move QualityScaler::Settings to VideoEncoder::QualityThresholds to avoid the deps change?
On 2016/11/15 08:53:32, perkj_webrtc wrote: > https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video_encoder.h > File webrtc/video_encoder.h (right): > > https://codereview.webrtc.org/2398963003/diff/560001/webrtc/video_encoder.h#n... > webrtc/video_encoder.h:156: virtual QualityScaler::Settings GetQPThresholds() > const { > Move QualityScaler::Settings to VideoEncoder::QualityThresholds to avoid the > deps change? Done. Please take another look.
lgtm https://codereview.webrtc.org/2398963003/diff/560001/webrtc/modules/video_cod... File webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.cc (right): https://codereview.webrtc.org/2398963003/diff/560001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.cc:485: } This is an artifact of a rebase, right?
https://codereview.webrtc.org/2398963003/diff/620001/webrtc/video/vie_encoder.cc File webrtc/video/vie_encoder.cc (right): https://codereview.webrtc.org/2398963003/diff/620001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:308: // This can happen since |degradation_preference_| is set on You have removed the degradation_preference_. https://codereview.webrtc.org/2398963003/diff/620001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:324: if (!IsResolutionScalingEnabledLocked()) { and here https://codereview.webrtc.org/2398963003/diff/620001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:803: int current_pixel_count = last_frame_height_ * last_frame_width_; Hm, you need to check the degradation_preference here too. If you change the source you might disable resolution scaling. But you don't check here if its enable or not so you will do ++scale_counter and update the stats. Only when you call source_proxy_->RequestResolution you will ignore the new value. I would keep the check for if scaling is enabled or not here. (And maybe also keep have the degradation_preference posted to the encoder__queue so you don't need to take a lock every time). Rember that the Overusedetector and still runs regardless of degradation preferences. This is since sprang said he will use it for dropping frames and since there are stats that are calculated there. From what I see in your cl, changing the degradation preferences does not stop the quality scaler either. Please add a unit test for this problem or modify an existing as well once its fixed.
The CQ bit was checked by kthelgason@webrtc.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.webrtc.org/...
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: Try jobs failed on following builders: android_clang_dbg on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/android_clang_dbg/build...) android_compile_x86_rel on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/android_compile_x86_rel...) linux_baremetal on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/linux_baremetal/builds/...) mac_baremetal on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/mac_baremetal/builds/16330) presubmit on master.tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/presubmit/builds/10348)
On 2016/11/16 20:56:13, perkj_webrtc wrote: > https://codereview.webrtc.org/2398963003/diff/620001/webrtc/video/vie_encoder.cc > File webrtc/video/vie_encoder.cc (right): > > https://codereview.webrtc.org/2398963003/diff/620001/webrtc/video/vie_encoder... > webrtc/video/vie_encoder.cc:308: // This can happen since > |degradation_preference_| is set on > You have removed the degradation_preference_. > > https://codereview.webrtc.org/2398963003/diff/620001/webrtc/video/vie_encoder... > webrtc/video/vie_encoder.cc:324: if (!IsResolutionScalingEnabledLocked()) { > and here > > https://codereview.webrtc.org/2398963003/diff/620001/webrtc/video/vie_encoder... > webrtc/video/vie_encoder.cc:803: int current_pixel_count = last_frame_height_ * > last_frame_width_; > Hm, you need to check the degradation_preference here too. > If you change the source you might disable resolution scaling. But you don't > check here if its enable or not so you will do ++scale_counter and update the > stats. Only when you call source_proxy_->RequestResolution you will ignore the > new value. > > I would keep the check for if scaling is enabled or not here. (And maybe also > keep have the degradation_preference posted to the encoder__queue so you don't > need to take a lock every time). > > Rember that the Overusedetector and still runs regardless of degradation > preferences. This is since sprang said he will use it for dropping frames and > since there are stats that are calculated there. > > From what I see in your cl, changing the degradation preferences does not stop > the quality scaler either. > Please add a unit test for this problem or modify an existing as well once its > fixed. I already implemented this in a previous patchset. Looks like it disappeared during a rebase. I've added it back and added a test for it as well.
magjed@webrtc.org changed reviewers: - sprang@google.com
https://codereview.webrtc.org/2398963003/diff/680001/webrtc/modules/video_cod... File webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.cc (right): https://codereview.webrtc.org/2398963003/diff/680001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.cc:473: } else { I'd rewrite this: if (NumberOfStreams(codec_) != 1) return VideoEncoder::ScalingSettings(false); return streaminfos_[0].encoder->GetScalingSettings(); https://codereview.webrtc.org/2398963003/diff/680001/webrtc/modules/video_cod... File webrtc/modules/video_coding/codecs/vp8/vp8_impl.h (right): https://codereview.webrtc.org/2398963003/diff/680001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/vp8/vp8_impl.h:60: void OnDroppedFrame() override; Add a TODO to remove this? https://codereview.webrtc.org/2398963003/diff/680001/webrtc/modules/video_cod... File webrtc/modules/video_coding/utility/quality_scaler.cc (left): https://codereview.webrtc.org/2398963003/diff/680001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:99: init_num_pixels = kQvgaNumPixels; How is initial resolutions handled with the new scaler? https://codereview.webrtc.org/2398963003/diff/680001/webrtc/modules/video_cod... File webrtc/modules/video_coding/utility/quality_scaler.cc (right): https://codereview.webrtc.org/2398963003/diff/680001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:65: class QualityScaler::CheckQPTask : public rtc::QueuedTask { Could you add a comment somewhere why we decide to complicate the code by using a task queue? This class is fairly simple and it's not obvious to me from reading the code what the task queue actually adds, e.g., why are we not running CheckQP on every reported QP? https://codereview.webrtc.org/2398963003/diff/680001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:149: ReportQPHigh(); This is a bit weird I think, why do we report high qp if the frame drop rate is high? Should probably rename the method. https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/overuse_fra... File webrtc/video/overuse_frame_detector.cc (right): https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/overuse_fra... webrtc/video/overuse_frame_detector.cc:52: const auto scale_reason = ScalingObserverInterface::ScaleReason::kCpu; kScaleReason Or why not use ScalingObserverInterface::ScaleReason::kCpu directly? :) https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/overuse_fra... webrtc/video/overuse_frame_detector.cc:374: observer_->ScaleDown(scale_reason); It looks here like scale_reason could have different values... I'd actually prefer something like: kScaleReasonCpu https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder.cc File webrtc/video/vie_encoder.cc (right): https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:663: if (max_pixel_count_ && current_pixel_count >= *max_pixel_count_) { This sounds incorrect to me. If current_pixel_count is greater than max we should scale down until we're below max, no? https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:669: return; Shouldn't we check this at the top and return early, or does scaling_enabled_ only apply to quality scaling for some reason? https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video_encoder.h File webrtc/video_encoder.h (right): https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video_encoder.h#n... webrtc/video_encoder.h:73: struct QPThresholds { QpThresholds https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video_encoder.h#n... webrtc/video_encoder.h:185: virtual void OnDroppedFrame() {} TODO remove.
https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder.cc File webrtc/video/vie_encoder.cc (right): https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:315: scaling_enabled_ = Why not store degradation_preference ? https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:576: encoder_queue_.PostTask([this, timestamp, time_sent, encoded_image] { Sorry if I missed this before. But you can not post encoded_image. This will create a copy of encoded_image but encoded_image contains pointers to data that is not valid when the task is processed. So you just copy and post the value you really need. ie, encoded_image.qp_. https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:663: if (max_pixel_count_ && current_pixel_count >= *max_pixel_count_) { On 2016/11/17 16:12:57, stefan-webrtc (holmer) wrote: > This sounds incorrect to me. If current_pixel_count is greater than max we > should scale down until we're below max, no? No, when max_pixel_count is set it means we are ordering the capturer to reduce the resolution to max_pixel_count_. So this happens when the capturer has not yet fulfilled the request but the quality scaler or overusedetector reports overuse/bad quality again. https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:668: if (!scaling_enabled_) yes we should. Otherwise this will give you problem for cpu adaptation. Also, if sprang is working on frame rate degradation I think you should keep degradation_preferences instead of just a bool for resolution scaling. https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:704: if (!scaling_enabled_) dito. https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder.h File webrtc/video/vie_encoder.h (right): https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.h:28: #include "webrtc/modules/video_coding/utility/simulcast_rate_allocator.h" ? https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.h:112: static const int kMaxCpuDowngrades = 2; Order was correct from the beginning. https://google.github.io/styleguide/cppguide.html#Declaration_Order https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder... File webrtc/video/vie_encoder_unittest.cc (left): https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder... webrtc/video/vie_encoder_unittest.cc:579: vie_encoder_->SetSource(&video_source_, and this? https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder... webrtc/video/vie_encoder_unittest.cc:595: EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); and this? https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder... File webrtc/video/vie_encoder_unittest.cc (right): https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder... webrtc/video/vie_encoder_unittest.cc:554: EXPECT_FALSE(stats.cpu_limited_resolution); Why these changes? Now you dont test that switching source after cpu adaptation keeps the adaptation. https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder... webrtc/video/vie_encoder_unittest.cc:619: TEST_F(ViEEncoderTest, ScalingUpAndDownDoesNothingWithMaintainResolution) { LowQualityWhenScalingDisabled? https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder... webrtc/video/vie_encoder_unittest.cc:639: const auto last_pixel_count = *video_source_.sink_wants().max_pixel_count; nit const int last_pix...
https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder.cc File webrtc/video/vie_encoder.cc (right): https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:663: if (max_pixel_count_ && current_pixel_count >= *max_pixel_count_) { On 2016/11/17 21:23:38, perkj_webrtc wrote: > On 2016/11/17 16:12:57, stefan-webrtc (holmer) wrote: > > This sounds incorrect to me. If current_pixel_count is greater than max we > > should scale down until we're below max, no? > > No, when max_pixel_count is set it means we are ordering the capturer to reduce > the resolution to max_pixel_count_. > So this happens when the capturer has not yet fulfilled the request but the > quality scaler or overusedetector reports overuse/bad quality again. So max_pixel_count_ is the currently requested max resolution? Maybe the variable name could be improved to avoid the ambiguity.
Thanks for taking a look stefan, I replied to your comments and fixed most of them. https://codereview.webrtc.org/2398963003/diff/680001/webrtc/modules/video_cod... File webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.cc (right): https://codereview.webrtc.org/2398963003/diff/680001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.cc:473: } else { On 2016/11/17 16:12:57, stefan-webrtc (holmer) wrote: > I'd rewrite this: > > if (NumberOfStreams(codec_) != 1) > return VideoEncoder::ScalingSettings(false); > return streaminfos_[0].encoder->GetScalingSettings(); Done. https://codereview.webrtc.org/2398963003/diff/680001/webrtc/modules/video_cod... File webrtc/modules/video_coding/codecs/vp8/vp8_impl.h (right): https://codereview.webrtc.org/2398963003/diff/680001/webrtc/modules/video_cod... webrtc/modules/video_coding/codecs/vp8/vp8_impl.h:60: void OnDroppedFrame() override; On 2016/11/17 16:12:57, stefan-webrtc (holmer) wrote: > Add a TODO to remove this? I just removed it outright. https://codereview.webrtc.org/2398963003/diff/680001/webrtc/modules/video_cod... File webrtc/modules/video_coding/utility/quality_scaler.cc (left): https://codereview.webrtc.org/2398963003/diff/680001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:99: init_num_pixels = kQvgaNumPixels; On 2016/11/17 16:12:57, stefan-webrtc (holmer) wrote: > How is initial resolutions handled with the new scaler? I had assumed this would be handled where the initial sinkWants are determined. If that's not the case, it probably should be. https://codereview.webrtc.org/2398963003/diff/680001/webrtc/modules/video_cod... File webrtc/modules/video_coding/utility/quality_scaler.cc (right): https://codereview.webrtc.org/2398963003/diff/680001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:65: class QualityScaler::CheckQPTask : public rtc::QueuedTask { On 2016/11/17 16:12:57, stefan-webrtc (holmer) wrote: > Could you add a comment somewhere why we decide to complicate the code by using > a task queue? This class is fairly simple and it's not obvious to me from > reading the code what the task queue actually adds, e.g., why are we not running > CheckQP on every reported QP? Well, it seems logical that the QualityScaler and the CpuOveruseAdaptor should use the same interface for adjusting the source resolution. That interface is asynchronous and so this class needs to run on the right task queue to use it. Seems easier to complicate the QualityScaler code and keep ViEEncoder the same, than to introduce another path to set scaling preferences. Anyway, this is mentioned in the CL description to some extent, perhaps not clearly. https://codereview.webrtc.org/2398963003/diff/680001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:149: ReportQPHigh(); On 2016/11/17 16:12:57, stefan-webrtc (holmer) wrote: > This is a bit weird I think, why do we report high qp if the frame drop rate is > high? Should probably rename the method. You're right. This is actually unused now, as framedrop is never reported to the QualityScaler. Perhaps it would be better to just remove the related code for now. https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/overuse_fra... File webrtc/video/overuse_frame_detector.cc (right): https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/overuse_fra... webrtc/video/overuse_frame_detector.cc:52: const auto scale_reason = ScalingObserverInterface::ScaleReason::kCpu; On 2016/11/17 16:12:57, stefan-webrtc (holmer) wrote: > kScaleReason > > Or why not use ScalingObserverInterface::ScaleReason::kCpu directly? :) Just seems dirty to be passing a constant directly all the time. It feels like it will be easier to change be naming a constant here. https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/overuse_fra... webrtc/video/overuse_frame_detector.cc:374: observer_->ScaleDown(scale_reason); On 2016/11/17 16:12:57, stefan-webrtc (holmer) wrote: > It looks here like scale_reason could have different values... > > I'd actually prefer something like: > kScaleReasonCpu Done. https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder.cc File webrtc/video/vie_encoder.cc (right): https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:315: scaling_enabled_ = On 2016/11/17 21:23:38, perkj_webrtc wrote: > Why not store degradation_preference ? Just because I thought this was enough. It also means that I don't always have to make the comparison against that 70 character-long constant. https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:576: encoder_queue_.PostTask([this, timestamp, time_sent, encoded_image] { On 2016/11/17 21:23:38, perkj_webrtc wrote: > Sorry if I missed this before. But you can not post encoded_image. This will > create a copy of encoded_image but encoded_image contains pointers to data that > is not valid when the task is processed. So you just copy and post the value you > really need. ie, encoded_image.qp_. > Thanks, done. https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:663: if (max_pixel_count_ && current_pixel_count >= *max_pixel_count_) { On 2016/11/17 21:23:38, perkj_webrtc wrote: > On 2016/11/17 16:12:57, stefan-webrtc (holmer) wrote: > > This sounds incorrect to me. If current_pixel_count is greater than max we > > should scale down until we're below max, no? > > No, when max_pixel_count is set it means we are ordering the capturer to reduce > the resolution to max_pixel_count_. > So this happens when the capturer has not yet fulfilled the request but the > quality scaler or overusedetector reports overuse/bad quality again. Acknowledged. https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:668: if (!scaling_enabled_) On 2016/11/17 21:23:38, perkj_webrtc wrote: > yes we should. Otherwise this will give you problem for cpu adaptation. > > Also, if sprang is working on frame rate degradation I think you should keep > degradation_preferences instead of just a bool for resolution scaling. If that helps his work he should do it in his CL. I don't want to make assumptions here about how his implementation will work, as they will probably turn out to be wrong. https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:669: return; On 2016/11/17 16:12:57, stefan-webrtc (holmer) wrote: > Shouldn't we check this at the top and return early, or does scaling_enabled_ > only apply to quality scaling for some reason? For some reason I thought CPU adaptation should be exempt from this. Fixed. https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:704: if (!scaling_enabled_) On 2016/11/17 21:23:38, perkj_webrtc wrote: > dito. Done. https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder.h File webrtc/video/vie_encoder.h (right): https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.h:28: #include "webrtc/modules/video_coding/utility/simulcast_rate_allocator.h" On 2016/11/17 21:23:38, perkj_webrtc wrote: > ? Rebase artifact... Removed. https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.h:112: static const int kMaxCpuDowngrades = 2; On 2016/11/17 21:23:38, perkj_webrtc wrote: > Order was correct from the beginning. > https://google.github.io/styleguide/cppguide.html#Declaration_Order Done. https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder... File webrtc/video/vie_encoder_unittest.cc (left): https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder... webrtc/video/vie_encoder_unittest.cc:579: vie_encoder_->SetSource(&video_source_, On 2016/11/17 21:23:38, perkj_webrtc wrote: > and this? Done. https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder... webrtc/video/vie_encoder_unittest.cc:595: EXPECT_EQ(2, stats.number_of_cpu_adapt_changes); On 2016/11/17 21:23:38, perkj_webrtc wrote: > and this? Done. https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder... File webrtc/video/vie_encoder_unittest.cc (right): https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder... webrtc/video/vie_encoder_unittest.cc:554: EXPECT_FALSE(stats.cpu_limited_resolution); On 2016/11/17 21:23:38, perkj_webrtc wrote: > Why these changes? Now you dont test that switching source after cpu adaptation > keeps the adaptation. Sorry, this must've gotten lost somewhere in the rebase process. Fixed. https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder... webrtc/video/vie_encoder_unittest.cc:619: TEST_F(ViEEncoderTest, ScalingUpAndDownDoesNothingWithMaintainResolution) { On 2016/11/17 21:23:38, perkj_webrtc wrote: > LowQualityWhenScalingDisabled? I think the current name better describes what this is testing. https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video/vie_encoder... webrtc/video/vie_encoder_unittest.cc:639: const auto last_pixel_count = *video_source_.sink_wants().max_pixel_count; On 2016/11/17 21:23:38, perkj_webrtc wrote: > nit const int last_pix... Done. https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video_encoder.h File webrtc/video_encoder.h (right): https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video_encoder.h#n... webrtc/video_encoder.h:73: struct QPThresholds { On 2016/11/17 16:12:57, stefan-webrtc (holmer) wrote: > QpThresholds Done. https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video_encoder.h#n... webrtc/video_encoder.h:185: virtual void OnDroppedFrame() {} On 2016/11/17 16:12:57, stefan-webrtc (holmer) wrote: > TODO remove. Should this be removed from the interface? If so, I don't think it should be done as part of this CL.
https://codereview.webrtc.org/2398963003/diff/700001/webrtc/video/vie_encoder.cc File webrtc/video/vie_encoder.cc (right): https://codereview.webrtc.org/2398963003/diff/700001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:411: LOG(LS_INFO) << "Initializing quality scaler."; nit: I think you should remove this log. It will be printed every time the input resolution change due to that the quality scaler orders it to. https://codereview.webrtc.org/2398963003/diff/700001/webrtc/video/vie_encoder... File webrtc/video/vie_encoder_unittest.cc (right): https://codereview.webrtc.org/2398963003/diff/700001/webrtc/video/vie_encoder... webrtc/video/vie_encoder_unittest.cc:725: EXPECT_EQ(video_source_.sink_wants().max_pixel_count, last_pixel_count); Why do you expect max_pixel_count set if the degradation preference is set to MaintainResolution? Sink want should be unknown then. o, I see this is the previous video source sink wants not new_video_source. Sorry but I dont understand what this tests. you have switched source and check things on the old source?
https://codereview.webrtc.org/2398963003/diff/700001/webrtc/video/vie_encoder.cc File webrtc/video/vie_encoder.cc (right): https://codereview.webrtc.org/2398963003/diff/700001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.cc:411: LOG(LS_INFO) << "Initializing quality scaler."; On 2016/11/22 19:04:16, perkj_webrtc wrote: > nit: I think you should remove this log. It will be printed every time the input > resolution change due to that the quality scaler orders it to. Done. https://codereview.webrtc.org/2398963003/diff/700001/webrtc/video/vie_encoder... File webrtc/video/vie_encoder_unittest.cc (right): https://codereview.webrtc.org/2398963003/diff/700001/webrtc/video/vie_encoder... webrtc/video/vie_encoder_unittest.cc:725: EXPECT_EQ(video_source_.sink_wants().max_pixel_count, last_pixel_count); On 2016/11/22 19:04:16, perkj_webrtc wrote: > Why do you expect max_pixel_count set if the degradation preference is set to > MaintainResolution? Sink want should be unknown then. > o, I see this is the previous video source sink wants not new_video_source. > > Sorry but I dont understand what this tests. > > you have switched source and check things on the old source? These are all good questions, I'm not exactly sure what I was intending here, but it looks like I didn't finish implementing the test. Fixed.
VIE encoder lgtm https://codereview.webrtc.org/2398963003/diff/720001/webrtc/video/vie_encoder... File webrtc/video/vie_encoder_unittest.cc (right): https://codereview.webrtc.org/2398963003/diff/720001/webrtc/video/vie_encoder... webrtc/video/vie_encoder_unittest.cc:691: int frame_width = 1280; Can we remove line 691 to 707 and move the whole test to just below ResolutionSinkWantsResetOnSetSourceWithDisabledResolutionScaling and maybe call it ResolutionSinkWantsUnaffectedWithDisabledResolutionScaling ? Or remove "Resolution" from both names. https://codereview.webrtc.org/2398963003/diff/720001/webrtc/video/vie_encoder... webrtc/video/vie_encoder_unittest.cc:733: Also test that CPUadaptation does nothing when VideoSendStream::DegradationPreference::kMaintainResolution is set.
https://codereview.webrtc.org/2398963003/diff/680001/webrtc/modules/video_cod... File webrtc/modules/video_coding/utility/quality_scaler.cc (right): https://codereview.webrtc.org/2398963003/diff/680001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:65: class QualityScaler::CheckQPTask : public rtc::QueuedTask { On 2016/11/21 13:06:52, kthelgason wrote: > On 2016/11/17 16:12:57, stefan-webrtc (holmer) wrote: > > Could you add a comment somewhere why we decide to complicate the code by > using > > a task queue? This class is fairly simple and it's not obvious to me from > > reading the code what the task queue actually adds, e.g., why are we not > running > > CheckQP on every reported QP? > > Well, it seems logical that the QualityScaler and the CpuOveruseAdaptor should > use the same interface for adjusting the source resolution. That interface is > asynchronous and so this class needs to run on the right task queue to use it. > > Seems easier to complicate the QualityScaler code and keep ViEEncoder the same, > than to introduce another path to set scaling preferences. > > Anyway, this is mentioned in the CL description to some extent, perhaps not > clearly. I'm mostly asking if we should comment on why somewhere here to make it a bit more clear? https://codereview.webrtc.org/2398963003/diff/680001/webrtc/modules/video_cod... webrtc/modules/video_coding/utility/quality_scaler.cc:149: ReportQPHigh(); On 2016/11/21 13:06:52, kthelgason wrote: > On 2016/11/17 16:12:57, stefan-webrtc (holmer) wrote: > > This is a bit weird I think, why do we report high qp if the frame drop rate > is > > high? Should probably rename the method. > > You're right. This is actually unused now, as framedrop is never reported to the > QualityScaler. Perhaps it would be better to just remove the related code for > now. Does that mean this is a regression compared to when the QS was integrated with the encoder wrappers? https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video_encoder.h File webrtc/video_encoder.h (right): https://codereview.webrtc.org/2398963003/diff/680001/webrtc/video_encoder.h#n... webrtc/video_encoder.h:185: virtual void OnDroppedFrame() {} On 2016/11/21 13:06:53, kthelgason wrote: > On 2016/11/17 16:12:57, stefan-webrtc (holmer) wrote: > > TODO remove. > > Should this be removed from the interface? If so, I don't think it should be > done as part of this CL. I thought it was only used for quality scaling? If it's not used for anything else I don't see a reason to keep it.
On 2016/11/24 09:36:55, stefan-webrtc (holmer) wrote: > I'm mostly asking if we should comment on why somewhere here to make it a bit > more clear? I think if I were new to the codebase at this point, seeing the usage of the two classes and their implementations, it would make a lot of sense to me. More, even, than the way it was before where they are completely independent. However, I'm not at all opposed to adding a comment at the top of the QualityScaler class that outlines what it does and why it's implemented this way. > Does that mean this is a regression compared to when the QS was integrated with > the encoder wrappers? I don't think so. As far as I can tell, these OnDroppedFrame methods are not used in the codebase as it is today. At least I can't find any usage of them outside of the tests. > I thought it was only used for quality scaling? If it's not used for anything > else I don't see a reason to keep it. Yes, you're right. I will remove these.
On 2016/11/24 13:45:47, kthelgason wrote: > On 2016/11/24 09:36:55, stefan-webrtc (holmer) wrote: > > I'm mostly asking if we should comment on why somewhere here to make it a bit > > more clear? > > I think if I were new to the codebase at this point, seeing the usage of the > two classes and their implementations, it would make a lot of sense to me. > More, even, than the way it was before where they are completely independent. > > However, I'm not at all opposed to adding a comment at the top of the > QualityScaler class that outlines what it does and why it's implemented this > way. > > > > Does that mean this is a regression compared to when the QS was integrated > with > > the encoder wrappers? > > I don't think so. As far as I can tell, these OnDroppedFrame methods are not > used in the codebase as it is today. At least I can't find any usage of them > outside of the tests. https://cs.chromium.org/chromium/src/third_party/webrtc/modules/video_coding/... Seems like it's called when ever a frame is dropped by the frame dropper which resides right outside the encoder, which has the job of ensuring that the encoders doesn't overshoot target bitrate too badly. > > > I thought it was only used for quality scaling? If it's not used for anything > > else I don't see a reason to keep it. > > Yes, you're right. I will remove these.
On 2016/11/24 14:00:41, stefan-webrtc (holmer) wrote: > Seems like it's called when ever a frame is dropped by the frame dropper which > resides right outside the encoder, which has the job of ensuring that the > encoders doesn't overshoot target bitrate too badly. The latest patchset adds a callback to ViEEncoder on dropped frames and uses that to report them to the QualityScaler. I also removed OnDroppedFrame from the VideoEncoder interface.
Mostly looks good now, a test might be is missing though. https://codereview.webrtc.org/2398963003/diff/740001/webrtc/modules/video_cod... File webrtc/modules/video_coding/video_coding_impl.h (right): https://codereview.webrtc.org/2398963003/diff/740001/webrtc/modules/video_cod... webrtc/modules/video_coding/video_coding_impl.h:116: EncodedImageCallback *post_encode_callback_; EncodedImageCallback* const post_encode_callback_; https://codereview.webrtc.org/2398963003/diff/740001/webrtc/video/vie_encoder.h File webrtc/video/vie_encoder.h (right): https://codereview.webrtc.org/2398963003/diff/740001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.h:165: void OnDroppedFrame() override; Should / can we add tests for this which would have been a regression if I hadn't seen it?
https://codereview.webrtc.org/2398963003/diff/740001/webrtc/modules/video_cod... File webrtc/modules/video_coding/video_coding_impl.h (right): https://codereview.webrtc.org/2398963003/diff/740001/webrtc/modules/video_cod... webrtc/modules/video_coding/video_coding_impl.h:116: EncodedImageCallback *post_encode_callback_; On 2016/11/25 at 10:45:25, stefan-webrtc (holmer) wrote: > EncodedImageCallback* const post_encode_callback_; Done. https://codereview.webrtc.org/2398963003/diff/740001/webrtc/video/vie_encoder.h File webrtc/video/vie_encoder.h (right): https://codereview.webrtc.org/2398963003/diff/740001/webrtc/video/vie_encoder... webrtc/video/vie_encoder.h:165: void OnDroppedFrame() override; On 2016/11/25 at 10:45:25, stefan-webrtc (holmer) wrote: > Should / can we add tests for this which would have been a regression if I hadn't seen it? As to whether we should, I think the answer is yes. I looked at adding tests but it seems quite hard, especially if we want to isolate this feature. Since most dependencies in this chain are not injected it's difficult to break it in a test and insert a mock. Testing this in a sensible way would require a pretty big refactoring, at least I don't see another way. I'd love to be wrong though!
On 2016/11/25 12:34:01, kthelgason wrote: > https://codereview.webrtc.org/2398963003/diff/740001/webrtc/modules/video_cod... > File webrtc/modules/video_coding/video_coding_impl.h (right): > > https://codereview.webrtc.org/2398963003/diff/740001/webrtc/modules/video_cod... > webrtc/modules/video_coding/video_coding_impl.h:116: EncodedImageCallback > *post_encode_callback_; > On 2016/11/25 at 10:45:25, stefan-webrtc (holmer) wrote: > > EncodedImageCallback* const post_encode_callback_; > > Done. > > https://codereview.webrtc.org/2398963003/diff/740001/webrtc/video/vie_encoder.h > File webrtc/video/vie_encoder.h (right): > > https://codereview.webrtc.org/2398963003/diff/740001/webrtc/video/vie_encoder... > webrtc/video/vie_encoder.h:165: void OnDroppedFrame() override; > On 2016/11/25 at 10:45:25, stefan-webrtc (holmer) wrote: > > Should / can we add tests for this which would have been a regression if I > hadn't seen it? > > As to whether we should, I think the answer is yes. I looked at adding tests but > it seems quite hard, especially if we want to isolate this feature. Since most > dependencies in this chain are not injected it's difficult to break it in a test > and insert a mock. Testing this in a sensible way would require a pretty big > refactoring, at least I don't see another way. I'd love to be wrong though! I would have done it in video_send_stream_tests.cc, but it may not be easily done there either... lgtm
The CQ bit was checked by kthelgason@webrtc.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.webrtc.org/...
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: This issue passed the CQ dry run.
The CQ bit was checked by kthelgason@webrtc.org
The patchset sent to the CQ was uploaded after l-g-t-m from magjed@webrtc.org, sprang@webrtc.org, perkj@webrtc.org, stefan@webrtc.org Link to the patchset: https://codereview.webrtc.org/2398963003/#ps780001 (title: "rebase")
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.webrtc.org/...
CQ is committing da patch. Bot data: {"patchset_id": 780001, "attempt_start_ts": 1480412525596580, "parent_rev": "d03c8460a29b6c21c61fed75b19d82a83ca87ad4", "commit_rev": "01b33f67f50cffd5a44d57f12596a67908b7dd63"}
Message was sent while issue was closed.
Description was changed from ========== Move usage of QualityScaler to ViEEncoder. This brings QualityScaler much more in line with OveruseFrameDetector. The two classes are conceptually similar, and should be used in the same way. The biggest changes in this CL are: - Quality scaling is now only done in ViEEncoder and not in each encoder implementation separately. - QualityScaler now checks the average QP asynchronously, instead of having to be polled on each frame. - QualityScaler is no longer responsible for actually scaling the frames, but has a callback to ViEEncoder that it uses to express it's desire for lower resolution. BUG=webrtc:6495 ========== to ========== Move usage of QualityScaler to ViEEncoder. This brings QualityScaler much more in line with OveruseFrameDetector. The two classes are conceptually similar, and should be used in the same way. The biggest changes in this CL are: - Quality scaling is now only done in ViEEncoder and not in each encoder implementation separately. - QualityScaler now checks the average QP asynchronously, instead of having to be polled on each frame. - QualityScaler is no longer responsible for actually scaling the frames, but has a callback to ViEEncoder that it uses to express it's desire for lower resolution. BUG=webrtc:6495 ==========
Message was sent while issue was closed.
Committed patchset #37 (id:780001)
Message was sent while issue was closed.
Description was changed from ========== Move usage of QualityScaler to ViEEncoder. This brings QualityScaler much more in line with OveruseFrameDetector. The two classes are conceptually similar, and should be used in the same way. The biggest changes in this CL are: - Quality scaling is now only done in ViEEncoder and not in each encoder implementation separately. - QualityScaler now checks the average QP asynchronously, instead of having to be polled on each frame. - QualityScaler is no longer responsible for actually scaling the frames, but has a callback to ViEEncoder that it uses to express it's desire for lower resolution. BUG=webrtc:6495 ========== to ========== Move usage of QualityScaler to ViEEncoder. This brings QualityScaler much more in line with OveruseFrameDetector. The two classes are conceptually similar, and should be used in the same way. The biggest changes in this CL are: - Quality scaling is now only done in ViEEncoder and not in each encoder implementation separately. - QualityScaler now checks the average QP asynchronously, instead of having to be polled on each frame. - QualityScaler is no longer responsible for actually scaling the frames, but has a callback to ViEEncoder that it uses to express it's desire for lower resolution. BUG=webrtc:6495 Committed: https://crrev.com/876222f77dfc640c852d5bb14f0aacf0f74e5690 Cr-Commit-Position: refs/heads/master@{#15286} ==========
Message was sent while issue was closed.
Patchset 37 (id:??) landed as https://crrev.com/876222f77dfc640c852d5bb14f0aacf0f74e5690 Cr-Commit-Position: refs/heads/master@{#15286} |