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

Side by Side Diff: webrtc/media/engine/webrtcvideocapturer.cc

Issue 2765243002: Delete RawVideoType enum, use the VideoType enum instead. (Closed)
Patch Set: Define constant webrtc::kI420, for backwards compatibility. Created 3 years, 7 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 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2011 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 #include "webrtc/media/engine/webrtcvideocapturer.h" 11 #include "webrtc/media/engine/webrtcvideocapturer.h"
12 12
13 #include "webrtc/base/arraysize.h" 13 #include "webrtc/base/arraysize.h"
14 #include "webrtc/base/bind.h" 14 #include "webrtc/base/bind.h"
15 #include "webrtc/base/checks.h" 15 #include "webrtc/base/checks.h"
16 #include "webrtc/base/criticalsection.h" 16 #include "webrtc/base/criticalsection.h"
17 #include "webrtc/base/logging.h" 17 #include "webrtc/base/logging.h"
18 #include "webrtc/base/safe_conversions.h" 18 #include "webrtc/base/safe_conversions.h"
19 #include "webrtc/base/thread.h" 19 #include "webrtc/base/thread.h"
20 #include "webrtc/base/timeutils.h" 20 #include "webrtc/base/timeutils.h"
21 21
22 #include "webrtc/base/win32.h" // Need this to #include the impl files. 22 #include "webrtc/base/win32.h" // Need this to #include the impl files.
23 #include "webrtc/modules/video_capture/video_capture_factory.h" 23 #include "webrtc/modules/video_capture/video_capture_factory.h"
24 #include "webrtc/system_wrappers/include/field_trial.h" 24 #include "webrtc/system_wrappers/include/field_trial.h"
25 25
26 namespace cricket { 26 namespace cricket {
27 27
28 namespace {
28 struct kVideoFourCCEntry { 29 struct kVideoFourCCEntry {
29 uint32_t fourcc; 30 uint32_t fourcc;
30 webrtc::RawVideoType webrtc_type; 31 webrtc::VideoType webrtc_type;
31 }; 32 };
32 33
33 // This indicates our format preferences and defines a mapping between 34 // This indicates our format preferences and defines a mapping between
34 // webrtc::RawVideoType (from video_capture_defines.h) to our FOURCCs. 35 // webrtc::RawVideoType (from video_capture_defines.h) to our FOURCCs.
35 static kVideoFourCCEntry kSupportedFourCCs[] = { 36 kVideoFourCCEntry kSupportedFourCCs[] = {
36 { FOURCC_I420, webrtc::kVideoI420 }, // 12 bpp, no conversion. 37 {FOURCC_I420, webrtc::VideoType::kI420}, // 12 bpp, no conversion.
37 { FOURCC_YV12, webrtc::kVideoYV12 }, // 12 bpp, no conversion. 38 {FOURCC_YV12, webrtc::VideoType::kYV12}, // 12 bpp, no conversion.
38 { FOURCC_YUY2, webrtc::kVideoYUY2 }, // 16 bpp, fast conversion. 39 {FOURCC_YUY2, webrtc::VideoType::kYUY2}, // 16 bpp, fast conversion.
39 { FOURCC_UYVY, webrtc::kVideoUYVY }, // 16 bpp, fast conversion. 40 {FOURCC_UYVY, webrtc::VideoType::kUYVY}, // 16 bpp, fast conversion.
40 { FOURCC_NV12, webrtc::kVideoNV12 }, // 12 bpp, fast conversion. 41 {FOURCC_NV12, webrtc::VideoType::kNV12}, // 12 bpp, fast conversion.
41 { FOURCC_NV21, webrtc::kVideoNV21 }, // 12 bpp, fast conversion. 42 {FOURCC_NV21, webrtc::VideoType::kNV21}, // 12 bpp, fast conversion.
42 { FOURCC_MJPG, webrtc::kVideoMJPEG }, // compressed, slow conversion. 43 {FOURCC_MJPG, webrtc::VideoType::kMJPEG}, // compressed, slow conversion.
43 { FOURCC_ARGB, webrtc::kVideoARGB }, // 32 bpp, slow conversion. 44 {FOURCC_ARGB, webrtc::VideoType::kARGB}, // 32 bpp, slow conversion.
44 { FOURCC_24BG, webrtc::kVideoRGB24 }, // 24 bpp, slow conversion. 45 {FOURCC_24BG, webrtc::VideoType::kRGB24}, // 24 bpp, slow conversion.
45 }; 46 };
46 47
47 class WebRtcVcmFactory : public WebRtcVcmFactoryInterface { 48 bool CapabilityToFormat(const webrtc::VideoCaptureCapability& cap,
48 public: 49 VideoFormat* format) {
49 virtual rtc::scoped_refptr<webrtc::VideoCaptureModule> Create(
50 const char* device) {
51 return webrtc::VideoCaptureFactory::Create(device);
52 }
53 virtual webrtc::VideoCaptureModule::DeviceInfo* CreateDeviceInfo() {
54 return webrtc::VideoCaptureFactory::CreateDeviceInfo();
55 }
56 virtual void DestroyDeviceInfo(webrtc::VideoCaptureModule::DeviceInfo* info) {
57 delete info;
58 }
59 };
60
61 static bool CapabilityToFormat(const webrtc::VideoCaptureCapability& cap,
62 VideoFormat* format) {
63 uint32_t fourcc = 0; 50 uint32_t fourcc = 0;
64 for (size_t i = 0; i < arraysize(kSupportedFourCCs); ++i) { 51 for (size_t i = 0; i < arraysize(kSupportedFourCCs); ++i) {
65 if (kSupportedFourCCs[i].webrtc_type == cap.rawType) { 52 if (kSupportedFourCCs[i].webrtc_type == cap.videoType) {
66 fourcc = kSupportedFourCCs[i].fourcc; 53 fourcc = kSupportedFourCCs[i].fourcc;
67 break; 54 break;
68 } 55 }
69 } 56 }
70 if (fourcc == 0) { 57 if (fourcc == 0) {
71 return false; 58 return false;
72 } 59 }
73 60
74 format->fourcc = fourcc; 61 format->fourcc = fourcc;
75 format->width = cap.width; 62 format->width = cap.width;
76 format->height = cap.height; 63 format->height = cap.height;
77 format->interval = VideoFormat::FpsToInterval(cap.maxFPS); 64 format->interval = VideoFormat::FpsToInterval(cap.maxFPS);
78 return true; 65 return true;
79 } 66 }
80 67
81 static bool FormatToCapability(const VideoFormat& format, 68 bool FormatToCapability(const VideoFormat& format,
82 webrtc::VideoCaptureCapability* cap) { 69 webrtc::VideoCaptureCapability* cap) {
83 webrtc::RawVideoType webrtc_type = webrtc::kVideoUnknown; 70 webrtc::VideoType webrtc_type = webrtc::VideoType::kUnknown;
84 for (size_t i = 0; i < arraysize(kSupportedFourCCs); ++i) { 71 for (size_t i = 0; i < arraysize(kSupportedFourCCs); ++i) {
85 if (kSupportedFourCCs[i].fourcc == format.fourcc) { 72 if (kSupportedFourCCs[i].fourcc == format.fourcc) {
86 webrtc_type = kSupportedFourCCs[i].webrtc_type; 73 webrtc_type = kSupportedFourCCs[i].webrtc_type;
87 break; 74 break;
88 } 75 }
89 } 76 }
90 if (webrtc_type == webrtc::kVideoUnknown) { 77 if (webrtc_type == webrtc::VideoType::kUnknown) {
91 return false; 78 return false;
92 } 79 }
93 80
94 cap->width = format.width; 81 cap->width = format.width;
95 cap->height = format.height; 82 cap->height = format.height;
96 cap->maxFPS = VideoFormat::IntervalToFps(format.interval); 83 cap->maxFPS = VideoFormat::IntervalToFps(format.interval);
97 cap->rawType = webrtc_type; 84 cap->videoType = webrtc_type;
98 cap->interlaced = false; 85 cap->interlaced = false;
99 return true; 86 return true;
100 } 87 }
101 88
89 } // namespace
90
91 class WebRtcVcmFactory : public WebRtcVcmFactoryInterface {
92 public:
93 virtual rtc::scoped_refptr<webrtc::VideoCaptureModule> Create(
94 const char* device) {
95 return webrtc::VideoCaptureFactory::Create(device);
96 }
97 virtual webrtc::VideoCaptureModule::DeviceInfo* CreateDeviceInfo() {
98 return webrtc::VideoCaptureFactory::CreateDeviceInfo();
99 }
100 virtual void DestroyDeviceInfo(webrtc::VideoCaptureModule::DeviceInfo* info) {
101 delete info;
102 }
103 };
104
102 /////////////////////////////////////////////////////////////////////////// 105 ///////////////////////////////////////////////////////////////////////////
103 // Implementation of class WebRtcVideoCapturer 106 // Implementation of class WebRtcVideoCapturer
104 /////////////////////////////////////////////////////////////////////////// 107 ///////////////////////////////////////////////////////////////////////////
105 108
106 WebRtcVideoCapturer::WebRtcVideoCapturer() 109 WebRtcVideoCapturer::WebRtcVideoCapturer()
107 : factory_(new WebRtcVcmFactory), 110 : factory_(new WebRtcVcmFactory),
108 module_(nullptr), 111 module_(nullptr),
109 captured_frames_(0), 112 captured_frames_(0),
110 start_thread_(nullptr), 113 start_thread_(nullptr),
111 async_invoker_(nullptr) {} 114 async_invoker_(nullptr) {}
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 std::vector<VideoFormat> supported; 161 std::vector<VideoFormat> supported;
159 int32_t num_caps = info->NumberOfCapabilities(vcm_id); 162 int32_t num_caps = info->NumberOfCapabilities(vcm_id);
160 for (int32_t i = 0; i < num_caps; ++i) { 163 for (int32_t i = 0; i < num_caps; ++i) {
161 webrtc::VideoCaptureCapability cap; 164 webrtc::VideoCaptureCapability cap;
162 if (info->GetCapability(vcm_id, i, cap) != -1) { 165 if (info->GetCapability(vcm_id, i, cap) != -1) {
163 VideoFormat format; 166 VideoFormat format;
164 if (CapabilityToFormat(cap, &format)) { 167 if (CapabilityToFormat(cap, &format)) {
165 supported.push_back(format); 168 supported.push_back(format);
166 } else { 169 } else {
167 LOG(LS_WARNING) << "Ignoring unsupported WebRTC capture format " 170 LOG(LS_WARNING) << "Ignoring unsupported WebRTC capture format "
168 << cap.rawType; 171 << static_cast<int>(cap.videoType);
169 } 172 }
170 } 173 }
171 } 174 }
172 factory_->DestroyDeviceInfo(info); 175 factory_->DestroyDeviceInfo(info);
173 176
174 if (supported.empty()) { 177 if (supported.empty()) {
175 LOG(LS_ERROR) << "Failed to find usable formats for id: " << device.id; 178 LOG(LS_ERROR) << "Failed to find usable formats for id: " << device.id;
176 return false; 179 return false;
177 } 180 }
178 181
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 if (1 == captured_frames_) { 344 if (1 == captured_frames_) {
342 LOG(LS_INFO) << "Captured frame size " 345 LOG(LS_INFO) << "Captured frame size "
343 << sample.width() << "x" << sample.height() 346 << sample.width() << "x" << sample.height()
344 << ". Expected format " << GetCaptureFormat()->ToString(); 347 << ". Expected format " << GetCaptureFormat()->ToString();
345 } 348 }
346 349
347 VideoCapturer::OnFrame(sample, sample.width(), sample.height()); 350 VideoCapturer::OnFrame(sample, sample.width(), sample.height());
348 } 351 }
349 352
350 } // namespace cricket 353 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/common_video/libyuv/webrtc_libyuv.cc ('k') | webrtc/media/engine/webrtcvideocapturer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698