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

Unified Diff: media/video/capture/linux/video_capture_device_chromeos.cc

Issue 270263008: Add a ChromeOS implementation of VideoCaptureDevice (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code review fixes Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: media/video/capture/linux/video_capture_device_chromeos.cc
diff --git a/media/video/capture/linux/video_capture_device_chromeos.cc b/media/video/capture/linux/video_capture_device_chromeos.cc
new file mode 100644
index 0000000000000000000000000000000000000000..86b0f22a3439e2ccd77f4371f6279d097e5ca704
--- /dev/null
+++ b/media/video/capture/linux/video_capture_device_chromeos.cc
@@ -0,0 +1,98 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/video/capture/linux/video_capture_device_chromeos.h"
+
+#include "base/bind.h"
+#include "base/memory/ref_counted.h"
+#include "ui/gfx/display.h"
+#include "ui/gfx/display_observer.h"
+#include "ui/gfx/screen.h"
+
+namespace media {
+
+// This is a delegate class used to transfer Display change events from the UI
+// thread to the media thread.
+class VideoCaptureDeviceChromeOS::ScreenObserverDelegate
+ : public gfx::DisplayObserver,
+ public base::RefCountedThreadSafe<ScreenObserverDelegate> {
+ public:
+ ScreenObserverDelegate(VideoCaptureDeviceChromeOS* capture_device)
+ : capture_device_(capture_device),
+ capture_thread_loop_(base::MessageLoop::current()) {
+ base::MessageLoopForUI::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&ScreenObserverDelegate::AddObserverOnUIThread, this));
+ }
+
+ void RemoveObserver() {
perkj_chrome 2014/05/12 07:57:13 add thread check
Zachary Kuznia 2014/05/12 08:56:22 Done.
+ capture_device_ = NULL;
+ base::MessageLoopForUI::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&ScreenObserverDelegate::RemoveObserverOnUIThread, this));
+ }
+
+ private:
+ friend class base::RefCountedThreadSafe<ScreenObserverDelegate>;
+
+ virtual ~ScreenObserverDelegate() {
+ DCHECK(!capture_device_);
+ }
+
+ // gfx::DisplayObserver:
+ virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE {
+ SendDisplayRotation(display);
+ }
+
+ virtual void OnDisplayAdded(const gfx::Display& /*new_display*/) OVERRIDE {}
+ virtual void OnDisplayRemoved(const gfx::Display& /*old_display*/) OVERRIDE {}
+
+ void AddObserverOnUIThread() {
+ gfx::Screen* screen =
+ gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE);
+ if (screen) {
+ screen->AddObserver(this);
+ SendDisplayRotation(screen->GetPrimaryDisplay());
+ }
+ }
+
+ void RemoveObserverOnUIThread() {
+ gfx::Screen* screen =
+ gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE);
+ if (screen)
+ screen->RemoveObserver(this);
+ }
+
+ void SendDisplayRotation(const gfx::Display& display) {
+ capture_thread_loop_->PostTask(
+ FROM_HERE,
+ base::Bind(&ScreenObserverDelegate::SendDisplayRotationOnCaptureThread,
+ this, display));
+ }
+
+ void SendDisplayRotationOnCaptureThread(const gfx::Display& display) {
+ capture_device_->SetDisplayRotation(display);
perkj_chrome 2014/05/12 07:57:13 add thread check
Zachary Kuznia 2014/05/12 08:56:22 Done.
+ }
+
+ VideoCaptureDeviceChromeOS* capture_device_;
+ base::MessageLoop* capture_thread_loop_;
perkj_chrome 2014/05/12 07:57:13 scoped_refptr<MessageLoopProxy> capture_thread_loo
Zachary Kuznia 2014/05/12 08:56:22 Unfortunately, MessageLoopProxy is not threadsafe,
perkj_chrome 2014/05/13 09:46:40 but if you set it in ctor and and only use it on t
+ DISALLOW_IMPLICIT_CONSTRUCTORS(ScreenObserverDelegate);
+};
+
+
+VideoCaptureDeviceChromeOS::VideoCaptureDeviceChromeOS(const Name& device_name)
+ : VideoCaptureDeviceLinux(device_name),
+ screen_observer_delegate_(new ScreenObserverDelegate(this)) {
+}
+
+VideoCaptureDeviceChromeOS::~VideoCaptureDeviceChromeOS() {
+}
+
+void VideoCaptureDeviceChromeOS::SetDisplayRotation(
+ const gfx::Display& display) {
perkj_chrome 2014/05/12 07:57:13 nit: Fits on line above?
Zachary Kuznia 2014/05/12 08:56:22 2 characters too long.
+ if (display.IsInternal())
+ SetRotation(display.rotation() * 90);
+}
+
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698