| 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 "base/threading/thread_checker.h" | 11 #include "base/threading/thread_checker.h" |
| 12 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
| 13 #include "content/renderer/media/native_handle_impl.h" | 13 #include "content/renderer/media/native_handle_impl.h" |
| 14 #include "content/renderer/media/webrtc/track_observer.h" | 14 #include "content/renderer/media/webrtc/track_observer.h" |
| 15 #include "media/base/bind_to_current_loop.h" | 15 #include "media/base/bind_to_current_loop.h" |
| 16 #include "media/base/video_frame.h" | 16 #include "media/base/video_frame.h" |
| 17 #include "media/base/video_frame_pool.h" | |
| 18 #include "media/base/video_util.h" | 17 #include "media/base/video_util.h" |
| 19 #include "third_party/libjingle/source/talk/media/base/videoframe.h" | 18 #include "third_party/libjingle/source/talk/media/base/videoframe.h" |
| 20 | 19 |
| 21 namespace content { | 20 namespace content { |
| 22 | 21 |
| 23 // 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 |
| 24 // libjingle thread and forward it to the IO-thread. | 23 // libjingle thread and forward it to the IO-thread. |
| 25 class MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate | 24 class MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate |
| 26 : public base::RefCountedThreadSafe<RemoteVideoSourceDelegate>, | 25 : public base::RefCountedThreadSafe<RemoteVideoSourceDelegate>, |
| 27 public webrtc::VideoRendererInterface { | 26 public webrtc::VideoRendererInterface { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 41 void RenderFrame(const cricket::VideoFrame* frame) override; | 40 void RenderFrame(const cricket::VideoFrame* frame) override; |
| 42 | 41 |
| 43 void DoRenderFrameOnIOThread( | 42 void DoRenderFrameOnIOThread( |
| 44 const scoped_refptr<media::VideoFrame>& video_frame); | 43 const scoped_refptr<media::VideoFrame>& video_frame); |
| 45 | 44 |
| 46 private: | 45 private: |
| 47 // Bound to the render thread. | 46 // Bound to the render thread. |
| 48 base::ThreadChecker thread_checker_; | 47 base::ThreadChecker thread_checker_; |
| 49 | 48 |
| 50 scoped_refptr<base::MessageLoopProxy> io_message_loop_; | 49 scoped_refptr<base::MessageLoopProxy> io_message_loop_; |
| 51 // |frame_pool_| is only accessed on whatever | |
| 52 // thread webrtc::VideoRendererInterface::RenderFrame is called on. | |
| 53 media::VideoFramePool frame_pool_; | |
| 54 | 50 |
| 55 // |frame_callback_| is accessed on the IO thread. | 51 // |frame_callback_| is accessed on the IO thread. |
| 56 VideoCaptureDeliverFrameCB frame_callback_; | 52 VideoCaptureDeliverFrameCB frame_callback_; |
| 57 }; | 53 }; |
| 58 | 54 |
| 59 MediaStreamRemoteVideoSource:: | 55 MediaStreamRemoteVideoSource:: |
| 60 RemoteVideoSourceDelegate::RemoteVideoSourceDelegate( | 56 RemoteVideoSourceDelegate::RemoteVideoSourceDelegate( |
| 61 const scoped_refptr<base::MessageLoopProxy>& io_message_loop, | 57 const scoped_refptr<base::MessageLoopProxy>& io_message_loop, |
| 62 const VideoCaptureDeliverFrameCB& new_frame_callback) | 58 const VideoCaptureDeliverFrameCB& new_frame_callback) |
| 63 : io_message_loop_(io_message_loop), | 59 : io_message_loop_(io_message_loop), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 80 frame->GetElapsedTime() / rtc::kNumNanosecsPerMicrosec); | 76 frame->GetElapsedTime() / rtc::kNumNanosecsPerMicrosec); |
| 81 | 77 |
| 82 scoped_refptr<media::VideoFrame> video_frame; | 78 scoped_refptr<media::VideoFrame> video_frame; |
| 83 if (frame->GetNativeHandle() != NULL) { | 79 if (frame->GetNativeHandle() != NULL) { |
| 84 NativeHandleImpl* handle = | 80 NativeHandleImpl* handle = |
| 85 static_cast<NativeHandleImpl*>(frame->GetNativeHandle()); | 81 static_cast<NativeHandleImpl*>(frame->GetNativeHandle()); |
| 86 video_frame = static_cast<media::VideoFrame*>(handle->GetHandle()); | 82 video_frame = static_cast<media::VideoFrame*>(handle->GetHandle()); |
| 87 video_frame->set_timestamp(timestamp); | 83 video_frame->set_timestamp(timestamp); |
| 88 } else { | 84 } else { |
| 89 gfx::Size size(frame->GetWidth(), frame->GetHeight()); | 85 gfx::Size size(frame->GetWidth(), frame->GetHeight()); |
| 90 video_frame = frame_pool_.CreateFrame( | |
| 91 media::VideoFrame::YV12, size, gfx::Rect(size), size, timestamp); | |
| 92 | 86 |
| 93 // Non-square pixels are unsupported. | 87 // Non-square pixels are unsupported. |
| 94 DCHECK_EQ(frame->GetPixelWidth(), 1u); | 88 DCHECK_EQ(frame->GetPixelWidth(), 1u); |
| 95 DCHECK_EQ(frame->GetPixelHeight(), 1u); | 89 DCHECK_EQ(frame->GetPixelHeight(), 1u); |
| 96 | 90 |
| 97 int y_rows = frame->GetHeight(); | 91 // Make a shallow copy. Both |frame| and |video_frame| will share a single |
| 98 int uv_rows = frame->GetChromaHeight(); | 92 // reference counted frame buffer. Const cast and hope no one will overwrite |
| 99 CopyYPlane( | 93 // the data. |
| 100 frame->GetYPlane(), frame->GetYPitch(), y_rows, video_frame.get()); | 94 // TODO(magjed): Update media::VideoFrame to support const data so we don't |
| 101 CopyUPlane( | 95 // need to const cast here. |
| 102 frame->GetUPlane(), frame->GetUPitch(), uv_rows, video_frame.get()); | 96 video_frame = media::VideoFrame::WrapExternalYuvData( |
| 103 CopyVPlane( | 97 media::VideoFrame::YV12, size, gfx::Rect(size), size, |
| 104 frame->GetVPlane(), frame->GetVPitch(), uv_rows, video_frame.get()); | 98 frame->GetYPitch(), frame->GetUPitch(), frame->GetVPitch(), |
| 99 const_cast<uint8_t*>(frame->GetYPlane()), |
| 100 const_cast<uint8_t*>(frame->GetUPlane()), |
| 101 const_cast<uint8_t*>(frame->GetVPlane()), timestamp, |
| 102 base::Bind(&base::DeletePointer<cricket::VideoFrame>, frame->Copy())); |
| 105 } | 103 } |
| 106 | 104 |
| 107 io_message_loop_->PostTask( | 105 io_message_loop_->PostTask( |
| 108 FROM_HERE, | 106 FROM_HERE, |
| 109 base::Bind(&RemoteVideoSourceDelegate::DoRenderFrameOnIOThread, | 107 base::Bind(&RemoteVideoSourceDelegate::DoRenderFrameOnIOThread, |
| 110 this, video_frame)); | 108 this, video_frame)); |
| 111 } | 109 } |
| 112 | 110 |
| 113 void MediaStreamRemoteVideoSource:: | 111 void MediaStreamRemoteVideoSource:: |
| 114 RemoteVideoSourceDelegate::DoRenderFrameOnIOThread( | 112 RemoteVideoSourceDelegate::DoRenderFrameOnIOThread( |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 case webrtc::MediaStreamTrackInterface::kEnded: | 181 case webrtc::MediaStreamTrackInterface::kEnded: |
| 184 SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded); | 182 SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded); |
| 185 break; | 183 break; |
| 186 default: | 184 default: |
| 187 NOTREACHED(); | 185 NOTREACHED(); |
| 188 break; | 186 break; |
| 189 } | 187 } |
| 190 } | 188 } |
| 191 | 189 |
| 192 } // namespace content | 190 } // namespace content |
| OLD | NEW |