|
OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 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 #ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ | |
6 #define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ | |
7 | |
8 #include <list> | |
9 #include <map> | |
10 | |
11 #include "base/message_loop_proxy.h" | |
12 #include "base/synchronization/lock.h" | |
13 #include "content/renderer/video_capture_message_filter.h" | |
14 #include "media/base/callback.h" | |
15 #include "media/base/message_loop_factory.h" | |
16 #include "media/video/capture/video_capture.h" | |
17 #include "ui/gfx/surface/transport_dib.h" | |
18 | |
19 class VideoCaptureImpl | |
scherkus (not reviewing)
2011/05/14 23:33:42
class level comment
wjia(left Chromium)
2011/05/17 04:00:25
Done.
| |
20 : public media::VideoCapture, | |
21 public VideoCaptureMessageFilter::Delegate { | |
22 private: | |
scherkus (not reviewing)
2011/05/14 23:33:42
nit: public section goes first
wjia(left Chromium)
2011/05/17 04:00:25
Done.
| |
23 enum State { | |
24 kStarted, | |
25 kStopping, | |
26 kStopped | |
27 }; | |
28 | |
29 struct DIBBuffer { | |
30 public: | |
31 DIBBuffer() {} | |
scherkus (not reviewing)
2011/05/14 23:33:42
do you need a default ctor?
otherwise it seems we
wjia(left Chromium)
2011/05/17 04:00:25
default ctor is removed.
On 2011/05/14 23:33:42,
| |
32 DIBBuffer(TransportDIB* d, media::VideoCapture::VideoFrameBuffer* ptr) | |
scherkus (not reviewing)
2011/05/14 23:33:42
please de-inline the ctor/dtor since this class co
wjia(left Chromium)
2011/05/17 04:00:25
Done.
| |
33 : dib(d), | |
34 mapped_memory(ptr) { | |
35 } | |
36 ~DIBBuffer() { | |
37 delete dib; | |
38 } | |
39 | |
40 TransportDIB* dib; | |
41 scoped_refptr<media::VideoCapture::VideoFrameBuffer> mapped_memory; | |
42 }; | |
43 typedef std::list<DIBBuffer*> CachedDIB; | |
scherkus (not reviewing)
2011/05/14 23:33:42
nit: I'd move this typedef down to where you decla
wjia(left Chromium)
2011/05/17 04:00:25
Done.
| |
44 | |
45 typedef std::map<media::VideoCapture::EventHandler*, VideoCaptureCapability> | |
scherkus (not reviewing)
2011/05/14 23:33:42
ditto
wjia(left Chromium)
2011/05/17 04:00:25
Done.
| |
46 ClientInfo; | |
47 | |
48 public: | |
49 // media::VideoCapture interface | |
scherkus (not reviewing)
2011/05/14 23:33:42
add period
wjia(left Chromium)
2011/05/17 04:00:25
Done.
| |
50 virtual void StartCapture(media::VideoCapture::EventHandler* handler, | |
51 const VideoCaptureCapability& capability); | |
52 virtual void StopCapture(media::VideoCapture::EventHandler* handler); | |
53 virtual bool CaptureStarted() { return state_ == kStarted; } | |
54 virtual int CaptureWidth() { return width_; } | |
55 virtual int CaptureHeight() { return height_; } | |
56 virtual int CaptureFrameRate() { return frame_rate_; } | |
scherkus (not reviewing)
2011/05/14 23:33:42
please de-inline all of these methods
virtual met
wjia(left Chromium)
2011/05/17 04:00:25
Done.
| |
57 | |
58 // VideoCaptureMessageFilter::Delegate interface | |
scherkus (not reviewing)
2011/05/14 23:33:42
add period
wjia(left Chromium)
2011/05/17 04:00:25
Done.
| |
59 virtual void OnBufferReceived(TransportDIB::Handle handle, | |
60 base::Time timestamp); | |
61 virtual void OnStateChanged(const media::VideoCapture::State& state); | |
62 virtual void OnDeviceInfoReceived( | |
63 const media::VideoCaptureParams& device_info); | |
64 | |
65 bool pending_start() { | |
66 return (new_width_ > 0 && new_height_ > 0); | |
67 } | |
68 | |
69 protected: | |
scherkus (not reviewing)
2011/05/14 23:33:42
do you intend to further extend this class?
wjia(left Chromium)
2011/05/17 04:00:25
no. moved them to private.
| |
70 friend class VideoCaptureImplManager; | |
71 | |
72 VideoCaptureImpl(media::VideoCaptureSessionId id, | |
73 scoped_refptr<base::MessageLoopProxy> ml_proxy, | |
74 VideoCaptureMessageFilter* filter); | |
75 virtual ~VideoCaptureImpl(); | |
76 | |
77 private: | |
78 void Init(); | |
79 void DeInit(Task* task); | |
80 void StopDevice(); | |
81 void RestartCapture(); | |
82 void StartCaptureInternal(); | |
83 void AddDelegateOnIOThread(); | |
84 void RemoveDelegateOnIOThread(Task* task); | |
85 | |
86 scoped_refptr<VideoCaptureMessageFilter> filter_; | |
87 media::VideoCaptureSessionId session_id_; | |
88 scoped_refptr<base::MessageLoopProxy> ml_proxy_; | |
89 int device_id_; | |
90 | |
91 // Pool of DIBs. | |
92 CachedDIB cached_dibs_; | |
93 | |
94 ClientInfo clients_; | |
95 std::list<media::VideoCapture::EventHandler*> master_clients_; | |
96 | |
97 int width_; | |
98 int height_; | |
99 int frame_rate_; | |
100 media::VideoFrame::Format video_type_; | |
101 | |
102 int new_width_; | |
103 int new_height_; | |
104 State state_; | |
105 | |
106 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImpl); | |
107 }; | |
108 | |
109 DISABLE_RUNNABLE_METHOD_REFCOUNT(VideoCaptureImpl); | |
110 | |
111 class VideoCaptureImplManager { | |
scherkus (not reviewing)
2011/05/14 23:33:42
please move to separate file + class-level comment
wjia(left Chromium)
2011/05/17 04:00:25
Done.
| |
112 public: | |
113 VideoCaptureImplManager(); | |
114 virtual ~VideoCaptureImplManager() {} | |
115 | |
116 static media::VideoCapture* AddDevice( | |
117 media::VideoCaptureSessionId id, | |
118 media::VideoCapture::EventHandler* handler); | |
119 static void RemoveDevice(media::VideoCaptureSessionId id, | |
120 media::VideoCapture::EventHandler* handler); | |
121 | |
122 static VideoCaptureImplManager* GetInstance(); | |
123 | |
124 private: | |
125 struct Device { | |
126 Device() : vc(NULL) {} | |
scherkus (not reviewing)
2011/05/14 23:33:42
please de-inline ctor/dtor since struct contains n
wjia(left Chromium)
2011/05/17 04:00:25
Done.
| |
127 Device(VideoCaptureImpl* device, media::VideoCapture::EventHandler* handler) | |
128 : vc(device) { | |
129 clients.push_front(handler); | |
130 } | |
131 | |
132 VideoCaptureImpl* vc; | |
scherkus (not reviewing)
2011/05/14 23:33:42
sanity check: should Device own this pointer?
wjia(left Chromium)
2011/05/17 04:00:25
yes, vc is owned by Device, and essentially manage
| |
133 std::list<media::VideoCapture::EventHandler*> clients; | |
134 }; | |
135 typedef std::map<media::VideoCaptureSessionId, Device> Devices; | |
scherkus (not reviewing)
2011/05/14 23:33:42
nit: move to variable declaration
wjia(left Chromium)
2011/05/17 04:00:25
Done.
| |
136 | |
137 void FreeDevice(VideoCaptureImpl* vc); | |
138 | |
139 Devices devices_; | |
140 base::Lock lock_; | |
141 scoped_refptr<base::MessageLoopProxy> ml_proxy_; | |
142 scoped_ptr<media::MessageLoopFactory> ml_factory_; | |
143 }; | |
scherkus (not reviewing)
2011/05/14 23:33:42
DISALLOW_ etc....
wjia(left Chromium)
2011/05/17 04:00:25
Done.
| |
144 | |
145 DISABLE_RUNNABLE_METHOD_REFCOUNT(VideoCaptureImplManager); | |
146 | |
147 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ | |
OLD | NEW |