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

Side by Side Diff: content/browser/media/capture/content_video_capture_device_core.cc

Issue 955253002: Add metadata to media::VideoFrame and plumb it through IPC/MediaStream. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Windows compile errors. Created 5 years, 9 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/browser/media/capture/content_video_capture_device_core.h" 5 #include "content/browser/media/capture/content_video_capture_device_core.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback_forward.h" 9 #include "base/callback_forward.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 } 63 }
64 64
65 ThreadSafeCaptureOracle::~ThreadSafeCaptureOracle() {} 65 ThreadSafeCaptureOracle::~ThreadSafeCaptureOracle() {}
66 66
67 bool ThreadSafeCaptureOracle::ObserveEventAndDecideCapture( 67 bool ThreadSafeCaptureOracle::ObserveEventAndDecideCapture(
68 VideoCaptureOracle::Event event, 68 VideoCaptureOracle::Event event,
69 const gfx::Rect& damage_rect, 69 const gfx::Rect& damage_rect,
70 base::TimeTicks event_time, 70 base::TimeTicks event_time,
71 scoped_refptr<media::VideoFrame>* storage, 71 scoped_refptr<media::VideoFrame>* storage,
72 CaptureFrameCallback* callback) { 72 CaptureFrameCallback* callback) {
73 // Grab the current time before waiting to acquire the |lock_|.
74 const base::TimeTicks capture_begin_time = base::TimeTicks::Now();
75
73 base::AutoLock guard(lock_); 76 base::AutoLock guard(lock_);
74 77
75 if (!client_) 78 if (!client_)
76 return false; // Capture is stopped. 79 return false; // Capture is stopped.
77 80
78 // Always round up the coded size to multiple of 16 pixels. 81 // Always round up the coded size to multiple of 16 pixels.
79 // See http://crbug.com/402151. 82 // See http://crbug.com/402151.
80 const gfx::Size visible_size = params_.requested_format.frame_size; 83 const gfx::Size visible_size = params_.requested_format.frame_size;
81 const gfx::Size coded_size((visible_size.width() + 15) & ~15, 84 const gfx::Size coded_size((visible_size.width() + 15) & ~15,
82 (visible_size.height() + 15) & ~15); 85 (visible_size.height() + 15) & ~15);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 static_cast<uint8*>(output_buffer->data()), 137 static_cast<uint8*>(output_buffer->data()),
135 output_buffer->size(), 138 output_buffer->size(),
136 base::SharedMemory::NULLHandle(), 139 base::SharedMemory::NULLHandle(),
137 0, 140 0,
138 base::TimeDelta(), 141 base::TimeDelta(),
139 base::Closure()); 142 base::Closure());
140 } 143 }
141 *callback = base::Bind(&ThreadSafeCaptureOracle::DidCaptureFrame, 144 *callback = base::Bind(&ThreadSafeCaptureOracle::DidCaptureFrame,
142 this, 145 this,
143 frame_number, 146 frame_number,
144 output_buffer); 147 output_buffer,
148 capture_begin_time);
145 return true; 149 return true;
146 } 150 }
147 151
148 gfx::Size ThreadSafeCaptureOracle::GetCaptureSize() const { 152 gfx::Size ThreadSafeCaptureOracle::GetCaptureSize() const {
149 base::AutoLock guard(lock_); 153 base::AutoLock guard(lock_);
150 return params_.requested_format.frame_size; 154 return params_.requested_format.frame_size;
151 } 155 }
152 156
153 void ThreadSafeCaptureOracle::UpdateCaptureSize(const gfx::Size& source_size) { 157 void ThreadSafeCaptureOracle::UpdateCaptureSize(const gfx::Size& source_size) {
154 base::AutoLock guard(lock_); 158 base::AutoLock guard(lock_);
(...skipping 26 matching lines...) Expand all
181 185
182 void ThreadSafeCaptureOracle::ReportError(const std::string& reason) { 186 void ThreadSafeCaptureOracle::ReportError(const std::string& reason) {
183 base::AutoLock guard(lock_); 187 base::AutoLock guard(lock_);
184 if (client_) 188 if (client_)
185 client_->OnError(reason); 189 client_->OnError(reason);
186 } 190 }
187 191
188 void ThreadSafeCaptureOracle::DidCaptureFrame( 192 void ThreadSafeCaptureOracle::DidCaptureFrame(
189 int frame_number, 193 int frame_number,
190 const scoped_refptr<media::VideoCaptureDevice::Client::Buffer>& buffer, 194 const scoped_refptr<media::VideoCaptureDevice::Client::Buffer>& buffer,
195 base::TimeTicks capture_begin_time,
191 const scoped_refptr<media::VideoFrame>& frame, 196 const scoped_refptr<media::VideoFrame>& frame,
192 base::TimeTicks timestamp, 197 base::TimeTicks timestamp,
193 bool success) { 198 bool success) {
194 base::AutoLock guard(lock_); 199 base::AutoLock guard(lock_);
195 TRACE_EVENT_ASYNC_END2("mirroring", "Capture", buffer.get(), 200 TRACE_EVENT_ASYNC_END2("mirroring", "Capture", buffer.get(),
196 "success", success, 201 "success", success,
197 "timestamp", timestamp.ToInternalValue()); 202 "timestamp", timestamp.ToInternalValue());
198 203
199 if (!client_) 204 if (!client_)
200 return; // Capture is stopped. 205 return; // Capture is stopped.
201 206
202 if (success) { 207 if (success) {
203 if (oracle_->CompleteCapture(frame_number, &timestamp)) { 208 if (oracle_->CompleteCapture(frame_number, &timestamp)) {
204 media::VideoCaptureFormat format = params_.requested_format; 209 // TODO(miu): Use the locked-in frame rate from AnimatedContentSampler.
205 // TODO(miu): Passing VideoCaptureFormat here introduces ambiguities. The 210 frame->metadata().SetDouble(media::VideoFrame::kFrameRateMetadataKey,
206 // following is a hack where frame_size takes on a different meaning than 211 params_.requested_format.frame_rate);
207 // everywhere else (i.e., coded size, not visible size). Will fix in 212 // Provide capture begin/end timestamps in the VideoFrame metadata.
208 // soon-upcoming code change. 213 // Casting the int64 internal value of the start and end TimeTickses to
209 format.frame_size = frame->coded_size(); 214 // double is reasonable here. This will guarantee 1us resolution for
210 client_->OnIncomingCapturedVideoFrame(buffer, format, frame, timestamp); 215 // values up to 2^53 (e.g., ~285 years since kernel boot). Alternative
216 // approaches are much more heavyweight (e.g., storing the low and high 32
217 // bits as separate fields, storing as formatted ASCII strings, etc.).
218 frame->metadata().SetDouble(
219 "captureBeginTimeTicks",
Alpha Left Google 2015/02/26 21:17:23 Can these names be defined in video_frame.h as wel
miu 2015/02/26 23:25:18 I'm uncomfortable with starting the practice of pu
220 static_cast<double>(capture_begin_time.ToInternalValue()));
221 frame->metadata().SetDouble(
222 "captureEndTimeTicks",
223 static_cast<double>(base::TimeTicks::Now().ToInternalValue()));
224 client_->OnIncomingCapturedVideoFrame(buffer, frame, timestamp);
211 } 225 }
212 } 226 }
213 } 227 }
214 228
215 void ContentVideoCaptureDeviceCore::AllocateAndStart( 229 void ContentVideoCaptureDeviceCore::AllocateAndStart(
216 const media::VideoCaptureParams& params, 230 const media::VideoCaptureParams& params,
217 scoped_ptr<media::VideoCaptureDevice::Client> client) { 231 scoped_ptr<media::VideoCaptureDevice::Client> client) {
218 DCHECK(thread_checker_.CalledOnValidThread()); 232 DCHECK(thread_checker_.CalledOnValidThread());
219 233
220 if (state_ != kIdle) { 234 if (state_ != kIdle) {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 return; 364 return;
351 365
352 if (oracle_proxy_.get()) 366 if (oracle_proxy_.get())
353 oracle_proxy_->ReportError(reason); 367 oracle_proxy_->ReportError(reason);
354 368
355 StopAndDeAllocate(); 369 StopAndDeAllocate();
356 TransitionStateTo(kError); 370 TransitionStateTo(kError);
357 } 371 }
358 372
359 } // namespace content 373 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698