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 "content/common/gpu/gpu_command_buffer_stub.h"
13 #include "ipc/ipc_listener.h"
14 #include "media/video/video_encode_accelerator.h"
15 #include "ui/gfx/size.h"
25 // This class encapsulates the GPU process view of a VideoEncodeAccelerator,
26 // wrapping the platform-specific VideoEncodeAccelerator instance. It handles
27 // IPC coming in from the renderer and passes it to the underlying VEA.
28 class GpuVideoEncodeAccelerator
29 : public IPC::Listener
,
30 public media::VideoEncodeAccelerator::Client
,
31 public GpuCommandBufferStub::DestructionObserver
{
33 GpuVideoEncodeAccelerator(int32 host_route_id
, GpuCommandBufferStub
* stub
);
34 virtual ~GpuVideoEncodeAccelerator();
36 // Initialize this accelerator with the given parameters and send
37 // |init_done_msg| when complete.
38 void Initialize(media::VideoFrame::Format input_format
,
39 const gfx::Size
& input_visible_size
,
40 media::VideoCodecProfile output_profile
,
41 uint32 initial_bitrate
,
42 IPC::Message
* init_done_msg
);
44 // IPC::Listener implementation
45 virtual bool OnMessageReceived(const IPC::Message
& message
) OVERRIDE
;
47 // media::VideoEncodeAccelerator::Client implementation.
48 virtual void RequireBitstreamBuffers(unsigned int input_count
,
49 const gfx::Size
& input_coded_size
,
50 size_t output_buffer_size
) OVERRIDE
;
51 virtual void BitstreamBufferReady(int32 bitstream_buffer_id
,
53 bool key_frame
) OVERRIDE
;
54 virtual void NotifyError(media::VideoEncodeAccelerator::Error error
) OVERRIDE
;
56 // GpuCommandBufferStub::DestructionObserver implementation.
57 virtual void OnWillDestroyStub() OVERRIDE
;
59 // Static query for supported profiles. This query calls the appropriate
60 // platform-specific version.
61 static std::vector
<media::VideoEncodeAccelerator::SupportedProfile
>
62 GetSupportedProfiles();
65 // Create the appropriate platform-specific VEA.
68 // IPC handlers, proxying media::VideoEncodeAccelerator for the renderer
70 void OnEncode(int32 frame_id
,
71 base::SharedMemoryHandle buffer_handle
,
74 void OnUseOutputBitstreamBuffer(int32 buffer_id
,
75 base::SharedMemoryHandle buffer_handle
,
77 void OnRequestEncodingParametersChange(uint32 bitrate
, uint32 framerate
);
81 void EncodeFrameFinished(int32 frame_id
, scoped_ptr
<base::SharedMemory
> shm
);
83 void Send(IPC::Message
* message
);
84 // Helper for replying to the creation request.
85 void SendCreateEncoderReply(IPC::Message
* message
, bool succeeded
);
87 // Route ID to communicate with the host.
90 // Unowned pointer to the underlying GpuCommandBufferStub. |this| is
91 // registered as a DestuctionObserver of |stub_| and will self-delete when
92 // |stub_| is destroyed.
93 GpuCommandBufferStub
* stub_
;
95 // Owned pointer to the underlying VideoEncodeAccelerator.
96 scoped_ptr
<media::VideoEncodeAccelerator
> encoder_
;
97 base::Callback
<bool(void)> make_context_current_
;
99 // Video encoding parameters.
100 media::VideoFrame::Format input_format_
;
101 gfx::Size input_visible_size_
;
102 gfx::Size input_coded_size_
;
103 size_t output_buffer_size_
;
105 // Weak pointer for media::VideoFrames that refer back to |this|.
106 base::WeakPtrFactory
<GpuVideoEncodeAccelerator
> weak_this_factory_
;
108 DISALLOW_COPY_AND_ASSIGN(GpuVideoEncodeAccelerator
);
111 } // namespace content
113 #endif // CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_ENCODE_ACCELERATOR_H_