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

Unified Diff: webrtc/test/frame_generator_capturer.cc

Issue 2716643002: Add framerate to VideoSinkWants and ability to signal on overuse (Closed)
Patch Set: Addressed comments 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..e12f48527dc5bf31f9449b9279f6764a33028581 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"
@@ -25,14 +27,12 @@ FrameGeneratorCapturer* FrameGeneratorCapturer::Create(int width,
int height,
int target_fps,
Clock* clock) {
- FrameGeneratorCapturer* capturer = new FrameGeneratorCapturer(
- clock, FrameGenerator::CreateSquareGenerator(width, height), target_fps);
- if (!capturer->Init()) {
- delete capturer;
- return NULL;
- }
+ std::unique_ptr<FrameGeneratorCapturer> capturer(new FrameGeneratorCapturer(
+ clock, FrameGenerator::CreateSquareGenerator(width, height), target_fps));
+ if (!capturer->Init())
+ return nullptr;
- return capturer;
+ return capturer.release();
}
FrameGeneratorCapturer* FrameGeneratorCapturer::CreateFromYuvFile(
@@ -41,16 +41,15 @@ FrameGeneratorCapturer* FrameGeneratorCapturer::CreateFromYuvFile(
size_t height,
int target_fps,
Clock* clock) {
- FrameGeneratorCapturer* capturer = new FrameGeneratorCapturer(
- clock, FrameGenerator::CreateFromYuvFile(
- std::vector<std::string>(1, file_name), width, height, 1),
- target_fps);
- if (!capturer->Init()) {
- delete capturer;
- return NULL;
- }
-
- return capturer;
+ std::unique_ptr<FrameGeneratorCapturer> capturer(new FrameGeneratorCapturer(
+ clock,
+ FrameGenerator::CreateFromYuvFile(std::vector<std::string>(1, file_name),
+ width, height, 1),
+ target_fps));
+ if (!capturer->Init())
+ return nullptr;
+
+ return capturer.release();
}
FrameGeneratorCapturer::FrameGeneratorCapturer(
@@ -72,7 +71,6 @@ FrameGeneratorCapturer::FrameGeneratorCapturer(
FrameGeneratorCapturer::~FrameGeneratorCapturer() {
Stop();
-
thread_.Stop();
}
@@ -84,11 +82,13 @@ void FrameGeneratorCapturer::SetFakeRotation(VideoRotation rotation) {
bool FrameGeneratorCapturer::Init() {
// This check is added because frame_generator_ might be file based and should
// not crash because a file moved.
- if (frame_generator_.get() == NULL)
+ if (frame_generator_.get() == nullptr)
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 +100,8 @@ bool FrameGeneratorCapturer::Run(void* obj) {
}
void FrameGeneratorCapturer::InsertFrame() {
+ int64_t start_tims_ms = rtc::TimeMillis();
+ int64_t sleep_time_ms;
{
rtc::CritScope cs(&lock_);
if (sending_) {
@@ -109,11 +111,25 @@ void FrameGeneratorCapturer::InsertFrame() {
if (first_frame_capture_time_ == -1) {
first_frame_capture_time_ = frame->ntp_time_ms();
}
- if (sink_)
- sink_->OnFrame(*frame);
+
+ if (sink_) {
+ rtc::Optional<VideoFrame> out_frame = AdaptFrame(*frame);
+ if (out_frame)
+ sink_->OnFrame(*out_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);
}
void FrameGeneratorCapturer::Start() {
@@ -145,6 +161,15 @@ void FrameGeneratorCapturer::AddOrUpdateSink(
sink_ = sink;
if (sink_wants_observer_)
sink_wants_observer_->OnSinkWantsChanged(sink, wants);
+
+ // Handle framerate within this class, just pass on resolution for possible
+ // adaptation.
+ rtc::VideoSinkWants resolution_wants = wants;
+ resolution_wants.max_framerate_fps = std::numeric_limits<int>::max();
+ VideoCapturer::AddOrUpdateSink(sink, resolution_wants);
+
+ if (wants.max_framerate_fps < target_fps_)
+ wanted_fps_.emplace(wants.max_framerate_fps);
}
void FrameGeneratorCapturer::RemoveSink(

Powered by Google App Engine
This is Rietveld 408576698