| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MEDIA_CAPTURE_CONTENT_VIDEO_CAPTURE_ORACLE_H_ | 5 #ifndef MEDIA_CAPTURE_CONTENT_VIDEO_CAPTURE_ORACLE_H_ |
| 6 #define MEDIA_CAPTURE_CONTENT_VIDEO_CAPTURE_ORACLE_H_ | 6 #define MEDIA_CAPTURE_CONTENT_VIDEO_CAPTURE_ORACLE_H_ |
| 7 | 7 |
| 8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "media/base/media_export.h" | 11 #include "media/base/media_export.h" |
| 12 #include "media/capture/content/animated_content_sampler.h" | 12 #include "media/capture/content/animated_content_sampler.h" |
| 13 #include "media/capture/content/capture_resolution_chooser.h" | 13 #include "media/capture/content/capture_resolution_chooser.h" |
| 14 #include "media/capture/content/feedback_signal_accumulator.cc" | 14 #include "media/capture/content/feedback_signal_accumulator.cc" |
| 15 #include "media/capture/content/smooth_event_sampler.h" | 15 #include "media/capture/content/smooth_event_sampler.h" |
| 16 #include "ui/gfx/geometry/rect.h" | 16 #include "ui/gfx/geometry/rect.h" |
| 17 | 17 |
| 18 namespace media { | 18 namespace media { |
| 19 | 19 |
| 20 // VideoCaptureOracle manages the producer-side throttling of captured frames | 20 // VideoCaptureOracle manages the producer-side throttling of captured frames |
| 21 // from a video capture device. It is informed of every update by the device; | 21 // from a video capture device. It is informed of every update by the device; |
| 22 // this empowers it to look into the future and decide if a particular frame | 22 // this empowers it to look into the future and decide if a particular frame |
| 23 // ought to be captured in order to achieve its target frame rate. | 23 // ought to be captured in order to achieve its target frame rate. |
| 24 class MEDIA_EXPORT VideoCaptureOracle { | 24 class MEDIA_EXPORT VideoCaptureOracle { |
| 25 public: | 25 public: |
| 26 enum Event { | 26 enum Event { |
| 27 kTimerPoll, | |
| 28 kCompositorUpdate, | 27 kCompositorUpdate, |
| 28 kActiveRefreshRequest, |
| 29 kPassiveRefreshRequest, |
| 29 kMouseCursorUpdate, | 30 kMouseCursorUpdate, |
| 30 kNumEvents, | 31 kNumEvents, |
| 31 }; | 32 }; |
| 32 | 33 |
| 33 enum { | |
| 34 // The recommended minimum amount of time between calls to | |
| 35 // ObserveEventAndDecideCapture() for the kTimerPoll Event type. Anything | |
| 36 // lower than this isn't harmful, just wasteful. | |
| 37 kMinTimerPollPeriodMillis = 125, // 8 FPS | |
| 38 }; | |
| 39 | |
| 40 VideoCaptureOracle(base::TimeDelta min_capture_period, | 34 VideoCaptureOracle(base::TimeDelta min_capture_period, |
| 41 const gfx::Size& max_frame_size, | 35 const gfx::Size& max_frame_size, |
| 42 media::ResolutionChangePolicy resolution_change_policy, | 36 media::ResolutionChangePolicy resolution_change_policy, |
| 43 bool enable_auto_throttling); | 37 bool enable_auto_throttling); |
| 44 | 38 |
| 45 virtual ~VideoCaptureOracle(); | 39 virtual ~VideoCaptureOracle(); |
| 46 | 40 |
| 47 // Sets the source content size. This may not have an immediate effect on the | 41 // Sets the source content size. This may not have an immediate effect on the |
| 48 // proposed capture size, as the oracle will prevent too-frequent changes from | 42 // proposed capture size, as the oracle will prevent too-frequent changes from |
| 49 // occurring. | 43 // occurring. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 // Returns the capture frame size the client should use. This is updated by | 91 // Returns the capture frame size the client should use. This is updated by |
| 98 // calls to ObserveEventAndDecideCapture(). The oracle prevents too-frequent | 92 // calls to ObserveEventAndDecideCapture(). The oracle prevents too-frequent |
| 99 // changes to the capture size, to avoid stressing the end-to-end pipeline. | 93 // changes to the capture size, to avoid stressing the end-to-end pipeline. |
| 100 gfx::Size capture_size() const { return capture_size_; } | 94 gfx::Size capture_size() const { return capture_size_; } |
| 101 | 95 |
| 102 // Returns the oracle's estimate of the last time animation was detected. | 96 // Returns the oracle's estimate of the last time animation was detected. |
| 103 base::TimeTicks last_time_animation_was_detected() const { | 97 base::TimeTicks last_time_animation_was_detected() const { |
| 104 return last_time_animation_was_detected_; | 98 return last_time_animation_was_detected_; |
| 105 } | 99 } |
| 106 | 100 |
| 101 // Returns a NUL-terminated string containing a short, human-readable form of |
| 102 // |event|. |
| 103 static const char* EventAsString(Event event); |
| 104 |
| 107 private: | 105 private: |
| 108 // Retrieve/Assign a frame timestamp by capture |frame_number|. Only valid | 106 // Retrieve/Assign a frame timestamp by capture |frame_number|. Only valid |
| 109 // when IsFrameInRecentHistory(frame_number) returns true. | 107 // when IsFrameInRecentHistory(frame_number) returns true. |
| 110 base::TimeTicks GetFrameTimestamp(int frame_number) const; | 108 base::TimeTicks GetFrameTimestamp(int frame_number) const; |
| 111 void SetFrameTimestamp(int frame_number, base::TimeTicks timestamp); | 109 void SetFrameTimestamp(int frame_number, base::TimeTicks timestamp); |
| 112 | 110 |
| 113 // Returns true if the frame timestamp ring-buffer currently includes a | 111 // Returns true if the frame timestamp ring-buffer currently includes a |
| 114 // slot for the given |frame_number|. | 112 // slot for the given |frame_number|. |
| 115 bool IsFrameInRecentHistory(int frame_number) const; | 113 bool IsFrameInRecentHistory(int frame_number) const; |
| 116 | 114 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 | 197 |
| 200 // The timestamp of the frame where |content_sampler_| last detected | 198 // The timestamp of the frame where |content_sampler_| last detected |
| 201 // animation. This determines whether capture size increases will be | 199 // animation. This determines whether capture size increases will be |
| 202 // aggressive (because content is not animating). | 200 // aggressive (because content is not animating). |
| 203 base::TimeTicks last_time_animation_was_detected_; | 201 base::TimeTicks last_time_animation_was_detected_; |
| 204 }; | 202 }; |
| 205 | 203 |
| 206 } // namespace media | 204 } // namespace media |
| 207 | 205 |
| 208 #endif // MEDIA_CAPTURE_CONTENT_VIDEO_CAPTURE_ORACLE_H_ | 206 #endif // MEDIA_CAPTURE_CONTENT_VIDEO_CAPTURE_ORACLE_H_ |
| OLD | NEW |