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" |
(...skipping 18 matching lines...) Expand all Loading... |
29 const scoped_refptr<base::MessageLoopProxy>& io_message_loop, | 29 const scoped_refptr<base::MessageLoopProxy>& io_message_loop, |
30 const VideoCaptureDeliverFrameCB& new_frame_callback); | 30 const VideoCaptureDeliverFrameCB& new_frame_callback); |
31 | 31 |
32 protected: | 32 protected: |
33 friend class base::RefCountedThreadSafe<RemoteVideoSourceDelegate>; | 33 friend class base::RefCountedThreadSafe<RemoteVideoSourceDelegate>; |
34 ~RemoteVideoSourceDelegate() override; | 34 ~RemoteVideoSourceDelegate() override; |
35 | 35 |
36 // Implements webrtc::VideoRendererInterface used for receiving video frames | 36 // Implements webrtc::VideoRendererInterface used for receiving video frames |
37 // from the PeerConnection video track. May be called on a libjingle internal | 37 // from the PeerConnection video track. May be called on a libjingle internal |
38 // thread. | 38 // thread. |
39 void SetSize(int width, int height) override; | |
40 void RenderFrame(const cricket::VideoFrame* frame) override; | 39 void RenderFrame(const cricket::VideoFrame* frame) override; |
41 | 40 |
42 void DoRenderFrameOnIOThread( | 41 void DoRenderFrameOnIOThread( |
43 const scoped_refptr<media::VideoFrame>& video_frame); | 42 const scoped_refptr<media::VideoFrame>& video_frame); |
44 | 43 |
45 private: | 44 private: |
46 // Bound to the render thread. | 45 // Bound to the render thread. |
47 base::ThreadChecker thread_checker_; | 46 base::ThreadChecker thread_checker_; |
48 | 47 |
49 scoped_refptr<base::MessageLoopProxy> io_message_loop_; | 48 scoped_refptr<base::MessageLoopProxy> io_message_loop_; |
50 | 49 |
51 // |frame_callback_| is accessed on the IO thread. | 50 // |frame_callback_| is accessed on the IO thread. |
52 VideoCaptureDeliverFrameCB frame_callback_; | 51 VideoCaptureDeliverFrameCB frame_callback_; |
53 }; | 52 }; |
54 | 53 |
55 MediaStreamRemoteVideoSource:: | 54 MediaStreamRemoteVideoSource:: |
56 RemoteVideoSourceDelegate::RemoteVideoSourceDelegate( | 55 RemoteVideoSourceDelegate::RemoteVideoSourceDelegate( |
57 const scoped_refptr<base::MessageLoopProxy>& io_message_loop, | 56 const scoped_refptr<base::MessageLoopProxy>& io_message_loop, |
58 const VideoCaptureDeliverFrameCB& new_frame_callback) | 57 const VideoCaptureDeliverFrameCB& new_frame_callback) |
59 : io_message_loop_(io_message_loop), | 58 : io_message_loop_(io_message_loop), |
60 frame_callback_(new_frame_callback) { | 59 frame_callback_(new_frame_callback) { |
61 } | 60 } |
62 | 61 |
63 MediaStreamRemoteVideoSource:: | 62 MediaStreamRemoteVideoSource:: |
64 RemoteVideoSourceDelegate::~RemoteVideoSourceDelegate() { | 63 RemoteVideoSourceDelegate::~RemoteVideoSourceDelegate() { |
65 } | 64 } |
66 | 65 |
67 void MediaStreamRemoteVideoSource:: | 66 void MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate::RenderFrame( |
68 RemoteVideoSourceDelegate::SetSize(int width, int height) { | 67 const cricket::VideoFrame* incoming_frame) { |
69 } | |
70 | |
71 void MediaStreamRemoteVideoSource:: | |
72 RemoteVideoSourceDelegate::RenderFrame( | |
73 const cricket::VideoFrame* frame) { | |
74 TRACE_EVENT0("webrtc", "RemoteVideoSourceDelegate::RenderFrame"); | 68 TRACE_EVENT0("webrtc", "RemoteVideoSourceDelegate::RenderFrame"); |
75 base::TimeDelta timestamp = base::TimeDelta::FromMicroseconds( | 69 base::TimeDelta timestamp = base::TimeDelta::FromMicroseconds( |
76 frame->GetElapsedTime() / rtc::kNumNanosecsPerMicrosec); | 70 incoming_frame->GetElapsedTime() / rtc::kNumNanosecsPerMicrosec); |
77 | 71 |
78 scoped_refptr<media::VideoFrame> video_frame; | 72 scoped_refptr<media::VideoFrame> video_frame; |
79 if (frame->GetNativeHandle() != NULL) { | 73 if (incoming_frame->GetNativeHandle() != NULL) { |
80 NativeHandleImpl* handle = | 74 NativeHandleImpl* handle = |
81 static_cast<NativeHandleImpl*>(frame->GetNativeHandle()); | 75 static_cast<NativeHandleImpl*>(incoming_frame->GetNativeHandle()); |
82 video_frame = static_cast<media::VideoFrame*>(handle->GetHandle()); | 76 video_frame = static_cast<media::VideoFrame*>(handle->GetHandle()); |
83 video_frame->set_timestamp(timestamp); | 77 video_frame->set_timestamp(timestamp); |
84 } else { | 78 } else { |
| 79 const cricket::VideoFrame* frame = |
| 80 incoming_frame->GetCopyWithRotationApplied(); |
| 81 |
85 gfx::Size size(frame->GetWidth(), frame->GetHeight()); | 82 gfx::Size size(frame->GetWidth(), frame->GetHeight()); |
86 | 83 |
87 // Non-square pixels are unsupported. | 84 // Non-square pixels are unsupported. |
88 DCHECK_EQ(frame->GetPixelWidth(), 1u); | 85 DCHECK_EQ(frame->GetPixelWidth(), 1u); |
89 DCHECK_EQ(frame->GetPixelHeight(), 1u); | 86 DCHECK_EQ(frame->GetPixelHeight(), 1u); |
90 | 87 |
91 // Make a shallow copy. Both |frame| and |video_frame| will share a single | 88 // Make a shallow copy. Both |frame| and |video_frame| will share a single |
92 // reference counted frame buffer. Const cast and hope no one will overwrite | 89 // reference counted frame buffer. Const cast and hope no one will overwrite |
93 // the data. | 90 // the data. |
94 // TODO(magjed): Update media::VideoFrame to support const data so we don't | 91 // TODO(magjed): Update media::VideoFrame to support const data so we don't |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 case webrtc::MediaStreamTrackInterface::kEnded: | 178 case webrtc::MediaStreamTrackInterface::kEnded: |
182 SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded); | 179 SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded); |
183 break; | 180 break; |
184 default: | 181 default: |
185 NOTREACHED(); | 182 NOTREACHED(); |
186 break; | 183 break; |
187 } | 184 } |
188 } | 185 } |
189 | 186 |
190 } // namespace content | 187 } // namespace content |
OLD | NEW |