2013-05-29 13:41:03 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef TEST_FRAME_GENERATOR_CAPTURER_H_
|
|
|
|
|
#define TEST_FRAME_GENERATOR_CAPTURER_H_
|
2013-05-29 13:41:03 +00:00
|
|
|
|
2016-05-01 14:53:46 -07:00
|
|
|
#include <memory>
|
2015-02-18 12:46:06 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
2019-02-28 13:30:04 +01:00
|
|
|
#include "api/task_queue/task_queue_factory.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "api/video/video_frame.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/critical_section.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/task_queue.h"
|
2019-07-31 17:30:03 +02:00
|
|
|
#include "rtc_base/task_utils/repeating_task.h"
|
2018-03-09 15:03:26 -08:00
|
|
|
#include "test/frame_generator.h"
|
2018-08-13 14:24:58 +02:00
|
|
|
#include "test/test_video_capturer.h"
|
2013-05-29 13:41:03 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
namespace test {
|
2019-07-31 17:30:03 +02:00
|
|
|
namespace frame_gen_cap_impl {
|
|
|
|
|
template <typename T>
|
|
|
|
|
class AutoOpt : public absl::optional<T> {
|
|
|
|
|
public:
|
|
|
|
|
T* operator->() {
|
|
|
|
|
if (!absl::optional<T>::has_value())
|
|
|
|
|
this->emplace(T());
|
|
|
|
|
return absl::optional<T>::operator->();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
} // namespace frame_gen_cap_impl
|
|
|
|
|
struct FrameGeneratorCapturerConfig {
|
|
|
|
|
struct SquaresVideo {
|
|
|
|
|
int framerate = 30;
|
2019-10-04 09:25:06 +02:00
|
|
|
FrameGenerator::OutputType pixel_format = FrameGenerator::OutputType::kI420;
|
2019-07-31 17:30:03 +02:00
|
|
|
int width = 320;
|
|
|
|
|
int height = 180;
|
|
|
|
|
int num_squares = 10;
|
|
|
|
|
};
|
2013-05-29 13:41:03 +00:00
|
|
|
|
2019-07-31 17:30:03 +02:00
|
|
|
struct SquareSlides {
|
|
|
|
|
int framerate = 30;
|
|
|
|
|
TimeDelta change_interval = TimeDelta::seconds(10);
|
|
|
|
|
int width = 1600;
|
|
|
|
|
int height = 1200;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct VideoFile {
|
|
|
|
|
int framerate = 30;
|
|
|
|
|
std::string name;
|
|
|
|
|
// Must be set to width and height of the source video file.
|
|
|
|
|
int width = 0;
|
|
|
|
|
int height = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct ImageSlides {
|
|
|
|
|
int framerate = 30;
|
|
|
|
|
TimeDelta change_interval = TimeDelta::seconds(10);
|
|
|
|
|
struct Crop {
|
|
|
|
|
TimeDelta scroll_duration = TimeDelta::seconds(0);
|
|
|
|
|
absl::optional<int> width;
|
|
|
|
|
absl::optional<int> height;
|
|
|
|
|
} crop;
|
|
|
|
|
int width = 1850;
|
|
|
|
|
int height = 1110;
|
|
|
|
|
std::vector<std::string> paths = {
|
|
|
|
|
"web_screenshot_1850_1110",
|
|
|
|
|
"presentation_1850_1110",
|
|
|
|
|
"photo_1850_1110",
|
|
|
|
|
"difficult_photo_1850_1110",
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
frame_gen_cap_impl::AutoOpt<SquaresVideo> squares_video;
|
|
|
|
|
frame_gen_cap_impl::AutoOpt<SquareSlides> squares_slides;
|
|
|
|
|
frame_gen_cap_impl::AutoOpt<VideoFile> video_file;
|
|
|
|
|
frame_gen_cap_impl::AutoOpt<ImageSlides> image_slides;
|
|
|
|
|
};
|
2013-05-29 13:41:03 +00:00
|
|
|
|
2018-08-13 14:24:58 +02:00
|
|
|
class FrameGeneratorCapturer : public TestVideoCapturer {
|
2013-05-29 13:41:03 +00:00
|
|
|
public:
|
2016-11-01 11:45:46 -07:00
|
|
|
class SinkWantsObserver {
|
|
|
|
|
public:
|
|
|
|
|
// OnSinkWantsChanged is called when FrameGeneratorCapturer::AddOrUpdateSink
|
|
|
|
|
// is called.
|
|
|
|
|
virtual void OnSinkWantsChanged(rtc::VideoSinkInterface<VideoFrame>* sink,
|
|
|
|
|
const rtc::VideoSinkWants& wants) = 0;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual ~SinkWantsObserver() {}
|
|
|
|
|
};
|
|
|
|
|
|
2019-04-23 13:45:12 +02:00
|
|
|
FrameGeneratorCapturer(Clock* clock,
|
|
|
|
|
std::unique_ptr<FrameGenerator> frame_generator,
|
|
|
|
|
int target_fps,
|
|
|
|
|
TaskQueueFactory& task_queue_factory);
|
2013-05-29 13:41:03 +00:00
|
|
|
virtual ~FrameGeneratorCapturer();
|
|
|
|
|
|
2019-07-31 17:30:03 +02:00
|
|
|
static std::unique_ptr<FrameGeneratorCapturer> Create(
|
|
|
|
|
Clock* clock,
|
|
|
|
|
TaskQueueFactory& task_queue_factory,
|
|
|
|
|
FrameGeneratorCapturerConfig::SquaresVideo config);
|
|
|
|
|
static std::unique_ptr<FrameGeneratorCapturer> Create(
|
|
|
|
|
Clock* clock,
|
|
|
|
|
TaskQueueFactory& task_queue_factory,
|
|
|
|
|
FrameGeneratorCapturerConfig::SquareSlides config);
|
|
|
|
|
static std::unique_ptr<FrameGeneratorCapturer> Create(
|
|
|
|
|
Clock* clock,
|
|
|
|
|
TaskQueueFactory& task_queue_factory,
|
|
|
|
|
FrameGeneratorCapturerConfig::VideoFile config);
|
|
|
|
|
static std::unique_ptr<FrameGeneratorCapturer> Create(
|
|
|
|
|
Clock* clock,
|
|
|
|
|
TaskQueueFactory& task_queue_factory,
|
|
|
|
|
FrameGeneratorCapturerConfig::ImageSlides config);
|
|
|
|
|
static std::unique_ptr<FrameGeneratorCapturer> Create(
|
|
|
|
|
Clock* clock,
|
|
|
|
|
TaskQueueFactory& task_queue_factory,
|
|
|
|
|
const FrameGeneratorCapturerConfig& config);
|
|
|
|
|
|
2018-12-14 13:35:32 +01:00
|
|
|
void Start();
|
|
|
|
|
void Stop();
|
2016-10-02 23:45:26 -07:00
|
|
|
void ChangeResolution(size_t width, size_t height);
|
2018-08-30 11:19:23 +02:00
|
|
|
void ChangeFramerate(int target_framerate);
|
2016-09-16 07:53:41 -07:00
|
|
|
|
2016-11-01 11:45:46 -07:00
|
|
|
void SetSinkWantsObserver(SinkWantsObserver* observer);
|
|
|
|
|
|
2016-09-16 07:53:41 -07:00
|
|
|
void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
|
|
|
|
|
const rtc::VideoSinkWants& wants) override;
|
|
|
|
|
void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override;
|
|
|
|
|
|
2015-08-03 04:38:41 -07:00
|
|
|
void ForceFrame();
|
2016-04-19 15:01:23 +02:00
|
|
|
void SetFakeRotation(VideoRotation rotation);
|
2018-12-12 11:17:43 +01:00
|
|
|
void SetFakeColorSpace(absl::optional<ColorSpace> color_space);
|
2013-05-29 13:41:03 +00:00
|
|
|
|
2014-04-24 22:10:24 +00:00
|
|
|
int64_t first_frame_capture_time() const { return first_frame_capture_time_; }
|
|
|
|
|
|
2013-05-29 13:41:03 +00:00
|
|
|
bool Init();
|
2015-02-18 12:46:06 +00:00
|
|
|
|
|
|
|
|
private:
|
2013-05-29 13:41:03 +00:00
|
|
|
void InsertFrame();
|
|
|
|
|
static bool Run(void* obj);
|
Reland of Add framerate to VideoSinkWants and ability to signal on overuse (patchset #1 id:1 of https://codereview.webrtc.org/2783183003/ )
Reason for revert:
Seem to be a flaky test rather than an issue with this cl. Creating reland, will add code to reduce flakiness to that test.
Original issue's description:
> Revert of Add framerate to VideoSinkWants and ability to signal on overuse (patchset #8 id:410001 of https://codereview.webrtc.org/2781433002/ )
>
> Reason for revert:
> This has resulted in failure of CallPerfTest.ReceivesCpuOveruseAndUnderuse test on the Win7 build bot https://build.chromium.org/p/client.webrtc.perf/builders/Win7/builds/1780
>
> Original issue's description:
> > Reland of Add framerate to VideoSinkWants and ability to signal on overuse (patchset #1 id:1 of https://codereview.webrtc.org/2764133002/ )
> >
> > Reason for revert:
> > Found issue with test case, will add fix to reland cl.
> >
> > Original issue's description:
> > > Revert of Add framerate to VideoSinkWants and ability to signal on overuse (patchset #14 id:250001 of https://codereview.webrtc.org/2716643002/ )
> > >
> > > Reason for revert:
> > > Breaks perf tests:
> > > https://build.chromium.org/p/client.webrtc.perf/builders/Win7/builds/1679
> > > https://build.chromium.org/p/client.webrtc.perf/builders/Android32%20Tests%20%28L%20Nexus5%29/builds/2325
> > >
> > > Original issue's description:
> > > > Add framerate to VideoSinkWants and ability to signal on overuse
> > > >
> > > > In ViEEncoder, try to reduce framerate instead of resolution if the
> > > > current degradation preference is maintain-resolution rather than
> > > > balanced.
> > > >
> > > > BUG=webrtc:4172
> > > >
> > > > Review-Url: https://codereview.webrtc.org/2716643002
> > > > Cr-Commit-Position: refs/heads/master@{#17327}
> > > > Committed: https://chromium.googlesource.com/external/webrtc/+/72acf2526177bb4dbb5103cd6e165eb4361a5ae6
> > >
> > > TBR=nisse@webrtc.org,magjed@webrtc.org,kthelgason@webrtc.org,ilnik@webrtc.org,stefan@webrtc.org,sprang@webrtc.org
> > > # Skipping CQ checks because original CL landed less than 1 days ago.
> > > NOPRESUBMIT=true
> > > NOTREECHECKS=true
> > > NOTRY=true
> > > BUG=webrtc:4172
> > >
> > > Review-Url: https://codereview.webrtc.org/2764133002
> > > Cr-Commit-Position: refs/heads/master@{#17331}
> > > Committed: https://chromium.googlesource.com/external/webrtc/+/8b45b11144c968b4173215c76f78c710c9a2ed0b
> >
> > TBR=nisse@webrtc.org,magjed@webrtc.org,kthelgason@webrtc.org,ilnik@webrtc.org,stefan@webrtc.org,skvlad@webrtc.org
> > # Not skipping CQ checks because original CL landed more than 1 days ago.
> > BUG=webrtc:4172
> >
> > Review-Url: https://codereview.webrtc.org/2781433002
> > Cr-Commit-Position: refs/heads/master@{#17474}
> > Committed: https://chromium.googlesource.com/external/webrtc/+/3ea3c77e93121b1ab9d5e46641e6764f2cca0d51
>
> TBR=ilnik@webrtc.org,stefan@webrtc.org,asapersson@webrtc.org,sprang@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:4172
>
> Review-Url: https://codereview.webrtc.org/2783183003
> Cr-Commit-Position: refs/heads/master@{#17477}
> Committed: https://chromium.googlesource.com/external/webrtc/+/f9ed235c9b7248694edcb46feb1f29ce7456ab59
R=ilnik@webrtc.org,stefan@webrtc.org
BUG=webrtc:4172
Review-Url: https://codereview.webrtc.org/2789823002
Cr-Commit-Position: refs/heads/master@{#17498}
2017-04-02 23:53:04 -07:00
|
|
|
int GetCurrentConfiguredFramerate();
|
2018-12-20 13:46:06 +01:00
|
|
|
void UpdateFps(int max_fps) RTC_EXCLUSIVE_LOCKS_REQUIRED(&lock_);
|
2013-05-29 13:41:03 +00:00
|
|
|
|
2014-04-28 13:00:21 +00:00
|
|
|
Clock* const clock_;
|
2019-07-31 17:30:03 +02:00
|
|
|
RepeatingTaskHandle frame_task_;
|
2013-05-29 13:41:03 +00:00
|
|
|
bool sending_;
|
2017-09-09 04:17:22 -07:00
|
|
|
SinkWantsObserver* sink_wants_observer_ RTC_GUARDED_BY(&lock_);
|
2013-05-29 13:41:03 +00:00
|
|
|
|
2015-05-01 13:00:41 +02:00
|
|
|
rtc::CriticalSection lock_;
|
2016-05-01 14:53:46 -07:00
|
|
|
std::unique_ptr<FrameGenerator> frame_generator_;
|
2013-05-29 13:41:03 +00:00
|
|
|
|
2018-08-30 11:19:23 +02:00
|
|
|
int source_fps_ RTC_GUARDED_BY(&lock_);
|
|
|
|
|
int target_capture_fps_ RTC_GUARDED_BY(&lock_);
|
2018-06-18 12:54:17 +02:00
|
|
|
absl::optional<int> wanted_fps_ RTC_GUARDED_BY(&lock_);
|
2016-04-19 15:01:23 +02:00
|
|
|
VideoRotation fake_rotation_ = kVideoRotation_0;
|
2018-12-12 11:17:43 +01:00
|
|
|
absl::optional<ColorSpace> fake_color_space_ RTC_GUARDED_BY(&lock_);
|
2014-04-24 22:10:24 +00:00
|
|
|
|
|
|
|
|
int64_t first_frame_capture_time_;
|
2017-03-17 05:55:25 -07:00
|
|
|
// Must be the last field, so it will be deconstructed first as tasks
|
|
|
|
|
// in the TaskQueue access other fields of the instance of this class.
|
|
|
|
|
rtc::TaskQueue task_queue_;
|
2013-05-29 13:41:03 +00:00
|
|
|
};
|
2017-03-17 05:55:25 -07:00
|
|
|
} // namespace test
|
|
|
|
|
} // namespace webrtc
|
2013-05-29 13:41:03 +00:00
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // TEST_FRAME_GENERATOR_CAPTURER_H_
|