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

Unified Diff: webrtc/test/fake_encoder.cc

Issue 1682253005: Fix SetRates for encoders with internal sources. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: sync Created 4 years, 8 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
« webrtc/test/fake_encoder.h ('K') | « webrtc/test/fake_encoder.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/test/fake_encoder.cc
diff --git a/webrtc/test/fake_encoder.cc b/webrtc/test/fake_encoder.cc
index 72df40f9a51690f3b81bd0c25f30cab36c23dff0..e3f8b3d0cea64c15b191ec16ca1da822f381ca11 100644
--- a/webrtc/test/fake_encoder.cc
+++ b/webrtc/test/fake_encoder.cc
@@ -203,5 +203,81 @@ int32_t DelayedEncoder::Encode(const VideoFrame& input_image,
SleepMs(delay_ms_);
return FakeEncoder::Encode(input_image, codec_specific_info, frame_types);
}
+
+InternalSourceEncoder::InternalSourceEncoder(Clock* clock,
+ uint32_t frame_period_ms,
+ uint32_t first_frame_timestamp_ms)
+ : test::FakeEncoder(clock),
+ thread_(EncoderProcess, this, "InternalSourceEncoderProcess"),
+ frame_period_ms_(frame_period_ms),
+ current_frame_timestamp_ms_(first_frame_timestamp_ms),
+ shutting_down_(false),
+ next_frame_type_(kVideoFrameKey) {}
+
+int32_t InternalSourceEncoder::InitEncode(const VideoCodec* config,
+ int32_t number_of_cores,
+ size_t max_payload_size) {
+ int32_t result =
+ test::FakeEncoder::InitEncode(config, number_of_cores, max_payload_size);
+ thread_.Start();
+ return result;
+}
+
+bool InternalSourceEncoder::EncoderProcess(void* encoder_void_ptr) {
+ InternalSourceEncoder* encoder =
+ static_cast<InternalSourceEncoder*>(encoder_void_ptr);
+ SleepMs(encoder->frame_period_ms_);
+ return encoder->EncodeFrame();
+}
+
+bool InternalSourceEncoder::EncodeFrame() {
+ FrameType frame_type;
+ {
+ rtc::CritScope crit(&lock_);
+ if (shutting_down_) {
+ return false;
+ }
+ frame_type = next_frame_type_;
+ // Reset the frame type, now that we've consumed a keyframe request (if it
+ // was kVideoFrameKey).
+ next_frame_type_ = kVideoFrameDelta;
+ }
+ VideoFrame input_image(rtc::scoped_refptr<webrtc::VideoFrameBuffer>(),
+ current_frame_timestamp_ms_ * 90,
+ current_frame_timestamp_ms_, kVideoRotation_0);
+ current_frame_timestamp_ms_ += frame_period_ms_;
+ std::vector<FrameType> frame_types{frame_type};
+
+ // Call the base class explicitly, to skip our no-op override.
+ test::FakeEncoder::Encode(input_image, nullptr, &frame_types);
+ return true;
+}
+
+int32_t InternalSourceEncoder::Release() {
+ {
+ rtc::CritScope crit(&lock_);
+ shutting_down_ = true;
+ }
+ thread_.Stop();
+ return test::FakeEncoder::Release();
+}
+
+int32_t InternalSourceEncoder::Encode(
+ const VideoFrame& input_image,
+ const CodecSpecificInfo* codec_specific_info,
+ const std::vector<FrameType>* frame_types) {
+ // Check for keyframe requests.
+ if (frame_types) {
+ for (FrameType type : *frame_types) {
+ if (type == kVideoFrameKey) {
+ rtc::CritScope crit(&lock_);
+ next_frame_type_ = kVideoFrameKey;
+ break;
+ }
+ }
+ }
+ return WEBRTC_VIDEO_CODEC_OK;
+}
+
} // namespace test
} // namespace webrtc
« webrtc/test/fake_encoder.h ('K') | « webrtc/test/fake_encoder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698