summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoravayvod@chromium.org <avayvod@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-15 14:52:55 +0000
committeravayvod@chromium.org <avayvod@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-15 14:52:55 +0000
commite4e7376ab3b4a03c326db14ab54ea5621b771738 (patch)
tree609c9f598bd5b5fe383d4c70bfb70c5d2a0ea343
parent8855d1a0c691c4fbd0a84537e91353dab2f9772a (diff)
downloadchromium_src-e4e7376ab3b4a03c326db14ab54ea5621b771738.zip
chromium_src-e4e7376ab3b4a03c326db14ab54ea5621b771738.tar.gz
chromium_src-e4e7376ab3b4a03c326db14ab54ea5621b771738.tar.bz2
[cros] Stopping camera when reinit. Opening /dev/video%d instead of /dev/video0
BUG=chromiumos:16048 TEST=On image screen while taking picture close the lid and open it again. Chrome must not crash, camera should reinitialize. Review URL: http://codereview.chromium.org/7148013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89185 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/login/camera.cc20
-rw-r--r--chrome/browser/chromeos/login/camera_controller.cc29
2 files changed, 30 insertions, 19 deletions
diff --git a/chrome/browser/chromeos/login/camera.cc b/chrome/browser/chromeos/login/camera.cc
index 475b79f..cedf158 100644
--- a/chrome/browser/chromeos/login/camera.cc
+++ b/chrome/browser/chromeos/login/camera.cc
@@ -113,7 +113,9 @@ gfx::Size get_best_frame_size(int fd,
}
// Default camera device name.
-const char kDeviceName[] = "/dev/video0";
+const char kDeviceNameFormat[] = "/dev/video%d";
+// Number of times we retry initializing camera with different device index.
+const int kOpenDeviceRetries = 10;
// Default width of each frame received from the camera.
const int kFrameWidth = 640;
// Default height of each frame received from the camera.
@@ -131,7 +133,6 @@ const long kSelectTimeout = 1 * base::Time::kMicrosecondsPerSecond;
Camera::Camera(Delegate* delegate, base::Thread* thread, bool mirrored)
: delegate_(delegate),
thread_(thread),
- device_name_(kDeviceName),
device_descriptor_(-1),
is_capturing_(false),
desired_width_(kFrameWidth),
@@ -142,6 +143,7 @@ Camera::Camera(Delegate* delegate, base::Thread* thread, bool mirrored)
}
Camera::~Camera() {
+ Uninitialize();
DCHECK_EQ(-1, device_descriptor_) << "Don't forget to uninitialize camera.";
}
@@ -186,7 +188,15 @@ void Camera::DoInitialize(int desired_width, int desired_height) {
return;
}
- int fd = OpenDevice(device_name_.c_str());
+ int fd = -1;
+ for (int i = 0; i < kOpenDeviceRetries; ++i) {
+ device_name_ = StringPrintf(kDeviceNameFormat, i);
+ fd = OpenDevice(device_name_.c_str());
+ if (fd != -1)
+ break;
+ LOG(WARNING) << "Failed to open device: " << device_name_;
+ }
+
if (fd == -1) {
ReportFailure();
return;
@@ -223,7 +233,7 @@ void Camera::DoInitialize(int desired_width, int desired_height) {
format.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
format.fmt.pix.field = V4L2_FIELD_INTERLACED;
if (xioctl(fd, VIDIOC_S_FMT, &format) == -1) {
- LOG(ERROR) << "VIDIOC_S_FMT failed.";
+ log_errno("VIDIOC_S_FMT failed.");
ReportFailure();
return;
}
@@ -335,7 +345,7 @@ int Camera::OpenDevice(const char* device_name) const {
DCHECK(IsOnCameraThread());
struct stat st;
if (stat(device_name, &st) == -1) {
- log_errno(base::StringPrintf("Cannot identify %s", device_name));
+ log_errno(base::StringPrintf("Cannot find %s", device_name));
return -1;
}
if (!S_ISCHR(st.st_mode)) {
diff --git a/chrome/browser/chromeos/login/camera_controller.cc b/chrome/browser/chromeos/login/camera_controller.cc
index 2f3e12e..9985df0 100644
--- a/chrome/browser/chromeos/login/camera_controller.cc
+++ b/chrome/browser/chromeos/login/camera_controller.cc
@@ -28,32 +28,33 @@ CameraController::CameraController(Delegate* delegate)
frame_height_(0),
capture_failure_counter_(0),
camera_init_failure_counter_(0),
- camera_thread_(new base::Thread(kCameraThreadName)),
delegate_(delegate) {
- camera_thread_->Start();
}
CameraController::~CameraController() {
- if (camera_.get())
- camera_->set_delegate(NULL);
- {
- // A ScopedAllowIO object is required to join the thread when calling Stop.
- // See http://crosbug.com/11392.
- base::ThreadRestrictions::ScopedAllowIO allow_io_for_thread_join;
- camera_thread_.reset();
- }
+ Stop();
}
void CameraController::Start() {
+ Stop();
+ camera_thread_.reset(new base::Thread(kCameraThreadName));
+ camera_thread_->Start();
camera_ = new Camera(this, camera_thread_.get(), true);
camera_->Initialize(frame_width_, frame_height_);
}
void CameraController::Stop() {
- if (!camera_.get())
- return;
- camera_->StopCapturing();
- camera_->Uninitialize();
+ if (camera_.get()) {
+ camera_->set_delegate(NULL);
+ camera_->Uninitialize();
+ camera_ = NULL;
+ }
+ {
+ // A ScopedAllowIO object is required to join the thread when calling Stop.
+ // See http://crosbug.com/11392.
+ base::ThreadRestrictions::ScopedAllowIO allow_io_for_thread_join;
+ camera_thread_.reset();
+ }
}
void CameraController::GetFrame(SkBitmap* frame) const {