Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / renderer / pepper / video_encoder_shim.h
blob44049efed6846d58f0a7135bd851dd03c54f5ae7
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.
5 #ifndef CONTENT_RENDERER_PEPPER_VIDEO_ENCODER_SHIM_H_
6 #define CONTENT_RENDERER_PEPPER_VIDEO_ENCODER_SHIM_H_
8 #include <vector>
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "media/video/video_encode_accelerator.h"
14 namespace base {
15 class SingleThreadTaskRunner;
18 namespace gfx {
19 class Size;
22 namespace content {
24 class PepperVideoEncoderHost;
26 // This class is a shim to wrap a media::cast::SoftwareVideoEncoder so that it
27 // can be used by PepperVideoEncoderHost in place of a
28 // media::VideoEncodeAccelerator. This class should be constructed, used, and
29 // destructed on the main (render) thread.
30 class VideoEncoderShim : public media::VideoEncodeAccelerator {
31 public:
32 explicit VideoEncoderShim(PepperVideoEncoderHost* host);
33 ~VideoEncoderShim() override;
35 // media::VideoEncodeAccelerator implementation.
36 media::VideoEncodeAccelerator::SupportedProfiles GetSupportedProfiles()
37 override;
38 bool Initialize(media::VideoPixelFormat input_format,
39 const gfx::Size& input_visible_size,
40 media::VideoCodecProfile output_profile,
41 uint32 initial_bitrate,
42 media::VideoEncodeAccelerator::Client* client) override;
43 void Encode(const scoped_refptr<media::VideoFrame>& frame,
44 bool force_keyframe) override;
45 void UseOutputBitstreamBuffer(const media::BitstreamBuffer& buffer) override;
46 void RequestEncodingParametersChange(uint32 bitrate,
47 uint32 framerate) override;
48 void Destroy() override;
50 private:
51 class EncoderImpl;
53 void OnRequireBitstreamBuffers(unsigned int input_count,
54 const gfx::Size& input_coded_size,
55 size_t output_buffer_size);
56 void OnBitstreamBufferReady(scoped_refptr<media::VideoFrame> frame,
57 int32 bitstream_buffer_id,
58 size_t payload_size,
59 bool key_frame);
60 void OnNotifyError(media::VideoEncodeAccelerator::Error error);
62 scoped_ptr<EncoderImpl> encoder_impl_;
64 PepperVideoEncoderHost* host_;
66 // Task doing the encoding.
67 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_;
69 base::WeakPtrFactory<VideoEncoderShim> weak_ptr_factory_;
71 DISALLOW_COPY_AND_ASSIGN(VideoEncoderShim);
74 } // namespace content
76 #endif // CONTENT_RENDERER_PEPPER_VIDEO_ENCODER_SHIM_H_