OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_MEDIA_CAPTURE_CONTENT_VIDEO_CAPTURE_DEVICE_CORE_H_ | 5 #ifndef CONTENT_BROWSER_MEDIA_CAPTURE_CONTENT_VIDEO_CAPTURE_DEVICE_CORE_H_ |
6 #define CONTENT_BROWSER_MEDIA_CAPTURE_CONTENT_VIDEO_CAPTURE_DEVICE_CORE_H_ | 6 #define CONTENT_BROWSER_MEDIA_CAPTURE_CONTENT_VIDEO_CAPTURE_DEVICE_CORE_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" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
13 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
14 #include "content/browser/media/capture/video_capture_oracle.h" | 14 #include "content/browser/media/capture/video_capture_oracle.h" |
15 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
16 #include "media/base/video_frame.h" | |
16 #include "media/video/capture/video_capture_device.h" | 17 #include "media/video/capture/video_capture_device.h" |
17 | 18 |
18 namespace media { | 19 namespace media { |
20 class VideoCaptureParams; | |
19 class VideoFrame; | 21 class VideoFrame; |
20 } // namespace media | 22 } // namespace media |
21 | 23 |
22 namespace content { | 24 namespace content { |
23 | 25 |
24 const int kMinFrameWidth = 2; | |
25 const int kMinFrameHeight = 2; | |
26 | |
27 // Returns the nearest even integer closer to zero. | 26 // Returns the nearest even integer closer to zero. |
28 template<typename IntType> | 27 template<typename IntType> |
29 IntType MakeEven(IntType x) { | 28 IntType MakeEven(IntType x) { |
30 return x & static_cast<IntType>(-2); | 29 return x & static_cast<IntType>(-2); |
31 } | 30 } |
32 | 31 |
33 // TODO(nick): Remove this once frame subscription is supported on Aura and | 32 // TODO(nick): Remove this once frame subscription is supported on Aura and |
34 // Linux. | 33 // Linux. |
35 #if (defined(OS_WIN) || defined(OS_MACOSX)) || defined(USE_AURA) | 34 #if (defined(OS_WIN) || defined(OS_MACOSX)) || defined(USE_AURA) |
36 const bool kAcceleratedSubscriberIsSupported = true; | 35 const bool kAcceleratedSubscriberIsSupported = true; |
37 #else | 36 #else |
38 const bool kAcceleratedSubscriberIsSupported = false; | 37 const bool kAcceleratedSubscriberIsSupported = false; |
39 #endif | 38 #endif |
40 | 39 |
41 class VideoCaptureMachine; | 40 class VideoCaptureMachine; |
42 | 41 |
43 // Thread-safe, refcounted proxy to the VideoCaptureOracle. This proxy wraps | 42 // Thread-safe, refcounted proxy to the VideoCaptureOracle. This proxy wraps |
44 // the VideoCaptureOracle, which decides which frames to capture, and a | 43 // the VideoCaptureOracle, which decides which frames to capture, and a |
45 // VideoCaptureDevice::Client, which allocates and receives the captured | 44 // VideoCaptureDevice::Client, which allocates and receives the captured |
46 // frames, in a lock to synchronize state between the two. | 45 // frames, in a lock to synchronize state between the two. |
47 class ThreadSafeCaptureOracle | 46 class ThreadSafeCaptureOracle |
48 : public base::RefCountedThreadSafe<ThreadSafeCaptureOracle> { | 47 : public base::RefCountedThreadSafe<ThreadSafeCaptureOracle> { |
49 public: | 48 public: |
50 ThreadSafeCaptureOracle(scoped_ptr<media::VideoCaptureDevice::Client> client, | 49 ThreadSafeCaptureOracle(scoped_ptr<media::VideoCaptureDevice::Client> client, |
51 scoped_ptr<VideoCaptureOracle> oracle, | 50 scoped_ptr<VideoCaptureOracle> oracle, |
52 const media::VideoCaptureParams& params); | 51 const media::VideoCaptureParams& params); |
53 | 52 |
54 // Called when a captured frame is available or an error has occurred. | 53 // Called when a captured frame is available or an error has occurred. |
55 // If |success| is true then the frame provided is valid and |timestamp| | 54 // If |success| is true then |frame| is valid and |timestamp| indicates when |
56 // indicates when the frame was painted. | 55 // the frame was painted. |
57 // If |success| is false, both the frame provided and |timestamp| are invalid. | 56 // If |success| is false, all other parameters are invalid. |
Ami GONE FROM CHROMIUM
2014/04/01 18:03:38
Maybe make this the first param, then?
hshi1
2014/04/24 20:55:45
It's a bit messy. See web_contents_video_capture_d
Ami GONE FROM CHROMIUM
2014/04/24 21:05:28
Yeah, not worth it.
| |
58 typedef base::Callback<void(base::TimeTicks timestamp, bool success)> | 57 typedef base::Callback<void(const scoped_refptr<media::VideoFrame>& frame, |
59 CaptureFrameCallback; | 58 base::TimeTicks timestamp, |
59 bool success)> CaptureFrameCallback; | |
60 | 60 |
61 bool ObserveEventAndDecideCapture(VideoCaptureOracle::Event event, | 61 bool ObserveEventAndDecideCapture(VideoCaptureOracle::Event event, |
62 base::TimeTicks event_time, | 62 base::TimeTicks event_time, |
63 scoped_refptr<media::VideoFrame>* storage, | 63 scoped_refptr<media::VideoFrame>* storage, |
64 CaptureFrameCallback* callback); | 64 CaptureFrameCallback* callback); |
65 | 65 |
66 base::TimeDelta capture_period() const { | 66 base::TimeDelta capture_period() const { |
67 return oracle_->capture_period(); | 67 return oracle_->capture_period(); |
68 } | 68 } |
69 | 69 |
70 // Returns the current capture resolution. | 70 // Returns the current capture resolution. |
71 gfx::Size GetCaptureSize() const; | 71 gfx::Size GetCaptureSize() const; |
72 | 72 |
73 // Updates capture resolution based on the supplied source size and the | 73 // Updates capture resolution based on the supplied source size and the |
74 // maximum frame size. | 74 // maximum frame size. |
75 void UpdateCaptureSize(const gfx::Size& source_size); | 75 void UpdateCaptureSize(const gfx::Size& source_size); |
76 | 76 |
77 // Stop new captures from happening (but doesn't forget the client). | 77 // Stop new captures from happening (but doesn't forget the client). |
78 void Stop(); | 78 void Stop(); |
79 | 79 |
80 // Signal an error to the client. | 80 // Signal an error to the client. |
81 void ReportError(const std::string& reason); | 81 void ReportError(const std::string& reason); |
82 | 82 |
83 private: | 83 private: |
84 friend class base::RefCountedThreadSafe<ThreadSafeCaptureOracle>; | 84 friend class base::RefCountedThreadSafe<ThreadSafeCaptureOracle>; |
85 virtual ~ThreadSafeCaptureOracle(); | 85 virtual ~ThreadSafeCaptureOracle(); |
86 | 86 |
87 // Callback invoked on completion of all captures. | 87 // Callback invoked on completion of all captures. |
88 void DidCaptureFrame( | 88 void DidCaptureFrame( |
89 int frame_number, | |
89 const scoped_refptr<media::VideoCaptureDevice::Client::Buffer>& buffer, | 90 const scoped_refptr<media::VideoCaptureDevice::Client::Buffer>& buffer, |
90 const scoped_refptr<media::VideoFrame>& frame, | 91 const scoped_refptr<media::VideoFrame>& frame, |
91 int frame_number, | |
92 base::TimeTicks timestamp, | 92 base::TimeTicks timestamp, |
93 bool success); | 93 bool success); |
94 | 94 |
95 // Protects everything below it. | 95 // Protects everything below it. |
96 mutable base::Lock lock_; | 96 mutable base::Lock lock_; |
97 | 97 |
98 // Recipient of our capture activity. | 98 // Recipient of our capture activity. |
99 scoped_ptr<media::VideoCaptureDevice::Client> client_; | 99 scoped_ptr<media::VideoCaptureDevice::Client> client_; |
100 | 100 |
101 // Makes the decision to capture a frame. | 101 // Makes the decision to capture a frame. |
102 const scoped_ptr<VideoCaptureOracle> oracle_; | 102 const scoped_ptr<VideoCaptureOracle> oracle_; |
103 | 103 |
104 // The video capture parameters used to construct the oracle proxy. | 104 // The video capture parameters used to construct the oracle proxy. |
105 const media::VideoCaptureParams params_; | 105 media::VideoCaptureParams params_; |
106 | 106 |
107 // Indicates if capture size has been updated after construction. | 107 // Indicates if capture size has been updated after construction. |
108 bool capture_size_updated_; | 108 bool capture_size_updated_; |
109 | 109 |
110 // The current capturing resolution and frame rate. | 110 // The current capturing format, as a media::VideoFrame::Format. |
111 gfx::Size capture_size_; | 111 media::VideoFrame::Format video_frame_format_; |
112 int frame_rate_; | |
113 }; | 112 }; |
114 | 113 |
115 // Keeps track of the video capture source frames and executes copying on the | 114 // Keeps track of the video capture source frames and executes copying on the |
116 // UI BrowserThread. | 115 // UI BrowserThread. |
117 class VideoCaptureMachine { | 116 class VideoCaptureMachine { |
118 public: | 117 public: |
119 VideoCaptureMachine() : started_(false) {} | 118 VideoCaptureMachine() : started_(false) {} |
120 virtual ~VideoCaptureMachine() {} | 119 virtual ~VideoCaptureMachine() {} |
121 | 120 |
122 // This should only be checked on the UI thread. | 121 // This should only be checked on the UI thread. |
123 bool started() const { return started_; } | 122 bool started() const { return started_; } |
124 | 123 |
125 // Starts capturing. Returns true if succeeded. | 124 // Starts capturing. Returns true if succeeded. |
126 // Must be run on the UI BrowserThread. | 125 // Must be run on the UI BrowserThread. |
127 virtual bool Start( | 126 virtual bool Start(const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy, |
128 const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy) = 0; | 127 const media::VideoCaptureParams& params) = 0; |
129 | 128 |
130 // Stops capturing. Must be run on the UI BrowserThread. | 129 // Stops capturing. Must be run on the UI BrowserThread. |
131 // |callback| is invoked after the capturing has stopped. | 130 // |callback| is invoked after the capturing has stopped. |
132 virtual void Stop(const base::Closure& callback) = 0; | 131 virtual void Stop(const base::Closure& callback) = 0; |
133 | 132 |
134 protected: | 133 protected: |
135 bool started_; | 134 bool started_; |
136 | 135 |
137 private: | 136 private: |
138 DISALLOW_COPY_AND_ASSIGN(VideoCaptureMachine); | 137 DISALLOW_COPY_AND_ASSIGN(VideoCaptureMachine); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 // component of the/ system with direct access to |client_|. | 192 // component of the/ system with direct access to |client_|. |
194 scoped_refptr<ThreadSafeCaptureOracle> oracle_proxy_; | 193 scoped_refptr<ThreadSafeCaptureOracle> oracle_proxy_; |
195 | 194 |
196 DISALLOW_COPY_AND_ASSIGN(ContentVideoCaptureDeviceCore); | 195 DISALLOW_COPY_AND_ASSIGN(ContentVideoCaptureDeviceCore); |
197 }; | 196 }; |
198 | 197 |
199 | 198 |
200 } // namespace content | 199 } // namespace content |
201 | 200 |
202 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_CONTENT_VIDEO_CAPTURE_DEVICE_CORE_H_ | 201 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_CONTENT_VIDEO_CAPTURE_DEVICE_CORE_H_ |
OLD | NEW |