OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 CONTENT_BROWSER_DEVTOOLS_PROTOCOL_FRAME_RECORDER_H_ | 5 #ifndef CONTENT_BROWSER_DEVTOOLS_PROTOCOL_FRAME_RECORDER_H_ |
6 #define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_FRAME_RECORDER_H_ | 6 #define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_FRAME_RECORDER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
| 9 #include <utility> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/cancelable_callback.h" |
12 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
13 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
14 #include "base/time/time.h" | 16 #include "base/time/time.h" |
15 #include "content/browser/devtools/protocol/devtools_protocol_handler.h" | 17 #include "content/browser/devtools/protocol/devtools_protocol_handler.h" |
16 #include "content/public/browser/readback_types.h" | 18 #include "content/public/browser/readback_types.h" |
17 | 19 |
18 class SkBitmap; | 20 class SkBitmap; |
19 | 21 |
20 namespace content { | 22 namespace content { |
21 | 23 |
22 class RenderViewHostImpl; | 24 class RenderViewHostImpl; |
23 | 25 |
24 namespace devtools { | 26 namespace devtools { |
25 namespace page { | 27 namespace page { |
26 | 28 |
| 29 using EncodedFrame = std::pair<std::string, double>; |
| 30 |
27 class FrameRecorder { | 31 class FrameRecorder { |
28 public: | 32 public: |
29 using Response = DevToolsProtocolClient::Response; | 33 using Response = DevToolsProtocolClient::Response; |
30 using StopRecordingFramesCallback = | 34 using StopRecordingFramesCallback = |
31 base::Callback<void(scoped_refptr<StopRecordingFramesResponse>)>; | 35 base::Callback<void(scoped_refptr<StopRecordingFramesResponse>)>; |
32 | 36 |
33 explicit FrameRecorder(); | 37 explicit FrameRecorder(); |
34 virtual ~FrameRecorder(); | 38 virtual ~FrameRecorder(); |
35 | 39 |
36 Response StartRecordingFrames(int max_frame_count); | 40 Response StartRecordingFrames(int max_frame_count); |
37 Response StopRecordingFrames(StopRecordingFramesCallback callback); | 41 Response StopRecordingFrames(StopRecordingFramesCallback callback); |
| 42 Response CancelRecordingFrames(); |
38 | 43 |
39 void SetRenderViewHost(RenderViewHostImpl* host); | 44 void SetRenderViewHost(RenderViewHostImpl* host); |
40 void OnSwapCompositorFrame(); | 45 void OnSwapCompositorFrame(); |
41 | 46 |
42 private: | 47 private: |
43 enum State { | 48 enum State { |
44 Ready, | 49 Ready, |
45 Recording, | 50 Recording, |
46 Encoding | 51 Encoding |
47 }; | 52 }; |
48 | 53 |
49 void FrameCaptured(const SkBitmap& bitmap, ReadbackResponse response); | 54 void FrameCaptured(const SkBitmap& bitmap, ReadbackResponse response); |
50 void FrameEncoded(double timestamp, const std::string& encoded_frame); | 55 void FrameEncoded(const scoped_ptr<EncodedFrame>& encoded_frame); |
51 void MaybeSendResponse(); | 56 void MaybeSendResponse(); |
52 | 57 |
53 RenderViewHostImpl* host_; | 58 RenderViewHostImpl* host_; |
54 State state_; | 59 State state_; |
55 StopRecordingFramesCallback callback_; | 60 StopRecordingFramesCallback callback_; |
56 size_t inflight_requests_count_; | 61 size_t inflight_requests_count_; |
57 size_t max_frame_count_; | 62 size_t max_frame_count_; |
58 size_t captured_frames_count_; | 63 size_t captured_frames_count_; |
59 base::Time last_captured_frame_timestamp_; | 64 base::Time last_captured_frame_timestamp_; |
60 std::vector<scoped_refptr<devtools::page::RecordedFrame>> frames_; | 65 std::vector<scoped_refptr<devtools::page::RecordedFrame>> frames_; |
61 | 66 |
| 67 base::CancelableCallback<void(const scoped_ptr<EncodedFrame>&)> |
| 68 frame_encoded_callback_; |
62 base::WeakPtrFactory<FrameRecorder> weak_factory_; | 69 base::WeakPtrFactory<FrameRecorder> weak_factory_; |
63 | 70 |
64 DISALLOW_COPY_AND_ASSIGN(FrameRecorder); | 71 DISALLOW_COPY_AND_ASSIGN(FrameRecorder); |
65 }; | 72 }; |
66 | 73 |
67 } // namespace page | 74 } // namespace page |
68 } // namespace devtools | 75 } // namespace devtools |
69 } // namespace content | 76 } // namespace content |
70 | 77 |
71 #endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_FRAME_RECORDER_H_ | 78 #endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_FRAME_RECORDER_H_ |
OLD | NEW |