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_
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "media/video/video_encode_accelerator.h"
15 class SingleThreadTaskRunner
;
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
{
32 explicit VideoEncoderShim(PepperVideoEncoderHost
* host
);
33 ~VideoEncoderShim() override
;
35 // media::VideoEncodeAccelerator implementation.
36 std::vector
<media::VideoEncodeAccelerator::SupportedProfile
>
37 GetSupportedProfiles() override
;
38 bool Initialize(media::VideoFrame::Format 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
;
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
,
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_