harvester/harvesterplugins/RTPPlugin/src/harvesterrtpmetadatareader.cpp
changeset 0 c53acadfccc6
child 40 910a23996aa0
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2007-2009 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 "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:  Reads metadata from rtp clip meta header
       
    15 *
       
    16 */
       
    17 
       
    18 #include "harvesterrtpmetadatareader.h"
       
    19 #include "harvesterrtpplugin.h"
       
    20 #include "harvesterlog.h"
       
    21 
       
    22 _LIT( KTxtSpace, " ");
       
    23 
       
    24 // ======== MEMBER FUNCTIONS ========
       
    25 
       
    26 // ---------------------------------------------------------------------------
       
    27 // Constructor
       
    28 // ---------------------------------------------------------------------------
       
    29 //
       
    30 CHarvesterRtpMetaDataReader* CHarvesterRtpMetaDataReader::NewL( 
       
    31     const TDesC8* aFileBuffer  )
       
    32     {
       
    33     CHarvesterRtpMetaDataReader* self =
       
    34         new( ELeave ) CHarvesterRtpMetaDataReader( aFileBuffer );
       
    35     CleanupStack::PushL( self );
       
    36     self->ConstructL();
       
    37     CleanupStack::Pop( self );
       
    38     return self;
       
    39     }
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // Destructor
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 CHarvesterRtpMetaDataReader::~CHarvesterRtpMetaDataReader()
       
    46     {
       
    47     WRITELOG( "CHarvesterRtpMetaDataReader::~CHarvesterRtpMetaDataReader()" );
       
    48     delete iMetaData;
       
    49     }
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // Read details from meta header
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 void CHarvesterRtpMetaDataReader::GetClipDetailsL( 
       
    56     CHarvesterRtpClipDetails& aDetails )
       
    57     {
       
    58     WRITELOG( "CHarvesterRtpMetaDataReader::GetClipDetailsL()" );
       
    59     
       
    60     // Attributes
       
    61     TPtrC8 bytes( iDataPtr.Mid( KAttributesPoint, KIntegerBytes ) );
       
    62     TUint data( 0 );
       
    63     User::LeaveIfError( GetValue( bytes, data ) );
       
    64 
       
    65     // Recording quality 
       
    66     aDetails.iQuality = 
       
    67         ( TUint8 )( ( data >> KQualityFieldShift ) & KMaxTUint8 );
       
    68     //Recording ongoing 
       
    69     aDetails.iRecOngoing = 
       
    70         ( data >> KOngoingFlagShift ) & ETrue;
       
    71     // Recording completed 
       
    72     aDetails.iRecCompleted = 
       
    73         ( data >> KCompletedFlagShift ) & ETrue;
       
    74     //Recording failed 
       
    75     aDetails.iRecFailed = 
       
    76         ( data >> KFailedFlagShift ) & ETrue;
       
    77     //Parental rate
       
    78     aDetails.iParental =
       
    79          ( TUint8 )( ( data >> KParentalFieldShift ) & KMaxTUint8 );
       
    80     // Post rule    
       
    81     TUint8 postRule = 
       
    82         ( TUint8 )( ( data >> KPostRuleFieldShift ) & KMaxTUint8 );
       
    83     
       
    84     if ( postRule == KContentRightsLockToDevice )
       
    85         {
       
    86         aDetails.iPostRule = ETrue;
       
    87         }
       
    88     else
       
    89         {
       
    90         aDetails.iPostRule = EFalse;
       
    91         }
       
    92         
       
    93     // Duration
       
    94     TUint duration( 0 ); 
       
    95     TPtrC8 durationBytes ( iDataPtr.Mid( KDurationPoint, KIntegerBytes ) );
       
    96     User::LeaveIfError( GetValue( durationBytes, duration ) );
       
    97     duration /= 1000; //Convert to seconds 
       
    98     aDetails.iDuration = static_cast<TReal32>( duration );
       
    99     
       
   100     // Title
       
   101     GetProgramTitleL( aDetails.iTitle );
       
   102     }
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // Default constructor
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 CHarvesterRtpMetaDataReader::CHarvesterRtpMetaDataReader(
       
   109     const TDesC8* aFileBuffer )
       
   110     : iMetaTotal( KErrNotFound ),
       
   111       iMetaData( NULL ),
       
   112       iDataPtr( 0, 0 ),
       
   113       iEsgDataPoint ( KErrNotFound ),
       
   114       iFileBuffer( aFileBuffer )
       
   115     {
       
   116     // None
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // 2nd phase constructor
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 void CHarvesterRtpMetaDataReader::ConstructL()
       
   124     {
       
   125     WRITELOG( "CHarvesterRtpMetaDataReader::ConstructL()" );
       
   126     TPtrC8 bytes;
       
   127     
       
   128     if ( iFileBuffer 
       
   129         && iFileBuffer->Length() > KIntegerBytes )
       
   130         {
       
   131         // Read whole meta area
       
   132         bytes.Set( iFileBuffer->Mid( KMetaLengthPoint, KIntegerBytes ) );
       
   133         }        
       
   134 
       
   135     TUint value ( 0 );
       
   136     User::LeaveIfError( GetValue( bytes, value ) );
       
   137     
       
   138     iMetaTotal = value;
       
   139     
       
   140     if ( iMetaTotal > KMaxMetaHeaderLength || iMetaTotal <= 0 )
       
   141         {
       
   142         //Length not reasonable, metadata corrupted
       
   143         WRITELOG( "CHarvesterRtpMetaDataReader - metadata corrupted, leave!" );
       
   144         User::Leave( KErrCorrupt );
       
   145         }
       
   146 
       
   147     iMetaData = HBufC8::NewL( iMetaTotal );
       
   148     *iMetaData = iFileBuffer->Mid( KMetaLengthPoint, iMetaTotal );
       
   149 
       
   150     iDataPtr.Set( iMetaData->Des() );
       
   151             
       
   152     // Check that all data exist in meta header
       
   153     if ( iDataPtr.Length() < iMetaTotal )
       
   154         {
       
   155         //Meta header corrupted
       
   156         WRITELOG( "CHarvesterRtpMetaDataReader - metaheader corrupted, leave!" );
       
   157         User::Leave( KErrCorrupt );
       
   158         }
       
   159 
       
   160     // ESG data point ( device info point + device info data )
       
   161     iEsgDataPoint = KDeviceInfoPoint + KStringLengthBytes +
       
   162                     iDataPtr[KDeviceInfoPoint];
       
   163 
       
   164     }
       
   165 
       
   166 // -----------------------------------------------------------------------------
       
   167 // Reads data with length info of meta header from the clip
       
   168 // -----------------------------------------------------------------------------
       
   169 //
       
   170 void CHarvesterRtpMetaDataReader::ReadStringDataL( 
       
   171     const TInt aPosition, 
       
   172     TPtrC8& aData )
       
   173     {
       
   174     WRITELOG( "CHarvesterRtpMetaDataReader::ReadStringDataL()" );
       
   175 
       
   176     if ( aPosition < 0 
       
   177         || aPosition > iDataPtr.Length() )
       
   178         {
       
   179         WRITELOG( "CHarvesterRtpMetaDataReader - KErrArgument, leave!" );
       
   180         User::Leave( KErrArgument );
       
   181         }
       
   182 
       
   183     const TInt len( iDataPtr[aPosition] );
       
   184     
       
   185     if ( len < 0 
       
   186         || len > TInt( KMaxTUint8 ) )
       
   187         {
       
   188         WRITELOG( "CHarvesterRtpMetaDataReader - KErrCorrupt, leave!" );
       
   189         User::Leave( KErrCorrupt );
       
   190         }
       
   191         
       
   192     aData.Set( iDataPtr.Mid( aPosition + KStringLengthBytes, len ) );
       
   193     }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // Get value
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 TInt CHarvesterRtpMetaDataReader::GetValue( 
       
   200     const TDesC8& aBytes, 
       
   201     TUint& aValue )
       
   202     {
       
   203     WRITELOG( "CHarvesterRtpMetaDataReader::GetValue()" );
       
   204     if ( aBytes.Length() >= KIntegerBytes )
       
   205         {
       
   206         aValue = ( TUint )( aBytes[0] );
       
   207         aValue <<= 8;
       
   208         aValue |= ( TUint )( aBytes[1] );
       
   209         aValue <<= 8;
       
   210         aValue |= ( TUint )( aBytes[2] );
       
   211         aValue <<= 8;
       
   212         aValue |= ( TUint )( aBytes[3] );
       
   213         return KErrNone;
       
   214         }
       
   215 
       
   216     WRITELOG( "CHarvesterRtpMetaDataReader::GetValue() : KErrUnderFlow!" );
       
   217     return KErrUnderflow;
       
   218     }
       
   219 
       
   220 // -----------------------------------------------------------------------------
       
   221 // Get and format clip title
       
   222 // -----------------------------------------------------------------------------
       
   223 //
       
   224 void CHarvesterRtpMetaDataReader::GetProgramTitleL( TDes& aTitle )
       
   225     {
       
   226     WRITELOG( "CHarvesterRtpMetaDataReader::GetProgramTitleL()" );
       
   227     
       
   228     User::LeaveIfError( iEsgDataPoint );
       
   229     aTitle.Zero();
       
   230 
       
   231     TUint32 totalLength( 0 );
       
   232     TPtrC8 service;
       
   233     TPtrC8 program;
       
   234     
       
   235     ReadStringDataL( iEsgDataPoint, service );
       
   236     
       
   237     totalLength += service.Length();
       
   238     totalLength += KSpaceLength;
       
   239 
       
   240     // Program name
       
   241     const TInt progPos( iEsgDataPoint + KStringLengthBytes + service.Length() );
       
   242     ReadStringDataL( progPos, program );
       
   243     
       
   244     totalLength += program.Length();
       
   245 
       
   246     HBufC8* title = HBufC8::NewLC( totalLength );
       
   247     title->Des().Append( service.Ptr(), service.Length() );
       
   248     title->Des().Append( KTxtSpace );
       
   249     title->Des().Append( program.Ptr(), program.Length() ); 
       
   250     
       
   251     if ( totalLength > KMaxProgramTitle ) 
       
   252         {
       
   253         //Make title fit in max title length
       
   254         TPtrC8 titlePtr( *title );
       
   255         aTitle.Copy( titlePtr.Mid( 0 , KMaxProgramTitle ) );
       
   256         }
       
   257     else
       
   258         {
       
   259         aTitle.Copy( *title );
       
   260         }
       
   261                 
       
   262     CleanupStack::PopAndDestroy( title );
       
   263     }
       
   264