| 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   static VideoCapturerState* Create(VideoCapturer* video_capturer); |   26   explicit VideoCapturerState(VideoCapturer* 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   } |  | 
|   39   VideoCapturer* GetVideoCapturer() { |   35   VideoCapturer* GetVideoCapturer() { | 
|   40     RTC_DCHECK(thread_checker_.CalledOnValidThread()); |   36     RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 
|   41     return adapter()->video_capturer(); |   37     return video_capturer_; | 
|   42   } |   38   } | 
|   43  |   39  | 
|   44   int start_count() const { |   40   int start_count() const { | 
|   45     RTC_DCHECK(thread_checker_.CalledOnValidThread()); |   41     RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 
|   46     return start_count_; |   42     return start_count_; | 
|   47   } |   43   } | 
|   48  |   44  | 
|   49  private: |   45  private: | 
|   50   struct CaptureResolutionInfo { |   46   struct CaptureResolutionInfo { | 
|   51     VideoFormat video_format; |   47     VideoFormat video_format; | 
|   52     int format_ref_count; |   48     int format_ref_count; | 
|   53   }; |   49   }; | 
|   54   typedef std::vector<CaptureResolutionInfo> CaptureFormats; |   50   typedef std::vector<CaptureResolutionInfo> CaptureFormats; | 
|   55  |   51  | 
|   56   explicit VideoCapturerState(CaptureRenderAdapter* adapter); |   52   rtc::ThreadChecker thread_checker_; | 
|   57  |   53  | 
|   58   rtc::ThreadChecker thread_checker_; |   54   VideoCapturer* video_capturer_; | 
|   59   rtc::scoped_ptr<CaptureRenderAdapter> adapter_; |  | 
|   60  |  | 
|   61   int start_count_; |   55   int start_count_; | 
|   62   CaptureFormats capture_formats_; |   56   CaptureFormats capture_formats_; | 
|   63 }; |   57 }; | 
|   64  |   58  | 
|   65 const VideoFormatPod VideoCapturerState::kDefaultCaptureFormat = { |   59 const VideoFormatPod VideoCapturerState::kDefaultCaptureFormat = { | 
|   66   640, 360, FPS_TO_INTERVAL(30), FOURCC_ANY |   60   640, 360, FPS_TO_INTERVAL(30), FOURCC_ANY | 
|   67 }; |   61 }; | 
|   68  |   62  | 
|   69 VideoCapturerState::VideoCapturerState(CaptureRenderAdapter* adapter) |   63 VideoCapturerState::VideoCapturerState(VideoCapturer* capturer) | 
|   70     : adapter_(adapter), start_count_(1) {} |   64     : video_capturer_(capturer), 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 } |  | 
|   80  |   65  | 
|   81 void VideoCapturerState::AddCaptureResolution( |   66 void VideoCapturerState::AddCaptureResolution( | 
|   82     const VideoFormat& desired_format) { |   67     const VideoFormat& desired_format) { | 
|   83   RTC_DCHECK(thread_checker_.CalledOnValidThread()); |   68   RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 
|   84   for (CaptureFormats::iterator iter = capture_formats_.begin(); |   69   for (CaptureFormats::iterator iter = capture_formats_.begin(); | 
|   85        iter != capture_formats_.end(); ++iter) { |   70        iter != capture_formats_.end(); ++iter) { | 
|   86     if (desired_format == iter->video_format) { |   71     if (desired_format == iter->video_format) { | 
|   87       ++(iter->format_ref_count); |   72       ++(iter->format_ref_count); | 
|   88       return; |   73       return; | 
|   89     } |   74     } | 
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  269   return true; |  254   return true; | 
|  270 } |  255 } | 
|  271  |  256  | 
|  272 void CaptureManager::AddVideoSink(VideoCapturer* video_capturer, |  257 void CaptureManager::AddVideoSink(VideoCapturer* video_capturer, | 
|  273                                   rtc::VideoSinkInterface<VideoFrame>* sink) { |  258                                   rtc::VideoSinkInterface<VideoFrame>* sink) { | 
|  274   RTC_DCHECK(thread_checker_.CalledOnValidThread()); |  259   RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 
|  275   // TODO(nisse): Do we really need to tolerate NULL inputs? |  260   // TODO(nisse): Do we really need to tolerate NULL inputs? | 
|  276   if (!video_capturer || !sink) { |  261   if (!video_capturer || !sink) { | 
|  277     return; |  262     return; | 
|  278   } |  263   } | 
|  279   CaptureRenderAdapter* adapter = GetAdapter(video_capturer); |  264   rtc::VideoSinkWants wants; | 
|  280   if (!adapter) { |  265   // Renderers must be able to apply rotation. | 
|  281     return; |  266   wants.rotation_applied = false; | 
|  282   } |  267   video_capturer->AddOrUpdateSink(sink, wants); | 
|  283   adapter->AddSink(sink); |  | 
|  284 } |  268 } | 
|  285  |  269  | 
|  286 void CaptureManager::RemoveVideoSink( |  270 void CaptureManager::RemoveVideoSink( | 
|  287     VideoCapturer* video_capturer, |  271     VideoCapturer* video_capturer, | 
|  288     rtc::VideoSinkInterface<VideoFrame>* sink) { |  272     rtc::VideoSinkInterface<VideoFrame>* sink) { | 
|  289   RTC_DCHECK(thread_checker_.CalledOnValidThread()); |  273   RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 
|  290   if (!video_capturer || !sink) { |  274   if (!video_capturer || !sink) { | 
|  291     return; |  275     return; | 
|  292   } |  276   } | 
|  293   CaptureRenderAdapter* adapter = GetAdapter(video_capturer); |  277   video_capturer->RemoveSink(sink); | 
|  294   if (!adapter) { |  | 
|  295     return; |  | 
|  296   } |  | 
|  297   adapter->RemoveSink(sink); |  | 
|  298 } |  278 } | 
|  299  |  279  | 
|  300 bool CaptureManager::IsCapturerRegistered(VideoCapturer* video_capturer) const { |  280 bool CaptureManager::IsCapturerRegistered(VideoCapturer* video_capturer) const { | 
|  301   RTC_DCHECK(thread_checker_.CalledOnValidThread()); |  281   RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 
|  302   return GetCaptureState(video_capturer) != NULL; |  282   return GetCaptureState(video_capturer) != NULL; | 
|  303 } |  283 } | 
|  304  |  284  | 
|  305 bool CaptureManager::RegisterVideoCapturer(VideoCapturer* video_capturer) { |  285 bool CaptureManager::RegisterVideoCapturer(VideoCapturer* video_capturer) { | 
|  306   RTC_DCHECK(thread_checker_.CalledOnValidThread()); |  286   RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 
|  307   VideoCapturerState* capture_state = |  287   VideoCapturerState* capture_state = new VideoCapturerState(video_capturer); | 
|  308       VideoCapturerState::Create(video_capturer); |  | 
|  309   if (!capture_state) { |  | 
|  310     return false; |  | 
|  311   } |  | 
|  312   capture_states_[video_capturer] = capture_state; |  288   capture_states_[video_capturer] = capture_state; | 
|  313   SignalCapturerStateChange.repeat(video_capturer->SignalStateChange); |  289   SignalCapturerStateChange.repeat(video_capturer->SignalStateChange); | 
|  314   return true; |  290   return true; | 
|  315 } |  291 } | 
|  316  |  292  | 
|  317 void CaptureManager::UnregisterVideoCapturer( |  293 void CaptureManager::UnregisterVideoCapturer( | 
|  318     VideoCapturerState* capture_state) { |  294     VideoCapturerState* capture_state) { | 
|  319   RTC_DCHECK(thread_checker_.CalledOnValidThread()); |  295   RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 
|  320   VideoCapturer* video_capturer = capture_state->GetVideoCapturer(); |  296   VideoCapturer* video_capturer = capture_state->GetVideoCapturer(); | 
|  321   capture_states_.erase(video_capturer); |  297   capture_states_.erase(video_capturer); | 
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  369 VideoCapturerState* CaptureManager::GetCaptureState( |  345 VideoCapturerState* CaptureManager::GetCaptureState( | 
|  370     VideoCapturer* video_capturer) const { |  346     VideoCapturer* video_capturer) const { | 
|  371   RTC_DCHECK(thread_checker_.CalledOnValidThread()); |  347   RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 
|  372   CaptureStates::const_iterator iter = capture_states_.find(video_capturer); |  348   CaptureStates::const_iterator iter = capture_states_.find(video_capturer); | 
|  373   if (iter == capture_states_.end()) { |  349   if (iter == capture_states_.end()) { | 
|  374     return NULL; |  350     return NULL; | 
|  375   } |  351   } | 
|  376   return iter->second; |  352   return iter->second; | 
|  377 } |  353 } | 
|  378  |  354  | 
|  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  |  | 
|  389 }  // namespace cricket |  355 }  // namespace cricket | 
| OLD | NEW |