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 CONTENT_COMMON_GPU_MEDIA_VAAPI_VIDEO_ENCODE_ACCELERATOR_H_ |
6 #define CONTENT_COMMON_GPU_MEDIA_VAAPI_VIDEO_ENCODE_ACCELERATOR_H_ | 6 #define CONTENT_COMMON_GPU_MEDIA_VAAPI_VIDEO_ENCODE_ACCELERATOR_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <queue> | 9 #include <queue> |
10 | 10 |
11 #include "base/memory/linked_ptr.h" | 11 #include "base/memory/linked_ptr.h" |
12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
13 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
14 #include "content/common/gpu/media/h264_dpb.h" | 14 #include "content/common/gpu/media/h264_dpb.h" |
15 #include "content/common/gpu/media/va_surface.h" | 15 #include "content/common/gpu/media/va_surface.h" |
16 #include "content/common/gpu/media/vaapi_wrapper.h" | 16 #include "content/common/gpu/media/vaapi_wrapper.h" |
17 #include "media/filters/h264_bitstream_buffer.h" | 17 #include "media/filters/h264_bitstream_buffer.h" |
18 #include "media/video/video_encode_accelerator.h" | 18 #include "media/video/video_encode_accelerator.h" |
19 | 19 |
20 namespace content { | 20 namespace content { |
21 | 21 |
22 // A VideoEncodeAccelerator implementation that uses VA-API | 22 // A VideoEncodeAccelerator implementation that uses VA-API |
23 // (http://www.freedesktop.org/wiki/Software/vaapi) for HW-accelerated | 23 // (http://www.freedesktop.org/wiki/Software/vaapi) for HW-accelerated |
24 // video encode. | 24 // video encode. |
25 class CONTENT_EXPORT VaapiVideoEncodeAccelerator | 25 class CONTENT_EXPORT VaapiVideoEncodeAccelerator |
26 : public media::VideoEncodeAccelerator { | 26 : public media::VideoEncodeAccelerator { |
27 public: | 27 public: |
28 explicit VaapiVideoEncodeAccelerator(Display* x_display); | 28 VaapiVideoEncodeAccelerator(); |
29 virtual ~VaapiVideoEncodeAccelerator(); | 29 virtual ~VaapiVideoEncodeAccelerator(); |
30 | 30 |
31 // media::VideoEncodeAccelerator implementation. | 31 // media::VideoEncodeAccelerator implementation. |
32 virtual std::vector<media::VideoEncodeAccelerator::SupportedProfile> | 32 virtual std::vector<media::VideoEncodeAccelerator::SupportedProfile> |
33 GetSupportedProfiles() override; | 33 GetSupportedProfiles() override; |
34 virtual bool Initialize(media::VideoFrame::Format format, | 34 virtual bool Initialize(media::VideoFrame::Format format, |
35 const gfx::Size& input_visible_size, | 35 const gfx::Size& input_visible_size, |
36 media::VideoCodecProfile output_profile, | 36 media::VideoCodecProfile output_profile, |
37 uint32 initial_bitrate, | 37 uint32 initial_bitrate, |
38 Client* client) override; | 38 Client* client) override; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 void TryToReturnBitstreamBuffer(); | 144 void TryToReturnBitstreamBuffer(); |
145 | 145 |
146 // Puts the encoder into en error state and notifies client about the error. | 146 // Puts the encoder into en error state and notifies client about the error. |
147 void NotifyError(Error error); | 147 void NotifyError(Error error); |
148 | 148 |
149 // Sets the encoder state on the correct thread. | 149 // Sets the encoder state on the correct thread. |
150 void SetState(State state); | 150 void SetState(State state); |
151 | 151 |
152 // VaapiWrapper is the owner of all HW resources (surfaces and buffers) | 152 // VaapiWrapper is the owner of all HW resources (surfaces and buffers) |
153 // and will free them on destruction. | 153 // and will free them on destruction. |
154 scoped_ptr<VaapiWrapper> vaapi_wrapper_; | 154 scoped_refptr<VaapiWrapper> vaapi_wrapper_; |
155 | 155 |
156 // Input profile and sizes. | 156 // Input profile and sizes. |
157 media::VideoCodecProfile profile_; | 157 media::VideoCodecProfile profile_; |
158 gfx::Size visible_size_; | 158 gfx::Size visible_size_; |
159 gfx::Size coded_size_; // Macroblock-aligned. | 159 gfx::Size coded_size_; // Macroblock-aligned. |
160 // Width/height in macroblocks. | 160 // Width/height in macroblocks. |
161 unsigned int mb_width_; | 161 unsigned int mb_width_; |
162 unsigned int mb_height_; | 162 unsigned int mb_height_; |
163 | 163 |
164 // Maximum size of the reference list 0. | 164 // Maximum size of the reference list 0. |
165 unsigned int max_ref_idx_l0_size_; | 165 unsigned int max_ref_idx_l0_size_; |
166 | 166 |
167 // Initial QP. | 167 // Initial QP. |
168 unsigned int qp_; | 168 unsigned int qp_; |
169 | 169 |
170 // IDR frame period. | 170 // IDR frame period. |
171 unsigned int idr_period_; | 171 unsigned int idr_period_; |
172 // I frame period. | 172 // I frame period. |
173 unsigned int i_period_; | 173 unsigned int i_period_; |
174 // IP period, i.e. how often do we need to have either an I or a P frame in | 174 // IP period, i.e. how often do we need to have either an I or a P frame in |
175 // the stream. Period of 1 means we can have no B frames. | 175 // the stream. Period of 1 means we can have no B frames. |
176 unsigned int ip_period_; | 176 unsigned int ip_period_; |
177 | 177 |
178 // Size in bytes required for input bitstream buffers. | 178 // Size in bytes required for input bitstream buffers. |
179 size_t output_buffer_byte_size_; | 179 size_t output_buffer_byte_size_; |
180 | 180 |
181 Display* x_display_; | |
182 | |
183 // All of the members below must be accessed on the encoder_thread_, | 181 // All of the members below must be accessed on the encoder_thread_, |
184 // while it is running. | 182 // while it is running. |
185 | 183 |
186 // Encoder state. Encode tasks will only run in kEncoding state. | 184 // Encoder state. Encode tasks will only run in kEncoding state. |
187 State state_; | 185 State state_; |
188 | 186 |
189 // frame_num to be used for the next frame. | 187 // frame_num to be used for the next frame. |
190 unsigned int frame_num_; | 188 unsigned int frame_num_; |
191 // frame_num of the previous IDR. | 189 // frame_num of the previous IDR. |
192 unsigned int last_idr_frame_num_; | 190 unsigned int last_idr_frame_num_; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 // thread (it's a member of this class). | 252 // thread (it's a member of this class). |
255 base::WeakPtr<VaapiVideoEncodeAccelerator> weak_this_; | 253 base::WeakPtr<VaapiVideoEncodeAccelerator> weak_this_; |
256 base::WeakPtrFactory<VaapiVideoEncodeAccelerator> weak_this_ptr_factory_; | 254 base::WeakPtrFactory<VaapiVideoEncodeAccelerator> weak_this_ptr_factory_; |
257 | 255 |
258 DISALLOW_COPY_AND_ASSIGN(VaapiVideoEncodeAccelerator); | 256 DISALLOW_COPY_AND_ASSIGN(VaapiVideoEncodeAccelerator); |
259 }; | 257 }; |
260 | 258 |
261 } // namespace content | 259 } // namespace content |
262 | 260 |
263 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_VIDEO_ENCODE_ACCELERATOR_H_ | 261 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_VIDEO_ENCODE_ACCELERATOR_H_ |
OLD | NEW |