h265_inline.h (1739B)
1 /* 2 * Copyright (c) 2023 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 // This header file includes the inline functions in H265 parser. 12 13 #ifndef COMMON_VIDEO_H265_H265_INLINE_H_ 14 #define COMMON_VIDEO_H265_H265_INLINE_H_ 15 16 #include <stdint.h> 17 18 #include "rtc_base/compile_assert_c.h" 19 20 extern const int8_t kWebRtcVideo_CountLeadingZeros32_Table[64]; 21 22 static __inline int WebRtcVideo_CountLeadingZeros32_NotBuiltin(uint32_t n) { 23 // Normalize n by rounding up to the nearest number that is a sequence of 0 24 // bits followed by a sequence of 1 bits. This number has the same number of 25 // leading zeros as the original n. There are exactly 33 such values. 26 n |= n >> 1; 27 n |= n >> 2; 28 n |= n >> 4; 29 n |= n >> 8; 30 n |= n >> 16; 31 32 // Multiply the modified n with a constant selected (by exhaustive search) 33 // such that each of the 33 possible values of n give a product whose 6 most 34 // significant bits are unique. Then look up the answer in the table. 35 return kWebRtcVideo_CountLeadingZeros32_Table[(n * 0x8c0b2891) >> 26]; 36 } 37 38 // Returns the number of leading zero bits in the argument. 39 static __inline int WebRtcVideo_CountLeadingZeros32(uint32_t n) { 40 #ifdef __GNUC__ 41 RTC_COMPILE_ASSERT(sizeof(unsigned int) == sizeof(uint32_t)); 42 return n == 0 ? 32 : __builtin_clz(n); 43 #else 44 return WebRtcVideo_CountLeadingZeros32_NotBuiltin(n); 45 #endif 46 } 47 #endif // COMMON_VIDEO_H265_H265_INLINE_H_