blob: 8e502822c99f4f86beebfd988e085c626e2e66dc [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
avi1023d012015-12-25 02:39:1414#include "base/macros.h"
lionel.g.landwerlin7918cb62015-03-23 16:35:4615#include "base/memory/weak_ptr.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
19namespace base {
20class SingleThreadTaskRunner;
21}
22
23namespace gfx {
24class Size;
25}
26
27namespace content {
28
29class 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.
35class VideoEncoderShim : public media::VideoEncodeAccelerator {
36 public:
37 explicit VideoEncoderShim(PepperVideoEncoderHost* host);
38 ~VideoEncoderShim() override;
39
40 // media::VideoEncodeAccelerator implementation.
henryhsud1185442015-04-10 06:39:1441 media::VideoEncodeAccelerator::SupportedProfiles GetSupportedProfiles()
42 override;
Pin-chih Line6ff3d972018-07-27 11:15:0443 bool Initialize(const media::VideoEncodeAccelerator::Config& config,
lionel.g.landwerlin7918cb62015-03-23 16:35:4644 media::VideoEncodeAccelerator::Client* client) override;
John Rummell70cf8feb2019-05-16 19:13:5845 void Encode(scoped_refptr<media::VideoFrame> frame,
lionel.g.landwerlin7918cb62015-03-23 16:35:4646 bool force_keyframe) override;
Matthew Cary1ad95fe82019-05-15 12:51:3347 void UseOutputBitstreamBuffer(media::BitstreamBuffer buffer) override;
Clarissa Garvey2dac3a72021-07-14 03:24:5048 void RequestEncodingParametersChange(const media::Bitrate& bitrate,
avi1023d012015-12-25 02:39:1449 uint32_t framerate) override;
lionel.g.landwerlin7918cb62015-03-23 16:35:4650 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,
avi1023d012015-12-25 02:39:1459 int32_t bitstream_buffer_id,
lionel.g.landwerlin7918cb62015-03-23 16:35:4660 size_t payload_size,
61 bool key_frame);
62 void OnNotifyError(media::VideoEncodeAccelerator::Error error);
63
dchengcedca5612016-04-09 01:40:1564 std::unique_ptr<EncoderImpl> encoder_impl_;
lionel.g.landwerlin7918cb62015-03-23 16:35:4665
66 PepperVideoEncoderHost* host_;
67
68 // Task doing the encoding.
69 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_;
70
Jeremy Roman3bca4bf2019-07-11 03:41:2571 base::WeakPtrFactory<VideoEncoderShim> weak_ptr_factory_{this};
lionel.g.landwerlin7918cb62015-03-23 16:35:4672
73 DISALLOW_COPY_AND_ASSIGN(VideoEncoderShim);
74};
75
76} // namespace content
77
78#endif // CONTENT_RENDERER_PEPPER_VIDEO_ENCODER_SHIM_H_