Reading Video and Audio Content

This tutorial describes how to read video and audio content.

Purpose

The purpose of this tutorial is to show you how to read video and audio content synchronously and asynchronously.

Required background

The 3GP Library Overview introduces the 3GP Parser.

Introduction

Video and audio content is read frame by frame. Video and audio frames do not necessarily have to be read in the same order that they are stored in a file. There are separate index counters for video and audio streams, which makes it possible to get all video stream data first, then get the data in the audio stream. Random access to video and audio frames is also possible with other functions provided by the C3GPParse class.

Using frames

The following tasks are covered in this tutorial:

Reading a video frame

To read a video frame, call one of the overloads of C3GPParse::ReadVideoFrame():

Note: There are separate cursors for storing current positions of video and audio streams. Calling C3GPParse::ReadVideoFrame() does not affect the position of the next audio stream.

Reading audio frames

To read audio frames, call one of the overloads of C3GPParse::ReadAudioFrames():

  • To read the audio frames that are stored in the current audio sample from the 3GP file or stream and return them synchronously, call C3GPParse::ReadAudioFrames(TDes8 &, TInt &, TUint &, TUint &):

    IMPORT_C TInt ReadAudioFrames(TDes8 &aBuffer, TInt &aReturnedFrames, TUint &aTimeStampInMs, TUint &aTimeStampInTimescale) const;

    The next frame read depends on the current position in the input 3GP file. You can use the C3GPParse::Seek() function to change the current position in the 3GP file.

  • To read the audio frames that are stored in the current audio sample from the 3GP file or stream and return them asynchronously, call C3GPParse::ReadAudioFrames(M3GPParseCallback &, TDes8 &):

    IMPORT_C void ReadAudioFrames(M3GPParseCallback &aCallback, TDes8 &aBuffer);

    Upon completion, successful or otherwise, the callback function M3GPParseCallback::AudioFramesAvailable(TInt, TUint, TUint, TUint) is called.

    Note: The asynchronous C3GPParse::ReadAudioFrames() function is not supported when the 3GP Parser is in buffer mode.

Note: There are separate cursors for storing current positions for video and audio streams. Calling C3GPParse::ReadAudioFrames() does not change the current position of the video stream.

Example

The following example shows you how to read video and audio frames:

CMyApp::ReadFileL(const RFile& aFile)
    {
    ...
    // See example code in Setting up a 3GP Parser and Getting Audio and Video Stream Metadata. 
    ...
    TInt err = KErrNone;
    while (err != KErrNotFound)
        {
        TInt err = parser->ReadVideoFrame(...);
        if (err == KErrNone)
            {
            // do something with the video data                        
            ...
            }                
        }
        
    err = KErrNone        
    while (err != KErrNotFound)
        {
        // retrieve audio frames
        TInt err = parser->ReadAudioFrames(...);
        if (err == KErrNone)
            {
            // do something with the audio data                        
            ...
            }                

        ...