summaryrefslogtreecommitdiff
path: root/audio_codec/libflac/flac.h (plain)
blob: 115c06ea881eee37f0aaf41851849cdd214a3252
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/**
23 * @file libavcodec/flac.h
24 * FLAC (Free Lossless Audio Codec) decoder/demuxer common functions
25 */
26
27#ifndef AVCODEC_FLAC_H
28#define AVCODEC_FLAC_H
29
30#include "avcodec.h"
31
32#define FLAC_STREAMINFO_SIZE 34
33#define FLAC_MAX_CHANNELS 8
34#define FLAC_MIN_BLOCKSIZE 16
35#define FLAC_MAX_BLOCKSIZE 65535
36#define FLAC_MIN_FRAME_SIZE 11
37
38enum {
39 FLAC_CHMODE_INDEPENDENT = 0,
40 FLAC_CHMODE_LEFT_SIDE = 8,
41 FLAC_CHMODE_RIGHT_SIDE = 9,
42 FLAC_CHMODE_MID_SIDE = 10,
43};
44
45enum {
46 FLAC_METADATA_TYPE_STREAMINFO = 0,
47 FLAC_METADATA_TYPE_PADDING,
48 FLAC_METADATA_TYPE_APPLICATION,
49 FLAC_METADATA_TYPE_SEEKTABLE,
50 FLAC_METADATA_TYPE_VORBIS_COMMENT,
51 FLAC_METADATA_TYPE_CUESHEET,
52 FLAC_METADATA_TYPE_PICTURE,
53 FLAC_METADATA_TYPE_INVALID = 127
54};
55
56enum FLACExtradataFormat {
57 FLAC_EXTRADATA_FORMAT_STREAMINFO = 0,
58 FLAC_EXTRADATA_FORMAT_FULL_HEADER = 1
59};
60
61#define FLACCOMMONINFO \
62 int samplerate; /**< sample rate */\
63 int channels; /**< number of channels */\
64 int bps; /**< bits-per-sample */\
65
66/**
67 * Data needed from the Streaminfo header for use by the raw FLAC demuxer
68 * and/or the FLAC decoder.
69 */
70#define FLACSTREAMINFO \
71 FLACCOMMONINFO \
72 int max_blocksize; /**< maximum block size, in samples */\
73 int max_framesize; /**< maximum frame size, in bytes */\
74 int64_t samples; /**< total number of samples */\
75
76typedef struct FLACStreaminfo {
77 FLACSTREAMINFO
78} FLACStreaminfo;
79
80typedef struct FLACFrameInfo {
81 FLACCOMMONINFO
82 int blocksize; /**< block size of the frame */
83 int ch_mode; /**< channel decorrelation mode */
84} FLACFrameInfo;
85
86/**
87 * Parse the Streaminfo metadata block
88 * @param[out] avctx codec context to set basic stream parameters
89 * @param[out] s where parsed information is stored
90 * @param[in] buffer pointer to start of 34-byte streaminfo data
91 */
92void ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s,
93 const uint8_t *buffer);
94
95/**
96 * Validate the FLAC extradata.
97 * @param[in] avctx codec context containing the extradata.
98 * @param[out] format extradata format.
99 * @param[out] streaminfo_start pointer to start of 34-byte STREAMINFO data.
100 * @return 1 if valid, 0 if not valid.
101 */
102int ff_flac_is_extradata_valid(AVCodecContext *avctx,
103 enum FLACExtradataFormat *format,
104 uint8_t **streaminfo_start);
105
106/**
107 * Parse the metadata block parameters from the header.
108 * @param[in] block_header header data, at least 4 bytes
109 * @param[out] last indicator for last metadata block
110 * @param[out] type metadata block type
111 * @param[out] size metadata block size
112 */
113void ff_flac_parse_block_header(const uint8_t *block_header,
114 int *last, int *type, int *size);
115
116/**
117 * Calculate an estimate for the maximum frame size based on verbatim mode.
118 * @param blocksize block size, in samples
119 * @param ch number of channels
120 * @param bps bits-per-sample
121 */
122int ff_flac_get_max_frame_size(int blocksize, int ch, int bps);
123
124#endif /* AVCODEC_FLAC_H */
125