Chromium Code Reviews| 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/capturerenderadapter.h" | 11 #include "webrtc/media/base/capturerenderadapter.h" |
| 12 | 12 |
| 13 #include "webrtc/base/logging.h" | 13 #include "webrtc/base/logging.h" |
| 14 #include "webrtc/media/base/videocapturer.h" | 14 #include "webrtc/media/base/videocapturer.h" |
| 15 #include "webrtc/media/base/videorenderer.h" | 15 #include "webrtc/media/base/videorenderer.h" |
| 16 | 16 |
| 17 namespace cricket { | 17 namespace cricket { |
| 18 | 18 |
| 19 CaptureRenderAdapter::CaptureRenderAdapter(VideoCapturer* video_capturer) | 19 CaptureRenderAdapter::CaptureRenderAdapter(VideoCapturer* video_capturer) |
| 20 : video_capturer_(video_capturer) { | 20 : video_capturer_(video_capturer) { |
| 21 } | 21 } |
| 22 | 22 |
| 23 CaptureRenderAdapter::~CaptureRenderAdapter() { | 23 CaptureRenderAdapter::~CaptureRenderAdapter() { |
|
pthatcher1
2016/02/09 17:13:41
Deleted! Woohoo!
| |
| 24 // Since the signal we're connecting to is multi-threaded, | 24 video_capturer_->RemoveSink(this); |
| 25 // disconnect_all() will block until all calls are serviced, meaning any | |
| 26 // outstanding calls to OnVideoFrame will be done when this is done, and no | |
| 27 // more calls will be serviced by this. | |
| 28 // We do this explicitly instead of just letting the has_slots<> destructor | |
| 29 // take care of it because we need to do this *before* sinks_ is | |
| 30 // cleared by the destructor; otherwise we could mess with it while | |
| 31 // OnVideoFrame is running. | |
| 32 // We *don't* take capture_crit_ here since it could deadlock with the lock | |
| 33 // taken by the video frame signal. | |
| 34 disconnect_all(); | |
| 35 } | 25 } |
| 36 | 26 |
| 37 CaptureRenderAdapter* CaptureRenderAdapter::Create( | 27 CaptureRenderAdapter* CaptureRenderAdapter::Create( |
| 38 VideoCapturer* video_capturer) { | 28 VideoCapturer* video_capturer) { |
| 39 if (!video_capturer) { | 29 if (!video_capturer) { |
| 40 return NULL; | 30 return NULL; |
| 41 } | 31 } |
| 42 CaptureRenderAdapter* return_value = new CaptureRenderAdapter(video_capturer); | 32 CaptureRenderAdapter* return_value = new CaptureRenderAdapter(video_capturer); |
| 43 return_value->Init(); // Can't fail. | 33 return_value->Init(); // Can't fail. |
| 44 return return_value; | 34 return return_value; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 57 | 47 |
| 58 void CaptureRenderAdapter::RemoveSink( | 48 void CaptureRenderAdapter::RemoveSink( |
| 59 rtc::VideoSinkInterface<VideoFrame>* sink) { | 49 rtc::VideoSinkInterface<VideoFrame>* sink) { |
| 60 RTC_DCHECK(sink); | 50 RTC_DCHECK(sink); |
| 61 | 51 |
| 62 rtc::CritScope cs(&capture_crit_); | 52 rtc::CritScope cs(&capture_crit_); |
| 63 sinks_.erase(std::remove(sinks_.begin(), sinks_.end(), sink), sinks_.end()); | 53 sinks_.erase(std::remove(sinks_.begin(), sinks_.end(), sink), sinks_.end()); |
| 64 } | 54 } |
| 65 | 55 |
| 66 void CaptureRenderAdapter::Init() { | 56 void CaptureRenderAdapter::Init() { |
| 67 video_capturer_->SignalVideoFrame.connect( | 57 video_capturer_->AddSink(this); |
| 68 this, | |
| 69 &CaptureRenderAdapter::OnVideoFrame); | |
| 70 } | 58 } |
| 71 | 59 |
| 72 void CaptureRenderAdapter::OnVideoFrame(VideoCapturer* capturer, | 60 void CaptureRenderAdapter::OnFrame(const VideoFrame& frame) { |
| 73 const VideoFrame* video_frame) { | |
| 74 rtc::CritScope cs(&capture_crit_); | 61 rtc::CritScope cs(&capture_crit_); |
| 75 if (sinks_.empty()) { | 62 if (sinks_.empty()) { |
| 76 return; | 63 return; |
| 77 } | 64 } |
| 78 | 65 |
| 79 for (auto* sink : sinks_) | 66 for (auto* sink : sinks_) |
| 80 sink->OnFrame(*video_frame); | 67 sink->OnFrame(frame); |
| 81 } | 68 } |
| 82 | 69 |
| 83 } // namespace cricket | 70 } // namespace cricket |
| OLD | NEW |