examples/sfexamples/oggvorbiscodec/src/OggVorbisUtil/OggPackets.cpp

00001 // OggPackets.cpp
00002 //
00003 // Copyright © Symbian Software Ltd 2005 - 2008.  All rights reserved.
00004 //
00005 
00006 
00007 #include <e32base.h>
00008 #include <e32debug.h>
00009 #include <oggutil.h>
00010 #include "OggUtilBody.h"
00011 
00012 //-------------------------- COggStream --------------------------
00013 
00014 EXPORT_C COggStream* COggStream::NewL()
00015     {
00016     COggStream* self = new(ELeave)COggStream;
00017     CleanupStack::PushL(self);
00018     self->ConstructL();
00019     CleanupStack::Pop(self);
00020     return self;
00021     }
00022 
00023 COggStream::COggStream()
00024     {
00025     }
00026 
00027 COggStream::~COggStream()
00028     {
00029     delete iBody;
00030     }
00031 
00032 void COggStream::ConstructL()
00033     {
00034     iBody = new(ELeave) COggStream::CBody;
00035     iBody->ConstructL();
00036     }
00037 
00038 EXPORT_C TInt COggStream::PageIn(TOggPage& aPage)
00039     {
00040     return iBody->PageIn(aPage);
00041     }
00042 
00043 EXPORT_C TInt COggStream::PacketOut(TOggPacket& aDst)
00044     {
00045     return iBody->PacketOut(aDst);
00046     }
00047 
00048 EXPORT_C void COggStream::Reset()
00049     {
00050     iBody->Reset();
00051     }
00052 
00053 EXPORT_C TInt COggStream::GetSerialNo()
00054     {
00055     return iBody->GetSerialNo();
00056     }
00057 
00058 //---------------------- COggStream::CBody -----------------------
00059 
00060 
00061 COggStream::CBody::CBody()
00062     : iStreamLocked(EFalse)
00063     {
00064     }
00065 
00066 void COggStream::CBody::ConstructL()
00067     {
00068 #ifdef SYMBIAN_CODEC_FLOAT_POINT
00069         iStreamState = &iOggStreamState;
00070         //during recording we give a random serial number to the stream.
00071         const TInt KStreamSerialNumber = 10;
00072         ogg_stream_init(iStreamState, KStreamSerialNumber);
00073 #else
00074         //stream with negative serial indicates it is not initialized. We do this during playing because we 
00075         //get the serial number from the clip.
00076         iStreamState = ogg_stream_create(-1);
00077 #endif
00078 
00079     }
00080 
00081 COggStream::CBody::~CBody()
00082     {
00083 #ifdef SYMBIAN_CODEC_FLOAT_POINT
00084         ogg_stream_clear(&iOggStreamState);
00085 #else
00086         ogg_packet_release(&iPacket);
00087     ogg_page_release(&iPage);
00088     ogg_stream_destroy(iStreamState);
00089 #endif
00090     }
00091 
00100 TInt COggStream::CBody::PageIn(TOggPage& aPage)
00101     {
00102     OggUtil::Make_ogg_page(aPage, iPage); // get an ogg_page from the TOggPage
00103     if (!iStreamLocked)
00104         {
00105         ogg_stream_reset_serialno
00106             (iStreamState, ogg_page_serialno(&iPage));
00107         iStreamLocked=ETrue;
00108         }
00109      if (ogg_page_serialno(&iPage)==iStreamState->serialno)
00110         {
00111         ogg_stream_pagein(iStreamState, &iPage);
00112         return KErrNone;
00113         }
00114      else 
00115         {
00116         return KErrArgument;// this page does not belong to our stream
00117         }
00118     }
00119 
00128 TInt COggStream::CBody::PacketOut(TOggPacket& aPacket)
00129     {
00130     while (ETrue)
00131         {
00132         TInt res = ogg_stream_packetout(iStreamState, &iPacket);
00133         if (res<0) // out of sync/gap in data
00134             {
00135             //Usually this will not be a fatal error so continue. This happens during seeking
00136             RDebug::Printf("out of sync and there is a gap in the data...continue\n");
00137             //resync
00138             }
00139         else if (res==0) // need more data
00140             {
00141             return KErrNotFound;
00142             }
00143         else // have a packet
00144             {
00145             OggUtil::MakeOggPacket(iPacket, aPacket);
00146             return KErrNone;
00147             }
00148         }
00149     }
00150 
00151 void COggStream::CBody::Reset()
00152     {
00153     ogg_stream_reset(iStreamState);
00154     }
00155 
00156 TInt COggStream::CBody::GetSerialNo()
00157     {
00158     return iStreamState->serialno;
00159     }

Generated by  doxygen 1.6.2