You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
5.0KB

  1. /*
  2. * FLAC (Free Lossless Audio Codec) decoder/demuxer common functions
  3. * Copyright (c) 2008 Justin Ruggles
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * Libav is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with Libav; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * FLAC (Free Lossless Audio Codec) decoder/demuxer common functions
  24. */
  25. #ifndef AVCODEC_FLAC_H
  26. #define AVCODEC_FLAC_H
  27. #include "avcodec.h"
  28. #include "get_bits.h"
  29. #define FLAC_STREAMINFO_SIZE 34
  30. #define FLAC_MAX_CHANNELS 8
  31. #define FLAC_MIN_BLOCKSIZE 16
  32. #define FLAC_MAX_BLOCKSIZE 65535
  33. #define FLAC_MIN_FRAME_SIZE 11
  34. enum {
  35. FLAC_CHMODE_INDEPENDENT = 0,
  36. FLAC_CHMODE_LEFT_SIDE = 1,
  37. FLAC_CHMODE_RIGHT_SIDE = 2,
  38. FLAC_CHMODE_MID_SIDE = 3,
  39. };
  40. enum {
  41. FLAC_METADATA_TYPE_STREAMINFO = 0,
  42. FLAC_METADATA_TYPE_PADDING,
  43. FLAC_METADATA_TYPE_APPLICATION,
  44. FLAC_METADATA_TYPE_SEEKTABLE,
  45. FLAC_METADATA_TYPE_VORBIS_COMMENT,
  46. FLAC_METADATA_TYPE_CUESHEET,
  47. FLAC_METADATA_TYPE_PICTURE,
  48. FLAC_METADATA_TYPE_INVALID = 127
  49. };
  50. enum FLACExtradataFormat {
  51. FLAC_EXTRADATA_FORMAT_STREAMINFO = 0,
  52. FLAC_EXTRADATA_FORMAT_FULL_HEADER = 1
  53. };
  54. #define FLACCOMMONINFO \
  55. int samplerate; /**< sample rate */\
  56. int channels; /**< number of channels */\
  57. int bps; /**< bits-per-sample */\
  58. /**
  59. * Data needed from the Streaminfo header for use by the raw FLAC demuxer
  60. * and/or the FLAC decoder.
  61. */
  62. #define FLACSTREAMINFO \
  63. FLACCOMMONINFO \
  64. int max_blocksize; /**< maximum block size, in samples */\
  65. int max_framesize; /**< maximum frame size, in bytes */\
  66. int64_t samples; /**< total number of samples */\
  67. typedef struct FLACStreaminfo {
  68. FLACSTREAMINFO
  69. } FLACStreaminfo;
  70. typedef struct FLACFrameInfo {
  71. FLACCOMMONINFO
  72. int blocksize; /**< block size of the frame */
  73. int ch_mode; /**< channel decorrelation mode */
  74. int64_t frame_or_sample_num; /**< frame number or sample number */
  75. int is_var_size; /**< specifies if the stream uses variable
  76. block sizes or a fixed block size;
  77. also determines the meaning of
  78. frame_or_sample_num */
  79. } FLACFrameInfo;
  80. /**
  81. * Parse the Streaminfo metadata block
  82. * @param[out] avctx codec context to set basic stream parameters
  83. * @param[out] s where parsed information is stored
  84. * @param[in] buffer pointer to start of 34-byte streaminfo data
  85. */
  86. void avpriv_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s,
  87. const uint8_t *buffer);
  88. /**
  89. * Validate the FLAC extradata.
  90. * @param[in] avctx codec context containing the extradata.
  91. * @param[out] format extradata format.
  92. * @param[out] streaminfo_start pointer to start of 34-byte STREAMINFO data.
  93. * @return 1 if valid, 0 if not valid.
  94. */
  95. int avpriv_flac_is_extradata_valid(AVCodecContext *avctx,
  96. enum FLACExtradataFormat *format,
  97. uint8_t **streaminfo_start);
  98. /**
  99. * Parse the metadata block parameters from the header.
  100. * @param[in] block_header header data, at least 4 bytes
  101. * @param[out] last indicator for last metadata block
  102. * @param[out] type metadata block type
  103. * @param[out] size metadata block size
  104. */
  105. void avpriv_flac_parse_block_header(const uint8_t *block_header,
  106. int *last, int *type, int *size);
  107. /**
  108. * Calculate an estimate for the maximum frame size based on verbatim mode.
  109. * @param blocksize block size, in samples
  110. * @param ch number of channels
  111. * @param bps bits-per-sample
  112. */
  113. int ff_flac_get_max_frame_size(int blocksize, int ch, int bps);
  114. /**
  115. * Validate and decode a frame header.
  116. * @param avctx AVCodecContext to use as av_log() context
  117. * @param gb GetBitContext from which to read frame header
  118. * @param[out] fi frame information
  119. * @param log_level_offset log level offset. can be used to silence error messages.
  120. * @return non-zero on error, 0 if ok
  121. */
  122. int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,
  123. FLACFrameInfo *fi, int log_level_offset);
  124. #endif /* AVCODEC_FLAC_H */