OLD | NEW |
(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 on 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 const VideoTrackRecorder::OnErrorCB& on_error_callback, |
| 33 int32_t bits_per_second, |
| 34 media::VideoCodecProfile codec, |
| 35 const gfx::Size& size); |
| 36 |
| 37 // media::VideoEncodeAccelerator::Client implementation. |
| 38 void RequireBitstreamBuffers(unsigned int input_count, |
| 39 const gfx::Size& input_coded_size, |
| 40 size_t output_buffer_size) override; |
| 41 void BitstreamBufferReady(int32_t bitstream_buffer_id, |
| 42 size_t payload_size, |
| 43 bool key_frame, |
| 44 base::TimeDelta timestamp) override; |
| 45 void NotifyError(media::VideoEncodeAccelerator::Error error) override; |
| 46 |
| 47 private: |
| 48 using VideoFrameAndTimestamp = |
| 49 std::pair<scoped_refptr<media::VideoFrame>, base::TimeTicks>; |
| 50 using VideoParamsAndTimestamp = |
| 51 std::pair<media::WebmMuxer::VideoParameters, base::TimeTicks>; |
| 52 |
| 53 void UseOutputBitstreamBufferId(int32_t bitstream_buffer_id); |
| 54 void FrameFinished(std::unique_ptr<base::SharedMemory> shm); |
| 55 |
| 56 // VideoTrackRecorder::Encoder implementation. |
| 57 ~VEAEncoder() override; |
| 58 void EncodeOnEncodingTaskRunner(scoped_refptr<media::VideoFrame> frame, |
| 59 base::TimeTicks capture_timestamp) override; |
| 60 |
| 61 void ConfigureEncoderOnEncodingTaskRunner(const gfx::Size& size); |
| 62 |
| 63 void DestroyOnEncodingTaskRunner(base::WaitableEvent* async_waiter); |
| 64 |
| 65 media::GpuVideoAcceleratorFactories* const gpu_factories_; |
| 66 |
| 67 const media::VideoCodecProfile codec_; |
| 68 |
| 69 // The underlying VEA to perform encoding on. |
| 70 std::unique_ptr<media::VideoEncodeAccelerator> video_encoder_; |
| 71 |
| 72 // Shared memory buffers for output with the VEA. |
| 73 std::vector<std::unique_ptr<base::SharedMemory>> output_buffers_; |
| 74 |
| 75 // Shared memory buffers for output with the VEA as FIFO. |
| 76 std::queue<std::unique_ptr<base::SharedMemory>> input_buffers_; |
| 77 |
| 78 // Tracks error status. |
| 79 bool error_notified_; |
| 80 |
| 81 // Tracks the last frame that we delay the encode. |
| 82 std::unique_ptr<VideoFrameAndTimestamp> last_frame_; |
| 83 |
| 84 // Size used to initialize encoder. |
| 85 gfx::Size input_visible_size_; |
| 86 |
| 87 // Coded size that encoder requests as input. |
| 88 gfx::Size vea_requested_input_coded_size_; |
| 89 |
| 90 // Frames and corresponding timestamps in encode as FIFO. |
| 91 std::queue<VideoParamsAndTimestamp> frames_in_encode_; |
| 92 |
| 93 // This callback can be exercised on any thread. |
| 94 const VideoTrackRecorder::OnErrorCB on_error_callback_; |
| 95 }; |
| 96 |
| 97 } // namespace content |
| 98 |
| 99 #endif // CONTENT_RENDERER_MEDIA_RECORDER_VEA_ENCODER_H_ |
OLD | NEW |