Setting up a 3GP Parser

This tutorial describes how to set up a 3GP Parser.

Purpose

The purpose of this tutorial is to show you how to set up a 3GP Parser to read a 3GP, 3G2 or MP4 file.

Required background

The 3GP Library Overview introduces the 3GP Parser.

Introduction

The C3GPParse class provides the setup functions for the 3GP Parser.

Using a 3GP Parser

The following tasks are covered in this tutorial:

  1. Creating an instance of a 3GP Parser

  2. Initialising a 3GP Parser for reading 3GP, 3G2 or MP4 data.

Creating an instance of a 3GP Parser

Create an instance of a 3GP Parser by calling one of the overloads of C3GPParse::NewL():

  • To use the default read buffer size, call C3GPParse::NewL():

    static IMPORT_C C3GPParse *NewL();

    The default value for the read buffer size is 8KB.

  • To set the read buffer size, call C3GPParse::NewL(TInt) and set aReadBufferSize to be the required buffer size:

    static IMPORT_C C3GPParse *NewL(TInt aReadBufferSize);

Initialising a 3GP Parser for reading 3GP, 3G2 or MP4 data

Initialise the 3GP Parser for reading data by calling one of the overloads of C3GPParse::Open():

  • To initialise the 3GP Parser for reading data from a buffer, call C3GPParse::Open():

    IMPORT_C TInt Open();
  • To initialise the 3GP Parser for reading data from a file, call C3GPParse::Open(const TDesC &) and set aFilename to be the full path name of the file:

    IMPORT_C TInt Open(const TDesC &aFilename);
  • To initialise the 3GP Parser for reading data from a file, call C3GPParse::Open(const RFile &) and set aFile to be the file handle of the file:

    IMPORT_C TInt Open(const RFile &aFile);
  • To initialise the 3GP Parser for reading data from a CAF object, call C3GPParse::Open(const ContentAccess::CData &) and set aData to be CData object pointing to a CAF object:

    IMPORT_C TInt Open(const ContentAccess::CData &aData);

Example

The following example shows you how to set up a 3GP Parser to read a 3GP, 3G2 or MP4 file through an opened RFile handle.

CMyApp::ReadFileL(const RFile& aFile)
    {
    ...
    C3GPParse* parser = C3GPParse::NewL();
    CleanupStack::PushL(parser);
    User::LeaveIfError(parser->Open(aFile));
    CleanupStack::Pop(parser);
    ...
    }  

You can use either a file handle or a file path to specify the input file in C3GPParse::Open(). In the event that the input file is encrypted, a CData object should be supplied instead, for example:

CMyApp::ReadFileL(const RFile& aFile)
    {
    ...
    C3GPParse* parser = C3GPParse::NewL();
    CleanupStack::PushL(parser);

    CData* data = CData::NewLC(aFile, ...);
    User::LeaveIfError(parser->Open(*data));

    CleanupStack::Pop(2);    // parser, data
    ...
    }