| 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_CLIENT_GPU_VIDEO_ENCODE_ACCELERATOR_HOST_H_ | 5 #ifndef CONTENT_COMMON_GPU_CLIENT_GPU_VIDEO_ENCODE_ACCELERATOR_HOST_H_ |
| 6 #define CONTENT_COMMON_GPU_CLIENT_GPU_VIDEO_ENCODE_ACCELERATOR_HOST_H_ | 6 #define CONTENT_COMMON_GPU_CLIENT_GPU_VIDEO_ENCODE_ACCELERATOR_HOST_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/containers/hash_tables.h" | 12 #include "base/containers/hash_tables.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/threading/non_thread_safe.h" | 16 #include "base/threading/non_thread_safe.h" |
| 17 #include "content/common/gpu/client/command_buffer_proxy_impl.h" | |
| 18 #include "gpu/config/gpu_info.h" | 17 #include "gpu/config/gpu_info.h" |
| 18 #include "gpu/ipc/client/command_buffer_proxy_impl.h" |
| 19 #include "ipc/ipc_listener.h" | 19 #include "ipc/ipc_listener.h" |
| 20 #include "media/video/video_encode_accelerator.h" | 20 #include "media/video/video_encode_accelerator.h" |
| 21 | 21 |
| 22 namespace gfx { | 22 namespace gfx { |
| 23 struct GpuMemoryBufferHandle; | 23 struct GpuMemoryBufferHandle; |
| 24 class Size; | 24 class Size; |
| 25 } // namespace gfx | 25 } // namespace gfx |
| 26 | 26 |
| 27 namespace gpu { |
| 28 class GpuChannelHost; |
| 29 } // namespace gpu |
| 30 |
| 27 namespace media { | 31 namespace media { |
| 28 class VideoFrame; | 32 class VideoFrame; |
| 29 } // namespace media | 33 } // namespace media |
| 30 | 34 |
| 31 namespace tracked_objects { | 35 namespace tracked_objects { |
| 32 class Location; | 36 class Location; |
| 33 } // namespace tracked_objects | 37 } // namespace tracked_objects |
| 34 | 38 |
| 35 namespace content { | 39 namespace content { |
| 36 class GpuChannelHost; | |
| 37 | 40 |
| 38 // This class is the renderer-side host for the VideoEncodeAccelerator in the | 41 // This class is the renderer-side host for the VideoEncodeAccelerator in the |
| 39 // GPU process, coordinated over IPC. | 42 // GPU process, coordinated over IPC. |
| 40 class GpuVideoEncodeAcceleratorHost | 43 class GpuVideoEncodeAcceleratorHost |
| 41 : public IPC::Listener, | 44 : public IPC::Listener, |
| 42 public media::VideoEncodeAccelerator, | 45 public media::VideoEncodeAccelerator, |
| 43 public CommandBufferProxyImpl::DeletionObserver, | 46 public gpu::CommandBufferProxyImpl::DeletionObserver, |
| 44 public base::NonThreadSafe { | 47 public base::NonThreadSafe { |
| 45 public: | 48 public: |
| 46 // |this| is guaranteed not to outlive |channel| and |impl|. (See comments | 49 // |this| is guaranteed not to outlive |channel| and |impl|. (See comments |
| 47 // for |channel_| and |impl_|.) | 50 // for |channel_| and |impl_|.) |
| 48 GpuVideoEncodeAcceleratorHost(GpuChannelHost* channel, | 51 GpuVideoEncodeAcceleratorHost(gpu::GpuChannelHost* channel, |
| 49 CommandBufferProxyImpl* impl); | 52 gpu::CommandBufferProxyImpl* impl); |
| 50 | 53 |
| 51 // IPC::Listener implementation. | 54 // IPC::Listener implementation. |
| 52 bool OnMessageReceived(const IPC::Message& message) override; | 55 bool OnMessageReceived(const IPC::Message& message) override; |
| 53 void OnChannelError() override; | 56 void OnChannelError() override; |
| 54 | 57 |
| 55 // media::VideoEncodeAccelerator implementation. | 58 // media::VideoEncodeAccelerator implementation. |
| 56 SupportedProfiles GetSupportedProfiles() override; | 59 SupportedProfiles GetSupportedProfiles() override; |
| 57 bool Initialize(media::VideoPixelFormat input_format, | 60 bool Initialize(media::VideoPixelFormat input_format, |
| 58 const gfx::Size& input_visible_size, | 61 const gfx::Size& input_visible_size, |
| 59 media::VideoCodecProfile output_profile, | 62 media::VideoCodecProfile output_profile, |
| 60 uint32_t initial_bitrate, | 63 uint32_t initial_bitrate, |
| 61 Client* client) override; | 64 Client* client) override; |
| 62 void Encode(const scoped_refptr<media::VideoFrame>& frame, | 65 void Encode(const scoped_refptr<media::VideoFrame>& frame, |
| 63 bool force_keyframe) override; | 66 bool force_keyframe) override; |
| 64 void UseOutputBitstreamBuffer(const media::BitstreamBuffer& buffer) override; | 67 void UseOutputBitstreamBuffer(const media::BitstreamBuffer& buffer) override; |
| 65 void RequestEncodingParametersChange(uint32_t bitrate, | 68 void RequestEncodingParametersChange(uint32_t bitrate, |
| 66 uint32_t framerate_num) override; | 69 uint32_t framerate_num) override; |
| 67 void Destroy() override; | 70 void Destroy() override; |
| 68 | 71 |
| 69 // CommandBufferProxyImpl::DeletionObserver implementation. | 72 // gpu::CommandBufferProxyImpl::DeletionObserver implementation. |
| 70 void OnWillDeleteImpl() override; | 73 void OnWillDeleteImpl() override; |
| 71 | 74 |
| 72 private: | 75 private: |
| 73 // Only Destroy() should be deleting |this|. | 76 // Only Destroy() should be deleting |this|. |
| 74 ~GpuVideoEncodeAcceleratorHost() override; | 77 ~GpuVideoEncodeAcceleratorHost() override; |
| 75 | 78 |
| 76 // Encode specific video frame types. | 79 // Encode specific video frame types. |
| 77 void EncodeGpuMemoryBufferFrame(const scoped_refptr<media::VideoFrame>& frame, | 80 void EncodeGpuMemoryBufferFrame(const scoped_refptr<media::VideoFrame>& frame, |
| 78 bool force_keyframe); | 81 bool force_keyframe); |
| 79 void EncodeSharedMemoryFrame(const scoped_refptr<media::VideoFrame>& frame, | 82 void EncodeSharedMemoryFrame(const scoped_refptr<media::VideoFrame>& frame, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 92 uint32_t output_buffer_size); | 95 uint32_t output_buffer_size); |
| 93 void OnNotifyInputDone(int32_t frame_id); | 96 void OnNotifyInputDone(int32_t frame_id); |
| 94 void OnBitstreamBufferReady(int32_t bitstream_buffer_id, | 97 void OnBitstreamBufferReady(int32_t bitstream_buffer_id, |
| 95 uint32_t payload_size, | 98 uint32_t payload_size, |
| 96 bool key_frame); | 99 bool key_frame); |
| 97 void OnNotifyError(Error error); | 100 void OnNotifyError(Error error); |
| 98 | 101 |
| 99 // Unowned reference to the GpuChannelHost to send IPC messages to the GPU | 102 // Unowned reference to the GpuChannelHost to send IPC messages to the GPU |
| 100 // process. |channel_| outlives |impl_|, so the reference is always valid as | 103 // process. |channel_| outlives |impl_|, so the reference is always valid as |
| 101 // long as it is not NULL. | 104 // long as it is not NULL. |
| 102 GpuChannelHost* channel_; | 105 gpu::GpuChannelHost* channel_; |
| 103 | 106 |
| 104 // Route ID for the associated encoder in the GPU process. | 107 // Route ID for the associated encoder in the GPU process. |
| 105 int32_t encoder_route_id_; | 108 int32_t encoder_route_id_; |
| 106 | 109 |
| 107 // The client that will receive callbacks from the encoder. | 110 // The client that will receive callbacks from the encoder. |
| 108 Client* client_; | 111 Client* client_; |
| 109 | 112 |
| 110 // Unowned reference to the CommandBufferProxyImpl that created us. |this| | 113 // Unowned reference to the gpu::CommandBufferProxyImpl that created us. |
| 111 // registers as a DeletionObserver of |impl_|, so the reference is always | 114 // |this| registers as a DeletionObserver of |impl_|, so the reference is |
| 112 // valid as long as it is not NULL. | 115 // always valid as long as it is not NULL. |
| 113 CommandBufferProxyImpl* impl_; | 116 gpu::CommandBufferProxyImpl* impl_; |
| 114 | 117 |
| 115 // media::VideoFrames sent to the encoder. | 118 // media::VideoFrames sent to the encoder. |
| 116 // base::IDMap not used here, since that takes pointers, not scoped_refptr. | 119 // base::IDMap not used here, since that takes pointers, not scoped_refptr. |
| 117 typedef base::hash_map<int32_t, scoped_refptr<media::VideoFrame>> FrameMap; | 120 typedef base::hash_map<int32_t, scoped_refptr<media::VideoFrame>> FrameMap; |
| 118 FrameMap frame_map_; | 121 FrameMap frame_map_; |
| 119 | 122 |
| 120 // ID serial number for the next frame to send to the GPU process. | 123 // ID serial number for the next frame to send to the GPU process. |
| 121 int32_t next_frame_id_; | 124 int32_t next_frame_id_; |
| 122 | 125 |
| 123 // WeakPtr factory for posting tasks back to itself. | 126 // WeakPtr factory for posting tasks back to itself. |
| 124 base::WeakPtrFactory<GpuVideoEncodeAcceleratorHost> weak_this_factory_; | 127 base::WeakPtrFactory<GpuVideoEncodeAcceleratorHost> weak_this_factory_; |
| 125 | 128 |
| 126 DISALLOW_COPY_AND_ASSIGN(GpuVideoEncodeAcceleratorHost); | 129 DISALLOW_COPY_AND_ASSIGN(GpuVideoEncodeAcceleratorHost); |
| 127 }; | 130 }; |
| 128 | 131 |
| 129 } // namespace content | 132 } // namespace content |
| 130 | 133 |
| 131 #endif // CONTENT_COMMON_GPU_CLIENT_GPU_VIDEO_ENCODE_ACCELERATOR_HOST_H_ | 134 #endif // CONTENT_COMMON_GPU_CLIENT_GPU_VIDEO_ENCODE_ACCELERATOR_HOST_H_ |
| OLD | NEW |