| 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 25 matching lines...) Expand all Loading... |
| 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 // Since the signal we're connecting to is multi-threaded, |
| 42 // disconnect_all() will block until all calls are serviced, meaning any | 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 | 43 // outstanding calls to OnVideoFrame will be done when this is done, and no |
| 44 // more calls will be serviced by this. | 44 // more calls will be serviced by this. |
| 45 // We do this explicitly instead of just letting the has_slots<> destructor | 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* video_renderers_ is | 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 | 47 // cleared by the destructor; otherwise we could mess with it while |
| 48 // OnVideoFrame is running. | 48 // OnVideoFrame is running. |
| 49 // We *don't* take capture_crit_ here since it could deadlock with the lock | 49 // We *don't* take capture_crit_ here since it could deadlock with the lock |
| 50 // taken by the video frame signal. | 50 // taken by the video frame signal. |
| 51 disconnect_all(); | 51 disconnect_all(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 CaptureRenderAdapter* CaptureRenderAdapter::Create( | 54 CaptureRenderAdapter* CaptureRenderAdapter::Create( |
| 55 VideoCapturer* video_capturer) { | 55 VideoCapturer* video_capturer) { |
| 56 if (!video_capturer) { | 56 if (!video_capturer) { |
| 57 return NULL; | 57 return NULL; |
| 58 } | 58 } |
| 59 CaptureRenderAdapter* return_value = new CaptureRenderAdapter(video_capturer); | 59 CaptureRenderAdapter* return_value = new CaptureRenderAdapter(video_capturer); |
| 60 return_value->Init(); // Can't fail. | 60 return_value->Init(); // Can't fail. |
| 61 return return_value; | 61 return return_value; |
| 62 } | 62 } |
| 63 | 63 |
| 64 void CaptureRenderAdapter::AddRenderer(VideoRenderer* video_renderer) { | 64 void CaptureRenderAdapter::AddSink(rtc::VideoSinkInterface<VideoFrame>* sink) { |
| 65 RTC_DCHECK(video_renderer); | 65 RTC_DCHECK(sink); |
| 66 | 66 |
| 67 rtc::CritScope cs(&capture_crit_); | 67 rtc::CritScope cs(&capture_crit_); |
| 68 // This implements set semantics, the same renderer can only be | 68 // This implements set semantics, the same renderer can only be |
| 69 // added once. | 69 // added once. |
| 70 // TODO(nisse): Is this really needed? | 70 // TODO(nisse): Is this really needed? |
| 71 if (std::find(video_renderers_.begin(), video_renderers_.end(), | 71 if (std::find(sinks_.begin(), sinks_.end(), sink) == sinks_.end()) |
| 72 video_renderer) == video_renderers_.end()) | 72 sinks_.push_back(sink); |
| 73 video_renderers_.push_back(video_renderer); | |
| 74 } | 73 } |
| 75 | 74 |
| 76 void CaptureRenderAdapter::RemoveRenderer(VideoRenderer* video_renderer) { | 75 void CaptureRenderAdapter::RemoveSink( |
| 77 RTC_DCHECK(video_renderer); | 76 rtc::VideoSinkInterface<VideoFrame>* sink) { |
| 77 RTC_DCHECK(sink); |
| 78 | 78 |
| 79 rtc::CritScope cs(&capture_crit_); | 79 rtc::CritScope cs(&capture_crit_); |
| 80 // TODO(nisse): Switch to using std::list, and use its remove | 80 sinks_.erase(std::remove(sinks_.begin(), sinks_.end(), sink), sinks_.end()); |
| 81 // method. And similarly in VideoTrackRenderers, which this class | |
| 82 // mostly duplicates. | |
| 83 for (VideoRenderers::iterator iter = video_renderers_.begin(); | |
| 84 iter != video_renderers_.end(); ++iter) { | |
| 85 if (video_renderer == *iter) { | |
| 86 video_renderers_.erase(iter); | |
| 87 break; | |
| 88 } | |
| 89 } | |
| 90 } | 81 } |
| 91 | 82 |
| 92 void CaptureRenderAdapter::Init() { | 83 void CaptureRenderAdapter::Init() { |
| 93 video_capturer_->SignalVideoFrame.connect( | 84 video_capturer_->SignalVideoFrame.connect( |
| 94 this, | 85 this, |
| 95 &CaptureRenderAdapter::OnVideoFrame); | 86 &CaptureRenderAdapter::OnVideoFrame); |
| 96 } | 87 } |
| 97 | 88 |
| 98 void CaptureRenderAdapter::OnVideoFrame(VideoCapturer* capturer, | 89 void CaptureRenderAdapter::OnVideoFrame(VideoCapturer* capturer, |
| 99 const VideoFrame* video_frame) { | 90 const VideoFrame* video_frame) { |
| 100 rtc::CritScope cs(&capture_crit_); | 91 rtc::CritScope cs(&capture_crit_); |
| 101 if (video_renderers_.empty()) { | 92 if (sinks_.empty()) { |
| 102 return; | 93 return; |
| 103 } | 94 } |
| 104 | 95 |
| 105 for (auto* renderer : video_renderers_) | 96 for (auto* sink : sinks_) |
| 106 renderer->RenderFrame(video_frame); | 97 sink->OnFrame(*video_frame); |
| 107 } | 98 } |
| 108 | 99 |
| 109 } // namespace cricket | 100 } // namespace cricket |
| OLD | NEW |