Chromium Code Reviews| Index: webrtc/media/base/videobroadcaster.cc |
| diff --git a/webrtc/media/base/videobroadcaster.cc b/webrtc/media/base/videobroadcaster.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..83a32a01c4eafb990314d09ab4a894c1f0859264 |
| --- /dev/null |
| +++ b/webrtc/media/base/videobroadcaster.cc |
| @@ -0,0 +1,73 @@ |
| +/* |
| + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| + * |
| + * Use of this source code is governed by a BSD-style license |
| + * that can be found in the LICENSE file in the root of the source |
| + * tree. An additional intellectual property rights grant can be found |
| + * in the file PATENTS. All contributing project authors may |
| + * be found in the AUTHORS file in the root of the source tree. |
| + */ |
| + |
| +#include "webrtc/media/base/videobroadcaster.h" |
| + |
| +#include "webrtc/base/checks.h" |
| + |
| +namespace rtc { |
| + |
| +VideoBroadCaster::VideoBroadCaster() { |
| + thread_checker_.DetachFromThread(); |
| +} |
| + |
| +void VideoBroadCaster::AddSink(VideoSinkInterface<cricket::VideoFrame>* sink) { |
| + RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| + RTC_DCHECK(sink != nullptr); |
| + RTC_DCHECK(std::find(sinks_.begin(), sinks_.end(), sink) == sinks_.end()); |
| + sinks_.push_back(sink); |
| +} |
| + |
| +void VideoBroadCaster::AddOrUpdateSink( |
| + VideoSinkInterface<cricket::VideoFrame>* sink, |
| + const VideoSinkHints& hints) { |
| + RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| + RTC_DCHECK(sink != nullptr); |
| + if (std::find(sinks_.begin(), sinks_.end(), sink) == sinks_.end()) { |
| + sinks_.push_back(sink); |
| + } |
| + |
| + // TODO(perkj): Handle different sinks with different hints. |
| + RTC_DCHECK(current_hints_.first == nullptr || current_hints_.first == sink); |
| + |
| + current_hints_.first = sink; |
| + if (hints != current_hints_.second) { |
| + current_hints_.second = hints; |
| + } |
| +} |
| + |
| +void VideoBroadCaster::RemoveSink( |
| + VideoSinkInterface<cricket::VideoFrame>* sink) { |
| + RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| + RTC_DCHECK(sink != nullptr); |
| + RTC_DCHECK(std::find(sinks_.begin(), sinks_.end(), sink) != sinks_.end()); |
| + sinks_.erase(std::remove(sinks_.begin(), sinks_.end(), sink), sinks_.end()); |
| + if (current_hints_.first == sink) |
| + current_hints_.first = nullptr; |
|
pthatcher1
2016/02/08 20:59:39
{}s please
perkj_webrtc
2016/02/09 13:23:57
Acknowledged.
|
| +} |
| + |
| +bool VideoBroadCaster::FrameWillBeDelivered() const { |
| + RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| + return !sinks_.empty(); |
| +} |
| + |
| +VideoSinkHints VideoBroadCaster::DerivedHints() const { |
| + RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| + return current_hints_.second; |
| +} |
| + |
| +void VideoBroadCaster::OnFrame(const cricket::VideoFrame& frame) { |
| + RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| + for (auto* sink : sinks_) { |
| + sink->OnFrame(frame); |
| + } |
| +} |
| + |
| +} // namespace rtc |