pps_parser.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (c) 2016 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. #ifndef COMMON_VIDEO_H264_PPS_PARSER_H_
  11. #define COMMON_VIDEO_H264_PPS_PARSER_H_
  12. #include "absl/types/optional.h"
  13. namespace rtc {
  14. class BitBuffer;
  15. }
  16. namespace webrtc {
  17. // A class for parsing out picture parameter set (PPS) data from a H264 NALU.
  18. class PpsParser {
  19. public:
  20. // The parsed state of the PPS. Only some select values are stored.
  21. // Add more as they are actually needed.
  22. struct PpsState {
  23. PpsState() = default;
  24. bool bottom_field_pic_order_in_frame_present_flag = false;
  25. bool weighted_pred_flag = false;
  26. bool entropy_coding_mode_flag = false;
  27. uint32_t weighted_bipred_idc = false;
  28. uint32_t redundant_pic_cnt_present_flag = 0;
  29. int pic_init_qp_minus26 = 0;
  30. uint32_t id = 0;
  31. uint32_t sps_id = 0;
  32. };
  33. // Unpack RBSP and parse PPS state from the supplied buffer.
  34. static absl::optional<PpsState> ParsePps(const uint8_t* data, size_t length);
  35. static bool ParsePpsIds(const uint8_t* data,
  36. size_t length,
  37. uint32_t* pps_id,
  38. uint32_t* sps_id);
  39. static absl::optional<uint32_t> ParsePpsIdFromSlice(const uint8_t* data,
  40. size_t length);
  41. protected:
  42. // Parse the PPS state, for a bit buffer where RBSP decoding has already been
  43. // performed.
  44. static absl::optional<PpsState> ParseInternal(rtc::BitBuffer* bit_buffer);
  45. static bool ParsePpsIdsInternal(rtc::BitBuffer* bit_buffer,
  46. uint32_t* pps_id,
  47. uint32_t* sps_id);
  48. };
  49. } // namespace webrtc
  50. #endif // COMMON_VIDEO_H264_PPS_PARSER_H_