FFmpeg
Loading...
Searching...
No Matches
mpegaudiodecheader.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19/**
20 * Walks the MPEG audio frames of a file, checks that every frame header
21 * encodes back to its original bits, and prints each distinct header.
22 */
23
24#include <inttypes.h>
25#include <stdint.h>
26#include <stdio.h>
27#include <string.h>
28
29#include "libavutil/file.h"
30#include "libavutil/mem.h"
32
34
35#define PADDING_BIT (1U << 9)
36
37static size_t id3v2_size(const uint8_t *buf, size_t size)
38{
39 if (size < 10 || memcmp(buf, "ID3", 3))
40 return 0;
41
42 return 10 + (buf[5] & 0x10 ? 10 : 0) +
43 ((buf[6] & 0x7f) << 21 | (buf[7] & 0x7f) << 14 |
44 (buf[8] & 0x7f) << 7 | (buf[9] & 0x7f));
45}
46
47static void print_header(size_t offset, unsigned frames, uint32_t bits,
49{
50 printf("offset=%zu frames=%u header=%08"PRIX32" layer=%d sample_rate=%d "
51 "bit_rate=%d crc=%d mode=%d mode_ext=%d copyright=%d original=%d "
52 "emphasis=%d private_bit=%d\n",
53 offset, frames, bits, header->layer, header->sample_rate,
54 header->bit_rate, header->error_protection, header->mode,
55 header->mode_ext, header->copyright, header->original,
56 header->emphasis, header->private_bit);
57}
58
59int main(int argc, char *argv[])
60{
61 MPADecodeHeader2 run_header, *