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

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

Issue 1655793003: Make cricket::VideoCapturer implement VideoSourceInterface (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Adding VideoSourceInterface and letting cricket::VideoCapturer implement it Created 4 years, 10 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
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2004 Google Inc. 3 * Copyright 2004 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 16 matching lines...) Expand all
27 27
28 #ifndef TALK_MEDIA_BASE_FAKEVIDEOCAPTURER_H_ 28 #ifndef TALK_MEDIA_BASE_FAKEVIDEOCAPTURER_H_
29 #define TALK_MEDIA_BASE_FAKEVIDEOCAPTURER_H_ 29 #define TALK_MEDIA_BASE_FAKEVIDEOCAPTURER_H_
30 30
31 #include <string.h> 31 #include <string.h>
32 32
33 #include <vector> 33 #include <vector>
34 34
35 #include "talk/media/base/videocapturer.h" 35 #include "talk/media/base/videocapturer.h"
36 #include "talk/media/base/videocommon.h" 36 #include "talk/media/base/videocommon.h"
37 #include "talk/media/base/videoframe.h" 37 #include "talk/media/webrtc/webrtcvideoframe.h"
38 #include "webrtc/base/timeutils.h" 38 #include "webrtc/base/timeutils.h"
39 #ifdef HAVE_WEBRTC_VIDEO 39 #ifdef HAVE_WEBRTC_VIDEO
40 #include "talk/media/webrtc/webrtcvideoframefactory.h" 40 #include "talk/media/webrtc/webrtcvideoframefactory.h"
41 #endif 41 #endif
42 42
43 namespace cricket { 43 namespace cricket {
44 44
45 // Fake video capturer that allows the test to manually pump in frames. 45 // Fake video capturer that allows the test to manually pump in frames.
46 class FakeVideoCapturer : public cricket::VideoCapturer { 46 class FakeVideoCapturer : public cricket::VideoCapturer {
47 public: 47 public:
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 memset(reinterpret_cast<uint8_t*>(frame.data) + (size / 2), 2, 125 memset(reinterpret_cast<uint8_t*>(frame.data) + (size / 2), 2,
126 size - (size / 2)); 126 size - (size / 2));
127 memcpy(frame.data, reinterpret_cast<const uint8_t*>(&fourcc), 4); 127 memcpy(frame.data, reinterpret_cast<const uint8_t*>(&fourcc), 4);
128 frame.rotation = rotation_; 128 frame.rotation = rotation_;
129 // TODO(zhurunz): SignalFrameCaptured carry returned value to be able to 129 // TODO(zhurunz): SignalFrameCaptured carry returned value to be able to
130 // capture results from downstream. 130 // capture results from downstream.
131 SignalFrameCaptured(this, &frame); 131 SignalFrameCaptured(this, &frame);
132 return true; 132 return true;
133 } 133 }
134 134
135 void SetTime(int64_t t) {
136 next_timestamp_ = t;
137 }
138 // Helper function to generate a new frame and send it directly to
139 // |sink|, without using cricket::CapturedFrame SignalFrameCaptured.
140 void SendFrame(rtc::VideoSinkInterface<cricket::VideoFrame>* sink) {
141 int width = GetCaptureFormat()->width;
142 int height = GetCaptureFormat()->height;
143
144 rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer =
145 new rtc::RefCountedObject<webrtc::I420Buffer>(width, height);
146
147 memset(buffer->MutableData(webrtc::kYPlane), 1, width * height);
148 memset(buffer->MutableData(webrtc::kUPlane), 2,
149 (height+1)/2 * buffer->stride(webrtc::kUPlane));
150 memset(buffer->MutableData(webrtc::kVPlane), 3,
151 (height+1)/2 * buffer->stride(webrtc::kVPlane));
152
153 sink->OnFrame(WebRtcVideoFrame(buffer,
154 initial_unix_timestamp_ + next_timestamp_,
155 rotation_));
156
157 next_timestamp_ += GetCaptureFormat()->interval;
158 }
159
135 void SignalCapturedFrame(cricket::CapturedFrame* frame) { 160 void SignalCapturedFrame(cricket::CapturedFrame* frame) {
136 SignalFrameCaptured(this, frame); 161 SignalFrameCaptured(this, frame);
137 } 162 }
138 163
139 sigslot::signal1<FakeVideoCapturer*> SignalDestroyed; 164 sigslot::signal1<FakeVideoCapturer*> SignalDestroyed;
140 165
141 virtual cricket::CaptureState Start(const cricket::VideoFormat& format) { 166 virtual cricket::CaptureState Start(const cricket::VideoFormat& format) {
142 cricket::VideoFormat supported; 167 cricket::VideoFormat supported;
143 if (GetBestCaptureFormat(format, &supported)) { 168 if (GetBestCaptureFormat(format, &supported)) {
144 SetCaptureFormat(&supported); 169 SetCaptureFormat(&supported);
(...skipping 28 matching lines...) Expand all
173 bool running_; 198 bool running_;
174 int64_t initial_unix_timestamp_; 199 int64_t initial_unix_timestamp_;
175 int64_t next_timestamp_; 200 int64_t next_timestamp_;
176 bool is_screencast_; 201 bool is_screencast_;
177 webrtc::VideoRotation rotation_; 202 webrtc::VideoRotation rotation_;
178 }; 203 };
179 204
180 } // namespace cricket 205 } // namespace cricket
181 206
182 #endif // TALK_MEDIA_BASE_FAKEVIDEOCAPTURER_H_ 207 #endif // TALK_MEDIA_BASE_FAKEVIDEOCAPTURER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698