ReactOS 0.4.15-dev-7846-g8ba6c66
mpeghead.h
Go to the documentation of this file.
1/*
2 mpeghead: the bits of an MPEG frame header
3
4 copyright ?-2011 by the mpg123 project - free software under the terms of the LGPL 2.1
5 see COPYING and AUTHORS files in distribution or http://mpg123.org
6 initially written by Michael Hipp & Thomas Orgis (from parse.c)
7*/
8#ifndef MPG123_MPEGHEAD_H
9#define MPG123_MPEGHEAD_H
10
11/*
12 Avoid human error, let perl do the work of dissecting an MPEG header into parts.
13 To be clear: Never edit the following definitions by hand, modify the code block inside this comment and run it through perl instead!
14
15 $head = "AAAAAAAA AAABBCCD EEEEFFGH IIJJKLMM";
16 %parts = qw(A sync B version C layer D crc E bitrate F samplerate G padding H private I channel J chanex K copyright L original M emphasis);
17 for(sort keys %parts)
18 {
19 $name = uc($parts{$_});
20 $bits = $head;
21 $bits =~ s/$_/1/g;
22 $bits =~ s/[^1 ]/0/g;
23 print "\/\* $bits \*\/\n";
24 $bits =~ s/\s//g;
25 print "#define HDR_$name".(" " x (18-length($name))).sprintf("0x%08x", eval("0b$bits"))."\n";
26 $bits =~ m/(0*)$/;
27 print "#define HDR_${name}_VAL(h)".(" " x (11-length($name)))."(((h)\&HDR_$name) >> ".length($1).")\n";
28 }
29*/
30
31/* 11111111 11100000 00000000 00000000 */
32#define HDR_SYNC 0xffe00000
33#define HDR_SYNC_VAL(h) (((h)&HDR_SYNC) >> 21)
34/* 00000000 00011000 00000000 00000000 */
35#define HDR_VERSION 0x00180000
36#define HDR_VERSION_VAL(h) (((h)&HDR_VERSION) >> 19)
37/* 00000000 00000110 00000000 00000000 */
38#define HDR_LAYER 0x00060000
39#define HDR_LAYER_VAL(h) (((h)&HDR_LAYER) >> 17)
40/* 00000000 00000001 00000000 00000000 */
41#define HDR_CRC 0x00010000
42#define HDR_CRC_VAL(h) (((h)&HDR_CRC) >> 16)
43/* 00000000 00000000 11110000 00000000 */
44#define HDR_BITRATE 0x0000f000
45#define HDR_BITRATE_VAL(h) (((h)&HDR_BITRATE) >> 12)
46/* 00000000 00000000 00001100 00000000 */
47#define HDR_SAMPLERATE 0x00000c00
48#define HDR_SAMPLERATE_VAL(h) (((h)&HDR_SAMPLERATE) >> 10)
49/* 00000000 00000000 00000010 00000000 */
50#define HDR_PADDING 0x00000200
51#define HDR_PADDING_VAL(h) (((h)&HDR_PADDING) >> 9)
52/* 00000000 00000000 00000001 00000000 */
53#define HDR_PRIVATE 0x00000100
54#define HDR_PRIVATE_VAL(h) (((h)&HDR_PRIVATE) >> 8)
55/* 00000000 00000000 00000000 11000000 */
56#define HDR_CHANNEL 0x000000c0
57#define HDR_CHANNEL_VAL(h) (((h)&HDR_CHANNEL) >> 6)
58/* 00000000 00000000 00000000 00110000 */
59#define HDR_CHANEX 0x00000030
60#define HDR_CHANEX_VAL(h) (((h)&HDR_CHANEX) >> 4)
61/* 00000000 00000000 00000000 00001000 */
62#define HDR_COPYRIGHT 0x00000008
63#define HDR_COPYRIGHT_VAL(h) (((h)&HDR_COPYRIGHT) >> 3)
64/* 00000000 00000000 00000000 00000100 */
65#define HDR_ORIGINAL 0x00000004
66#define HDR_ORIGINAL_VAL(h) (((h)&HDR_ORIGINAL) >> 2)
67/* 00000000 00000000 00000000 00000011 */
68#define HDR_EMPHASIS 0x00000003
69#define HDR_EMPHASIS_VAL(h) (((h)&HDR_EMPHASIS) >> 0)
70
71/*
72 A generic mask for telling if a header is somewhat valid for the current stream.
73 Meaning: Most basic info is not allowed to change.
74 Checking of channel count needs to be done, too, though. So,
75 if channel count matches, frames are decoded the same way: frame buffers and decoding
76 routines can stay the same, especially frame buffers (think spf * channels!).
77*/
78#define HDR_CMPMASK (HDR_SYNC|HDR_VERSION|HDR_LAYER|HDR_SAMPLERATE)
79
80/* A stricter mask, for matching free format headers. */
81#define HDR_SAMEMASK (HDR_SYNC|HDR_VERSION|HDR_LAYER|HDR_BITRATE|HDR_SAMPLERATE|HDR_CHANNEL)
82
83/* Free format headers have zero bitrate value. */
84#define HDR_FREE_FORMAT(head) (!(head & HDR_BITRATE))
85
86/* A mask for changed sampling rate (version or rate bits). */
87#define HDR_SAMPMASK (HDR_VERSION|HDR_SAMPLERATE)
88
89#endif