| OLD | NEW | 
|    1 /* |    1 /* | 
|    2  *  Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. |    2  *  Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. | 
|    3  * |    3  * | 
|    4  *  Use of this source code is governed by a BSD-style license |    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 |    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 |    6  *  tree. An additional intellectual property rights grant can be found | 
|    7  *  in the file PATENTS.  All contributing project authors may |    7  *  in the file PATENTS.  All contributing project authors may | 
|    8  *  be found in the AUTHORS file in the root of the source tree. |    8  *  be found in the AUTHORS file in the root of the source tree. | 
|    9  */ |    9  */ | 
|   10  |   10  | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
|   24 namespace cricket { |   24 namespace cricket { | 
|   25  |   25  | 
|   26 class VideoAdapterTest : public testing::Test { |   26 class VideoAdapterTest : public testing::Test { | 
|   27  public: |   27  public: | 
|   28   virtual void SetUp() { |   28   virtual void SetUp() { | 
|   29     capturer_.reset(new FakeVideoCapturer); |   29     capturer_.reset(new FakeVideoCapturer); | 
|   30     capture_format_ = capturer_->GetSupportedFormats()->at(0); |   30     capture_format_ = capturer_->GetSupportedFormats()->at(0); | 
|   31     capture_format_.interval = VideoFormat::FpsToInterval(30); |   31     capture_format_.interval = VideoFormat::FpsToInterval(30); | 
|   32  |   32  | 
|   33     listener_.reset(new VideoCapturerListener(&adapter_)); |   33     listener_.reset(new VideoCapturerListener(&adapter_)); | 
|   34     capturer_->SignalFrameCaptured.connect( |   34     capturer_->AddOrUpdateSink(listener_.get(), rtc::VideoSinkWants()); | 
|   35         listener_.get(), &VideoCapturerListener::OnFrameCaptured); |  | 
|   36   } |   35   } | 
|   37  |   36  | 
|   38   virtual void TearDown() { |   37   virtual void TearDown() { | 
|   39     // Explicitly disconnect the VideoCapturer before to avoid data races |   38     // Explicitly disconnect the VideoCapturer before to avoid data races | 
|   40     // (frames delivered to VideoCapturerListener while it's being destructed). |   39     // (frames delivered to VideoCapturerListener while it's being destructed). | 
|   41     capturer_->SignalFrameCaptured.disconnect_all(); |   40     capturer_->RemoveSink(listener_.get()); | 
|   42   } |   41   } | 
|   43  |   42  | 
|   44  protected: |   43  protected: | 
|   45   class VideoCapturerListener: public sigslot::has_slots<> { |   44   class VideoCapturerListener | 
 |   45       : public rtc::VideoSinkInterface<cricket::VideoFrame> { | 
|   46    public: |   46    public: | 
|   47     struct Stats { |   47     struct Stats { | 
|   48       int captured_frames; |   48       int captured_frames; | 
|   49       int dropped_frames; |   49       int dropped_frames; | 
|   50       bool last_adapt_was_no_op; |   50       bool last_adapt_was_no_op; | 
|   51  |   51  | 
|   52       int cropped_width; |   52       int cropped_width; | 
|   53       int cropped_height; |   53       int cropped_height; | 
|   54       int out_width; |   54       int out_width; | 
|   55       int out_height; |   55       int out_height; | 
|   56     }; |   56     }; | 
|   57  |   57  | 
|   58     explicit VideoCapturerListener(VideoAdapter* adapter) |   58     explicit VideoCapturerListener(VideoAdapter* adapter) | 
|   59         : video_adapter_(adapter), |   59         : video_adapter_(adapter), | 
|   60           captured_frames_(0), |   60           captured_frames_(0), | 
|   61           dropped_frames_(0), |   61           dropped_frames_(0), | 
|   62           last_adapt_was_no_op_(false) { |   62           last_adapt_was_no_op_(false) { | 
|   63     } |   63     } | 
|   64  |   64  | 
|   65     void OnFrameCaptured(VideoCapturer* capturer, |   65     void OnFrame(const cricket::VideoFrame& frame) { | 
|   66                          const CapturedFrame* captured_frame) { |  | 
|   67       rtc::CritScope lock(&crit_); |   66       rtc::CritScope lock(&crit_); | 
|   68       const int in_width = captured_frame->width; |   67       const int in_width = frame.width(); | 
|   69       const int in_height = abs(captured_frame->height); |   68       const int in_height = frame.height(); | 
|   70       int cropped_width; |   69       int cropped_width; | 
|   71       int cropped_height; |   70       int cropped_height; | 
|   72       int out_width; |   71       int out_width; | 
|   73       int out_height; |   72       int out_height; | 
|   74       if (video_adapter_->AdaptFrameResolution(in_width, in_height, |   73       if (video_adapter_->AdaptFrameResolution( | 
|   75                                                captured_frame->time_stamp, |   74               in_width, in_height, | 
|   76                                                &cropped_width, &cropped_height, |   75               frame.timestamp_us() * rtc::kNumNanosecsPerMicrosec, | 
|   77                                                &out_width, &out_height)) { |   76               &cropped_width, &cropped_height, &out_width, &out_height)) { | 
|   78         cropped_width_ = cropped_width; |   77         cropped_width_ = cropped_width; | 
|   79         cropped_height_ = cropped_height; |   78         cropped_height_ = cropped_height; | 
|   80         out_width_ = out_width; |   79         out_width_ = out_width; | 
|   81         out_height_ = out_height; |   80         out_height_ = out_height; | 
|   82         last_adapt_was_no_op_ = |   81         last_adapt_was_no_op_ = | 
|   83             (in_width == cropped_width && in_height == cropped_height && |   82             (in_width == cropped_width && in_height == cropped_height && | 
|   84              in_width == out_width && in_height == out_height); |   83              in_width == out_width && in_height == out_height); | 
|   85       } else { |   84       } else { | 
|   86         ++dropped_frames_; |   85         ++dropped_frames_; | 
|   87       } |   86       } | 
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  176   EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_)); |  175   EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_)); | 
|  177  |  176  | 
|  178   // Capture 10 frames and verify that every other frame is dropped. The first |  177   // Capture 10 frames and verify that every other frame is dropped. The first | 
|  179   // frame should not be dropped. |  178   // frame should not be dropped. | 
|  180   capturer_->CaptureFrame(); |  179   capturer_->CaptureFrame(); | 
|  181   EXPECT_GE(listener_->GetStats().captured_frames, 1); |  180   EXPECT_GE(listener_->GetStats().captured_frames, 1); | 
|  182   EXPECT_EQ(0, listener_->GetStats().dropped_frames); |  181   EXPECT_EQ(0, listener_->GetStats().dropped_frames); | 
|  183  |  182  | 
|  184   capturer_->CaptureFrame(); |  183   capturer_->CaptureFrame(); | 
|  185   EXPECT_GE(listener_->GetStats().captured_frames, 2); |  184   EXPECT_GE(listener_->GetStats().captured_frames, 2); | 
|  186   EXPECT_EQ(0, listener_->GetStats().dropped_frames); |  185   EXPECT_EQ(1, listener_->GetStats().dropped_frames); | 
|  187  |  186  | 
|  188   capturer_->CaptureFrame(); |  187   capturer_->CaptureFrame(); | 
|  189   EXPECT_GE(listener_->GetStats().captured_frames, 3); |  188   EXPECT_GE(listener_->GetStats().captured_frames, 3); | 
|  190   EXPECT_EQ(1, listener_->GetStats().dropped_frames); |  189   EXPECT_EQ(1, listener_->GetStats().dropped_frames); | 
|  191  |  190  | 
|  192   capturer_->CaptureFrame(); |  191   capturer_->CaptureFrame(); | 
|  193   EXPECT_GE(listener_->GetStats().captured_frames, 4); |  192   EXPECT_GE(listener_->GetStats().captured_frames, 4); | 
|  194   EXPECT_EQ(1, listener_->GetStats().dropped_frames); |  193   EXPECT_EQ(2, listener_->GetStats().dropped_frames); | 
|  195  |  194  | 
|  196   capturer_->CaptureFrame(); |  195   capturer_->CaptureFrame(); | 
|  197   EXPECT_GE(listener_->GetStats().captured_frames, 5); |  196   EXPECT_GE(listener_->GetStats().captured_frames, 5); | 
|  198   EXPECT_EQ(2, listener_->GetStats().dropped_frames); |  197   EXPECT_EQ(2, listener_->GetStats().dropped_frames); | 
|  199  |  198  | 
|  200   capturer_->CaptureFrame(); |  199   capturer_->CaptureFrame(); | 
|  201   EXPECT_GE(listener_->GetStats().captured_frames, 6); |  200   EXPECT_GE(listener_->GetStats().captured_frames, 6); | 
|  202   EXPECT_EQ(2, listener_->GetStats().dropped_frames); |  201   EXPECT_EQ(3, listener_->GetStats().dropped_frames); | 
|  203  |  202  | 
|  204   capturer_->CaptureFrame(); |  203   capturer_->CaptureFrame(); | 
|  205   EXPECT_GE(listener_->GetStats().captured_frames, 7); |  204   EXPECT_GE(listener_->GetStats().captured_frames, 7); | 
|  206   EXPECT_EQ(3, listener_->GetStats().dropped_frames); |  205   EXPECT_EQ(3, listener_->GetStats().dropped_frames); | 
|  207  |  206  | 
|  208   capturer_->CaptureFrame(); |  207   capturer_->CaptureFrame(); | 
|  209   EXPECT_GE(listener_->GetStats().captured_frames, 8); |  208   EXPECT_GE(listener_->GetStats().captured_frames, 8); | 
|  210   EXPECT_EQ(3, listener_->GetStats().dropped_frames); |  209   EXPECT_EQ(4, listener_->GetStats().dropped_frames); | 
|  211  |  210  | 
|  212   capturer_->CaptureFrame(); |  211   capturer_->CaptureFrame(); | 
|  213   EXPECT_GE(listener_->GetStats().captured_frames, 9); |  212   EXPECT_GE(listener_->GetStats().captured_frames, 9); | 
|  214   EXPECT_EQ(4, listener_->GetStats().dropped_frames); |  213   EXPECT_EQ(4, listener_->GetStats().dropped_frames); | 
|  215  |  214  | 
|  216   capturer_->CaptureFrame(); |  215   capturer_->CaptureFrame(); | 
|  217   EXPECT_GE(listener_->GetStats().captured_frames, 10); |  216   EXPECT_GE(listener_->GetStats().captured_frames, 10); | 
|  218   EXPECT_EQ(4, listener_->GetStats().dropped_frames); |  217   EXPECT_EQ(5, listener_->GetStats().dropped_frames); | 
|  219 } |  218 } | 
|  220  |  219  | 
|  221 // Adapt the frame rate to be two thirds of the capture rate at the beginning. |  220 // Adapt the frame rate to be two thirds of the capture rate at the beginning. | 
|  222 // Expect the number of dropped frames to be one thirds of the number the |  221 // Expect the number of dropped frames to be one thirds of the number the | 
|  223 // captured frames. |  222 // captured frames. | 
|  224 TEST_F(VideoAdapterTest, AdaptFramerateToTwoThirds) { |  223 TEST_F(VideoAdapterTest, AdaptFramerateToTwoThirds) { | 
|  225   VideoFormat request_format = capture_format_; |  224   VideoFormat request_format = capture_format_; | 
|  226   request_format.interval = request_format.interval * 3 / 2; |  225   request_format.interval = request_format.interval * 3 / 2; | 
|  227   adapter_.OnOutputFormatRequest(request_format); |  226   adapter_.OnOutputFormatRequest(request_format); | 
|  228   EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_)); |  227   EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_)); | 
| (...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  946  |  945  | 
|  947   // Instead of getting the exact aspect ratio with cropped resolution 640x360, |  946   // Instead of getting the exact aspect ratio with cropped resolution 640x360, | 
|  948   // the resolution should be adjusted to get a perfect scale factor instead. |  947   // the resolution should be adjusted to get a perfect scale factor instead. | 
|  949   EXPECT_EQ(640, cropped_width_); |  948   EXPECT_EQ(640, cropped_width_); | 
|  950   EXPECT_EQ(368, cropped_height_); |  949   EXPECT_EQ(368, cropped_height_); | 
|  951   EXPECT_EQ(120, out_width_); |  950   EXPECT_EQ(120, out_width_); | 
|  952   EXPECT_EQ(69, out_height_); |  951   EXPECT_EQ(69, out_height_); | 
|  953 } |  952 } | 
|  954  |  953  | 
|  955 }  // namespace cricket |  954 }  // namespace cricket | 
| OLD | NEW |