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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "media/video/capture/linux/video_capture_device_chromeos.h"
6
7 #include "base/bind.h"
8 #include "base/memory/ref_counted.h"
9 #include "ui/gfx/display.h"
10 #include "ui/gfx/display_observer.h"
11 #include "ui/gfx/screen.h"
12
13 namespace media {
14
15 // This is a delegate class used to transfer Display change events from the UI
16 // thread to the media thread.
17 class VideoCaptureDeviceChromeOS::ScreenObserverDelegate
18 : public gfx::DisplayObserver,
19 public base::RefCountedThreadSafe<ScreenObserverDelegate> {
20 public:
21 ScreenObserverDelegate(VideoCaptureDeviceChromeOS* capture_device)
22 : capture_device_(capture_device),
23 capture_thread_loop_(base::MessageLoop::current()) {
24 base::MessageLoopForUI::current()->PostTask(
25 FROM_HERE,
26 base::Bind(&ScreenObserverDelegate::AddObserverOnUIThread, this));
27 }
28
29 void RemoveObserver() {
perkj_chrome 2014/05/12 07:57:13 add thread check
Zachary Kuznia 2014/05/12 08:56:22 Done.
30 capture_device_ = NULL;
31 base::MessageLoopForUI::current()->PostTask(
32 FROM_HERE,
33 base::Bind(&ScreenObserverDelegate::RemoveObserverOnUIThread, this));
34 }
35
36 private:
37 friend class base::RefCountedThreadSafe<ScreenObserverDelegate>;
38
39 virtual ~ScreenObserverDelegate() {
40 DCHECK(!capture_device_);
41 }
42
43 // gfx::DisplayObserver:
44 virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE {
45 SendDisplayRotation(display);
46 }
47
48 virtual void OnDisplayAdded(const gfx::Display& /*new_display*/) OVERRIDE {}
49 virtual void OnDisplayRemoved(const gfx::Display& /*old_display*/) OVERRIDE {}
50
51 void AddObserverOnUIThread() {
52 gfx::Screen* screen =
53 gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE);
54 if (screen) {
55 screen->AddObserver(this);
56 SendDisplayRotation(screen->GetPrimaryDisplay());
57 }
58 }
59
60 void RemoveObserverOnUIThread() {
61 gfx::Screen* screen =
62 gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE);
63 if (screen)
64 screen->RemoveObserver(this);
65 }
66
67 void SendDisplayRotation(const gfx::Display& display) {
68 capture_thread_loop_->PostTask(
69 FROM_HERE,
70 base::Bind(&ScreenObserverDelegate::SendDisplayRotationOnCaptureThread,
71 this, display));
72 }
73
74 void SendDisplayRotationOnCaptureThread(const gfx::Display& display) {
75 capture_device_->SetDisplayRotation(display);
perkj_chrome 2014/05/12 07:57:13 add thread check
Zachary Kuznia 2014/05/12 08:56:22 Done.
76 }
77
78 VideoCaptureDeviceChromeOS* capture_device_;
79 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
80 DISALLOW_IMPLICIT_CONSTRUCTORS(ScreenObserverDelegate);
81 };
82
83
84 VideoCaptureDeviceChromeOS::VideoCaptureDeviceChromeOS(const Name& device_name)
85 : VideoCaptureDeviceLinux(device_name),
86 screen_observer_delegate_(new ScreenObserverDelegate(this)) {
87 }
88
89 VideoCaptureDeviceChromeOS::~VideoCaptureDeviceChromeOS() {
90 }
91
92 void VideoCaptureDeviceChromeOS::SetDisplayRotation(
93 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.
94 if (display.IsInternal())
95 SetRotation(display.rotation() * 90);
96 }
97
98 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698