Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: content/renderer/media_recorder/vea_encoder.h

Issue 2793303003: Refactor VideoTrackRecorder into smaller classes (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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 CONTENT_RENDERER_MEDIA_RECORDER_VEA_ENCODER_H_
6 #define CONTENT_RENDERER_MEDIA_RECORDER_VEA_ENCODER_H_
7
8 #include <queue>
9
10 #include "content/renderer/media_recorder/video_track_recorder.h"
11 #include "media/video/video_encode_accelerator.h"
12 #include "ui/gfx/geometry/size.h"
13
14 namespace base {
15 class WaitableEvent;
16 } // namespace base
17
18 namespace media {
19 class GpuVideoAcceleratorFactories;
20 } // namespace media
21
22 namespace content {
23
24 // Class encapsulating VideoEncodeAccelerator interactions.
25 // This class is created and destroyed in its owner thread. All other methods
26 // operate on the task runner pointed by GpuFactories.
27 class VEAEncoder final : public VideoTrackRecorder::Encoder,
28 public media::VideoEncodeAccelerator::Client {
29 public:
30 VEAEncoder(
31 const VideoTrackRecorder::OnEncodedVideoCB& on_encoded_video_callback,
32 int32_t bits_per_second,
33 media::VideoCodecProfile codec,
34 const gfx::Size& size);
35
36 // media::VideoEncodeAccelerator::Client implementation.
37 void RequireBitstreamBuffers(unsigned int input_count,
38 const gfx::Size& input_coded_size,
39 size_t output_buffer_size) override;
40 void BitstreamBufferReady(int32_t bitstream_buffer_id,
41 size_t payload_size,
42 bool key_frame,
43 base::TimeDelta timestamp) override;
44 void NotifyError(media::VideoEncodeAccelerator::Error error) override;
45
46 private:
47 using VideoFrameAndTimestamp =
48 std::pair<scoped_refptr<media::VideoFrame>, base::TimeTicks>;
49 using VideoParamsAndTimestamp =
50 std::pair<media::WebmMuxer::VideoParameters, base::TimeTicks>;
51
52 void UseOutputBitstreamBufferId(int32_t bitstream_buffer_id);
53 void FrameFinished(std::unique_ptr<base::SharedMemory> shm);
54
55 // VideoTrackRecorder::Encoder implementation.
56 ~VEAEncoder() override;
57 void EncodeOnEncodingTaskRunner(scoped_refptr<media::VideoFrame> frame,
58 base::TimeTicks capture_timestamp) override;
59
60 void ConfigureEncoderOnEncodingTaskRunner(const gfx::Size& size);
61
62 void DestroyOnEncodingTaskRunner(base::WaitableEvent* async_waiter);
63
64 media::GpuVideoAcceleratorFactories* const gpu_factories_;
65
66 const media::VideoCodecProfile codec_;
67
68 // The underlying VEA to perform encoding on.
69 std::unique_ptr<media::VideoEncodeAccelerator> video_encoder_;
70
71 // Shared memory buffers for output with the VEA.
72 std::vector<std::unique_ptr<base::SharedMemory>> output_buffers_;
73
74 // Shared memory buffers for output with the VEA as FIFO.
75 std::queue<std::unique_ptr<base::SharedMemory>> input_buffers_;
76
77 // Tracks error status.
78 bool error_notified_;
79
80 // Tracks the last frame that we delay the encode.
81 std::unique_ptr<VideoFrameAndTimestamp> last_frame_;
82
83 // Size used to initialize encoder.
84 gfx::Size input_visible_size_;
85
86 // Coded size that encoder requests as input.
87 gfx::Size vea_requested_input_coded_size_;
88
89 // Frames and corresponding timestamps in encode as FIFO.
90 std::queue<VideoParamsAndTimestamp> frames_in_encode_;
91 };
92
93 } // namespace content
94
95 #endif // CONTENT_RENDERER_MEDIA_RECORDER_VEA_ENCODER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698