1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmlibs/mmfw/Recogniser/src/id3parser.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,93 @@
1.4 +// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "parsers.h"
1.20 +
1.21 +// The ID3 tag has a 10 byte header.
1.22 +static const TInt KID3HeaderSize = 10;
1.23 +
1.24 +
1.25 +//
1.26 +// Checks if an ID3 header is present at the current
1.27 +// reader position, and skips over it if it is.
1.28 +// Returns ETrue if a header was found, EFalse otherwise.
1.29 +//
1.30 +TBool TID3Parser::ReadAndSkipID3L(CReader& aReader)
1.31 + {
1.32 + TBuf8<KID3HeaderSize> header;
1.33 + TUint8 a;
1.34 + TUint8 b;
1.35 + TUint8 c;
1.36 + TUint8 d;
1.37 +
1.38 + header.SetLength(KID3HeaderSize);
1.39 + aReader.ReadBytesL(header);
1.40 +
1.41 + do
1.42 + {
1.43 + // Look for the ID3 header.
1.44 + if ((header[0] != 'I') || (header[1] != 'D') || (header[2] != '3'))
1.45 + {
1.46 + break;
1.47 + }
1.48 +
1.49 + // The last 4 bits of byte[5] should be zero.
1.50 + if ((header[5] & 0x0f)) // [00001111]
1.51 + {
1.52 + break;
1.53 + }
1.54 +
1.55 + // Read the tag size. It's stored in a sync-safe manner
1.56 + // (the highest bit is never set so it won't be confused
1.57 + // with a frame-sync). If the highest bit is set, it's invalid.
1.58 + a = header[6];
1.59 + b = header[7];
1.60 + c = header[8];
1.61 + d = header[9];
1.62 +
1.63 + // OR the values together and check that the highest bit of
1.64 + // the result isn't set. Saves on doing four individual checks.
1.65 + if ((a | b | c | d) & 0x80) // [10000000]
1.66 + {
1.67 + break;
1.68 + }
1.69 +
1.70 + // Convert from sync-safe format to normal format.
1.71 + // [0aaaaaaa][0bbbbbbb][0ccccccc][0ddddddd] is changed to
1.72 + // [0000aaaa][aaabbbbb][bbcccccc][cddddddd]
1.73 + //
1.74 + // Copy bit[0] of c into bit[7] of d.
1.75 + d |= ((c & 0x01) << 7);
1.76 + c >>= 1;
1.77 +
1.78 + // Copy bit[1,0] of b into bit[7,6] of c.
1.79 + c |= ((b & 0x03) << 6);
1.80 + b >>= 2;
1.81 +
1.82 + // Copy bit[2,1,0] of a into bit[7,6,5] of b.
1.83 + b |= ((a & 0x07) << 5);
1.84 + a >>= 3;
1.85 +
1.86 + TInt length = MAKE_INT32(a, b, c, d);
1.87 + aReader.SeekL(length);
1.88 + return ETrue;
1.89 + }
1.90 + while (EFalse);
1.91 +
1.92 + // It's not an ID3 header.
1.93 + // Undo the header read.
1.94 + aReader.SeekL(-KID3HeaderSize);
1.95 + return EFalse;
1.96 + }