dvrengine/CommonRecordingEngine/DvrRtpClipHandler/src/CRtpMetaHeader.cpp
branchRCL_3
changeset 47 826cea16efd9
parent 45 798ee5f1972c
child 48 13a33d82ad98
equal deleted inserted replaced
45:798ee5f1972c 47:826cea16efd9
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:    Implementation of the Common Recording Engine RTP read class.*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <ipvideo/CRtpMetaHeader.h>
       
    22 #include <bsp.h>
       
    23 #include <etelmm.h>
       
    24 #include "videoserviceutilsLogger.h"
       
    25 
       
    26 // CONSTANTS
       
    27 // None
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CRtpMetaHeader::NewL
       
    33 // Static two-phased constructor. Leaves object to cleanup stack.
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 CRtpMetaHeader* CRtpMetaHeader::NewL( RFile& aFile, const TMetaMode& aMode )
       
    37     {
       
    38     CRtpMetaHeader* self = CRtpMetaHeader::NewLC( aFile, aMode );
       
    39     CleanupStack::Pop( self );
       
    40     return self;
       
    41     }
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CRtpMetaHeader::NewLC
       
    45 // Static two-phased constructor. Leaves object to cleanup stack.
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 CRtpMetaHeader* CRtpMetaHeader::NewLC( RFile& aFile, const TMetaMode& aMode )
       
    49     {
       
    50     CRtpMetaHeader* self = new( ELeave ) CRtpMetaHeader( aFile, aMode );
       
    51     CleanupStack::PushL( self );
       
    52     self->ConstructL();
       
    53     return self;
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CRtpMetaHeader::CRtpMetaHeader
       
    58 // C++ default constructor can NOT contain any code, that might leave.
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 CRtpMetaHeader::CRtpMetaHeader( RFile& aFile, const TMetaMode& aMode )
       
    62   : iFile( aFile ),
       
    63     iMode( aMode ),
       
    64     iMetaData( NULL ),
       
    65     iDataPtr( 0, 0 ),
       
    66     iEsgDataPoint( KErrNotFound ),
       
    67     iSrtpDataPoint( KErrNotFound ),
       
    68     iSdpDataPoint( KErrNotFound ),
       
    69     iMetaTotal( KErrNotFound )
       
    70     {
       
    71     // None
       
    72     }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CRtpMetaHeader::ConstructL
       
    76 // Symbian 2nd phase constructor can leave.
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 void CRtpMetaHeader::ConstructL()
       
    80     {
       
    81     LOG( "CRtpMetaHeader::ConstructL()" );
       
    82     
       
    83     // Mode
       
    84     if ( iMode == EMetaRead || iMode == EMetaUpdate )
       
    85         {
       
    86         // Read whole meta area
       
    87         ReadTintFromFileL( KMetaLengthPoint, iMetaTotal );
       
    88 
       
    89         // Meta header has reasonable length?
       
    90         if ( iMetaTotal > KMaxMetaHeaderLength || iMetaTotal <= 0 )
       
    91             {
       
    92             LOG( "CRtpMetaHeader::ConstructL(), Meta Total Corrupted" );
       
    93             User::Leave( KErrCorrupt );
       
    94             }
       
    95 
       
    96         // Room for header
       
    97         iMetaData = HBufC8::NewL( iMetaTotal );
       
    98         iDataPtr.Set( iMetaData->Des() );
       
    99         User::LeaveIfError( iFile.Read( KMetaLengthPoint, iDataPtr, iMetaTotal ) );
       
   100         
       
   101         // All data exist in meta header?
       
   102         if ( iDataPtr.Length() < iMetaTotal )
       
   103             {
       
   104             LOG( "CRtpMetaHeader::ConstructL(), Meta Header Corrupted" );
       
   105             User::Leave( KErrCorrupt );
       
   106             }
       
   107 
       
   108         // ESG data point ( device info point + device info data )
       
   109         iEsgDataPoint = KDeviceInfoPoint + KStringLengthBytes +
       
   110                         iDataPtr[KDeviceInfoPoint];
       
   111         
       
   112         // SRTP data point ( ESG data point + Service name + Program name )
       
   113         TInt snp( iEsgDataPoint + KStringLengthBytes + iDataPtr[iEsgDataPoint] );
       
   114         iSrtpDataPoint = snp + KStringLengthBytes + iDataPtr[snp];
       
   115 
       
   116         // SDD file point ( SRTP data point + SRTP data )
       
   117         const TInt srtplen( CRtpUtil::GetValueL( 
       
   118                             iDataPtr.Mid( iSrtpDataPoint, KIntegerBytes ) ) );
       
   119         User::LeaveIfError( srtplen );
       
   120         iSdpDataPoint = iSrtpDataPoint + KIntegerBytes + srtplen;
       
   121         }
       
   122     else // Write
       
   123         {
       
   124         iMetaData = HBufC8::NewL( 0 );
       
   125         // Room for meta length
       
   126         iMetaTotal = KMetaLengthPoint;
       
   127         AddIntegerL( KMetaLengthPoint, KErrNotFound );
       
   128         }
       
   129     }
       
   130 
       
   131 // -----------------------------------------------------------------------------
       
   132 // Destructor
       
   133 //
       
   134 CRtpMetaHeader::~CRtpMetaHeader()
       
   135 // -----------------------------------------------------------------------------
       
   136     {
       
   137     LOG( "CRtpMetaHeader::~CRtpMetaHeader()" );
       
   138     
       
   139     delete iMetaData;
       
   140     }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // CRtpMetaHeader::SeekHeaderPoint
       
   144 // Getter for seek header point.
       
   145 // Returns: Point to seek header
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 TInt CRtpMetaHeader::SeekHeaderPoint()
       
   149     {
       
   150     return iMetaTotal;
       
   151     }
       
   152  
       
   153 // -----------------------------------------------------------------------------
       
   154 // CRtpMetaHeader::CommitL
       
   155 // Writes meta header to the clip.
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 void CRtpMetaHeader::CommitL()
       
   159     {
       
   160     LOG( "CRtpMetaHeader::CommitL() in" );
       
   161 
       
   162     User::LeaveIfError( iMetaTotal );
       
   163     User::LeaveIfError( ( iMetaTotal > KMaxMetaHeaderLength ) * KErrCorrupt );
       
   164     
       
   165     if ( iMode == EMetaWrite )
       
   166         {
       
   167         User::LeaveIfError( iEsgDataPoint );
       
   168         User::LeaveIfError( iSrtpDataPoint );
       
   169         User::LeaveIfError( iSdpDataPoint );
       
   170         
       
   171         // Meta length
       
   172         iDataPtr.Delete( KMetaLengthPoint, KIntegerBytes );
       
   173         AddIntegerL( KMetaLengthPoint, iMetaTotal );
       
   174         
       
   175         User::LeaveIfError( iFile.Write( iDataPtr, iMetaTotal ) );
       
   176         }
       
   177 
       
   178     LOG( "CRtpMetaHeader::CommitL() out" );
       
   179     }
       
   180  
       
   181 // -----------------------------------------------------------------------------
       
   182 // CRtpMetaHeader::WriteAttributesL
       
   183 // Writes atributes to meta data header of the clip.
       
   184 // -----------------------------------------------------------------------------
       
   185 //
       
   186 void CRtpMetaHeader::WriteAttributesL( const SAttributes& aAtt )
       
   187     {
       
   188     TInt data( 0 );
       
   189     data|= aAtt.iOngoing << KOngoingFlagShift;
       
   190     data|= aAtt.iCompleted << KCompletedFlagShift;
       
   191     data|= aAtt.iProtected << KProtectedFlagShift;
       
   192     data|= aAtt.iFailed << KFailedFlagShift;
       
   193     data|= aAtt.iVersion << KVersionFieldShift;
       
   194     data|= aAtt.iQuality << KQualityFieldShift;
       
   195     data|= aAtt.iPostRule << KPostRuleFieldShift;
       
   196     data|= aAtt.iParental << KParentalFieldShift;
       
   197 
       
   198     AddIntegerL( KAttributesPoint, data );
       
   199     AddIntegerL( KPlayCountPoint, aAtt.iPlayCount );
       
   200     AddIntegerL( KPlaySpotPoint, aAtt.iPlaySpot );
       
   201     
       
   202     // Reserved room for 4 integers
       
   203     AddIntegerL( KReservedPoint1, 0 );
       
   204     AddIntegerL( KReservedPoint2, 0 );
       
   205     AddIntegerL( KReservedPoint3, 0 );
       
   206     AddIntegerL( KReservedPoint4, 0 );
       
   207     }
       
   208  
       
   209 // -----------------------------------------------------------------------------
       
   210 // CRtpMetaHeader::WriteStartTimeL
       
   211 // Writes start date/time info to meta header of the clip.
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 void CRtpMetaHeader::WriteStartTimeL( const TTime& aTime )
       
   215     {
       
   216     AddTimeL( KStartTimePoint, aTime );
       
   217     }
       
   218  
       
   219 // -----------------------------------------------------------------------------
       
   220 // CRtpMetaHeader::WriteEndTimeL
       
   221 // Writes end date/time info to meta header of the clip.
       
   222 // -----------------------------------------------------------------------------
       
   223 //
       
   224 void CRtpMetaHeader::WriteEndTimeL( const TTime& aTime )
       
   225     {
       
   226     AddTimeL( KEndTimePoint, aTime );
       
   227     }
       
   228  
       
   229 // -----------------------------------------------------------------------------
       
   230 // CRtpMetaHeader::WriteDurationL
       
   231 // Writes duration of clip to meta header of the clip.
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 void CRtpMetaHeader::WriteDurationL( const TInt aDuration )
       
   235     {
       
   236     AddIntegerL( KDurationPoint, aDuration );
       
   237     }
       
   238  
       
   239 // -----------------------------------------------------------------------------
       
   240 // CRtpMetaHeader::WriteSeekArrayPointL
       
   241 // Writes seek array point of clip to meta header of the clip.
       
   242 // -----------------------------------------------------------------------------
       
   243 //
       
   244 void CRtpMetaHeader::WriteSeekArrayPointL( const TInt aPoint )
       
   245     {
       
   246     AddIntegerL( KSeekArrayPoint, aPoint );
       
   247     }
       
   248 
       
   249 // -----------------------------------------------------------------------------
       
   250 // CRtpMetaHeader::WriteUserIdL
       
   251 // Writes user id to meta header of the clip.
       
   252 // -----------------------------------------------------------------------------
       
   253 //
       
   254 void CRtpMetaHeader::WriteUserIdL( const TDesC& aId )
       
   255     {
       
   256     WriteStringDataL( KUserIdPoint, aId );
       
   257     }
       
   258  
       
   259 // -----------------------------------------------------------------------------
       
   260 // CRtpMetaHeader::WriteDeviceInfoL
       
   261 // Writes device info to meta header of the clip.
       
   262 // -----------------------------------------------------------------------------
       
   263 //
       
   264 void CRtpMetaHeader::WriteDeviceInfoL( const TDesC& aInfo )
       
   265     {
       
   266     WriteStringDataL( KDeviceInfoPoint, aInfo );
       
   267     iEsgDataPoint = KDeviceInfoPoint + KStringLengthBytes + aInfo.Length();
       
   268     }
       
   269  
       
   270 // -----------------------------------------------------------------------------
       
   271 // CRtpMetaHeader::WriteEsgDataL
       
   272 // Writes ESG data to meta header of the clip.
       
   273 // -----------------------------------------------------------------------------
       
   274 //
       
   275 void CRtpMetaHeader::WriteEsgDataL( const TDesC& aService, const TDesC& aProgram )
       
   276     {
       
   277     // Device info must exist first
       
   278     User::LeaveIfError( iEsgDataPoint );
       
   279 
       
   280     // Service name
       
   281     WriteStringDataL( iEsgDataPoint, aService );
       
   282     
       
   283     // Program name
       
   284     const TInt prog( iEsgDataPoint + KStringLengthBytes + aService.Length() );
       
   285     WriteStringDataL( prog, aProgram );
       
   286     iSrtpDataPoint = prog + KStringLengthBytes + aProgram.Length();
       
   287     }
       
   288  
       
   289 // -----------------------------------------------------------------------------
       
   290 // CRtpMetaHeader::WriteSrtpDataL
       
   291 // Writes SRTP data to meta header of the clip.
       
   292 // -----------------------------------------------------------------------------
       
   293 //
       
   294 void CRtpMetaHeader::WriteSrtpDataL( const TDesC8& aSrtpData )
       
   295     {
       
   296     // ESG data must exist first
       
   297     User::LeaveIfError( iSrtpDataPoint );
       
   298     User::LeaveIfError( ( iMode!=EMetaWrite ) * KErrAccessDenied );
       
   299 
       
   300     AddIntegerL( iSrtpDataPoint, aSrtpData.Length() );
       
   301     AddDataL( iSrtpDataPoint + KIntegerBytes, aSrtpData );
       
   302     iSdpDataPoint = iSrtpDataPoint + KIntegerBytes + aSrtpData.Length();
       
   303     }
       
   304  
       
   305 // -----------------------------------------------------------------------------
       
   306 // CRtpMetaHeader::WriteSdpDataL
       
   307 // Writes SDP file data to meta header of the clip.
       
   308 // -----------------------------------------------------------------------------
       
   309 //
       
   310 void CRtpMetaHeader::WriteSdpDataL( const TDesC8& aSdpData )
       
   311     {
       
   312     // SRTP data must exist first
       
   313     User::LeaveIfError( iSdpDataPoint );
       
   314     User::LeaveIfError( ( iMode != EMetaWrite ) * KErrAccessDenied );
       
   315 
       
   316     if ( aSdpData.Length() )
       
   317         {
       
   318         AddIntegerL( iSdpDataPoint, aSdpData.Length() );
       
   319         AddDataL( iSdpDataPoint + KIntegerBytes, aSdpData );
       
   320         }
       
   321     else
       
   322         {
       
   323         AddIntegerL( iSdpDataPoint, 0 );
       
   324         }
       
   325     }
       
   326  
       
   327 // -----------------------------------------------------------------------------
       
   328 // CRtpMetaHeader::ReadAttributesL
       
   329 // Reads attributes of meta data header from clip.
       
   330 // -----------------------------------------------------------------------------
       
   331 //
       
   332 void CRtpMetaHeader::ReadAttributesL( SAttributes& aAtt )
       
   333     {
       
   334     aAtt.iVersion = 0;
       
   335 
       
   336     // Attributes
       
   337     HBufC8* bytes = iDataPtr.Mid( KAttributesPoint, KIntegerBytes ).AllocLC();
       
   338     TUint data( CRtpUtil::GetValueL( bytes->Des() ) );
       
   339     CleanupStack::PopAndDestroy( bytes );
       
   340     aAtt.iOngoing = ( data >> KOngoingFlagShift ) & ETrue;
       
   341     aAtt.iCompleted = ( data >> KCompletedFlagShift ) & ETrue;
       
   342     aAtt.iProtected = ( data >> KProtectedFlagShift ) & ETrue;
       
   343     aAtt.iFailed = ( data >> KFailedFlagShift ) & ETrue;
       
   344     aAtt.iVersion = ( TUint8 )( ( data >> KVersionFieldShift ) & 0xF );
       
   345     aAtt.iQuality = ( TUint8 )( ( data >> KQualityFieldShift ) & KMaxTUint8 );
       
   346     aAtt.iPostRule = ( TUint8 )( ( data >> KPostRuleFieldShift ) & KMaxTUint8 );
       
   347     aAtt.iParental = ( TUint8 )( ( data >> KParentalFieldShift ) & KMaxTUint8 );
       
   348 
       
   349     // Play count
       
   350     bytes = iDataPtr.Mid( KPlayCountPoint, KIntegerBytes ).AllocLC();
       
   351     aAtt.iPlayCount = CRtpUtil::GetValueL( bytes->Des() );
       
   352     CleanupStack::PopAndDestroy( bytes );
       
   353 
       
   354     // Play start spot
       
   355     bytes = iDataPtr.Mid( KPlaySpotPoint, KIntegerBytes ).AllocLC();
       
   356     aAtt.iPlaySpot = CRtpUtil::GetValueL( bytes->Des() );
       
   357     CleanupStack::PopAndDestroy( bytes );
       
   358 
       
   359     // Reserved room for 4 integers
       
   360     /*
       
   361     bytes = iDataPtr.Mid( KReservedPoint1, KIntegerBytes ).AllocLC();
       
   362     aAtt.iReservedX = CRtpUtil::GetValueL( bytes->Des() );
       
   363     CleanupStack::PopAndDestroy( bytes );
       
   364 
       
   365     bytes = iDataPtr.Mid( KReservedPoint2, KIntegerBytes ).AllocLC();
       
   366     aAtt.iReservedX = CRtpUtil::GetValueL( bytes->Des() );
       
   367     CleanupStack::PopAndDestroy( bytes );
       
   368 
       
   369     bytes = iDataPtr.Mid( KReservedPoint3, KIntegerBytes ).AllocLC();
       
   370     aAtt.iReservedX = CRtpUtil::GetValueL( bytes->Des() );
       
   371     CleanupStack::PopAndDestroy( bytes );
       
   372 
       
   373     bytes = iDataPtr.Mid( KReservedPoint4, KIntegerBytes ).AllocLC();
       
   374     aAtt.iReservedX = CRtpUtil::GetValueL( bytes->Des() );
       
   375     CleanupStack::PopAndDestroy( bytes );
       
   376     */
       
   377     }
       
   378  
       
   379 // -----------------------------------------------------------------------------
       
   380 // CRtpMetaHeader::ReadStartTimeL
       
   381 // Reads date/time of meta header from the clip.
       
   382 // -----------------------------------------------------------------------------
       
   383 //
       
   384 void CRtpMetaHeader::ReadStartTimeL( TTime& aTime )
       
   385     {
       
   386     GetTimeL( KStartTimePoint, aTime );
       
   387     }
       
   388  
       
   389 // -----------------------------------------------------------------------------
       
   390 // CRtpMetaHeader::ReadEndTimeL
       
   391 // Reads date/time of meta header from the clip.
       
   392 // -----------------------------------------------------------------------------
       
   393 //
       
   394 void CRtpMetaHeader::ReadEndTimeL( TTime& aTime )
       
   395     {
       
   396     GetTimeL( KEndTimePoint, aTime );
       
   397     }
       
   398  
       
   399 // -----------------------------------------------------------------------------
       
   400 // CRtpMetaHeader::ReadDurationL
       
   401 // Reads clip duration of meta header from the clip.
       
   402 // -----------------------------------------------------------------------------
       
   403 //
       
   404 void CRtpMetaHeader::ReadDurationL( TInt& aDuration )
       
   405     {
       
   406     HBufC8* bytes = iDataPtr.Mid( KDurationPoint, KIntegerBytes ).AllocLC();
       
   407     aDuration = CRtpUtil::GetValueL( bytes->Des() );
       
   408     User::LeaveIfError( aDuration );
       
   409     CleanupStack::PopAndDestroy( bytes );
       
   410     }
       
   411  
       
   412 // -----------------------------------------------------------------------------
       
   413 // CRtpMetaHeader::ReadSeekArrayPointL
       
   414 // Reads seek array point of meta header from the clip.
       
   415 // -----------------------------------------------------------------------------
       
   416 //
       
   417 void CRtpMetaHeader::ReadSeekArrayPointL( TInt& aPoint )
       
   418     {
       
   419     HBufC8* bytes = iDataPtr.Mid( KSeekArrayPoint, KIntegerBytes ).AllocLC();
       
   420     aPoint = CRtpUtil::GetValueL( bytes->Des() );
       
   421     User::LeaveIfError( aPoint );
       
   422     CleanupStack::PopAndDestroy( bytes );
       
   423     }
       
   424  
       
   425 // -----------------------------------------------------------------------------
       
   426 // CRtpMetaHeader::ReadUserIdL
       
   427 // Reads user id of meta header from the clip.
       
   428 // -----------------------------------------------------------------------------
       
   429 //
       
   430 void CRtpMetaHeader::ReadUserIdL( TDes& aId )
       
   431     {
       
   432     ReadStringDataL( KUserIdPoint, aId );
       
   433     }
       
   434  
       
   435 // -----------------------------------------------------------------------------
       
   436 // CRtpMetaHeader::ReadDeviceInfoL
       
   437 // Reads device info of meta header from the clip.
       
   438 // -----------------------------------------------------------------------------
       
   439 //
       
   440 void CRtpMetaHeader::ReadDeviceInfoL( TDes& aInfo )
       
   441     {
       
   442     ReadStringDataL( KDeviceInfoPoint, aInfo );
       
   443     }
       
   444  
       
   445 // -----------------------------------------------------------------------------
       
   446 // CRtpMetaHeader::ReadEsgDataL
       
   447 // Reads ESG data of meta header from the clip.
       
   448 // -----------------------------------------------------------------------------
       
   449 //
       
   450 void CRtpMetaHeader::ReadEsgDataL( TDes& aService, TDes& aProgram )
       
   451     {
       
   452     User::LeaveIfError( iEsgDataPoint );
       
   453 
       
   454     // Service name
       
   455     ReadStringDataL( iEsgDataPoint, aService );
       
   456     
       
   457     // Program name
       
   458     const TInt prog( iEsgDataPoint + KStringLengthBytes + aService.Length() );
       
   459     ReadStringDataL( prog, aProgram );
       
   460     }
       
   461  
       
   462 // -----------------------------------------------------------------------------
       
   463 // CRtpMetaHeader::ReadSrtpDataL
       
   464 // Reads SRTP data of meta header from the clip.
       
   465 // -----------------------------------------------------------------------------
       
   466 //
       
   467 HBufC8* CRtpMetaHeader::ReadSrtpDataL()
       
   468     {
       
   469     User::LeaveIfError( iSrtpDataPoint );
       
   470 
       
   471     // Length
       
   472     const TInt len( CRtpUtil::GetValueL( 
       
   473                     iDataPtr.Mid( iSrtpDataPoint, KIntegerBytes ) ) );
       
   474     // Data
       
   475     const TInt total( iSrtpDataPoint + KIntegerBytes + len );
       
   476     User::LeaveIfError( ( len < 0 || total > iDataPtr.MaxLength() ) * KErrCorrupt );
       
   477     HBufC8* buf = iDataPtr.Mid( iSrtpDataPoint + KIntegerBytes, len ).AllocL();
       
   478     return buf;
       
   479     }
       
   480  
       
   481 // -----------------------------------------------------------------------------
       
   482 // CRtpMetaHeader::ReadSdpDataL
       
   483 // Reads SDP file data of meta header from the clip.
       
   484 // -----------------------------------------------------------------------------
       
   485 //
       
   486 HBufC8* CRtpMetaHeader::ReadSdpDataL()
       
   487     {
       
   488     User::LeaveIfError( iSdpDataPoint );
       
   489 
       
   490     // Length
       
   491     const TInt len( CRtpUtil::GetValueL( 
       
   492                     iDataPtr.Mid( iSdpDataPoint, KIntegerBytes ) ) );
       
   493     // Data
       
   494     const TInt total( iSdpDataPoint + KIntegerBytes + len );
       
   495     User::LeaveIfError( ( len <= 0 || total > iDataPtr.MaxLength() ) * KErrCorrupt );
       
   496     HBufC8* buf = iDataPtr.Mid( iSdpDataPoint + KIntegerBytes, len ).AllocL();
       
   497     return buf;
       
   498     }
       
   499  
       
   500 // -----------------------------------------------------------------------------
       
   501 // CRtpMetaHeader::WriteStringDataL
       
   502 // Writes data with length info to meta header of the clip.
       
   503 // -----------------------------------------------------------------------------
       
   504 //
       
   505 void CRtpMetaHeader::WriteStringDataL( const TInt aPosition, const TDesC& aData )
       
   506     {
       
   507     const TInt len( aData.Length() );
       
   508     User::LeaveIfError( ( len > TInt( KMaxTUint8 ) ) * KErrArgument );
       
   509     User::LeaveIfError( ( iMode != EMetaWrite ) * KErrAccessDenied );
       
   510     
       
   511     // Length
       
   512     TBuf8<KStringLengthBytes> buf( KNullDesC8 );
       
   513     buf.Append( KCharSpace );
       
   514     buf[0] = ( TUint8 )( len );
       
   515     AddDataL( aPosition, buf );
       
   516 
       
   517     // Data to 8-bit
       
   518     HBufC8* data = HBufC8::NewLC( aData.Length() );
       
   519     TPtr8 ptr( data->Des() );
       
   520     ptr.Copy( aData );
       
   521     AddDataL( aPosition + KStringLengthBytes, ptr );
       
   522     CleanupStack::PopAndDestroy( data );
       
   523     }
       
   524  
       
   525 // -----------------------------------------------------------------------------
       
   526 // CRtpMetaHeader::ReadStringDataL
       
   527 // Reads data with length info of meta header from the clip.
       
   528 // -----------------------------------------------------------------------------
       
   529 //
       
   530 void CRtpMetaHeader::ReadStringDataL( const TInt aPosition, TDes& aData )
       
   531     {
       
   532     User::LeaveIfError( ( aPosition < 0 || aPosition > iDataPtr.Length() )
       
   533                         * KErrArgument );
       
   534     const TInt len( iDataPtr[aPosition] );
       
   535     User::LeaveIfError( ( len < 0 || len > TInt( KMaxTUint8 ) ) * KErrCorrupt );
       
   536     User::LeaveIfError( ( len > aData.MaxLength() ) * KErrArgument );
       
   537 
       
   538     aData.Copy( iDataPtr.Mid( aPosition + KStringLengthBytes, len ) );
       
   539     }
       
   540  
       
   541 // -----------------------------------------------------------------------------
       
   542 // CRtpMetaHeader::AddTimeL
       
   543 // Writes data/time or duration of clip to meta header of the clip.
       
   544 // -----------------------------------------------------------------------------
       
   545 //
       
   546 void CRtpMetaHeader::AddTimeL( const TInt aPosition, const TTime& aTime )
       
   547     {
       
   548     HBufC8* bytes = CRtpUtil::MakeBytesLC( I64LOW( aTime.Int64() ) );
       
   549     AddDataL( aPosition, bytes->Des() );
       
   550     CleanupStack::PopAndDestroy( bytes );
       
   551 
       
   552     bytes = CRtpUtil::MakeBytesLC( I64HIGH( aTime.Int64() ) );
       
   553     AddDataL( aPosition + KIntegerBytes, bytes->Des() );
       
   554     CleanupStack::PopAndDestroy( bytes );
       
   555     }
       
   556  
       
   557 // -----------------------------------------------------------------------------
       
   558 // CRtpMetaHeader::GetTimeL
       
   559 // Reads time value of meta header from the clip.
       
   560 // -----------------------------------------------------------------------------
       
   561 //
       
   562 void CRtpMetaHeader::GetTimeL( const TInt aPosition, TTime& aTime )
       
   563     {
       
   564     TUint low( CRtpUtil::GetValueL(
       
   565         iDataPtr.Mid( aPosition, KIntegerBytes ) ) );
       
   566     TUint high( CRtpUtil::GetValueL( 
       
   567         iDataPtr.Mid( aPosition +  KIntegerBytes, KIntegerBytes ) ) );
       
   568 
       
   569     aTime = TInt64( MAKE_TINT64( high, low ) );
       
   570     }
       
   571  
       
   572 // -----------------------------------------------------------------------------
       
   573 // CRtpMetaHeader::AddIntegerL
       
   574 // -----------------------------------------------------------------------------
       
   575 //
       
   576 void CRtpMetaHeader::AddIntegerL( const TInt aPosition, const TInt aValue )
       
   577     {
       
   578     HBufC8* bytes = CRtpUtil::MakeBytesLC( aValue );
       
   579     AddDataL( aPosition, bytes->Des() );
       
   580     CleanupStack::PopAndDestroy( bytes );
       
   581     }
       
   582 
       
   583 // -----------------------------------------------------------------------------
       
   584 // CRtpMetaHeader::AddDataL
       
   585 // -----------------------------------------------------------------------------
       
   586 //
       
   587 void CRtpMetaHeader::AddDataL( const TInt aPosition, const TDesC8& aData )
       
   588     {
       
   589     // Write must be in certain order
       
   590     User::LeaveIfError( ( aPosition > iMetaTotal ) * KErrWrite );
       
   591 
       
   592     switch ( iMode )
       
   593         {
       
   594         case EMetaWrite:
       
   595             iMetaTotal = iMetaData->Length() + aData.Length();
       
   596             iMetaData = iMetaData->ReAllocL( iMetaTotal );
       
   597             iDataPtr.Set( iMetaData->Des() );
       
   598             iDataPtr.Insert( aPosition, aData );
       
   599             break;
       
   600 
       
   601         case EMetaUpdate:
       
   602             User::LeaveIfError( iFile.Write( aPosition, aData, aData.Length() ) );
       
   603             break;
       
   604 
       
   605         default:
       
   606             User::Leave( KErrNotSupported );
       
   607             break;
       
   608         }
       
   609     }
       
   610  
       
   611 // -----------------------------------------------------------------------------
       
   612 // CRtpMetaHeader::ReadTintFromFileL
       
   613 // -----------------------------------------------------------------------------
       
   614 //
       
   615 void CRtpMetaHeader::ReadTintFromFileL( const TInt& aPosition, TInt& aValue )
       
   616     {
       
   617     HBufC8* bytes = HBufC8::NewLC( KIntegerBytes );
       
   618     TPtr8 ptr( bytes->Des() );
       
   619     User::LeaveIfError( iFile.Read( aPosition, ptr, KIntegerBytes ) );
       
   620     
       
   621     aValue = CRtpUtil::GetValueL( ptr );
       
   622     CleanupStack::PopAndDestroy( bytes );
       
   623     }
       
   624     
       
   625 //  End of File