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

Unified Diff: webrtc/video/vie_encoder.h

Issue 2304363002: Let ViEEncoder express resolution requests as Sinkwants (Closed)
Patch Set: Rebased and fixed. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/video/vie_encoder.h
diff --git a/webrtc/video/vie_encoder.h b/webrtc/video/vie_encoder.h
index 68f043e1c5818e876b5e0166deab1dbc785ab325..6c77823a7b2285c13129ee5191221d084a7bb14b 100644
--- a/webrtc/video/vie_encoder.h
+++ b/webrtc/video/vie_encoder.h
@@ -60,11 +60,13 @@ class ViEEncoder : public rtc::VideoSinkInterface<VideoFrame>,
int min_transmit_bitrate_bps) = 0;
};
+ // Down grade resolution at most 2 times for CPU reasons.
+ static const int kMaxCpuDowngrades = 2;
+
ViEEncoder(uint32_t number_of_cores,
SendStatisticsProxy* stats_proxy,
const webrtc::VideoSendStream::Config::EncoderSettings& settings,
rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback,
- LoadObserver* overuse_callback,
EncodedFrameObserver* encoder_timing);
~ViEEncoder();
// RegisterProcessThread register |module_process_thread| with those objects
@@ -74,8 +76,16 @@ class ViEEncoder : public rtc::VideoSinkInterface<VideoFrame>,
void RegisterProcessThread(ProcessThread* module_process_thread);
void DeRegisterProcessThread();
- void SetSource(rtc::VideoSourceInterface<VideoFrame>* source);
- void SetSink(EncoderSink* sink);
+ // Sets the source that will provide I420 video frames.
+ // |disable_resolution| means that this encoder will not request |source| to
+ // lower the resolution due to CPU adaptation.
+ void SetSource(rtc::VideoSourceInterface<VideoFrame>* source,
+ bool disable_resolution_scaling);
+
+ // Sets the |sink| that gets the encoded frames. |rotation_applied| means
+ // that the source must support rotation. Only set |rotation_applied| if the
+ // remote side does not support the rotation extension.
+ void SetSink(EncoderSink* sink, bool rotation_applied);
// TODO(perkj): Can we remove VideoCodec.startBitrate ?
void SetStartBitrate(int start_bitrate_bps);
@@ -98,6 +108,16 @@ class ViEEncoder : public rtc::VideoSinkInterface<VideoFrame>,
uint8_t fraction_lost,
int64_t round_trip_time_ms);
+ protected:
+ // Used for testing. For example the |CpuOveruseObserver| methods must be
+ // called on |encoder_queue_|.
+ rtc::TaskQueue* encoder_queue() { return &encoder_queue_; }
+
+ // webrtc::CpuOveruseObserver implementation.
+ // These methods are protected for easier testing.
+ void OveruseDetected() override;
+ void NormalUsage() override;
+
private:
class ConfigureEncoderTask;
class EncodeTask;
@@ -138,10 +158,6 @@ class ViEEncoder : public rtc::VideoSinkInterface<VideoFrame>,
const CodecSpecificInfo* codec_specific_info,
const RTPFragmentationHeader* fragmentation) override;
- // webrtc::CpuOveruseObserver implementation.
- void OveruseDetected() override;
- void NormalUsage() override;
-
bool EncoderPaused() const;
void TraceFrameDropStart();
void TraceFrameDropEnd();
@@ -156,9 +172,8 @@ class ViEEncoder : public rtc::VideoSinkInterface<VideoFrame>,
const VideoCodecType codec_type_;
vcm::VideoSender video_sender_ ACCESS_ON(&encoder_queue_);
-
+ bool disable_resolution_scaling_ ACCESS_ON(&encoder_queue_);
OveruseFrameDetector overuse_detector_ ACCESS_ON(&encoder_queue_);
- LoadObserver* const load_observer_ ACCESS_ON(&encoder_queue_);
SendStatisticsProxy* const stats_proxy_;
rtc::VideoSinkInterface<VideoFrame>* const pre_encode_callback_;
@@ -188,6 +203,16 @@ class ViEEncoder : public rtc::VideoSinkInterface<VideoFrame>,
bool has_received_rpsi_ ACCESS_ON(&encoder_queue_);
uint64_t picture_id_rpsi_ ACCESS_ON(&encoder_queue_);
Clock* const clock_;
+ // Counter used for deciding if the video resolution is currently
+ // restricted by CPU usage. It is reset if |source_| is changed.
+ int cpu_restricted_counter_; // ACCESS_ON(&encoder_queue_);
+
+ int last_frame_width_; // ACCESS_ON(&encoder_queue_);
+ int last_frame_height_; // ACCESS_ON(&encoder_queue_);
+ // Resolution has been requested to be less than |max_pixel_count_|.
+ rtc::Optional<int> max_pixel_count_; // ACCESS_ON(&encoder_queue_);
+ // Resolution has been requested to higher than |max_pixel_count_step_up_|.
+ rtc::Optional<int> max_pixel_count_step_up_; // ACCESS_ON(&encoder_queue_);
rtc::RaceChecker incoming_frame_race_checker_;
Atomic32 posted_frames_waiting_for_encode_;

Powered by Google App Engine
This is Rietveld 408576698