camera_controller.h revision ddb351dbec246cf1fab5ec20d2d5520909041de1
1// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_CAMERA_CONTROLLER_H_
6#define CHROME_BROWSER_CHROMEOS_LOGIN_CAMERA_CONTROLLER_H_
7#pragma once
8
9#include "base/memory/scoped_ptr.h"
10#include "base/threading/thread.h"
11#include "chrome/browser/chromeos/login/camera.h"
12#include "third_party/skia/include/core/SkBitmap.h"
13
14namespace chromeos {
15
16class CameraController: public Camera::Delegate {
17 public:
18  class Delegate {
19   public:
20    virtual ~Delegate() {}
21
22    // Called when new frame was captured by camera.
23    virtual void OnCaptureSuccess() = 0;
24
25    // Called when camera failed to initialize or get the next frame.
26    virtual void OnCaptureFailure() = 0;
27  };
28
29  explicit CameraController(Delegate* delegate);
30  virtual ~CameraController();
31
32  void set_frame_width(int width) { frame_width_ = width; }
33  int frame_width() const { return frame_width_; }
34
35  void set_frame_height(int height) { frame_height_ = height; }
36  int frame_height() const { return frame_height_; }
37
38  // Initializes camera and starts video capturing.
39  void Start();
40
41  // Stops video capturing and deinitializes camera.
42  void Stop();
43
44  // Returns the last captured frame from the camera.
45  void GetFrame(SkBitmap* frame) const;
46
47  // Camera::Delegate implementation:
48  virtual void OnInitializeSuccess();
49  virtual void OnInitializeFailure();
50  virtual void OnStartCapturingSuccess();
51  virtual void OnStartCapturingFailure();
52  virtual void OnCaptureSuccess();
53  virtual void OnCaptureFailure();
54
55 private:
56  // Size of frame we want to receive.
57  int frame_width_;
58  int frame_height_;
59
60  // Object that handles video capturing.
61  scoped_refptr<Camera> camera_;
62
63  // Counts how many times in a row capture failed.
64  int capture_failure_counter_;
65
66  // Counts how many times camera initialization failed.
67  int camera_init_failure_counter_;
68
69  // Thread for camera to work on.
70  scoped_ptr<base::Thread> camera_thread_;
71
72  Delegate* delegate_;
73
74  DISALLOW_COPY_AND_ASSIGN(CameraController);
75};
76
77}  // namespace chromeos
78
79#endif  // CHROME_BROWSER_CHROMEOS_LOGIN_CAMERA_CONTROLLER_H_
80
81