blob: e9422015b026bda6d3d41abc4398fed0aee1a34a [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// Copyright (c) 2012 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// VideoCaptureImplManager manages video capture devices in renderer process.
6// The video capture clients use AddDevice() to get a pointer to
7// video capture device. VideoCaputreImplManager supports multiple clients
8// accessing same device.
9
10#ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_
11#define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_
12
13#include <list>
14#include <map>
15
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010016#include "base/message_loop/message_loop_proxy.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000017#include "base/threading/thread.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000018#include "base/synchronization/lock.h"
19#include "content/common/content_export.h"
20#include "media/video/capture/video_capture.h"
21
22namespace content {
23
24class VideoCaptureImpl;
25class VideoCaptureMessageFilter;
26
27class CONTENT_EXPORT VideoCaptureImplManager
28 : public base::RefCountedThreadSafe<VideoCaptureImplManager> {
29 public:
30 VideoCaptureImplManager();
31
32 // Called by video capture client |handler| to add device referenced
33 // by |id| to VideoCaptureImplManager's list of opened device list.
34 // A pointer to VideoCapture is returned to client so that client can
35 // operate on that pointer, such as StartCaptrue, StopCapture.
36 virtual media::VideoCapture* AddDevice(
37 media::VideoCaptureSessionId id,
38 media::VideoCapture::EventHandler* handler);
39
40 // Called by video capture client |handler| to remove device referenced
41 // by |id| from VideoCaptureImplManager's list of opened device list.
42 virtual void RemoveDevice(media::VideoCaptureSessionId id,
43 media::VideoCapture::EventHandler* handler);
44
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010045 // Make all existing VideoCaptureImpl instances stop/resume delivering
46 // video frames to their clients, depends on flag |suspend|.
47 virtual void SuspendDevices(bool suspend);
48
Torne (Richard Coles)58218062012-11-14 11:43:16 +000049 VideoCaptureMessageFilter* video_capture_message_filter() const {
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010050 return filter_.get();
Torne (Richard Coles)58218062012-11-14 11:43:16 +000051 }
52
53 protected:
54 virtual ~VideoCaptureImplManager();
55
56 private:
57 friend class base::RefCountedThreadSafe<VideoCaptureImplManager>;
58
59 struct Device {
60 Device(VideoCaptureImpl* device,
61 media::VideoCapture::EventHandler* handler);
62 ~Device();
63
64 VideoCaptureImpl* vc;
65 std::list<media::VideoCapture::EventHandler*> clients;
66 };
67
68 void FreeDevice(VideoCaptureImpl* vc);
69
70 typedef std::map<media::VideoCaptureSessionId, Device*> Devices;
71 Devices devices_;
72 base::Lock lock_;
73 scoped_refptr<VideoCaptureMessageFilter> filter_;
74 base::Thread thread_;
75 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
76
Torne (Richard Coles)58218062012-11-14 11:43:16 +000077 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImplManager);
78};
79
80} // namespace content
81
82#endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_MANAGER_H_