tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

h265_common.cc (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 #include "common_video/h265/h265_common.h"
     12 
     13 #include <cstdint>
     14 #include <vector>
     15 
     16 #include "api/array_view.h"
     17 #include "common_video/h264/h264_common.h"
     18 #include "common_video/h265/h265_inline.h"
     19 #include "rtc_base/buffer.h"
     20 
     21 namespace webrtc {
     22 namespace H265 {
     23 
     24 constexpr uint8_t kNaluTypeMask = 0x7E;
     25 
     26 std::vector<NaluIndex> FindNaluIndices(ArrayView<const uint8_t> buffer) {
     27  std::vector<H264::NaluIndex> indices = H264::FindNaluIndices(buffer);
     28  std::vector<NaluIndex> results;
     29  results.reserve(indices.size());
     30  for (auto& index : indices) {
     31    results.push_back(
     32        {index.start_offset, index.payload_start_offset, index.payload_size});
     33  }
     34  return results;
     35 }
     36 
     37 NaluType ParseNaluType(uint8_t data) {
     38  return static_cast<NaluType>((data & kNaluTypeMask) >> 1);
     39 }
     40 
     41 std::vector<uint8_t> ParseRbsp(ArrayView<const uint8_t> data) {
     42  return H264::ParseRbsp(data);
     43 }
     44 
     45 void WriteRbsp(ArrayView<const uint8_t> bytes, Buffer* destination) {
     46  H264::WriteRbsp(bytes, destination);
     47 }
     48 
     49 uint32_t Log2Ceiling(uint32_t value) {
     50  // When n == 0, we want the function to return -1.
     51  // When n == 0, (n - 1) will underflow to 0xFFFFFFFF, which is
     52  // why the statement below starts with (n ? 32 : -1).
     53  return (value ? 32 : -1) - WebRtcVideo_CountLeadingZeros32(value - 1);
     54 }
     55 
     56 }  // namespace H265
     57 }  // namespace webrtc