Chromium Code Reviews| 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 MEDIA_GPU_IPC_SERVICE_GPU_VIDEO_ENCODE_ACCELERATOR_H_ | 5 #ifndef MEDIA_GPU_IPC_SERVICE_GPU_VIDEO_ENCODE_ACCELERATOR_H_ |
| 6 #define MEDIA_GPU_IPC_SERVICE_GPU_VIDEO_ENCODE_ACCELERATOR_H_ | 6 #define MEDIA_GPU_IPC_SERVICE_GPU_VIDEO_ENCODE_ACCELERATOR_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/synchronization/waitable_event.h" | |
| 17 #include "base/threading/thread.h" | |
| 16 #include "gpu/config/gpu_info.h" | 18 #include "gpu/config/gpu_info.h" |
| 17 #include "gpu/ipc/service/gpu_command_buffer_stub.h" | 19 #include "gpu/ipc/service/gpu_command_buffer_stub.h" |
| 18 #include "ipc/ipc_listener.h" | 20 #include "ipc/ipc_listener.h" |
| 19 #include "media/video/video_encode_accelerator.h" | 21 #include "media/video/video_encode_accelerator.h" |
| 20 #include "ui/gfx/geometry/size.h" | 22 #include "ui/gfx/geometry/size.h" |
| 21 | 23 |
| 22 struct AcceleratedVideoEncoderMsg_Encode_Params; | 24 struct AcceleratedVideoEncoderMsg_Encode_Params; |
| 23 | 25 |
| 24 namespace base { | 26 namespace base { |
| 25 class SharedMemory; | 27 class SharedMemory; |
| 26 } // namespace base | 28 } // namespace base |
| 27 | 29 |
| 28 namespace gpu { | 30 namespace gpu { |
| 29 struct GpuPreferences; | 31 struct GpuPreferences; |
| 30 } // namespace gpu | 32 } // namespace gpu |
| 31 | 33 |
| 32 namespace media { | 34 namespace media { |
| 33 | 35 |
| 34 // This class encapsulates the GPU process view of a VideoEncodeAccelerator, | 36 // This class encapsulates the GPU process view of a VideoEncodeAccelerator, |
| 35 // wrapping the platform-specific VideoEncodeAccelerator instance. It handles | 37 // wrapping the platform-specific VideoEncodeAccelerator instance. It handles |
| 36 // IPC coming in from the renderer and passes it to the underlying VEA. | 38 // IPC coming in from the renderer and passes it to the underlying VEA. |
| 37 class GpuVideoEncodeAccelerator | 39 class GpuVideoEncodeAccelerator |
| 38 : public IPC::Listener, | 40 : public IPC::Listener, |
|
Pawel Osciak
2016/11/07 02:00:36
Should we also derive from IPC::Sender now that we
emircan
2016/11/07 19:35:29
Done.
| |
| 39 public VideoEncodeAccelerator::Client, | 41 public VideoEncodeAccelerator::Client, |
| 40 public gpu::GpuCommandBufferStub::DestructionObserver { | 42 public gpu::GpuCommandBufferStub::DestructionObserver { |
| 41 public: | 43 public: |
| 42 GpuVideoEncodeAccelerator(int32_t host_route_id, | 44 GpuVideoEncodeAccelerator( |
| 43 gpu::GpuCommandBufferStub* stub); | 45 int32_t host_route_id, |
| 46 gpu::GpuCommandBufferStub* stub, | |
| 47 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); | |
| 44 ~GpuVideoEncodeAccelerator() override; | 48 ~GpuVideoEncodeAccelerator() override; |
| 45 | 49 |
| 46 // Initialize this accelerator with the given parameters and send | 50 // Initialize this accelerator with the given parameters and send |
| 47 // |init_done_msg| when complete. | 51 // |init_done_msg| when complete. |
| 48 bool Initialize(VideoPixelFormat input_format, | 52 bool Initialize(VideoPixelFormat input_format, |
| 49 const gfx::Size& input_visible_size, | 53 const gfx::Size& input_visible_size, |
| 50 VideoCodecProfile output_profile, | 54 VideoCodecProfile output_profile, |
| 51 uint32_t initial_bitrate); | 55 uint32_t initial_bitrate); |
| 52 | 56 |
| 53 // IPC::Listener implementation | 57 // IPC::Listener implementation |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 65 | 69 |
| 66 // gpu::GpuCommandBufferStub::DestructionObserver implementation. | 70 // gpu::GpuCommandBufferStub::DestructionObserver implementation. |
| 67 void OnWillDestroyStub() override; | 71 void OnWillDestroyStub() override; |
| 68 | 72 |
| 69 // Static query for supported profiles. This query calls the appropriate | 73 // Static query for supported profiles. This query calls the appropriate |
| 70 // platform-specific version. The returned supported profiles vector will | 74 // platform-specific version. The returned supported profiles vector will |
| 71 // not contain duplicates. | 75 // not contain duplicates. |
| 72 static gpu::VideoEncodeAcceleratorSupportedProfiles GetSupportedProfiles( | 76 static gpu::VideoEncodeAcceleratorSupportedProfiles GetSupportedProfiles( |
| 73 const gpu::GpuPreferences& gpu_preferences); | 77 const gpu::GpuPreferences& gpu_preferences); |
| 74 | 78 |
| 79 // Called on IO thread when |filter_| has been removed. | |
| 80 void OnFilterRemoved(); | |
|
Pawel Osciak
2016/11/07 02:00:35
I think in c++11 this can be private.
emircan
2016/11/07 19:35:29
Done.
| |
| 81 | |
| 75 private: | 82 private: |
| 76 // Returns a vector of VEAFactoryFunctions for the current platform. | 83 // Returns a vector of VEAFactoryFunctions for the current platform. |
| 77 using VEAFactoryFunction = | 84 using VEAFactoryFunction = |
| 78 base::Callback<std::unique_ptr<VideoEncodeAccelerator>()>; | 85 base::Callback<std::unique_ptr<VideoEncodeAccelerator>()>; |
| 79 static std::vector<VEAFactoryFunction> GetVEAFactoryFunctions( | 86 static std::vector<VEAFactoryFunction> GetVEAFactoryFunctions( |
| 80 const gpu::GpuPreferences& gpu_preferences); | 87 const gpu::GpuPreferences& gpu_preferences); |
| 81 | 88 |
| 89 class MessageFilter; | |
| 90 | |
| 82 // IPC handlers, proxying VideoEncodeAccelerator for the renderer | 91 // IPC handlers, proxying VideoEncodeAccelerator for the renderer |
| 83 // process. | 92 // process. |
| 84 void OnEncode(const AcceleratedVideoEncoderMsg_Encode_Params& params); | 93 void OnEncode(const AcceleratedVideoEncoderMsg_Encode_Params& params); |
| 85 void OnUseOutputBitstreamBuffer(int32_t buffer_id, | 94 void OnUseOutputBitstreamBuffer(int32_t buffer_id, |
| 86 base::SharedMemoryHandle buffer_handle, | 95 base::SharedMemoryHandle buffer_handle, |
| 87 uint32_t buffer_size); | 96 uint32_t buffer_size); |
| 88 void OnRequestEncodingParametersChange(uint32_t bitrate, uint32_t framerate); | 97 void OnRequestEncodingParametersChange(uint32_t bitrate, uint32_t framerate); |
| 89 | 98 |
| 90 void OnDestroy(); | 99 void OnDestroy(); |
| 91 | 100 |
| 92 void EncodeFrameFinished(int32_t frame_id, | 101 // Operations that run on encoder worker thread. |
| 93 std::unique_ptr<base::SharedMemory> shm); | 102 void CreateEncodeFrameOnEncoderWorker( |
| 94 void Send(IPC::Message* message); | 103 const AcceleratedVideoEncoderMsg_Encode_Params& params); |
| 104 void DestroyOnEncoderWorker(); | |
| 105 | |
| 106 // Completes encode tasks with the received |frame|. | |
| 107 void OnEncodeFrameCreated(int32_t frame_id, | |
| 108 bool force_keyframe, | |
| 109 const scoped_refptr<media::VideoFrame>& frame); | |
| 110 | |
| 111 void EncodeFrameFinished(int32_t frame_id); | |
| 112 bool Send(IPC::Message* message); | |
| 113 | |
| 114 // Checks that function is called on the correct thread. If MessageFilter is | |
| 115 // used, checks if it is called on |io_task_runner_|. If not, checks if it is | |
| 116 // called on |main_task_runner_|. | |
| 117 bool CheckIfCalledOnCorrectThread(); | |
| 95 | 118 |
| 96 // Route ID to communicate with the host. | 119 // Route ID to communicate with the host. |
| 97 const uint32_t host_route_id_; | 120 const uint32_t host_route_id_; |
| 98 | 121 |
| 99 // Unowned pointer to the underlying gpu::GpuCommandBufferStub. |this| is | 122 // Unowned pointer to the underlying gpu::GpuCommandBufferStub. |this| is |
| 100 // registered as a DestuctionObserver of |stub_| and will self-delete when | 123 // registered as a DestuctionObserver of |stub_| and will self-delete when |
| 101 // |stub_| is destroyed. | 124 // |stub_| is destroyed. |
| 102 gpu::GpuCommandBufferStub* const stub_; | 125 gpu::GpuCommandBufferStub* const stub_; |
| 103 | 126 |
| 104 // Owned pointer to the underlying VideoEncodeAccelerator. | 127 // Owned pointer to the underlying VideoEncodeAccelerator. |
| 105 std::unique_ptr<VideoEncodeAccelerator> encoder_; | 128 std::unique_ptr<VideoEncodeAccelerator> encoder_; |
| 106 base::Callback<bool(void)> make_context_current_; | 129 base::Callback<bool(void)> make_context_current_; |
| 107 | 130 |
| 108 // Video encoding parameters. | 131 // Video encoding parameters. |
| 109 VideoPixelFormat input_format_; | 132 VideoPixelFormat input_format_; |
| 110 gfx::Size input_visible_size_; | 133 gfx::Size input_visible_size_; |
| 111 gfx::Size input_coded_size_; | 134 gfx::Size input_coded_size_; |
| 112 size_t output_buffer_size_; | 135 size_t output_buffer_size_; |
| 113 | 136 |
| 114 // Weak pointer for VideoFrames that refer back to |this|. | 137 // The message filter to run VEA encode methods on IO thread if VEA supports |
| 138 // it. | |
| 139 scoped_refptr<MessageFilter> filter_; | |
| 140 | |
| 141 // Used to wait on for |filter_| to be removed, before we can safely | |
| 142 // destroy the VEA. | |
| 143 base::WaitableEvent filter_removed_; | |
| 144 | |
| 145 // This thread services the operations necessary for encode so that they | |
| 146 // wouldn't block |main_task_runner_| or |io_task_runner_|. | |
| 147 base::Thread encoder_worker_thread_; | |
| 148 scoped_refptr<base::SingleThreadTaskRunner> encoder_worker_task_runner_; | |
| 149 | |
| 150 // GPU main thread task runner. | |
| 151 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | |
| 152 | |
| 153 // GPU IO thread task runner. | |
| 154 const scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | |
| 155 | |
| 156 // Task runner used for posting encode tasks. If | |
| 157 // TryToSetupEncodeOnSeperateThread() is true, |io_task_runner_| is used, | |
| 158 // otherwise |main_thread_task_runner_|. | |
| 159 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_; | |
| 160 | |
| 161 // Weak pointer for referring back to |this| on |encoder_worker_task_runner_|. | |
| 162 base::WeakPtrFactory<GpuVideoEncodeAccelerator> | |
| 163 weak_this_factory_for_encoder_worker; | |
|
Pawel Osciak
2016/11/07 02:00:36
s/weak_this_factory_for_encoder_worker/weak_this_f
emircan
2016/11/07 19:35:29
Done.
| |
| 164 | |
| 165 // Weak pointer for VideoFrames that refer back to |this| on | |
| 166 // |main_task_runner| or |io_task_runner_|. | |
| 115 base::WeakPtrFactory<GpuVideoEncodeAccelerator> weak_this_factory_; | 167 base::WeakPtrFactory<GpuVideoEncodeAccelerator> weak_this_factory_; |
| 116 | 168 |
| 117 DISALLOW_COPY_AND_ASSIGN(GpuVideoEncodeAccelerator); | 169 DISALLOW_COPY_AND_ASSIGN(GpuVideoEncodeAccelerator); |
| 118 }; | 170 }; |
| 119 | 171 |
| 120 } // namespace media | 172 } // namespace media |
| 121 | 173 |
| 122 #endif // MEDIA_GPU_IPC_SERVICE_GPU_VIDEO_ENCODE_ACCELERATOR_H_ | 174 #endif // MEDIA_GPU_IPC_SERVICE_GPU_VIDEO_ENCODE_ACCELERATOR_H_ |
| OLD | NEW |