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 #include "content/common/gpu/media/h264_parser.h" | 5 #include "content/common/gpu/media/h264_parser.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 | 10 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 STLDeleteValues(&active_PPSes_); | 113 STLDeleteValues(&active_PPSes_); |
114 } | 114 } |
115 | 115 |
116 void H264Parser::Reset() { | 116 void H264Parser::Reset() { |
117 stream_ = NULL; | 117 stream_ = NULL; |
118 bytes_left_ = 0; | 118 bytes_left_ = 0; |
119 } | 119 } |
120 | 120 |
121 void H264Parser::SetStream(const uint8* stream, off_t stream_size) { | 121 void H264Parser::SetStream(const uint8* stream, off_t stream_size) { |
122 DCHECK(stream); | 122 DCHECK(stream); |
123 DCHECK(stream_size > 0); | 123 DCHECK_GT(stream_size, 0); |
124 | 124 |
125 stream_ = stream; | 125 stream_ = stream; |
126 bytes_left_ = stream_size; | 126 bytes_left_ = stream_size; |
127 } | 127 } |
128 | 128 |
129 const H264PPS* H264Parser::GetPPS(int pps_id) { | 129 const H264PPS* H264Parser::GetPPS(int pps_id) { |
130 return active_PPSes_[pps_id]; | 130 return active_PPSes_[pps_id]; |
131 } | 131 } |
132 | 132 |
133 const H264SPS* H264Parser::GetSPS(int sps_id) { | 133 const H264SPS* H264Parser::GetSPS(int sps_id) { |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 stream_ += off_to_nalu_start + nalu->size; | 274 stream_ += off_to_nalu_start + nalu->size; |
275 bytes_left_ -= off_to_nalu_start + nalu->size; | 275 bytes_left_ -= off_to_nalu_start + nalu->size; |
276 | 276 |
277 // Read NALU header, skip the forbidden_zero_bit, but check for it. | 277 // Read NALU header, skip the forbidden_zero_bit, but check for it. |
278 READ_BITS_OR_RETURN(1, &data); | 278 READ_BITS_OR_RETURN(1, &data); |
279 TRUE_OR_RETURN(data == 0); | 279 TRUE_OR_RETURN(data == 0); |
280 | 280 |
281 READ_BITS_OR_RETURN(2, &nalu->nal_ref_idc); | 281 READ_BITS_OR_RETURN(2, &nalu->nal_ref_idc); |
282 READ_BITS_OR_RETURN(5, &nalu->nal_unit_type); | 282 READ_BITS_OR_RETURN(5, &nalu->nal_unit_type); |
283 | 283 |
284 DVLOG(4) << "NALU type: " << (int)nalu->nal_unit_type | 284 DVLOG(4) << "NALU type: " << static_cast<int>(nalu->nal_unit_type) |
285 << " at: " << (void*)nalu->data << " size: " << nalu->size | 285 << " at: " << reinterpret_cast<const void*>(nalu->data) |
286 << " ref: " << (int)nalu->nal_ref_idc; | 286 << " size: " << nalu->size |
| 287 << " ref: " << static_cast<int>(nalu->nal_ref_idc); |
287 | 288 |
288 return kOk; | 289 return kOk; |
289 } | 290 } |
290 | 291 |
291 // Default scaling lists (per spec). | 292 // Default scaling lists (per spec). |
292 static const int kDefault4x4Intra[kH264ScalingList4x4Length] = { | 293 static const int kDefault4x4Intra[kH264ScalingList4x4Length] = { |
293 6, 13, 13, 20, 20, 20, 28, 28, 28, 28, 32, 32, 32, 37, 37, 42, }; | 294 6, 13, 13, 20, 20, 20, 28, 28, 28, 28, 32, 32, 32, 37, 37, 42, }; |
294 | 295 |
295 static const int kDefault4x4Inter[kH264ScalingList4x4Length] = { | 296 static const int kDefault4x4Inter[kH264ScalingList4x4Length] = { |
296 10, 14, 14, 20, 20, 20, 24, 24, 24, 24, 27, 27, 27, 30, 30, 34, }; | 297 10, 14, 14, 20, 20, 20, 24, 24, 24, 24, 27, 27, 27, 30, 30, 34, }; |
297 | 298 |
298 static const int kDefault8x8Intra[kH264ScalingList8x8Length] = { | 299 static const int kDefault8x8Intra[kH264ScalingList8x8Length] = { |
299 6, 10, 10, 13, 11, 13, 16, 16, 16, 16, 18, 18, 18, 18, 18, 23, | 300 6, 10, 10, 13, 11, 13, 16, 16, 16, 16, 18, 18, 18, 18, 18, 23, |
300 23, 23, 23, 23, 23, 25, 25, 25, 25, 25, 25, 25, 27, 27, 27, 27, | 301 23, 23, 23, 23, 23, 25, 25, 25, 25, 25, 25, 25, 27, 27, 27, 27, |
301 27, 27, 27, 27, 29, 29, 29, 29, 29, 29, 29, 31, 31, 31, 31, 31, | 302 27, 27, 27, 27, 29, 29, 29, 29, 29, 29, 29, 31, 31, 31, 31, 31, |
302 31, 33, 33, 33, 33, 33, 36, 36, 36, 36, 38, 38, 38, 40, 40, 42, }; | 303 31, 33, 33, 33, 33, 33, 36, 36, 36, 36, 38, 38, 38, 40, 40, 42, }; |
303 | 304 |
304 static const int kDefault8x8Inter[kH264ScalingList8x8Length] = { | 305 static const int kDefault8x8Inter[kH264ScalingList8x8Length] = { |
305 9, 13, 13, 15, 13, 15, 17, 17, 17, 17, 19, 19, 19, 19, 19, 21, | 306 9, 13, 13, 15, 13, 15, 17, 17, 17, 17, 19, 19, 19, 19, 19, 21, |
306 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 24, 24, 24, 24, | 307 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 24, 24, 24, 24, |
307 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 27, 27, 27, 27, 27, | 308 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 27, 27, 27, 27, 27, |
308 27, 28, 28, 28, 28, 28, 30, 30, 30, 30, 32, 32, 32, 33, 33, 35, }; | 309 27, 28, 28, 28, 28, 28, 30, 30, 30, 30, 32, 32, 32, 33, 33, 35, }; |
309 | 310 |
310 static inline void DefaultScalingList4x4( | 311 static inline void DefaultScalingList4x4( |
311 int i, | 312 int i, |
312 int scaling_list4x4[][kH264ScalingList4x4Length]) { | 313 int scaling_list4x4[][kH264ScalingList4x4Length]) { |
313 DCHECK(i < 6); | 314 DCHECK_LT(i, 6); |
314 | 315 |
315 if (i < 3) | 316 if (i < 3) |
316 memcpy(scaling_list4x4[i], kDefault4x4Intra, sizeof(kDefault4x4Intra)); | 317 memcpy(scaling_list4x4[i], kDefault4x4Intra, sizeof(kDefault4x4Intra)); |
317 else if (i < 6) | 318 else if (i < 6) |
318 memcpy(scaling_list4x4[i], kDefault4x4Inter, sizeof(kDefault4x4Inter)); | 319 memcpy(scaling_list4x4[i], kDefault4x4Inter, sizeof(kDefault4x4Inter)); |
319 } | 320 } |
320 | 321 |
321 static inline void DefaultScalingList8x8( | 322 static inline void DefaultScalingList8x8( |
322 int i, | 323 int i, |
323 int scaling_list8x8[][kH264ScalingList8x8Length]) { | 324 int scaling_list8x8[][kH264ScalingList8x8Length]) { |
324 DCHECK(i < 6); | 325 DCHECK_LT(i, 6); |
325 | 326 |
326 if (i % 2 == 0) | 327 if (i % 2 == 0) |
327 memcpy(scaling_list8x8[i], kDefault8x8Intra, sizeof(kDefault8x8Intra)); | 328 memcpy(scaling_list8x8[i], kDefault8x8Intra, sizeof(kDefault8x8Intra)); |
328 else | 329 else |
329 memcpy(scaling_list8x8[i], kDefault8x8Inter, sizeof(kDefault8x8Inter)); | 330 memcpy(scaling_list8x8[i], kDefault8x8Inter, sizeof(kDefault8x8Inter)); |
330 } | 331 } |
331 | 332 |
332 static void FallbackScalingList4x4( | 333 static void FallbackScalingList4x4( |
333 int i, | 334 int i, |
334 const int default_scaling_list_intra[], | 335 const int default_scaling_list_intra[], |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 } | 558 } |
558 | 559 |
559 static void FillDefaultSeqScalingLists(H264SPS* sps) { | 560 static void FillDefaultSeqScalingLists(H264SPS* sps) { |
560 for (int i = 0; i < 6; ++i) | 561 for (int i = 0; i < 6; ++i) |
561 for (int j = 0; j < kH264ScalingList4x4Length; ++j) | 562 for (int j = 0; j < kH264ScalingList4x4Length; ++j) |
562 sps->scaling_list4x4[i][j] = 16; | 563 sps->scaling_list4x4[i][j] = 16; |
563 | 564 |
564 for (int i = 0; i < 6; ++i) | 565 for (int i = 0; i < 6; ++i) |
565 for (int j = 0; j < kH264ScalingList8x8Length; ++j) | 566 for (int j = 0; j < kH264ScalingList8x8Length; ++j) |
566 sps->scaling_list8x8[i][j] = 16; | 567 sps->scaling_list8x8[i][j] = 16; |
567 | |
568 } | 568 } |
569 | 569 |
570 H264Parser::Result H264Parser::ParseSPS(int* sps_id) { | 570 H264Parser::Result H264Parser::ParseSPS(int* sps_id) { |
571 // See 7.4.2.1. | 571 // See 7.4.2.1. |
572 int data; | 572 int data; |
573 Result res; | 573 Result res; |
574 | 574 |
575 *sps_id = -1; | 575 *sps_id = -1; |
576 | 576 |
577 scoped_ptr<H264SPS> sps(new H264SPS()); | 577 scoped_ptr<H264SPS> sps(new H264SPS()); |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
944 | 944 |
945 H264Parser::Result H264Parser::ParseSliceHeader(const H264NALU& nalu, | 945 H264Parser::Result H264Parser::ParseSliceHeader(const H264NALU& nalu, |
946 H264SliceHeader* shdr) { | 946 H264SliceHeader* shdr) { |
947 // See 7.4.3. | 947 // See 7.4.3. |
948 const H264SPS* sps; | 948 const H264SPS* sps; |
949 const H264PPS* pps; | 949 const H264PPS* pps; |
950 Result res; | 950 Result res; |
951 | 951 |
952 memset(shdr, 0, sizeof(*shdr)); | 952 memset(shdr, 0, sizeof(*shdr)); |
953 | 953 |
954 shdr->idr_pic_flag = ((nalu.nal_unit_type == 5) ? true : false); | 954 shdr->idr_pic_flag = (nalu.nal_unit_type == 5); |
955 shdr->nal_ref_idc = nalu.nal_ref_idc; | 955 shdr->nal_ref_idc = nalu.nal_ref_idc; |
956 shdr->nalu_data = nalu.data; | 956 shdr->nalu_data = nalu.data; |
957 shdr->nalu_size = nalu.size; | 957 shdr->nalu_size = nalu.size; |
958 | 958 |
959 READ_UE_OR_RETURN(&shdr->first_mb_in_slice); | 959 READ_UE_OR_RETURN(&shdr->first_mb_in_slice); |
960 READ_UE_OR_RETURN(&shdr->slice_type); | 960 READ_UE_OR_RETURN(&shdr->slice_type); |
961 TRUE_OR_RETURN(shdr->slice_type < 10); | 961 TRUE_OR_RETURN(shdr->slice_type < 10); |
962 | 962 |
963 READ_UE_OR_RETURN(&shdr->pic_parameter_set_id); | 963 READ_UE_OR_RETURN(&shdr->pic_parameter_set_id); |
964 | 964 |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1123 | 1123 |
1124 default: | 1124 default: |
1125 DVLOG(4) << "Unsupported SEI message"; | 1125 DVLOG(4) << "Unsupported SEI message"; |
1126 break; | 1126 break; |
1127 } | 1127 } |
1128 | 1128 |
1129 return kOk; | 1129 return kOk; |
1130 } | 1130 } |
1131 | 1131 |
1132 } // namespace content | 1132 } // namespace content |
OLD | NEW |