Chromium Code Reviews| Index: content/browser/media_stream/video_capture_manager.h |
| =================================================================== |
| --- content/browser/media_stream/video_capture_manager.h (revision 0) |
| +++ content/browser/media_stream/video_capture_manager.h (revision 0) |
| @@ -0,0 +1,142 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// VideoCaptureManager is used to open/close, start/stop as well as enumerate |
| +// available video capture devices. All functions are expected to be called from |
| +// the Browser::IO thread. VideoCaptureManager will open OS dependent instances |
| +// of VideoCaptureDevice. A device can only be opened once. |
| + |
| +#ifndef CONTENT_BROWSER_MEDIA_STREAM_VIDEO_CAPTURE_MANAGER_H_ |
| +#define CONTENT_BROWSER_MEDIA_STREAM_VIDEO_CAPTURE_MANAGER_H_ |
| +#pragma once |
|
wjia(left Chromium)
2011/05/06 00:11:31
pragma is not needed.
mflodman1
2011/05/06 11:52:38
Done.
|
| + |
| +// TODO(mflodman) Use device type instead of int! |
| +#include <map> |
| + |
| +#include "base/lazy_instance.h" |
| +#include "base/threading/thread.h" |
| +#include "content/browser/media_stream/media_stream_provider.h" |
| +#include "media/video/capture/video_capture_types.h" |
| +#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.
|
| + |
| +namespace media_stream { |
| + |
| +class VideoCaptureManager |
| + : public MediaStreamProvider { |
| + public: |
| + // Calling Start of this id will open the first device, even though open has |
| + // 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.
|
| + enum { kStartOpenSessionId = 0 }; |
| + |
| + // Called to get a pointer to the singleton |
| + static VideoCaptureManager* Get(); |
| + |
| + // Implements MediaStreamProvider: |
| + // 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.
|
| + // Registers a listener to get results from Open, Close and EnumerateDevices. |
| + 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.
|
| + MediaStreamProviderListener* listener); |
| + virtual void Unregister(MediaStreamType stream_type, |
| + MediaStreamProviderListener* listener); |
| + |
| + // Enumerates existing video capture devices and calls the registered |
| + // listener. |
| + virtual void EnumerateDevices(MediaStreamType stream_type); |
| + |
| + // Opens the specified device. The device is not started and it is still |
| + // possible for other applications to open the device before the device is |
| + // started. |
| + virtual MediaCaptureSessionId Open(MediaStreamType stream_type, |
| + const MediaCaptureDeviceInfo& device); |
| + virtual void Close(MediaStreamType stream_type, |
| + 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
|
| + |
| + // Functions used to start and stop media flow. |
| + // Start allocates the device and no other application can use the device |
| + // before Stop is called. |
| + void Start(const media::VideoCaptureParams& capture_params, |
| + media::VideoCaptureDevice::EventHandler* video_capture_receiver); |
| + |
| + // '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.
|
| + // frames will be delivered to the frame receiver. |
| + void Stop(const media::VideoCaptureSessionId capture_session_id, |
| + Task* stopped_task); |
| + |
| + virtual ~VideoCaptureManager(); |
| + |
| + // Used for unit test to make sure a fake device is used instead of a real |
| + // video capture device, due to time requirements. |
| + static void CreateTestManager(); |
| + MessageLoop* GetMessageLoop(); |
| + |
| + protected: |
| + // Used for testing to mock platform dependent device code. |
| + void UseFakeDevice(); |
| + static bool use_fake_device_; |
| + |
| + private: |
| + friend struct base::DefaultLazyInstanceTraits<VideoCaptureManager>; |
| + |
| + VideoCaptureManager(); |
| + |
| + // Called by the public functions, executed on vc_device_thread_. |
| + void OnEnumerateDevices(); |
| + void OnOpen(MediaCaptureSessionId capture_session_id, |
| + const MediaCaptureDeviceInfo device); |
| + void OnClose(MediaCaptureSessionId capture_session_id); |
| + void OnStart(const media::VideoCaptureParams capture_params, |
| + media::VideoCaptureDevice::EventHandler* video_capture_receiver); |
| + void OnStop(const media::VideoCaptureSessionId capture_session_id, |
| + Task* stopped_task); |
| + |
| + |
| + // Executed on Browser::IO thread to call Listener. |
| + void OnOpened(MediaCaptureSessionId capture_session_id); |
| + void OnClosed(MediaCaptureSessionId capture_session_id); |
| + void OnDevicesEnumerated(const MediaCaptureDevices& devices); |
| + void OnError(MediaCaptureSessionId capture_session_id, |
| + MediaStreamProviderError error); |
| + |
| + // Executed on vc_device_thread_ to make sure Listener is called from |
| + // Browser::IO thread. |
| + void PostOnOpened(MediaCaptureSessionId capture_session_id); |
| + void PostOnClosed(MediaCaptureSessionId capture_session_id); |
| + void PostOnDevicesEnumerated( |
| + const MediaCaptureDevices& devices); |
| + void PostOnError(MediaCaptureSessionId capture_session_id, |
| + MediaStreamProviderError error); |
| + |
| + // Called on Browser::IO thread, forwarders to the singleton methods. |
| + // Required to avoid the ownership of the manager object to be managed by both |
| + // RefCountedThreadSafe and LazyInstance. |
| + static void OnOpenedProxy(MediaCaptureSessionId capture_session_id); |
| + static void OnClosedProxy(MediaCaptureSessionId capture_session_id); |
| + static void OnDevicesEnumeratedProxy(const MediaCaptureDevices devices); |
| + static void OnErrorProxy(MediaCaptureSessionId capture_session_id, |
| + MediaStreamProviderError error); |
| + |
| + // Helpers |
| + void GetAvailableDevices(media::VideoCaptureDevice::Names* device_names); |
| + bool DeviceOpened(const media::VideoCaptureDevice::Name& device_name); |
| + bool IsOnCaptureDeviceThread() const; |
| + |
| + // Thread for all calls to VideoCaptureDevice |
| + base::Thread vc_device_thread_; |
| + |
| + // Only accessed on IO thread |
| + MediaStreamProviderListener* listener_; |
| + MediaCaptureSessionId new_capture_session_id_; |
| + |
| + // Only accessed from vc_device_thread_ |
| + typedef std::map<int, media::VideoCaptureDevice*> VideoCaptureDevices; |
| + VideoCaptureDevices devices_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); |
| +}; |
| + |
| +} // namespace media_stream |
| + |
| +DISABLE_RUNNABLE_METHOD_REFCOUNT(media_stream::VideoCaptureManager); |
| + |
| +#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.
|