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

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: VideoCaptureManager.cc error check changes 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
13 #include <map>
14
15 #include "base/lazy_instance.h"
16 #include "base/threading/thread.h"
17 #include "content/browser/media_stream/media_stream_provider.h"
18 #include "media/video/capture/video_capture_device.h"
19 #include "media/video/capture/video_capture_types.h"
20
21 namespace media_stream {
22
23 class VideoCaptureManager
John Knottenbelt 2011/05/11 11:36:35 Please provide a class level comment describing th
mflodman1 2011/05/15 20:24:00 I wrote a description at the top of this file. Do
24 : public MediaStreamProvider {
John Knottenbelt 2011/05/11 11:36:35 Join with the previous line.
mflodman1 2011/05/15 20:24:00 Done.
25 public:
26 // Calling Start of this id will open the first device, even though open has
27 // not been called.
28 enum { kStartOpenSessionId = 1 };
29
30 // Called to get a pointer to the singleton
31 static VideoCaptureManager* Get();
32
33 // Implements MediaStreamProvider.
34 virtual bool Register(MediaStreamType service_type,
35 MediaStreamProviderListener* listener);
36
37 virtual void Unregister(MediaStreamType stream_type,
38 MediaStreamProviderListener* listener);
39
40 virtual void EnumerateDevices(MediaStreamType stream_type);
41
42 virtual MediaCaptureSessionId Open(MediaStreamType stream_type,
43 const MediaCaptureDeviceInfo& device);
44 virtual void Close(MediaStreamType stream_type,
45 MediaCaptureSessionId capture_session_id);
46
47 // Functions used to start and stop media flow.
48 // Start allocates the device and no other application can use the device
49 // before Stop is called.
50 void Start(const media::VideoCaptureParams& capture_params,
John Knottenbelt 2011/05/11 11:36:35 Question: Can the VideoCaptureSessionId specified
mflodman1 2011/05/15 20:24:00 Yes. kStartOpenSessionId will only be used when Me
51 media::VideoCaptureDevice::EventHandler* video_capture_receiver);
52
53 // Stops capture device referenced by |capture_session_id|. No more frames
54 // will be delivered to the frame receiver, and |stopped_task| will be called.
55 void Stop(const media::VideoCaptureSessionId capture_session_id,
56 Task* stopped_task);
57
58 virtual ~VideoCaptureManager();
59
60 // Used by unit test to make sure a fake device is used instead of a real
61 // video capture device, due to time requirements. The function must be called
John Knottenbelt 2011/05/11 11:36:35 Nit: device, due => device. Due time => timing re
mflodman1 2011/05/15 20:24:00 Done.
62 // before EnumerateDevices and Open.
63 static void CreateTestManager();
John Knottenbelt 2011/05/11 11:36:35 Nit: Move to just below static VideoCaptureManager
mflodman1 2011/05/15 20:24:00 Done.
64 MessageLoop* GetMessageLoop();
65
66 protected:
67 // Used for testing to mock platform dependent device code.
John Knottenbelt 2011/05/11 11:36:35 Nit: to => with
mflodman1 2011/05/15 20:24:00 Done.
68 void UseFakeDevice();
69 static bool use_fake_device_;
70
71 private:
72 friend struct base::DefaultLazyInstanceTraits<VideoCaptureManager>;
73
74 VideoCaptureManager();
75
76 // Called by the public functions, executed on vc_device_thread_.
77 void OnEnumerateDevices();
78 void OnOpen(MediaCaptureSessionId capture_session_id,
79 const MediaCaptureDeviceInfo device);
80 void OnClose(MediaCaptureSessionId capture_session_id);
81 void OnStart(const media::VideoCaptureParams capture_params,
82 media::VideoCaptureDevice::EventHandler* video_capture_receiver);
83 void OnStop(const media::VideoCaptureSessionId capture_session_id,
84 Task* stopped_task);
85
86
87 // Executed on Browser::IO thread to call Listener.
88 void OnOpened(MediaCaptureSessionId capture_session_id);
89 void OnClosed(MediaCaptureSessionId capture_session_id);
90 void OnDevicesEnumerated(const MediaCaptureDevices& devices);
91 void OnError(MediaCaptureSessionId capture_session_id,
92 MediaStreamProviderError error);
93
94 // Executed on vc_device_thread_ to make sure Listener is called from
95 // Browser::IO thread.
96 void PostOnOpened(MediaCaptureSessionId capture_session_id);
97 void PostOnClosed(MediaCaptureSessionId capture_session_id);
98 void PostOnDevicesEnumerated(MediaCaptureDevices devices);
99 void PostOnError(MediaCaptureSessionId capture_session_id,
100 MediaStreamProviderError error);
101
102 // Helpers
103 void GetAvailableDevices(media::VideoCaptureDevice::Names* device_names);
104 bool DeviceOpened(const media::VideoCaptureDevice::Name& device_name);
105 bool DeviceOpened(const MediaCaptureDeviceInfo& device_info);
106 bool IsOnCaptureDeviceThread() const;
107
108 // Thread for all calls to VideoCaptureDevice
109 base::Thread vc_device_thread_;
110
111 // Only accessed on IO thread
John Knottenbelt 2011/05/11 11:36:35 Nit: IO => Browser::IO (for consistency with above
mflodman1 2011/05/15 20:24:00 Done.
112 MediaStreamProviderListener* listener_;
113 MediaCaptureSessionId new_capture_session_id_;
114
115 // Only accessed from vc_device_thread_
116 typedef std::map<int, media::VideoCaptureDevice*> VideoCaptureDevices;
John Knottenbelt 2011/05/11 11:36:35 Question: Could we use MediaCaptureSessionId inste
mflodman1 2011/05/15 20:24:00 I've added a TODO(mflodman) for changing key type
117 VideoCaptureDevices devices_;
118
119 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager);
120 };
121
122 } // namespace media_stream
123
124 DISABLE_RUNNABLE_METHOD_REFCOUNT(media_stream::VideoCaptureManager);
125
126 #endif // CONTENT_BROWSER_MEDIA_STREAM_VIDEO_CAPTURE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698