Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(404)

Side by Side Diff: content/renderer/media/webrtc/webrtc_video_capturer_adapter_unittest.cc

Issue 2456443002: Add callback to copy texture backed frames in WebRtcVideoFrameAdapter (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "content/renderer/media/webrtc/webrtc_video_capturer_adapter.h" 7 #include "content/renderer/media/webrtc/webrtc_video_capturer_adapter.h"
8 #include "gpu/command_buffer/common/mailbox_holder.h"
8 #include "media/base/video_frame.h" 9 #include "media/base/video_frame.h"
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 11
12 namespace {
13 static void ReleaseMailboxCB(const gpu::SyncToken& sync_token) {}
14 } // anonymous namespace
15
11 namespace content { 16 namespace content {
12 17
13 class WebRtcVideoCapturerAdapterTest 18 class WebRtcVideoCapturerAdapterTest
14 : public rtc::VideoSinkInterface<cricket::VideoFrame>, 19 : public rtc::VideoSinkInterface<cricket::VideoFrame>,
15 public ::testing::Test { 20 public ::testing::Test {
16 public: 21 public:
17 WebRtcVideoCapturerAdapterTest() 22 WebRtcVideoCapturerAdapterTest()
18 : adapter_(false), 23 : adapter_(false),
19 output_frame_width_(0), 24 output_frame_width_(0),
20 output_frame_height_(0) { 25 output_frame_height_(0) {
(...skipping 16 matching lines...) Expand all
37 gfx::Size natural_size(natural_width, natural_height); 42 gfx::Size natural_size(natural_width, natural_height);
38 gfx::Rect view_rect(horiz_crop, vert_crop, cropped_width, cropped_height); 43 gfx::Rect view_rect(horiz_crop, vert_crop, cropped_width, cropped_height);
39 scoped_refptr<media::VideoFrame> frame = media::VideoFrame::CreateFrame( 44 scoped_refptr<media::VideoFrame> frame = media::VideoFrame::CreateFrame(
40 media::PIXEL_FORMAT_I420, coded_size, view_rect, natural_size, 45 media::PIXEL_FORMAT_I420, coded_size, view_rect, natural_size,
41 base::TimeDelta()); 46 base::TimeDelta());
42 adapter_.OnFrameCaptured(frame); 47 adapter_.OnFrameCaptured(frame);
43 EXPECT_EQ(natural_width, output_frame_width_); 48 EXPECT_EQ(natural_width, output_frame_width_);
44 EXPECT_EQ(natural_height, output_frame_height_); 49 EXPECT_EQ(natural_height, output_frame_height_);
45 } 50 }
46 51
52 void TestSourceTextureFrame() {
53 gpu::MailboxHolder holders[media::VideoFrame::kMaxPlanes] = {
54 gpu::MailboxHolder(gpu::Mailbox::Generate(), gpu::SyncToken(), 5)};
55 scoped_refptr<media::VideoFrame> frame =
56 media::VideoFrame::WrapNativeTextures(
57 media::PIXEL_FORMAT_ARGB, holders, base::Bind(&ReleaseMailboxCB),
58 gfx::Size(10, 10), gfx::Rect(10, 10), gfx::Size(10, 10),
59 base::TimeDelta());
60 adapter_.OnFrameCaptured(frame);
61 rtc::scoped_refptr<webrtc::VideoFrameBuffer> texture_frame =
62 output_frame_.video_frame_buffer();
63 EXPECT_EQ(nullptr, texture_frame->DataY());
64 rtc::scoped_refptr<webrtc::VideoFrameBuffer> copied_frame =
65 texture_frame->NativeToI420Buffer();
66 EXPECT_NE(nullptr, copied_frame->DataY());
67 }
68
47 // rtc::VideoSinkInterface 69 // rtc::VideoSinkInterface
48 void OnFrame(const cricket::VideoFrame& frame) override { 70 void OnFrame(const cricket::VideoFrame& frame) override {
71 output_frame_ = frame;
49 output_frame_width_ = frame.width(); 72 output_frame_width_ = frame.width();
50 output_frame_height_ = frame.height(); 73 output_frame_height_ = frame.height();
51 } 74 }
52 75
53 private: 76 private:
54 WebRtcVideoCapturerAdapter adapter_; 77 WebRtcVideoCapturerAdapter adapter_;
78 cricket::VideoFrame output_frame_;
55 int output_frame_width_; 79 int output_frame_width_;
56 int output_frame_height_; 80 int output_frame_height_;
57 }; 81 };
58 82
59 TEST_F(WebRtcVideoCapturerAdapterTest, CropFrameTo640360) { 83 TEST_F(WebRtcVideoCapturerAdapterTest, CropFrameTo640360) {
60 TestSourceCropFrame(640, 480, 640, 360, 640, 360); 84 TestSourceCropFrame(640, 480, 640, 360, 640, 360);
61 } 85 }
62 86
63 TEST_F(WebRtcVideoCapturerAdapterTest, CropFrameTo320320) { 87 TEST_F(WebRtcVideoCapturerAdapterTest, CropFrameTo320320) {
64 TestSourceCropFrame(640, 480, 480, 480, 320, 320); 88 TestSourceCropFrame(640, 480, 480, 480, 320, 320);
65 } 89 }
66 90
67 TEST_F(WebRtcVideoCapturerAdapterTest, Scale720To640360) { 91 TEST_F(WebRtcVideoCapturerAdapterTest, Scale720To640360) {
68 TestSourceCropFrame(1280, 720, 1280, 720, 640, 360); 92 TestSourceCropFrame(1280, 720, 1280, 720, 640, 360);
69 } 93 }
70 94
95 TEST_F(WebRtcVideoCapturerAdapterTest, SendsWithCopyTextureFrameCallback) {
96 TestSourceTextureFrame();
97 }
98
71 } // namespace content 99 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698