Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / media / capture / content / thread_safe_capture_oracle.h
blob1aa905e37f1171a12debfb247c322589eed9e0f4
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/content/video_capture_oracle.h"
15 #include "media/capture/video/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(int frame_number,
74 scoped_ptr<VideoCaptureDevice::Client::Buffer> buffer,
75 base::TimeTicks capture_begin_time,
76 base::TimeDelta estimated_frame_duration,
77 const scoped_refptr<VideoFrame>& frame,
78 base::TimeTicks timestamp,
79 bool success);
81 // Callback invoked once all consumers have finished with a delivered video
82 // frame. Consumer feedback signals are scanned from the frame's |metadata|.
83 void DidConsumeFrame(int frame_number,
84 const media::VideoFrameMetadata* metadata);
86 // Protects everything below it.
87 mutable base::Lock lock_;
89 // Recipient of our capture activity.
90 scoped_ptr<VideoCaptureDevice::Client> client_;
92 // Makes the decision to capture a frame.
93 VideoCaptureOracle oracle_;
95 // The video capture parameters used to construct the oracle proxy.
96 const VideoCaptureParams params_;
99 } // namespace media
101 #endif // MEDIA_CAPTURE_THREAD_SAFE_CAPTURE_ORACLE_H_