Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / media / capture / content / screen_capture_device_core.h
blob0720094f5b88a06d9492b409c15bd96edcfa705a
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.
5 #ifndef MEDIA_CAPTURE_SCREEN_CAPTURE_DEVICE_CORE_H_
6 #define MEDIA_CAPTURE_SCREEN_CAPTURE_DEVICE_CORE_H_
8 #include <string>
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/threading/thread_checker.h"
13 #include "media/base/media_export.h"
14 #include "media/capture/content/thread_safe_capture_oracle.h"
15 #include "media/capture/video/video_capture_device.h"
17 namespace media {
19 struct VideoCaptureParams;
21 class ThreadSafeCaptureOracle;
23 // Keeps track of the video capture source frames and executes copying.
24 class MEDIA_EXPORT VideoCaptureMachine {
25 public:
26 VideoCaptureMachine();
27 virtual ~VideoCaptureMachine();
29 // Starts capturing.
30 // |callback| is invoked with true if succeeded. Otherwise, with false.
31 virtual void Start(const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy,
32 const VideoCaptureParams& params,
33 const base::Callback<void(bool)> callback) = 0;
35 // Stops capturing.
36 // |callback| is invoked after the capturing has stopped.
37 virtual void Stop(const base::Closure& callback) = 0;
39 // Returns true if the video capture is configured to monitor end-to-end
40 // system utilization, and alter frame sizes and/or frame rates to mitigate
41 // overloading or under-utilization.
42 virtual bool IsAutoThrottlingEnabled() const;
44 private:
45 DISALLOW_COPY_AND_ASSIGN(VideoCaptureMachine);
48 // The "meat" of a content video capturer.
50 // Separating this from the "shell classes" WebContentsVideoCaptureDevice and
51 // DesktopCaptureDeviceAura allows safe destruction without needing to block any
52 // threads, as well as code sharing.
54 // ScreenCaptureDeviceCore manages a simple state machine and the pipeline
55 // (see notes at top of this file). It times the start of successive captures
56 // and facilitates the processing of each through the stages of the
57 // pipeline.
58 class MEDIA_EXPORT ScreenCaptureDeviceCore
59 : public base::SupportsWeakPtr<ScreenCaptureDeviceCore> {
60 public:
61 ScreenCaptureDeviceCore(scoped_ptr<VideoCaptureMachine> capture_machine);
62 virtual ~ScreenCaptureDeviceCore();
64 // Asynchronous requests to change ScreenCaptureDeviceCore state.
65 void AllocateAndStart(const VideoCaptureParams& params,
66 scoped_ptr<VideoCaptureDevice::Client> client);
67 void StopAndDeAllocate();
69 private:
70 // Flag indicating current state.
71 enum State { kIdle, kCapturing, kError };
73 void TransitionStateTo(State next_state);
75 // Called back in response to StartCaptureMachine(). |success| is true if
76 // capture machine succeeded to start.
77 void CaptureStarted(bool success);
79 // Stops capturing and notifies client_ of an error state.
80 void Error(const std::string& reason);
82 // Tracks that all activity occurs on the media stream manager's thread.
83 base::ThreadChecker thread_checker_;
85 // Current lifecycle state.
86 State state_;
88 // Tracks the CaptureMachine that's doing work on our behalf
89 // on the device thread or UI thread.
90 // This value should never be dereferenced by this class.
91 scoped_ptr<VideoCaptureMachine> capture_machine_;
93 // Our thread-safe capture oracle which serves as the gateway to the video
94 // capture pipeline. Besides the VideoCaptureDevice itself, it is the only
95 // component of the system with direct access to |client_|.
96 scoped_refptr<ThreadSafeCaptureOracle> oracle_proxy_;
98 DISALLOW_COPY_AND_ASSIGN(ScreenCaptureDeviceCore);
101 } // namespace media
103 #endif // MEDIA_CAPTURE_SCREEN_CAPTURE_DEVICE_CORE_H_