00001 /* 00002 Copyright (c) 2005, The Musepack Development Team 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without 00006 modification, are permitted provided that the following conditions are 00007 met: 00008 00009 * Redistributions of source code must retain the above copyright 00010 notice, this list of conditions and the following disclaimer. 00011 00012 * Redistributions in binary form must reproduce the above 00013 copyright notice, this list of conditions and the following 00014 disclaimer in the documentation and/or other materials provided 00015 with the distribution. 00016 00017 * Neither the name of the The Musepack Development Team nor the 00018 names of its contributors may be used to endorse or promote 00019 products derived from this software without specific prior 00020 written permission. 00021 00022 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00023 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00024 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00025 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00026 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00027 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00028 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00029 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00030 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00031 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00032 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 */ 00034 00038 00039 #include "musepack/musepack.h" 00040 #include "musepack/internal.h" 00041 00042 mpc_int32_t 00043 JumpID3v2 (mpc_reader* r) { 00044 unsigned char tmp [10]; 00045 mpc_uint32_t Unsynchronisation; // ID3v2.4-flag 00046 mpc_uint32_t ExtHeaderPresent; // ID3v2.4-flag 00047 mpc_uint32_t ExperimentalFlag; // ID3v2.4-flag 00048 mpc_uint32_t FooterPresent; // ID3v2.4-flag 00049 mpc_int32_t ret; 00050 00051 // seek to first byte of mpc data 00052 if (!r->seek (r->data, 0)) { 00053 return 0; 00054 } 00055 00056 r->read(r->data, tmp, sizeof(tmp)); 00057 00058 // check id3-tag 00059 if ( 0 != memcmp ( tmp, "ID3", 3) ) 00060 return 0; 00061 00062 // read flags 00063 Unsynchronisation = tmp[5] & 0x80; 00064 ExtHeaderPresent = tmp[5] & 0x40; 00065 ExperimentalFlag = tmp[5] & 0x20; 00066 FooterPresent = tmp[5] & 0x10; 00067 00068 if ( tmp[5] & 0x0F ) 00069 return -1; // not (yet???) allowed 00070 if ( (tmp[6] | tmp[7] | tmp[8] | tmp[9]) & 0x80 ) 00071 return -1; // not allowed 00072 00073 // read HeaderSize (syncsave: 4 * $0xxxxxxx = 28 significant bits) 00074 ret = tmp[6] << 21; 00075 ret += tmp[7] << 14; 00076 ret += tmp[8] << 7; 00077 ret += tmp[9] ; 00078 ret += 10; 00079 if ( FooterPresent ) 00080 ret += 10; 00081 00082 return ret; 00083 }