OLD | NEW |
---|---|
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 if (fourcc == cricket::FOURCC_ARGB) { | 80 if (fourcc == cricket::FOURCC_ARGB) { |
87 size = width * 4 * height; | 81 size = width * 4 * height; |
88 } else if (fourcc == cricket::FOURCC_I420) { | 82 } else if (fourcc == cricket::FOURCC_I420) { |
89 size = width * height + 2 * ((width + 1) / 2) * ((height + 1) / 2); | 83 size = width * height + 2 * ((width + 1) / 2) * ((height + 1) / 2); |
90 } else { | 84 } else { |
91 return false; // Unsupported FOURCC. | 85 return false; // Unsupported FOURCC. |
92 } | 86 } |
93 if (size == 0u) { | 87 if (size == 0u) { |
94 return false; // Width and/or Height were zero. | 88 return false; // Width and/or Height were zero. |
95 } | 89 } |
96 | 90 #if 0 |
91 // TODO(nisse): Create a cricket::VideoFrame and call OnFrame. | |
97 cricket::CapturedFrame frame; | 92 cricket::CapturedFrame frame; |
98 frame.width = width; | 93 frame.width = width; |
99 frame.height = height; | 94 frame.height = height; |
100 frame.fourcc = fourcc; | 95 frame.fourcc = fourcc; |
101 frame.data_size = size; | 96 frame.data_size = size; |
102 frame.time_stamp = initial_timestamp_ + next_timestamp_; | 97 frame.time_stamp = initial_timestamp_ + next_timestamp_; |
103 next_timestamp_ += timestamp_interval; | 98 next_timestamp_ += timestamp_interval; |
104 | 99 |
105 std::unique_ptr<char[]> data(new char[size]); | 100 std::unique_ptr<char[]> data(new char[size]); |
106 frame.data = data.get(); | 101 frame.data = data.get(); |
107 // Copy something non-zero into the buffer so Validate wont complain that | 102 // Copy something non-zero into the buffer so Validate wont complain that |
108 // the frame is all duplicate. | 103 // the frame is all duplicate. |
109 memset(frame.data, 1, size / 2); | 104 memset(frame.data, 1, size / 2); |
110 memset(reinterpret_cast<uint8_t*>(frame.data) + (size / 2), 2, | 105 memset(reinterpret_cast<uint8_t*>(frame.data) + (size / 2), 2, |
111 size - (size / 2)); | 106 size - (size / 2)); |
112 memcpy(frame.data, reinterpret_cast<const uint8_t*>(&fourcc), 4); | 107 memcpy(frame.data, reinterpret_cast<const uint8_t*>(&fourcc), 4); |
113 frame.rotation = rotation_; | 108 frame.rotation = rotation_; |
114 // TODO(zhurunz): SignalFrameCaptured carry returned value to be able to | 109 // TODO(zhurunz): SignalFrameCaptured carry returned value to be able to |
115 // capture results from downstream. | 110 // capture results from downstream. |
116 SignalFrameCaptured(this, &frame); | 111 SignalFrameCaptured(this, &frame); |
112 #endif | |
113 // TODO(nisse): XXX Keep to avoid warning. | |
pthatcher1
2016/08/23 00:13:13
So are you going to delete this too?
nisse-webrtc
2016/08/23 06:46:39
No, but the #if:ed out block needs to be rewritten
| |
114 next_timestamp_ += timestamp_interval; | |
115 | |
117 return true; | 116 return true; |
118 } | 117 } |
119 | 118 |
120 void SignalCapturedFrame(cricket::CapturedFrame* frame) { | |
121 SignalFrameCaptured(this, frame); | |
122 } | |
123 | |
124 sigslot::signal1<FakeVideoCapturer*> SignalDestroyed; | 119 sigslot::signal1<FakeVideoCapturer*> SignalDestroyed; |
125 | 120 |
126 virtual cricket::CaptureState Start(const cricket::VideoFormat& format) { | 121 virtual cricket::CaptureState Start(const cricket::VideoFormat& format) { |
127 cricket::VideoFormat supported; | 122 cricket::VideoFormat supported; |
128 if (GetBestCaptureFormat(format, &supported)) { | 123 if (GetBestCaptureFormat(format, &supported)) { |
129 SetCaptureFormat(&supported); | 124 SetCaptureFormat(&supported); |
130 } | 125 } |
131 running_ = true; | 126 running_ = true; |
132 SetCaptureState(cricket::CS_RUNNING); | 127 SetCaptureState(cricket::CS_RUNNING); |
133 return cricket::CS_RUNNING; | 128 return cricket::CS_RUNNING; |
(...skipping 21 matching lines...) Expand all Loading... | |
155 bool running_; | 150 bool running_; |
156 int64_t initial_timestamp_; | 151 int64_t initial_timestamp_; |
157 int64_t next_timestamp_; | 152 int64_t next_timestamp_; |
158 const bool is_screencast_; | 153 const bool is_screencast_; |
159 webrtc::VideoRotation rotation_; | 154 webrtc::VideoRotation rotation_; |
160 }; | 155 }; |
161 | 156 |
162 } // namespace cricket | 157 } // namespace cricket |
163 | 158 |
164 #endif // WEBRTC_MEDIA_BASE_FAKEVIDEOCAPTURER_H_ | 159 #endif // WEBRTC_MEDIA_BASE_FAKEVIDEOCAPTURER_H_ |
OLD | NEW |