videocapturer_unittest.cc revision 28e20752806a492f5a6a5d343c02f9556f39b1cd
128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org// Copyright 2008 Google Inc.
228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#include <stdio.h>
428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#include <vector>
528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#include "talk/base/gunit.h"
728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#include "talk/base/logging.h"
828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#include "talk/base/thread.h"
928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#include "talk/media/base/fakemediaprocessor.h"
1028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#include "talk/media/base/fakevideocapturer.h"
1128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#include "talk/media/base/fakevideorenderer.h"
1228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#include "talk/media/base/testutils.h"
1328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#include "talk/media/base/videocapturer.h"
1428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#include "talk/media/base/videoprocessor.h"
1528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
1628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org// If HAS_I420_FRAME is not defined the video capturer will not be able to
1728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org// provide OnVideoFrame-callbacks since they require cricket::CapturedFrame to
1828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org// be decoded as a cricket::VideoFrame (i.e. an I420 frame). This functionality
1928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org// only exist if HAS_I420_FRAME is defined below. I420 frames are also a
2028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org// requirement for the VideoProcessors so they will not be called either.
2128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#if defined(HAVE_WEBRTC_VIDEO)
2228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#define HAS_I420_FRAME
2328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#endif
2428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
2528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgusing cricket::FakeVideoCapturer;
2628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
2728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgnamespace {
2828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
2928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgconst int kMsCallbackWait = 500;
3028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org// For HD only the height matters.
3128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgconst int kMinHdHeight = 720;
3228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgconst uint32 kTimeout = 5000U;
3328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
3428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org}  // namespace
3528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
3628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org// Sets the elapsed time in the video frame to 0.
3728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgclass VideoProcessor0 : public cricket::VideoProcessor {
3828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org public:
3928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  virtual void OnFrame(uint32 /*ssrc*/, cricket::VideoFrame* frame,
4028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                       bool* drop_frame) {
4128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    frame->SetElapsedTime(0u);
4228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  }
4328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org};
4428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
4528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org// Adds one to the video frame's elapsed time. Note that VideoProcessor0 and
4628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org// VideoProcessor1 are not commutative.
4728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgclass VideoProcessor1 : public cricket::VideoProcessor {
4828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org public:
4928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  virtual void OnFrame(uint32 /*ssrc*/, cricket::VideoFrame* frame,
5028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                       bool* drop_frame) {
5128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    int64 elapsed_time = frame->GetElapsedTime();
5228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    frame->SetElapsedTime(elapsed_time + 1);
5328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  }
5428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org};
5528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
5628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgclass VideoCapturerTest
5728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    : public sigslot::has_slots<>,
5828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      public testing::Test {
5928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org public:
6028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  VideoCapturerTest()
6128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      : capture_state_(cricket::CS_STOPPED),
6228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org        num_state_changes_(0),
6328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org        video_frames_received_(0),
6428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org        last_frame_elapsed_time_(0) {
6528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    capturer_.SignalVideoFrame.connect(this, &VideoCapturerTest::OnVideoFrame);
6628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    capturer_.SignalStateChange.connect(this,
6728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                                        &VideoCapturerTest::OnStateChange);
6828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  }
6928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
7028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org protected:
7128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  void OnVideoFrame(cricket::VideoCapturer*, const cricket::VideoFrame* frame) {
7228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    ++video_frames_received_;
7328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    last_frame_elapsed_time_ = frame->GetElapsedTime();
7428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    renderer_.RenderFrame(frame);
7528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  }
7628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  void OnStateChange(cricket::VideoCapturer*,
7728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                     cricket::CaptureState capture_state) {
7828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    capture_state_ = capture_state;
7928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    ++num_state_changes_;
8028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  }
8128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  cricket::CaptureState capture_state() { return capture_state_; }
8228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  int num_state_changes() { return num_state_changes_; }
8328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  int video_frames_received() const {
8428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    return video_frames_received_;
8528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  }
8628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  int64 last_frame_elapsed_time() const { return last_frame_elapsed_time_; }
8728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
8828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  cricket::FakeVideoCapturer capturer_;
8928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  cricket::CaptureState capture_state_;
9028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  int num_state_changes_;
9128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  int video_frames_received_;
9228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  int64 last_frame_elapsed_time_;
9328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  cricket::FakeVideoRenderer renderer_;
9428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org};
9528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
9628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgTEST_F(VideoCapturerTest, CaptureState) {
9728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(cricket::CS_RUNNING, capturer_.Start(cricket::VideoFormat(
9828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      640,
9928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      480,
10028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30),
10128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::FOURCC_I420)));
10228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.IsRunning());
10328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait);
10428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(1, num_state_changes());
10528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  capturer_.Stop();
10628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ_WAIT(cricket::CS_STOPPED, capture_state(), kMsCallbackWait);
10728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(2, num_state_changes());
10828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  capturer_.Stop();
10928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  talk_base::Thread::Current()->ProcessMessages(100);
11028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(2, num_state_changes());
11128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org}
11228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
11328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgTEST_F(VideoCapturerTest, TestRestart) {
11428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(cricket::CS_RUNNING, capturer_.Start(cricket::VideoFormat(
11528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      640,
11628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      480,
11728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30),
11828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::FOURCC_I420)));
11928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.IsRunning());
12028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait);
12128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(1, num_state_changes());
12228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.Restart(cricket::VideoFormat(
12328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      320,
12428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      240,
12528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30),
12628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::FOURCC_I420)));
12728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait);
12828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.IsRunning());
12928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_GE(1, num_state_changes());
13028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  capturer_.Stop();
13128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  talk_base::Thread::Current()->ProcessMessages(100);
13228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_FALSE(capturer_.IsRunning());
13328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org}
13428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
13528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgTEST_F(VideoCapturerTest, TestStartingWithRestart) {
13628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_FALSE(capturer_.IsRunning());
13728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.Restart(cricket::VideoFormat(
13828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      640,
13928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      480,
14028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30),
14128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::FOURCC_I420)));
14228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.IsRunning());
14328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait);
14428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org}
14528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
14628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgTEST_F(VideoCapturerTest, TestRestartWithSameFormat) {
14728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  cricket::VideoFormat format(640, 480,
14828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                              cricket::VideoFormat::FpsToInterval(30),
14928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                              cricket::FOURCC_I420);
15028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(cricket::CS_RUNNING, capturer_.Start(format));
15128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.IsRunning());
15228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait);
15328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(1, num_state_changes());
15428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.Restart(format));
15528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(cricket::CS_RUNNING, capture_state());
15628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.IsRunning());
15728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(1, num_state_changes());
15828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org}
15928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
16028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgTEST_F(VideoCapturerTest, CameraOffOnMute) {
16128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(cricket::CS_RUNNING, capturer_.Start(cricket::VideoFormat(
16228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      640,
16328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      480,
16428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30),
16528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::FOURCC_I420)));
16628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.IsRunning());
16728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(0, video_frames_received());
16828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.CaptureFrame());
16928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(1, video_frames_received());
17028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_FALSE(capturer_.IsMuted());
17128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
17228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Mute the camera and expect black output frame.
17328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  capturer_.MuteToBlackThenPause(true);
17428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.IsMuted());
17528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  for (int i = 0; i < 31; ++i) {
17628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    EXPECT_TRUE(capturer_.CaptureFrame());
17728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    EXPECT_TRUE(renderer_.black_frame());
17828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  }
17928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(32, video_frames_received());
18028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ_WAIT(cricket::CS_PAUSED,
18128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                 capturer_.capture_state(), kTimeout);
18228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
18328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Verify that the camera is off.
18428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_FALSE(capturer_.CaptureFrame());
18528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(32, video_frames_received());
18628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
18728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Unmute the camera and expect non-black output frame.
18828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  capturer_.MuteToBlackThenPause(false);
18928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_FALSE(capturer_.IsMuted());
19028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ_WAIT(cricket::CS_RUNNING,
19128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                 capturer_.capture_state(), kTimeout);
19228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.CaptureFrame());
19328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_FALSE(renderer_.black_frame());
19428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(33, video_frames_received());
19528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org}
19628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
19728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgTEST_F(VideoCapturerTest, TestFourccMatch) {
19828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  cricket::VideoFormat desired(640, 480,
19928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                               cricket::VideoFormat::FpsToInterval(30),
20028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                               cricket::FOURCC_ANY);
20128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  cricket::VideoFormat best;
20228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best));
20328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(640, best.width);
20428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(480, best.height);
20528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval);
20628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
20728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  desired.fourcc = cricket::FOURCC_MJPG;
20828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_FALSE(capturer_.GetBestCaptureFormat(desired, &best));
20928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
21028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  desired.fourcc = cricket::FOURCC_I420;
21128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best));
21228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org}
21328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
21428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgTEST_F(VideoCapturerTest, TestResolutionMatch) {
21528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  cricket::VideoFormat desired(1920, 1080,
21628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                               cricket::VideoFormat::FpsToInterval(30),
21728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                               cricket::FOURCC_ANY);
21828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  cricket::VideoFormat best;
21928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Ask for 1920x1080. Get HD 1280x720 which is the highest.
22028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best));
22128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(1280, best.width);
22228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(720, best.height);
22328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval);
22428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
22528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  desired.width = 360;
22628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  desired.height = 250;
22728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Ask for a little higher than QVGA. Get QVGA.
22828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best));
22928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(320, best.width);
23028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(240, best.height);
23128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval);
23228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
23328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  desired.width = 480;
23428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  desired.height = 270;
23528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Ask for HVGA. Get VGA.
23628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best));
23728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(640, best.width);
23828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(480, best.height);
23928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval);
24028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
24128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  desired.width = 320;
24228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  desired.height = 240;
24328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Ask for QVGA. Get QVGA.
24428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best));
24528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(320, best.width);
24628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(240, best.height);
24728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval);
24828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
24928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  desired.width = 80;
25028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  desired.height = 60;
25128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Ask for lower than QQVGA. Get QQVGA, which is the lowest.
25228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best));
25328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(160, best.width);
25428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(120, best.height);
25528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval);
25628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org}
25728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
25828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgTEST_F(VideoCapturerTest, TestHDResolutionMatch) {
25928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Add some HD formats typical of a mediocre HD webcam.
26028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  std::vector<cricket::VideoFormat> formats;
26128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  formats.push_back(cricket::VideoFormat(320, 240,
26228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
26328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  formats.push_back(cricket::VideoFormat(640, 480,
26428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
26528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  formats.push_back(cricket::VideoFormat(960, 544,
26628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(24), cricket::FOURCC_I420));
26728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  formats.push_back(cricket::VideoFormat(1280, 720,
26828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(15), cricket::FOURCC_I420));
26928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  formats.push_back(cricket::VideoFormat(2592, 1944,
27028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(7), cricket::FOURCC_I420));
27128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  capturer_.ResetSupportedFormats(formats);
27228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
27328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  cricket::VideoFormat desired(960, 720,
27428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                               cricket::VideoFormat::FpsToInterval(30),
27528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                               cricket::FOURCC_ANY);
27628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  cricket::VideoFormat best;
27728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Ask for 960x720 30 fps. Get qHD 24 fps
27828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best));
27928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(960, best.width);
28028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(544, best.height);
28128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(cricket::VideoFormat::FpsToInterval(24), best.interval);
28228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
28328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  desired.width = 960;
28428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  desired.height = 544;
28528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  desired.interval = cricket::VideoFormat::FpsToInterval(30);
28628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Ask for qHD 30 fps. Get qHD 24 fps
28728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best));
28828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(960, best.width);
28928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(544, best.height);
29028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(cricket::VideoFormat::FpsToInterval(24), best.interval);
29128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
29228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  desired.width = 360;
29328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  desired.height = 250;
29428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  desired.interval = cricket::VideoFormat::FpsToInterval(30);
29528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Ask for a little higher than QVGA. Get QVGA.
29628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best));
29728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(320, best.width);
29828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(240, best.height);
29928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval);
30028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
30128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  desired.width = 480;
30228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  desired.height = 270;
30328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Ask for HVGA. Get VGA.
30428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best));
30528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(640, best.width);
30628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(480, best.height);
30728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval);
30828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
30928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  desired.width = 320;
31028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  desired.height = 240;
31128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Ask for QVGA. Get QVGA.
31228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best));
31328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(320, best.width);
31428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(240, best.height);
31528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval);
31628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
31728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  desired.width = 160;
31828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  desired.height = 120;
31928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Ask for lower than QVGA. Get QVGA, which is the lowest.
32028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best));
32128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(320, best.width);
32228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(240, best.height);
32328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval);
32428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
32528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  desired.width = 1280;
32628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  desired.height = 720;
32728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Ask for HD. 720p fps is too low. Get VGA which has 30 fps.
32828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best));
32928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(640, best.width);
33028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(480, best.height);
33128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval);
33228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
33328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  desired.width = 1280;
33428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  desired.height = 720;
33528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  desired.interval = cricket::VideoFormat::FpsToInterval(15);
33628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Ask for HD 15 fps. Fps matches. Get HD
33728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best));
33828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(1280, best.width);
33928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(720, best.height);
34028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(cricket::VideoFormat::FpsToInterval(15), best.interval);
34128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
34228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  desired.width = 1920;
34328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  desired.height = 1080;
34428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  desired.interval = cricket::VideoFormat::FpsToInterval(30);
34528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Ask for 1080p. Fps of HD formats is too low. Get VGA which can do 30 fps.
34628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best));
34728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(640, best.width);
34828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(480, best.height);
34928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval);
35028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org}
35128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
35228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org// Some cameras support 320x240 and 320x640. Verify we choose 320x240.
35328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgTEST_F(VideoCapturerTest, TestStrangeFormats) {
35428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  std::vector<cricket::VideoFormat> supported_formats;
35528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(320, 240,
35628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
35728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(320, 640,
35828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
35928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  capturer_.ResetSupportedFormats(supported_formats);
36028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
36128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  std::vector<cricket::VideoFormat> required_formats;
36228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  required_formats.push_back(cricket::VideoFormat(320, 240,
36328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
36428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  required_formats.push_back(cricket::VideoFormat(320, 200,
36528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
36628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  required_formats.push_back(cricket::VideoFormat(320, 180,
36728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
36828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  cricket::VideoFormat best;
36928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  for (size_t i = 0; i < required_formats.size(); ++i) {
37028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[i], &best));
37128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    EXPECT_EQ(320, best.width);
37228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    EXPECT_EQ(240, best.height);
37328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  }
37428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
37528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.clear();
37628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(320, 640,
37728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
37828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(320, 240,
37928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
38028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  capturer_.ResetSupportedFormats(supported_formats);
38128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
38228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  for (size_t i = 0; i < required_formats.size(); ++i) {
38328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[i], &best));
38428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    EXPECT_EQ(320, best.width);
38528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    EXPECT_EQ(240, best.height);
38628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  }
38728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org}
38828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
38928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org// Some cameras only have very low fps. Verify we choose something sensible.
39028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgTEST_F(VideoCapturerTest, TestPoorFpsFormats) {
39128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // all formats are low framerate
39228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  std::vector<cricket::VideoFormat> supported_formats;
39328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(320, 240,
39428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(10), cricket::FOURCC_I420));
39528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(640, 480,
39628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(7), cricket::FOURCC_I420));
39728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(1280, 720,
39828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(2), cricket::FOURCC_I420));
39928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  capturer_.ResetSupportedFormats(supported_formats);
40028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
40128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  std::vector<cricket::VideoFormat> required_formats;
40228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  required_formats.push_back(cricket::VideoFormat(320, 240,
40328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
40428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  required_formats.push_back(cricket::VideoFormat(640, 480,
40528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
40628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  cricket::VideoFormat best;
40728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  for (size_t i = 0; i < required_formats.size(); ++i) {
40828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[i], &best));
40928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    EXPECT_EQ(required_formats[i].width, best.width);
41028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    EXPECT_EQ(required_formats[i].height, best.height);
41128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  }
41228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
41328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Increase framerate of 320x240. Expect low fps VGA avoided.
41428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.clear();
41528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(320, 240,
41628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
41728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(640, 480,
41828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(7), cricket::FOURCC_I420));
41928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(1280, 720,
42028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(2), cricket::FOURCC_I420));
42128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  capturer_.ResetSupportedFormats(supported_formats);
42228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
42328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  for (size_t i = 0; i < required_formats.size(); ++i) {
42428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[i], &best));
42528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    EXPECT_EQ(320, best.width);
42628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    EXPECT_EQ(240, best.height);
42728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  }
42828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org}
42928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
43028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org// Some cameras support same size with different frame rates. Verify we choose
43128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org// the frame rate properly.
43228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgTEST_F(VideoCapturerTest, TestSameSizeDifferentFpsFormats) {
43328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  std::vector<cricket::VideoFormat> supported_formats;
43428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(320, 240,
43528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(10), cricket::FOURCC_I420));
43628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(320, 240,
43728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(20), cricket::FOURCC_I420));
43828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(320, 240,
43928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
44028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  capturer_.ResetSupportedFormats(supported_formats);
44128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
44228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  std::vector<cricket::VideoFormat> required_formats = supported_formats;
44328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  cricket::VideoFormat best;
44428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  for (size_t i = 0; i < required_formats.size(); ++i) {
44528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[i], &best));
44628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    EXPECT_EQ(320, best.width);
44728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    EXPECT_EQ(240, best.height);
44828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    EXPECT_EQ(required_formats[i].interval, best.interval);
44928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  }
45028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org}
45128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
45228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org// Some cameras support the correct resolution but at a lower fps than
45328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org// we'd like. This tests we get the expected resolution and fps.
45428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgTEST_F(VideoCapturerTest, TestFpsFormats) {
45528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // We have VGA but low fps. Choose VGA, not HD
45628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  std::vector<cricket::VideoFormat> supported_formats;
45728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(1280, 720,
45828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
45928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(640, 480,
46028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(15), cricket::FOURCC_I420));
46128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(640, 400,
46228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
46328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(640, 360,
46428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
46528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  capturer_.ResetSupportedFormats(supported_formats);
46628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
46728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  std::vector<cricket::VideoFormat> required_formats;
46828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  required_formats.push_back(cricket::VideoFormat(640, 480,
46928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_ANY));
47028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  required_formats.push_back(cricket::VideoFormat(640, 480,
47128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(20), cricket::FOURCC_ANY));
47228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  required_formats.push_back(cricket::VideoFormat(640, 480,
47328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(10), cricket::FOURCC_ANY));
47428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  cricket::VideoFormat best;
47528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
47628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // expect 30 fps to choose 30 fps format
47728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[0], &best));
47828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(640, best.width);
47928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(400, best.height);
48028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval);
48128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
48228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // expect 20 fps to choose 20 fps format
48328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[1], &best));
48428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(640, best.width);
48528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(400, best.height);
48628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(cricket::VideoFormat::FpsToInterval(20), best.interval);
48728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
48828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // expect 10 fps to choose 15 fps format but set fps to 10
48928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[2], &best));
49028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(640, best.width);
49128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(480, best.height);
49228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(cricket::VideoFormat::FpsToInterval(10), best.interval);
49328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
49428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // We have VGA 60 fps and 15 fps. Choose best fps.
49528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.clear();
49628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(1280, 720,
49728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
49828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(640, 480,
49928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(60), cricket::FOURCC_MJPG));
50028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(640, 480,
50128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(15), cricket::FOURCC_I420));
50228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(640, 400,
50328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
50428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(640, 360,
50528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
50628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  capturer_.ResetSupportedFormats(supported_formats);
50728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
50828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // expect 30 fps to choose 60 fps format, but will set best fps to 30
50928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[0], &best));
51028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(640, best.width);
51128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(480, best.height);
51228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval);
51328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
51428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // expect 20 fps to choose 60 fps format, but will set best fps to 20
51528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[1], &best));
51628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(640, best.width);
51728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(480, best.height);
51828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(cricket::VideoFormat::FpsToInterval(20), best.interval);
51928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
52028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // expect 10 fps to choose 10 fps
52128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[2], &best));
52228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(640, best.width);
52328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(480, best.height);
52428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(cricket::VideoFormat::FpsToInterval(10), best.interval);
52528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org}
52628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
52728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgTEST_F(VideoCapturerTest, TestRequest16x10_9) {
52828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  std::vector<cricket::VideoFormat> supported_formats;
52928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // We do not support HD, expect 4x3 for 4x3, 16x10, and 16x9 requests.
53028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(640, 480,
53128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
53228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(640, 400,
53328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
53428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(640, 360,
53528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
53628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  capturer_.ResetSupportedFormats(supported_formats);
53728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
53828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  std::vector<cricket::VideoFormat> required_formats = supported_formats;
53928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  cricket::VideoFormat best;
54028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Expect 4x3, 16x10, and 16x9 requests are respected.
54128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  for (size_t i = 0; i < required_formats.size(); ++i) {
54228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[i], &best));
54328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    EXPECT_EQ(required_formats[i].width, best.width);
54428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    EXPECT_EQ(required_formats[i].height, best.height);
54528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  }
54628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
54728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // We do not support 16x9 HD, expect 4x3 for 4x3, 16x10, and 16x9 requests.
54828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.clear();
54928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(960, 720,
55028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
55128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(640, 480,
55228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
55328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(640, 400,
55428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
55528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(640, 360,
55628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
55728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  capturer_.ResetSupportedFormats(supported_formats);
55828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
55928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Expect 4x3, 16x10, and 16x9 requests are respected.
56028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  for (size_t i = 0; i < required_formats.size(); ++i) {
56128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[i], &best));
56228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    EXPECT_EQ(required_formats[i].width, best.width);
56328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    EXPECT_EQ(required_formats[i].height, best.height);
56428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  }
56528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
56628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // We support 16x9HD, Expect 4x3, 16x10, and 16x9 requests are respected.
56728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.clear();
56828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(1280, 720,
56928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
57028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(640, 480,
57128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
57228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(640, 400,
57328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
57428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  supported_formats.push_back(cricket::VideoFormat(640, 360,
57528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
57628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  capturer_.ResetSupportedFormats(supported_formats);
57728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
57828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Expect 4x3 for 4x3 and 16x10 requests.
57928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  for (size_t i = 0; i < required_formats.size() - 1; ++i) {
58028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[i], &best));
58128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    EXPECT_EQ(required_formats[i].width, best.width);
58228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    EXPECT_EQ(required_formats[i].height, best.height);
58328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  }
58428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
58528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Expect 16x9 for 16x9 request.
58628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.GetBestCaptureFormat(required_formats[2], &best));
58728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(640, best.width);
58828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(360, best.height);
58928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org}
59028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
59128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#if defined(HAS_I420_FRAME)
59228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgTEST_F(VideoCapturerTest, VideoFrame) {
59328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(cricket::CS_RUNNING, capturer_.Start(cricket::VideoFormat(
59428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      640,
59528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      480,
59628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30),
59728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::FOURCC_I420)));
59828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.IsRunning());
59928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(0, video_frames_received());
60028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.CaptureFrame());
60128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(1, video_frames_received());
60228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org}
60328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
60428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgTEST_F(VideoCapturerTest, ProcessorChainTest) {
60528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  VideoProcessor0 processor0;
60628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  VideoProcessor1 processor1;
60728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(cricket::CS_RUNNING, capturer_.Start(cricket::VideoFormat(
60828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      640,
60928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      480,
61028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30),
61128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::FOURCC_I420)));
61228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.IsRunning());
61328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(0, video_frames_received());
61428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // First processor sets elapsed time to 0.
61528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  capturer_.AddVideoProcessor(&processor0);
61628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Second processor adds 1 to the elapsed time. I.e. a frames elapsed time
61728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // should now always be 1 (and not 0).
61828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  capturer_.AddVideoProcessor(&processor1);
61928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.CaptureFrame());
62028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(1, video_frames_received());
62128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(1u, last_frame_elapsed_time());
62228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  capturer_.RemoveVideoProcessor(&processor1);
62328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.CaptureFrame());
62428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Since processor1 has been removed the elapsed time should now be 0.
62528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(2, video_frames_received());
62628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(0u, last_frame_elapsed_time());
62728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org}
62828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
62928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgTEST_F(VideoCapturerTest, ProcessorDropFrame) {
63028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  cricket::FakeMediaProcessor dropping_processor_;
63128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  dropping_processor_.set_drop_frames(true);
63228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(cricket::CS_RUNNING, capturer_.Start(cricket::VideoFormat(
63328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      640,
63428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      480,
63528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::VideoFormat::FpsToInterval(30),
63628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      cricket::FOURCC_I420)));
63728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.IsRunning());
63828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(0, video_frames_received());
63928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Install a processor that always drop frames.
64028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  capturer_.AddVideoProcessor(&dropping_processor_);
64128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(capturer_.CaptureFrame());
64228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_EQ(0, video_frames_received());
64328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org}
64428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#endif  // HAS_I420_FRAME
64528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
64628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgbool HdFormatInList(const std::vector<cricket::VideoFormat>& formats) {
64728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  for (std::vector<cricket::VideoFormat>::const_iterator found =
64828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org           formats.begin(); found != formats.end(); ++found) {
64928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    if (found->height >= kMinHdHeight) {
65028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org      return true;
65128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    }
65228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  }
65328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  return false;
65428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org}
65528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
65628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgTEST_F(VideoCapturerTest, Whitelist) {
65728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // The definition of HD only applies to the height. Set the HD width to the
65828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // smallest legal number to document this fact in this test.
65928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  const int kMinHdWidth = 1;
66028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  cricket::VideoFormat hd_format(kMinHdWidth,
66128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                                 kMinHdHeight,
66228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                                 cricket::VideoFormat::FpsToInterval(30),
66328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                                 cricket::FOURCC_I420);
66428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  cricket::VideoFormat vga_format(640, 480,
66528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                                  cricket::VideoFormat::FpsToInterval(30),
66628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                                  cricket::FOURCC_I420);
66728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  std::vector<cricket::VideoFormat> formats = *capturer_.GetSupportedFormats();
66828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  formats.push_back(hd_format);
66928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
67028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Enable whitelist. Expect HD not in list.
67128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  capturer_.set_enable_camera_list(true);
67228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  capturer_.ResetSupportedFormats(formats);
67328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(HdFormatInList(*capturer_.GetSupportedFormats()));
67428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  capturer_.ConstrainSupportedFormats(vga_format);
67528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_FALSE(HdFormatInList(*capturer_.GetSupportedFormats()));
67628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
67728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Disable whitelist. Expect HD in list.
67828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  capturer_.set_enable_camera_list(false);
67928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  capturer_.ResetSupportedFormats(formats);
68028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(HdFormatInList(*capturer_.GetSupportedFormats()));
68128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  capturer_.ConstrainSupportedFormats(vga_format);
68228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  EXPECT_TRUE(HdFormatInList(*capturer_.GetSupportedFormats()));
68328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org}
684