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

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,
perkj_chrome 2014/05/13 09:46:40 nit: indentation
Zachary Kuznia 2014/05/13 13:54:29 Done.
26 base::Bind(&ScreenObserverDelegate::AddObserverOnUIThread, this));
27 }
28
29 void RemoveObserver() {
30 DCHECK(capture_thread_loop_ == base::MessageLoop::current());
31 capture_device_ = NULL;
32 base::MessageLoopForUI::current()->PostTask(
33 FROM_HERE,
34 base::Bind(&ScreenObserverDelegate::RemoveObserverOnUIThread, this));
35 }
36
37 private:
38 friend class base::RefCountedThreadSafe<ScreenObserverDelegate>;
39
40 virtual ~ScreenObserverDelegate() {
41 DCHECK(!capture_device_);
42 }
43
44 // gfx::DisplayObserver:
45 virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE {
46 SendDisplayRotation(display);
47 }
48
49 virtual void OnDisplayAdded(const gfx::Display& /*new_display*/) OVERRIDE {}
perkj_chrome 2014/05/13 09:46:40 style nit - name all arguments even if they are no
Zachary Kuznia 2014/05/13 13:54:29 See: http://google-styleguide.googlecode.com/svn/t
50 virtual void OnDisplayRemoved(const gfx::Display& /*old_display*/) OVERRIDE {}
51
52 void AddObserverOnUIThread() {
tommi (sloooow) - chröme 2014/05/13 11:02:51 nit: add a dcheck that we're indeed on the ui thre
Zachary Kuznia 2014/05/13 13:54:29 Done.
53 gfx::Screen* screen =
54 gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE);
55 if (screen) {
56 screen->AddObserver(this);
57 SendDisplayRotation(screen->GetPrimaryDisplay());
58 }
59 }
60
61 void RemoveObserverOnUIThread() {
62 gfx::Screen* screen =
tommi (sloooow) - chröme 2014/05/13 11:02:51 dcheck
Zachary Kuznia 2014/05/13 13:54:29 Done.
63 gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE);
64 if (screen)
65 screen->RemoveObserver(this);
66 }
67
68 void SendDisplayRotation(const gfx::Display& display) {
69 capture_thread_loop_->PostTask(
perkj_chrome 2014/05/13 09:46:40 Can you add thread check here as well.
Zachary Kuznia 2014/05/13 13:54:29 Done.
70 FROM_HERE,
perkj_chrome 2014/05/13 09:46:40 nit: intendation
Zachary Kuznia 2014/05/13 13:54:29 Done.
71 base::Bind(&ScreenObserverDelegate::SendDisplayRotationOnCaptureThread,
72 this, display));
73 }
74
75 void SendDisplayRotationOnCaptureThread(const gfx::Display& display) {
76 DCHECK(capture_thread_loop_ == base::MessageLoop::current());
77 capture_device_->SetDisplayRotation(display);
78 }
79
perkj_chrome 2014/05/13 09:46:40 Can you add a threadchecker and verify that you ar
Zachary Kuznia 2014/05/13 13:54:29 I don't think a threadchecker would be useful, bec
80 VideoCaptureDeviceChromeOS* capture_device_;
81 base::MessageLoop* capture_thread_loop_;
tommi (sloooow) - chröme 2014/05/13 11:02:51 if you use this variable on a thread other than th
Zachary Kuznia 2014/05/13 13:54:29 I actually used a MessageLoopProxy initially, but
tommi (sloooow) - chröme 2014/05/13 14:35:17 Ah, I'm guessing this is the error you ran into: h
82 DISALLOW_IMPLICIT_CONSTRUCTORS(ScreenObserverDelegate);
83 };
84
85
86 VideoCaptureDeviceChromeOS::VideoCaptureDeviceChromeOS(const Name& device_name)
87 : VideoCaptureDeviceLinux(device_name),
88 screen_observer_delegate_(new ScreenObserverDelegate(this)) {
89 }
90
91 VideoCaptureDeviceChromeOS::~VideoCaptureDeviceChromeOS() {
92 }
93
94 void VideoCaptureDeviceChromeOS::SetDisplayRotation(
95 const gfx::Display& display) {
96 if (display.IsInternal())
97 SetRotation(display.rotation() * 90);
98 }
99
100 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698