Home | History | Annotate | Download | only in test
      1 /*
      2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 #include <stdio.h>
     12 
     13 #include <map>
     14 #include <sstream>
     15 
     16 #include "testing/gtest/include/gtest/gtest.h"
     17 #include "webrtc/base/scoped_ptr.h"
     18 #include "webrtc/base/scoped_ref_ptr.h"
     19 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
     20 #include "webrtc/modules/utility/include/process_thread.h"
     21 #include "webrtc/modules/video_capture/video_capture.h"
     22 #include "webrtc/modules/video_capture/video_capture_factory.h"
     23 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
     24 #include "webrtc/system_wrappers/include/sleep.h"
     25 #include "webrtc/system_wrappers/include/tick_util.h"
     26 #include "webrtc/video_frame.h"
     27 
     28 using rtc::scoped_ptr;
     29 using webrtc::CriticalSectionWrapper;
     30 using webrtc::CriticalSectionScoped;
     31 using webrtc::SleepMs;
     32 using webrtc::TickTime;
     33 using webrtc::VideoCaptureAlarm;
     34 using webrtc::VideoCaptureCapability;
     35 using webrtc::VideoCaptureDataCallback;
     36 using webrtc::VideoCaptureFactory;
     37 using webrtc::VideoCaptureFeedBack;
     38 using webrtc::VideoCaptureModule;
     39 
     40 
     41 #define WAIT_(ex, timeout, res) \
     42   do { \
     43     res = (ex); \
     44     int64_t start = TickTime::MillisecondTimestamp(); \
     45     while (!res && TickTime::MillisecondTimestamp() < start + timeout) { \
     46       SleepMs(5); \
     47       res = (ex); \
     48     } \
     49   } while (0)
     50 
     51 #define EXPECT_TRUE_WAIT(ex, timeout) \
     52   do { \
     53     bool res; \
     54     WAIT_(ex, timeout, res); \
     55     if (!res) EXPECT_TRUE(ex); \
     56   } while (0)
     57 
     58 
     59 static const int kTimeOut = 5000;
     60 static const int kTestHeight = 288;
     61 static const int kTestWidth = 352;
     62 static const int kTestFramerate = 30;
     63 
     64 // Compares the content of two video frames.
     65 static bool CompareFrames(const webrtc::VideoFrame& frame1,
     66                           const webrtc::VideoFrame& frame2) {
     67   bool result =
     68       (frame1.stride(webrtc::kYPlane) == frame2.stride(webrtc::kYPlane)) &&
     69       (frame1.stride(webrtc::kUPlane) == frame2.stride(webrtc::kUPlane)) &&
     70       (frame1.stride(webrtc::kVPlane) == frame2.stride(webrtc::kVPlane)) &&
     71       (frame1.width() == frame2.width()) &&
     72       (frame1.height() == frame2.height());
     73 
     74   if (!result)
     75     return false;
     76   for (int plane = 0; plane < webrtc::kNumOfPlanes; plane ++) {
     77       webrtc::PlaneType plane_type = static_cast<webrtc::PlaneType>(plane);
     78       int allocated_size1 = frame1.allocated_size(plane_type);
     79       int allocated_size2 = frame2.allocated_size(plane_type);
     80       if (allocated_size1 != allocated_size2)
     81         return false;
     82       const uint8_t* plane_buffer1 = frame1.buffer(plane_type);
     83       const uint8_t* plane_buffer2 = frame2.buffer(plane_type);
     84       if (memcmp(plane_buffer1, plane_buffer2, allocated_size1))
     85         return false;
     86     }
     87     return true;
     88 }
     89 
     90 class TestVideoCaptureCallback : public VideoCaptureDataCallback {
     91  public:
     92   TestVideoCaptureCallback()
     93       : capture_cs_(CriticalSectionWrapper::CreateCriticalSection()),
     94         capture_delay_(-1),
     95         last_render_time_ms_(0),
     96         incoming_frames_(0),
     97         timing_warnings_(0),
     98         rotate_frame_(webrtc::kVideoRotation_0) {}
     99 
    100   ~TestVideoCaptureCallback() {
    101     if (timing_warnings_ > 0)
    102       printf("No of timing warnings %d\n", timing_warnings_);
    103   }
    104 
    105   virtual void OnIncomingCapturedFrame(const int32_t id,
    106                                        const webrtc::VideoFrame& videoFrame) {
    107     CriticalSectionScoped cs(capture_cs_.get());
    108     int height = videoFrame.height();
    109     int width = videoFrame.width();
    110 #if ANDROID
    111     // Android camera frames may be rotated depending on test device
    112     // orientation.
    113     EXPECT_TRUE(height == capability_.height || height == capability_.width);
    114     EXPECT_TRUE(width == capability_.width || width == capability_.height);
    115 #else
    116     if (rotate_frame_ == webrtc::kVideoRotation_90 ||
    117         rotate_frame_ == webrtc::kVideoRotation_270) {
    118       EXPECT_EQ(width, capability_.height);
    119       EXPECT_EQ(height, capability_.width);
    120     } else {
    121       EXPECT_EQ(height, capability_.height);
    122       EXPECT_EQ(width, capability_.width);
    123     }
    124 #endif
    125     // RenderTimstamp should be the time now.
    126     EXPECT_TRUE(
    127         videoFrame.render_time_ms() >= TickTime::MillisecondTimestamp()-30 &&
    128         videoFrame.render_time_ms() <= TickTime::MillisecondTimestamp());
    129 
    130     if ((videoFrame.render_time_ms() >
    131             last_render_time_ms_ + (1000 * 1.1) / capability_.maxFPS &&
    132             last_render_time_ms_ > 0) ||
    133         (videoFrame.render_time_ms() <
    134             last_render_time_ms_ + (1000 * 0.9) / capability_.maxFPS &&
    135             last_render_time_ms_ > 0)) {
    136       timing_warnings_++;
    137     }
    138 
    139     incoming_frames_++;
    140     last_render_time_ms_ = videoFrame.render_time_ms();
    141     last_frame_.CopyFrame(videoFrame);
    142   }
    143 
    144   virtual void OnCaptureDelayChanged(const int32_t id,
    145                                      const int32_t delay) {
    146     CriticalSectionScoped cs(capture_cs_.get());
    147     capture_delay_ = delay;
    148   }
    149 
    150   void SetExpectedCapability(VideoCaptureCapability capability) {
    151     CriticalSectionScoped cs(capture_cs_.get());
    152     capability_= capability;
    153     incoming_frames_ = 0;
    154     last_render_time_ms_ = 0;
    155     capture_delay_ = -1;
    156   }
    157   int incoming_frames() {
    158     CriticalSectionScoped cs(capture_cs_.get());
    159     return incoming_frames_;
    160   }
    161 
    162   int capture_delay() {
    163     CriticalSectionScoped cs(capture_cs_.get());
    164     return capture_delay_;
    165   }
    166   int timing_warnings() {
    167     CriticalSectionScoped cs(capture_cs_.get());
    168     return timing_warnings_;
    169   }
    170   VideoCaptureCapability capability() {
    171     CriticalSectionScoped cs(capture_cs_.get());
    172     return capability_;
    173   }
    174 
    175   bool CompareLastFrame(const webrtc::VideoFrame& frame) {
    176     CriticalSectionScoped cs(capture_cs_.get());
    177     return CompareFrames(last_frame_, frame);
    178   }
    179 
    180   void SetExpectedCaptureRotation(webrtc::VideoRotation rotation) {
    181     CriticalSectionScoped cs(capture_cs_.get());
    182     rotate_frame_ = rotation;
    183   }
    184 
    185  private:
    186   scoped_ptr<CriticalSectionWrapper> capture_cs_;
    187   VideoCaptureCapability capability_;
    188   int capture_delay_;
    189   int64_t last_render_time_ms_;
    190   int incoming_frames_;
    191   int timing_warnings_;
    192   webrtc::VideoFrame last_frame_;
    193   webrtc::VideoRotation rotate_frame_;
    194 };
    195 
    196 class TestVideoCaptureFeedBack : public VideoCaptureFeedBack {
    197  public:
    198   TestVideoCaptureFeedBack() :
    199     capture_cs_(CriticalSectionWrapper::CreateCriticalSection()),
    200     frame_rate_(0),
    201     alarm_(webrtc::Cleared) {
    202   }
    203 
    204   virtual void OnCaptureFrameRate(const int32_t id,
    205                                   const uint32_t frameRate) {
    206     CriticalSectionScoped cs(capture_cs_.get());
    207     frame_rate_ = frameRate;
    208   }
    209 
    210   virtual void OnNoPictureAlarm(const int32_t id,
    211                                 const VideoCaptureAlarm reported_alarm) {
    212     CriticalSectionScoped cs(capture_cs_.get());
    213     alarm_ = reported_alarm;
    214   }
    215   int frame_rate() {
    216     CriticalSectionScoped cs(capture_cs_.get());
    217     return frame_rate_;
    218 
    219   }
    220   VideoCaptureAlarm alarm() {
    221     CriticalSectionScoped cs(capture_cs_.get());
    222     return alarm_;
    223   }
    224 
    225  private:
    226   scoped_ptr<CriticalSectionWrapper> capture_cs_;
    227   unsigned int frame_rate_;
    228   VideoCaptureAlarm alarm_;
    229 };
    230 
    231 class VideoCaptureTest : public testing::Test {
    232  public:
    233   VideoCaptureTest() : number_of_devices_(0) {}
    234 
    235   void SetUp() {
    236     device_info_.reset(VideoCaptureFactory::CreateDeviceInfo(0));
    237     assert(device_info_.get());
    238     number_of_devices_ = device_info_->NumberOfDevices();
    239     ASSERT_GT(number_of_devices_, 0u);
    240   }
    241 
    242   rtc::scoped_refptr<VideoCaptureModule> OpenVideoCaptureDevice(
    243       unsigned int device,
    244       VideoCaptureDataCallback* callback) {
    245     char device_name[256];
    246     char unique_name[256];
    247 
    248     EXPECT_EQ(0, device_info_->GetDeviceName(
    249         device, device_name, 256, unique_name, 256));
    250 
    251     rtc::scoped_refptr<VideoCaptureModule> module(
    252         VideoCaptureFactory::Create(device, unique_name));
    253     if (module.get() == NULL)
    254       return NULL;
    255 
    256     EXPECT_FALSE(module->CaptureStarted());
    257 
    258     module->RegisterCaptureDataCallback(*callback);
    259     return module;
    260   }
    261 
    262   void StartCapture(VideoCaptureModule* capture_module,
    263                     VideoCaptureCapability capability) {
    264     ASSERT_EQ(0, capture_module->StartCapture(capability));
    265     EXPECT_TRUE(capture_module->CaptureStarted());
    266 
    267     VideoCaptureCapability resulting_capability;
    268     EXPECT_EQ(0, capture_module->CaptureSettings(resulting_capability));
    269     EXPECT_EQ(capability.width, resulting_capability.width);
    270     EXPECT_EQ(capability.height, resulting_capability.height);
    271   }
    272 
    273   scoped_ptr<VideoCaptureModule::DeviceInfo> device_info_;
    274   unsigned int number_of_devices_;
    275 };
    276 
    277 #ifdef WEBRTC_MAC
    278 // Currently fails on Mac 64-bit, see
    279 // https://bugs.chromium.org/p/webrtc/issues/detail?id=5406
    280 #define MAYBE_CreateDelete DISABLED_CreateDelete
    281 #else
    282 #define MAYBE_CreateDelete CreateDelete
    283 #endif
    284 TEST_F(VideoCaptureTest, MAYBE_CreateDelete) {
    285   for (int i = 0; i < 5; ++i) {
    286     int64_t start_time = TickTime::MillisecondTimestamp();
    287     TestVideoCaptureCallback capture_observer;
    288     rtc::scoped_refptr<VideoCaptureModule> module(
    289         OpenVideoCaptureDevice(0, &capture_observer));
    290     ASSERT_TRUE(module.get() != NULL);
    291 
    292     VideoCaptureCapability capability;
    293 #ifndef WEBRTC_MAC
    294     device_info_->GetCapability(module->CurrentDeviceName(), 0, capability);
    295 #else
    296     capability.width = kTestWidth;
    297     capability.height = kTestHeight;
    298     capability.maxFPS = kTestFramerate;
    299     capability.rawType = webrtc::kVideoUnknown;
    300 #endif
    301     capture_observer.SetExpectedCapability(capability);
    302     ASSERT_NO_FATAL_FAILURE(StartCapture(module.get(), capability));
    303 
    304     // Less than 4s to start the camera.
    305     EXPECT_LE(TickTime::MillisecondTimestamp() - start_time, 4000);
    306 
    307     // Make sure 5 frames are captured.
    308     EXPECT_TRUE_WAIT(capture_observer.incoming_frames() >= 5, kTimeOut);
    309 
    310     EXPECT_GE(capture_observer.capture_delay(), 0);
    311 
    312     int64_t stop_time = TickTime::MillisecondTimestamp();
    313     EXPECT_EQ(0, module->StopCapture());
    314     EXPECT_FALSE(module->CaptureStarted());
    315 
    316     // Less than 3s to stop the camera.
    317     EXPECT_LE(TickTime::MillisecondTimestamp() - stop_time, 3000);
    318   }
    319 }
    320 
    321 #ifdef WEBRTC_MAC
    322 // Currently fails on Mac 64-bit, see
    323 // https://bugs.chromium.org/p/webrtc/issues/detail?id=5406
    324 #define MAYBE_Capabilities DISABLED_Capabilities
    325 #else
    326 #define MAYBE_Capabilities Capabilities
    327 #endif
    328 TEST_F(VideoCaptureTest, MAYBE_Capabilities) {
    329 #ifdef WEBRTC_MAC
    330   printf("Video capture capabilities are not supported on Mac.\n");
    331   return;
    332 #endif
    333 
    334   TestVideoCaptureCallback capture_observer;
    335 
    336   rtc::scoped_refptr<VideoCaptureModule> module(
    337       OpenVideoCaptureDevice(0, &capture_observer));
    338   ASSERT_TRUE(module.get() != NULL);
    339 
    340   int number_of_capabilities = device_info_->NumberOfCapabilities(
    341       module->CurrentDeviceName());
    342   EXPECT_GT(number_of_capabilities, 0);
    343   // Key is <width>x<height>, value is vector of maxFPS values at that
    344   // resolution.
    345   typedef std::map<std::string, std::vector<int> > FrameRatesByResolution;
    346   FrameRatesByResolution frame_rates_by_resolution;
    347   for (int i = 0; i < number_of_capabilities; ++i) {
    348     VideoCaptureCapability capability;
    349     EXPECT_EQ(0, device_info_->GetCapability(module->CurrentDeviceName(), i,
    350                                              capability));
    351     std::ostringstream resolutionStream;
    352     resolutionStream << capability.width << "x" << capability.height;
    353     resolutionStream.flush();
    354     std::string resolution = resolutionStream.str();
    355     frame_rates_by_resolution[resolution].push_back(capability.maxFPS);
    356 
    357     // Since Android presents so many resolution/FPS combinations and the test
    358     // runner imposes a timeout, we only actually start the capture and test
    359     // that a frame was captured for 2 frame-rates at each resolution.
    360     if (frame_rates_by_resolution[resolution].size() > 2)
    361       continue;
    362 
    363     capture_observer.SetExpectedCapability(capability);
    364     ASSERT_NO_FATAL_FAILURE(StartCapture(module.get(), capability));
    365     // Make sure at least one frame is captured.
    366     EXPECT_TRUE_WAIT(capture_observer.incoming_frames() >= 1, kTimeOut);
    367 
    368     EXPECT_EQ(0, module->StopCapture());
    369   }
    370 
    371 #if ANDROID
    372   // There's no reason for this to _necessarily_ be true, but in practice all
    373   // Android devices this test runs on in fact do support multiple capture
    374   // resolutions and multiple frame-rates per captured resolution, so we assert
    375   // this fact here as a regression-test against the time that we only noticed a
    376   // single frame-rate per resolution (bug 2974).  If this test starts being run
    377   // on devices for which this is untrue (e.g. Nexus4) then the following should
    378   // probably be wrapped in a base::android::BuildInfo::model()/device() check.
    379   EXPECT_GT(frame_rates_by_resolution.size(), 1U);
    380   for (FrameRatesByResolution::const_iterator it =
    381            frame_rates_by_resolution.begin();
    382        it != frame_rates_by_resolution.end();
    383        ++it) {
    384     EXPECT_GT(it->second.size(), 1U) << it->first;
    385   }
    386 #endif  // ANDROID
    387 }
    388 
    389 // NOTE: flaky, crashes sometimes.
    390 // http://code.google.com/p/webrtc/issues/detail?id=777
    391 TEST_F(VideoCaptureTest, DISABLED_TestTwoCameras) {
    392   if (number_of_devices_ < 2) {
    393     printf("There are not two cameras available. Aborting test. \n");
    394     return;
    395   }
    396 
    397   TestVideoCaptureCallback capture_observer1;
    398   rtc::scoped_refptr<VideoCaptureModule> module1(
    399       OpenVideoCaptureDevice(0, &capture_observer1));
    400   ASSERT_TRUE(module1.get() != NULL);
    401   VideoCaptureCapability capability1;
    402 #ifndef WEBRTC_MAC
    403   device_info_->GetCapability(module1->CurrentDeviceName(), 0, capability1);
    404 #else
    405   capability1.width = kTestWidth;
    406   capability1.height = kTestHeight;
    407   capability1.maxFPS = kTestFramerate;
    408   capability1.rawType = webrtc::kVideoUnknown;
    409 #endif
    410   capture_observer1.SetExpectedCapability(capability1);
    411 
    412   TestVideoCaptureCallback capture_observer2;
    413   rtc::scoped_refptr<VideoCaptureModule> module2(
    414       OpenVideoCaptureDevice(1, &capture_observer2));
    415   ASSERT_TRUE(module1.get() != NULL);
    416 
    417 
    418   VideoCaptureCapability capability2;
    419 #ifndef WEBRTC_MAC
    420   device_info_->GetCapability(module2->CurrentDeviceName(), 0, capability2);
    421 #else
    422   capability2.width = kTestWidth;
    423   capability2.height = kTestHeight;
    424   capability2.maxFPS = kTestFramerate;
    425   capability2.rawType = webrtc::kVideoUnknown;
    426 #endif
    427   capture_observer2.SetExpectedCapability(capability2);
    428 
    429   ASSERT_NO_FATAL_FAILURE(StartCapture(module1.get(), capability1));
    430   ASSERT_NO_FATAL_FAILURE(StartCapture(module2.get(), capability2));
    431   EXPECT_TRUE_WAIT(capture_observer1.incoming_frames() >= 5, kTimeOut);
    432   EXPECT_TRUE_WAIT(capture_observer2.incoming_frames() >= 5, kTimeOut);
    433   EXPECT_EQ(0, module2->StopCapture());
    434   EXPECT_EQ(0, module1->StopCapture());
    435 }
    436 
    437 // Test class for testing external capture and capture feedback information
    438 // such as frame rate and picture alarm.
    439 class VideoCaptureExternalTest : public testing::Test {
    440  public:
    441   void SetUp() {
    442     capture_module_ = VideoCaptureFactory::Create(0, capture_input_interface_);
    443     process_module_ = webrtc::ProcessThread::Create("ProcessThread");
    444     process_module_->Start();
    445     process_module_->RegisterModule(capture_module_);
    446 
    447     VideoCaptureCapability capability;
    448     capability.width = kTestWidth;
    449     capability.height = kTestHeight;
    450     capability.rawType = webrtc::kVideoYV12;
    451     capability.maxFPS = kTestFramerate;
    452     capture_callback_.SetExpectedCapability(capability);
    453 
    454     test_frame_.CreateEmptyFrame(kTestWidth, kTestHeight, kTestWidth,
    455                                  ((kTestWidth + 1) / 2), (kTestWidth + 1) / 2);
    456     SleepMs(1); // Wait 1ms so that two tests can't have the same timestamp.
    457     memset(test_frame_.buffer(webrtc::kYPlane), 127, kTestWidth * kTestHeight);
    458     memset(test_frame_.buffer(webrtc::kUPlane), 127,
    459            ((kTestWidth + 1) / 2) * ((kTestHeight + 1) / 2));
    460     memset(test_frame_.buffer(webrtc::kVPlane), 127,
    461            ((kTestWidth + 1) / 2) * ((kTestHeight + 1) / 2));
    462 
    463     capture_module_->RegisterCaptureDataCallback(capture_callback_);
    464     capture_module_->RegisterCaptureCallback(capture_feedback_);
    465     capture_module_->EnableFrameRateCallback(true);
    466     capture_module_->EnableNoPictureAlarm(true);
    467   }
    468 
    469   void TearDown() {
    470     process_module_->Stop();
    471   }
    472 
    473   webrtc::VideoCaptureExternal* capture_input_interface_;
    474   rtc::scoped_refptr<VideoCaptureModule> capture_module_;
    475   rtc::scoped_ptr<webrtc::ProcessThread> process_module_;
    476   webrtc::VideoFrame test_frame_;
    477   TestVideoCaptureCallback capture_callback_;
    478   TestVideoCaptureFeedBack capture_feedback_;
    479 };
    480 
    481 // Test input of external video frames.
    482 TEST_F(VideoCaptureExternalTest, TestExternalCapture) {
    483   size_t length = webrtc::CalcBufferSize(webrtc::kI420,
    484                                          test_frame_.width(),
    485                                          test_frame_.height());
    486   scoped_ptr<uint8_t[]> test_buffer(new uint8_t[length]);
    487   webrtc::ExtractBuffer(test_frame_, length, test_buffer.get());
    488   EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(),
    489       length, capture_callback_.capability(), 0));
    490   EXPECT_TRUE(capture_callback_.CompareLastFrame(test_frame_));
    491 }
    492 
    493 // Test frame rate and no picture alarm.
    494 // Flaky on Win32, see webrtc:3270.
    495 #if defined(WEBRTC_WIN)
    496 #define MAYBE_FrameRate DISABLED_FrameRate
    497 #else
    498 #define MAYBE_FrameRate FrameRate
    499 #endif
    500 TEST_F(VideoCaptureExternalTest, MAYBE_FrameRate) {
    501   int64_t testTime = 3;
    502   TickTime startTime = TickTime::Now();
    503 
    504   while ((TickTime::Now() - startTime).Milliseconds() < testTime * 1000) {
    505      size_t length = webrtc::CalcBufferSize(webrtc::kI420,
    506                                             test_frame_.width(),
    507                                             test_frame_.height());
    508      scoped_ptr<uint8_t[]> test_buffer(new uint8_t[length]);
    509      webrtc::ExtractBuffer(test_frame_, length, test_buffer.get());
    510      EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(),
    511        length, capture_callback_.capability(), 0));
    512     SleepMs(100);
    513   }
    514   EXPECT_TRUE(capture_feedback_.frame_rate() >= 8 &&
    515               capture_feedback_.frame_rate() <= 10);
    516   SleepMs(500);
    517   EXPECT_EQ(webrtc::Raised, capture_feedback_.alarm());
    518 
    519   startTime = TickTime::Now();
    520   while ((TickTime::Now() - startTime).Milliseconds() < testTime * 1000) {
    521     size_t length = webrtc::CalcBufferSize(webrtc::kI420,
    522                                            test_frame_.width(),
    523                                            test_frame_.height());
    524     scoped_ptr<uint8_t[]> test_buffer(new uint8_t[length]);
    525     webrtc::ExtractBuffer(test_frame_, length, test_buffer.get());
    526     EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(),
    527       length, capture_callback_.capability(), 0));
    528     SleepMs(1000 / 30);
    529   }
    530   EXPECT_EQ(webrtc::Cleared, capture_feedback_.alarm());
    531   // Frame rate might be less than 33 since we have paused providing
    532   // frames for a while.
    533   EXPECT_TRUE(capture_feedback_.frame_rate() >= 25 &&
    534               capture_feedback_.frame_rate() <= 33);
    535 }
    536 
    537 TEST_F(VideoCaptureExternalTest, Rotation) {
    538   EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_0));
    539   size_t length = webrtc::CalcBufferSize(webrtc::kI420,
    540                                          test_frame_.width(),
    541                                          test_frame_.height());
    542   scoped_ptr<uint8_t[]> test_buffer(new uint8_t[length]);
    543   webrtc::ExtractBuffer(test_frame_, length, test_buffer.get());
    544   EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(),
    545     length, capture_callback_.capability(), 0));
    546   EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_90));
    547   capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_90);
    548   EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(),
    549     length, capture_callback_.capability(), 0));
    550   EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_180));
    551   capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_180);
    552   EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(),
    553     length, capture_callback_.capability(), 0));
    554   EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_270));
    555   capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_270);
    556   EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(),
    557     length, capture_callback_.capability(), 0));
    558 }
    559