Chromium Code Reviews| 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" | 17 #include "media/base/video_frame_pool.h" |
| 18 #include "media/base/video_util.h" | 18 #include "media/base/video_util.h" |
| 19 #include "third_party/libjingle/source/talk/media/base/videoframe.h" | 19 #include "third_party/libjingle/source/talk/media/base/videoframe.h" |
| 20 | 20 |
| 21 namespace { | |
| 22 | |
| 23 // Release |frame| when it goes out of scope. | |
|
tommi (sloooow) - chröme
2015/01/29 14:21:41
nit: s/Release/Delete
(since Release usually refer
magjed_chromium
2015/01/30 12:27:44
Done.
| |
| 24 void FreeCricketFrame(scoped_ptr<cricket::VideoFrame> frame) { | |
| 25 } | |
| 26 | |
| 27 } // namespace | |
| 28 | |
| 21 namespace content { | 29 namespace content { |
| 22 | 30 |
| 23 // Internal class used for receiving frames from the webrtc track on a | 31 // Internal class used for receiving frames from the webrtc track on a |
| 24 // libjingle thread and forward it to the IO-thread. | 32 // libjingle thread and forward it to the IO-thread. |
| 25 class MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate | 33 class MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate |
| 26 : public base::RefCountedThreadSafe<RemoteVideoSourceDelegate>, | 34 : public base::RefCountedThreadSafe<RemoteVideoSourceDelegate>, |
| 27 public webrtc::VideoRendererInterface { | 35 public webrtc::VideoRendererInterface { |
| 28 public: | 36 public: |
| 29 RemoteVideoSourceDelegate( | 37 RemoteVideoSourceDelegate( |
| 30 const scoped_refptr<base::MessageLoopProxy>& io_message_loop, | 38 const scoped_refptr<base::MessageLoopProxy>& io_message_loop, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 frame->GetElapsedTime() / rtc::kNumNanosecsPerMicrosec); | 87 frame->GetElapsedTime() / rtc::kNumNanosecsPerMicrosec); |
| 80 | 88 |
| 81 scoped_refptr<media::VideoFrame> video_frame; | 89 scoped_refptr<media::VideoFrame> video_frame; |
| 82 if (frame->GetNativeHandle() != NULL) { | 90 if (frame->GetNativeHandle() != NULL) { |
| 83 NativeHandleImpl* handle = | 91 NativeHandleImpl* handle = |
| 84 static_cast<NativeHandleImpl*>(frame->GetNativeHandle()); | 92 static_cast<NativeHandleImpl*>(frame->GetNativeHandle()); |
| 85 video_frame = static_cast<media::VideoFrame*>(handle->GetHandle()); | 93 video_frame = static_cast<media::VideoFrame*>(handle->GetHandle()); |
| 86 video_frame->set_timestamp(timestamp); | 94 video_frame->set_timestamp(timestamp); |
| 87 } else { | 95 } else { |
| 88 gfx::Size size(frame->GetWidth(), frame->GetHeight()); | 96 gfx::Size size(frame->GetWidth(), frame->GetHeight()); |
| 89 video_frame = frame_pool_.CreateFrame( | |
|
perkj_chrome
2015/01/30 08:57:40
frame_pool_ is not needed now. Please remove it an
magjed_chromium
2015/01/30 12:27:44
Done.
| |
| 90 media::VideoFrame::YV12, size, gfx::Rect(size), size, timestamp); | |
| 91 | 97 |
| 92 // Non-square pixels are unsupported. | 98 // Non-square pixels are unsupported. |
| 93 DCHECK_EQ(frame->GetPixelWidth(), 1u); | 99 DCHECK_EQ(frame->GetPixelWidth(), 1u); |
| 94 DCHECK_EQ(frame->GetPixelHeight(), 1u); | 100 DCHECK_EQ(frame->GetPixelHeight(), 1u); |
| 95 | 101 |
| 96 int y_rows = frame->GetHeight(); | 102 // Take a shallow copy. Both |frame| and |copied_frame| will share a single |
|
perkj_chrome
2015/01/30 08:57:40
nit Make a shallow copy...
magjed_chromium
2015/01/30 12:27:44
Done.
| |
| 97 int uv_rows = frame->GetChromaHeight(); | 103 // reference counted frame buffer. |
| 98 CopyYPlane( | 104 scoped_ptr<cricket::VideoFrame> copied_frame(frame->Copy()); |
| 99 frame->GetYPlane(), frame->GetYPitch(), y_rows, video_frame.get()); | 105 video_frame = |
| 100 CopyUPlane( | 106 media::VideoFrame::WrapExternalYuvData( |
| 101 frame->GetUPlane(), frame->GetUPitch(), uv_rows, video_frame.get()); | 107 media::VideoFrame::YV12, |
| 102 CopyVPlane( | 108 size, |
| 103 frame->GetVPlane(), frame->GetVPitch(), uv_rows, video_frame.get()); | 109 gfx::Rect(size), |
| 110 size, | |
| 111 copied_frame->GetYPitch(), | |
| 112 copied_frame->GetUPitch(), | |
| 113 copied_frame->GetVPitch(), | |
| 114 copied_frame->GetYPlane(), | |
| 115 copied_frame->GetUPlane(), | |
| 116 copied_frame->GetVPlane(), | |
| 117 timestamp, | |
| 118 base::Bind(&FreeCricketFrame, Passed(&copied_frame))); | |
| 104 } | 119 } |
| 105 | 120 |
| 106 media::VideoPixelFormat pixel_format = | 121 media::VideoPixelFormat pixel_format = |
| 107 (video_frame->format() == media::VideoFrame::YV12) ? | 122 (video_frame->format() == media::VideoFrame::YV12) ? |
| 108 media::PIXEL_FORMAT_YV12 : media::PIXEL_FORMAT_TEXTURE; | 123 media::PIXEL_FORMAT_YV12 : media::PIXEL_FORMAT_TEXTURE; |
| 109 | 124 |
| 110 media::VideoCaptureFormat format( | 125 media::VideoCaptureFormat format( |
| 111 gfx::Size(video_frame->natural_size().width(), | 126 gfx::Size(video_frame->natural_size().width(), |
| 112 video_frame->natural_size().height()), | 127 video_frame->natural_size().height()), |
| 113 MediaStreamVideoSource::kUnknownFrameRate, | 128 MediaStreamVideoSource::kUnknownFrameRate, |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 case webrtc::MediaStreamTrackInterface::kEnded: | 208 case webrtc::MediaStreamTrackInterface::kEnded: |
| 194 SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded); | 209 SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded); |
| 195 break; | 210 break; |
| 196 default: | 211 default: |
| 197 NOTREACHED(); | 212 NOTREACHED(); |
| 198 break; | 213 break; |
| 199 } | 214 } |
| 200 } | 215 } |
| 201 | 216 |
| 202 } // namespace content | 217 } // namespace content |
| OLD | NEW |