Remove INJECT_EVENTS permissions from test APKs.
[chromium-blink-merge.git] / media / capture / screen_capture_device_core.h
blob86c1fc57fe370180e8e01c868671014528fa8b47
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/thread_safe_capture_oracle.h"
15 #include "media/video/capture/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 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 private:
40 DISALLOW_COPY_AND_ASSIGN(VideoCaptureMachine);
43 // The "meat" of a content video capturer.
45 // Separating this from the "shell classes" WebContentsVideoCaptureDevice and
46 // DesktopCaptureDeviceAura allows safe destruction without needing to block any
47 // threads, as well as code sharing.
49 // ScreenCaptureDeviceCore manages a simple state machine and the pipeline
50 // (see notes at top of this file). It times the start of successive captures
51 // and facilitates the processing of each through the stages of the
52 // pipeline.
53 class MEDIA_EXPORT ScreenCaptureDeviceCore
54 : public base::SupportsWeakPtr<ScreenCaptureDeviceCore> {
55 public:
56 ScreenCaptureDeviceCore(
57 scoped_ptr<VideoCaptureMachine> capture_machine);
58 virtual ~ScreenCaptureDeviceCore();
60 // Asynchronous requests to change ScreenCaptureDeviceCore state.
61 void AllocateAndStart(const VideoCaptureParams& params,
62 scoped_ptr<VideoCaptureDevice::Client> client);
63 void StopAndDeAllocate();
65 private:
66 // Flag indicating current state.
67 enum State {
68 kIdle,
69 kCapturing,
70 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);
102 } // namespace media
104 #endif // MEDIA_CAPTURE_SCREEN_CAPTURE_DEVICE_CORE_H_