#ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_
#define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_
#include <map>
#include "base/callback.h"
#include "base/memory/linked_ptr.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/synchronization/lock.h"
#include "base/threading/thread_checker.h"
#include "content/common/content_export.h"
#include "media/video/capture/video_capture.h"
namespace content {
class VideoCaptureImpl;
class VideoCaptureImplManager;
class VideoCaptureMessageFilter;
class CONTENT_EXPORT VideoCaptureHandle : media::VideoCapture {
public:
virtual ~VideoCaptureHandle();
virtual void StartCapture(
EventHandler* handler,
const media::VideoCaptureParams& params) OVERRIDE;
virtual void StopCapture(EventHandler* handler) OVERRIDE;
virtual bool CaptureStarted() OVERRIDE;
virtual int CaptureFrameRate() OVERRIDE;
virtual void GetDeviceSupportedFormats(
const DeviceFormatsCallback& callback) OVERRIDE;
virtual void GetDeviceFormatsInUse(
const DeviceFormatsInUseCallback& callback) OVERRIDE;
private:
friend class VideoCaptureImplManager;
VideoCaptureHandle(media::VideoCapture* impl,
base::Closure destruction_cb);
media::VideoCapture* impl_;
base::Closure destruction_cb_;
DISALLOW_COPY_AND_ASSIGN(VideoCaptureHandle);
};
class CONTENT_EXPORT VideoCaptureImplManager {
public:
VideoCaptureImplManager();
virtual ~VideoCaptureImplManager();
scoped_ptr<VideoCaptureHandle> UseDevice(media::VideoCaptureSessionId id);
void SuspendDevices(bool suspend);
VideoCaptureMessageFilter* video_capture_message_filter() const {
return filter_.get();
}
protected:
virtual VideoCaptureImpl* CreateVideoCaptureImpl(
media::VideoCaptureSessionId id,
VideoCaptureMessageFilter* filter) const;
private:
void UnrefDevice(media::VideoCaptureSessionId id);
typedef std::map<media::VideoCaptureSessionId,
std::pair<int, linked_ptr<VideoCaptureImpl> > >
VideoCaptureDeviceMap;
VideoCaptureDeviceMap devices_;
scoped_refptr<VideoCaptureMessageFilter> filter_;
base::ThreadChecker thread_checker_;
base::WeakPtrFactory<VideoCaptureImplManager> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplManager);
};
}
#endif