OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/media/media_stream_video_track.h" | 5 #include "content/renderer/media/media_stream_video_track.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" | 10 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 | 38 |
39 // Removes |callback| associated with |id| from receiving video frames if |id| | 39 // Removes |callback| associated with |id| from receiving video frames if |id| |
40 // has been added. It is ok to call RemoveCallback even if the |id| has not | 40 // has been added. It is ok to call RemoveCallback even if the |id| has not |
41 // been added. Note that the added callback will be reset on the main thread. | 41 // been added. Note that the added callback will be reset on the main thread. |
42 // Must be called on the main render thread. | 42 // Must be called on the main render thread. |
43 void RemoveCallback(void* id); | 43 void RemoveCallback(void* id); |
44 | 44 |
45 // Triggers all registered callbacks with |frame|, |format| and | 45 // Triggers all registered callbacks with |frame|, |format| and |
46 // |estimated_capture_time| as parameters. Must be called on the IO-thread. | 46 // |estimated_capture_time| as parameters. Must be called on the IO-thread. |
47 void DeliverFrameOnIO(const scoped_refptr<media::VideoFrame>& frame, | 47 void DeliverFrameOnIO(const scoped_refptr<media::VideoFrame>& frame, |
48 const media::VideoCaptureFormat& format, | |
49 const base::TimeTicks& estimated_capture_time); | 48 const base::TimeTicks& estimated_capture_time); |
50 | 49 |
51 private: | 50 private: |
52 friend class base::RefCountedThreadSafe<FrameDeliverer>; | 51 friend class base::RefCountedThreadSafe<FrameDeliverer>; |
53 virtual ~FrameDeliverer(); | 52 virtual ~FrameDeliverer(); |
54 void AddCallbackOnIO(void* id, const VideoCaptureDeliverFrameCB& callback); | 53 void AddCallbackOnIO(void* id, const VideoCaptureDeliverFrameCB& callback); |
55 void RemoveCallbackOnIO( | 54 void RemoveCallbackOnIO( |
56 void* id, const scoped_refptr<base::MessageLoopProxy>& message_loop); | 55 void* id, const scoped_refptr<base::MessageLoopProxy>& message_loop); |
57 | 56 |
58 void SetEnabledOnIO(bool enabled); | 57 void SetEnabledOnIO(bool enabled); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 | 137 |
139 void MediaStreamVideoTrack::FrameDeliverer::SetEnabledOnIO(bool enabled) { | 138 void MediaStreamVideoTrack::FrameDeliverer::SetEnabledOnIO(bool enabled) { |
140 DCHECK(io_message_loop_->BelongsToCurrentThread()); | 139 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
141 enabled_ = enabled; | 140 enabled_ = enabled; |
142 if (enabled_) | 141 if (enabled_) |
143 black_frame_ = NULL; | 142 black_frame_ = NULL; |
144 } | 143 } |
145 | 144 |
146 void MediaStreamVideoTrack::FrameDeliverer::DeliverFrameOnIO( | 145 void MediaStreamVideoTrack::FrameDeliverer::DeliverFrameOnIO( |
147 const scoped_refptr<media::VideoFrame>& frame, | 146 const scoped_refptr<media::VideoFrame>& frame, |
148 const media::VideoCaptureFormat& format, | |
149 const base::TimeTicks& estimated_capture_time) { | 147 const base::TimeTicks& estimated_capture_time) { |
150 DCHECK(io_message_loop_->BelongsToCurrentThread()); | 148 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
151 const scoped_refptr<media::VideoFrame>& video_frame = | 149 const scoped_refptr<media::VideoFrame>& video_frame = |
152 enabled_ ? frame : GetBlackFrame(frame); | 150 enabled_ ? frame : GetBlackFrame(frame); |
153 | 151 for (const auto& entry : callbacks_) |
154 for (std::vector<VideoIdCallbackPair>::iterator it = callbacks_.begin(); | 152 entry.second.Run(video_frame, estimated_capture_time); |
155 it != callbacks_.end(); ++it) { | |
156 it->second.Run(video_frame, format, estimated_capture_time); | |
157 } | |
158 } | 153 } |
159 | 154 |
160 const scoped_refptr<media::VideoFrame>& | 155 const scoped_refptr<media::VideoFrame>& |
161 MediaStreamVideoTrack::FrameDeliverer::GetBlackFrame( | 156 MediaStreamVideoTrack::FrameDeliverer::GetBlackFrame( |
162 const scoped_refptr<media::VideoFrame>& reference_frame) { | 157 const scoped_refptr<media::VideoFrame>& reference_frame) { |
163 DCHECK(io_message_loop_->BelongsToCurrentThread()); | 158 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
164 if (!black_frame_.get() || | 159 if (!black_frame_.get() || |
165 black_frame_->natural_size() != reference_frame->natural_size()) | 160 black_frame_->natural_size() != reference_frame->natural_size()) |
166 black_frame_ = | 161 black_frame_ = |
167 media::VideoFrame::CreateBlackFrame(reference_frame->natural_size()); | 162 media::VideoFrame::CreateBlackFrame(reference_frame->natural_size()); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 void MediaStreamVideoTrack::OnReadyStateChanged( | 250 void MediaStreamVideoTrack::OnReadyStateChanged( |
256 blink::WebMediaStreamSource::ReadyState state) { | 251 blink::WebMediaStreamSource::ReadyState state) { |
257 DCHECK(thread_checker_.CalledOnValidThread()); | 252 DCHECK(thread_checker_.CalledOnValidThread()); |
258 for (std::vector<MediaStreamVideoSink*>::const_iterator it = sinks_.begin(); | 253 for (std::vector<MediaStreamVideoSink*>::const_iterator it = sinks_.begin(); |
259 it != sinks_.end(); ++it) { | 254 it != sinks_.end(); ++it) { |
260 (*it)->OnReadyStateChanged(state); | 255 (*it)->OnReadyStateChanged(state); |
261 } | 256 } |
262 } | 257 } |
263 | 258 |
264 } // namespace content | 259 } // namespace content |
OLD | NEW |