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.

124 lines
4.1KB

  1. /*
  2. * FLAC (Free Lossless Audio Codec) decoder/demuxer common functions
  3. * Copyright (c) 2008 Justin Ruggles
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg 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. * FFmpeg 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 FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file libavcodec/flac.h
  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. #define FLAC_STREAMINFO_SIZE 34
  29. #define FLAC_MAX_CHANNELS 8
  30. #define FLAC_MIN_BLOCKSIZE 16
  31. #define FLAC_MAX_BLOCKSIZE 65535
  32. enum {
  33. FLAC_CHMODE_INDEPENDENT = 0,
  34. FLAC_CHMODE_LEFT_SIDE = 8,
  35. FLAC_CHMODE_RIGHT_SIDE = 9,
  36. FLAC_CHMODE_MID_SIDE = 10,
  37. };
  38. enum {
  39. FLAC_METADATA_TYPE_STREAMINFO = 0,
  40. FLAC_METADATA_TYPE_PADDING,
  41. FLAC_METADATA_TYPE_APPLICATION,
  42. FLAC_METADATA_TYPE_SEEKTABLE,
  43. FLAC_METADATA_TYPE_VORBIS_COMMENT,
  44. FLAC_METADATA_TYPE_CUESHEET,
  45. FLAC_METADATA_TYPE_PICTURE,
  46. FLAC_METADATA_TYPE_INVALID = 127
  47. };
  48. enum FLACExtradataFormat {
  49. FLAC_EXTRADATA_FORMAT_STREAMINFO = 0,
  50. FLAC_EXTRADATA_FORMAT_FULL_HEADER = 1
  51. };
  52. #define FLACCOMMONINFO \
  53. int samplerate; /**< sample rate */\
  54. int channels; /**< number of channels */\
  55. int bps; /**< bits-per-sample */\
  56. /**
  57. * Data needed from the Streaminfo header for use by the raw FLAC demuxer
  58. * and/or the FLAC decoder.
  59. */
  60. #define FLACSTREAMINFO \
  61. FLACCOMMONINFO \
  62. int max_blocksize; /**< maximum block size, in samples */\
  63. int max_framesize; /**< maximum frame size, in bytes */\
  64. int64_t samples; /**< total number of samples */\
  65. typedef struct FLACStreaminfo {
  66. FLACSTREAMINFO
  67. } FLACStreaminfo;
  68. typedef struct FLACFrameInfo {
  69. FLACCOMMONINFO
  70. int blocksize; /**< block size of the frame */
  71. int ch_mode; /**< channel decorrelation mode */
  72. } FLACFrameInfo;
  73. /**
  74. * Parse the Streaminfo metadata block
  75. * @param[out] avctx codec context to set basic stream parameters
  76. * @param[out] s where parsed information is stored
  77. * @param[in] buffer pointer to start of 34-byte streaminfo data
  78. */
  79. void ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s,
  80. const uint8_t *buffer);
  81. /**
  82. * Validate the FLAC extradata.
  83. * @param[in] avctx codec context containing the extradata.
  84. * @param[out] format extradata format.
  85. * @param[out] streaminfo_start pointer to start of 34-byte STREAMINFO data.
  86. * @return 1 if valid, 0 if not valid.
  87. */
  88. int ff_flac_is_extradata_valid(AVCodecContext *avctx,
  89. enum FLACExtradataFormat *format,
  90. uint8_t **streaminfo_start);
  91. /**
  92. * Parse the metadata block parameters from the header.
  93. * @param[in] block_header header data, at least 4 bytes
  94. * @param[out] last indicator for last metadata block
  95. * @param[out] type metadata block type
  96. * @param[out] size metadata block size
  97. */
  98. void ff_flac_parse_block_header(const uint8_t *block_header,
  99. int *last, int *type, int *size);
  100. /**
  101. * Calculate an estimate for the maximum frame size based on verbatim mode.
  102. * @param blocksize block size, in samples
  103. * @param ch number of channels
  104. * @param bps bits-per-sample
  105. */
  106. int ff_flac_get_max_frame_size(int blocksize, int ch, int bps);
  107. #endif /* AVCODEC_FLAC_H */