flac.h
Go to the documentation of this file.
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
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 #include "get_bits.h"
32 
33 #define FLAC_STREAMINFO_SIZE 34
34 #define FLAC_MAX_CHANNELS 8
35 #define FLAC_MIN_BLOCKSIZE 16
36 #define FLAC_MAX_BLOCKSIZE 65535
37 #define FLAC_MIN_FRAME_SIZE 11
38 
39 enum {
44 };
45 
46 enum {
55 };
56 
60 };
61 
62 #define FLACCOMMONINFO \
63  int samplerate; /**< sample rate */\
64  int channels; /**< number of channels */\
65  int bps; /**< bits-per-sample */\
66 
67 /**
68  * Data needed from the Streaminfo header for use by the raw FLAC demuxer
69  * and/or the FLAC decoder.
70  */
71 #define FLACSTREAMINFO \
72  FLACCOMMONINFO \
73  int max_blocksize; /**< maximum block size, in samples */\
74  int max_framesize; /**< maximum frame size, in bytes */\
75  int64_t samples; /**< total number of samples */\
76 
77 typedef struct FLACStreaminfo {
80 
81 typedef struct FLACFrameInfo {
83  int blocksize; /**< block size of the frame */
84  int ch_mode; /**< channel decorrelation mode */
85  int64_t frame_or_sample_num; /**< frame number or sample number */
86  int is_var_size; /**< specifies if the stream uses variable
87  block sizes or a fixed block size;
88  also determines the meaning of
89  frame_or_sample_num */
91 
92 /**
93  * Parse the Streaminfo metadata block
94  * @param[out] avctx codec context to set basic stream parameters
95  * @param[out] s where parsed information is stored
96  * @param[in] buffer pointer to start of 34-byte streaminfo data
97  */
99  const uint8_t *buffer);
100 
101 /**
102  * Validate the FLAC extradata.
103  * @param[in] avctx codec context containing the extradata.
104  * @param[out] format extradata format.
105  * @param[out] streaminfo_start pointer to start of 34-byte STREAMINFO data.
106  * @return 1 if valid, 0 if not valid.
107  */
110  uint8_t **streaminfo_start);
111 
112 /**
113  * Parse the metadata block parameters from the header.
114  * @param[in] block_header header data, at least 4 bytes
115  * @param[out] last indicator for last metadata block
116  * @param[out] type metadata block type
117  * @param[out] size metadata block size
118  */
119 void avpriv_flac_parse_block_header(const uint8_t *block_header,
120  int *last, int *type, int *size);
121 
122 /**
123  * Calculate an estimate for the maximum frame size based on verbatim mode.
124  * @param blocksize block size, in samples
125  * @param ch number of channels
126  * @param bps bits-per-sample
127  */
128 int ff_flac_get_max_frame_size(int blocksize, int ch, int bps);
129 
130 /**
131  * Validate and decode a frame header.
132  * @param avctx AVCodecContext to use as av_log() context
133  * @param gb GetBitContext from which to read frame header
134  * @param[out] fi frame information
135  * @param log_level_offset log level offset. can be used to silence error messages.
136  * @return non-zero on error, 0 if ok
137  */
139  FLACFrameInfo *fi, int log_level_offset);
140 
142 
143 #endif /* AVCODEC_FLAC_H */
const char * s
Definition: avisynth_c.h:668
int size
int ff_flac_get_max_frame_size(int blocksize, int ch, int bps)
Calculate an estimate for the maximum frame size based on verbatim mode.
Definition: flac.c:148
int bps
bits-per-sample
Definition: flac.h:80
void ff_flac_set_channel_layout(AVCodecContext *avctx)
Definition: flac.c:196
void avpriv_flac_parse_block_header(const uint8_t *block_header, int *last, int *type, int *size)
Parse the metadata block parameters from the header.
Definition: flac.c:236
bitstream reader API header.
int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb, FLACFrameInfo *fi, int log_level_offset)
Validate and decode a frame header.
Definition: flac.c:50
struct FLACFrameInfo FLACFrameInfo
FLACExtradataFormat
Definition: flac.h:57
AVS_FilterInfo ** fi
Definition: avisynth_c.h:635
#define FLACCOMMONINFO
bits-per-sample
Definition: flac.h:62
#define FLACSTREAMINFO
Data needed from the Streaminfo header for use by the raw FLAC demuxer and/or the FLAC decoder...
Definition: flac.h:72
external API header
void avpriv_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s, const uint8_t *buffer)
Parse the Streaminfo metadata block.
Definition: flac.c:204
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate.The lists are not just lists
int avpriv_flac_is_extradata_valid(AVCodecContext *avctx, enum FLACExtradataFormat *format, uint8_t **streaminfo_start)
Validate the FLAC extradata.
Definition: flac.c:169
struct FLACStreaminfo FLACStreaminfo
main external API structure.
#define type
the buffer and buffer reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFilterBuffer structures They must not be accessed but through references stored in AVFilterBufferRef structures Several references can point to the same buffer