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

Side by Side Diff: media/capture/content/screen_capture_device_core.h

Issue 2143903003: [WIP] Move media/capture to device/capture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef MEDIA_CAPTURE_CONTENT_SCREEN_CAPTURE_DEVICE_CORE_H_
6 #define MEDIA_CAPTURE_CONTENT_SCREEN_CAPTURE_DEVICE_CORE_H_
7
8 #include <memory>
9 #include <string>
10
11 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/threading/thread_checker.h"
14 #include "media/capture/capture_export.h"
15 #include "media/capture/content/thread_safe_capture_oracle.h"
16 #include "media/capture/video/video_capture_device.h"
17
18 namespace tracked_objects {
19 class Location;
20 } // namespace tracked_objects
21
22 namespace media {
23
24 struct VideoCaptureParams;
25
26 class ThreadSafeCaptureOracle;
27
28 // Keeps track of the video capture source frames and executes copying.
29 class CAPTURE_EXPORT VideoCaptureMachine {
30 public:
31 VideoCaptureMachine();
32 virtual ~VideoCaptureMachine();
33
34 // Starts capturing.
35 // |callback| is invoked with true if succeeded. Otherwise, with false.
36 virtual void Start(const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy,
37 const VideoCaptureParams& params,
38 const base::Callback<void(bool)> callback) = 0;
39
40 // Stops capturing.
41 // |callback| is invoked after the capturing has stopped.
42 virtual void Stop(const base::Closure& callback) = 0;
43
44 // Returns true if the video capture is configured to monitor end-to-end
45 // system utilization, and alter frame sizes and/or frame rates to mitigate
46 // overloading or under-utilization.
47 virtual bool IsAutoThrottlingEnabled() const;
48
49 // Called by ScreenCaptureDeviceCore when it failed to satisfy a "refresh
50 // frame" request by attempting to resurrect the last video frame from the
51 // buffer pool (this is referred to as the "passive" refresh approach). The
52 // failure can happen for a number of reasons (e.g., the oracle decided to
53 // change resolution, or consumers of the last video frame are not yet
54 // finished with it).
55 //
56 // The implementation of this method should consult the oracle, using the
57 // kActiveRefreshRequest event type, to decide whether to initiate a new frame
58 // capture, and then do so if the oracle agrees.
59 virtual void MaybeCaptureForRefresh() = 0;
60
61 private:
62 DISALLOW_COPY_AND_ASSIGN(VideoCaptureMachine);
63 };
64
65 // The "meat" of a content video capturer.
66 //
67 // Separating this from the "shell classes" WebContentsVideoCaptureDevice and
68 // DesktopCaptureDeviceAura allows safe destruction without needing to block any
69 // threads, as well as code sharing.
70 //
71 // ScreenCaptureDeviceCore manages a simple state machine and the pipeline
72 // (see notes at top of this file). It times the start of successive captures
73 // and facilitates the processing of each through the stages of the
74 // pipeline.
75 class CAPTURE_EXPORT ScreenCaptureDeviceCore
76 : public base::SupportsWeakPtr<ScreenCaptureDeviceCore> {
77 public:
78 ScreenCaptureDeviceCore(std::unique_ptr<VideoCaptureMachine> capture_machine);
79 virtual ~ScreenCaptureDeviceCore();
80
81 // Asynchronous requests to change ScreenCaptureDeviceCore state.
82 void AllocateAndStart(const VideoCaptureParams& params,
83 std::unique_ptr<VideoCaptureDevice::Client> client);
84 void RequestRefreshFrame();
85 void StopAndDeAllocate();
86
87 private:
88 // Flag indicating current state.
89 enum State { kIdle, kCapturing, kError, kLastCaptureState };
90
91 void TransitionStateTo(State next_state);
92
93 // Called back in response to StartCaptureMachine(). |success| is true if
94 // capture machine succeeded to start.
95 void CaptureStarted(bool success);
96
97 // Stops capturing and notifies client_ of an error state.
98 void Error(const tracked_objects::Location& from_here,
99 const std::string& reason);
100
101 // Tracks that all activity occurs on the media stream manager's thread.
102 base::ThreadChecker thread_checker_;
103
104 // Current lifecycle state.
105 State state_;
106
107 // Tracks the CaptureMachine that's doing work on our behalf
108 // on the device thread or UI thread.
109 // This value should never be dereferenced by this class.
110 std::unique_ptr<VideoCaptureMachine> capture_machine_;
111
112 // Our thread-safe capture oracle which serves as the gateway to the video
113 // capture pipeline. Besides the VideoCaptureDevice itself, it is the only
114 // component of the system with direct access to |client_|.
115 scoped_refptr<ThreadSafeCaptureOracle> oracle_proxy_;
116
117 DISALLOW_COPY_AND_ASSIGN(ScreenCaptureDeviceCore);
118 };
119
120 } // namespace media
121
122 #endif // MEDIA_CAPTURE_CONTENT_SCREEN_CAPTURE_DEVICE_CORE_H_
OLDNEW
« no previous file with comments | « media/capture/content/feedback_signal_accumulator_unittest.cc ('k') | media/capture/content/screen_capture_device_core.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698