00001 /* (C) Copyright 2001 by Felix Opatz <felix@zotteljedi.de> 00002 * 00003 * Copyright (c) 2003 00004 * Felix Opatz <felix@zotteljedi.de>. All rights reserved. 00005 * 00006 * Copyright (c) 2007 00007 * Philip Busch <philip@0xe3.com>. All rights reserved. 00008 * 00009 * Redistribution and use in source and binary forms, with or without 00010 * modification, are permitted provided that the following conditions 00011 * are met: 00012 * 1. Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer as 00014 * the first lines of this file unmodified. 00015 * 2. Redistributions in binary form must reproduce the above copyright 00016 * notice, this list of conditions and the following disclaimer in the 00017 * documentation and/or other materials provided with the distribution. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00020 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00021 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00022 * IN NO EVENT SHALL FELIX OPATZ BE LIABLE FOR ANY DIRECT, INDIRECT, 00023 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00024 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00025 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00026 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00028 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 */ 00030 00031 #ifndef _MPEG_H 00032 #define _MPEG_H 00033 00034 00035 #define MPEG_VERSION_1 3 00036 #define MPEG_VERSION_2 2 00037 #define MPEG_VERSION_2_5 0 00038 00039 #define LAYER_VERSION_1 3 00040 #define LAYER_VERSION_2 2 00041 #define LAYER_VERSION_3 1 00042 00043 #define CMODE_STEREO 0 00044 #define CMODE_JOINT_STEREO 1 00045 #define CMODE_DUAL_CHANNEL 2 00046 #define CMODE_SINGLE_CHANNEL 3 00047 00048 /* number of samples per frame */ 00049 #define FRAME_SIZE_LAYER_1 384 00050 #define FRAME_SIZE_LAYER_2 1152 00051 #define FRAME_SIZE_LAYER_3 1152 00052 00053 #define MASK_SYNC 0xFFE00000 00054 #define SHIFT_SYNC 21 00055 00056 #define MASK_MPEG 0x180000 00057 #define SHIFT_MPEG 19 00058 00059 #define MASK_LAYER 0x60000 00060 #define SHIFT_LAYER 17 00061 00062 #define MASK_PROT 0x10000 00063 #define SHIFT_PROT 16 00064 00065 #define MASK_BITRATE 0xF000 00066 #define SHIFT_BITRATE 12 00067 00068 #define MASK_FREQ 0xC00 00069 #define SHIFT_FREQ 10 00070 00071 #define MASK_PADDING 0x200 00072 #define SHIFT_PADDING 9 00073 00074 #define MASK_PRIV 0x100 00075 #define SHIFT_PRIV 8 00076 00077 #define MASK_CHAN 0xC0 00078 #define SHIFT_CHAN 6 00079 00080 #define MASK_MODE_EXT 0x30 00081 #define SHIFT_MODE_EXT 4 00082 00083 #define MASK_COPYRIGHT 0x8 00084 #define SHIFT_COPYRIGHT 3 00085 00086 #define MASK_ORIG 0x4 00087 #define SHIFT_ORIG 2 00088 00089 #define MASK_EMPHASIS 0x3 00090 #define SHIFT_EMPHASIS 0 00091 00092 struct mpeg { 00093 int mpeg_version; 00094 int layer_desc; 00095 int bitrate; 00096 int freq; 00097 int chan; 00098 int mode_ext; 00099 int emphasis; 00100 int bit_padding; 00101 int bit_priv; 00102 int bit_copyright; 00103 int bit_orig; 00104 int bit_prot; 00105 }; 00106 00107 int mpeg_read(const char *_path, struct mpeg *_mpeg); 00108 unsigned long int mpeg_seek_next_header(FILE *_fp); 00109 int mpeg_extract_info(unsigned long int _header, struct mpeg *_mpeg); 00110 size_t mpeg_frame_length(struct mpeg *_mpeg); 00111 size_t mpeg_frame_bytes(struct mpeg *_mpeg); 00112 void mpeg_print(struct mpeg *_mpeg); 00113 00114 #endif /* ! _MPEG_H */