| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 // WebRTC Chromium timestamp diff | 73 // WebRTC Chromium timestamp diff |
| 74 const base::TimeDelta time_diff_; | 74 const base::TimeDelta time_diff_; |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate:: | 77 MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate:: |
| 78 RemoteVideoSourceDelegate( | 78 RemoteVideoSourceDelegate( |
| 79 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | 79 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
| 80 const VideoCaptureDeliverFrameCB& new_frame_callback) | 80 const VideoCaptureDeliverFrameCB& new_frame_callback) |
| 81 : io_task_runner_(io_task_runner), | 81 : io_task_runner_(io_task_runner), |
| 82 frame_callback_(new_frame_callback), | 82 frame_callback_(new_frame_callback), |
| 83 start_timestamp_(media::kNoTimestamp()), | 83 start_timestamp_(media::kNoTimestamp), |
| 84 // TODO(qiangchen): There can be two differences between clocks: 1) | 84 // TODO(qiangchen): There can be two differences between clocks: 1) |
| 85 // the offset, 2) the rate (i.e., one clock runs faster than the other). | 85 // the offset, 2) the rate (i.e., one clock runs faster than the other). |
| 86 // See http://crbug/516700 | 86 // See http://crbug/516700 |
| 87 time_diff_(base::TimeTicks::Now() - base::TimeTicks() - | 87 time_diff_(base::TimeTicks::Now() - base::TimeTicks() - |
| 88 base::TimeDelta::FromMicroseconds(rtc::TimeMicros())) {} | 88 base::TimeDelta::FromMicroseconds(rtc::TimeMicros())) {} |
| 89 | 89 |
| 90 MediaStreamRemoteVideoSource:: | 90 MediaStreamRemoteVideoSource:: |
| 91 RemoteVideoSourceDelegate::~RemoteVideoSourceDelegate() { | 91 RemoteVideoSourceDelegate::~RemoteVideoSourceDelegate() { |
| 92 } | 92 } |
| 93 | 93 |
| 94 namespace { | 94 namespace { |
| 95 void DoNothing(const scoped_refptr<rtc::RefCountInterface>& ref) {} | 95 void DoNothing(const scoped_refptr<rtc::RefCountInterface>& ref) {} |
| 96 } // anonymous | 96 } // anonymous |
| 97 | 97 |
| 98 void MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate::OnFrame( | 98 void MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate::OnFrame( |
| 99 const cricket::VideoFrame& incoming_frame) { | 99 const cricket::VideoFrame& incoming_frame) { |
| 100 const base::TimeDelta incoming_timestamp = base::TimeDelta::FromMicroseconds( | 100 const base::TimeDelta incoming_timestamp = base::TimeDelta::FromMicroseconds( |
| 101 incoming_frame.GetTimeStamp() / rtc::kNumNanosecsPerMicrosec); | 101 incoming_frame.GetTimeStamp() / rtc::kNumNanosecsPerMicrosec); |
| 102 const base::TimeTicks render_time = | 102 const base::TimeTicks render_time = |
| 103 base::TimeTicks() + incoming_timestamp + time_diff_; | 103 base::TimeTicks() + incoming_timestamp + time_diff_; |
| 104 | 104 |
| 105 TRACE_EVENT1("webrtc", "RemoteVideoSourceDelegate::RenderFrame", | 105 TRACE_EVENT1("webrtc", "RemoteVideoSourceDelegate::RenderFrame", |
| 106 "Ideal Render Instant", render_time.ToInternalValue()); | 106 "Ideal Render Instant", render_time.ToInternalValue()); |
| 107 | 107 |
| 108 CHECK_NE(media::kNoTimestamp(), incoming_timestamp); | 108 CHECK_NE(media::kNoTimestamp, incoming_timestamp); |
| 109 if (start_timestamp_ == media::kNoTimestamp()) | 109 if (start_timestamp_ == media::kNoTimestamp) |
| 110 start_timestamp_ = incoming_timestamp; | 110 start_timestamp_ = incoming_timestamp; |
| 111 const base::TimeDelta elapsed_timestamp = | 111 const base::TimeDelta elapsed_timestamp = |
| 112 incoming_timestamp - start_timestamp_; | 112 incoming_timestamp - start_timestamp_; |
| 113 | 113 |
| 114 scoped_refptr<media::VideoFrame> video_frame; | 114 scoped_refptr<media::VideoFrame> video_frame; |
| 115 scoped_refptr<webrtc::VideoFrameBuffer> buffer( | 115 scoped_refptr<webrtc::VideoFrameBuffer> buffer( |
| 116 incoming_frame.video_frame_buffer()); | 116 incoming_frame.video_frame_buffer()); |
| 117 | 117 |
| 118 if (buffer->native_handle() != NULL) { | 118 if (buffer->native_handle() != NULL) { |
| 119 video_frame = static_cast<media::VideoFrame*>(buffer->native_handle()); | 119 video_frame = static_cast<media::VideoFrame*>(buffer->native_handle()); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 case webrtc::MediaStreamTrackInterface::kEnded: | 242 case webrtc::MediaStreamTrackInterface::kEnded: |
| 243 SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded); | 243 SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded); |
| 244 break; | 244 break; |
| 245 default: | 245 default: |
| 246 NOTREACHED(); | 246 NOTREACHED(); |
| 247 break; | 247 break; |
| 248 } | 248 } |
| 249 } | 249 } |
| 250 | 250 |
| 251 } // namespace content | 251 } // namespace content |
| OLD | NEW |