MemorySanitizer: blacklist two false positives.
[chromium-blink-merge.git] / remoting / host / video_frame_recorder.h
blobc204c9ac39cdbdd875ebdc6f22bbb02071597ca7
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 REMOTING_HOST_VIDEO_FRAME_RECORDER_H_
6 #define REMOTING_HOST_VIDEO_FRAME_RECORDER_H_
8 #include <stdint.h>
9 #include <list>
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"
16 namespace webrtc {
17 class DesktopFrame;
20 namespace remoting {
22 class VideoEncoder;
24 // Allows sequences of DesktopFrames passed to a VideoEncoder to be recorded.
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.
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.
40 // The wrapper VideoEncoder is designed to be handed off to the video encoding
41 // thread, and used and torn down there.
43 // The VideoFrameRecorder and VideoEncoder may be torn down in any order; frame
44 // recording will stop as soon as either is destroyed.
46 class VideoFrameRecorder {
47 public:
48 VideoFrameRecorder();
49 virtual ~VideoFrameRecorder();
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);
56 // Enables/disables frame recording. Frame recording is initially disabled.
57 void SetEnableRecording(bool enable_recording);
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);
64 // Pops the next recorded frame in the sequence, and returns it.
65 scoped_ptr<webrtc::DesktopFrame> NextFrame();
67 private:
68 class RecordingVideoEncoder;
69 friend class RecordingVideoEncoder;
71 void SetEncoderTaskRunner(scoped_refptr<base::TaskRunner> task_runner);
72 void RecordFrame(scoped_ptr<webrtc::DesktopFrame> frame);
74 // The recorded frames, in sequence.
75 std::list<webrtc::DesktopFrame*> recorded_frames_;
77 // Size of the recorded frames' content, in bytes.
78 int64_t content_bytes_;
80 // Size that recorded frames' content must not exceed.
81 int64_t max_content_bytes_;
83 // True if recording is started, false otherwise.
84 bool enable_recording_;
86 // Task runner on which the wrapper VideoEncoder is being run.
87 scoped_refptr<base::TaskRunner> encoder_task_runner_;
89 // Weak reference to the wrapper VideoEncoder, to use to control it.
90 base::WeakPtr<RecordingVideoEncoder> recording_encoder_;
92 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_;
93 base::WeakPtrFactory<VideoFrameRecorder> weak_factory_;
95 DISALLOW_COPY_AND_ASSIGN(VideoFrameRecorder);
98 } // namespace remoting
100 #endif // REMOTING_HOST_VIDEO_FRAME_RECORDER_H_