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

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: Fix a nit 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/screen.h"
11
12 namespace media {
13
14 // This is a delegate class used to transfer Display change events from the UI
15 // thread to the media thread.
16 class VideoCaptureDeviceChromeOS::ScreenObserverDelegate
17 : public gfx::DisplayObserver,
18 public base::RefCountedThreadSafe<ScreenObserverDelegate> {
19 public:
20 ScreenObserverDelegate(VideoCaptureDeviceChromeOS* capture_device)
21 : capture_device_(capture_device),
22 media_message_loop_(base::MessageLoop::current()) {
23 base::MessageLoopForUI::current()->PostTask(
24 FROM_HERE,
25 base::Bind(&ScreenObserverDelegate::AddObserverOnUIThread, this));
26 }
27
28 ~ScreenObserverDelegate() {
29 DCHECK(!capture_device_);
30 }
31
32 void RemoveObserver() {
33 capture_device_ = NULL;
34 base::MessageLoopForUI::current()->PostTask(
35 FROM_HERE,
36 base::Bind(&ScreenObserverDelegate::RemoveObserverOnUIThread, this));
37 }
38
39 private:
40 friend class base::RefCountedThreadSafe<ScreenObserverDelegate>;
mcasas 2014/05/11 18:41:25 According to base/memory/ref_counted.h, if you use
Zachary Kuznia 2014/05/12 02:54:18 Done.
41
42 // gfx::DisplayObserver:
43 virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE {
44 SendDisplayRotation(display);
45 }
46
47 virtual void OnDisplayAdded(const gfx::Display& /*new_display*/) OVERRIDE {}
48 virtual void OnDisplayRemoved(const gfx::Display& /*old_display*/) OVERRIDE {}
mcasas 2014/05/11 18:41:25 Shouldn't these 3 methods from gfx::DisplayObserve
Zachary Kuznia 2014/05/12 02:54:18 This is a controversial topic. See: https://group
49
50 void AddObserverOnUIThread() {
51 gfx::Screen* screen =
52 gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE);
mcasas 2014/05/11 18:41:25 Why not gfx::SCREEN_TYPE_NATIVE?
Zachary Kuznia 2014/05/12 02:54:18 Because this is the pattern established in ash/she
53 if (screen) {
54 screen->AddObserver(this);
55 SendDisplayRotation(screen->GetPrimaryDisplay());
56 }
57 }
58
59 void RemoveObserverOnUIThread() {
60 gfx::Screen* screen =
61 gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE);
62 if (screen)
63 screen->RemoveObserver(this);
64 }
65
66 void SendDisplayRotation(const gfx::Display& display) {
67 media_message_loop_->PostTask(
68 FROM_HERE,
69 base::Bind(&ScreenObserverDelegate::SendDisplayRotationOnMediaThread,
70 this, display));
71 }
72
73 void SendDisplayRotationOnMediaThread(const gfx::Display& display) {
74 capture_device_->SetDisplayRotation(display);
75 }
76
77 VideoCaptureDeviceChromeOS* capture_device_;
mcasas 2014/05/11 18:41:25 Ugh naked pointer. Maybe const?
Zachary Kuznia 2014/05/12 02:54:18 Unfortunately, that would require marking rotation
78 base::MessageLoop* media_message_loop_;
mcasas 2014/05/11 18:41:25 const? ultra-nit: would you mind terribly calling
Zachary Kuznia 2014/05/12 02:54:18 Nits Done. The MessageLoop pointer can't be const
79 DISALLOW_IMPLICIT_CONSTRUCTORS(ScreenObserverDelegate);
80 };
81
82
83 VideoCaptureDeviceChromeOS::VideoCaptureDeviceChromeOS(const Name& device_name)
84 : VideoCaptureDeviceLinux(device_name),
85 screen_observer_delegate_(new ScreenObserverDelegate(this)) {
86 }
87
88 VideoCaptureDeviceChromeOS::~VideoCaptureDeviceChromeOS() {
89
mcasas 2014/05/11 18:41:25 nit: no empty line.
Zachary Kuznia 2014/05/12 02:54:18 Done.
90 }
91
92 void VideoCaptureDeviceChromeOS::SetDisplayRotation(
93 const gfx::Display& display) {
94 if (display.IsInternal())
95 SetRotation(display.rotation() * 90);
96 }
97
98 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698