OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This file contains an implementation of a class that provides H264 decode | 5 // This file contains an implementation of a class that provides H264 decode |
6 // support for use with VAAPI hardware video decode acceleration on Intel | 6 // support for use with VAAPI hardware video decode acceleration on Intel |
7 // systems. | 7 // systems. |
8 | 8 |
9 #ifndef CONTENT_COMMON_GPU_MEDIA_VAAPI_H264_DECODER_H_ | 9 #ifndef CONTENT_COMMON_GPU_MEDIA_VAAPI_H264_DECODER_H_ |
10 #define CONTENT_COMMON_GPU_MEDIA_VAAPI_H264_DECODER_H_ | 10 #define CONTENT_COMMON_GPU_MEDIA_VAAPI_H264_DECODER_H_ |
11 | 11 |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/callback_forward.h" | 14 #include "base/callback_forward.h" |
15 #include "base/memory/linked_ptr.h" | 15 #include "base/memory/linked_ptr.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "content/common/gpu/media/vaapi_h264_dpb.h" | 18 #include "content/common/gpu/media/h264_dpb.h" |
19 #include "content/common/gpu/media/vaapi_wrapper.h" | 19 #include "content/common/gpu/media/vaapi_wrapper.h" |
20 #include "media/base/limits.h" | 20 #include "media/base/limits.h" |
21 #include "media/filters/h264_parser.h" | 21 #include "media/filters/h264_parser.h" |
22 | 22 |
23 namespace content { | 23 namespace content { |
24 | 24 |
25 // An H264 decoder that utilizes VA-API. Provides features not supported by | 25 // An H264 decoder that utilizes VA-API. Provides features not supported by |
26 // the VA-API userspace library (libva), including stream parsing, reference | 26 // the VA-API userspace library (libva), including stream parsing, reference |
27 // picture management and other operations not supported by the HW codec. | 27 // picture management and other operations not supported by the HW codec. |
28 // | 28 // |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 | 109 |
110 private: | 110 private: |
111 // We need to keep at most kDPBMaxSize pictures in DPB for | 111 // We need to keep at most kDPBMaxSize pictures in DPB for |
112 // reference/to display later and an additional one for the one currently | 112 // reference/to display later and an additional one for the one currently |
113 // being decoded. We also ask for some additional ones since VDA needs | 113 // being decoded. We also ask for some additional ones since VDA needs |
114 // to accumulate a few ready-to-output pictures before it actually starts | 114 // to accumulate a few ready-to-output pictures before it actually starts |
115 // displaying and giving them back. +2 instead of +1 because of subjective | 115 // displaying and giving them back. +2 instead of +1 because of subjective |
116 // smoothness improvement during testing. | 116 // smoothness improvement during testing. |
117 enum { | 117 enum { |
118 kPicsInPipeline = media::limits::kMaxVideoFrames + 2, | 118 kPicsInPipeline = media::limits::kMaxVideoFrames + 2, |
119 kMaxNumReqPictures = VaapiH264DPB::kDPBMaxSize + kPicsInPipeline, | 119 kMaxNumReqPictures = H264DPB::kDPBMaxSize + kPicsInPipeline, |
120 }; | 120 }; |
121 | 121 |
122 // Internal state of the decoder. | 122 // Internal state of the decoder. |
123 enum State { | 123 enum State { |
124 kNeedStreamMetadata, // After initialization, need an SPS. | 124 kNeedStreamMetadata, // After initialization, need an SPS. |
125 kDecoding, // Ready to decode from any point. | 125 kDecoding, // Ready to decode from any point. |
126 kAfterReset, // After Reset(), need a resume point. | 126 kAfterReset, // After Reset(), need a resume point. |
127 kError, // Error in decode, can't continue. | 127 kError, // Error in decode, can't continue. |
128 }; | 128 }; |
129 | 129 |
(...skipping 17 matching lines...) Expand all Loading... |
147 | 147 |
148 // Prepare reference picture lists (ref_pic_list[01]_). | 148 // Prepare reference picture lists (ref_pic_list[01]_). |
149 bool PrepareRefPicLists(media::H264SliceHeader* slice_hdr); | 149 bool PrepareRefPicLists(media::H264SliceHeader* slice_hdr); |
150 | 150 |
151 // Construct initial reference picture lists for use in decoding of | 151 // Construct initial reference picture lists for use in decoding of |
152 // P and B pictures (see 8.2.4 in spec). | 152 // P and B pictures (see 8.2.4 in spec). |
153 void ConstructReferencePicListsP(media::H264SliceHeader* slice_hdr); | 153 void ConstructReferencePicListsP(media::H264SliceHeader* slice_hdr); |
154 void ConstructReferencePicListsB(media::H264SliceHeader* slice_hdr); | 154 void ConstructReferencePicListsB(media::H264SliceHeader* slice_hdr); |
155 | 155 |
156 // Helper functions for reference list construction, per spec. | 156 // Helper functions for reference list construction, per spec. |
157 int PicNumF(VaapiH264Picture *pic); | 157 int PicNumF(H264Picture *pic); |
158 int LongTermPicNumF(VaapiH264Picture *pic); | 158 int LongTermPicNumF(H264Picture *pic); |
159 | 159 |
160 // Perform the reference picture lists' modification (reordering), as | 160 // Perform the reference picture lists' modification (reordering), as |
161 // specified in spec (8.2.4). | 161 // specified in spec (8.2.4). |
162 // | 162 // |
163 // |list| indicates list number and should be either 0 or 1. | 163 // |list| indicates list number and should be either 0 or 1. |
164 bool ModifyReferencePicList(media::H264SliceHeader* slice_hdr, int list); | 164 bool ModifyReferencePicList(media::H264SliceHeader* slice_hdr, int list); |
165 | 165 |
166 // Perform reference picture memory management operations (marking/unmarking | 166 // Perform reference picture memory management operations (marking/unmarking |
167 // of reference pictures, long term picture management, discarding, etc.). | 167 // of reference pictures, long term picture management, discarding, etc.). |
168 // See 8.2.5 in spec. | 168 // See 8.2.5 in spec. |
(...skipping 18 matching lines...) Expand all Loading... |
187 void ClearDPB(); | 187 void ClearDPB(); |
188 | 188 |
189 // These queue up data for HW decoder to be committed on running HW decode. | 189 // These queue up data for HW decoder to be committed on running HW decode. |
190 bool SendPPS(); | 190 bool SendPPS(); |
191 bool SendIQMatrix(); | 191 bool SendIQMatrix(); |
192 bool SendVASliceParam(media::H264SliceHeader* slice_hdr); | 192 bool SendVASliceParam(media::H264SliceHeader* slice_hdr); |
193 bool SendSliceData(const uint8* ptr, size_t size); | 193 bool SendSliceData(const uint8* ptr, size_t size); |
194 bool QueueSlice(media::H264SliceHeader* slice_hdr); | 194 bool QueueSlice(media::H264SliceHeader* slice_hdr); |
195 | 195 |
196 // Helper methods for filling HW structures. | 196 // Helper methods for filling HW structures. |
197 void FillVAPicture(VAPictureH264 *va_pic, VaapiH264Picture* pic); | 197 void FillVAPicture(VAPictureH264 *va_pic, H264Picture* pic); |
198 int FillVARefFramesFromDPB(VAPictureH264 *va_pics, int num_pics); | 198 int FillVARefFramesFromDPB(VAPictureH264 *va_pics, int num_pics); |
199 | 199 |
200 // Commits all pending data for HW decoder and starts HW decoder. | 200 // Commits all pending data for HW decoder and starts HW decoder. |
201 bool DecodePicture(); | 201 bool DecodePicture(); |
202 | 202 |
203 // Notifies client that a picture is ready for output. | 203 // Notifies client that a picture is ready for output. |
204 bool OutputPic(VaapiH264Picture* pic); | 204 bool OutputPic(H264Picture* pic); |
205 | 205 |
206 // Output all pictures in DPB that have not been outputted yet. | 206 // Output all pictures in DPB that have not been outputted yet. |
207 bool OutputAllRemainingPics(); | 207 bool OutputAllRemainingPics(); |
208 | 208 |
209 // Represents a frame being decoded. Will always have a VASurface | 209 // Represents a frame being decoded. Will always have a VASurface |
210 // assigned to it, which will eventually contain decoded picture data. | 210 // assigned to it, which will eventually contain decoded picture data. |
211 class DecodeSurface; | 211 class DecodeSurface; |
212 | 212 |
213 // Assign an available surface to the given PicOrderCnt |poc|, | 213 // Assign an available surface to the given PicOrderCnt |poc|, |
214 // removing it from the available surfaces pool. Return true if a surface | 214 // removing it from the available surfaces pool. Return true if a surface |
215 // has been found, false otherwise. | 215 // has been found, false otherwise. |
216 bool AssignSurfaceToPoC(int32 input_id, int poc); | 216 bool AssignSurfaceToPoC(int32 input_id, int poc); |
217 | 217 |
218 // Indicate that a surface is no longer needed by decoder. | 218 // Indicate that a surface is no longer needed by decoder. |
219 void UnassignSurfaceFromPoC(int poc); | 219 void UnassignSurfaceFromPoC(int poc); |
220 | 220 |
221 // Return DecodeSurface assigned to |poc|. | 221 // Return DecodeSurface assigned to |poc|. |
222 DecodeSurface* DecodeSurfaceByPoC(int poc); | 222 DecodeSurface* DecodeSurfaceByPoC(int poc); |
223 | 223 |
224 // Decoder state. | 224 // Decoder state. |
225 State state_; | 225 State state_; |
226 | 226 |
227 // Parser in use. | 227 // Parser in use. |
228 media::H264Parser parser_; | 228 media::H264Parser parser_; |
229 | 229 |
230 // DPB in use. | 230 // DPB in use. |
231 VaapiH264DPB dpb_; | 231 H264DPB dpb_; |
232 | 232 |
233 // Picture currently being processed/decoded. | 233 // Picture currently being processed/decoded. |
234 scoped_ptr<VaapiH264Picture> curr_pic_; | 234 scoped_ptr<H264Picture> curr_pic_; |
235 | 235 |
236 // Reference picture lists, constructed for each picture before decoding. | 236 // Reference picture lists, constructed for each picture before decoding. |
237 // Those lists are not owners of the pointers (DPB is). | 237 // Those lists are not owners of the pointers (DPB is). |
238 VaapiH264Picture::PtrVector ref_pic_list0_; | 238 H264Picture::PtrVector ref_pic_list0_; |
239 VaapiH264Picture::PtrVector ref_pic_list1_; | 239 H264Picture::PtrVector ref_pic_list1_; |
240 | 240 |
241 // Global state values, needed in decoding. See spec. | 241 // Global state values, needed in decoding. See spec. |
242 int max_pic_order_cnt_lsb_; | 242 int max_pic_order_cnt_lsb_; |
243 int max_frame_num_; | 243 int max_frame_num_; |
244 int max_pic_num_; | 244 int max_pic_num_; |
245 int max_long_term_frame_idx_; | 245 int max_long_term_frame_idx_; |
246 size_t max_num_reorder_frames_; | 246 size_t max_num_reorder_frames_; |
247 | 247 |
248 int frame_num_; | 248 int frame_num_; |
249 int prev_frame_num_; | 249 int prev_frame_num_; |
250 int prev_frame_num_offset_; | 250 int prev_frame_num_offset_; |
251 bool prev_has_memmgmnt5_; | 251 bool prev_has_memmgmnt5_; |
252 | 252 |
253 // Values related to previously decoded reference picture. | 253 // Values related to previously decoded reference picture. |
254 bool prev_ref_has_memmgmnt5_; | 254 bool prev_ref_has_memmgmnt5_; |
255 int prev_ref_top_field_order_cnt_; | 255 int prev_ref_top_field_order_cnt_; |
256 int prev_ref_pic_order_cnt_msb_; | 256 int prev_ref_pic_order_cnt_msb_; |
257 int prev_ref_pic_order_cnt_lsb_; | 257 int prev_ref_pic_order_cnt_lsb_; |
258 VaapiH264Picture::Field prev_ref_field_; | 258 H264Picture::Field prev_ref_field_; |
259 | 259 |
260 // Currently active SPS and PPS. | 260 // Currently active SPS and PPS. |
261 int curr_sps_id_; | 261 int curr_sps_id_; |
262 int curr_pps_id_; | 262 int curr_pps_id_; |
263 | 263 |
264 // Output picture size. | 264 // Output picture size. |
265 gfx::Size pic_size_; | 265 gfx::Size pic_size_; |
266 | 266 |
267 // Maps H.264 PicOrderCount to currently used DecodeSurfaces; | 267 // Maps H.264 PicOrderCount to currently used DecodeSurfaces; |
268 typedef std::map<int, linked_ptr<DecodeSurface> > DecSurfacesInUse; | 268 typedef std::map<int, linked_ptr<DecodeSurface> > DecSurfacesInUse; |
(...skipping 17 matching lines...) Expand all Loading... |
286 | 286 |
287 // PicOrderCount of the previously outputted frame. | 287 // PicOrderCount of the previously outputted frame. |
288 int last_output_poc_; | 288 int last_output_poc_; |
289 | 289 |
290 DISALLOW_COPY_AND_ASSIGN(VaapiH264Decoder); | 290 DISALLOW_COPY_AND_ASSIGN(VaapiH264Decoder); |
291 }; | 291 }; |
292 | 292 |
293 } // namespace content | 293 } // namespace content |
294 | 294 |
295 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_H264_DECODER_H_ | 295 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_H264_DECODER_H_ |
OLD | NEW |