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

Side by Side Diff: content/browser/media_stream/video_capture_manager.h

Issue 6946001: VideoCaptureManager opens/closes, starts/stops and enumerates video capture devices. VideoCapture... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 9 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 (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 // VideoCaptureManager is used to open/close, start/stop as well as enumerate
6 // available video capture devices. All functions are expected to be called from
7 // the Browser::IO thread. VideoCaptureManager will open OS dependent instances
8 // of VideoCaptureDevice. A device can only be opened once.
9
10 #ifndef CONTENT_BROWSER_MEDIA_STREAM_VIDEO_CAPTURE_MANAGER_H_
11 #define CONTENT_BROWSER_MEDIA_STREAM_VIDEO_CAPTURE_MANAGER_H_
12 #pragma once
wjia(left Chromium) 2011/05/06 00:11:31 pragma is not needed.
mflodman1 2011/05/06 11:52:38 Done.
13
14 // TODO(mflodman) Use device type instead of int!
15 #include <map>
16
17 #include "base/lazy_instance.h"
18 #include "base/threading/thread.h"
19 #include "content/browser/media_stream/media_stream_provider.h"
20 #include "media/video/capture/video_capture_types.h"
21 #include "media/video/capture/video_capture_device.h"
mflodman1 2011/05/05 11:11:22 Will change include order or _types.h and device.h
mflodman1 2011/05/06 11:52:38 Done.
22
23 namespace media_stream {
24
25 class VideoCaptureManager
26 : public MediaStreamProvider {
27 public:
28 // Calling Start of this id will open the first device, even though open has
29 // not been called. Temporary(?) before MediaStreamManager is submitted.
wjia(left Chromium) 2011/05/06 00:11:31 Will this enum stay even after MediaStreamManager
mflodman1 2011/05/06 11:52:38 Comment updated, removed last part. I don't know.
30 enum { kStartOpenSessionId = 0 };
31
32 // Called to get a pointer to the singleton
33 static VideoCaptureManager* Get();
34
35 // Implements MediaStreamProvider:
36 // Register, Unregister, Open, Close, EnumerateDevices
wjia(left Chromium) 2011/05/06 00:11:31 no need to have comments for each function. These
mflodman1 2011/05/06 11:52:38 Done.
37 // Registers a listener to get results from Open, Close and EnumerateDevices.
38 virtual int Register(MediaStreamType service_type,
wjia(left Chromium) 2011/05/06 00:11:31 what's the meaning of returned value? If there are
mflodman1 2011/05/06 11:52:38 Done.
39 MediaStreamProviderListener* listener);
40 virtual void Unregister(MediaStreamType stream_type,
41 MediaStreamProviderListener* listener);
42
43 // Enumerates existing video capture devices and calls the registered
44 // listener.
45 virtual void EnumerateDevices(MediaStreamType stream_type);
46
47 // Opens the specified device. The device is not started and it is still
48 // possible for other applications to open the device before the device is
49 // started.
50 virtual MediaCaptureSessionId Open(MediaStreamType stream_type,
51 const MediaCaptureDeviceInfo& device);
52 virtual void Close(MediaStreamType stream_type,
53 MediaCaptureSessionId capture_session_id);
wjia(left Chromium) 2011/05/06 00:11:31 How many modules will call Open/Close? If there ar
mflodman1 2011/05/06 11:52:38 Only one module will call Open/Close, only one lis
54
55 // Functions used to start and stop media flow.
56 // Start allocates the device and no other application can use the device
57 // before Stop is called.
58 void Start(const media::VideoCaptureParams& capture_params,
59 media::VideoCaptureDevice::EventHandler* video_capture_receiver);
60
61 // 'stopped_task' will be called when a device has been stopped and no more
wjia(left Chromium) 2011/05/06 00:11:31 would it good to rephrase this to: Stop device cap
mflodman1 2011/05/06 11:52:38 Comment updated.
62 // frames will be delivered to the frame receiver.
63 void Stop(const media::VideoCaptureSessionId capture_session_id,
64 Task* stopped_task);
65
66 virtual ~VideoCaptureManager();
67
68 // Used for unit test to make sure a fake device is used instead of a real
69 // video capture device, due to time requirements.
70 static void CreateTestManager();
71 MessageLoop* GetMessageLoop();
72
73 protected:
74 // Used for testing to mock platform dependent device code.
75 void UseFakeDevice();
76 static bool use_fake_device_;
77
78 private:
79 friend struct base::DefaultLazyInstanceTraits<VideoCaptureManager>;
80
81 VideoCaptureManager();
82
83 // Called by the public functions, executed on vc_device_thread_.
84 void OnEnumerateDevices();
85 void OnOpen(MediaCaptureSessionId capture_session_id,
86 const MediaCaptureDeviceInfo device);
87 void OnClose(MediaCaptureSessionId capture_session_id);
88 void OnStart(const media::VideoCaptureParams capture_params,
89 media::VideoCaptureDevice::EventHandler* video_capture_receiver);
90 void OnStop(const media::VideoCaptureSessionId capture_session_id,
91 Task* stopped_task);
92
93
94 // Executed on Browser::IO thread to call Listener.
95 void OnOpened(MediaCaptureSessionId capture_session_id);
96 void OnClosed(MediaCaptureSessionId capture_session_id);
97 void OnDevicesEnumerated(const MediaCaptureDevices& devices);
98 void OnError(MediaCaptureSessionId capture_session_id,
99 MediaStreamProviderError error);
100
101 // Executed on vc_device_thread_ to make sure Listener is called from
102 // Browser::IO thread.
103 void PostOnOpened(MediaCaptureSessionId capture_session_id);
104 void PostOnClosed(MediaCaptureSessionId capture_session_id);
105 void PostOnDevicesEnumerated(
106 const MediaCaptureDevices& devices);
107 void PostOnError(MediaCaptureSessionId capture_session_id,
108 MediaStreamProviderError error);
109
110 // Called on Browser::IO thread, forwarders to the singleton methods.
111 // Required to avoid the ownership of the manager object to be managed by both
112 // RefCountedThreadSafe and LazyInstance.
113 static void OnOpenedProxy(MediaCaptureSessionId capture_session_id);
114 static void OnClosedProxy(MediaCaptureSessionId capture_session_id);
115 static void OnDevicesEnumeratedProxy(const MediaCaptureDevices devices);
116 static void OnErrorProxy(MediaCaptureSessionId capture_session_id,
117 MediaStreamProviderError error);
118
119 // Helpers
120 void GetAvailableDevices(media::VideoCaptureDevice::Names* device_names);
121 bool DeviceOpened(const media::VideoCaptureDevice::Name& device_name);
122 bool IsOnCaptureDeviceThread() const;
123
124 // Thread for all calls to VideoCaptureDevice
125 base::Thread vc_device_thread_;
126
127 // Only accessed on IO thread
128 MediaStreamProviderListener* listener_;
129 MediaCaptureSessionId new_capture_session_id_;
130
131 // Only accessed from vc_device_thread_
132 typedef std::map<int, media::VideoCaptureDevice*> VideoCaptureDevices;
133 VideoCaptureDevices devices_;
134
135 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager);
136 };
137
138 } // namespace media_stream
139
140 DISABLE_RUNNABLE_METHOD_REFCOUNT(media_stream::VideoCaptureManager);
141
142 #endif // CONTENT_BROWSER_MEDIA_STREAM_VIDEO_CAPTURE_MANAGER_H_
mflodman1 2011/05/05 11:11:22 Will add newline in next upload.
mflodman1 2011/05/06 11:52:38 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698