OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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/base/capturemanager.h" | 11 #include "webrtc/media/base/capturemanager.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 | 14 |
15 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
16 #include "webrtc/base/logging.h" | 16 #include "webrtc/base/logging.h" |
17 #include "webrtc/media/base/videocapturer.h" | 17 #include "webrtc/media/base/videocapturer.h" |
18 | 18 |
19 namespace cricket { | 19 namespace cricket { |
20 | 20 |
21 // CaptureManager helper class. | 21 // CaptureManager helper class. |
22 class VideoCapturerState { | 22 class VideoCapturerState { |
23 public: | 23 public: |
24 static const VideoFormatPod kDefaultCaptureFormat; | 24 static const VideoFormatPod kDefaultCaptureFormat; |
25 | 25 |
26 explicit VideoCapturerState(VideoCapturer* capturer); | 26 static VideoCapturerState* Create(VideoCapturer* video_capturer); |
27 ~VideoCapturerState() {} | 27 ~VideoCapturerState() {} |
28 | 28 |
29 void AddCaptureResolution(const VideoFormat& desired_format); | 29 void AddCaptureResolution(const VideoFormat& desired_format); |
30 bool RemoveCaptureResolution(const VideoFormat& format); | 30 bool RemoveCaptureResolution(const VideoFormat& format); |
31 VideoFormat GetHighestFormat(VideoCapturer* video_capturer) const; | 31 VideoFormat GetHighestFormat(VideoCapturer* video_capturer) const; |
32 | 32 |
33 int IncCaptureStartRef(); | 33 int IncCaptureStartRef(); |
34 int DecCaptureStartRef(); | 34 int DecCaptureStartRef(); |
| 35 CaptureRenderAdapter* adapter() { |
| 36 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 37 return adapter_.get(); |
| 38 } |
35 VideoCapturer* GetVideoCapturer() { | 39 VideoCapturer* GetVideoCapturer() { |
36 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 40 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
37 return video_capturer_; | 41 return adapter()->video_capturer(); |
38 } | 42 } |
39 | 43 |
40 int start_count() const { | 44 int start_count() const { |
41 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 45 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
42 return start_count_; | 46 return start_count_; |
43 } | 47 } |
44 | 48 |
45 private: | 49 private: |
46 struct CaptureResolutionInfo { | 50 struct CaptureResolutionInfo { |
47 VideoFormat video_format; | 51 VideoFormat video_format; |
48 int format_ref_count; | 52 int format_ref_count; |
49 }; | 53 }; |
50 typedef std::vector<CaptureResolutionInfo> CaptureFormats; | 54 typedef std::vector<CaptureResolutionInfo> CaptureFormats; |
51 | 55 |
| 56 explicit VideoCapturerState(CaptureRenderAdapter* adapter); |
| 57 |
52 rtc::ThreadChecker thread_checker_; | 58 rtc::ThreadChecker thread_checker_; |
| 59 rtc::scoped_ptr<CaptureRenderAdapter> adapter_; |
53 | 60 |
54 VideoCapturer* video_capturer_; | |
55 int start_count_; | 61 int start_count_; |
56 CaptureFormats capture_formats_; | 62 CaptureFormats capture_formats_; |
57 }; | 63 }; |
58 | 64 |
59 const VideoFormatPod VideoCapturerState::kDefaultCaptureFormat = { | 65 const VideoFormatPod VideoCapturerState::kDefaultCaptureFormat = { |
60 640, 360, FPS_TO_INTERVAL(30), FOURCC_ANY | 66 640, 360, FPS_TO_INTERVAL(30), FOURCC_ANY |
61 }; | 67 }; |
62 | 68 |
63 VideoCapturerState::VideoCapturerState(VideoCapturer* capturer) | 69 VideoCapturerState::VideoCapturerState(CaptureRenderAdapter* adapter) |
64 : video_capturer_(capturer), start_count_(1) {} | 70 : adapter_(adapter), start_count_(1) {} |
| 71 |
| 72 // static |
| 73 VideoCapturerState* VideoCapturerState::Create(VideoCapturer* video_capturer) { |
| 74 CaptureRenderAdapter* adapter = CaptureRenderAdapter::Create(video_capturer); |
| 75 if (!adapter) { |
| 76 return NULL; |
| 77 } |
| 78 return new VideoCapturerState(adapter); |
| 79 } |
65 | 80 |
66 void VideoCapturerState::AddCaptureResolution( | 81 void VideoCapturerState::AddCaptureResolution( |
67 const VideoFormat& desired_format) { | 82 const VideoFormat& desired_format) { |
68 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 83 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
69 for (CaptureFormats::iterator iter = capture_formats_.begin(); | 84 for (CaptureFormats::iterator iter = capture_formats_.begin(); |
70 iter != capture_formats_.end(); ++iter) { | 85 iter != capture_formats_.end(); ++iter) { |
71 if (desired_format == iter->video_format) { | 86 if (desired_format == iter->video_format) { |
72 ++(iter->format_ref_count); | 87 ++(iter->format_ref_count); |
73 return; | 88 return; |
74 } | 89 } |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 return true; | 269 return true; |
255 } | 270 } |
256 | 271 |
257 void CaptureManager::AddVideoSink(VideoCapturer* video_capturer, | 272 void CaptureManager::AddVideoSink(VideoCapturer* video_capturer, |
258 rtc::VideoSinkInterface<VideoFrame>* sink) { | 273 rtc::VideoSinkInterface<VideoFrame>* sink) { |
259 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 274 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
260 // TODO(nisse): Do we really need to tolerate NULL inputs? | 275 // TODO(nisse): Do we really need to tolerate NULL inputs? |
261 if (!video_capturer || !sink) { | 276 if (!video_capturer || !sink) { |
262 return; | 277 return; |
263 } | 278 } |
264 rtc::VideoSinkWants wants; | 279 CaptureRenderAdapter* adapter = GetAdapter(video_capturer); |
265 // Renderers must be able to apply rotation. | 280 if (!adapter) { |
266 wants.rotation_applied = false; | 281 return; |
267 video_capturer->AddOrUpdateSink(sink, wants); | 282 } |
| 283 adapter->AddSink(sink); |
268 } | 284 } |
269 | 285 |
270 void CaptureManager::RemoveVideoSink( | 286 void CaptureManager::RemoveVideoSink( |
271 VideoCapturer* video_capturer, | 287 VideoCapturer* video_capturer, |
272 rtc::VideoSinkInterface<VideoFrame>* sink) { | 288 rtc::VideoSinkInterface<VideoFrame>* sink) { |
273 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 289 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
274 if (!video_capturer || !sink) { | 290 if (!video_capturer || !sink) { |
275 return; | 291 return; |
276 } | 292 } |
277 video_capturer->RemoveSink(sink); | 293 CaptureRenderAdapter* adapter = GetAdapter(video_capturer); |
| 294 if (!adapter) { |
| 295 return; |
| 296 } |
| 297 adapter->RemoveSink(sink); |
278 } | 298 } |
279 | 299 |
280 bool CaptureManager::IsCapturerRegistered(VideoCapturer* video_capturer) const { | 300 bool CaptureManager::IsCapturerRegistered(VideoCapturer* video_capturer) const { |
281 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 301 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
282 return GetCaptureState(video_capturer) != NULL; | 302 return GetCaptureState(video_capturer) != NULL; |
283 } | 303 } |
284 | 304 |
285 bool CaptureManager::RegisterVideoCapturer(VideoCapturer* video_capturer) { | 305 bool CaptureManager::RegisterVideoCapturer(VideoCapturer* video_capturer) { |
286 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 306 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
287 VideoCapturerState* capture_state = new VideoCapturerState(video_capturer); | 307 VideoCapturerState* capture_state = |
| 308 VideoCapturerState::Create(video_capturer); |
| 309 if (!capture_state) { |
| 310 return false; |
| 311 } |
288 capture_states_[video_capturer] = capture_state; | 312 capture_states_[video_capturer] = capture_state; |
289 SignalCapturerStateChange.repeat(video_capturer->SignalStateChange); | 313 SignalCapturerStateChange.repeat(video_capturer->SignalStateChange); |
290 return true; | 314 return true; |
291 } | 315 } |
292 | 316 |
293 void CaptureManager::UnregisterVideoCapturer( | 317 void CaptureManager::UnregisterVideoCapturer( |
294 VideoCapturerState* capture_state) { | 318 VideoCapturerState* capture_state) { |
295 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 319 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
296 VideoCapturer* video_capturer = capture_state->GetVideoCapturer(); | 320 VideoCapturer* video_capturer = capture_state->GetVideoCapturer(); |
297 capture_states_.erase(video_capturer); | 321 capture_states_.erase(video_capturer); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 VideoCapturerState* CaptureManager::GetCaptureState( | 369 VideoCapturerState* CaptureManager::GetCaptureState( |
346 VideoCapturer* video_capturer) const { | 370 VideoCapturer* video_capturer) const { |
347 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 371 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
348 CaptureStates::const_iterator iter = capture_states_.find(video_capturer); | 372 CaptureStates::const_iterator iter = capture_states_.find(video_capturer); |
349 if (iter == capture_states_.end()) { | 373 if (iter == capture_states_.end()) { |
350 return NULL; | 374 return NULL; |
351 } | 375 } |
352 return iter->second; | 376 return iter->second; |
353 } | 377 } |
354 | 378 |
| 379 CaptureRenderAdapter* CaptureManager::GetAdapter( |
| 380 VideoCapturer* video_capturer) const { |
| 381 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 382 VideoCapturerState* capture_state = GetCaptureState(video_capturer); |
| 383 if (!capture_state) { |
| 384 return NULL; |
| 385 } |
| 386 return capture_state->adapter(); |
| 387 } |
| 388 |
355 } // namespace cricket | 389 } // namespace cricket |
OLD | NEW |