Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: content/renderer/media/webrtc/media_stream_remote_video_source.cc

Issue 1265433003: Preliminary change for new rtc rendering algorithm (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: WebRTC Chromium Timestamp Alignment Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/threading/thread_checker.h" 10 #include "base/threading/thread_checker.h"
11 #include "base/trace_event/trace_event.h" 11 #include "base/trace_event/trace_event.h"
12 #include "content/renderer/media/webrtc/track_observer.h" 12 #include "content/renderer/media/webrtc/track_observer.h"
13 #include "media/base/bind_to_current_loop.h" 13 #include "media/base/bind_to_current_loop.h"
14 #include "media/base/video_frame.h" 14 #include "media/base/video_frame.h"
15 #include "media/base/video_util.h" 15 #include "media/base/video_util.h"
16 #include "third_party/libjingle/source/talk/media/base/videoframe.h" 16 #include "third_party/libjingle/source/talk/media/base/videoframe.h"
17 #include "third_party/webrtc/system_wrappers/interface/tick_util.h"
17 18
18 namespace content { 19 namespace content {
19 20
20 // Internal class used for receiving frames from the webrtc track on a 21 // Internal class used for receiving frames from the webrtc track on a
21 // libjingle thread and forward it to the IO-thread. 22 // libjingle thread and forward it to the IO-thread.
22 class MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate 23 class MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate
23 : public base::RefCountedThreadSafe<RemoteVideoSourceDelegate>, 24 : public base::RefCountedThreadSafe<RemoteVideoSourceDelegate>,
24 public webrtc::VideoRendererInterface { 25 public webrtc::VideoRendererInterface {
25 public: 26 public:
26 RemoteVideoSourceDelegate( 27 RemoteVideoSourceDelegate(
(...skipping 13 matching lines...) Expand all
40 const scoped_refptr<media::VideoFrame>& video_frame); 41 const scoped_refptr<media::VideoFrame>& video_frame);
41 42
42 private: 43 private:
43 // Bound to the render thread. 44 // Bound to the render thread.
44 base::ThreadChecker thread_checker_; 45 base::ThreadChecker thread_checker_;
45 46
46 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; 47 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
47 48
48 // |frame_callback_| is accessed on the IO thread. 49 // |frame_callback_| is accessed on the IO thread.
49 VideoCaptureDeliverFrameCB frame_callback_; 50 VideoCaptureDeliverFrameCB frame_callback_;
51
52 // WebRTC Chromium timestamp diff
53 int64_t time_diff_us_;
50 }; 54 };
51 55
52 MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate:: 56 MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate::
53 RemoteVideoSourceDelegate( 57 RemoteVideoSourceDelegate(
54 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, 58 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
55 const VideoCaptureDeliverFrameCB& new_frame_callback) 59 const VideoCaptureDeliverFrameCB& new_frame_callback)
56 : io_task_runner_(io_task_runner), frame_callback_(new_frame_callback) { 60 : io_task_runner_(io_task_runner), frame_callback_(new_frame_callback) {
61 time_diff_us_ =
miu 2015/08/04 04:35:07 Yes, this can be a tricky problem. There's two di
qiangchen 2015/08/04 16:35:25 Did the TODO. While, adding SetRealTimeClock() can
miu 2015/08/04 20:37:32 Oh, yeah. I did mean in another CL. ;)
62 (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds() -
63 webrtc::TickTime::MicrosecondTimestamp();
57 } 64 }
58 65
59 MediaStreamRemoteVideoSource:: 66 MediaStreamRemoteVideoSource::
60 RemoteVideoSourceDelegate::~RemoteVideoSourceDelegate() { 67 RemoteVideoSourceDelegate::~RemoteVideoSourceDelegate() {
61 } 68 }
62 69
63 void MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate::RenderFrame( 70 void MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate::RenderFrame(
64 const cricket::VideoFrame* incoming_frame) { 71 const cricket::VideoFrame* incoming_frame) {
65 TRACE_EVENT0("webrtc", "RemoteVideoSourceDelegate::RenderFrame"); 72 base::TimeTicks render_time =
73 base::TimeTicks() +
74 base::TimeDelta::FromMicroseconds(incoming_frame->GetTimeStamp() / 1000 +
75 time_diff_us_);
76
77 TRACE_EVENT1("webrtc", "RemoteVideoSourceDelegate::RenderFrame",
78 "Ideal Render Instant", render_time.ToInternalValue());
79
66 base::TimeDelta timestamp = base::TimeDelta::FromMicroseconds( 80 base::TimeDelta timestamp = base::TimeDelta::FromMicroseconds(
67 incoming_frame->GetElapsedTime() / rtc::kNumNanosecsPerMicrosec); 81 incoming_frame->GetElapsedTime() / rtc::kNumNanosecsPerMicrosec);
68 82
69 scoped_refptr<media::VideoFrame> video_frame; 83 scoped_refptr<media::VideoFrame> video_frame;
70 if (incoming_frame->GetNativeHandle() != NULL) { 84 if (incoming_frame->GetNativeHandle() != NULL) {
71 video_frame = 85 video_frame =
72 static_cast<media::VideoFrame*>(incoming_frame->GetNativeHandle()); 86 static_cast<media::VideoFrame*>(incoming_frame->GetNativeHandle());
73 video_frame->set_timestamp(timestamp); 87 video_frame->set_timestamp(timestamp);
74 } else { 88 } else {
75 const cricket::VideoFrame* frame = 89 const cricket::VideoFrame* frame =
(...skipping 13 matching lines...) Expand all
89 video_frame = media::VideoFrame::WrapExternalYuvData( 103 video_frame = media::VideoFrame::WrapExternalYuvData(
90 media::PIXEL_FORMAT_YV12, size, gfx::Rect(size), size, 104 media::PIXEL_FORMAT_YV12, size, gfx::Rect(size), size,
91 frame->GetYPitch(), frame->GetUPitch(), frame->GetVPitch(), 105 frame->GetYPitch(), frame->GetUPitch(), frame->GetVPitch(),
92 const_cast<uint8_t*>(frame->GetYPlane()), 106 const_cast<uint8_t*>(frame->GetYPlane()),
93 const_cast<uint8_t*>(frame->GetUPlane()), 107 const_cast<uint8_t*>(frame->GetUPlane()),
94 const_cast<uint8_t*>(frame->GetVPlane()), timestamp); 108 const_cast<uint8_t*>(frame->GetVPlane()), timestamp);
95 video_frame->AddDestructionObserver( 109 video_frame->AddDestructionObserver(
96 base::Bind(&base::DeletePointer<cricket::VideoFrame>, frame->Copy())); 110 base::Bind(&base::DeletePointer<cricket::VideoFrame>, frame->Copy()));
97 } 111 }
98 112
113 video_frame->metadata()->SetTimeTicks(
114 media::VideoFrameMetadata::REFERENCE_TIME, render_time);
115
99 io_task_runner_->PostTask( 116 io_task_runner_->PostTask(
100 FROM_HERE, base::Bind(&RemoteVideoSourceDelegate::DoRenderFrameOnIOThread, 117 FROM_HERE, base::Bind(&RemoteVideoSourceDelegate::DoRenderFrameOnIOThread,
101 this, video_frame)); 118 this, video_frame));
102 } 119 }
103 120
104 void MediaStreamRemoteVideoSource:: 121 void MediaStreamRemoteVideoSource::
105 RemoteVideoSourceDelegate::DoRenderFrameOnIOThread( 122 RemoteVideoSourceDelegate::DoRenderFrameOnIOThread(
106 const scoped_refptr<media::VideoFrame>& video_frame) { 123 const scoped_refptr<media::VideoFrame>& video_frame) {
107 DCHECK(io_task_runner_->BelongsToCurrentThread()); 124 DCHECK(io_task_runner_->BelongsToCurrentThread());
108 TRACE_EVENT0("webrtc", "RemoteVideoSourceDelegate::DoRenderFrameOnIOThread"); 125 TRACE_EVENT0("webrtc", "RemoteVideoSourceDelegate::DoRenderFrameOnIOThread");
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 case webrtc::MediaStreamTrackInterface::kEnded: 192 case webrtc::MediaStreamTrackInterface::kEnded:
176 SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded); 193 SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded);
177 break; 194 break;
178 default: 195 default:
179 NOTREACHED(); 196 NOTREACHED();
180 break; 197 break;
181 } 198 }
182 } 199 }
183 200
184 } // namespace content 201 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698