Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2015 The Chromium Authors |
lionel.g.landwerlin | 7918cb6 | 2015-03-23 16:35:46 | [diff] [blame] | 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_PEPPER_VIDEO_ENCODER_SHIM_H_ |
| 6 | #define CONTENT_RENDERER_PEPPER_VIDEO_ENCODER_SHIM_H_ |
| 7 | |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 8 | #include <stddef.h> |
| 9 | #include <stdint.h> |
| 10 | |
dcheng | cedca561 | 2016-04-09 01:40:15 | [diff] [blame] | 11 | #include <memory> |
lionel.g.landwerlin | 7918cb6 | 2015-03-23 16:35:46 | [diff] [blame] | 12 | #include <vector> |
| 13 | |
Kalvin Lee | bc3754ae | 2023-10-01 22:37:34 | [diff] [blame] | 14 | #include "base/memory/raw_ptr.h" |
lionel.g.landwerlin | 7918cb6 | 2015-03-23 16:35:46 | [diff] [blame] | 15 | #include "base/memory/weak_ptr.h" |
Markus Handell | 2878995f | 2022-10-14 07:32:09 | [diff] [blame] | 16 | #include "base/task/sequenced_task_runner.h" |
Clarissa Garvey | 2dac3a7 | 2021-07-14 03:24:50 | [diff] [blame] | 17 | #include "media/base/bitrate.h" |
Phil Yan | 34737a1 | 2025-03-26 23:10:14 | [diff] [blame] | 18 | #include "media/base/encoder_status.h" |
lionel.g.landwerlin | 7918cb6 | 2015-03-23 16:35:46 | [diff] [blame] | 19 | #include "media/video/video_encode_accelerator.h" |
| 20 | |
lionel.g.landwerlin | 7918cb6 | 2015-03-23 16:35:46 | [diff] [blame] | 21 | namespace gfx { |
| 22 | class Size; |
| 23 | } |
| 24 | |
| 25 | namespace content { |
| 26 | |
| 27 | class PepperVideoEncoderHost; |
| 28 | |
| 29 | // This class is a shim to wrap a media::cast::SoftwareVideoEncoder so that it |
| 30 | // can be used by PepperVideoEncoderHost in place of a |
| 31 | // media::VideoEncodeAccelerator. This class should be constructed, used, and |
| 32 | // destructed on the main (render) thread. |
| 33 | class VideoEncoderShim : public media::VideoEncodeAccelerator { |
| 34 | public: |
| 35 | explicit VideoEncoderShim(PepperVideoEncoderHost* host); |
Peter Boström | 828b902 | 2021-09-21 02:28:43 | [diff] [blame] | 36 | |
| 37 | VideoEncoderShim(const VideoEncoderShim&) = delete; |
| 38 | VideoEncoderShim& operator=(const VideoEncoderShim&) = delete; |
| 39 | |
lionel.g.landwerlin | 7918cb6 | 2015-03-23 16:35:46 | [diff] [blame] | 40 | ~VideoEncoderShim() override; |
| 41 | |
| 42 | // media::VideoEncodeAccelerator implementation. |
henryhsu | d118544 | 2015-04-10 06:39:14 | [diff] [blame] | 43 | media::VideoEncodeAccelerator::SupportedProfiles GetSupportedProfiles() |
| 44 | override; |
Phil Yan | 34737a1 | 2025-03-26 23:10:14 | [diff] [blame] | 45 | media::EncoderStatus Initialize( |
François Beaufort | cf0f41d | 2022-03-08 23:28:30 | [diff] [blame] | 46 | const media::VideoEncodeAccelerator::Config& config, |
| 47 | media::VideoEncodeAccelerator::Client* client, |
| 48 | std::unique_ptr<media::MediaLog> media_log = nullptr) override; |
John Rummell | 70cf8feb | 2019-05-16 19:13:58 | [diff] [blame] | 49 | void Encode(scoped_refptr<media::VideoFrame> frame, |
lionel.g.landwerlin | 7918cb6 | 2015-03-23 16:35:46 | [diff] [blame] | 50 | bool force_keyframe) override; |
Matthew Cary | 1ad95fe8 | 2019-05-15 12:51:33 | [diff] [blame] | 51 | void UseOutputBitstreamBuffer(media::BitstreamBuffer buffer) override; |
Jianjun Zhu | dc172fed | 2023-11-27 03:10:21 | [diff] [blame] | 52 | void RequestEncodingParametersChange( |
| 53 | const media::Bitrate& bitrate, |
| 54 | uint32_t framerate, |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 55 | const std::optional<gfx::Size>& size) override; |
lionel.g.landwerlin | 7918cb6 | 2015-03-23 16:35:46 | [diff] [blame] | 56 | void Destroy() override; |
| 57 | |
| 58 | private: |
| 59 | class EncoderImpl; |
| 60 | |
| 61 | void OnRequireBitstreamBuffers(unsigned int input_count, |
| 62 | const gfx::Size& input_coded_size, |
| 63 | size_t output_buffer_size); |
| 64 | void OnBitstreamBufferReady(scoped_refptr<media::VideoFrame> frame, |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 65 | int32_t bitstream_buffer_id, |
lionel.g.landwerlin | 7918cb6 | 2015-03-23 16:35:46 | [diff] [blame] | 66 | size_t payload_size, |
| 67 | bool key_frame); |
Hirokazu Honda | 86ab7de7 | 2023-04-18 06:03:44 | [diff] [blame] | 68 | void OnNotifyErrorStatus(const media::EncoderStatus& status); |
lionel.g.landwerlin | 7918cb6 | 2015-03-23 16:35:46 | [diff] [blame] | 69 | |
dcheng | cedca561 | 2016-04-09 01:40:15 | [diff] [blame] | 70 | std::unique_ptr<EncoderImpl> encoder_impl_; |
lionel.g.landwerlin | 7918cb6 | 2015-03-23 16:35:46 | [diff] [blame] | 71 | |
Bartek Nowierski | f473c24b | 2024-02-20 17:51:15 | [diff] [blame] | 72 | raw_ptr<PepperVideoEncoderHost> host_; |
lionel.g.landwerlin | 7918cb6 | 2015-03-23 16:35:46 | [diff] [blame] | 73 | |
| 74 | // Task doing the encoding. |
Markus Handell | 2878995f | 2022-10-14 07:32:09 | [diff] [blame] | 75 | scoped_refptr<base::SequencedTaskRunner> media_task_runner_; |
lionel.g.landwerlin | 7918cb6 | 2015-03-23 16:35:46 | [diff] [blame] | 76 | |
Jeremy Roman | 3bca4bf | 2019-07-11 03:41:25 | [diff] [blame] | 77 | base::WeakPtrFactory<VideoEncoderShim> weak_ptr_factory_{this}; |
lionel.g.landwerlin | 7918cb6 | 2015-03-23 16:35:46 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | } // namespace content |
| 81 | |
| 82 | #endif // CONTENT_RENDERER_PEPPER_VIDEO_ENCODER_SHIM_H_ |