OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_ENCODE_ACCELERATOR_H_ | 5 #ifndef CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_ENCODE_ACCELERATOR_H_ |
6 #define CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_ENCODE_ACCELERATOR_H_ | 6 #define CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_ENCODE_ACCELERATOR_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "content/common/gpu/gpu_command_buffer_stub.h" |
12 #include "ipc/ipc_listener.h" | 13 #include "ipc/ipc_listener.h" |
13 #include "media/video/video_encode_accelerator.h" | 14 #include "media/video/video_encode_accelerator.h" |
14 #include "ui/gfx/size.h" | 15 #include "ui/gfx/size.h" |
15 | 16 |
16 namespace base { | 17 namespace base { |
17 | 18 |
18 class SharedMemory; | 19 class SharedMemory; |
19 | 20 |
20 } // namespace base | 21 } // namespace base |
21 | 22 |
22 namespace content { | 23 namespace content { |
23 | 24 |
24 class GpuChannel; | |
25 | |
26 // This class encapsulates the GPU process view of a VideoEncodeAccelerator, | 25 // This class encapsulates the GPU process view of a VideoEncodeAccelerator, |
27 // wrapping the platform-specific VideoEncodeAccelerator instance. It handles | 26 // wrapping the platform-specific VideoEncodeAccelerator instance. It handles |
28 // IPC coming in from the renderer and passes it to the underlying VEA. | 27 // IPC coming in from the renderer and passes it to the underlying VEA. |
29 class GpuVideoEncodeAccelerator : public IPC::Listener, | 28 class GpuVideoEncodeAccelerator |
30 public media::VideoEncodeAccelerator::Client { | 29 : public IPC::Listener, |
| 30 public media::VideoEncodeAccelerator::Client, |
| 31 public GpuCommandBufferStub::DestructionObserver { |
31 public: | 32 public: |
32 GpuVideoEncodeAccelerator(GpuChannel* gpu_channel, int32 route_id); | 33 GpuVideoEncodeAccelerator(int32 host_route_id, GpuCommandBufferStub* stub); |
33 virtual ~GpuVideoEncodeAccelerator(); | 34 virtual ~GpuVideoEncodeAccelerator(); |
34 | 35 |
| 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); |
| 43 |
35 // IPC::Listener implementation | 44 // IPC::Listener implementation |
36 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 45 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
37 virtual void OnChannelError() OVERRIDE; | |
38 | 46 |
39 // media::VideoEncodeAccelerator::Client implementation. | 47 // media::VideoEncodeAccelerator::Client implementation. |
40 virtual void NotifyInitializeDone() OVERRIDE; | |
41 virtual void RequireBitstreamBuffers(unsigned int input_count, | 48 virtual void RequireBitstreamBuffers(unsigned int input_count, |
42 const gfx::Size& input_coded_size, | 49 const gfx::Size& input_coded_size, |
43 size_t output_buffer_size) OVERRIDE; | 50 size_t output_buffer_size) OVERRIDE; |
44 virtual void BitstreamBufferReady(int32 bitstream_buffer_id, | 51 virtual void BitstreamBufferReady(int32 bitstream_buffer_id, |
45 size_t payload_size, | 52 size_t payload_size, |
46 bool key_frame) OVERRIDE; | 53 bool key_frame) OVERRIDE; |
47 virtual void NotifyError(media::VideoEncodeAccelerator::Error error) OVERRIDE; | 54 virtual void NotifyError(media::VideoEncodeAccelerator::Error error) OVERRIDE; |
48 | 55 |
| 56 // GpuCommandBufferStub::DestructionObserver implementation. |
| 57 virtual void OnWillDestroyStub() OVERRIDE; |
| 58 |
49 // Static query for supported profiles. This query calls the appropriate | 59 // Static query for supported profiles. This query calls the appropriate |
50 // platform-specific version. | 60 // platform-specific version. |
51 static std::vector<media::VideoEncodeAccelerator::SupportedProfile> | 61 static std::vector<media::VideoEncodeAccelerator::SupportedProfile> |
52 GetSupportedProfiles(); | 62 GetSupportedProfiles(); |
53 | 63 |
54 private: | 64 private: |
55 // Create the appropriate platform-specific VEA. | 65 // Create the appropriate platform-specific VEA. |
56 void CreateEncoder(); | 66 void CreateEncoder(); |
57 | 67 |
58 // IPC handlers, proxying media::VideoEncodeAccelerator for the renderer | 68 // IPC handlers, proxying media::VideoEncodeAccelerator for the renderer |
59 // process. | 69 // 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, | 70 void OnEncode(int32 frame_id, |
65 base::SharedMemoryHandle buffer_handle, | 71 base::SharedMemoryHandle buffer_handle, |
66 uint32 buffer_size, | 72 uint32 buffer_size, |
67 bool force_keyframe); | 73 bool force_keyframe); |
68 void OnUseOutputBitstreamBuffer(int32 buffer_id, | 74 void OnUseOutputBitstreamBuffer(int32 buffer_id, |
69 base::SharedMemoryHandle buffer_handle, | 75 base::SharedMemoryHandle buffer_handle, |
70 uint32 buffer_size); | 76 uint32 buffer_size); |
71 void OnRequestEncodingParametersChange(uint32 bitrate, uint32 framerate); | 77 void OnRequestEncodingParametersChange(uint32 bitrate, uint32 framerate); |
72 | 78 |
| 79 void OnDestroy(); |
| 80 |
73 void EncodeFrameFinished(int32 frame_id, scoped_ptr<base::SharedMemory> shm); | 81 void EncodeFrameFinished(int32 frame_id, scoped_ptr<base::SharedMemory> shm); |
74 | 82 |
75 void Send(IPC::Message* message); | 83 void Send(IPC::Message* message); |
| 84 // Helper for replying to the creation request. |
| 85 void SendCreateEncoderReply(IPC::Message* message, int32 route_id); |
76 | 86 |
77 // Weak pointer for media::VideoFrames that refer back to |this|. | 87 // Route ID to communicate with the host. |
78 base::WeakPtrFactory<GpuVideoEncodeAccelerator> weak_this_factory_; | 88 int32 host_route_id_; |
79 | 89 |
80 // The GpuChannel owns this GpuVideoEncodeAccelerator and will outlive |this|. | 90 // Unowned pointer to the underlying GpuCommandBufferStub. |this| is |
81 GpuChannel* channel_; | 91 // registered as a DestuctionObserver of |stub_| and will self-delete when |
82 const int32 route_id_; | 92 // |stub_| is destroyed. |
| 93 GpuCommandBufferStub* stub_; |
83 | 94 |
84 // Owned pointer to the underlying VideoEncodeAccelerator. | 95 // Owned pointer to the underlying VideoEncodeAccelerator. |
85 scoped_ptr<media::VideoEncodeAccelerator> encoder_; | 96 scoped_ptr<media::VideoEncodeAccelerator> encoder_; |
| 97 base::Callback<bool(void)> make_context_current_; |
86 | 98 |
87 // Video encoding parameters. | 99 // Video encoding parameters. |
88 media::VideoFrame::Format input_format_; | 100 media::VideoFrame::Format input_format_; |
89 gfx::Size input_visible_size_; | 101 gfx::Size input_visible_size_; |
90 gfx::Size input_coded_size_; | 102 gfx::Size input_coded_size_; |
91 size_t output_buffer_size_; | 103 size_t output_buffer_size_; |
92 | 104 |
| 105 // Weak pointer for media::VideoFrames that refer back to |this|. |
| 106 base::WeakPtrFactory<GpuVideoEncodeAccelerator> weak_this_factory_; |
| 107 |
93 DISALLOW_COPY_AND_ASSIGN(GpuVideoEncodeAccelerator); | 108 DISALLOW_COPY_AND_ASSIGN(GpuVideoEncodeAccelerator); |
94 }; | 109 }; |
95 | 110 |
96 } // namespace content | 111 } // namespace content |
97 | 112 |
98 #endif // CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_ENCODE_ACCELERATOR_H_ | 113 #endif // CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_ENCODE_ACCELERATOR_H_ |
OLD | NEW |