OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <algorithm> | 5 #include <algorithm> |
6 | 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/run_loop.h" |
| 9 #include "content/child/child_process.h" |
7 #include "content/renderer/media/webrtc/webrtc_video_capturer_adapter.h" | 10 #include "content/renderer/media/webrtc/webrtc_video_capturer_adapter.h" |
| 11 #include "gpu/command_buffer/common/mailbox_holder.h" |
8 #include "media/base/video_frame.h" | 12 #include "media/base/video_frame.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
10 | 14 |
| 15 namespace { |
| 16 static void ReleaseMailboxCB(const gpu::SyncToken& sync_token) {} |
| 17 } // anonymous namespace |
| 18 |
11 namespace content { | 19 namespace content { |
12 | 20 |
13 class WebRtcVideoCapturerAdapterTest | 21 class WebRtcVideoCapturerAdapterTest |
14 : public rtc::VideoSinkInterface<cricket::VideoFrame>, | 22 : public rtc::VideoSinkInterface<cricket::VideoFrame>, |
15 public ::testing::Test { | 23 public ::testing::Test { |
16 public: | 24 public: |
17 WebRtcVideoCapturerAdapterTest() | 25 WebRtcVideoCapturerAdapterTest() |
18 : adapter_(false), | 26 : adapter_(false), |
19 output_frame_width_(0), | 27 output_frame_width_(0), |
20 output_frame_height_(0) { | 28 output_frame_height_(0) { |
(...skipping 16 matching lines...) Expand all Loading... |
37 gfx::Size natural_size(natural_width, natural_height); | 45 gfx::Size natural_size(natural_width, natural_height); |
38 gfx::Rect view_rect(horiz_crop, vert_crop, cropped_width, cropped_height); | 46 gfx::Rect view_rect(horiz_crop, vert_crop, cropped_width, cropped_height); |
39 scoped_refptr<media::VideoFrame> frame = media::VideoFrame::CreateFrame( | 47 scoped_refptr<media::VideoFrame> frame = media::VideoFrame::CreateFrame( |
40 media::PIXEL_FORMAT_I420, coded_size, view_rect, natural_size, | 48 media::PIXEL_FORMAT_I420, coded_size, view_rect, natural_size, |
41 base::TimeDelta()); | 49 base::TimeDelta()); |
42 adapter_.OnFrameCaptured(frame); | 50 adapter_.OnFrameCaptured(frame); |
43 EXPECT_EQ(natural_width, output_frame_width_); | 51 EXPECT_EQ(natural_width, output_frame_width_); |
44 EXPECT_EQ(natural_height, output_frame_height_); | 52 EXPECT_EQ(natural_height, output_frame_height_); |
45 } | 53 } |
46 | 54 |
| 55 void TestSourceTextureFrame() { |
| 56 EXPECT_TRUE(message_loop_.IsCurrent()); |
| 57 gpu::MailboxHolder holders[media::VideoFrame::kMaxPlanes] = { |
| 58 gpu::MailboxHolder(gpu::Mailbox::Generate(), gpu::SyncToken(), 5)}; |
| 59 scoped_refptr<media::VideoFrame> frame = |
| 60 media::VideoFrame::WrapNativeTextures( |
| 61 media::PIXEL_FORMAT_ARGB, holders, base::Bind(&ReleaseMailboxCB), |
| 62 gfx::Size(10, 10), gfx::Rect(10, 10), gfx::Size(10, 10), |
| 63 base::TimeDelta()); |
| 64 adapter_.OnFrameCaptured(frame); |
| 65 rtc::scoped_refptr<webrtc::VideoFrameBuffer> texture_frame = |
| 66 output_frame_.video_frame_buffer(); |
| 67 EXPECT_EQ(media::VideoFrame::STORAGE_OPAQUE, |
| 68 static_cast<media::VideoFrame*>(texture_frame->native_handle()) |
| 69 ->storage_type()); |
| 70 |
| 71 rtc::scoped_refptr<webrtc::VideoFrameBuffer> copied_frame = |
| 72 texture_frame->NativeToI420Buffer(); |
| 73 EXPECT_TRUE(copied_frame); |
| 74 EXPECT_TRUE(copied_frame->DataY()); |
| 75 EXPECT_TRUE(copied_frame->DataU()); |
| 76 EXPECT_TRUE(copied_frame->DataV()); |
| 77 } |
| 78 |
47 // rtc::VideoSinkInterface | 79 // rtc::VideoSinkInterface |
48 void OnFrame(const cricket::VideoFrame& frame) override { | 80 void OnFrame(const cricket::VideoFrame& frame) override { |
| 81 output_frame_ = frame; |
49 output_frame_width_ = frame.width(); | 82 output_frame_width_ = frame.width(); |
50 output_frame_height_ = frame.height(); | 83 output_frame_height_ = frame.height(); |
51 } | 84 } |
52 | 85 |
53 private: | 86 private: |
| 87 const base::MessageLoopForIO message_loop_; |
| 88 const ChildProcess child_process_; |
| 89 |
54 WebRtcVideoCapturerAdapter adapter_; | 90 WebRtcVideoCapturerAdapter adapter_; |
| 91 cricket::VideoFrame output_frame_; |
55 int output_frame_width_; | 92 int output_frame_width_; |
56 int output_frame_height_; | 93 int output_frame_height_; |
57 }; | 94 }; |
58 | 95 |
59 TEST_F(WebRtcVideoCapturerAdapterTest, CropFrameTo640360) { | 96 TEST_F(WebRtcVideoCapturerAdapterTest, CropFrameTo640360) { |
60 TestSourceCropFrame(640, 480, 640, 360, 640, 360); | 97 TestSourceCropFrame(640, 480, 640, 360, 640, 360); |
61 } | 98 } |
62 | 99 |
63 TEST_F(WebRtcVideoCapturerAdapterTest, CropFrameTo320320) { | 100 TEST_F(WebRtcVideoCapturerAdapterTest, CropFrameTo320320) { |
64 TestSourceCropFrame(640, 480, 480, 480, 320, 320); | 101 TestSourceCropFrame(640, 480, 480, 480, 320, 320); |
65 } | 102 } |
66 | 103 |
67 TEST_F(WebRtcVideoCapturerAdapterTest, Scale720To640360) { | 104 TEST_F(WebRtcVideoCapturerAdapterTest, Scale720To640360) { |
68 TestSourceCropFrame(1280, 720, 1280, 720, 640, 360); | 105 TestSourceCropFrame(1280, 720, 1280, 720, 640, 360); |
69 } | 106 } |
70 | 107 |
| 108 TEST_F(WebRtcVideoCapturerAdapterTest, SendsWithCopyTextureFrameCallback) { |
| 109 TestSourceTextureFrame(); |
| 110 } |
| 111 |
71 } // namespace content | 112 } // namespace content |
OLD | NEW |