Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: media/capture/media_video_capture_device_core.h

Issue 1162863003: Move ContentVideoCaptureDeviceCore from src/content to src/media (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 MEDIA_CAPTURE_MEDIA_VIDEO_CAPTURE_DEVICE_CORE_H_
6 #define CONTENT_BROWSER_MEDIA_CAPTURE_CONTENT_VIDEO_CAPTURE_DEVICE_CORE_H_ 6 #define MEDIA_CAPTURE_MEDIA_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/capture_resolution_chooser.h" 14 #include "media/base/media_export.h"
15 #include "content/browser/media/capture/video_capture_oracle.h"
16 #include "content/common/content_export.h"
17 #include "media/base/video_frame.h" 15 #include "media/base/video_frame.h"
16 #include "media/capture/capture_resolution_chooser.h"
17 #include "media/capture/video_capture_oracle.h"
18 #include "media/video/capture/video_capture_device.h" 18 #include "media/video/capture/video_capture_device.h"
19 19
20 namespace media { 20 namespace media {
21
21 class VideoCaptureParams; 22 class VideoCaptureParams;
22 class VideoFrame; 23 class VideoFrame;
23 } // namespace media
24
25 namespace content {
26 24
27 class VideoCaptureMachine; 25 class VideoCaptureMachine;
28 26
29 // Thread-safe, refcounted proxy to the VideoCaptureOracle. This proxy wraps 27 // Thread-safe, refcounted proxy to the VideoCaptureOracle. This proxy wraps
30 // the VideoCaptureOracle, which decides which frames to capture, and a 28 // the VideoCaptureOracle, which decides which frames to capture, and a
31 // VideoCaptureDevice::Client, which allocates and receives the captured 29 // VideoCaptureDevice::Client, which allocates and receives the captured
32 // frames, in a lock to synchronize state between the two. 30 // frames, in a lock to synchronize state between the two.
33 class ThreadSafeCaptureOracle 31 class ThreadSafeCaptureOracle
34 : public base::RefCountedThreadSafe<ThreadSafeCaptureOracle> { 32 : public base::RefCountedThreadSafe<ThreadSafeCaptureOracle> {
35 public: 33 public:
36 ThreadSafeCaptureOracle(scoped_ptr<media::VideoCaptureDevice::Client> client, 34 ThreadSafeCaptureOracle(scoped_ptr<VideoCaptureDevice::Client> client,
37 const media::VideoCaptureParams& params); 35 const VideoCaptureParams& params);
38 36
39 // Called when a captured frame is available or an error has occurred. 37 // Called when a captured frame is available or an error has occurred.
40 // If |success| is true then |frame| is valid and |timestamp| indicates when 38 // If |success| is true then |frame| is valid and |timestamp| indicates when
41 // the frame was painted. 39 // the frame was painted.
42 // If |success| is false, all other parameters are invalid. 40 // If |success| is false, all other parameters are invalid.
43 typedef base::Callback<void(const scoped_refptr<media::VideoFrame>& frame, 41 typedef base::Callback<void(const scoped_refptr<VideoFrame>& frame,
44 base::TimeTicks timestamp, 42 base::TimeTicks timestamp,
45 bool success)> CaptureFrameCallback; 43 bool success)> CaptureFrameCallback;
46 44
47 bool ObserveEventAndDecideCapture(VideoCaptureOracle::Event event, 45 bool ObserveEventAndDecideCapture(VideoCaptureOracle::Event event,
48 const gfx::Rect& damage_rect, 46 const gfx::Rect& damage_rect,
49 base::TimeTicks event_time, 47 base::TimeTicks event_time,
50 scoped_refptr<media::VideoFrame>* storage, 48 scoped_refptr<VideoFrame>* storage,
51 CaptureFrameCallback* callback); 49 CaptureFrameCallback* callback);
52 50
53 base::TimeDelta min_capture_period() const { 51 base::TimeDelta min_capture_period() const {
54 return oracle_.min_capture_period(); 52 return oracle_.min_capture_period();
55 } 53 }
56 54
57 gfx::Size max_frame_size() const { 55 gfx::Size max_frame_size() const {
58 return params_.requested_format.frame_size; 56 return params_.requested_format.frame_size;
59 } 57 }
60 58
(...skipping 10 matching lines...) Expand all
71 // Signal an error to the client. 69 // Signal an error to the client.
72 void ReportError(const std::string& reason); 70 void ReportError(const std::string& reason);
73 71
74 private: 72 private:
75 friend class base::RefCountedThreadSafe<ThreadSafeCaptureOracle>; 73 friend class base::RefCountedThreadSafe<ThreadSafeCaptureOracle>;
76 virtual ~ThreadSafeCaptureOracle(); 74 virtual ~ThreadSafeCaptureOracle();
77 75
78 // Callback invoked on completion of all captures. 76 // Callback invoked on completion of all captures.
79 void DidCaptureFrame( 77 void DidCaptureFrame(
80 int frame_number, 78 int frame_number,
81 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer, 79 scoped_ptr<VideoCaptureDevice::Client::Buffer> buffer,
82 base::TimeTicks capture_begin_time, 80 base::TimeTicks capture_begin_time,
83 base::TimeDelta estimated_frame_duration, 81 base::TimeDelta estimated_frame_duration,
84 const scoped_refptr<media::VideoFrame>& frame, 82 const scoped_refptr<VideoFrame>& frame,
85 base::TimeTicks timestamp, 83 base::TimeTicks timestamp,
86 bool success); 84 bool success);
87 85
88 // Protects everything below it. 86 // Protects everything below it.
89 mutable base::Lock lock_; 87 mutable base::Lock lock_;
90 88
91 // Recipient of our capture activity. 89 // Recipient of our capture activity.
92 scoped_ptr<media::VideoCaptureDevice::Client> client_; 90 scoped_ptr<VideoCaptureDevice::Client> client_;
93 91
94 // Makes the decision to capture a frame. 92 // Makes the decision to capture a frame.
95 VideoCaptureOracle oracle_; 93 VideoCaptureOracle oracle_;
96 94
97 // The video capture parameters used to construct the oracle proxy. 95 // The video capture parameters used to construct the oracle proxy.
98 const media::VideoCaptureParams params_; 96 const VideoCaptureParams params_;
99 97
100 // Determines video capture frame sizes. 98 // Determines video capture frame sizes.
101 CaptureResolutionChooser resolution_chooser_; 99 CaptureResolutionChooser resolution_chooser_;
102 }; 100 };
103 101
104 // Keeps track of the video capture source frames and executes copying on the 102 // Keeps track of the video capture source frames and executes copying on the
105 // UI BrowserThread. 103 // UI BrowserThread.
106 class VideoCaptureMachine { 104 class VideoCaptureMachine {
107 public: 105 public:
108 VideoCaptureMachine() {} 106 VideoCaptureMachine() {}
109 virtual ~VideoCaptureMachine() {} 107 virtual ~VideoCaptureMachine() {}
110 108
111 // Starts capturing. Returns true if succeeded. 109 // Starts capturing.
112 // Must be run on the UI BrowserThread. 110 // |callback| is invoked with true if succeeded. Otherwise, with false.
113 virtual bool Start(const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy, 111 virtual void Start(const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy,
114 const media::VideoCaptureParams& params) = 0; 112 const VideoCaptureParams& params,
113 const base::Callback<void(bool)> callback) = 0;
115 114
116 // Stops capturing. Must be run on the UI BrowserThread. 115 // Stops capturing.
117 // |callback| is invoked after the capturing has stopped. 116 // |callback| is invoked after the capturing has stopped.
118 virtual void Stop(const base::Closure& callback) = 0; 117 virtual void Stop(const base::Closure& callback) = 0;
119 118
120 private: 119 private:
121 DISALLOW_COPY_AND_ASSIGN(VideoCaptureMachine); 120 DISALLOW_COPY_AND_ASSIGN(VideoCaptureMachine);
122 }; 121 };
123 122
124 // The "meat" of a content video capturer. 123 // The "meat" of a content video capturer.
125 // 124 //
126 // Separating this from the "shell classes" WebContentsVideoCaptureDevice and 125 // Separating this from the "shell classes" WebContentsVideoCaptureDevice and
127 // DesktopCaptureDeviceAura allows safe destruction without needing to block any 126 // DesktopCaptureDeviceAura allows safe destruction without needing to block any
128 // threads, as well as code sharing. 127 // threads, as well as code sharing.
129 // 128 //
130 // ContentVideoCaptureDeviceCore manages a simple state machine and the pipeline 129 // MediaVideoCaptureDeviceCore manages a simple state machine and the pipeline
131 // (see notes at top of this file). It times the start of successive captures 130 // (see notes at top of this file). It times the start of successive captures
132 // and facilitates the processing of each through the stages of the 131 // and facilitates the processing of each through the stages of the
133 // pipeline. 132 // pipeline.
134 class CONTENT_EXPORT ContentVideoCaptureDeviceCore 133 class MEDIA_EXPORT MediaVideoCaptureDeviceCore
miu 2015/06/05 01:13:37 naming: Could you name this class ScreenCaptureDev
jiajia.qin 2015/06/05 02:31:34 Hi, miu. I am considering that maybe VideoCaptureD
jiajia.qin 2015/06/08 04:58:24 Done.
135 : public base::SupportsWeakPtr<ContentVideoCaptureDeviceCore> { 134 : public base::SupportsWeakPtr<MediaVideoCaptureDeviceCore> {
136 public: 135 public:
137 ContentVideoCaptureDeviceCore( 136 MediaVideoCaptureDeviceCore(
138 scoped_ptr<VideoCaptureMachine> capture_machine); 137 scoped_ptr<VideoCaptureMachine> capture_machine);
139 virtual ~ContentVideoCaptureDeviceCore(); 138 virtual ~MediaVideoCaptureDeviceCore();
140 139
141 // Asynchronous requests to change ContentVideoCaptureDeviceCore state. 140 // Asynchronous requests to change MediaVideoCaptureDeviceCore state.
142 void AllocateAndStart(const media::VideoCaptureParams& params, 141 void AllocateAndStart(const VideoCaptureParams& params,
143 scoped_ptr<media::VideoCaptureDevice::Client> client); 142 scoped_ptr<VideoCaptureDevice::Client> client);
144 void StopAndDeAllocate(); 143 void StopAndDeAllocate();
145 144
146 private: 145 private:
147 // Flag indicating current state. 146 // Flag indicating current state.
148 enum State { 147 enum State {
149 kIdle, 148 kIdle,
150 kCapturing, 149 kCapturing,
151 kError 150 kError
152 }; 151 };
153 152
154 void TransitionStateTo(State next_state); 153 void TransitionStateTo(State next_state);
155 154
156 // Called back in response to StartCaptureMachine(). |success| is true if 155 // Called back in response to StartCaptureMachine(). |success| is true if
157 // capture machine succeeded to start. 156 // capture machine succeeded to start.
158 void CaptureStarted(bool success); 157 void CaptureStarted(bool success);
159 158
160 // Stops capturing and notifies client_ of an error state. 159 // Stops capturing and notifies client_ of an error state.
161 void Error(const std::string& reason); 160 void Error(const std::string& reason);
162 161
163 // Tracks that all activity occurs on the media stream manager's thread. 162 // Tracks that all activity occurs on the media stream manager's thread.
164 base::ThreadChecker thread_checker_; 163 base::ThreadChecker thread_checker_;
165 164
166 // Current lifecycle state. 165 // Current lifecycle state.
167 State state_; 166 State state_;
168 167
169 // Tracks the CaptureMachine that's doing work on our behalf on the UI thread. 168 // Tracks the CaptureMachine that's doing work on our behalf
170 // This value should never be dereferenced by this class, other than to 169 // on the device thread or UI thread.
171 // create and destroy it on the UI thread. 170 // This value should never be dereferenced by this class.
172 scoped_ptr<VideoCaptureMachine> capture_machine_; 171 scoped_ptr<VideoCaptureMachine> capture_machine_;
173 172
174 // Our thread-safe capture oracle which serves as the gateway to the video 173 // Our thread-safe capture oracle which serves as the gateway to the video
175 // capture pipeline. Besides the VideoCaptureDevice itself, it is the only 174 // capture pipeline. Besides the VideoCaptureDevice itself, it is the only
176 // component of the system with direct access to |client_|. 175 // component of the system with direct access to |client_|.
177 scoped_refptr<ThreadSafeCaptureOracle> oracle_proxy_; 176 scoped_refptr<ThreadSafeCaptureOracle> oracle_proxy_;
178 177
179 DISALLOW_COPY_AND_ASSIGN(ContentVideoCaptureDeviceCore); 178 DISALLOW_COPY_AND_ASSIGN(MediaVideoCaptureDeviceCore);
180 }; 179 };
181 180
182 181
183 } // namespace content 182 } // namespace media
184 183
185 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_CONTENT_VIDEO_CAPTURE_DEVICE_CORE_H_ 184 #endif // MEDIA_CAPTURE_MEDIA_VIDEO_CAPTURE_DEVICE_CORE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698