#ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_
#define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_
#include <list>
#include <map>
#include "base/memory/weak_ptr.h"
#include "content/common/content_export.h"
#include "content/common/media/video_capture.h"
#include "content/renderer/media/video_capture_message_filter.h"
#include "media/video/capture/video_capture.h"
#include "media/video/capture/video_capture_types.h"
namespace base {
class MessageLoopProxy;
}
namespace gpu {
struct MailboxHolder;
}
namespace content {
class CONTENT_EXPORT VideoCaptureImpl
: public media::VideoCapture, public VideoCaptureMessageFilter::Delegate {
public:
VideoCaptureImpl(media::VideoCaptureSessionId session_id,
VideoCaptureMessageFilter* filter);
virtual ~VideoCaptureImpl();
void Init();
void DeInit(base::Closure done_cb);
void SuspendCapture(bool suspend);
virtual void StartCapture(
media::VideoCapture::EventHandler* handler,
const media::VideoCaptureParams& params) OVERRIDE;
virtual void StopCapture(media::VideoCapture::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;
media::VideoCaptureSessionId session_id() const { return session_id_; }
private:
friend class VideoCaptureImplTest;
friend class MockVideoCaptureImpl;
class ClientBuffer;
typedef std::map<media::VideoCapture::EventHandler*,
media::VideoCaptureParams> ClientInfo;
void InitOnIOThread();
void DeInitOnIOThread(base::Closure done_cb);
void SuspendCaptureOnIOThread(bool suspend);
void StartCaptureOnIOThread(
media::VideoCapture::EventHandler* handler,
const media::VideoCaptureParams& params);
void StopCaptureOnIOThread(media::VideoCapture::EventHandler* handler);
void GetDeviceSupportedFormatsOnIOThread(
const DeviceFormatsCallback& callback);
void GetDeviceFormatsInUseOnIOThread(
const DeviceFormatsInUseCallback& callback);
virtual void OnBufferCreated(base::SharedMemoryHandle handle,
int length,
int buffer_id) OVERRIDE;
virtual void OnBufferDestroyed(int buffer_id) OVERRIDE;
virtual void OnBufferReceived(int buffer_id,
const media::VideoCaptureFormat& format,
base::TimeTicks) OVERRIDE;
virtual void OnMailboxBufferReceived(int buffer_id,
const gpu::MailboxHolder& mailbox_holder,
const media::VideoCaptureFormat& format,
base::TimeTicks timestamp) OVERRIDE;
virtual void OnStateChanged(VideoCaptureState state) OVERRIDE;
virtual void OnDeviceSupportedFormatsEnumerated(
const media::VideoCaptureFormats& supported_formats) OVERRIDE;
virtual void OnDeviceFormatsInUseReceived(
const media::VideoCaptureFormats& formats_in_use) OVERRIDE;
virtual void OnDelegateAdded(int32 device_id) OVERRIDE;
void OnClientBufferFinished(int buffer_id,
const scoped_refptr<ClientBuffer>& buffer,
scoped_ptr<gpu::MailboxHolder> mailbox_holder);
void StopDevice();
void RestartCapture();
void StartCaptureInternal();
virtual void Send(IPC::Message* message);
bool RemoveClient(media::VideoCapture::EventHandler* handler,
ClientInfo* clients);
const scoped_refptr<VideoCaptureMessageFilter> message_filter_;
const scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
int device_id_;
const int session_id_;
std::vector<DeviceFormatsCallback> device_formats_callback_queue_;
std::vector<DeviceFormatsInUseCallback> device_formats_in_use_callback_queue_;
typedef std::map<int32, scoped_refptr<ClientBuffer> > ClientBufferMap;
ClientBufferMap client_buffers_;
ClientInfo clients_;
ClientInfo clients_pending_on_filter_;
ClientInfo clients_pending_on_restart_;
media::VideoCaptureParams params_;
media::VideoCaptureFormat last_frame_format_;
base::TimeTicks first_frame_timestamp_;
bool suspended_;
VideoCaptureState state_;
base::WeakPtrFactory<VideoCaptureImpl> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(VideoCaptureImpl);
};
}
#endif