evc_parse.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. /**
  19. * @file
  20. * EVC decoder/parser shared code
  21. */
  22. #ifndef AVCODEC_EVC_PARSE_H
  23. #define AVCODEC_EVC_PARSE_H
  24. #include <stdint.h>
  25. #include "libavutil/intreadwrite.h"
  26. #include "libavutil/log.h"
  27. #include "evc.h"
  28. #include "evc_ps.h"
  29. // The structure reflects Slice Header RBSP(raw byte sequence payload) layout
  30. // @see ISO_IEC_23094-1 section 7.3.2.6
  31. //
  32. // The following descriptors specify the parsing process of each element
  33. // u(n) - unsigned integer using n bits
  34. // ue(v) - unsigned integer 0-th order Exp_Golomb-coded syntax element with the left bit first
  35. // u(n) - unsigned integer using n bits.
  36. // When n is "v" in the syntax table, the number of bits varies in a manner dependent on the value of other syntax elements.
  37. typedef struct EVCParserSliceHeader {
  38. uint8_t slice_pic_parameter_set_id; // ue(v)
  39. uint8_t single_tile_in_slice_flag; // u(1)
  40. uint8_t first_tile_id; // u(v)
  41. uint8_t arbitrary_slice_flag; // u(1)
  42. uint8_t last_tile_id; // u(v)
  43. uint32_t num_remaining_tiles_in_slice_minus1; // ue(v)
  44. uint16_t delta_tile_id_minus1[EVC_MAX_TILE_ROWS * EVC_MAX_TILE_COLUMNS]; // ue(v)
  45. uint8_t slice_type; // ue(v)
  46. uint8_t no_output_of_prior_pics_flag; // u(1)
  47. uint8_t mmvd_group_enable_flag; // u(1)
  48. uint8_t slice_alf_enabled_flag; // u(1)
  49. uint8_t slice_alf_luma_aps_id; // u(5)
  50. uint8_t slice_alf_map_flag; // u(1)
  51. uint8_t slice_alf_chroma_idc; // u(2)
  52. uint8_t slice_alf_chroma_aps_id; // u(5)
  53. uint8_t slice_alf_chroma_map_flag; // u(1)
  54. uint8_t slice_alf_chroma2_aps_id; // u(5)
  55. uint8_t slice_alf_chroma2_map_flag; // u(1)
  56. uint16_t slice_pic_order_cnt_lsb; // u(v)
  57. // @note
  58. // Currently the structure does not reflect the entire Slice Header RBSP layout.
  59. // It contains only the fields that are necessary to read from the NAL unit all the values
  60. // necessary for the correct initialization of the AVCodecContext structure.
  61. // @note
  62. // If necessary, add the missing fields to the structure to reflect
  63. // the contents of the entire NAL unit of the SPS type
  64. } EVCParserSliceHeader;
  65. // picture order count of the current picture
  66. typedef struct EVCParserPoc {
  67. int PicOrderCntVal; // current picture order count value
  68. int prevPicOrderCntVal; // the picture order count of the previous Tid0 picture
  69. int DocOffset; // the decoding order count of the previous picture
  70. } EVCParserPoc;
  71. static inline uint32_t evc_read_nal_unit_length(const uint8_t *bits, int bits_size, void *logctx)
  72. {
  73. uint32_t nalu_len = 0;
  74. if (bits_size < EVC_NALU_LENGTH_PREFIX_SIZE) {
  75. av_log(logctx, AV_LOG_ERROR, "Can't read NAL unit length\n");
  76. return 0;
  77. }
  78. nalu_len = AV_RB32(bits);
  79. return nalu_len;
  80. }
  81. int ff_evc_parse_slice_header(GetBitContext *gb, EVCParserSliceHeader *sh,
  82. const EVCParamSets *ps, enum EVCNALUnitType nalu_type);
  83. // POC (picture order count of the current picture) derivation
  84. // @see ISO/IEC 23094-1:2020(E) 8.3.1 Decoding process for picture order count
  85. int ff_evc_derive_poc(const EVCParamSets *ps, const EVCParserSliceHeader *sh,
  86. EVCParserPoc *poc, enum EVCNALUnitType nalu_type, int tid);
  87. #endif /* AVCODEC_EVC_PARSE_H */