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

Unified Diff: webrtc/test/frame_generator_capturer.cc

Issue 2716643002: Add framerate to VideoSinkWants and ability to signal on overuse (Closed)
Patch Set: windows warning Created 3 years, 9 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/test/frame_generator_capturer.cc
diff --git a/webrtc/test/frame_generator_capturer.cc b/webrtc/test/frame_generator_capturer.cc
index 00efbc8b40b467e2248169349ac498997b8de3d2..f0b205624a58ad45d966ecae7588ad393c9f680b 100644
--- a/webrtc/test/frame_generator_capturer.cc
+++ b/webrtc/test/frame_generator_capturer.cc
@@ -10,8 +10,10 @@
#include "webrtc/test/frame_generator_capturer.h"
+#include "webrtc/api/video/i420_buffer.h"
#include "webrtc/base/criticalsection.h"
#include "webrtc/base/platform_thread.h"
+#include "webrtc/media/base/videoadapter.h"
#include "webrtc/system_wrappers/include/clock.h"
#include "webrtc/system_wrappers/include/event_wrapper.h"
#include "webrtc/system_wrappers/include/sleep.h"
@@ -64,6 +66,7 @@ FrameGeneratorCapturer::FrameGeneratorCapturer(
tick_(EventTimerWrapper::Create()),
thread_(FrameGeneratorCapturer::Run, this, "FrameGeneratorCapturer"),
frame_generator_(std::move(frame_generator)),
+ video_adpter_(new cricket::VideoAdapter()),
target_fps_(target_fps),
first_frame_capture_time_(-1) {
RTC_DCHECK(frame_generator_);
@@ -87,8 +90,10 @@ bool FrameGeneratorCapturer::Init() {
if (frame_generator_.get() == NULL)
return false;
- if (!tick_->StartTimer(true, 1000 / target_fps_))
- return false;
+ {
+ rtc::CritScope cs(&lock_);
+ RTC_DCHECK(tick_->StartTimer(false, 1000 / target_fps_));
+ }
thread_.Start();
thread_.SetPriority(rtc::kHighPriority);
return true;
@@ -100,6 +105,8 @@ bool FrameGeneratorCapturer::Run(void* obj) {
}
void FrameGeneratorCapturer::InsertFrame() {
+ int64_t start_tims_ms = rtc::TimeMillis();
+ int64_t sleep_time_ms;
kthelgason 2017/03/14 10:01:20 can this be initialized here, rather than further
sprang_webrtc 2017/03/14 14:15:02 Need to hold the lock then, so made sense to me to
{
rtc::CritScope cs(&lock_);
if (sending_) {
@@ -109,11 +116,40 @@ void FrameGeneratorCapturer::InsertFrame() {
if (first_frame_capture_time_ == -1) {
first_frame_capture_time_ = frame->ntp_time_ms();
}
- if (sink_)
- sink_->OnFrame(*frame);
+
+ if (sink_) {
+ int cropped_width = 0;
+ int cropped_height = 0;
kthelgason 2017/03/14 10:01:20 these look unused
sprang_webrtc 2017/03/14 14:15:02 They're out params from video_adpter_->AdaptFrameR
+ int out_width = 0;
+ int out_height = 0;
+ video_adpter_->AdaptFrameResolution(
+ frame->width(), frame->height(), frame->timestamp_us() * 1000,
+ &cropped_width, &cropped_height, &out_width, &out_height);
+
+ if (out_height != frame->height() || out_width != frame->width()) {
+ rtc::scoped_refptr<I420Buffer> scaled_buffer =
+ I420Buffer::Create(out_width, out_height);
+ scaled_buffer->ScaleFrom(*frame->video_frame_buffer().get());
+ VideoFrame adapted_frame(scaled_buffer, kVideoRotation_0,
+ frame->timestamp_us());
+ sink_->OnFrame(adapted_frame);
+ } else {
+ sink_->OnFrame(*frame);
+ }
+ }
+ }
+
+ if (wanted_fps_) {
+ sleep_time_ms = 1000 / *wanted_fps_;
+ } else {
+ sleep_time_ms = 1000 / target_fps_;
}
}
- tick_->Wait(WEBRTC_EVENT_INFINITE);
+
+ int64_t correction_delta = rtc::TimeMillis() - start_tims_ms;
+ sleep_time_ms -= correction_delta;
+ if (sleep_time_ms > 0)
+ tick_->Wait(sleep_time_ms);
kthelgason 2017/03/14 10:01:20 the use of `tick` is behind a lock in `Init` but n
sprang_webrtc 2017/03/14 14:15:02 The lock is for |target_fps_|, not |tick_|.
}
void FrameGeneratorCapturer::Start() {
@@ -145,6 +181,10 @@ void FrameGeneratorCapturer::AddOrUpdateSink(
sink_ = sink;
if (sink_wants_observer_)
sink_wants_observer_->OnSinkWantsChanged(sink, wants);
+
+ video_adpter_->OnResolutionFramerateRequest(
+ wants.target_pixel_count, wants.max_pixel_count, rtc::Optional<int>());
+ wanted_fps_ = wants.max_framerate_fps;
}
void FrameGeneratorCapturer::RemoveSink(

Powered by Google App Engine
This is Rietveld 408576698