1 // Copyright 2013 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_COMMON_GPU_MEDIA_GPU_VIDEO_ENCODE_ACCELERATOR_H_
6 #define CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_ENCODE_ACCELERATOR_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "ipc/ipc_listener.h"
13 #include "media/video/video_encode_accelerator.h"
14 #include "ui/gfx/size.h"
26 // This class encapsulates the GPU process view of a VideoEncodeAccelerator,
27 // wrapping the platform-specific VideoEncodeAccelerator instance. It handles
28 // IPC coming in from the renderer and passes it to the underlying VEA.
29 class GpuVideoEncodeAccelerator
: public IPC::Listener
,
30 public media::VideoEncodeAccelerator::Client
{
32 GpuVideoEncodeAccelerator(GpuChannel
* gpu_channel
, int32 route_id
);
33 virtual ~GpuVideoEncodeAccelerator();
35 // IPC::Listener implementation
36 virtual bool OnMessageReceived(const IPC::Message
& message
) OVERRIDE
;
37 virtual void OnChannelError() OVERRIDE
;
39 // media::VideoEncodeAccelerator::Client implementation.
40 virtual void NotifyInitializeDone() OVERRIDE
;
41 virtual void RequireBitstreamBuffers(unsigned int input_count
,
42 const gfx::Size
& input_coded_size
,
43 size_t output_buffer_size
) OVERRIDE
;
44 virtual void BitstreamBufferReady(int32 bitstream_buffer_id
,
46 bool key_frame
) OVERRIDE
;
47 virtual void NotifyError(media::VideoEncodeAccelerator::Error error
) OVERRIDE
;
49 // Static query for supported profiles. This query calls the appropriate
50 // platform-specific version.
51 static std::vector
<media::VideoEncodeAccelerator::SupportedProfile
>
52 GetSupportedProfiles();
55 // Create the appropriate platform-specific VEA.
58 // IPC handlers, proxying media::VideoEncodeAccelerator for the renderer
60 void OnInitialize(media::VideoFrame::Format input_format
,
61 const gfx::Size
& input_visible_size
,
62 media::VideoCodecProfile output_profile
,
63 uint32 initial_bitrate
);
64 void OnEncode(int32 frame_id
,
65 base::SharedMemoryHandle buffer_handle
,
68 void OnUseOutputBitstreamBuffer(int32 buffer_id
,
69 base::SharedMemoryHandle buffer_handle
,
71 void OnRequestEncodingParametersChange(uint32 bitrate
, uint32 framerate
);
73 void EncodeFrameFinished(int32 frame_id
, scoped_ptr
<base::SharedMemory
> shm
);
75 void Send(IPC::Message
* message
);
77 // Weak pointer for media::VideoFrames that refer back to |this|.
78 base::WeakPtrFactory
<GpuVideoEncodeAccelerator
> weak_this_factory_
;
80 // The GpuChannel owns this GpuVideoEncodeAccelerator and will outlive |this|.
82 const int32 route_id_
;
84 // Owned pointer to the underlying VideoEncodeAccelerator.
85 scoped_ptr
<media::VideoEncodeAccelerator
> encoder_
;
87 // Video encoding parameters.
88 media::VideoFrame::Format input_format_
;
89 gfx::Size input_visible_size_
;
90 gfx::Size input_coded_size_
;
91 size_t output_buffer_size_
;
93 DISALLOW_COPY_AND_ASSIGN(GpuVideoEncodeAccelerator
);
96 } // namespace content
98 #endif // CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_ENCODE_ACCELERATOR_H_