Home | History | Annotate | Download | only in media
      1 // Copyright 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "content/renderer/media/media_stream_video_track.h"
      6 
      7 #include "content/renderer/media/webrtc/webrtc_video_sink_adapter.h"
      8 
      9 namespace content {
     10 
     11 // Wrapper which allows to use std::find_if() when adding and removing
     12 // sinks to/from |sinks_|.
     13 struct SinkWrapper {
     14   explicit SinkWrapper(MediaStreamVideoSink* sink) : sink_(sink) {}
     15   bool operator()(
     16       const WebRtcVideoSinkAdapter* owner) {
     17     return owner->sink() == sink_;
     18   }
     19   MediaStreamVideoSink* sink_;
     20 };
     21 
     22 MediaStreamVideoTrack::MediaStreamVideoTrack(webrtc::VideoTrackInterface* track,
     23                                              bool is_local_track)
     24     : MediaStreamTrackExtraData(track, is_local_track),
     25       video_track_(track) {
     26 }
     27 
     28 MediaStreamVideoTrack::~MediaStreamVideoTrack() {
     29   DCHECK(sinks_.empty());
     30 }
     31 
     32 void MediaStreamVideoTrack::AddSink(MediaStreamVideoSink* sink) {
     33   DCHECK(thread_checker_.CalledOnValidThread());
     34   DCHECK(std::find_if(sinks_.begin(), sinks_.end(),
     35                       SinkWrapper(sink)) == sinks_.end());
     36   sinks_.push_back(new WebRtcVideoSinkAdapter(video_track_, sink));
     37 }
     38 
     39 void MediaStreamVideoTrack::RemoveSink(MediaStreamVideoSink* sink) {
     40   DCHECK(thread_checker_.CalledOnValidThread());
     41   ScopedVector<WebRtcVideoSinkAdapter>::iterator it =
     42       std::find_if(sinks_.begin(), sinks_.end(), SinkWrapper(sink));
     43   DCHECK(it != sinks_.end());
     44   sinks_.erase(it);
     45 }
     46 
     47 }  // namespace content
     48