Initialising a Parser Plug-in

This tutorial describes how to initialise a parser plug-in.

Purpose

The purpose of this tutorial is to show you how to use the metadata client utility to initialise a parser plug-in.

Required Background

The Metadata Utility Library Overview introduces the metadata client utility.

Introduction

Client applications must initialise a parser before it can be used to read metadata. The client initialises the parser plug-in by passing either a filename (including path), file handler or buffer (containing unique header data and metadata). The InitializeParserL() method is used to do this. InitializeParserL() is responsible for deciding which parser plug-in should be used to provide support for a particular format.

Parser plug-ins provide information in their ECOM resource file. This information allows MUF (and ultimately the client application) to determine:

  • The formats the parser plug-in can parse

  • The MIME types applicable to the format

  • The file extensions that identify files that can be handled by the format

  • Any segments of header data that can be matched against the multimedia data to check that the data could be handled using this format.

  • The UID of the parser plug-in implementation.

Using InitializeParserL()

The following tasks will be covered in this tutorial:

  • Initialise a parser plug-in

Basic Procedure

The high level steps to initialise a parser plug-in are shown here:

  1. Create a new metadata utility object.

  2. Initialise a parser plug-in using one of the following overloads of InitializeParserL():

    • Initialise with input file

      IMPORT_C void InitializeParserL(const TDesC& aFileName);

      Call CMetaDataClientUtility::InitializeParserL() and set aFileName to an input file name including path. MUF resolves the parser plug-in using the input file extension and initialises the parser plug-in with the input file name.

    • Initialise with file handler

      IMPORT_C void InitializeParserL(RFile& aFile);

      Call CMetaDataClientUtility::InitializeParserL() and set aFile to an input file handler. MUF reads the file extension, resolves the parser plug-in with the input file extension and initialises the parser plug-in with the input file name.

    • Initialise with DRM protected file

      IMPORT_C void InitializeParserL(const TMMSource& aDRMSource);

      Call CMetaDataClientUtility::InitializeParserL() and set aDRMSource to a protected file source. MUF resolves the parser plug-in with the MIME type and initialises the parser plug-in with ContentAccess::CData.

    • Initialise with data buffer

      IMPORT_C void InitializeParserL(const TDesC8& aDescriptor);

      Call CMetaDataClientUtility::InitializeParserL() and set aDescriptor to a source buffer. Note that the source buffer contains unique header data and metadata. MUF resolves the parser plug-in with the unique header data and initialises the parser plug-in with the source buffer.

    • Initialise parser directly

      IMPORT_C void InitializeParserL(const TUid aParserUid,const TDesC& aFileName);

      If the client application resolves the parser from the supported formats, then the application can pass the UID of the parser and an input file name. Call CMetaDataClientUtility::InitializeParserL() and set aParserUid to the UID of the parser and aFileName to the input file name (including full path). MUF directly sets the file name on the requested parser.

      Note: ECOM plug-ins have several associated UIDs. The one identifying the plug-in is the implementation UID.

Examples

Initialise with input file

_LIT(KTestMp3File, "c:\\mm\\muf\\testfiles\\aagaya.mp3");
const TPtrC fileName(KTestMp3File);

CMetaDataClientUtility* utility = CMetaDataClientUtility::NewL(EAllPlugIns);
CleanupStack::PushL(utility);

utility->InitializeParserL(fileName);
:
CleanupStack::PopAndDestroy();

Initialise with file handler

_LIT(KTestMp3File, "c:\\mm\\muf\\testfiles\\aagaya.mp3");
const TPtrC fileName(KTestMp3File);
CMetaDataClientUtility* utility = CMetaDataClientUtility::NewL(EAllPlugIns);
CleanupStack::PushL(utility);
RFile file;
RFs fs;
User::LeaveIfError(fs.Connect());
User::LeaveIfError(file.Open(fs, fileName, EFileShareReadersOnly));
utility->InitializeParserL(file);
:
CleanupStack::PopAndDestroy();
file.Close();
fs.Close();

Initialise with DRM protected file

TPtrC proFileName;
CMetaDataClientUtility* utility = CMetaDataClientUtility::NewL(EAllPlugIns);
CleanupStack::PushL(utility);

utility->InitializeParserL(TMMFileSource(proFileName, KRightsPlayerUniqueId001, ContentAccess::EPlay));
:
CleanupStack::PopAndDestroy();

Initialise with data buffer

_LIT(KTestMp3File, "c:\\mm\\muf\\testfiles\\aagaya.mp3");
const TPtrC fileName(KTestMp3File);
CMetaDataClientUtility* utility = CMetaDataClientUtility::NewL(EAllPlugIns);
CleanupStack::PushL(utility);
RFile file;
RFs fs;
TInt headerSize = set to header size;
User::LeaveIfError(fs.Connect());
User::LeaveIfError(file.Open(fs, fileName, EFileRead));
HBufC8* fileData = HBufC8::NewL(headerSize);
TPtr8 buf = fileData->Des();
file.Read(buf, headerSize);
utility->InitializeParserL(*fileData);
:
CleanupStack::PopAndDestroy(2);
file.Close();
fs.Close();

Initialise parser directly

CMetaDataClientUtility* utility = CMetaDataClientUtility::NewL(EAllPlugIns);
CleanupStack::PushL(utility);
TUid uid;
//Get the uid from supported formats

utility->InitializeParserL(uid, fileName);
:
CleanupStack::PopAndDestroy();