| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_ENCODE_ACCELERATOR_H_ | |
| 6 #define CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_ENCODE_ACCELERATOR_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 #include <stdint.h> | |
| 10 | |
| 11 #include <memory> | |
| 12 #include <vector> | |
| 13 | |
| 14 #include "base/macros.h" | |
| 15 #include "base/memory/weak_ptr.h" | |
| 16 #include "gpu/config/gpu_info.h" | |
| 17 #include "gpu/ipc/service/gpu_command_buffer_stub.h" | |
| 18 #include "ipc/ipc_listener.h" | |
| 19 #include "media/video/video_encode_accelerator.h" | |
| 20 #include "ui/gfx/geometry/size.h" | |
| 21 | |
| 22 struct AcceleratedVideoEncoderMsg_Encode_Params; | |
| 23 struct AcceleratedVideoEncoderMsg_Encode_Params2; | |
| 24 | |
| 25 namespace base { | |
| 26 class SharedMemory; | |
| 27 } // namespace base | |
| 28 | |
| 29 namespace gpu { | |
| 30 struct GpuPreferences; | |
| 31 } // namespace gpu | |
| 32 | |
| 33 namespace content { | |
| 34 | |
| 35 // This class encapsulates the GPU process view of a VideoEncodeAccelerator, | |
| 36 // wrapping the platform-specific VideoEncodeAccelerator instance. It handles | |
| 37 // IPC coming in from the renderer and passes it to the underlying VEA. | |
| 38 class GpuVideoEncodeAccelerator | |
| 39 : public IPC::Listener, | |
| 40 public media::VideoEncodeAccelerator::Client, | |
| 41 public gpu::GpuCommandBufferStub::DestructionObserver { | |
| 42 public: | |
| 43 GpuVideoEncodeAccelerator(int32_t host_route_id, | |
| 44 gpu::GpuCommandBufferStub* stub); | |
| 45 ~GpuVideoEncodeAccelerator() override; | |
| 46 | |
| 47 // Initialize this accelerator with the given parameters and send | |
| 48 // |init_done_msg| when complete. | |
| 49 bool Initialize(media::VideoPixelFormat input_format, | |
| 50 const gfx::Size& input_visible_size, | |
| 51 media::VideoCodecProfile output_profile, | |
| 52 uint32_t initial_bitrate); | |
| 53 | |
| 54 // IPC::Listener implementation | |
| 55 bool OnMessageReceived(const IPC::Message& message) override; | |
| 56 | |
| 57 // media::VideoEncodeAccelerator::Client implementation. | |
| 58 void RequireBitstreamBuffers(unsigned int input_count, | |
| 59 const gfx::Size& input_coded_size, | |
| 60 size_t output_buffer_size) override; | |
| 61 void BitstreamBufferReady(int32_t bitstream_buffer_id, | |
| 62 size_t payload_size, | |
| 63 bool key_frame) override; | |
| 64 void NotifyError(media::VideoEncodeAccelerator::Error error) override; | |
| 65 | |
| 66 // gpu::GpuCommandBufferStub::DestructionObserver implementation. | |
| 67 void OnWillDestroyStub() override; | |
| 68 | |
| 69 // Static query for supported profiles. This query calls the appropriate | |
| 70 // platform-specific version. The returned supported profiles vector will | |
| 71 // not contain duplicates. | |
| 72 static gpu::VideoEncodeAcceleratorSupportedProfiles GetSupportedProfiles( | |
| 73 const gpu::GpuPreferences& gpu_preferences); | |
| 74 | |
| 75 private: | |
| 76 typedef std::unique_ptr<media::VideoEncodeAccelerator> (*CreateVEAFp)(); | |
| 77 | |
| 78 // Return a set of VEA Create function pointers applicable to the current | |
| 79 // platform. | |
| 80 static std::vector<CreateVEAFp> CreateVEAFps( | |
| 81 const gpu::GpuPreferences& gpu_preferences); | |
| 82 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC) | |
| 83 static std::unique_ptr<media::VideoEncodeAccelerator> CreateV4L2VEA(); | |
| 84 #endif | |
| 85 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | |
| 86 static std::unique_ptr<media::VideoEncodeAccelerator> CreateVaapiVEA(); | |
| 87 #endif | |
| 88 #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC) | |
| 89 static std::unique_ptr<media::VideoEncodeAccelerator> CreateAndroidVEA(); | |
| 90 #endif | |
| 91 #if defined(OS_MACOSX) | |
| 92 static std::unique_ptr<media::VideoEncodeAccelerator> CreateVTVEA(); | |
| 93 #endif | |
| 94 | |
| 95 // IPC handlers, proxying media::VideoEncodeAccelerator for the renderer | |
| 96 // process. | |
| 97 void OnEncode(const AcceleratedVideoEncoderMsg_Encode_Params& params); | |
| 98 void OnEncode2(const AcceleratedVideoEncoderMsg_Encode_Params2& params); | |
| 99 void OnUseOutputBitstreamBuffer(int32_t buffer_id, | |
| 100 base::SharedMemoryHandle buffer_handle, | |
| 101 uint32_t buffer_size); | |
| 102 void OnRequestEncodingParametersChange(uint32_t bitrate, uint32_t framerate); | |
| 103 | |
| 104 void OnDestroy(); | |
| 105 | |
| 106 void EncodeFrameFinished(int32_t frame_id, | |
| 107 std::unique_ptr<base::SharedMemory> shm); | |
| 108 void Send(IPC::Message* message); | |
| 109 | |
| 110 // Route ID to communicate with the host. | |
| 111 const uint32_t host_route_id_; | |
| 112 | |
| 113 // Unowned pointer to the underlying gpu::GpuCommandBufferStub. |this| is | |
| 114 // registered as a DestuctionObserver of |stub_| and will self-delete when | |
| 115 // |stub_| is destroyed. | |
| 116 gpu::GpuCommandBufferStub* const stub_; | |
| 117 | |
| 118 // Owned pointer to the underlying VideoEncodeAccelerator. | |
| 119 std::unique_ptr<media::VideoEncodeAccelerator> encoder_; | |
| 120 base::Callback<bool(void)> make_context_current_; | |
| 121 | |
| 122 // Video encoding parameters. | |
| 123 media::VideoPixelFormat input_format_; | |
| 124 gfx::Size input_visible_size_; | |
| 125 gfx::Size input_coded_size_; | |
| 126 size_t output_buffer_size_; | |
| 127 | |
| 128 // Weak pointer for media::VideoFrames that refer back to |this|. | |
| 129 base::WeakPtrFactory<GpuVideoEncodeAccelerator> weak_this_factory_; | |
| 130 | |
| 131 DISALLOW_COPY_AND_ASSIGN(GpuVideoEncodeAccelerator); | |
| 132 }; | |
| 133 | |
| 134 } // namespace content | |
| 135 | |
| 136 #endif // CONTENT_COMMON_GPU_MEDIA_GPU_VIDEO_ENCODE_ACCELERATOR_H_ | |
| OLD | NEW |