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

Unified Diff: content/renderer/media_recorder/vea_encoder.h

Issue 2793303003: Refactor VideoTrackRecorder into smaller classes (Closed)
Patch Set: Rebase 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/media_recorder/h264_encoder.cc ('k') | content/renderer/media_recorder/vea_encoder.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/media_recorder/vea_encoder.h
diff --git a/content/renderer/media_recorder/vea_encoder.h b/content/renderer/media_recorder/vea_encoder.h
new file mode 100644
index 0000000000000000000000000000000000000000..3f27f565ad6e57c09cad8f95ba8b5233e765588c
--- /dev/null
+++ b/content/renderer/media_recorder/vea_encoder.h
@@ -0,0 +1,99 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_RENDERER_MEDIA_RECORDER_VEA_ENCODER_H_
+#define CONTENT_RENDERER_MEDIA_RECORDER_VEA_ENCODER_H_
+
+#include <queue>
+
+#include "content/renderer/media_recorder/video_track_recorder.h"
+#include "media/video/video_encode_accelerator.h"
+#include "ui/gfx/geometry/size.h"
+
+namespace base {
+class WaitableEvent;
+} // namespace base
+
+namespace media {
+class GpuVideoAcceleratorFactories;
+} // namespace media
+
+namespace content {
+
+// Class encapsulating VideoEncodeAccelerator interactions.
+// This class is created and destroyed on its owner thread. All other methods
+// operate on the task runner pointed by GpuFactories.
+class VEAEncoder final : public VideoTrackRecorder::Encoder,
+ public media::VideoEncodeAccelerator::Client {
+ public:
+ VEAEncoder(
+ const VideoTrackRecorder::OnEncodedVideoCB& on_encoded_video_callback,
+ const VideoTrackRecorder::OnErrorCB& on_error_callback,
+ int32_t bits_per_second,
+ media::VideoCodecProfile codec,
+ const gfx::Size& size);
+
+ // media::VideoEncodeAccelerator::Client implementation.
+ void RequireBitstreamBuffers(unsigned int input_count,
+ const gfx::Size& input_coded_size,
+ size_t output_buffer_size) override;
+ void BitstreamBufferReady(int32_t bitstream_buffer_id,
+ size_t payload_size,
+ bool key_frame,
+ base::TimeDelta timestamp) override;
+ void NotifyError(media::VideoEncodeAccelerator::Error error) override;
+
+ private:
+ using VideoFrameAndTimestamp =
+ std::pair<scoped_refptr<media::VideoFrame>, base::TimeTicks>;
+ using VideoParamsAndTimestamp =
+ std::pair<media::WebmMuxer::VideoParameters, base::TimeTicks>;
+
+ void UseOutputBitstreamBufferId(int32_t bitstream_buffer_id);
+ void FrameFinished(std::unique_ptr<base::SharedMemory> shm);
+
+ // VideoTrackRecorder::Encoder implementation.
+ ~VEAEncoder() override;
+ void EncodeOnEncodingTaskRunner(scoped_refptr<media::VideoFrame> frame,
+ base::TimeTicks capture_timestamp) override;
+
+ void ConfigureEncoderOnEncodingTaskRunner(const gfx::Size& size);
+
+ void DestroyOnEncodingTaskRunner(base::WaitableEvent* async_waiter);
+
+ media::GpuVideoAcceleratorFactories* const gpu_factories_;
+
+ const media::VideoCodecProfile codec_;
+
+ // The underlying VEA to perform encoding on.
+ std::unique_ptr<media::VideoEncodeAccelerator> video_encoder_;
+
+ // Shared memory buffers for output with the VEA.
+ std::vector<std::unique_ptr<base::SharedMemory>> output_buffers_;
+
+ // Shared memory buffers for output with the VEA as FIFO.
+ std::queue<std::unique_ptr<base::SharedMemory>> input_buffers_;
+
+ // Tracks error status.
+ bool error_notified_;
+
+ // Tracks the last frame that we delay the encode.
+ std::unique_ptr<VideoFrameAndTimestamp> last_frame_;
+
+ // Size used to initialize encoder.
+ gfx::Size input_visible_size_;
+
+ // Coded size that encoder requests as input.
+ gfx::Size vea_requested_input_coded_size_;
+
+ // Frames and corresponding timestamps in encode as FIFO.
+ std::queue<VideoParamsAndTimestamp> frames_in_encode_;
+
+ // This callback can be exercised on any thread.
+ const VideoTrackRecorder::OnErrorCB on_error_callback_;
+};
+
+} // namespace content
+
+#endif // CONTENT_RENDERER_MEDIA_RECORDER_VEA_ENCODER_H_
« no previous file with comments | « content/renderer/media_recorder/h264_encoder.cc ('k') | content/renderer/media_recorder/vea_encoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698