OLD | NEW |
| (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 // VideoCaptureImpl represents a capture device in renderer process. It provides | |
6 // interfaces for clients to Start/Stop capture. It also communicates to clients | |
7 // when buffer is ready, state of capture device is changed. | |
8 | |
9 #ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ | |
10 #define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ | |
11 | |
12 #include <list> | |
13 #include <map> | |
14 | |
15 #include "content/renderer/video_capture_message_filter.h" | |
16 #include "media/base/callback.h" | |
17 #include "media/video/capture/video_capture.h" | |
18 #include "ui/gfx/surface/transport_dib.h" | |
19 | |
20 namespace base { | |
21 class MessageLoopProxy; | |
22 } | |
23 | |
24 class VideoCaptureImpl | |
25 : public media::VideoCapture, | |
26 public VideoCaptureMessageFilter::Delegate { | |
27 public: | |
28 // media::VideoCapture interface. | |
29 virtual void StartCapture(media::VideoCapture::EventHandler* handler, | |
30 const VideoCaptureCapability& capability); | |
31 virtual void StopCapture(media::VideoCapture::EventHandler* handler); | |
32 virtual bool CaptureStarted(); | |
33 virtual int CaptureWidth(); | |
34 virtual int CaptureHeight(); | |
35 virtual int CaptureFrameRate(); | |
36 | |
37 // VideoCaptureMessageFilter::Delegate interface. | |
38 virtual void OnBufferReceived(TransportDIB::Handle handle, | |
39 base::Time timestamp); | |
40 virtual void OnStateChanged(const media::VideoCapture::State& state); | |
41 virtual void OnDeviceInfoReceived( | |
42 const media::VideoCaptureParams& device_info); | |
43 virtual void OnDelegateAdded(int32 device_id); | |
44 | |
45 bool pending_start() { | |
46 return (new_width_ > 0 && new_height_ > 0); | |
47 } | |
48 | |
49 private: | |
50 friend class VideoCaptureImplManager; | |
51 friend class VideoCaptureImplTest; | |
52 | |
53 enum State { | |
54 kStarted, | |
55 kStopping, | |
56 kStopped | |
57 }; | |
58 | |
59 struct DIBBuffer { | |
60 public: | |
61 DIBBuffer(TransportDIB* d, media::VideoCapture::VideoFrameBuffer* ptr); | |
62 ~DIBBuffer(); | |
63 | |
64 TransportDIB* dib; | |
65 scoped_refptr<media::VideoCapture::VideoFrameBuffer> mapped_memory; | |
66 }; | |
67 | |
68 VideoCaptureImpl(media::VideoCaptureSessionId id, | |
69 scoped_refptr<base::MessageLoopProxy> ml_proxy, | |
70 VideoCaptureMessageFilter* filter); | |
71 virtual ~VideoCaptureImpl(); | |
72 | |
73 void Init(); | |
74 void DeInit(Task* task); | |
75 void StopDevice(); | |
76 void RestartCapture(); | |
77 void StartCaptureInternal(); | |
78 void AddDelegateOnIOThread(); | |
79 void RemoveDelegateOnIOThread(Task* task); | |
80 | |
81 scoped_refptr<VideoCaptureMessageFilter> message_filter_; | |
82 media::VideoCaptureSessionId session_id_; | |
83 scoped_refptr<base::MessageLoopProxy> ml_proxy_; | |
84 int device_id_; | |
85 | |
86 // Pool of DIBs. | |
87 typedef std::list<DIBBuffer*> CachedDIB; | |
88 CachedDIB cached_dibs_; | |
89 | |
90 typedef std::map<media::VideoCapture::EventHandler*, VideoCaptureCapability> | |
91 ClientInfo; | |
92 ClientInfo clients_; | |
93 std::list<media::VideoCapture::EventHandler*> master_clients_; | |
94 | |
95 ClientInfo pending_clients_; | |
96 | |
97 int width_; | |
98 int height_; | |
99 int frame_rate_; | |
100 media::VideoFrame::Format video_type_; | |
101 | |
102 int new_width_; | |
103 int new_height_; | |
104 State state_; | |
105 | |
106 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImpl); | |
107 }; | |
108 | |
109 DISABLE_RUNNABLE_METHOD_REFCOUNT(VideoCaptureImpl); | |
110 | |
111 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ | |
OLD | NEW |