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

Side by Side Diff: media/capture/video/file_video_capture_device.cc

Issue 2673373003: getUserMeida: report device starting states (Closed)
Patch Set: address comments on PS#4 and revise unittests Created 3 years, 10 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "media/capture/video/file_video_capture_device.h" 5 #include "media/capture/video/file_video_capture_device.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 return file_parser; 292 return file_parser;
293 } 293 }
294 294
295 if (!file_parser->Initialize(video_format)) { 295 if (!file_parser->Initialize(video_format)) {
296 file_parser.reset(); 296 file_parser.reset();
297 } 297 }
298 return file_parser; 298 return file_parser;
299 } 299 }
300 300
301 FileVideoCaptureDevice::FileVideoCaptureDevice(const base::FilePath& file_path) 301 FileVideoCaptureDevice::FileVideoCaptureDevice(const base::FilePath& file_path)
302 : capture_thread_("CaptureThread"), file_path_(file_path) {} 302 : capture_thread_("CaptureThread"), file_path_(file_path), capture_(0) {}
303 303
304 FileVideoCaptureDevice::~FileVideoCaptureDevice() { 304 FileVideoCaptureDevice::~FileVideoCaptureDevice() {
305 DCHECK(thread_checker_.CalledOnValidThread()); 305 DCHECK(thread_checker_.CalledOnValidThread());
306 // Check if the thread is running. 306 // Check if the thread is running.
307 // This means that the device have not been DeAllocated properly. 307 // This means that the device have not been DeAllocated properly.
308 CHECK(!capture_thread_.IsRunning()); 308 CHECK(!capture_thread_.IsRunning());
309 } 309 }
310 310
311 void FileVideoCaptureDevice::AllocateAndStart( 311 void FileVideoCaptureDevice::AllocateAndStart(
312 const VideoCaptureParams& params, 312 const VideoCaptureParams& params,
(...skipping 27 matching lines...) Expand all
340 340
341 DCHECK(!file_parser_); 341 DCHECK(!file_parser_);
342 file_parser_ = GetVideoFileParser(file_path_, &capture_format_); 342 file_parser_ = GetVideoFileParser(file_path_, &capture_format_);
343 if (!file_parser_) { 343 if (!file_parser_) {
344 client_->OnError(FROM_HERE, "Could not open Video file"); 344 client_->OnError(FROM_HERE, "Could not open Video file");
345 return; 345 return;
346 } 346 }
347 347
348 DVLOG(1) << "Opened video file " << capture_format_.frame_size.ToString() 348 DVLOG(1) << "Opened video file " << capture_format_.frame_size.ToString()
349 << ", fps: " << capture_format_.frame_rate; 349 << ", fps: " << capture_format_.frame_rate;
350 client_->OnStarted();
351 capture_ = true;
350 352
351 capture_thread_.task_runner()->PostTask( 353 capture_thread_.task_runner()->PostTask(
352 FROM_HERE, base::Bind(&FileVideoCaptureDevice::OnCaptureTask, 354 FROM_HERE, base::Bind(&FileVideoCaptureDevice::OnCaptureTask,
353 base::Unretained(this))); 355 base::Unretained(this)));
354 } 356 }
355 357
356 void FileVideoCaptureDevice::OnStopAndDeAllocate() { 358 void FileVideoCaptureDevice::OnStopAndDeAllocate() {
357 DCHECK(capture_thread_.task_runner()->BelongsToCurrentThread()); 359 DCHECK(capture_thread_.task_runner()->BelongsToCurrentThread());
360 capture_ = false;
358 file_parser_.reset(); 361 file_parser_.reset();
359 client_.reset(); 362 client_.reset();
360 next_frame_time_ = base::TimeTicks(); 363 next_frame_time_ = base::TimeTicks();
361 } 364 }
362 365
363 void FileVideoCaptureDevice::OnCaptureTask() { 366 void FileVideoCaptureDevice::OnCaptureTask() {
364 DCHECK(capture_thread_.task_runner()->BelongsToCurrentThread()); 367 DCHECK(capture_thread_.task_runner()->BelongsToCurrentThread());
365 if (!client_) 368 if (!client_ || !capture_)
366 return; 369 return;
367 370
368 // Give the captured frame to the client. 371 // Give the captured frame to the client.
369 int frame_size = 0; 372 int frame_size = 0;
370 const uint8_t* frame_ptr = file_parser_->GetNextFrame(&frame_size); 373 const uint8_t* frame_ptr = file_parser_->GetNextFrame(&frame_size);
371 DCHECK(frame_size); 374 DCHECK(frame_size);
372 CHECK(frame_ptr); 375 CHECK(frame_ptr);
373 const base::TimeTicks current_time = base::TimeTicks::Now(); 376 const base::TimeTicks current_time = base::TimeTicks::Now();
374 if (first_ref_time_.is_null()) 377 if (first_ref_time_.is_null())
375 first_ref_time_ = current_time; 378 first_ref_time_ = current_time;
(...skipping 11 matching lines...) Expand all
387 if (next_frame_time_ < current_time) 390 if (next_frame_time_ < current_time)
388 next_frame_time_ = current_time; 391 next_frame_time_ = current_time;
389 } 392 }
390 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 393 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
391 FROM_HERE, base::Bind(&FileVideoCaptureDevice::OnCaptureTask, 394 FROM_HERE, base::Bind(&FileVideoCaptureDevice::OnCaptureTask,
392 base::Unretained(this)), 395 base::Unretained(this)),
393 next_frame_time_ - current_time); 396 next_frame_time_ - current_time);
394 } 397 }
395 398
396 } // namespace media 399 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698