OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef REMOTING_HOST_VIDEO_FRAME_RECORDER_H_ | |
6 #define REMOTING_HOST_VIDEO_FRAME_RECORDER_H_ | |
7 | |
8 #include <stdint.h> | |
9 #include <list> | |
10 | |
11 #include "base/memory/ref_counted.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/memory/weak_ptr.h" | |
14 #include "base/single_thread_task_runner.h" | |
15 | |
16 namespace webrtc { | |
17 class DesktopFrame; | |
18 } | |
19 | |
20 namespace remoting { | |
21 | |
22 class VideoEncoder; | |
23 | |
24 // Allows sequences of DesktopFrames passed to a VideoEncoder to be recorded. | |
25 // | |
26 // VideoFrameRecorder is design to support applications which use a dedicated | |
27 // thread for video encoding, but need to manage that process from a "main" | |
28 // or "control" thread. | |
29 // | |
30 // On the control thread: | |
31 // 1. Create the VideoFrameRecorder on the controlling thread. | |
32 // 2. Specify the amount of memory that may be used for recording. | |
33 // 3. Call WrapVideoEncoder(), passing the actual VideoEncoder that will be | |
34 // used to encode frames. | |
35 // 4. Hand the returned wrapper VideoEncoder of to the video encoding thread, | |
36 // to call in place of the actual VideoEncoder. | |
37 // 5. Start/stop frame recording as necessary. | |
38 // 6. Use NextFrame() to read each recorded frame in sequence. | |
39 // | |
40 // The wrapper VideoEncoder is designed to be handed off to the video encoding | |
41 // thread, and used and torn down there. | |
42 // | |
43 // The VideoFrameRecorder and VideoEncoder may be torn down in any order; frame | |
44 // recording will stop as soon as either is destroyed. | |
45 | |
46 class VideoFrameRecorder { | |
47 public: | |
48 VideoFrameRecorder(); | |
49 virtual ~VideoFrameRecorder(); | |
50 | |
51 // Wraps the supplied VideoEncoder, returning a replacement VideoEncoder that | |
52 // will route frames to the recorder, as well as passing them for encoding. | |
53 // This may be called at most once on each VideoFrameRecorder instance. | |
54 scoped_ptr<VideoEncoder> WrapVideoEncoder(scoped_ptr<VideoEncoder> encoder); | |
55 | |
56 // Enables/disables frame recording. Frame recording is initially disabled. | |
57 void SetEnableRecording(bool enable_recording); | |
58 | |
59 // Sets the maximum number of bytes of pixel data that may be recorded. | |
60 // When this maximum is reached older frames will be discard to make space | |
61 // for new ones. | |
62 void SetMaxContentBytes(int64_t max_content_bytes); | |
63 | |
64 // Pops the next recorded frame in the sequence, and returns it. | |
65 scoped_ptr<webrtc::DesktopFrame> NextFrame(); | |
66 | |
67 private: | |
68 class RecordingVideoEncoder; | |
69 friend class RecordingVideoEncoder; | |
70 | |
71 void SetEncoderTaskRunner(scoped_refptr<base::TaskRunner> task_runner); | |
72 void RecordFrame(scoped_ptr<webrtc::DesktopFrame> frame); | |
73 | |
74 // The recorded frames, in sequence. | |
75 std::list<webrtc::DesktopFrame*> recorded_frames_; | |
76 | |
77 // Size of the recorded frames' content, in bytes. | |
78 int64_t content_bytes_; | |
79 | |
80 // Size that recorded frames' content must not exceed. | |
81 int64_t max_content_bytes_; | |
82 | |
83 // True if recording is started, false otherwise. | |
84 bool enable_recording_; | |
85 | |
86 // Task runner on which the wrapper VideoEncoder is being run. | |
87 scoped_refptr<base::TaskRunner> encoder_task_runner_; | |
88 | |
89 // Weak reference to the wrapper VideoEncoder, to use to control it. | |
90 base::WeakPtr<RecordingVideoEncoder> recording_encoder_; | |
91 | |
92 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_; | |
93 base::WeakPtrFactory<VideoFrameRecorder> weak_factory_; | |
94 | |
95 DISALLOW_COPY_AND_ASSIGN(VideoFrameRecorder); | |
96 }; | |
97 | |
98 } // namespace remoting | |
99 | |
100 #endif // REMOTING_HOST_VIDEO_FRAME_RECORDER_H_ | |
OLD | NEW |