blob: 5d489b2ed19a2bb23ecd29f3cfa540e013ab620c [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"
16#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);
37 ~VideoEncoderShim() override;
38
39 // media::VideoEncodeAccelerator implementation.
henryhsud1185442015-04-10 06:39:1440 media::VideoEncodeAccelerator::SupportedProfiles GetSupportedProfiles()
41 override;
Pin-chih Line6ff3d972018-07-27 11:15:0442 bool Initialize(const media::VideoEncodeAccelerator::Config& config,
lionel.g.landwerlin7918cb62015-03-23 16:35:4643 media::VideoEncodeAccelerator::Client* client) override;
44 void Encode(const scoped_refptr<media::VideoFrame>& frame,
45 bool force_keyframe) override;
Matthew Cary1ad95fe82019-05-15 12:51:3346 void UseOutputBitstreamBuffer(media::BitstreamBuffer buffer) override;
avi1023d012015-12-25 02:39:1447 void RequestEncodingParametersChange(uint32_t bitrate,
48 uint32_t framerate) override;
lionel.g.landwerlin7918cb62015-03-23 16:35:4649 void Destroy() override;
50
51 private:
52 class EncoderImpl;
53
54 void OnRequireBitstreamBuffers(unsigned int input_count,
55 const gfx::Size& input_coded_size,
56 size_t output_buffer_size);
57 void OnBitstreamBufferReady(scoped_refptr<media::VideoFrame> frame,
avi1023d012015-12-25 02:39:1458 int32_t bitstream_buffer_id,
lionel.g.landwerlin7918cb62015-03-23 16:35:4659 size_t payload_size,
60 bool key_frame);
61 void OnNotifyError(media::VideoEncodeAccelerator::Error error);
62
dchengcedca5612016-04-09 01:40:1563 std::unique_ptr<EncoderImpl> encoder_impl_;
lionel.g.landwerlin7918cb62015-03-23 16:35:4664
65 PepperVideoEncoderHost* host_;
66
67 // Task doing the encoding.
68 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_;
69
70 base::WeakPtrFactory<VideoEncoderShim> weak_ptr_factory_;
71
72 DISALLOW_COPY_AND_ASSIGN(VideoEncoderShim);
73};
74
75} // namespace content
76
77#endif // CONTENT_RENDERER_PEPPER_VIDEO_ENCODER_SHIM_H_