| 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" | |
| 9 | 8 |
| 10 namespace content { | 9 namespace content { |
| 11 | 10 |
| 12 RtcVideoCapturer::RtcVideoCapturer( | 11 RtcVideoCapturer::RtcVideoCapturer( |
| 13 const media::VideoCaptureSessionId id, | 12 const media::VideoCaptureSessionId id, |
| 14 VideoCaptureImplManager* vc_manager, | 13 VideoCaptureImplManager* vc_manager, |
| 15 bool is_screencast) | 14 bool is_screencast) |
| 16 : is_screencast_(is_screencast), | 15 : is_screencast_(is_screencast), |
| 17 delegate_(new RtcVideoCaptureDelegate(id, vc_manager)), | 16 delegate_(new RtcVideoCaptureDelegate(id, vc_manager)), |
| 18 state_(VIDEO_CAPTURE_STATE_STOPPED) { | 17 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); | |
| 30 } | 18 } |
| 31 | 19 |
| 32 RtcVideoCapturer::~RtcVideoCapturer() { | 20 RtcVideoCapturer::~RtcVideoCapturer() { |
| 33 DCHECK(VIDEO_CAPTURE_STATE_STOPPED); | 21 DCHECK(VIDEO_CAPTURE_STATE_STOPPED); |
| 34 DVLOG(3) << " RtcVideoCapturer::dtor"; | 22 DVLOG(3) << " RtcVideoCapturer::dtor"; |
| 35 } | 23 } |
| 36 | 24 |
| 37 cricket::CaptureState RtcVideoCapturer::Start( | 25 cricket::CaptureState RtcVideoCapturer::Start( |
| 38 const cricket::VideoFormat& capture_format) { | 26 const cricket::VideoFormat& capture_format) { |
| 39 DVLOG(3) << " RtcVideoCapturer::Start "; | 27 DVLOG(3) << " RtcVideoCapturer::Start "; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 const media::VideoCapture::VideoFrameBuffer& buf) { | 93 const media::VideoCapture::VideoFrameBuffer& buf) { |
| 106 // Currently, |fourcc| is always I420. | 94 // Currently, |fourcc| is always I420. |
| 107 cricket::CapturedFrame frame; | 95 cricket::CapturedFrame frame; |
| 108 frame.width = buf.width; | 96 frame.width = buf.width; |
| 109 frame.height = buf.height; | 97 frame.height = buf.height; |
| 110 frame.fourcc = cricket::FOURCC_I420; | 98 frame.fourcc = cricket::FOURCC_I420; |
| 111 frame.data_size = buf.buffer_size; | 99 frame.data_size = buf.buffer_size; |
| 112 // cricket::CapturedFrame time is in nanoseconds. | 100 // cricket::CapturedFrame time is in nanoseconds. |
| 113 frame.elapsed_time = (buf.timestamp - start_time_).InMicroseconds() * | 101 frame.elapsed_time = (buf.timestamp - start_time_).InMicroseconds() * |
| 114 base::Time::kNanosecondsPerMicrosecond; | 102 base::Time::kNanosecondsPerMicrosecond; |
| 115 // Timestamp in NTP time (seconds since 0:00 UTC 1 January 1900) in ms. | 103 frame.time_stamp = frame.elapsed_time; |
| 116 frame.time_stamp = (buf.timestamp - ntp_epoch_).InMilliseconds(); | |
| 117 frame.data = buf.memory_pointer; | 104 frame.data = buf.memory_pointer; |
| 118 frame.pixel_height = 1; | 105 frame.pixel_height = 1; |
| 119 frame.pixel_width = 1; | 106 frame.pixel_width = 1; |
| 120 | 107 |
| 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 | |
| 129 // This signals to libJingle that a new VideoFrame is available. | 108 // This signals to libJingle that a new VideoFrame is available. |
| 130 // libJingle have no assumptions on what thread this signal come from. | 109 // libJingle have no assumptions on what thread this signal come from. |
| 131 SignalFrameCaptured(this, &frame); | 110 SignalFrameCaptured(this, &frame); |
| 132 } | 111 } |
| 133 | 112 |
| 134 void RtcVideoCapturer::OnStateChange( | 113 void RtcVideoCapturer::OnStateChange( |
| 135 RtcVideoCaptureDelegate::CaptureState state) { | 114 RtcVideoCaptureDelegate::CaptureState state) { |
| 136 cricket::CaptureState converted_state = cricket::CS_FAILED; | 115 cricket::CaptureState converted_state = cricket::CS_FAILED; |
| 137 switch (state) { | 116 switch (state) { |
| 138 case RtcVideoCaptureDelegate::CAPTURE_STOPPED: | 117 case RtcVideoCaptureDelegate::CAPTURE_STOPPED: |
| 139 converted_state = cricket::CS_STOPPED; | 118 converted_state = cricket::CS_STOPPED; |
| 140 break; | 119 break; |
| 141 case RtcVideoCaptureDelegate::CAPTURE_RUNNING: | 120 case RtcVideoCaptureDelegate::CAPTURE_RUNNING: |
| 142 converted_state = cricket::CS_RUNNING; | 121 converted_state = cricket::CS_RUNNING; |
| 143 break; | 122 break; |
| 144 case RtcVideoCaptureDelegate::CAPTURE_FAILED: | 123 case RtcVideoCaptureDelegate::CAPTURE_FAILED: |
| 145 converted_state = cricket::CS_FAILED; | 124 converted_state = cricket::CS_FAILED; |
| 146 break; | 125 break; |
| 147 default: | 126 default: |
| 148 NOTREACHED(); | 127 NOTREACHED(); |
| 149 break; | 128 break; |
| 150 } | 129 } |
| 151 SignalStateChange(this, converted_state); | 130 SignalStateChange(this, converted_state); |
| 152 } | 131 } |
| 153 | 132 |
| 154 } // namespace content | 133 } // namespace content |
| OLD | NEW |