lionel.g.landwerlin | 7918cb6 | 2015-03-23 16:35:46 | [diff] [blame] | 1 | // Copyright 2015 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_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 | |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 14 | #include "base/macros.h" |
lionel.g.landwerlin | 7918cb6 | 2015-03-23 16:35:46 | [diff] [blame] | 15 | #include "base/memory/weak_ptr.h" |
Clarissa Garvey | 2dac3a7 | 2021-07-14 03:24:50 | [diff] [blame^] | 16 | #include "media/base/bitrate.h" |
lionel.g.landwerlin | 7918cb6 | 2015-03-23 16:35:46 | [diff] [blame] | 17 | #include "media/video/video_encode_accelerator.h" |
| 18 | |
| 19 | namespace base { |
| 20 | class SingleThreadTaskRunner; |
| 21 | } |
| 22 | |
| 23 | namespace gfx { |
| 24 | class Size; |
| 25 | } |
| 26 | |
| 27 | namespace content { |
| 28 | |
| 29 | class PepperVideoEncoderHost; |
| 30 | |
| 31 | // This class is a shim to wrap a media::cast::SoftwareVideoEncoder so that it |
| 32 | // can be used by PepperVideoEncoderHost in place of a |
| 33 | // media::VideoEncodeAccelerator. This class should be constructed, used, and |
| 34 | // destructed on the main (render) thread. |
| 35 | class VideoEncoderShim : public media::VideoEncodeAccelerator { |
| 36 | public: |
| 37 | explicit VideoEncoderShim(PepperVideoEncoderHost* host); |
| 38 | ~VideoEncoderShim() override; |
| 39 | |
| 40 | // media::VideoEncodeAccelerator implementation. |
henryhsu | d118544 | 2015-04-10 06:39:14 | [diff] [blame] | 41 | media::VideoEncodeAccelerator::SupportedProfiles GetSupportedProfiles() |
| 42 | override; |
Pin-chih Lin | e6ff3d97 | 2018-07-27 11:15:04 | [diff] [blame] | 43 | bool Initialize(const media::VideoEncodeAccelerator::Config& config, |
lionel.g.landwerlin | 7918cb6 | 2015-03-23 16:35:46 | [diff] [blame] | 44 | media::VideoEncodeAccelerator::Client* client) override; |
John Rummell | 70cf8feb | 2019-05-16 19:13:58 | [diff] [blame] | 45 | void Encode(scoped_refptr<media::VideoFrame> frame, |
lionel.g.landwerlin | 7918cb6 | 2015-03-23 16:35:46 | [diff] [blame] | 46 | bool force_keyframe) override; |
Matthew Cary | 1ad95fe8 | 2019-05-15 12:51:33 | [diff] [blame] | 47 | void UseOutputBitstreamBuffer(media::BitstreamBuffer buffer) override; |
Clarissa Garvey | 2dac3a7 | 2021-07-14 03:24:50 | [diff] [blame^] | 48 | void RequestEncodingParametersChange(const media::Bitrate& bitrate, |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 49 | uint32_t framerate) override; |
lionel.g.landwerlin | 7918cb6 | 2015-03-23 16:35:46 | [diff] [blame] | 50 | void Destroy() override; |
| 51 | |
| 52 | private: |
| 53 | class EncoderImpl; |
| 54 | |
| 55 | void OnRequireBitstreamBuffers(unsigned int input_count, |
| 56 | const gfx::Size& input_coded_size, |
| 57 | size_t output_buffer_size); |
| 58 | void OnBitstreamBufferReady(scoped_refptr<media::VideoFrame> frame, |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 59 | int32_t bitstream_buffer_id, |
lionel.g.landwerlin | 7918cb6 | 2015-03-23 16:35:46 | [diff] [blame] | 60 | size_t payload_size, |
| 61 | bool key_frame); |
| 62 | void OnNotifyError(media::VideoEncodeAccelerator::Error error); |
| 63 | |
dcheng | cedca561 | 2016-04-09 01:40:15 | [diff] [blame] | 64 | std::unique_ptr<EncoderImpl> encoder_impl_; |
lionel.g.landwerlin | 7918cb6 | 2015-03-23 16:35:46 | [diff] [blame] | 65 | |
| 66 | PepperVideoEncoderHost* host_; |
| 67 | |
| 68 | // Task doing the encoding. |
| 69 | scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_; |
| 70 | |
Jeremy Roman | 3bca4bf | 2019-07-11 03:41:25 | [diff] [blame] | 71 | base::WeakPtrFactory<VideoEncoderShim> weak_ptr_factory_{this}; |
lionel.g.landwerlin | 7918cb6 | 2015-03-23 16:35:46 | [diff] [blame] | 72 | |
| 73 | DISALLOW_COPY_AND_ASSIGN(VideoEncoderShim); |
| 74 | }; |
| 75 | |
| 76 | } // namespace content |
| 77 | |
| 78 | #endif // CONTENT_RENDERER_PEPPER_VIDEO_ENCODER_SHIM_H_ |