qwu16 972f28335a Added HEVC parser for WebRTC
This is part of effort to enable HEVC for WebRTC. Parser added here to support parsing of QP/picture size for bitstream, for dynamic adaptation and stream metadata abstraction.

Bug: webrtc:13485
Change-Id: I2fbdf210e72e77989ca87ce285da174df5bedd5c
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/298421
Reviewed-by: Sergey Silkin <ssilkin@webrtc.org>
Reviewed-by: Philip Eliasson <philipel@webrtc.org>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Sergey Silkin <ssilkin@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#40572}
2023-08-18 17:48:11 +00:00

48 lines
1.7 KiB
C

/*
* Copyright (c) 2023 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
// This header file includes the inline functions in H265 parser.
#ifndef COMMON_VIDEO_H265_H265_INLINE_H_
#define COMMON_VIDEO_H265_H265_INLINE_H_
#include <stdint.h>
#include "rtc_base/compile_assert_c.h"
extern const int8_t kWebRtcVideo_CountLeadingZeros32_Table[64];
static __inline int WebRtcVideo_CountLeadingZeros32_NotBuiltin(uint32_t n) {
// Normalize n by rounding up to the nearest number that is a sequence of 0
// bits followed by a sequence of 1 bits. This number has the same number of
// leading zeros as the original n. There are exactly 33 such values.
n |= n >> 1;
n |= n >> 2;
n |= n >> 4;
n |= n >> 8;
n |= n >> 16;
// Multiply the modified n with a constant selected (by exhaustive search)
// such that each of the 33 possible values of n give a product whose 6 most
// significant bits are unique. Then look up the answer in the table.
return kWebRtcVideo_CountLeadingZeros32_Table[(n * 0x8c0b2891) >> 26];
}
// Returns the number of leading zero bits in the argument.
static __inline int WebRtcVideo_CountLeadingZeros32(uint32_t n) {
#ifdef __GNUC__
RTC_COMPILE_ASSERT(sizeof(unsigned int) == sizeof(uint32_t));
return n == 0 ? 32 : __builtin_clz(n);
#else
return WebRtcVideo_CountLeadingZeros32_NotBuiltin(n);
#endif
}
#endif // COMMON_VIDEO_H265_H265_INLINE_H_