ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / content / common / gpu / media / gpu_video_encode_accelerator.h
blobe94a2dda8a66a921f63898abe7e2677de597bd15
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_
8 #include <vector>
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 "gpu/config/gpu_info.h"
14 #include "ipc/ipc_listener.h"
15 #include "media/video/video_encode_accelerator.h"
16 #include "ui/gfx/geometry/size.h"
18 namespace base {
20 class SharedMemory;
22 } // namespace base
24 namespace content {
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
30 : public IPC::Listener,
31 public media::VideoEncodeAccelerator::Client,
32 public GpuCommandBufferStub::DestructionObserver {
33 public:
34 GpuVideoEncodeAccelerator(int32 host_route_id, GpuCommandBufferStub* stub);
35 ~GpuVideoEncodeAccelerator() override;
37 // Initialize this accelerator with the given parameters and send
38 // |init_done_msg| when complete.
39 void Initialize(media::VideoFrame::Format input_format,
40 const gfx::Size& input_visible_size,
41 media::VideoCodecProfile output_profile,
42 uint32 initial_bitrate,
43 IPC::Message* init_done_msg);
45 // IPC::Listener implementation
46 bool OnMessageReceived(const IPC::Message& message) override;
48 // media::VideoEncodeAccelerator::Client implementation.
49 void RequireBitstreamBuffers(unsigned int input_count,
50 const gfx::Size& input_coded_size,
51 size_t output_buffer_size) override;
52 void BitstreamBufferReady(int32 bitstream_buffer_id,
53 size_t payload_size,
54 bool key_frame) override;
55 void NotifyError(media::VideoEncodeAccelerator::Error error) override;
57 // GpuCommandBufferStub::DestructionObserver implementation.
58 void OnWillDestroyStub() override;
60 // Static query for supported profiles. This query calls the appropriate
61 // platform-specific version.
62 static std::vector<gpu::VideoEncodeAcceleratorSupportedProfile>
63 GetSupportedProfiles();
64 static std::vector<gpu::VideoEncodeAcceleratorSupportedProfile>
65 ConvertMediaToGpuProfiles(const std::vector<
66 media::VideoEncodeAccelerator::SupportedProfile>& media_profiles);
68 private:
69 typedef scoped_ptr<media::VideoEncodeAccelerator>(*CreateVEAFp)();
71 // Return a set of VEA Create function pointers applicable to the current
72 // platform.
73 static std::vector<CreateVEAFp> CreateVEAFps();
74 static scoped_ptr<media::VideoEncodeAccelerator> CreateV4L2VEA();
75 static scoped_ptr<media::VideoEncodeAccelerator> CreateVaapiVEA();
76 static scoped_ptr<media::VideoEncodeAccelerator> CreateAndroidVEA();
78 // IPC handlers, proxying media::VideoEncodeAccelerator for the renderer
79 // process.
80 void OnEncode(int32 frame_id,
81 base::SharedMemoryHandle buffer_handle,
82 uint32 buffer_offset,
83 uint32 buffer_size,
84 bool force_keyframe);
85 void OnUseOutputBitstreamBuffer(int32 buffer_id,
86 base::SharedMemoryHandle buffer_handle,
87 uint32 buffer_size);
88 void OnRequestEncodingParametersChange(uint32 bitrate, uint32 framerate);
90 void OnDestroy();
92 void EncodeFrameFinished(int32 frame_id, scoped_ptr<base::SharedMemory> shm);
94 void Send(IPC::Message* message);
95 // Helper for replying to the creation request.
96 void SendCreateEncoderReply(IPC::Message* message, bool succeeded);
98 // Route ID to communicate with the host.
99 int32 host_route_id_;
101 // Unowned pointer to the underlying GpuCommandBufferStub. |this| is
102 // registered as a DestuctionObserver of |stub_| and will self-delete when
103 // |stub_| is destroyed.
104 GpuCommandBufferStub* stub_;
106 // Owned pointer to the underlying VideoEncodeAccelerator.
107 scoped_ptr<media::VideoEncodeAccelerator> encoder_;
108 base::Callback<bool(void)> make_context_current_;
110 // Video encoding parameters.
111 media::VideoFrame::Format input_format_;
112 gfx::Size input_visible_size_;
113 gfx::Size input_coded_size_;
114 size_t output_buffer_size_;
116 // Weak pointer for media::VideoFrames that refer back to |this|.
117 base::WeakPtrFactory<GpuVideoEncodeAccelerator> weak_this_factory_;
119 DISALLOW_COPY_AND_ASSIGN(GpuVideoEncodeAccelerator);
122 } // namespace content
124 #endif // CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_ENCODE_ACCELERATOR_H_