os/mm/mmlibs/mmfw/Recogniser/src/id3parser.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include "parsers.h"
sl@0
    17
sl@0
    18
// The ID3 tag has a 10 byte header.
sl@0
    19
static const TInt KID3HeaderSize = 10;
sl@0
    20
sl@0
    21
sl@0
    22
//
sl@0
    23
// Checks if an ID3 header is present at the current
sl@0
    24
// reader position, and skips over it if it is.
sl@0
    25
// Returns ETrue if a header was found, EFalse otherwise.
sl@0
    26
//
sl@0
    27
TBool TID3Parser::ReadAndSkipID3L(CReader& aReader)
sl@0
    28
	{
sl@0
    29
	TBuf8<KID3HeaderSize> header;
sl@0
    30
	TUint8 a;
sl@0
    31
	TUint8 b;
sl@0
    32
	TUint8 c;
sl@0
    33
	TUint8 d;
sl@0
    34
	
sl@0
    35
	header.SetLength(KID3HeaderSize);
sl@0
    36
	aReader.ReadBytesL(header);
sl@0
    37
	
sl@0
    38
	do
sl@0
    39
		{
sl@0
    40
		// Look for the ID3 header.
sl@0
    41
		if ((header[0] != 'I') || (header[1] != 'D') || (header[2] != '3'))
sl@0
    42
			{
sl@0
    43
			break;
sl@0
    44
			}
sl@0
    45
			
sl@0
    46
		// The last 4 bits of byte[5] should be zero.
sl@0
    47
		if ((header[5] & 0x0f))	// [00001111]
sl@0
    48
			{
sl@0
    49
			break;
sl@0
    50
			}
sl@0
    51
			
sl@0
    52
		// Read the tag size. It's stored in a sync-safe manner
sl@0
    53
		// (the highest bit is never set so it won't be confused
sl@0
    54
		// with a frame-sync). If the highest bit is set, it's invalid.
sl@0
    55
		a = header[6];
sl@0
    56
		b = header[7];
sl@0
    57
		c = header[8];
sl@0
    58
		d = header[9];
sl@0
    59
		
sl@0
    60
		// OR the values together and check that the highest bit of
sl@0
    61
		// the result isn't set. Saves on doing four individual checks.
sl@0
    62
		if ((a | b | c | d) & 0x80) // [10000000]
sl@0
    63
			{
sl@0
    64
			break;
sl@0
    65
			}
sl@0
    66
		
sl@0
    67
		// Convert from sync-safe format to normal format.
sl@0
    68
		// [0aaaaaaa][0bbbbbbb][0ccccccc][0ddddddd] is changed to
sl@0
    69
		// [0000aaaa][aaabbbbb][bbcccccc][cddddddd]
sl@0
    70
		//
sl@0
    71
		// Copy bit[0] of c into bit[7] of d.
sl@0
    72
		d |= ((c & 0x01) << 7);
sl@0
    73
		c >>= 1;
sl@0
    74
		
sl@0
    75
		// Copy bit[1,0] of b into bit[7,6] of c.
sl@0
    76
		c |= ((b & 0x03) << 6);
sl@0
    77
		b >>= 2;
sl@0
    78
		
sl@0
    79
		// Copy bit[2,1,0] of a into bit[7,6,5] of b.
sl@0
    80
		b |= ((a & 0x07) << 5);
sl@0
    81
		a >>= 3;
sl@0
    82
		
sl@0
    83
		TInt length = MAKE_INT32(a, b, c, d);
sl@0
    84
		aReader.SeekL(length);
sl@0
    85
		return ETrue;
sl@0
    86
		}
sl@0
    87
	while (EFalse);
sl@0
    88
	
sl@0
    89
	// It's not an ID3 header.
sl@0
    90
	// Undo the header read.
sl@0
    91
	aReader.SeekL(-KID3HeaderSize);
sl@0
    92
	return EFalse;
sl@0
    93
	}