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

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

Issue 2262443003: Delete VideoFrameFactory, CapturedFrame, and related code. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Update apply_rotation_ comment. 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
26 23
27 namespace cricket { 24 namespace cricket {
28 25
29 // Fake video capturer that allows the test to manually pump in frames. 26 // Fake video capturer that allows the test to manually pump in frames.
30 class FakeVideoCapturer : public cricket::VideoCapturer { 27 class FakeVideoCapturer : public cricket::VideoCapturer {
31 public: 28 public:
32 FakeVideoCapturer(bool is_screencast) 29 FakeVideoCapturer(bool is_screencast)
33 : running_(false), 30 : running_(false),
34 initial_timestamp_(rtc::TimeNanos()), 31 initial_timestamp_(rtc::TimeNanos()),
35 next_timestamp_(rtc::kNumNanosecsPerMillisec), 32 next_timestamp_(rtc::kNumNanosecsPerMillisec),
36 is_screencast_(is_screencast), 33 is_screencast_(is_screencast),
37 rotation_(webrtc::kVideoRotation_0) { 34 rotation_(webrtc::kVideoRotation_0) {
38 #ifdef HAVE_WEBRTC_VIDEO
39 set_frame_factory(new cricket::WebRtcVideoFrameFactory());
40 #endif
41 // Default supported formats. Use ResetSupportedFormats to over write. 35 // Default supported formats. Use ResetSupportedFormats to over write.
42 std::vector<cricket::VideoFormat> formats; 36 std::vector<cricket::VideoFormat> formats;
43 formats.push_back(cricket::VideoFormat(1280, 720, 37 formats.push_back(cricket::VideoFormat(1280, 720,
44 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); 38 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
45 formats.push_back(cricket::VideoFormat(640, 480, 39 formats.push_back(cricket::VideoFormat(640, 480,
46 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); 40 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
47 formats.push_back(cricket::VideoFormat(320, 240, 41 formats.push_back(cricket::VideoFormat(320, 240,
48 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); 42 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
49 formats.push_back(cricket::VideoFormat(160, 120, 43 formats.push_back(cricket::VideoFormat(160, 120,
50 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); 44 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420));
(...skipping 23 matching lines...) Expand all
74 // default to 30fps 68 // default to 30fps
75 return CaptureCustomFrame(width, height, 33333333, fourcc); 69 return CaptureCustomFrame(width, height, 33333333, fourcc);
76 } 70 }
77 bool CaptureCustomFrame(int width, 71 bool CaptureCustomFrame(int width,
78 int height, 72 int height,
79 int64_t timestamp_interval, 73 int64_t timestamp_interval,
80 uint32_t fourcc) { 74 uint32_t fourcc) {
81 if (!running_) { 75 if (!running_) {
82 return false; 76 return false;
83 } 77 }
84 // Currently, |fourcc| is always I420 or ARGB. 78 RTC_CHECK(fourcc == FOURCC_I420);
85 uint32_t size = 0u; 79 RTC_CHECK(width > 0);
86 if (fourcc == cricket::FOURCC_ARGB) { 80 RTC_CHECK(height > 0);
87 size = width * 4 * height; 81
88 } else if (fourcc == cricket::FOURCC_I420) { 82 int adapted_width;
89 size = width * height + 2 * ((width + 1) / 2) * ((height + 1) / 2); 83 int adapted_height;
90 } else { 84 int crop_width;
91 return false; // Unsupported FOURCC. 85 int crop_height;
86 int crop_x;
87 int crop_y;
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);
92 } 103 }
93 if (size == 0u) {
94 return false; // Width and/or Height were zero.
95 }
96
97 cricket::CapturedFrame frame;
98 frame.width = width;
99 frame.height = height;
100 frame.fourcc = fourcc;
101 frame.data_size = size;
102 frame.time_stamp = initial_timestamp_ + next_timestamp_;
103 next_timestamp_ += timestamp_interval; 104 next_timestamp_ += timestamp_interval;
104 105
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);
117 return true; 106 return true;
118 } 107 }
119 108
120 void SignalCapturedFrame(cricket::CapturedFrame* frame) {
121 SignalFrameCaptured(this, frame);
122 }
123
124 sigslot::signal1<FakeVideoCapturer*> SignalDestroyed; 109 sigslot::signal1<FakeVideoCapturer*> SignalDestroyed;
125 110
126 cricket::CaptureState Start(const cricket::VideoFormat& format) override { 111 cricket::CaptureState Start(const cricket::VideoFormat& format) override {
127 cricket::VideoFormat supported; 112 cricket::VideoFormat supported;
128 if (GetBestCaptureFormat(format, &supported)) { 113 if (GetBestCaptureFormat(format, &supported)) {
129 SetCaptureFormat(&supported); 114 SetCaptureFormat(&supported);
130 } 115 }
131 running_ = true; 116 running_ = true;
132 SetCaptureState(cricket::CS_RUNNING); 117 SetCaptureState(cricket::CS_RUNNING);
133 return cricket::CS_RUNNING; 118 return cricket::CS_RUNNING;
(...skipping 29 matching lines...) Expand all
163 int64_t initial_timestamp_; 148 int64_t initial_timestamp_;
164 int64_t next_timestamp_; 149 int64_t next_timestamp_;
165 const bool is_screencast_; 150 const bool is_screencast_;
166 rtc::Optional<bool> needs_denoising_; 151 rtc::Optional<bool> needs_denoising_;
167 webrtc::VideoRotation rotation_; 152 webrtc::VideoRotation rotation_;
168 }; 153 };
169 154
170 } // namespace cricket 155 } // namespace cricket
171 156
172 #endif // WEBRTC_MEDIA_BASE_FAKEVIDEOCAPTURER_H_ 157 #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