blob: 20344f5e6d87e41bda805ff13ee92d54c6c7e24e [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2015 The Chromium Authors
lionel.g.landwerlin7918cb62015-03-23 16:35:462// 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
avi1023d012015-12-25 02:39:148#include <stddef.h>
9#include <stdint.h>
10
dchengcedca5612016-04-09 01:40:1511#include <memory>
lionel.g.landwerlin7918cb62015-03-23 16:35:4612#include <vector>
13
lionel.g.landwerlin7918cb62015-03-23 16:35:4614#include "base/memory/weak_ptr.h"
Markus Handell2878995f2022-10-14 07:32:0915#include "base/task/sequenced_task_runner.h"
Clarissa Garvey2dac3a72021-07-14 03:24:5016#include "media/base/bitrate.h"
lionel.g.landwerlin7918cb62015-03-23 16:35:4617#include "media/video/video_encode_accelerator.h"
18
lionel.g.landwerlin7918cb62015-03-23 16:35:4619namespace gfx {
20class Size;
21}
22
23namespace content {
24
25class PepperVideoEncoderHost;
26
27// This class is a shim to wrap a media::cast::SoftwareVideoEncoder so that it
28// can be used by PepperVideoEncoderHost in place of a
29// media::VideoEncodeAccelerator. This class should be constructed, used, and
30// destructed on the main (render) thread.
31class VideoEncoderShim : public media::VideoEncodeAccelerator {
32 public:
33 explicit VideoEncoderShim(PepperVideoEncoderHost* host);
Peter Boström828b9022021-09-21 02:28:4334
35 VideoEncoderShim(const VideoEncoderShim&) = delete;
36 VideoEncoderShim& operator=(const VideoEncoderShim&) = delete;
37
lionel.g.landwerlin7918cb62015-03-23 16:35:4638 ~VideoEncoderShim() override;
39
40 // media::VideoEncodeAccelerator implementation.
henryhsud1185442015-04-10 06:39:1441 media::VideoEncodeAccelerator::SupportedProfiles GetSupportedProfiles()
42 override;
François Beaufortcf0f41d2022-03-08 23:28:3043 bool Initialize(
44 const media::VideoEncodeAccelerator::Config& config,
45 media::VideoEncodeAccelerator::Client* client,
46 std::unique_ptr<media::MediaLog> media_log = nullptr) override;
John Rummell70cf8feb2019-05-16 19:13:5847 void Encode(scoped_refptr<media::VideoFrame> frame,
lionel.g.landwerlin7918cb62015-03-23 16:35:4648 bool force_keyframe) override;
Matthew Cary1ad95fe82019-05-15 12:51:3349 void UseOutputBitstreamBuffer(media::BitstreamBuffer buffer) override;
Clarissa Garvey2dac3a72021-07-14 03:24:5050 void RequestEncodingParametersChange(const media::Bitrate& bitrate,
avi1023d012015-12-25 02:39:1451 uint32_t framerate) override;
lionel.g.landwerlin7918cb62015-03-23 16:35:4652 void Destroy() override;
53
54 private:
55 class EncoderImpl;
56
57 void OnRequireBitstreamBuffers(unsigned int input_count,
58 const gfx::Size& input_coded_size,
59 size_t output_buffer_size);
60 void OnBitstreamBufferReady(scoped_refptr<media::VideoFrame> frame,
avi1023d012015-12-25 02:39:1461 int32_t bitstream_buffer_id,
lionel.g.landwerlin7918cb62015-03-23 16:35:4662 size_t payload_size,
63 bool key_frame);
Hirokazu Honda86ab7de72023-04-18 06:03:4464 void OnNotifyErrorStatus(const media::EncoderStatus& status);
lionel.g.landwerlin7918cb62015-03-23 16:35:4665
dchengcedca5612016-04-09 01:40:1566 std::unique_ptr<EncoderImpl> encoder_impl_;
lionel.g.landwerlin7918cb62015-03-23 16:35:4667
68 PepperVideoEncoderHost* host_;
69
70 // Task doing the encoding.
Markus Handell2878995f2022-10-14 07:32:0971 scoped_refptr<base::SequencedTaskRunner> media_task_runner_;
lionel.g.landwerlin7918cb62015-03-23 16:35:4672
Jeremy Roman3bca4bf2019-07-11 03:41:2573 base::WeakPtrFactory<VideoEncoderShim> weak_ptr_factory_{this};
lionel.g.landwerlin7918cb62015-03-23 16:35:4674};
75
76} // namespace content
77
78#endif // CONTENT_RENDERER_PEPPER_VIDEO_ENCODER_SHIM_H_