FFmpeg
Loading...
Searching...
No Matches
mpegaudiodecheader.h
Go to the documentation of this file.
1/*
2 * MPEG Audio header decoder
3 * Copyright (c) 2001, 2002 Fabrice Bellard
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 * MPEG Audio header decoder.
25 */
26
27#ifndef AVCODEC_MPEGAUDIODECHEADER_H
28#define AVCODEC_MPEGAUDIODECHEADER_H
29
30#include <stdint.h>
31
33
34#include "codec_id.h"
35#include "version_major.h"
36
37#define MP3_MASK 0xFFFE0CCF
38
39#define FF_MPEGAUDIO_LEGACY_DECODE_HEADER (LIBAVCODEC_VERSION_MAJOR < 64)
40
41#if FF_MPEGAUDIO_LEGACY_DECODE_HEADER
42#define MPA_DECODE_HEADER \
43 int frame_size; \
44 int error_protection; \
45 int layer; \
46 int sample_rate; \
47 int sample_rate_index; /* between 0 and 8 */ \
48 int bit_rate; \
49 int nb_channels; \
50 int mode; \
51 int mode_ext; \
52 int lsf;
53
54typedef struct MPADecodeHeader {
55 MPA_DECODE_HEADER
56} MPADecodeHeader;
57
58/* header decoding. MUST check the header before because no
59 consistency check is done there. Return 1 if free format found and
60 that the frame size must be computed externally */
61int avpriv_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header);
62#endif
63
64/**
65 * Same as MPADecodeHeader, plus the header fields that carry no decoding
66 * information. Its size is not part of the libavcodec ABI: it is only ever
67 * allocated by avpriv_mpegaudio_decode_header2().
68 */
87
88/**
89 * Decode an MPEG audio header into *phdr, which is allocated if it is NULL.
90 *
91 * The header must have been checked beforehand, as no consistency check is
92 * done here.
93 *
94 * @return 1 if free format was found and the frame size must be computed
95 * externally, 0 on success, a negative AVERROR code on failure
96 */
98
99/* same as avpriv_mpegaudio_decode_header2(), for callers within libavcodec,
100 which are built against this very header and may allocate it themselves */
102
103/* useful helper to get MPEG audio stream info. Return -1 if error in
104 header, otherwise the coded frame size in bytes */
105int ff_mpa_decode_header(uint32_t head, int *sample_rate,
106 int *channels, int *frame_size, int *bitrate, enum AVCodecID *codec_id);
107
108/* fast header check for resync */
109static inline int ff_mpa_check_header(uint32_t header){
110 /* header */
111 if ((header & 0xffe00000) != 0xffe00000)
112 return -1;
113 /* version check */
114 if ((header & (3<<19)) == 1<<19)
115 return -1;
116 /* layer check */
117 if ((header & (3<<17)) == 0)
118 return -1;
119 /* bit rate */
120 if ((header & (0xf<<12)) == 0xf<<12)
121 return -1;
122 /* frequency */
123 if ((header & (3<<10)) == 3<<10)
124 return -1;
125 return 0;
126}
127
128static inline uint32_t ff_mpa_encode_header(const MPADecodeHeader2 *s)
129{
130 int version = s->sample_rate_index < 6 ? 3 - s->sample_rate_index / 3 : 0;
131
132 return 0xffeU << 20 |
133 version << 19 |
134 (4 - s->layer) << 17 |
135 !s->error_protection << 16 |
136 s->bitrate_index << 12 |
137 s->sample_rate_index % 3 << 10 |
138 s->padding << 9 |
139 s->private_bit << 8 |
140 s->mode << 6 |
141 s->mode_ext << 4 |
142 s->copyright << 3 |
143 s->original << 2 |
144 s->emphasis;
145}
146
147#endif /* AVCODEC_MPEGAUDIODECHEADER_H */
channels
Definition aptx.h:31
#define s(width, name)
Definition cbs_vp9.c:198
static const uint8_t frame_size[4]
Definition g723_1.h:222
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition codec_id.h:47
Libavcodec version macros.
Macro definitions for various function/variable attributes.
version
Definition libkvazaar.c:313
int ff_mpa_decode_header(uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bitrate, enum AVCodecID *codec_id)
static uint32_t ff_mpa_encode_header(const MPADecodeHeader2 *s)
int ff_mpegaudio_decode_header(MPADecodeHeader2 *s, uint32_t header)
static int ff_mpa_check_header(uint32_t header)
int avpriv_mpegaudio_decode_header2(MPADecodeHeader2 **phdr, uint32_t header)
Decode an MPEG audio header into *phdr, which is allocated if it is NULL.
static const uint8_t header[24]
Definition sdr2.c:68
Same as MPADecodeHeader, plus the header fields that carry no decoding information.
int64_t bitrate
Definition av1_levels.c:47
enum AVCodecID codec_id