| 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" | 7 #include "base/bind.h" |
| 8 #include "base/optional.h" |
| 8 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 9 #include "content/child/child_process.h" | 10 #include "content/child/child_process.h" |
| 10 #include "content/renderer/media/webrtc/webrtc_video_capturer_adapter.h" | 11 #include "content/renderer/media/webrtc/webrtc_video_capturer_adapter.h" |
| 11 #include "gpu/command_buffer/common/mailbox_holder.h" | 12 #include "gpu/command_buffer/common/mailbox_holder.h" |
| 12 #include "media/base/video_frame.h" | 13 #include "media/base/video_frame.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 static void ReleaseMailboxCB(const gpu::SyncToken& sync_token) {} | 17 static void ReleaseMailboxCB(const gpu::SyncToken& sync_token) {} |
| 17 } // anonymous namespace | 18 } // anonymous namespace |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 void TestSourceTextureFrame() { | 56 void TestSourceTextureFrame() { |
| 56 EXPECT_TRUE(message_loop_.IsCurrent()); | 57 EXPECT_TRUE(message_loop_.IsCurrent()); |
| 57 gpu::MailboxHolder holders[media::VideoFrame::kMaxPlanes] = { | 58 gpu::MailboxHolder holders[media::VideoFrame::kMaxPlanes] = { |
| 58 gpu::MailboxHolder(gpu::Mailbox::Generate(), gpu::SyncToken(), 5)}; | 59 gpu::MailboxHolder(gpu::Mailbox::Generate(), gpu::SyncToken(), 5)}; |
| 59 scoped_refptr<media::VideoFrame> frame = | 60 scoped_refptr<media::VideoFrame> frame = |
| 60 media::VideoFrame::WrapNativeTextures( | 61 media::VideoFrame::WrapNativeTextures( |
| 61 media::PIXEL_FORMAT_ARGB, holders, base::Bind(&ReleaseMailboxCB), | 62 media::PIXEL_FORMAT_ARGB, holders, base::Bind(&ReleaseMailboxCB), |
| 62 gfx::Size(10, 10), gfx::Rect(10, 10), gfx::Size(10, 10), | 63 gfx::Size(10, 10), gfx::Rect(10, 10), gfx::Size(10, 10), |
| 63 base::TimeDelta()); | 64 base::TimeDelta()); |
| 64 adapter_.OnFrameCaptured(frame); | 65 adapter_.OnFrameCaptured(frame); |
| 66 ASSERT_TRUE(output_frame_); |
| 65 rtc::scoped_refptr<webrtc::VideoFrameBuffer> texture_frame = | 67 rtc::scoped_refptr<webrtc::VideoFrameBuffer> texture_frame = |
| 66 output_frame_.video_frame_buffer(); | 68 output_frame_->video_frame_buffer(); |
| 67 EXPECT_EQ(media::VideoFrame::STORAGE_OPAQUE, | 69 EXPECT_EQ(media::VideoFrame::STORAGE_OPAQUE, |
| 68 static_cast<media::VideoFrame*>(texture_frame->native_handle()) | 70 static_cast<media::VideoFrame*>(texture_frame->native_handle()) |
| 69 ->storage_type()); | 71 ->storage_type()); |
| 70 | 72 |
| 71 rtc::scoped_refptr<webrtc::VideoFrameBuffer> copied_frame = | 73 rtc::scoped_refptr<webrtc::VideoFrameBuffer> copied_frame = |
| 72 texture_frame->NativeToI420Buffer(); | 74 texture_frame->NativeToI420Buffer(); |
| 73 EXPECT_TRUE(copied_frame); | 75 EXPECT_TRUE(copied_frame); |
| 74 EXPECT_TRUE(copied_frame->DataY()); | 76 EXPECT_TRUE(copied_frame->DataY()); |
| 75 EXPECT_TRUE(copied_frame->DataU()); | 77 EXPECT_TRUE(copied_frame->DataU()); |
| 76 EXPECT_TRUE(copied_frame->DataV()); | 78 EXPECT_TRUE(copied_frame->DataV()); |
| 77 } | 79 } |
| 78 | 80 |
| 79 // rtc::VideoSinkInterface | 81 // rtc::VideoSinkInterface |
| 80 void OnFrame(const webrtc::VideoFrame& frame) override { | 82 void OnFrame(const webrtc::VideoFrame& frame) override { |
| 81 output_frame_ = frame; | 83 output_frame_ = base::Optional<webrtc::VideoFrame>(frame); |
| 82 output_frame_width_ = frame.width(); | 84 output_frame_width_ = frame.width(); |
| 83 output_frame_height_ = frame.height(); | 85 output_frame_height_ = frame.height(); |
| 84 } | 86 } |
| 85 | 87 |
| 86 private: | 88 private: |
| 87 const base::MessageLoopForIO message_loop_; | 89 const base::MessageLoopForIO message_loop_; |
| 88 const ChildProcess child_process_; | 90 const ChildProcess child_process_; |
| 89 | 91 |
| 90 WebRtcVideoCapturerAdapter adapter_; | 92 WebRtcVideoCapturerAdapter adapter_; |
| 91 // TODO(nisse): Default constructor is deprecated. Use std::optional? | 93 base::Optional<webrtc::VideoFrame> output_frame_; |
| 92 webrtc::VideoFrame output_frame_; | |
| 93 int output_frame_width_; | 94 int output_frame_width_; |
| 94 int output_frame_height_; | 95 int output_frame_height_; |
| 95 }; | 96 }; |
| 96 | 97 |
| 97 TEST_F(WebRtcVideoCapturerAdapterTest, CropFrameTo640360) { | 98 TEST_F(WebRtcVideoCapturerAdapterTest, CropFrameTo640360) { |
| 98 TestSourceCropFrame(640, 480, 640, 360, 640, 360); | 99 TestSourceCropFrame(640, 480, 640, 360, 640, 360); |
| 99 } | 100 } |
| 100 | 101 |
| 101 TEST_F(WebRtcVideoCapturerAdapterTest, CropFrameTo320320) { | 102 TEST_F(WebRtcVideoCapturerAdapterTest, CropFrameTo320320) { |
| 102 TestSourceCropFrame(640, 480, 480, 480, 320, 320); | 103 TestSourceCropFrame(640, 480, 480, 480, 320, 320); |
| 103 } | 104 } |
| 104 | 105 |
| 105 TEST_F(WebRtcVideoCapturerAdapterTest, Scale720To640360) { | 106 TEST_F(WebRtcVideoCapturerAdapterTest, Scale720To640360) { |
| 106 TestSourceCropFrame(1280, 720, 1280, 720, 640, 360); | 107 TestSourceCropFrame(1280, 720, 1280, 720, 640, 360); |
| 107 } | 108 } |
| 108 | 109 |
| 109 TEST_F(WebRtcVideoCapturerAdapterTest, SendsWithCopyTextureFrameCallback) { | 110 TEST_F(WebRtcVideoCapturerAdapterTest, SendsWithCopyTextureFrameCallback) { |
| 110 TestSourceTextureFrame(); | 111 TestSourceTextureFrame(); |
| 111 } | 112 } |
| 112 | 113 |
| 113 } // namespace content | 114 } // namespace content |
| OLD | NEW |