| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/webrtc/media_stream_remote_video_source.h" | 5 #include "content/renderer/media/webrtc/media_stream_remote_video_source.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| 11 #include "content/renderer/media/native_handle_impl.h" | 11 #include "content/renderer/media/native_handle_impl.h" |
| 12 #include "media/base/bind_to_current_loop.h" | 12 #include "media/base/bind_to_current_loop.h" |
| 13 #include "media/base/video_frame.h" | 13 #include "media/base/video_frame.h" |
| 14 #include "media/base/video_frame_pool.h" | 14 #include "media/base/video_frame_pool.h" |
| 15 #include "media/base/video_util.h" | 15 #include "media/base/video_util.h" |
| 16 #include "third_party/libjingle/source/talk/media/base/videoframe.h" | 16 #include "third_party/libjingle/source/talk/media/base/videoframe.h" |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 | 19 |
| 20 const char kTypeName[] = "Remote Video"; |
| 21 |
| 20 // Internal class used for receiving frames from the webrtc track on a | 22 // Internal class used for receiving frames from the webrtc track on a |
| 21 // libjingle thread and forward it to the IO-thread. | 23 // libjingle thread and forward it to the IO-thread. |
| 22 class MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate | 24 class MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate |
| 23 : public base::RefCountedThreadSafe<RemoteVideoSourceDelegate>, | 25 : public base::RefCountedThreadSafe<RemoteVideoSourceDelegate>, |
| 24 public webrtc::VideoRendererInterface { | 26 public webrtc::VideoRendererInterface { |
| 25 public: | 27 public: |
| 26 RemoteVideoSourceDelegate( | 28 RemoteVideoSourceDelegate( |
| 27 const scoped_refptr<base::MessageLoopProxy>& io_message_loop, | 29 const scoped_refptr<base::MessageLoopProxy>& io_message_loop, |
| 28 const VideoCaptureDeliverFrameCB& new_frame_callback); | 30 const VideoCaptureDeliverFrameCB& new_frame_callback); |
| 29 | 31 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 remote_track_->AddRenderer(delegate_.get()); | 158 remote_track_->AddRenderer(delegate_.get()); |
| 157 OnStartDone(MEDIA_DEVICE_OK); | 159 OnStartDone(MEDIA_DEVICE_OK); |
| 158 } | 160 } |
| 159 | 161 |
| 160 void MediaStreamRemoteVideoSource::StopSourceImpl() { | 162 void MediaStreamRemoteVideoSource::StopSourceImpl() { |
| 161 DCHECK(thread_checker_.CalledOnValidThread()); | 163 DCHECK(thread_checker_.CalledOnValidThread()); |
| 162 DCHECK(state() != MediaStreamVideoSource::ENDED); | 164 DCHECK(state() != MediaStreamVideoSource::ENDED); |
| 163 remote_track_->RemoveRenderer(delegate_.get()); | 165 remote_track_->RemoveRenderer(delegate_.get()); |
| 164 } | 166 } |
| 165 | 167 |
| 168 std::string MediaStreamRemoteVideoSource::TypeName() const { |
| 169 return kTypeName; |
| 170 } |
| 171 |
| 166 webrtc::VideoRendererInterface* | 172 webrtc::VideoRendererInterface* |
| 167 MediaStreamRemoteVideoSource::RenderInterfaceForTest() { | 173 MediaStreamRemoteVideoSource::RenderInterfaceForTest() { |
| 168 return delegate_.get(); | 174 return delegate_.get(); |
| 169 } | 175 } |
| 170 | 176 |
| 171 void MediaStreamRemoteVideoSource::OnChanged() { | 177 void MediaStreamRemoteVideoSource::OnChanged() { |
| 172 DCHECK(thread_checker_.CalledOnValidThread()); | 178 DCHECK(thread_checker_.CalledOnValidThread()); |
| 173 webrtc::MediaStreamTrackInterface::TrackState state = remote_track_->state(); | 179 webrtc::MediaStreamTrackInterface::TrackState state = remote_track_->state(); |
| 174 if (state != last_state_) { | 180 if (state != last_state_) { |
| 175 last_state_ = state; | 181 last_state_ = state; |
| 176 switch (state) { | 182 switch (state) { |
| 177 case webrtc::MediaStreamTrackInterface::kInitializing: | 183 case webrtc::MediaStreamTrackInterface::kInitializing: |
| 178 // Ignore the kInitializing state since there is no match in | 184 // Ignore the kInitializing state since there is no match in |
| 179 // WebMediaStreamSource::ReadyState. | 185 // WebMediaStreamSource::ReadyState. |
| 180 break; | 186 break; |
| 181 case webrtc::MediaStreamTrackInterface::kLive: | 187 case webrtc::MediaStreamTrackInterface::kLive: |
| 182 SetReadyState(blink::WebMediaStreamSource::ReadyStateLive); | 188 SetReadyState(blink::WebMediaStreamSource::ReadyStateLive); |
| 183 break; | 189 break; |
| 184 case webrtc::MediaStreamTrackInterface::kEnded: | 190 case webrtc::MediaStreamTrackInterface::kEnded: |
| 185 SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded); | 191 SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded); |
| 186 break; | 192 break; |
| 187 default: | 193 default: |
| 188 NOTREACHED(); | 194 NOTREACHED(); |
| 189 break; | 195 break; |
| 190 } | 196 } |
| 191 } | 197 } |
| 192 } | 198 } |
| 193 | 199 |
| 194 } // namespace content | 200 } // namespace content |
| OLD | NEW |