| 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" | 17 #include "content/common/gpu/client/command_buffer_proxy_impl.h" |
| 18 #include "content/common/gpu/client/ipc/gpu_video_encode_accelerator_host_ipc_tr
ansport.h" |
| 18 #include "gpu/config/gpu_info.h" | 19 #include "gpu/config/gpu_info.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 media { | 27 namespace media { |
| 28 class VideoFrame; | 28 class VideoFrame; |
| 29 } // namespace media | 29 } // namespace media |
| 30 | 30 |
| 31 namespace tracked_objects { | 31 namespace tracked_objects { |
| 32 class Location; | 32 class Location; |
| 33 } // namespace tracked_objects | 33 } // namespace tracked_objects |
| 34 | 34 |
| 35 namespace content { | 35 namespace content { |
| 36 class GpuChannelHost; | 36 class GpuChannelHost; |
| 37 | 37 |
| 38 // This class is the renderer-side host for the VideoEncodeAccelerator in the | 38 // This class is the renderer-side host for the VideoEncodeAccelerator in the |
| 39 // GPU process, coordinated over IPC. | 39 // GPU process, coordinated over IPC. |
| 40 class GpuVideoEncodeAcceleratorHost | 40 class GpuVideoEncodeAcceleratorHost |
| 41 : public IPC::Listener, | 41 : public media::VideoEncodeAccelerator, |
| 42 public media::VideoEncodeAccelerator, | |
| 43 public CommandBufferProxyImpl::DeletionObserver, | 42 public CommandBufferProxyImpl::DeletionObserver, |
| 43 public GpuVideoEncodeAcceleratorHostIPCTransport::Client, |
| 44 public base::NonThreadSafe { | 44 public base::NonThreadSafe { |
| 45 public: | 45 public: |
| 46 // |this| is guaranteed not to outlive |channel| and |impl|. (See comments | 46 // |this| is guaranteed not to outlive |channel| and |impl|. (See comments |
| 47 // for |channel_| and |impl_|.) | 47 // for |channel_| and |impl_|.) |
| 48 GpuVideoEncodeAcceleratorHost(GpuChannelHost* channel, | 48 GpuVideoEncodeAcceleratorHost( |
| 49 CommandBufferProxyImpl* impl); | 49 GpuChannelHost* channel, |
| 50 | 50 scoped_ptr<GpuVideoEncodeAcceleratorHostIPCTransport> transport, |
| 51 // IPC::Listener implementation. | 51 CommandBufferProxyImpl* impl); |
| 52 bool OnMessageReceived(const IPC::Message& message) override; | |
| 53 void OnChannelError() override; | |
| 54 | 52 |
| 55 // media::VideoEncodeAccelerator implementation. | 53 // media::VideoEncodeAccelerator implementation. |
| 56 SupportedProfiles GetSupportedProfiles() override; | 54 SupportedProfiles GetSupportedProfiles() override; |
| 57 bool Initialize(media::VideoPixelFormat input_format, | 55 bool Initialize(media::VideoPixelFormat input_format, |
| 58 const gfx::Size& input_visible_size, | 56 const gfx::Size& input_visible_size, |
| 59 media::VideoCodecProfile output_profile, | 57 media::VideoCodecProfile output_profile, |
| 60 uint32_t initial_bitrate, | 58 uint32_t initial_bitrate, |
| 61 Client* client) override; | 59 media::VideoEncodeAccelerator::Client* client) override; |
| 62 void Encode(const scoped_refptr<media::VideoFrame>& frame, | 60 void Encode(const scoped_refptr<media::VideoFrame>& frame, |
| 63 bool force_keyframe) override; | 61 bool force_keyframe) override; |
| 64 void UseOutputBitstreamBuffer(const media::BitstreamBuffer& buffer) override; | 62 void UseOutputBitstreamBuffer(const media::BitstreamBuffer& buffer) override; |
| 65 void RequestEncodingParametersChange(uint32_t bitrate, | 63 void RequestEncodingParametersChange(uint32_t bitrate, |
| 66 uint32_t framerate_num) override; | 64 uint32_t framerate_num) override; |
| 67 void Destroy() override; | 65 void Destroy() override; |
| 68 | 66 |
| 69 // CommandBufferProxyImpl::DeletionObserver implementation. | 67 // CommandBufferProxyImpl::DeletionObserver implementation. |
| 70 void OnWillDeleteImpl() override; | 68 void OnWillDeleteImpl() override; |
| 71 | 69 |
| 72 private: | 70 private: |
| 73 // Only Destroy() should be deleting |this|. | 71 // Only Destroy() should be deleting |this|. |
| 74 ~GpuVideoEncodeAcceleratorHost() override; | 72 ~GpuVideoEncodeAcceleratorHost() override; |
| 75 | 73 |
| 76 // Encode specific video frame types. | 74 // Encode specific video frame types. |
| 77 void EncodeGpuMemoryBufferFrame(const scoped_refptr<media::VideoFrame>& frame, | 75 void EncodeGpuMemoryBufferFrame(const scoped_refptr<media::VideoFrame>& frame, |
| 78 bool force_keyframe); | 76 bool force_keyframe); |
| 79 void EncodeSharedMemoryFrame(const scoped_refptr<media::VideoFrame>& frame, | 77 void EncodeSharedMemoryFrame(const scoped_refptr<media::VideoFrame>& frame, |
| 80 bool force_keyframe); | 78 bool force_keyframe); |
| 81 | 79 |
| 82 // Notify |client_| of an error. Posts a task to avoid re-entrancy. | 80 // Notify |client_| of an error. Posts a task to avoid re-entrancy. |
| 83 void PostNotifyError(const tracked_objects::Location& location, | 81 void PostNotifyError(const tracked_objects::Location& location, |
| 84 Error error, const std::string& message); | 82 Error error, const std::string& message); |
| 85 | 83 |
| 86 void Send(IPC::Message* message); | |
| 87 | |
| 88 // IPC handlers, proxying media::VideoEncodeAccelerator::Client for the GPU | 84 // IPC handlers, proxying media::VideoEncodeAccelerator::Client for the GPU |
| 89 // process. Should not be called directly. | 85 // process. Should not be called directly. |
| 90 void OnRequireBitstreamBuffers(uint32_t input_count, | 86 void OnRequireBitstreamBuffers(uint32_t input_count, |
| 91 const gfx::Size& input_coded_size, | 87 const gfx::Size& input_coded_size, |
| 92 uint32_t output_buffer_size); | 88 uint32_t output_buffer_size) override; |
| 93 void OnNotifyInputDone(int32_t frame_id); | 89 void OnNotifyInputDone(int32_t frame_id) override; |
| 94 void OnBitstreamBufferReady(int32_t bitstream_buffer_id, | 90 void OnBitstreamBufferReady(int32_t bitstream_buffer_id, |
| 95 uint32_t payload_size, | 91 uint32_t payload_size, |
| 96 bool key_frame); | 92 bool key_frame) override; |
| 97 void OnNotifyError(Error error); | 93 void OnNotifyError(Error error) override; |
| 98 | 94 |
| 99 // Unowned reference to the GpuChannelHost to send IPC messages to the GPU | 95 // Unowned reference to the GpuChannelHost to send IPC messages to the GPU |
| 100 // process. |channel_| outlives |impl_|, so the reference is always valid as | 96 // process. |channel_| outlives |impl_|, so the reference is always valid as |
| 101 // long as it is not NULL. | 97 // long as it is not NULL. |
| 102 GpuChannelHost* channel_; | 98 GpuChannelHost* channel_; |
| 103 | 99 |
| 104 // Route ID for the associated encoder in the GPU process. | 100 scoped_ptr<GpuVideoEncodeAcceleratorHostIPCTransport> transport_; |
| 105 int32_t encoder_route_id_; | |
| 106 | 101 |
| 107 // The client that will receive callbacks from the encoder. | 102 // The client that will receive callbacks from the encoder. |
| 108 Client* client_; | 103 media::VideoEncodeAccelerator::Client* client_; |
| 109 | 104 |
| 110 // Unowned reference to the CommandBufferProxyImpl that created us. |this| | 105 // Unowned reference to the CommandBufferProxyImpl that created us. |this| |
| 111 // registers as a DeletionObserver of |impl_|, so the reference is always | 106 // registers as a DeletionObserver of |impl_|, so the reference is always |
| 112 // valid as long as it is not NULL. | 107 // valid as long as it is not NULL. |
| 113 CommandBufferProxyImpl* impl_; | 108 CommandBufferProxyImpl* impl_; |
| 114 | 109 |
| 115 // media::VideoFrames sent to the encoder. | 110 // media::VideoFrames sent to the encoder. |
| 116 // base::IDMap not used here, since that takes pointers, not scoped_refptr. | 111 // base::IDMap not used here, since that takes pointers, not scoped_refptr. |
| 117 typedef base::hash_map<int32_t, scoped_refptr<media::VideoFrame>> FrameMap; | 112 typedef base::hash_map<int32_t, scoped_refptr<media::VideoFrame>> FrameMap; |
| 118 FrameMap frame_map_; | 113 FrameMap frame_map_; |
| 119 | 114 |
| 120 // ID serial number for the next frame to send to the GPU process. | 115 // ID serial number for the next frame to send to the GPU process. |
| 121 int32_t next_frame_id_; | 116 int32_t next_frame_id_; |
| 122 | 117 |
| 123 // WeakPtr factory for posting tasks back to itself. | 118 // WeakPtr factory for posting tasks back to itself. |
| 124 base::WeakPtrFactory<GpuVideoEncodeAcceleratorHost> weak_this_factory_; | 119 base::WeakPtrFactory<GpuVideoEncodeAcceleratorHost> weak_this_factory_; |
| 125 | 120 |
| 126 DISALLOW_COPY_AND_ASSIGN(GpuVideoEncodeAcceleratorHost); | 121 DISALLOW_COPY_AND_ASSIGN(GpuVideoEncodeAcceleratorHost); |
| 127 }; | 122 }; |
| 128 | 123 |
| 129 } // namespace content | 124 } // namespace content |
| 130 | 125 |
| 131 #endif // CONTENT_COMMON_GPU_CLIENT_GPU_VIDEO_ENCODE_ACCELERATOR_HOST_H_ | 126 #endif // CONTENT_COMMON_GPU_CLIENT_GPU_VIDEO_ENCODE_ACCELERATOR_HOST_H_ |
| OLD | NEW |