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 <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 // TODO(qiangchen): There can be two differences between clocks: 1) | 65 // TODO(qiangchen): There can be two differences between clocks: 1) |
66 // the offset, 2) the rate (i.e., one clock runs faster than the other). | 66 // the offset, 2) the rate (i.e., one clock runs faster than the other). |
67 // See http://crbug/516700 | 67 // See http://crbug/516700 |
68 time_diff_(base::TimeTicks::Now() - base::TimeTicks() - | 68 time_diff_(base::TimeTicks::Now() - base::TimeTicks() - |
69 base::TimeDelta::FromMicroseconds(rtc::TimeMicros())) {} | 69 base::TimeDelta::FromMicroseconds(rtc::TimeMicros())) {} |
70 | 70 |
71 MediaStreamRemoteVideoSource:: | 71 MediaStreamRemoteVideoSource:: |
72 RemoteVideoSourceDelegate::~RemoteVideoSourceDelegate() { | 72 RemoteVideoSourceDelegate::~RemoteVideoSourceDelegate() { |
73 } | 73 } |
74 | 74 |
| 75 namespace { |
| 76 void DoNothing(const scoped_refptr<rtc::RefCountInterface>& ref) {} |
| 77 } // anonymous |
| 78 |
75 void MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate::OnFrame( | 79 void MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate::OnFrame( |
76 const cricket::VideoFrame& incoming_frame) { | 80 const cricket::VideoFrame& incoming_frame) { |
77 const base::TimeDelta incoming_timestamp = base::TimeDelta::FromMicroseconds( | 81 const base::TimeDelta incoming_timestamp = base::TimeDelta::FromMicroseconds( |
78 incoming_frame.GetTimeStamp() / rtc::kNumNanosecsPerMicrosec); | 82 incoming_frame.GetTimeStamp() / rtc::kNumNanosecsPerMicrosec); |
79 const base::TimeTicks render_time = | 83 const base::TimeTicks render_time = |
80 base::TimeTicks() + incoming_timestamp + time_diff_; | 84 base::TimeTicks() + incoming_timestamp + time_diff_; |
81 | 85 |
82 TRACE_EVENT1("webrtc", "RemoteVideoSourceDelegate::RenderFrame", | 86 TRACE_EVENT1("webrtc", "RemoteVideoSourceDelegate::RenderFrame", |
83 "Ideal Render Instant", render_time.ToInternalValue()); | 87 "Ideal Render Instant", render_time.ToInternalValue()); |
84 | 88 |
85 CHECK_NE(media::kNoTimestamp(), incoming_timestamp); | 89 CHECK_NE(media::kNoTimestamp(), incoming_timestamp); |
86 if (start_timestamp_ == media::kNoTimestamp()) | 90 if (start_timestamp_ == media::kNoTimestamp()) |
87 start_timestamp_ = incoming_timestamp; | 91 start_timestamp_ = incoming_timestamp; |
88 const base::TimeDelta elapsed_timestamp = | 92 const base::TimeDelta elapsed_timestamp = |
89 incoming_timestamp - start_timestamp_; | 93 incoming_timestamp - start_timestamp_; |
90 | 94 |
91 scoped_refptr<media::VideoFrame> video_frame; | 95 scoped_refptr<media::VideoFrame> video_frame; |
92 if (incoming_frame.video_frame_buffer()->native_handle() != NULL) { | 96 scoped_refptr<webrtc::VideoFrameBuffer> buffer( |
| 97 incoming_frame.video_frame_buffer()); |
| 98 |
| 99 if (buffer->native_handle() != NULL) { |
93 video_frame = | 100 video_frame = |
94 static_cast<media::VideoFrame*>( | 101 static_cast<media::VideoFrame*>(buffer->native_handle()); |
95 incoming_frame.video_frame_buffer()->native_handle()); | |
96 video_frame->set_timestamp(elapsed_timestamp); | 102 video_frame->set_timestamp(elapsed_timestamp); |
97 } else { | 103 } else { |
98 const cricket::VideoFrame* frame = | 104 // Note that the GetCopyWithRotationApplied returns a pointer to a |
99 incoming_frame.GetCopyWithRotationApplied(); | 105 // frame owned by incoming_frame. |
100 | 106 buffer = |
101 gfx::Size size(frame->width(), frame->height()); | 107 incoming_frame.GetCopyWithRotationApplied()->video_frame_buffer(); |
| 108 gfx::Size size(buffer->width(), buffer->height()); |
102 | 109 |
103 // Make a shallow copy. Both |frame| and |video_frame| will share a single | 110 // Make a shallow copy. Both |frame| and |video_frame| will share a single |
104 // reference counted frame buffer. Const cast and hope no one will overwrite | 111 // reference counted frame buffer. Const cast and hope no one will overwrite |
105 // the data. | 112 // the data. |
106 // TODO(magjed): Update media::VideoFrame to support const data so we don't | 113 // TODO(magjed): Update media::VideoFrame to support const data so we don't |
107 // need to const cast here. | 114 // need to const cast here. |
108 video_frame = media::VideoFrame::WrapExternalYuvData( | 115 video_frame = media::VideoFrame::WrapExternalYuvData( |
109 media::PIXEL_FORMAT_YV12, size, gfx::Rect(size), size, | 116 media::PIXEL_FORMAT_YV12, size, gfx::Rect(size), size, |
110 frame->video_frame_buffer()->StrideY(), | 117 buffer->StrideY(), |
111 frame->video_frame_buffer()->StrideU(), | 118 buffer->StrideU(), |
112 frame->video_frame_buffer()->StrideV(), | 119 buffer->StrideV(), |
113 const_cast<uint8_t*>(frame->video_frame_buffer()->DataY()), | 120 const_cast<uint8_t*>(buffer->DataY()), |
114 const_cast<uint8_t*>(frame->video_frame_buffer()->DataU()), | 121 const_cast<uint8_t*>(buffer->DataU()), |
115 const_cast<uint8_t*>(frame->video_frame_buffer()->DataV()), | 122 const_cast<uint8_t*>(buffer->DataV()), |
116 elapsed_timestamp); | 123 elapsed_timestamp); |
117 if (!video_frame) | 124 if (!video_frame) |
118 return; | 125 return; |
119 video_frame->AddDestructionObserver( | 126 // The bind ensures that we keep a reference to the underlying buffer. |
120 base::Bind(&base::DeletePointer<cricket::VideoFrame>, frame->Copy())); | 127 video_frame->AddDestructionObserver(base::Bind(&DoNothing, buffer)); |
121 } | 128 } |
122 | 129 |
123 video_frame->metadata()->SetTimeTicks( | 130 video_frame->metadata()->SetTimeTicks( |
124 media::VideoFrameMetadata::REFERENCE_TIME, render_time); | 131 media::VideoFrameMetadata::REFERENCE_TIME, render_time); |
125 | 132 |
126 io_task_runner_->PostTask( | 133 io_task_runner_->PostTask( |
127 FROM_HERE, base::Bind(&RemoteVideoSourceDelegate::DoRenderFrameOnIOThread, | 134 FROM_HERE, base::Bind(&RemoteVideoSourceDelegate::DoRenderFrameOnIOThread, |
128 this, video_frame)); | 135 this, video_frame)); |
129 } | 136 } |
130 | 137 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 case webrtc::MediaStreamTrackInterface::kEnded: | 219 case webrtc::MediaStreamTrackInterface::kEnded: |
213 SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded); | 220 SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded); |
214 break; | 221 break; |
215 default: | 222 default: |
216 NOTREACHED(); | 223 NOTREACHED(); |
217 break; | 224 break; |
218 } | 225 } |
219 } | 226 } |
220 | 227 |
221 } // namespace content | 228 } // namespace content |
OLD | NEW |