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

Side by Side Diff: webrtc/media/base/fakevideocapturer.h

Issue 2357113002: Revert of Delete VideoFrameFactory, CapturedFrame, and related code. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 3 months 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
« no previous file with comments | « webrtc/media/BUILD.gn ('k') | webrtc/media/base/videoadapter_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2004 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
11 #ifndef WEBRTC_MEDIA_BASE_FAKEVIDEOCAPTURER_H_ 11 #ifndef WEBRTC_MEDIA_BASE_FAKEVIDEOCAPTURER_H_
12 #define WEBRTC_MEDIA_BASE_FAKEVIDEOCAPTURER_H_ 12 #define WEBRTC_MEDIA_BASE_FAKEVIDEOCAPTURER_H_
13 13
14 #include <string.h> 14 #include <string.h>
15 15
16 #include <memory> 16 #include <memory>
17 #include <vector> 17 #include <vector>
18 18
19 #include "webrtc/base/timeutils.h" 19 #include "webrtc/base/timeutils.h"
20 #include "webrtc/media/base/videocapturer.h" 20 #include "webrtc/media/base/videocapturer.h"
21 #include "webrtc/media/base/videocommon.h" 21 #include "webrtc/media/base/videocommon.h"
22 #include "webrtc/media/base/videoframe.h" 22 #include "webrtc/media/base/videoframe.h"
23 #ifdef HAVE_WEBRTC_VIDEO
24 #include "webrtc/media/engine/webrtcvideoframefactory.h"
25 #endif
23 26
24 namespace cricket { 27 namespace cricket {
25 28
26 // Fake video capturer that allows the test to manually pump in frames. 29 // Fake video capturer that allows the test to manually pump in frames.
27 class FakeVideoCapturer : public cricket::VideoCapturer { 30 class FakeVideoCapturer : public cricket::VideoCapturer {
28 public: 31 public:
29 FakeVideoCapturer(bool is_screencast) 32 FakeVideoCapturer(bool is_screencast)
30 : running_(false), 33 : running_(false),
31 initial_timestamp_(rtc::TimeNanos()), 34 initial_timestamp_(rtc::TimeNanos()),
32 next_timestamp_(rtc::kNumNanosecsPerMillisec), 35 next_timestamp_(rtc::kNumNanosecsPerMillisec),
33 is_screencast_(is_screencast), 36 is_screencast_(is_screencast),
34 rotation_(webrtc::kVideoRotation_0) { 37 rotation_(webrtc::kVideoRotation_0) {
38 #ifdef HAVE_WEBRTC_VIDEO
39 set_frame_factory(new cricket::WebRtcVideoFrameFactory());
40 #endif
35 // Default supported formats. Use ResetSupportedFormats to over write. 41 // Default supported formats. Use ResetSupportedFormats to over write.
36 std::vector<cricket::VideoFormat> formats; 42 std::vector<cricket::VideoFormat> formats;
37 formats.push_back(cricket::VideoFormat(1280, 720, 43 formats.push_back(cricket::VideoFormat(1280, 720,
38 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); 44 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
39 formats.push_back(cricket::VideoFormat(640, 480, 45 formats.push_back(cricket::VideoFormat(640, 480,
40 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); 46 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
41 formats.push_back(cricket::VideoFormat(320, 240, 47 formats.push_back(cricket::VideoFormat(320, 240,
42 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); 48 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
43 formats.push_back(cricket::VideoFormat(160, 120, 49 formats.push_back(cricket::VideoFormat(160, 120,
44 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); 50 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
(...skipping 23 matching lines...) Expand all
68 // default to 30fps 74 // default to 30fps
69 return CaptureCustomFrame(width, height, 33333333, fourcc); 75 return CaptureCustomFrame(width, height, 33333333, fourcc);
70 } 76 }
71 bool CaptureCustomFrame(int width, 77 bool CaptureCustomFrame(int width,
72 int height, 78 int height,
73 int64_t timestamp_interval, 79 int64_t timestamp_interval,
74 uint32_t fourcc) { 80 uint32_t fourcc) {
75 if (!running_) { 81 if (!running_) {
76 return false; 82 return false;
77 } 83 }
78 RTC_CHECK(fourcc == FOURCC_I420); 84 // Currently, |fourcc| is always I420 or ARGB.
79 RTC_CHECK(width > 0); 85 uint32_t size = 0u;
80 RTC_CHECK(height > 0); 86 if (fourcc == cricket::FOURCC_ARGB) {
87 size = width * 4 * height;
88 } else if (fourcc == cricket::FOURCC_I420) {
89 size = width * height + 2 * ((width + 1) / 2) * ((height + 1) / 2);
90 } else {
91 return false; // Unsupported FOURCC.
92 }
93 if (size == 0u) {
94 return false; // Width and/or Height were zero.
95 }
81 96
82 int adapted_width; 97 cricket::CapturedFrame frame;
83 int adapted_height; 98 frame.width = width;
84 int crop_width; 99 frame.height = height;
85 int crop_height; 100 frame.fourcc = fourcc;
86 int crop_x; 101 frame.data_size = size;
87 int crop_y; 102 frame.time_stamp = initial_timestamp_ + next_timestamp_;
88
89 // TODO(nisse): It's a bit silly to have this logic in a fake
90 // class. Child classes of VideoCapturer are expected to call
91 // AdaptFrame, and the test case
92 // VideoCapturerTest.SinkWantsMaxPixelAndMaxPixelCountStepUp
93 // depends on this.
94 if (AdaptFrame(width, height, 0, 0, &adapted_width, &adapted_height,
95 &crop_width, &crop_height, &crop_x, &crop_y, nullptr)) {
96 rtc::scoped_refptr<webrtc::I420Buffer> buffer(
97 webrtc::I420Buffer::Create(adapted_width, adapted_height));
98 buffer->InitializeData();
99
100 OnFrame(WebRtcVideoFrame(buffer, rotation_,
101 next_timestamp_ / rtc::kNumNanosecsPerMicrosec),
102 width, height);
103 }
104 next_timestamp_ += timestamp_interval; 103 next_timestamp_ += timestamp_interval;
105 104
105 std::unique_ptr<char[]> data(new char[size]);
106 frame.data = data.get();
107 // Copy something non-zero into the buffer so Validate wont complain that
108 // the frame is all duplicate.
109 memset(frame.data, 1, size / 2);
110 memset(reinterpret_cast<uint8_t*>(frame.data) + (size / 2), 2,
111 size - (size / 2));
112 memcpy(frame.data, reinterpret_cast<const uint8_t*>(&fourcc), 4);
113 frame.rotation = rotation_;
114 // TODO(zhurunz): SignalFrameCaptured carry returned value to be able to
115 // capture results from downstream.
116 SignalFrameCaptured(this, &frame);
106 return true; 117 return true;
107 } 118 }
108 119
120 void SignalCapturedFrame(cricket::CapturedFrame* frame) {
121 SignalFrameCaptured(this, frame);
122 }
123
109 sigslot::signal1<FakeVideoCapturer*> SignalDestroyed; 124 sigslot::signal1<FakeVideoCapturer*> SignalDestroyed;
110 125
111 cricket::CaptureState Start(const cricket::VideoFormat& format) override { 126 cricket::CaptureState Start(const cricket::VideoFormat& format) override {
112 cricket::VideoFormat supported; 127 cricket::VideoFormat supported;
113 if (GetBestCaptureFormat(format, &supported)) { 128 if (GetBestCaptureFormat(format, &supported)) {
114 SetCaptureFormat(&supported); 129 SetCaptureFormat(&supported);
115 } 130 }
116 running_ = true; 131 running_ = true;
117 SetCaptureState(cricket::CS_RUNNING); 132 SetCaptureState(cricket::CS_RUNNING);
118 return cricket::CS_RUNNING; 133 return cricket::CS_RUNNING;
(...skipping 29 matching lines...) Expand all
148 int64_t initial_timestamp_; 163 int64_t initial_timestamp_;
149 int64_t next_timestamp_; 164 int64_t next_timestamp_;
150 const bool is_screencast_; 165 const bool is_screencast_;
151 rtc::Optional<bool> needs_denoising_; 166 rtc::Optional<bool> needs_denoising_;
152 webrtc::VideoRotation rotation_; 167 webrtc::VideoRotation rotation_;
153 }; 168 };
154 169
155 } // namespace cricket 170 } // namespace cricket
156 171
157 #endif // WEBRTC_MEDIA_BASE_FAKEVIDEOCAPTURER_H_ 172 #endif // WEBRTC_MEDIA_BASE_FAKEVIDEOCAPTURER_H_
OLDNEW
« no previous file with comments | « webrtc/media/BUILD.gn ('k') | webrtc/media/base/videoadapter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698