h265_vps_parser.cc (1564B)
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_vps_parser.h" 12 13 #include <cstdint> 14 #include <optional> 15 16 #include "api/array_view.h" 17 #include "common_video/h265/h265_common.h" 18 #include "rtc_base/bitstream_reader.h" 19 20 namespace webrtc { 21 22 H265VpsParser::VpsState::VpsState() = default; 23 24 // General note: this is based off the 08/2021 version of the H.265 standard. 25 // You can find it on this page: 26 // http://www.itu.int/rec/T-REC-H.265 27 28 // Unpack RBSP and parse VPS state from the supplied buffer. 29 std::optional<H265VpsParser::VpsState> H265VpsParser::ParseVps( 30 ArrayView<const uint8_t> data) { 31 return ParseInternal(H265::ParseRbsp(data)); 32 } 33 34 std::optional<H265VpsParser::VpsState> H265VpsParser::ParseInternal( 35 ArrayView<const uint8_t> buffer) { 36 BitstreamReader reader(buffer); 37 38 // Now, we need to use a bit buffer to parse through the actual H265 VPS 39 // format. See Section 7.3.2.1 ("Video parameter set RBSP syntax") of the 40 // H.265 standard for a complete description. 41 VpsState vps; 42 43 // vps_video_parameter_set_id: u(4) 44 vps.id = reader.ReadBits(4); 45 46 if (!reader.Ok()) { 47 return std::nullopt; 48 } 49 50 return vps; 51 } 52 53 } // namespace webrtc