Chromium Code Reviews| Index: media/gpu/ipc/service/gpu_video_encode_accelerator.h |
| diff --git a/media/gpu/ipc/service/gpu_video_encode_accelerator.h b/media/gpu/ipc/service/gpu_video_encode_accelerator.h |
| index d4c23ae2e71077f634ffc060b83297607844f443..91e6c95c04f911e1c865f6dc100bbdd612d87c15 100644 |
| --- a/media/gpu/ipc/service/gpu_video_encode_accelerator.h |
| +++ b/media/gpu/ipc/service/gpu_video_encode_accelerator.h |
| @@ -13,6 +13,8 @@ |
| #include "base/macros.h" |
| #include "base/memory/weak_ptr.h" |
| +#include "base/synchronization/waitable_event.h" |
| +#include "base/threading/thread.h" |
| #include "gpu/config/gpu_info.h" |
| #include "gpu/ipc/service/gpu_command_buffer_stub.h" |
| #include "ipc/ipc_listener.h" |
| @@ -39,8 +41,10 @@ class GpuVideoEncodeAccelerator |
| public VideoEncodeAccelerator::Client, |
| public gpu::GpuCommandBufferStub::DestructionObserver { |
| public: |
| - GpuVideoEncodeAccelerator(int32_t host_route_id, |
| - gpu::GpuCommandBufferStub* stub); |
| + GpuVideoEncodeAccelerator( |
| + int32_t host_route_id, |
| + gpu::GpuCommandBufferStub* stub, |
| + const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); |
| ~GpuVideoEncodeAccelerator() override; |
| // Initialize this accelerator with the given parameters and send |
| @@ -72,6 +76,9 @@ class GpuVideoEncodeAccelerator |
| static gpu::VideoEncodeAcceleratorSupportedProfiles GetSupportedProfiles( |
| const gpu::GpuPreferences& gpu_preferences); |
| + // Called on IO thread when |filter_| has been removed. |
| + 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.
|
| + |
| private: |
| // Returns a vector of VEAFactoryFunctions for the current platform. |
| using VEAFactoryFunction = |
| @@ -79,6 +86,8 @@ class GpuVideoEncodeAccelerator |
| static std::vector<VEAFactoryFunction> GetVEAFactoryFunctions( |
| const gpu::GpuPreferences& gpu_preferences); |
| + class MessageFilter; |
| + |
| // IPC handlers, proxying VideoEncodeAccelerator for the renderer |
| // process. |
| void OnEncode(const AcceleratedVideoEncoderMsg_Encode_Params& params); |
| @@ -89,9 +98,23 @@ class GpuVideoEncodeAccelerator |
| void OnDestroy(); |
| - void EncodeFrameFinished(int32_t frame_id, |
| - std::unique_ptr<base::SharedMemory> shm); |
| - void Send(IPC::Message* message); |
| + // Operations that run on encoder worker thread. |
| + void CreateEncodeFrameOnEncoderWorker( |
| + const AcceleratedVideoEncoderMsg_Encode_Params& params); |
| + void DestroyOnEncoderWorker(); |
| + |
| + // Completes encode tasks with the received |frame|. |
| + void OnEncodeFrameCreated(int32_t frame_id, |
| + bool force_keyframe, |
| + const scoped_refptr<media::VideoFrame>& frame); |
| + |
| + void EncodeFrameFinished(int32_t frame_id); |
| + bool Send(IPC::Message* message); |
| + |
| + // Checks that function is called on the correct thread. If MessageFilter is |
| + // used, checks if it is called on |io_task_runner_|. If not, checks if it is |
| + // called on |main_task_runner_|. |
| + bool CheckIfCalledOnCorrectThread(); |
| // Route ID to communicate with the host. |
| const uint32_t host_route_id_; |
| @@ -111,7 +134,36 @@ class GpuVideoEncodeAccelerator |
| gfx::Size input_coded_size_; |
| size_t output_buffer_size_; |
| - // Weak pointer for VideoFrames that refer back to |this|. |
| + // The message filter to run VEA encode methods on IO thread if VEA supports |
| + // it. |
| + scoped_refptr<MessageFilter> filter_; |
| + |
| + // Used to wait on for |filter_| to be removed, before we can safely |
| + // destroy the VEA. |
| + base::WaitableEvent filter_removed_; |
| + |
| + // This thread services the operations necessary for encode so that they |
| + // wouldn't block |main_task_runner_| or |io_task_runner_|. |
| + base::Thread encoder_worker_thread_; |
| + scoped_refptr<base::SingleThreadTaskRunner> encoder_worker_task_runner_; |
| + |
| + // GPU main thread task runner. |
| + const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
| + |
| + // GPU IO thread task runner. |
| + const scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| + |
| + // Task runner used for posting encode tasks. If |
| + // TryToSetupEncodeOnSeperateThread() is true, |io_task_runner_| is used, |
| + // otherwise |main_thread_task_runner_|. |
| + scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_; |
| + |
| + // Weak pointer for referring back to |this| on |encoder_worker_task_runner_|. |
| + base::WeakPtrFactory<GpuVideoEncodeAccelerator> |
| + 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.
|
| + |
| + // Weak pointer for VideoFrames that refer back to |this| on |
| + // |main_task_runner| or |io_task_runner_|. |
| base::WeakPtrFactory<GpuVideoEncodeAccelerator> weak_this_factory_; |
| DISALLOW_COPY_AND_ASSIGN(GpuVideoEncodeAccelerator); |