OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 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 Loading... |
27 | 27 |
28 #include "talk/media/webrtc/webrtcvideocapturer.h" | 28 #include "talk/media/webrtc/webrtcvideocapturer.h" |
29 | 29 |
30 #ifdef HAVE_CONFIG_H | 30 #ifdef HAVE_CONFIG_H |
31 #include <config.h> | 31 #include <config.h> |
32 #endif | 32 #endif |
33 | 33 |
34 #ifdef HAVE_WEBRTC_VIDEO | 34 #ifdef HAVE_WEBRTC_VIDEO |
35 #include "talk/media/webrtc/webrtcvideoframe.h" | 35 #include "talk/media/webrtc/webrtcvideoframe.h" |
36 #include "talk/media/webrtc/webrtcvideoframefactory.h" | 36 #include "talk/media/webrtc/webrtcvideoframefactory.h" |
| 37 #include "webrtc/base/arraysize.h" |
37 #include "webrtc/base/bind.h" | 38 #include "webrtc/base/bind.h" |
38 #include "webrtc/base/checks.h" | 39 #include "webrtc/base/checks.h" |
39 #include "webrtc/base/criticalsection.h" | 40 #include "webrtc/base/criticalsection.h" |
40 #include "webrtc/base/logging.h" | 41 #include "webrtc/base/logging.h" |
41 #include "webrtc/base/safe_conversions.h" | 42 #include "webrtc/base/safe_conversions.h" |
42 #include "webrtc/base/thread.h" | 43 #include "webrtc/base/thread.h" |
43 #include "webrtc/base/timeutils.h" | 44 #include "webrtc/base/timeutils.h" |
44 | 45 |
45 #include "webrtc/base/win32.h" // Need this to #include the impl files. | 46 #include "webrtc/base/win32.h" // Need this to #include the impl files. |
46 #include "webrtc/modules/video_capture/include/video_capture_factory.h" | 47 #include "webrtc/modules/video_capture/include/video_capture_factory.h" |
(...skipping 29 matching lines...) Expand all Loading... |
76 return webrtc::VideoCaptureFactory::CreateDeviceInfo(id); | 77 return webrtc::VideoCaptureFactory::CreateDeviceInfo(id); |
77 } | 78 } |
78 virtual void DestroyDeviceInfo(webrtc::VideoCaptureModule::DeviceInfo* info) { | 79 virtual void DestroyDeviceInfo(webrtc::VideoCaptureModule::DeviceInfo* info) { |
79 delete info; | 80 delete info; |
80 } | 81 } |
81 }; | 82 }; |
82 | 83 |
83 static bool CapabilityToFormat(const webrtc::VideoCaptureCapability& cap, | 84 static bool CapabilityToFormat(const webrtc::VideoCaptureCapability& cap, |
84 VideoFormat* format) { | 85 VideoFormat* format) { |
85 uint32_t fourcc = 0; | 86 uint32_t fourcc = 0; |
86 for (size_t i = 0; i < ARRAY_SIZE(kSupportedFourCCs); ++i) { | 87 for (size_t i = 0; i < arraysize(kSupportedFourCCs); ++i) { |
87 if (kSupportedFourCCs[i].webrtc_type == cap.rawType) { | 88 if (kSupportedFourCCs[i].webrtc_type == cap.rawType) { |
88 fourcc = kSupportedFourCCs[i].fourcc; | 89 fourcc = kSupportedFourCCs[i].fourcc; |
89 break; | 90 break; |
90 } | 91 } |
91 } | 92 } |
92 if (fourcc == 0) { | 93 if (fourcc == 0) { |
93 return false; | 94 return false; |
94 } | 95 } |
95 | 96 |
96 format->fourcc = fourcc; | 97 format->fourcc = fourcc; |
97 format->width = cap.width; | 98 format->width = cap.width; |
98 format->height = cap.height; | 99 format->height = cap.height; |
99 format->interval = VideoFormat::FpsToInterval(cap.maxFPS); | 100 format->interval = VideoFormat::FpsToInterval(cap.maxFPS); |
100 return true; | 101 return true; |
101 } | 102 } |
102 | 103 |
103 static bool FormatToCapability(const VideoFormat& format, | 104 static bool FormatToCapability(const VideoFormat& format, |
104 webrtc::VideoCaptureCapability* cap) { | 105 webrtc::VideoCaptureCapability* cap) { |
105 webrtc::RawVideoType webrtc_type = webrtc::kVideoUnknown; | 106 webrtc::RawVideoType webrtc_type = webrtc::kVideoUnknown; |
106 for (size_t i = 0; i < ARRAY_SIZE(kSupportedFourCCs); ++i) { | 107 for (size_t i = 0; i < arraysize(kSupportedFourCCs); ++i) { |
107 if (kSupportedFourCCs[i].fourcc == format.fourcc) { | 108 if (kSupportedFourCCs[i].fourcc == format.fourcc) { |
108 webrtc_type = kSupportedFourCCs[i].webrtc_type; | 109 webrtc_type = kSupportedFourCCs[i].webrtc_type; |
109 break; | 110 break; |
110 } | 111 } |
111 } | 112 } |
112 if (webrtc_type == webrtc::kVideoUnknown) { | 113 if (webrtc_type == webrtc::kVideoUnknown) { |
113 return false; | 114 return false; |
114 } | 115 } |
115 | 116 |
116 cap->width = format.width; | 117 cap->width = format.width; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 } | 165 } |
165 | 166 |
166 // Find the desired camera, by name. | 167 // Find the desired camera, by name. |
167 // In the future, comparing IDs will be more robust. | 168 // In the future, comparing IDs will be more robust. |
168 // TODO(juberti): Figure what's needed to allow this. | 169 // TODO(juberti): Figure what's needed to allow this. |
169 int num_cams = info->NumberOfDevices(); | 170 int num_cams = info->NumberOfDevices(); |
170 char vcm_id[256] = ""; | 171 char vcm_id[256] = ""; |
171 bool found = false; | 172 bool found = false; |
172 for (int index = 0; index < num_cams; ++index) { | 173 for (int index = 0; index < num_cams; ++index) { |
173 char vcm_name[256]; | 174 char vcm_name[256]; |
174 if (info->GetDeviceName(index, vcm_name, ARRAY_SIZE(vcm_name), | 175 if (info->GetDeviceName(index, vcm_name, arraysize(vcm_name), vcm_id, |
175 vcm_id, ARRAY_SIZE(vcm_id)) != -1) { | 176 arraysize(vcm_id)) != -1) { |
176 if (device.name == reinterpret_cast<char*>(vcm_name)) { | 177 if (device.name == reinterpret_cast<char*>(vcm_name)) { |
177 found = true; | 178 found = true; |
178 break; | 179 break; |
179 } | 180 } |
180 } | 181 } |
181 } | 182 } |
182 if (!found) { | 183 if (!found) { |
183 LOG(LS_WARNING) << "Failed to find capturer for id: " << device.id; | 184 LOG(LS_WARNING) << "Failed to find capturer for id: " << device.id; |
184 factory_->DestroyDeviceInfo(info); | 185 factory_->DestroyDeviceInfo(info); |
185 return false; | 186 return false; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 bool WebRtcVideoCapturer::IsRunning() { | 355 bool WebRtcVideoCapturer::IsRunning() { |
355 return (module_ != NULL && module_->CaptureStarted()); | 356 return (module_ != NULL && module_->CaptureStarted()); |
356 } | 357 } |
357 | 358 |
358 bool WebRtcVideoCapturer::GetPreferredFourccs(std::vector<uint32_t>* fourccs) { | 359 bool WebRtcVideoCapturer::GetPreferredFourccs(std::vector<uint32_t>* fourccs) { |
359 if (!fourccs) { | 360 if (!fourccs) { |
360 return false; | 361 return false; |
361 } | 362 } |
362 | 363 |
363 fourccs->clear(); | 364 fourccs->clear(); |
364 for (size_t i = 0; i < ARRAY_SIZE(kSupportedFourCCs); ++i) { | 365 for (size_t i = 0; i < arraysize(kSupportedFourCCs); ++i) { |
365 fourccs->push_back(kSupportedFourCCs[i].fourcc); | 366 fourccs->push_back(kSupportedFourCCs[i].fourcc); |
366 } | 367 } |
367 return true; | 368 return true; |
368 } | 369 } |
369 | 370 |
370 void WebRtcVideoCapturer::OnIncomingCapturedFrame( | 371 void WebRtcVideoCapturer::OnIncomingCapturedFrame( |
371 const int32_t id, | 372 const int32_t id, |
372 const webrtc::VideoFrame& sample) { | 373 const webrtc::VideoFrame& sample) { |
373 // This can only happen between Start() and Stop(). | 374 // This can only happen between Start() and Stop(). |
374 RTC_DCHECK(start_thread_); | 375 RTC_DCHECK(start_thread_); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 // Convert units from VideoFrame RenderTimeMs to CapturedFrame (nanoseconds). | 438 // Convert units from VideoFrame RenderTimeMs to CapturedFrame (nanoseconds). |
438 time_stamp = sample.render_time_ms() * rtc::kNumNanosecsPerMillisec; | 439 time_stamp = sample.render_time_ms() * rtc::kNumNanosecsPerMillisec; |
439 data_size = rtc::checked_cast<uint32_t>(length); | 440 data_size = rtc::checked_cast<uint32_t>(length); |
440 data = buffer; | 441 data = buffer; |
441 rotation = sample.rotation(); | 442 rotation = sample.rotation(); |
442 } | 443 } |
443 | 444 |
444 } // namespace cricket | 445 } // namespace cricket |
445 | 446 |
446 #endif // HAVE_WEBRTC_VIDEO | 447 #endif // HAVE_WEBRTC_VIDEO |
OLD | NEW |