| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_MEDIA_VAAPI_VIDEO_ENCODE_ACCELERATOR_H_ | 5 #ifndef MEDIA_GPU_VAAPI_VIDEO_ENCODE_ACCELERATOR_H_ |
| 6 #define CONTENT_COMMON_GPU_MEDIA_VAAPI_VIDEO_ENCODE_ACCELERATOR_H_ | 6 #define MEDIA_GPU_VAAPI_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 <list> | 11 #include <list> |
| 12 #include <queue> | 12 #include <queue> |
| 13 | 13 |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/linked_ptr.h" | 15 #include "base/memory/linked_ptr.h" |
| 16 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
| 17 #include "content/common/content_export.h" | |
| 18 #include "content/common/gpu/media/h264_dpb.h" | |
| 19 #include "content/common/gpu/media/va_surface.h" | |
| 20 #include "content/common/gpu/media/vaapi_wrapper.h" | |
| 21 #include "media/filters/h264_bitstream_buffer.h" | 17 #include "media/filters/h264_bitstream_buffer.h" |
| 18 #include "media/gpu/h264_dpb.h" |
| 19 #include "media/gpu/media_gpu_export.h" |
| 20 #include "media/gpu/va_surface.h" |
| 21 #include "media/gpu/vaapi_wrapper.h" |
| 22 #include "media/video/video_encode_accelerator.h" | 22 #include "media/video/video_encode_accelerator.h" |
| 23 | 23 |
| 24 namespace content { | 24 namespace media { |
| 25 | 25 |
| 26 // A VideoEncodeAccelerator implementation that uses VA-API | 26 // A VideoEncodeAccelerator implementation that uses VA-API |
| 27 // (http://www.freedesktop.org/wiki/Software/vaapi) for HW-accelerated | 27 // (http://www.freedesktop.org/wiki/Software/vaapi) for HW-accelerated |
| 28 // video encode. | 28 // video encode. |
| 29 class CONTENT_EXPORT VaapiVideoEncodeAccelerator | 29 class MEDIA_GPU_EXPORT VaapiVideoEncodeAccelerator |
| 30 : public media::VideoEncodeAccelerator { | 30 : public media::VideoEncodeAccelerator { |
| 31 public: | 31 public: |
| 32 VaapiVideoEncodeAccelerator(); | 32 VaapiVideoEncodeAccelerator(); |
| 33 ~VaapiVideoEncodeAccelerator() override; | 33 ~VaapiVideoEncodeAccelerator() override; |
| 34 | 34 |
| 35 // media::VideoEncodeAccelerator implementation. | 35 // media::VideoEncodeAccelerator implementation. |
| 36 media::VideoEncodeAccelerator::SupportedProfiles GetSupportedProfiles() | 36 media::VideoEncodeAccelerator::SupportedProfiles GetSupportedProfiles() |
| 37 override; | 37 override; |
| 38 bool Initialize(media::VideoPixelFormat format, | 38 bool Initialize(media::VideoPixelFormat format, |
| 39 const gfx::Size& input_visible_size, | 39 const gfx::Size& input_visible_size, |
| 40 media::VideoCodecProfile output_profile, | 40 media::VideoCodecProfile output_profile, |
| 41 uint32_t initial_bitrate, | 41 uint32_t initial_bitrate, |
| 42 Client* client) override; | 42 Client* client) override; |
| 43 void Encode(const scoped_refptr<media::VideoFrame>& frame, | 43 void Encode(const scoped_refptr<media::VideoFrame>& frame, |
| 44 bool force_keyframe) override; | 44 bool force_keyframe) override; |
| 45 void UseOutputBitstreamBuffer(const media::BitstreamBuffer& buffer) override; | 45 void UseOutputBitstreamBuffer(const media::BitstreamBuffer& buffer) override; |
| 46 void RequestEncodingParametersChange(uint32_t bitrate, | 46 void RequestEncodingParametersChange(uint32_t bitrate, |
| 47 uint32_t framerate) override; | 47 uint32_t framerate) override; |
| 48 void Destroy() override; | 48 void Destroy() override; |
| 49 | 49 |
| 50 private: | 50 private: |
| 51 // Reference picture list. | 51 // Reference picture list. |
| 52 typedef std::list<scoped_refptr<VASurface> > RefPicList; | 52 typedef std::list<scoped_refptr<VASurface>> RefPicList; |
| 53 | 53 |
| 54 // Encode job for one frame. Created when an input frame is awaiting and | 54 // Encode job for one frame. Created when an input frame is awaiting and |
| 55 // enough resources are available to proceed. Once the job is prepared and | 55 // enough resources are available to proceed. Once the job is prepared and |
| 56 // submitted to the hardware, it awaits on the submitted_encode_jobs_ queue | 56 // submitted to the hardware, it awaits on the submitted_encode_jobs_ queue |
| 57 // for an output bitstream buffer to become available. Once one is ready, | 57 // for an output bitstream buffer to become available. Once one is ready, |
| 58 // the encoded bytes are downloaded to it and job resources are released | 58 // the encoded bytes are downloaded to it and job resources are released |
| 59 // and become available for reuse. | 59 // and become available for reuse. |
| 60 struct EncodeJob { | 60 struct EncodeJob { |
| 61 // Input surface for video frame data. | 61 // Input surface for video frame data. |
| 62 scoped_refptr<VASurface> input_surface; | 62 scoped_refptr<VASurface> input_surface; |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 // VA buffers for coded frames. | 224 // VA buffers for coded frames. |
| 225 std::vector<VABufferID> available_va_buffer_ids_; | 225 std::vector<VABufferID> available_va_buffer_ids_; |
| 226 | 226 |
| 227 // Currently active reference surfaces. | 227 // Currently active reference surfaces. |
| 228 RefPicList ref_pic_list0_; | 228 RefPicList ref_pic_list0_; |
| 229 | 229 |
| 230 // Callback via which finished VA surfaces are returned to us. | 230 // Callback via which finished VA surfaces are returned to us. |
| 231 VASurface::ReleaseCB va_surface_release_cb_; | 231 VASurface::ReleaseCB va_surface_release_cb_; |
| 232 | 232 |
| 233 // VideoFrames passed from the client, waiting to be encoded. | 233 // VideoFrames passed from the client, waiting to be encoded. |
| 234 std::queue<linked_ptr<InputFrameRef> > encoder_input_queue_; | 234 std::queue<linked_ptr<InputFrameRef>> encoder_input_queue_; |
| 235 | 235 |
| 236 // BitstreamBuffers mapped, ready to be filled. | 236 // BitstreamBuffers mapped, ready to be filled. |
| 237 std::queue<linked_ptr<BitstreamBufferRef> > available_bitstream_buffers_; | 237 std::queue<linked_ptr<BitstreamBufferRef>> available_bitstream_buffers_; |
| 238 | 238 |
| 239 // Jobs submitted for encode, awaiting bitstream buffers to become available. | 239 // Jobs submitted for encode, awaiting bitstream buffers to become available. |
| 240 std::queue<linked_ptr<EncodeJob> > submitted_encode_jobs_; | 240 std::queue<linked_ptr<EncodeJob>> submitted_encode_jobs_; |
| 241 | 241 |
| 242 // Encoder thread. All tasks are executed on it. | 242 // Encoder thread. All tasks are executed on it. |
| 243 base::Thread encoder_thread_; | 243 base::Thread encoder_thread_; |
| 244 scoped_refptr<base::SingleThreadTaskRunner> encoder_thread_task_runner_; | 244 scoped_refptr<base::SingleThreadTaskRunner> encoder_thread_task_runner_; |
| 245 | 245 |
| 246 const scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_; | 246 const scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_; |
| 247 | 247 |
| 248 // To expose client callbacks from VideoEncodeAccelerator. | 248 // To expose client callbacks from VideoEncodeAccelerator. |
| 249 // NOTE: all calls to these objects *MUST* be executed on | 249 // NOTE: all calls to these objects *MUST* be executed on |
| 250 // child_task_runner_. | 250 // child_task_runner_. |
| 251 std::unique_ptr<base::WeakPtrFactory<Client>> client_ptr_factory_; | 251 std::unique_ptr<base::WeakPtrFactory<Client>> client_ptr_factory_; |
| 252 base::WeakPtr<Client> client_; | 252 base::WeakPtr<Client> client_; |
| 253 | 253 |
| 254 // WeakPtr to post from the encoder thread back to the ChildThread, as it may | 254 // WeakPtr to post from the encoder thread back to the ChildThread, as it may |
| 255 // outlive this. Posting from the ChildThread using base::Unretained(this) | 255 // outlive this. Posting from the ChildThread using base::Unretained(this) |
| 256 // to the encoder thread is safe, because |this| always outlives the encoder | 256 // to the encoder thread is safe, because |this| always outlives the encoder |
| 257 // thread (it's a member of this class). | 257 // thread (it's a member of this class). |
| 258 base::WeakPtr<VaapiVideoEncodeAccelerator> weak_this_; | 258 base::WeakPtr<VaapiVideoEncodeAccelerator> weak_this_; |
| 259 base::WeakPtrFactory<VaapiVideoEncodeAccelerator> weak_this_ptr_factory_; | 259 base::WeakPtrFactory<VaapiVideoEncodeAccelerator> weak_this_ptr_factory_; |
| 260 | 260 |
| 261 DISALLOW_COPY_AND_ASSIGN(VaapiVideoEncodeAccelerator); | 261 DISALLOW_COPY_AND_ASSIGN(VaapiVideoEncodeAccelerator); |
| 262 }; | 262 }; |
| 263 | 263 |
| 264 } // namespace content | 264 } // namespace media |
| 265 | 265 |
| 266 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_VIDEO_ENCODE_ACCELERATOR_H_ | 266 #endif // MEDIA_GPU_VAAPI_VIDEO_ENCODE_ACCELERATOR_H_ |
| OLD | NEW |