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

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

Issue 1304863002: Revert of Preliminary change for new rtc rendering algorithm (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « content/renderer/media/webmediaplayer_ms.cc ('k') | content/renderer/render_frame_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
18 17
19 namespace content { 18 namespace content {
20 19
21 // Internal class used for receiving frames from the webrtc track on a 20 // Internal class used for receiving frames from the webrtc track on a
22 // libjingle thread and forward it to the IO-thread. 21 // libjingle thread and forward it to the IO-thread.
23 class MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate 22 class MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate
24 : public base::RefCountedThreadSafe<RemoteVideoSourceDelegate>, 23 : public base::RefCountedThreadSafe<RemoteVideoSourceDelegate>,
25 public webrtc::VideoRendererInterface { 24 public webrtc::VideoRendererInterface {
26 public: 25 public:
27 RemoteVideoSourceDelegate( 26 RemoteVideoSourceDelegate(
(...skipping 13 matching lines...) Expand all
41 const scoped_refptr<media::VideoFrame>& video_frame); 40 const scoped_refptr<media::VideoFrame>& video_frame);
42 41
43 private: 42 private:
44 // Bound to the render thread. 43 // Bound to the render thread.
45 base::ThreadChecker thread_checker_; 44 base::ThreadChecker thread_checker_;
46 45
47 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; 46 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
48 47
49 // |frame_callback_| is accessed on the IO thread. 48 // |frame_callback_| is accessed on the IO thread.
50 VideoCaptureDeliverFrameCB frame_callback_; 49 VideoCaptureDeliverFrameCB frame_callback_;
51
52 // WebRTC Chromium timestamp diff
53 int64_t time_diff_us_;
54 }; 50 };
55 51
56 MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate:: 52 MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate::
57 RemoteVideoSourceDelegate( 53 RemoteVideoSourceDelegate(
58 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, 54 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
59 const VideoCaptureDeliverFrameCB& new_frame_callback) 55 const VideoCaptureDeliverFrameCB& new_frame_callback)
60 : io_task_runner_(io_task_runner), frame_callback_(new_frame_callback) { 56 : io_task_runner_(io_task_runner), frame_callback_(new_frame_callback) {
61 // TODO(qiangchen): There can be two differences between clocks: 1)
62 // the offset, 2) the rate (i.e., one clock runs faster than the other).
63 // See http://crbug/516700
64 time_diff_us_ =
65 (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds() -
66 webrtc::TickTime::MicrosecondTimestamp();
67 } 57 }
68 58
69 MediaStreamRemoteVideoSource:: 59 MediaStreamRemoteVideoSource::
70 RemoteVideoSourceDelegate::~RemoteVideoSourceDelegate() { 60 RemoteVideoSourceDelegate::~RemoteVideoSourceDelegate() {
71 } 61 }
72 62
73 void MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate::RenderFrame( 63 void MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate::RenderFrame(
74 const cricket::VideoFrame* incoming_frame) { 64 const cricket::VideoFrame* incoming_frame) {
75 base::TimeTicks render_time = 65 TRACE_EVENT0("webrtc", "RemoteVideoSourceDelegate::RenderFrame");
76 base::TimeTicks() +
77 base::TimeDelta::FromMicroseconds(incoming_frame->GetTimeStamp() / 1000 +
78 time_diff_us_);
79
80 TRACE_EVENT1("webrtc", "RemoteVideoSourceDelegate::RenderFrame",
81 "Ideal Render Instant", render_time.ToInternalValue());
82
83 base::TimeDelta timestamp = base::TimeDelta::FromMicroseconds( 66 base::TimeDelta timestamp = base::TimeDelta::FromMicroseconds(
84 incoming_frame->GetElapsedTime() / rtc::kNumNanosecsPerMicrosec); 67 incoming_frame->GetElapsedTime() / rtc::kNumNanosecsPerMicrosec);
85 68
86 scoped_refptr<media::VideoFrame> video_frame; 69 scoped_refptr<media::VideoFrame> video_frame;
87 if (incoming_frame->GetNativeHandle() != NULL) { 70 if (incoming_frame->GetNativeHandle() != NULL) {
88 video_frame = 71 video_frame =
89 static_cast<media::VideoFrame*>(incoming_frame->GetNativeHandle()); 72 static_cast<media::VideoFrame*>(incoming_frame->GetNativeHandle());
90 video_frame->set_timestamp(timestamp); 73 video_frame->set_timestamp(timestamp);
91 } else { 74 } else {
92 const cricket::VideoFrame* frame = 75 const cricket::VideoFrame* frame =
(...skipping 13 matching lines...) Expand all
106 video_frame = media::VideoFrame::WrapExternalYuvData( 89 video_frame = media::VideoFrame::WrapExternalYuvData(
107 media::PIXEL_FORMAT_YV12, size, gfx::Rect(size), size, 90 media::PIXEL_FORMAT_YV12, size, gfx::Rect(size), size,
108 frame->GetYPitch(), frame->GetUPitch(), frame->GetVPitch(), 91 frame->GetYPitch(), frame->GetUPitch(), frame->GetVPitch(),
109 const_cast<uint8_t*>(frame->GetYPlane()), 92 const_cast<uint8_t*>(frame->GetYPlane()),
110 const_cast<uint8_t*>(frame->GetUPlane()), 93 const_cast<uint8_t*>(frame->GetUPlane()),
111 const_cast<uint8_t*>(frame->GetVPlane()), timestamp); 94 const_cast<uint8_t*>(frame->GetVPlane()), timestamp);
112 video_frame->AddDestructionObserver( 95 video_frame->AddDestructionObserver(
113 base::Bind(&base::DeletePointer<cricket::VideoFrame>, frame->Copy())); 96 base::Bind(&base::DeletePointer<cricket::VideoFrame>, frame->Copy()));
114 } 97 }
115 98
116 video_frame->metadata()->SetTimeTicks(
117 media::VideoFrameMetadata::REFERENCE_TIME, render_time);
118
119 io_task_runner_->PostTask( 99 io_task_runner_->PostTask(
120 FROM_HERE, base::Bind(&RemoteVideoSourceDelegate::DoRenderFrameOnIOThread, 100 FROM_HERE, base::Bind(&RemoteVideoSourceDelegate::DoRenderFrameOnIOThread,
121 this, video_frame)); 101 this, video_frame));
122 } 102 }
123 103
124 void MediaStreamRemoteVideoSource:: 104 void MediaStreamRemoteVideoSource::
125 RemoteVideoSourceDelegate::DoRenderFrameOnIOThread( 105 RemoteVideoSourceDelegate::DoRenderFrameOnIOThread(
126 const scoped_refptr<media::VideoFrame>& video_frame) { 106 const scoped_refptr<media::VideoFrame>& video_frame) {
127 DCHECK(io_task_runner_->BelongsToCurrentThread()); 107 DCHECK(io_task_runner_->BelongsToCurrentThread());
128 TRACE_EVENT0("webrtc", "RemoteVideoSourceDelegate::DoRenderFrameOnIOThread"); 108 TRACE_EVENT0("webrtc", "RemoteVideoSourceDelegate::DoRenderFrameOnIOThread");
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 case webrtc::MediaStreamTrackInterface::kEnded: 175 case webrtc::MediaStreamTrackInterface::kEnded:
196 SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded); 176 SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded);
197 break; 177 break;
198 default: 178 default:
199 NOTREACHED(); 179 NOTREACHED();
200 break; 180 break;
201 } 181 }
202 } 182 }
203 183
204 } // namespace content 184 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/webmediaplayer_ms.cc ('k') | content/renderer/render_frame_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698