First public contribution.
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
18 // The ID3 tag has a 10 byte header.
19 static const TInt KID3HeaderSize = 10;
23 // Checks if an ID3 header is present at the current
24 // reader position, and skips over it if it is.
25 // Returns ETrue if a header was found, EFalse otherwise.
27 TBool TID3Parser::ReadAndSkipID3L(CReader& aReader)
29 TBuf8<KID3HeaderSize> header;
35 header.SetLength(KID3HeaderSize);
36 aReader.ReadBytesL(header);
40 // Look for the ID3 header.
41 if ((header[0] != 'I') || (header[1] != 'D') || (header[2] != '3'))
46 // The last 4 bits of byte[5] should be zero.
47 if ((header[5] & 0x0f)) // [00001111]
52 // Read the tag size. It's stored in a sync-safe manner
53 // (the highest bit is never set so it won't be confused
54 // with a frame-sync). If the highest bit is set, it's invalid.
60 // OR the values together and check that the highest bit of
61 // the result isn't set. Saves on doing four individual checks.
62 if ((a | b | c | d) & 0x80) // [10000000]
67 // Convert from sync-safe format to normal format.
68 // [0aaaaaaa][0bbbbbbb][0ccccccc][0ddddddd] is changed to
69 // [0000aaaa][aaabbbbb][bbcccccc][cddddddd]
71 // Copy bit[0] of c into bit[7] of d.
72 d |= ((c & 0x01) << 7);
75 // Copy bit[1,0] of b into bit[7,6] of c.
76 c |= ((b & 0x03) << 6);
79 // Copy bit[2,1,0] of a into bit[7,6,5] of b.
80 b |= ((a & 0x07) << 5);
83 TInt length = MAKE_INT32(a, b, c, d);
84 aReader.SeekL(length);
89 // It's not an ID3 header.
90 // Undo the header read.
91 aReader.SeekL(-KID3HeaderSize);