cbs_internal.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #ifndef AVCODEC_CBS_INTERNAL_H
  19. #define AVCODEC_CBS_INTERNAL_H
  20. #include "avcodec.h"
  21. #include "cbs.h"
  22. #include "get_bits.h"
  23. #include "put_bits.h"
  24. typedef struct CodedBitstreamType {
  25. enum AVCodecID codec_id;
  26. size_t priv_data_size;
  27. // Split frag->data into coded bitstream units, creating the
  28. // frag->units array. Fill data but not content on each unit.
  29. // The header argument should be set if the fragment came from
  30. // a header block, which may require different parsing for some
  31. // codecs (e.g. the AVCC header in H.264).
  32. int (*split_fragment)(CodedBitstreamContext *ctx,
  33. CodedBitstreamFragment *frag,
  34. int header);
  35. // Read the unit->data bitstream and decompose it, creating
  36. // unit->content.
  37. int (*read_unit)(CodedBitstreamContext *ctx,
  38. CodedBitstreamUnit *unit);
  39. // Write the data bitstream from unit->content into pbc.
  40. // Return value AVERROR(ENOSPC) indicates that pbc was too small.
  41. int (*write_unit)(CodedBitstreamContext *ctx,
  42. CodedBitstreamUnit *unit,
  43. PutBitContext *pbc);
  44. // Read the data from all of frag->units and assemble it into
  45. // a bitstream for the whole fragment.
  46. int (*assemble_fragment)(CodedBitstreamContext *ctx,
  47. CodedBitstreamFragment *frag);
  48. // Free the codec internal state.
  49. void (*close)(CodedBitstreamContext *ctx);
  50. } CodedBitstreamType;
  51. // Helper functions for trace output.
  52. void ff_cbs_trace_header(CodedBitstreamContext *ctx,
  53. const char *name);
  54. void ff_cbs_trace_syntax_element(CodedBitstreamContext *ctx, int position,
  55. const char *name, const int *subscripts,
  56. const char *bitstring, int64_t value);
  57. // Helper functions for read/write of common bitstream elements, including
  58. // generation of trace output.
  59. int ff_cbs_read_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc,
  60. int width, const char *name,
  61. const int *subscripts, uint32_t *write_to,
  62. uint32_t range_min, uint32_t range_max);
  63. int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc,
  64. int width, const char *name,
  65. const int *subscripts, uint32_t value,
  66. uint32_t range_min, uint32_t range_max);
  67. int ff_cbs_read_signed(CodedBitstreamContext *ctx, GetBitContext *gbc,
  68. int width, const char *name,
  69. const int *subscripts, int32_t *write_to,
  70. int32_t range_min, int32_t range_max);
  71. int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc,
  72. int width, const char *name,
  73. const int *subscripts, int32_t value,
  74. int32_t range_min, int32_t range_max);
  75. // The largest unsigned value representable in N bits, suitable for use as
  76. // range_max in the above functions.
  77. #define MAX_UINT_BITS(length) ((UINT64_C(1) << (length)) - 1)
  78. // The largest signed value representable in N bits, suitable for use as
  79. // range_max in the above functions.
  80. #define MAX_INT_BITS(length) ((INT64_C(1) << ((length) - 1)) - 1)
  81. // The smallest signed value representable in N bits, suitable for use as
  82. // range_min in the above functions.
  83. #define MIN_INT_BITS(length) (-(INT64_C(1) << ((length) - 1)))
  84. extern const CodedBitstreamType ff_cbs_type_av1;
  85. extern const CodedBitstreamType ff_cbs_type_h264;
  86. extern const CodedBitstreamType ff_cbs_type_h265;
  87. extern const CodedBitstreamType ff_cbs_type_jpeg;
  88. extern const CodedBitstreamType ff_cbs_type_mpeg2;
  89. extern const CodedBitstreamType ff_cbs_type_vp9;
  90. #endif /* AVCODEC_CBS_INTERNAL_H */