OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_VIDEO_CAPTURE_DEVICE_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_VIDEO_CAPTURE_DEVICE_IMPL_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_VIDEO_CAPTURE_DEVICE_IMPL_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_VIDEO_CAPTURE_DEVICE_IMPL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 | 38 |
39 // Thread-safe, refcounted proxy to the VideoCaptureOracle. This proxy wraps | 39 // Thread-safe, refcounted proxy to the VideoCaptureOracle. This proxy wraps |
40 // the VideoCaptureOracle, which decides which frames to capture, and a | 40 // the VideoCaptureOracle, which decides which frames to capture, and a |
41 // VideoCaptureDevice::Client, which allocates and receives the captured | 41 // VideoCaptureDevice::Client, which allocates and receives the captured |
42 // frames, in a lock to synchronize state between the two. | 42 // frames, in a lock to synchronize state between the two. |
43 class ThreadSafeCaptureOracle | 43 class ThreadSafeCaptureOracle |
44 : public base::RefCountedThreadSafe<ThreadSafeCaptureOracle> { | 44 : public base::RefCountedThreadSafe<ThreadSafeCaptureOracle> { |
45 public: | 45 public: |
46 ThreadSafeCaptureOracle(scoped_ptr<media::VideoCaptureDevice::Client> client, | 46 ThreadSafeCaptureOracle(scoped_ptr<media::VideoCaptureDevice::Client> client, |
47 scoped_ptr<VideoCaptureOracle> oracle, | 47 scoped_ptr<VideoCaptureOracle> oracle, |
48 const gfx::Size& capture_size, | 48 const gfx::Size& max_frame_size, |
49 int frame_rate); | 49 int frame_rate); |
50 | 50 |
51 // Called when a captured frame is available or an error has occurred. | 51 // Called when a captured frame is available or an error has occurred. |
52 // If |success| is true then the frame provided is valid and |timestamp| | 52 // If |success| is true then the frame provided is valid and |timestamp| |
53 // indicates when the frame was painted. | 53 // indicates when the frame was painted. |
54 // If |success| is false, both the frame provided and |timestamp| are invalid. | 54 // If |success| is false, both the frame provided and |timestamp| are invalid. |
55 typedef base::Callback<void(base::Time timestamp, bool success)> | 55 typedef base::Callback<void(base::Time timestamp, bool success)> |
56 CaptureFrameCallback; | 56 CaptureFrameCallback; |
57 | 57 |
58 bool ObserveEventAndDecideCapture(VideoCaptureOracle::Event event, | 58 bool ObserveEventAndDecideCapture(VideoCaptureOracle::Event event, |
59 base::Time event_time, | 59 base::Time event_time, |
60 scoped_refptr<media::VideoFrame>* storage, | 60 scoped_refptr<media::VideoFrame>* storage, |
61 CaptureFrameCallback* callback); | 61 CaptureFrameCallback* callback); |
62 | 62 |
63 base::TimeDelta capture_period() const { | 63 base::TimeDelta capture_period() const { |
64 return oracle_->capture_period(); | 64 return oracle_->capture_period(); |
65 } | 65 } |
66 | 66 |
| 67 // Updates capture resolution based on the supplied source size and the |
| 68 // maximum frame size. |
| 69 void UpdateCaptureSize(const gfx::Size& source_size); |
| 70 |
67 // Stop new captures from happening (but doesn't forget the client). | 71 // Stop new captures from happening (but doesn't forget the client). |
68 void Stop(); | 72 void Stop(); |
69 | 73 |
70 // Signal an error to the client. | 74 // Signal an error to the client. |
71 void ReportError(); | 75 void ReportError(); |
72 | 76 |
73 private: | 77 private: |
74 friend class base::RefCountedThreadSafe<ThreadSafeCaptureOracle>; | 78 friend class base::RefCountedThreadSafe<ThreadSafeCaptureOracle>; |
75 virtual ~ThreadSafeCaptureOracle(); | 79 virtual ~ThreadSafeCaptureOracle(); |
76 | 80 |
77 // Callback invoked on completion of all captures. | 81 // Callback invoked on completion of all captures. |
78 void DidCaptureFrame( | 82 void DidCaptureFrame( |
79 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer, | 83 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer, |
80 int frame_number, | 84 int frame_number, |
81 base::Time timestamp, | 85 base::Time timestamp, |
82 bool success); | 86 bool success); |
83 // Protects everything below it. | 87 // Protects everything below it. |
84 base::Lock lock_; | 88 base::Lock lock_; |
85 | 89 |
86 // Recipient of our capture activity. | 90 // Recipient of our capture activity. |
87 scoped_ptr<media::VideoCaptureDevice::Client> client_; | 91 scoped_ptr<media::VideoCaptureDevice::Client> client_; |
88 | 92 |
89 // Makes the decision to capture a frame. | 93 // Makes the decision to capture a frame. |
90 const scoped_ptr<VideoCaptureOracle> oracle_; | 94 const scoped_ptr<VideoCaptureOracle> oracle_; |
91 | 95 |
| 96 // The maximum frame size. |
| 97 const gfx::Size max_frame_size_; |
| 98 |
92 // The current capturing resolution and frame rate. | 99 // The current capturing resolution and frame rate. |
93 const gfx::Size capture_size_; | 100 gfx::Size capture_size_; |
94 const int frame_rate_; | 101 const int frame_rate_; |
95 }; | 102 }; |
96 | 103 |
97 // Keeps track of the video capture source frames and executes copying on the | 104 // Keeps track of the video capture source frames and executes copying on the |
98 // UI BrowserThread. | 105 // UI BrowserThread. |
99 class VideoCaptureMachine { | 106 class VideoCaptureMachine { |
100 public: | 107 public: |
101 VideoCaptureMachine() : started_(false) {} | 108 VideoCaptureMachine() : started_(false) {} |
102 virtual ~VideoCaptureMachine() {} | 109 virtual ~VideoCaptureMachine() {} |
103 | 110 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 // system with direct access to |client_|. | 180 // system with direct access to |client_|. |
174 scoped_refptr<ThreadSafeCaptureOracle> oracle_proxy_; | 181 scoped_refptr<ThreadSafeCaptureOracle> oracle_proxy_; |
175 | 182 |
176 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceImpl); | 183 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceImpl); |
177 }; | 184 }; |
178 | 185 |
179 | 186 |
180 } // namespace content | 187 } // namespace content |
181 | 188 |
182 #endif // CONTENT_BROWSER_RENDERER_HOST_VIDEO_CAPTURE_DEVICE_IMPL_H_ | 189 #endif // CONTENT_BROWSER_RENDERER_HOST_VIDEO_CAPTURE_DEVICE_IMPL_H_ |
OLD | NEW |