Move UpdateManifest test from unit_tests into extensions_unittests.
[chromium-blink-merge.git] / media / capture / thread_safe_capture_oracle.h
blobc5d83dfee7b2d1aeb421d1440ad9563a7c02bd35
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_THREAD_SAFE_CAPTURE_ORACLE_H_
6 #define MEDIA_CAPTURE_THREAD_SAFE_CAPTURE_ORACLE_H_
8 #include <string>
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "media/base/media_export.h"
13 #include "media/base/video_frame.h"
14 #include "media/capture/video_capture_oracle.h"
15 #include "media/video/capture/video_capture_device.h"
17 namespace media {
19 struct VideoCaptureParams;
20 class VideoFrame;
22 // Thread-safe, refcounted proxy to the VideoCaptureOracle. This proxy wraps
23 // the VideoCaptureOracle, which decides which frames to capture, and a
24 // VideoCaptureDevice::Client, which allocates and receives the captured
25 // frames, in a lock to synchronize state between the two.
26 class MEDIA_EXPORT ThreadSafeCaptureOracle
27 : public base::RefCountedThreadSafe<ThreadSafeCaptureOracle> {
28 public:
29 ThreadSafeCaptureOracle(scoped_ptr<VideoCaptureDevice::Client> client,
30 const VideoCaptureParams& params,
31 bool enable_auto_throttling);
33 // Called when a captured frame is available or an error has occurred.
34 // If |success| is true then |frame| is valid and |timestamp| indicates when
35 // the frame was painted.
36 // If |success| is false, all other parameters are invalid.
37 typedef base::Callback<void(const scoped_refptr<VideoFrame>& frame,
38 base::TimeTicks timestamp,
39 bool success)> CaptureFrameCallback;
41 bool ObserveEventAndDecideCapture(VideoCaptureOracle::Event event,
42 const gfx::Rect& damage_rect,
43 base::TimeTicks event_time,
44 scoped_refptr<VideoFrame>* storage,
45 CaptureFrameCallback* callback);
47 base::TimeDelta min_capture_period() const {
48 return oracle_.min_capture_period();
51 gfx::Size max_frame_size() const {
52 return params_.requested_format.frame_size;
55 // Returns the current capture resolution.
56 gfx::Size GetCaptureSize() const;
58 // Updates capture resolution based on the supplied source size and the
59 // maximum frame size.
60 void UpdateCaptureSize(const gfx::Size& source_size);
62 // Stop new captures from happening (but doesn't forget the client).
63 void Stop();
65 // Signal an error to the client.
66 void ReportError(const std::string& reason);
68 private:
69 friend class base::RefCountedThreadSafe<ThreadSafeCaptureOracle>;
70 virtual ~ThreadSafeCaptureOracle();
72 // Callback invoked on completion of all captures.
73 void DidCaptureFrame(
74 int frame_number,
75 scoped_ptr<VideoCaptureDevice::Client::Buffer> buffer,
76 base::TimeTicks capture_begin_time,
77 base::TimeDelta estimated_frame_duration,
78 const scoped_refptr<VideoFrame>& frame,
79 base::TimeTicks timestamp,
80 bool success);
82 // Callback invoked once all consumers have finished with a delivered video
83 // frame. Consumer feedback signals are scanned from the frame's |metadata|.
84 void DidConsumeFrame(int frame_number,
85 const media::VideoFrameMetadata* metadata);
87 // Protects everything below it.
88 mutable base::Lock lock_;
90 // Recipient of our capture activity.
91 scoped_ptr<VideoCaptureDevice::Client> client_;
93 // Makes the decision to capture a frame.
94 VideoCaptureOracle oracle_;
96 // The video capture parameters used to construct the oracle proxy.
97 const VideoCaptureParams params_;
100 } // namespace media
102 #endif // MEDIA_CAPTURE_THREAD_SAFE_CAPTURE_ORACLE_H_