sl@0: // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "parsers.h" sl@0: sl@0: // The ID3 tag has a 10 byte header. sl@0: static const TInt KID3HeaderSize = 10; sl@0: sl@0: sl@0: // sl@0: // Checks if an ID3 header is present at the current sl@0: // reader position, and skips over it if it is. sl@0: // Returns ETrue if a header was found, EFalse otherwise. sl@0: // sl@0: TBool TID3Parser::ReadAndSkipID3L(CReader& aReader) sl@0: { sl@0: TBuf8 header; sl@0: TUint8 a; sl@0: TUint8 b; sl@0: TUint8 c; sl@0: TUint8 d; sl@0: sl@0: header.SetLength(KID3HeaderSize); sl@0: aReader.ReadBytesL(header); sl@0: sl@0: do sl@0: { sl@0: // Look for the ID3 header. sl@0: if ((header[0] != 'I') || (header[1] != 'D') || (header[2] != '3')) sl@0: { sl@0: break; sl@0: } sl@0: sl@0: // The last 4 bits of byte[5] should be zero. sl@0: if ((header[5] & 0x0f)) // [00001111] sl@0: { sl@0: break; sl@0: } sl@0: sl@0: // Read the tag size. It's stored in a sync-safe manner sl@0: // (the highest bit is never set so it won't be confused sl@0: // with a frame-sync). If the highest bit is set, it's invalid. sl@0: a = header[6]; sl@0: b = header[7]; sl@0: c = header[8]; sl@0: d = header[9]; sl@0: sl@0: // OR the values together and check that the highest bit of sl@0: // the result isn't set. Saves on doing four individual checks. sl@0: if ((a | b | c | d) & 0x80) // [10000000] sl@0: { sl@0: break; sl@0: } sl@0: sl@0: // Convert from sync-safe format to normal format. sl@0: // [0aaaaaaa][0bbbbbbb][0ccccccc][0ddddddd] is changed to sl@0: // [0000aaaa][aaabbbbb][bbcccccc][cddddddd] sl@0: // sl@0: // Copy bit[0] of c into bit[7] of d. sl@0: d |= ((c & 0x01) << 7); sl@0: c >>= 1; sl@0: sl@0: // Copy bit[1,0] of b into bit[7,6] of c. sl@0: c |= ((b & 0x03) << 6); sl@0: b >>= 2; sl@0: sl@0: // Copy bit[2,1,0] of a into bit[7,6,5] of b. sl@0: b |= ((a & 0x07) << 5); sl@0: a >>= 3; sl@0: sl@0: TInt length = MAKE_INT32(a, b, c, d); sl@0: aReader.SeekL(length); sl@0: return ETrue; sl@0: } sl@0: while (EFalse); sl@0: sl@0: // It's not an ID3 header. sl@0: // Undo the header read. sl@0: aReader.SeekL(-KID3HeaderSize); sl@0: return EFalse; sl@0: }