Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 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 20 matching lines...) Expand all Loading... | |
| 31 #include "talk/media/base/videorenderer.h" | 31 #include "talk/media/base/videorenderer.h" |
| 32 #include "webrtc/base/logging.h" | 32 #include "webrtc/base/logging.h" |
| 33 | 33 |
| 34 namespace cricket { | 34 namespace cricket { |
| 35 | 35 |
| 36 CaptureRenderAdapter::CaptureRenderAdapter(VideoCapturer* video_capturer) | 36 CaptureRenderAdapter::CaptureRenderAdapter(VideoCapturer* video_capturer) |
| 37 : video_capturer_(video_capturer) { | 37 : video_capturer_(video_capturer) { |
| 38 } | 38 } |
| 39 | 39 |
| 40 CaptureRenderAdapter::~CaptureRenderAdapter() { | 40 CaptureRenderAdapter::~CaptureRenderAdapter() { |
| 41 // Since the signal we're connecting to is multi-threaded, | 41 video_capturer_->RemoveSink(this); |
| 42 // disconnect_all() will block until all calls are serviced, meaning any | |
| 43 // outstanding calls to OnVideoFrame will be done when this is done, and no | |
| 44 // more calls will be serviced by this. | |
| 45 // We do this explicitly instead of just letting the has_slots<> destructor | |
| 46 // take care of it because we need to do this *before* sinks_ is | |
| 47 // cleared by the destructor; otherwise we could mess with it while | |
| 48 // OnVideoFrame is running. | |
| 49 // We *don't* take capture_crit_ here since it could deadlock with the lock | |
| 50 // taken by the video frame signal. | |
| 51 disconnect_all(); | |
| 52 } | 42 } |
| 53 | 43 |
| 54 CaptureRenderAdapter* CaptureRenderAdapter::Create( | 44 CaptureRenderAdapter* CaptureRenderAdapter::Create( |
| 55 VideoCapturer* video_capturer) { | 45 VideoCapturer* video_capturer) { |
| 56 if (!video_capturer) { | 46 if (!video_capturer) { |
| 57 return NULL; | 47 return NULL; |
| 58 } | 48 } |
| 59 CaptureRenderAdapter* return_value = new CaptureRenderAdapter(video_capturer); | 49 CaptureRenderAdapter* return_value = new CaptureRenderAdapter(video_capturer); |
| 60 return_value->Init(); // Can't fail. | 50 return_value->Init(); // Can't fail. |
| 61 return return_value; | 51 return return_value; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 74 | 64 |
| 75 void CaptureRenderAdapter::RemoveSink( | 65 void CaptureRenderAdapter::RemoveSink( |
| 76 rtc::VideoSinkInterface<VideoFrame>* sink) { | 66 rtc::VideoSinkInterface<VideoFrame>* sink) { |
| 77 RTC_DCHECK(sink); | 67 RTC_DCHECK(sink); |
| 78 | 68 |
| 79 rtc::CritScope cs(&capture_crit_); | 69 rtc::CritScope cs(&capture_crit_); |
| 80 sinks_.erase(std::remove(sinks_.begin(), sinks_.end(), sink), sinks_.end()); | 70 sinks_.erase(std::remove(sinks_.begin(), sinks_.end(), sink), sinks_.end()); |
| 81 } | 71 } |
| 82 | 72 |
| 83 void CaptureRenderAdapter::Init() { | 73 void CaptureRenderAdapter::Init() { |
| 84 video_capturer_->SignalVideoFrame.connect( | 74 rtc::VideoSinkCapabilities capabilities; |
| 85 this, | 75 // All renderers must handle rotation. |
| 86 &CaptureRenderAdapter::OnVideoFrame); | 76 capabilities.can_apply_rotation = true; |
| 77 | |
| 78 video_capturer_->AddSink(this, capabilities); | |
| 87 } | 79 } |
| 88 | 80 |
| 89 void CaptureRenderAdapter::OnVideoFrame(VideoCapturer* capturer, | 81 void CaptureRenderAdapter::OnFrame(const VideoFrame& frame) { |
| 90 const VideoFrame* video_frame) { | |
| 91 rtc::CritScope cs(&capture_crit_); | 82 rtc::CritScope cs(&capture_crit_); |
| 92 if (sinks_.empty()) { | 83 if (sinks_.empty()) { |
|
nisse-webrtc
2016/02/03 09:16:34
This test isn't needed, right?
perkj_webrtc
2016/02/08 14:32:00
Done.
| |
| 93 return; | 84 return; |
| 94 } | 85 } |
| 95 | 86 |
| 96 for (auto* sink : sinks_) | 87 for (auto* sink : sinks_) |
| 97 sink->OnFrame(*video_frame); | 88 sink->OnFrame(frame); |
| 98 } | 89 } |
| 99 | 90 |
| 100 } // namespace cricket | 91 } // namespace cricket |
| OLD | NEW |