OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/rtc_video_capturer.h" | 5 #include "content/renderer/media/rtc_video_capturer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/debug/trace_event.h" |
8 | 9 |
9 namespace content { | 10 namespace content { |
10 | 11 |
11 RtcVideoCapturer::RtcVideoCapturer( | 12 RtcVideoCapturer::RtcVideoCapturer( |
12 const media::VideoCaptureSessionId id, | 13 const media::VideoCaptureSessionId id, |
13 VideoCaptureImplManager* vc_manager, | 14 VideoCaptureImplManager* vc_manager, |
14 bool is_screencast) | 15 bool is_screencast) |
15 : is_screencast_(is_screencast), | 16 : is_screencast_(is_screencast), |
16 delegate_(new RtcVideoCaptureDelegate(id, vc_manager)), | 17 delegate_(new RtcVideoCaptureDelegate(id, vc_manager)), |
17 state_(VIDEO_CAPTURE_STATE_STOPPED) { | 18 state_(VIDEO_CAPTURE_STATE_STOPPED) { |
| 19 base::Time::Exploded exploded = {}; |
| 20 exploded.year = 1900; |
| 21 exploded.month = 1; |
| 22 exploded.day_of_week = 0; |
| 23 exploded.day_of_month = 1; |
| 24 exploded.hour = 0; |
| 25 exploded.minute = 0; |
| 26 exploded.second = 0; |
| 27 exploded.millisecond = 0; |
| 28 DCHECK(exploded.HasValidValues()); |
| 29 ntp_epoch_ = base::Time::FromUTCExploded(exploded); |
18 } | 30 } |
19 | 31 |
20 RtcVideoCapturer::~RtcVideoCapturer() { | 32 RtcVideoCapturer::~RtcVideoCapturer() { |
21 DCHECK(VIDEO_CAPTURE_STATE_STOPPED); | 33 DCHECK(VIDEO_CAPTURE_STATE_STOPPED); |
22 DVLOG(3) << " RtcVideoCapturer::dtor"; | 34 DVLOG(3) << " RtcVideoCapturer::dtor"; |
23 } | 35 } |
24 | 36 |
25 cricket::CaptureState RtcVideoCapturer::Start( | 37 cricket::CaptureState RtcVideoCapturer::Start( |
26 const cricket::VideoFormat& capture_format) { | 38 const cricket::VideoFormat& capture_format) { |
27 DVLOG(3) << " RtcVideoCapturer::Start "; | 39 DVLOG(3) << " RtcVideoCapturer::Start "; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 const media::VideoCapture::VideoFrameBuffer& buf) { | 105 const media::VideoCapture::VideoFrameBuffer& buf) { |
94 // Currently, |fourcc| is always I420. | 106 // Currently, |fourcc| is always I420. |
95 cricket::CapturedFrame frame; | 107 cricket::CapturedFrame frame; |
96 frame.width = buf.width; | 108 frame.width = buf.width; |
97 frame.height = buf.height; | 109 frame.height = buf.height; |
98 frame.fourcc = cricket::FOURCC_I420; | 110 frame.fourcc = cricket::FOURCC_I420; |
99 frame.data_size = buf.buffer_size; | 111 frame.data_size = buf.buffer_size; |
100 // cricket::CapturedFrame time is in nanoseconds. | 112 // cricket::CapturedFrame time is in nanoseconds. |
101 frame.elapsed_time = (buf.timestamp - start_time_).InMicroseconds() * | 113 frame.elapsed_time = (buf.timestamp - start_time_).InMicroseconds() * |
102 base::Time::kNanosecondsPerMicrosecond; | 114 base::Time::kNanosecondsPerMicrosecond; |
103 frame.time_stamp = frame.elapsed_time; | 115 // Timestamp in NTP time (seconds since 0:00 UTC 1 January 1900) in ms. |
| 116 frame.time_stamp = (buf.timestamp - ntp_epoch_).InMilliseconds(); |
104 frame.data = buf.memory_pointer; | 117 frame.data = buf.memory_pointer; |
105 frame.pixel_height = 1; | 118 frame.pixel_height = 1; |
106 frame.pixel_width = 1; | 119 frame.pixel_width = 1; |
107 | 120 |
| 121 TRACE_EVENT_INSTANT2("rtc_video_capturer", |
| 122 "OnFrameCaptured", |
| 123 TRACE_EVENT_SCOPE_THREAD, |
| 124 "elapsed time", |
| 125 frame.elapsed_time, |
| 126 "timestamp", |
| 127 frame.time_stamp); |
| 128 |
108 // This signals to libJingle that a new VideoFrame is available. | 129 // This signals to libJingle that a new VideoFrame is available. |
109 // libJingle have no assumptions on what thread this signal come from. | 130 // libJingle have no assumptions on what thread this signal come from. |
110 SignalFrameCaptured(this, &frame); | 131 SignalFrameCaptured(this, &frame); |
111 } | 132 } |
112 | 133 |
113 void RtcVideoCapturer::OnStateChange( | 134 void RtcVideoCapturer::OnStateChange( |
114 RtcVideoCaptureDelegate::CaptureState state) { | 135 RtcVideoCaptureDelegate::CaptureState state) { |
115 cricket::CaptureState converted_state = cricket::CS_FAILED; | 136 cricket::CaptureState converted_state = cricket::CS_FAILED; |
116 DVLOG(3) << " RtcVideoCapturer::OnStateChange " << state; | 137 DVLOG(3) << " RtcVideoCapturer::OnStateChange " << state; |
117 switch (state) { | 138 switch (state) { |
(...skipping 11 matching lines...) Expand all Loading... |
129 converted_state = cricket::CS_FAILED; | 150 converted_state = cricket::CS_FAILED; |
130 break; | 151 break; |
131 default: | 152 default: |
132 NOTREACHED(); | 153 NOTREACHED(); |
133 break; | 154 break; |
134 } | 155 } |
135 SignalStateChange(this, converted_state); | 156 SignalStateChange(this, converted_state); |
136 } | 157 } |
137 | 158 |
138 } // namespace content | 159 } // namespace content |
OLD | NEW |