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 REMOTING_HOST_VIDEO_FRAME_RECORDER_H_ | 5 #ifndef REMOTING_HOST_VIDEO_FRAME_RECORDER_H_ |
6 #define REMOTING_HOST_VIDEO_FRAME_RECORDER_H_ | 6 #define REMOTING_HOST_VIDEO_FRAME_RECORDER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <list> | 9 #include <list> |
10 | 10 |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
15 | 15 |
16 namespace webrtc { | 16 namespace webrtc { |
17 class DesktopFrame; | 17 class DesktopFrame; |
18 } | 18 } |
19 | 19 |
20 namespace remoting { | 20 namespace remoting { |
21 | 21 |
22 class VideoEncoder; | 22 class VideoEncoder; |
23 | 23 |
24 // Allows sequences of DesktopFrames passed to a VideoEncoder to be recorded. | 24 // Allows sequences of DesktopFrames passed to a VideoEncoder to be recorded. |
25 // | 25 // |
26 // VideoFrameRecorder is design to support applications which use a dedicated | 26 // VideoFrameRecorder is designed to support applications which use a dedicated |
27 // thread for video encoding, but need to manage that process from a "main" | 27 // thread for video encoding, but need to manage that process from a "main" |
28 // or "control" thread. | 28 // or "control" thread. |
29 // | 29 // |
30 // On the control thread: | 30 // On the control thread: |
31 // 1. Create the VideoFrameRecorder on the controlling thread. | 31 // 1. Create the VideoFrameRecorder on the controlling thread. |
32 // 2. Specify the amount of memory that may be used for recording. | 32 // 2. Specify the amount of memory that may be used for recording. |
33 // 3. Call WrapVideoEncoder(), passing the actual VideoEncoder that will be | 33 // 3. Call WrapVideoEncoder(), passing the actual VideoEncoder that will be |
34 // used to encode frames. | 34 // used to encode frames. |
35 // 4. Hand the returned wrapper VideoEncoder of to the video encoding thread, | 35 // 4. Hand the returned wrapper VideoEncoder of to the video encoding thread, |
36 // to call in place of the actual VideoEncoder. | 36 // to call in place of the actual VideoEncoder. |
37 // 5. Start/stop frame recording as necessary. | 37 // 5. Start/stop frame recording as necessary. |
38 // 6. Use NextFrame() to read each recorded frame in sequence. | 38 // 6. Use NextFrame() to read each recorded frame in sequence. |
39 // | 39 // |
40 // The wrapper VideoEncoder is designed to be handed off to the video encoding | 40 // The wrapper VideoEncoder is designed to be handed off to the video encoding |
41 // thread, and used and torn down there. | 41 // thread, and used and torn down there. |
42 // | 42 // |
43 // The VideoFrameRecorder and VideoEncoder may be torn down in any order; frame | 43 // The VideoFrameRecorder and VideoEncoder may be torn down in any order; frame |
44 // recording will stop as soon as either is destroyed. | 44 // recording will stop as soon as either is destroyed. |
45 | 45 |
46 class VideoFrameRecorder { | 46 class VideoFrameRecorder { |
47 public: | 47 public: |
48 VideoFrameRecorder(); | 48 VideoFrameRecorder(); |
49 virtual ~VideoFrameRecorder(); | 49 virtual ~VideoFrameRecorder(); |
50 | 50 |
51 // Wraps the supplied VideoEncoder, returning a replacement VideoEncoder that | 51 // Wraps the supplied VideoEncoder, returning a replacement VideoEncoder that |
52 // will route frames to the recorder, as well as passing them for encoding. | 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. | 53 // The caller must delete the previous recording VideoEncoder, or call |
54 // DetachVideoEncoderWrapper() before calling WrapVideoEncoder() to create | |
55 // a new wrapper. | |
Jamie
2014/08/01 19:53:51
This seems fragile. Why can't Wrap call Detach aut
Wez
2014/08/01 22:33:56
If you create a second wrapper then it'll replace
| |
54 scoped_ptr<VideoEncoder> WrapVideoEncoder(scoped_ptr<VideoEncoder> encoder); | 56 scoped_ptr<VideoEncoder> WrapVideoEncoder(scoped_ptr<VideoEncoder> encoder); |
55 | 57 |
58 // Detaches the existing VideoEncoder wrapper, stopping it from recording. | |
59 void DetachVideoEncoderWrapper(); | |
60 | |
56 // Enables/disables frame recording. Frame recording is initially disabled. | 61 // Enables/disables frame recording. Frame recording is initially disabled. |
57 void SetEnableRecording(bool enable_recording); | 62 void SetEnableRecording(bool enable_recording); |
58 | 63 |
59 // Sets the maximum number of bytes of pixel data that may be recorded. | 64 // 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 | 65 // When this maximum is reached older frames will be discard to make space |
61 // for new ones. | 66 // for new ones. |
62 void SetMaxContentBytes(int64_t max_content_bytes); | 67 void SetMaxContentBytes(int64_t max_content_bytes); |
63 | 68 |
64 // Pops the next recorded frame in the sequence, and returns it. | 69 // Pops the next recorded frame in the sequence, and returns it. |
65 scoped_ptr<webrtc::DesktopFrame> NextFrame(); | 70 scoped_ptr<webrtc::DesktopFrame> NextFrame(); |
(...skipping 25 matching lines...) Expand all Loading... | |
91 | 96 |
92 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_; | 97 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_; |
93 base::WeakPtrFactory<VideoFrameRecorder> weak_factory_; | 98 base::WeakPtrFactory<VideoFrameRecorder> weak_factory_; |
94 | 99 |
95 DISALLOW_COPY_AND_ASSIGN(VideoFrameRecorder); | 100 DISALLOW_COPY_AND_ASSIGN(VideoFrameRecorder); |
96 }; | 101 }; |
97 | 102 |
98 } // namespace remoting | 103 } // namespace remoting |
99 | 104 |
100 #endif // REMOTING_HOST_VIDEO_FRAME_RECORDER_H_ | 105 #endif // REMOTING_HOST_VIDEO_FRAME_RECORDER_H_ |
OLD | NEW |