OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_ENCODE_ACCELERATOR_H_ | |
6 #define CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_ENCODE_ACCELERATOR_H_ | |
7 | |
8 #include <vector> | |
9 | |
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" | |
15 | |
16 namespace base { | |
17 | |
18 class SharedMemory; | |
19 | |
20 } // namespace base | |
21 | |
22 namespace content { | |
23 | |
24 class GpuChannel; | |
25 | |
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 { | |
31 public: | |
32 GpuVideoEncodeAccelerator(GpuChannel* gpu_channel, int32 route_id); | |
33 virtual ~GpuVideoEncodeAccelerator(); | |
34 | |
35 // IPC::Listener implementation | |
36 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
37 virtual void OnChannelError() OVERRIDE; | |
38 | |
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, | |
45 size_t payload_size, | |
46 bool key_frame) OVERRIDE; | |
47 virtual void NotifyError(media::VideoEncodeAccelerator::Error error) OVERRIDE; | |
48 | |
49 // Static query for supported profiles. This query calls the appropriate | |
50 // platform-specific version. | |
51 static std::vector<media::VideoEncodeAccelerator::SupportedProfile> | |
52 GetSupportedProfiles(); | |
53 | |
54 private: | |
55 // Create the appropriate platform-specific VEA. | |
56 void CreateEncoder(); | |
57 | |
58 // IPC handlers, proxying media::VideoEncodeAccelerator for the renderer | |
59 // process. | |
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, | |
66 uint32 buffer_size, | |
67 bool force_keyframe); | |
68 void OnUseOutputBitstreamBuffer(int32 buffer_id, | |
69 base::SharedMemoryHandle buffer_handle, | |
70 uint32 buffer_size); | |
71 void OnRequestEncodingParametersChange(uint32 bitrate, uint32 framerate); | |
72 | |
73 void EncodeFrameFinished(int32 frame_id, scoped_ptr<base::SharedMemory> shm); | |
74 | |
75 void Send(IPC::Message* message); | |
76 | |
77 // Weak pointer for media::VideoFrames that refer back to |this|. | |
78 base::WeakPtrFactory<GpuVideoEncodeAccelerator> weak_this_factory_; | |
79 | |
80 // The GpuChannel owns this GpuVideoEncodeAccelerator and will outlive |this|. | |
81 GpuChannel* channel_; | |
82 const int32 route_id_; | |
83 | |
84 // Owned pointer to the underlying VideoEncodeAccelerator. | |
85 scoped_ptr<media::VideoEncodeAccelerator> encoder_; | |
86 | |
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_; | |
92 | |
93 DISALLOW_COPY_AND_ASSIGN(GpuVideoEncodeAccelerator); | |
94 }; | |
95 | |
96 } // namespace content | |
97 | |
98 #endif // CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_ENCODE_ACCELERATOR_H_ | |
OLD | NEW |