| OLD | NEW | 
|    1 /* |    1 /* | 
|    2  * libjingle |    2  * libjingle | 
|    3  * Copyright 2008 Google Inc. |    3  * Copyright 2008 Google Inc. | 
|    4  * |    4  * | 
|    5  * Redistribution and use in source and binary forms, with or without |    5  * Redistribution and use in source and binary forms, with or without | 
|    6  * modification, are permitted provided that the following conditions are met: |    6  * modification, are permitted provided that the following conditions are met: | 
|    7  * |    7  * | 
|    8  *  1. Redistributions of source code must retain the above copyright notice, |    8  *  1. Redistributions of source code must retain the above copyright notice, | 
|    9  *     this list of conditions and the following disclaimer. |    9  *     this list of conditions and the following disclaimer. | 
|   10  *  2. Redistributions in binary form must reproduce the above copyright notice, |   10  *  2. Redistributions in binary form must reproduce the above copyright notice, | 
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  207       cricket::VideoFormat::FpsToInterval(5), cricket::FOURCC_ARGB)); |  207       cricket::VideoFormat::FpsToInterval(5), cricket::FOURCC_ARGB)); | 
|  208   capturer_.ResetSupportedFormats(formats); |  208   capturer_.ResetSupportedFormats(formats); | 
|  209  |  209  | 
|  210   EXPECT_EQ(cricket::CS_RUNNING, capturer_.Start(cricket::VideoFormat( |  210   EXPECT_EQ(cricket::CS_RUNNING, capturer_.Start(cricket::VideoFormat( | 
|  211       kWidth, |  211       kWidth, | 
|  212       kHeight, |  212       kHeight, | 
|  213       cricket::VideoFormat::FpsToInterval(30), |  213       cricket::VideoFormat::FpsToInterval(30), | 
|  214       cricket::FOURCC_ARGB))); |  214       cricket::FOURCC_ARGB))); | 
|  215   EXPECT_TRUE(capturer_.IsRunning()); |  215   EXPECT_TRUE(capturer_.IsRunning()); | 
|  216   EXPECT_EQ(0, renderer_.num_rendered_frames()); |  216   EXPECT_EQ(0, renderer_.num_rendered_frames()); | 
|  217   renderer_.SetSize(kWidth, kHeight, 0); |  | 
|  218   EXPECT_TRUE(capturer_.CaptureFrame()); |  217   EXPECT_TRUE(capturer_.CaptureFrame()); | 
|  219   EXPECT_EQ(1, renderer_.num_rendered_frames()); |  218   EXPECT_EQ(1, renderer_.num_rendered_frames()); | 
 |  219   EXPECT_EQ(kWidth, renderer_.width()); | 
 |  220   EXPECT_EQ(kHeight, renderer_.height()); | 
|  220 } |  221 } | 
|  221  |  222  | 
|  222 TEST_F(VideoCapturerTest, TestRotationPending) { |  223 TEST_F(VideoCapturerTest, TestRotationPending) { | 
|  223   int kWidth = 800; |  224   int kWidth = 800; | 
|  224   int kHeight = 400; |  225   int kHeight = 400; | 
|  225   int frame_count = 0; |  226   int frame_count = 0; | 
|  226  |  227  | 
|  227   std::vector<cricket::VideoFormat> formats; |  228   std::vector<cricket::VideoFormat> formats; | 
|  228   formats.push_back(cricket::VideoFormat(kWidth, kHeight, |  229   formats.push_back(cricket::VideoFormat(kWidth, kHeight, | 
|  229                                          cricket::VideoFormat::FpsToInterval(5), |  230                                          cricket::VideoFormat::FpsToInterval(5), | 
|  230                                          cricket::FOURCC_I420)); |  231                                          cricket::FOURCC_I420)); | 
|  231  |  232  | 
|  232   capturer_.ResetSupportedFormats(formats); |  233   capturer_.ResetSupportedFormats(formats); | 
|  233   // capturer_ should compensate rotation as default. |  234   // capturer_ should compensate rotation as default. | 
|  234   capturer_.UpdateAspectRatio(400, 200); |  235   capturer_.UpdateAspectRatio(400, 200); | 
|  235  |  236  | 
|  236   EXPECT_EQ(cricket::CS_RUNNING, |  237   EXPECT_EQ(cricket::CS_RUNNING, | 
|  237             capturer_.Start(cricket::VideoFormat( |  238             capturer_.Start(cricket::VideoFormat( | 
|  238                 kWidth, kHeight, cricket::VideoFormat::FpsToInterval(30), |  239                 kWidth, kHeight, cricket::VideoFormat::FpsToInterval(30), | 
|  239                 cricket::FOURCC_I420))); |  240                 cricket::FOURCC_I420))); | 
|  240   EXPECT_TRUE(capturer_.IsRunning()); |  241   EXPECT_TRUE(capturer_.IsRunning()); | 
|  241   EXPECT_EQ(0, renderer_.num_rendered_frames()); |  242   EXPECT_EQ(0, renderer_.num_rendered_frames()); | 
|  242  |  243  | 
|  243   // If the frame's rotation is compensated anywhere in the pipeline based on |  244   // If the frame's rotation is compensated anywhere in the pipeline based on | 
|  244   // the rotation information, the renderer should be given the right dimension |  245   // the rotation information, the renderer should be given the right dimension | 
|  245   // such that the frame could be rendered. |  246   // such that the frame could be rendered. | 
|  246  |  247  | 
|  247   // Swap the dimension for the next 2 frames which are rotated by 90 and 270 |  | 
|  248   // degree. |  | 
|  249   renderer_.SetSize(kHeight, kWidth, 0); |  | 
|  250  |  | 
|  251   capturer_.SetRotation(webrtc::kVideoRotation_90); |  248   capturer_.SetRotation(webrtc::kVideoRotation_90); | 
|  252   EXPECT_TRUE(capturer_.CaptureFrame()); |  249   EXPECT_TRUE(capturer_.CaptureFrame()); | 
|  253   EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); |  250   EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); | 
 |  251   // Swapped width and height | 
 |  252   EXPECT_EQ(kWidth, renderer_.height()); | 
 |  253   EXPECT_EQ(kHeight, renderer_.width()); | 
|  254  |  254  | 
|  255   capturer_.SetRotation(webrtc::kVideoRotation_270); |  255   capturer_.SetRotation(webrtc::kVideoRotation_270); | 
|  256   EXPECT_TRUE(capturer_.CaptureFrame()); |  256   EXPECT_TRUE(capturer_.CaptureFrame()); | 
|  257   EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); |  257   EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); | 
|  258  |  258   // Swapped width and height | 
|  259   // Reset the renderer to have corresponding width and height. |  259   EXPECT_EQ(kWidth, renderer_.height()); | 
|  260   renderer_.SetSize(kWidth, kHeight, 0); |  260   EXPECT_EQ(kHeight, renderer_.width()); | 
|  261  |  261  | 
|  262   capturer_.SetRotation(webrtc::kVideoRotation_180); |  262   capturer_.SetRotation(webrtc::kVideoRotation_180); | 
|  263   EXPECT_TRUE(capturer_.CaptureFrame()); |  263   EXPECT_TRUE(capturer_.CaptureFrame()); | 
|  264   EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); |  264   EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); | 
 |  265   // Back to normal width and height | 
 |  266   EXPECT_EQ(kWidth, renderer_.width()); | 
 |  267   EXPECT_EQ(kHeight, renderer_.height()); | 
|  265 } |  268 } | 
|  266  |  269  | 
|  267 TEST_F(VideoCapturerTest, TestRotationApplied) { |  270 TEST_F(VideoCapturerTest, TestRotationApplied) { | 
|  268   int kWidth = 800; |  271   int kWidth = 800; | 
|  269   int kHeight = 400; |  272   int kHeight = 400; | 
|  270  |  273  | 
|  271   std::vector<cricket::VideoFormat> formats; |  274   std::vector<cricket::VideoFormat> formats; | 
|  272   formats.push_back(cricket::VideoFormat(kWidth, kHeight, |  275   formats.push_back(cricket::VideoFormat(kWidth, kHeight, | 
|  273                                          cricket::VideoFormat::FpsToInterval(5), |  276                                          cricket::VideoFormat::FpsToInterval(5), | 
|  274                                          cricket::FOURCC_I420)); |  277                                          cricket::FOURCC_I420)); | 
|  275  |  278  | 
|  276   capturer_.ResetSupportedFormats(formats); |  279   capturer_.ResetSupportedFormats(formats); | 
|  277   // capturer_ should not compensate rotation. |  280   // capturer_ should not compensate rotation. | 
|  278   capturer_.SetApplyRotation(false); |  281   capturer_.SetApplyRotation(false); | 
|  279   capturer_.UpdateAspectRatio(400, 200); |  282   capturer_.UpdateAspectRatio(400, 200); | 
|  280   set_expected_compensation(false); |  283   set_expected_compensation(false); | 
|  281  |  284  | 
|  282   EXPECT_EQ(cricket::CS_RUNNING, |  285   EXPECT_EQ(cricket::CS_RUNNING, | 
|  283             capturer_.Start(cricket::VideoFormat( |  286             capturer_.Start(cricket::VideoFormat( | 
|  284                 kWidth, kHeight, cricket::VideoFormat::FpsToInterval(30), |  287                 kWidth, kHeight, cricket::VideoFormat::FpsToInterval(30), | 
|  285                 cricket::FOURCC_I420))); |  288                 cricket::FOURCC_I420))); | 
|  286   EXPECT_TRUE(capturer_.IsRunning()); |  289   EXPECT_TRUE(capturer_.IsRunning()); | 
|  287   EXPECT_EQ(0, renderer_.num_rendered_frames()); |  290   EXPECT_EQ(0, renderer_.num_rendered_frames()); | 
|  288  |  291  | 
|  289   renderer_.SetSize(kWidth, kHeight, 0); |  | 
|  290  |  | 
|  291   // If the frame's rotation is compensated anywhere in the pipeline, the frame |  292   // If the frame's rotation is compensated anywhere in the pipeline, the frame | 
|  292   // won't have its original dimension out from capturer. Since the renderer |  293   // won't have its original dimension out from capturer. Since the renderer | 
|  293   // here has the same dimension as the capturer, it will skip that frame as the |  294   // here has the same dimension as the capturer, it will skip that frame as the | 
|  294   // resolution won't match anymore. |  295   // resolution won't match anymore. | 
|  295  |  296  | 
|  296   int frame_count = 0; |  297   int frame_count = 0; | 
|  297   capturer_.SetRotation(webrtc::kVideoRotation_0); |  298   capturer_.SetRotation(webrtc::kVideoRotation_0); | 
|  298   EXPECT_TRUE(capturer_.CaptureFrame()); |  299   EXPECT_TRUE(capturer_.CaptureFrame()); | 
|  299   EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); |  300   EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); | 
|  300  |  301  | 
| (...skipping 23 matching lines...) Expand all  Loading... | 
|  324       cricket::VideoFormat::FpsToInterval(5), cricket::FOURCC_ARGB)); |  325       cricket::VideoFormat::FpsToInterval(5), cricket::FOURCC_ARGB)); | 
|  325   capturer_.ResetSupportedFormats(formats); |  326   capturer_.ResetSupportedFormats(formats); | 
|  326  |  327  | 
|  327   EXPECT_EQ(cricket::CS_RUNNING, capturer_.Start(cricket::VideoFormat( |  328   EXPECT_EQ(cricket::CS_RUNNING, capturer_.Start(cricket::VideoFormat( | 
|  328       kWidth, |  329       kWidth, | 
|  329       kHeight, |  330       kHeight, | 
|  330       cricket::VideoFormat::FpsToInterval(30), |  331       cricket::VideoFormat::FpsToInterval(30), | 
|  331       cricket::FOURCC_ARGB))); |  332       cricket::FOURCC_ARGB))); | 
|  332   EXPECT_TRUE(capturer_.IsRunning()); |  333   EXPECT_TRUE(capturer_.IsRunning()); | 
|  333   EXPECT_EQ(0, renderer_.num_rendered_frames()); |  334   EXPECT_EQ(0, renderer_.num_rendered_frames()); | 
|  334   renderer_.SetSize(2050, 1538, 0); |  | 
|  335   EXPECT_TRUE(capturer_.CaptureFrame()); |  335   EXPECT_TRUE(capturer_.CaptureFrame()); | 
|  336   EXPECT_EQ(1, renderer_.num_rendered_frames()); |  336   EXPECT_EQ(1, renderer_.num_rendered_frames()); | 
 |  337   EXPECT_EQ(kWidth / 2, renderer_.width()); | 
 |  338   EXPECT_EQ(kHeight / 2, renderer_.height()); | 
|  337 } |  339 } | 
|  338  |  340  | 
|  339 TEST_F(VideoCapturerTest, TestFourccMatch) { |  341 TEST_F(VideoCapturerTest, TestFourccMatch) { | 
|  340   cricket::VideoFormat desired(640, 480, |  342   cricket::VideoFormat desired(640, 480, | 
|  341                                cricket::VideoFormat::FpsToInterval(30), |  343                                cricket::VideoFormat::FpsToInterval(30), | 
|  342                                cricket::FOURCC_ANY); |  344                                cricket::FOURCC_ANY); | 
|  343   cricket::VideoFormat best; |  345   cricket::VideoFormat best; | 
|  344   EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); |  346   EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best)); | 
|  345   EXPECT_EQ(640, best.width); |  347   EXPECT_EQ(640, best.width); | 
|  346   EXPECT_EQ(480, best.height); |  348   EXPECT_EQ(480, best.height); | 
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  806   capturer_.set_enable_camera_list(true); |  808   capturer_.set_enable_camera_list(true); | 
|  807   capturer_.ConstrainSupportedFormats(vga_format); |  809   capturer_.ConstrainSupportedFormats(vga_format); | 
|  808   EXPECT_EQ(2u, capturer_.GetSupportedFormats()->size()); |  810   EXPECT_EQ(2u, capturer_.GetSupportedFormats()->size()); | 
|  809   // To make sure it's not just the camera list being broken, add in VGA and |  811   // To make sure it's not just the camera list being broken, add in VGA and | 
|  810   // try again. This time, only the VGA format should be there. |  812   // try again. This time, only the VGA format should be there. | 
|  811   supported_formats.push_back(vga_format); |  813   supported_formats.push_back(vga_format); | 
|  812   capturer_.ResetSupportedFormats(supported_formats); |  814   capturer_.ResetSupportedFormats(supported_formats); | 
|  813   ASSERT_EQ(1u, capturer_.GetSupportedFormats()->size()); |  815   ASSERT_EQ(1u, capturer_.GetSupportedFormats()->size()); | 
|  814   EXPECT_EQ(vga_format.height, capturer_.GetSupportedFormats()->at(0).height); |  816   EXPECT_EQ(vga_format.height, capturer_.GetSupportedFormats()->at(0).height); | 
|  815 } |  817 } | 
| OLD | NEW |