blob: e04e90831ad581ad65600d47b37ae1f4fc78d799 [file] [log] [blame]
lionel.g.landwerlin7918cb62015-03-23 16:35:461// 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
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"
Clarissa Garvey2dac3a72021-07-14 03:24:5015#include "media/base/bitrate.h"
lionel.g.landwerlin7918cb62015-03-23 16:35:4616#include "media/video/video_encode_accelerator.h"
17
18namespace base {
19class SingleThreadTaskRunner;
20}
21
22namespace gfx {
23class Size;
24}
25
26namespace content {
27
28class PepperVideoEncoderHost;
29
30// This class is a shim to wrap a media::cast::SoftwareVideoEncoder so that it
31// can be used by PepperVideoEncoderHost in place of a
32// media::VideoEncodeAccelerator. This class should be constructed, used, and
33// destructed on the main (render) thread.
34class VideoEncoderShim : public media::VideoEncodeAccelerator {
35 public:
36 explicit VideoEncoderShim(PepperVideoEncoderHost* host);
Peter Boström828b9022021-09-21 02:28:4337
38 VideoEncoderShim(const VideoEncoderShim&) = delete;
39 VideoEncoderShim& operator=(const VideoEncoderShim&) = delete;
40
lionel.g.landwerlin7918cb62015-03-23 16:35:4641 ~VideoEncoderShim() override;
42
43 // media::VideoEncodeAccelerator implementation.
henryhsud1185442015-04-10 06:39:1444 media::VideoEncodeAccelerator::SupportedProfiles GetSupportedProfiles()
45 override;
François Beaufortcf0f41d2022-03-08 23:28:3046 bool Initialize(
47 const media::VideoEncodeAccelerator::Config& config,
48 media::VideoEncodeAccelerator::Client* client,
49 std::unique_ptr<media::MediaLog> media_log = nullptr) override;
John Rummell70cf8feb2019-05-16 19:13:5850 void Encode(scoped_refptr<media::VideoFrame> frame,
lionel.g.landwerlin7918cb62015-03-23 16:35:4651 bool force_keyframe) override;
Matthew Cary1ad95fe82019-05-15 12:51:3352 void UseOutputBitstreamBuffer(media::BitstreamBuffer buffer) override;
Clarissa Garvey2dac3a72021-07-14 03:24:5053 void RequestEncodingParametersChange(const media::Bitrate& bitrate,
avi1023d012015-12-25 02:39:1454 uint32_t framerate) override;
lionel.g.landwerlin7918cb62015-03-23 16:35:4655 void Destroy() override;
56
57 private:
58 class EncoderImpl;
59
60 void OnRequireBitstreamBuffers(unsigned int input_count,
61 const gfx::Size& input_coded_size,
62 size_t output_buffer_size);
63 void OnBitstreamBufferReady(scoped_refptr<media::VideoFrame> frame,
avi1023d012015-12-25 02:39:1464 int32_t bitstream_buffer_id,
lionel.g.landwerlin7918cb62015-03-23 16:35:4665 size_t payload_size,
66 bool key_frame);
67 void OnNotifyError(media::VideoEncodeAccelerator::Error error);
68
dchengcedca5612016-04-09 01:40:1569 std::unique_ptr<EncoderImpl> encoder_impl_;
lionel.g.landwerlin7918cb62015-03-23 16:35:4670
71 PepperVideoEncoderHost* host_;
72
73 // Task doing the encoding.
74 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_;
75
Jeremy Roman3bca4bf2019-07-11 03:41:2576 base::WeakPtrFactory<VideoEncoderShim> weak_ptr_factory_{this};
lionel.g.landwerlin7918cb62015-03-23 16:35:4677};
78
79} // namespace content
80
81#endif // CONTENT_RENDERER_PEPPER_VIDEO_ENCODER_SHIM_H_