audio/ARM_CMMF_codecs/FrameTable/Src/FrameTable.cpp
changeset 34 31d6e1ae5283
parent 33 0267baa9dea9
child 36 6320e299b97a
child 38 4269ca484c7b
equal deleted inserted replaced
33:0267baa9dea9 34:31d6e1ae5283
     1 /*
       
     2 
       
     3 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     4 
       
     5 * All rights reserved.
       
     6 
       
     7 * This component and the accompanying materials are made available
       
     8 
       
     9 * under the terms of "Eclipse Public License v1.0"
       
    10 
       
    11 * which accompanies this distribution, and is available
       
    12 
       
    13 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
    14 
       
    15 *
       
    16 
       
    17 * Initial Contributors:
       
    18 
       
    19 * Nokia Corporation - initial contribution.
       
    20 
       
    21 *
       
    22 
       
    23 * Contributors:
       
    24 
       
    25 *
       
    26 
       
    27 * Description:  Class definition for the frame table functions.
       
    28 
       
    29  *
       
    30 
       
    31 */
       
    32 
       
    33 
       
    34 
       
    35 
       
    36 
       
    37 //  INCLUDES
       
    38 
       
    39 #include "FrameTable.h"
       
    40 
       
    41 #include "DebugMacros.h"
       
    42 
       
    43 #include <e32debug.h>
       
    44 
       
    45 
       
    46 
       
    47 // CONSTANTS
       
    48 
       
    49 const TInt KBuffersToKeep = 3;
       
    50 
       
    51 const TInt KLowResPeriodMs = 1000; // approximate interval for entries stored in low res table is 1 sec
       
    52 
       
    53 
       
    54 
       
    55 // ============================ MEMBER FUNCTIONS ===============================
       
    56 
       
    57 
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 
       
    61 // CFrameTable::CFrameTable
       
    62 
       
    63 // C++ default constructor can NOT contain any code, that
       
    64 
       
    65 // might leave.
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 
       
    69 //
       
    70 
       
    71 CFrameTable::CFrameTable()
       
    72 
       
    73     {
       
    74 
       
    75     }
       
    76 
       
    77 
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 
       
    81 // CFrameTable::ConstructL
       
    82 
       
    83 // Symbian 2nd phase constructor can leave.
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 
       
    87 //
       
    88 
       
    89 void CFrameTable::ConstructL()
       
    90 
       
    91     {
       
    92 
       
    93     DP0(_L("CFrameTable::ConstructL"));
       
    94 
       
    95     SetSourceReference(0,0);
       
    96 
       
    97     }
       
    98 
       
    99 
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 
       
   103 // CFrameTable::NewL
       
   104 
       
   105 // Two-phased constructor.
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 
       
   109 //
       
   110 
       
   111 EXPORT_C CFrameTable* CFrameTable::NewL()
       
   112 
       
   113     {
       
   114 
       
   115     DP0(_L("CFrameTable::NewL"));
       
   116 
       
   117 
       
   118 
       
   119     CFrameTable* self = new(ELeave) CFrameTable;
       
   120 
       
   121     CleanupStack::PushL(self);
       
   122 
       
   123     self->ConstructL();
       
   124 
       
   125     CleanupStack::Pop(self);
       
   126 
       
   127     return self;
       
   128 
       
   129     }
       
   130 
       
   131 
       
   132 
       
   133 // -----------------------------------------------------------------------------
       
   134 
       
   135 // CFrameTable::~CFrameTable
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 
       
   139 //
       
   140 
       
   141 EXPORT_C CFrameTable::~CFrameTable()
       
   142 
       
   143     {
       
   144 
       
   145     DP0(_L("CFrameTable::~CFrameTable"));
       
   146 
       
   147     iFrameTable.Close();
       
   148 
       
   149     iLowResFrameTable.Close();
       
   150 
       
   151     }
       
   152 
       
   153 
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 
       
   157 // CFrameTable::InitFrameTable
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 
       
   161 //
       
   162 
       
   163 EXPORT_C TInt CFrameTable::InitFrameTable(TInt aSampleRate, TInt aSamplesPerFrame)
       
   164 
       
   165     { // this is only intended to be used at the very beginning of play since it clears the table
       
   166 
       
   167     DP2(_L("CFrameTable::InitFrameTable aSampleRate[%d], aSamplesPerFrame[%d]"), aSampleRate, aSamplesPerFrame);
       
   168 
       
   169     TInt status = KErrNone;
       
   170 
       
   171     ResetTable();
       
   172 
       
   173     iSampleRate = aSampleRate;
       
   174 
       
   175     iSamplesPerFrame = aSamplesPerFrame;
       
   176 
       
   177 
       
   178 
       
   179     if ((iSampleRate> 0) && (iSamplesPerFrame> 0))
       
   180 
       
   181         {
       
   182 
       
   183         iMsecPerFrame = (iSamplesPerFrame*1000)/iSampleRate;
       
   184 
       
   185         iFramesPerLowResInterval = ((iSampleRate*KLowResPeriodMs/1000) / iSamplesPerFrame);
       
   186 
       
   187         iLowResIntervalMs = (iSamplesPerFrame*1000*iFramesPerLowResInterval)/iSampleRate;
       
   188 
       
   189         }
       
   190 
       
   191     else
       
   192 
       
   193         {
       
   194 
       
   195         status = KErrArgument;
       
   196 
       
   197         }
       
   198 
       
   199 
       
   200 
       
   201     return status;
       
   202 
       
   203     }
       
   204 
       
   205 
       
   206 
       
   207 //  0   1   2   3   4
       
   208 
       
   209 // -----------------------------------------------------------------------------
       
   210 
       
   211 // CFrameTable::SubmitTableEntry
       
   212 
       
   213 // -----------------------------------------------------------------------------
       
   214 
       
   215 //
       
   216 
       
   217 // The table will always have contiguous frames in it.
       
   218 
       
   219 EXPORT_C TInt CFrameTable::SubmitTableEntry(TUint aPos)
       
   220 
       
   221     {
       
   222 
       
   223     DP2(_L("CFrameTable::SubmitTableEntry aPos[%u], event pos[%u]"), aPos, iPosEventMs);
       
   224 
       
   225     TInt status = KErrNone;
       
   226 
       
   227     TBufRefPosEntry lastEntry;
       
   228 
       
   229     lastEntry.iPos = 0;
       
   230 
       
   231     TBufRefPosEntry bufRefPos;
       
   232 
       
   233     TUint frameNum;
       
   234 
       
   235 
       
   236 
       
   237     TUint pos = aPos+iOffset; // pos = absolute position (not including any header)
       
   238 
       
   239 
       
   240 
       
   241     if (aPos> 0)
       
   242 
       
   243         {
       
   244 
       
   245         iCurrentFrameCount++; // not a total frame count, but count from last reference set
       
   246 
       
   247         DP1(_L("CFrameTable::SubmitTableEntry iCurrentFrameCount[%u]"), iCurrentFrameCount);
       
   248 
       
   249         }
       
   250 
       
   251 
       
   252 
       
   253     TUint numEntries = iFrameTable.Count(); // this table will stay short - seeking backward resets it
       
   254 
       
   255 
       
   256 
       
   257     if (numEntries == 0)
       
   258 
       
   259         { // table gets reset if seeking in source
       
   260 
       
   261         bufRefPos.iPos = pos;
       
   262 
       
   263         bufRefPos.iFrameNum = iFrameNum; // first frame num is 0 so calculations for time 0 would point to frame 0
       
   264 
       
   265         status = iFrameTable.Append(bufRefPos);
       
   266 
       
   267         ASSERT(status == KErrNone);
       
   268 
       
   269         numEntries = 1;
       
   270 
       
   271         DP2(_L("CFrameTable::SubmitTableEntry init pos[%u] framenum[%u]"), pos, iFrameNum);
       
   272 
       
   273         }
       
   274 
       
   275     else
       
   276 
       
   277         {
       
   278 
       
   279         lastEntry = iFrameTable[numEntries-1];
       
   280 
       
   281 
       
   282 
       
   283         if (pos> lastEntry.iPos)
       
   284 
       
   285             {
       
   286 
       
   287             frameNum = lastEntry.iFrameNum + 1;
       
   288 
       
   289             bufRefPos.iPos = pos;
       
   290 
       
   291             bufRefPos.iFrameNum = frameNum;
       
   292 
       
   293 
       
   294 
       
   295             DP3 (_L ("CFrameTable::SubmitTableEntry, new entry iPos[%u], iFrameNum[%u], cnt[%u]"), bufRefPos.iPos, bufRefPos.iFrameNum, numEntries+1);
       
   296 
       
   297 
       
   298 
       
   299             status = iFrameTable.Append(bufRefPos);
       
   300 
       
   301             ASSERT(status == KErrNone);
       
   302 
       
   303             if (iOkToShrink)
       
   304 
       
   305                 {
       
   306 
       
   307                 DP0(_L("CFrameTable::SubmitTableEntry removing an entry "));
       
   308 
       
   309                 iFrameTable.Remove(0);
       
   310 
       
   311                 }
       
   312 
       
   313             }
       
   314 
       
   315         else
       
   316 
       
   317             {
       
   318 
       
   319             status = KErrArgument;
       
   320 
       
   321             }
       
   322 
       
   323         }
       
   324 
       
   325 
       
   326 
       
   327     if (status == KErrNone)
       
   328 
       
   329         {
       
   330 
       
   331         SubmitLowResTableEntry(bufRefPos); // do this before events are detected below
       
   332 
       
   333 
       
   334 
       
   335         // total average bitrate - not instantaneous bitrate - used for duration calculation
       
   336 
       
   337         if (pos> iLastBytePos)
       
   338 
       
   339             { // don't recalculate if we rewind
       
   340 
       
   341             iLastBytePos = pos; // pos is absolute position - relative to the start of actual data content (not file start - no metadata) as set by the user. User maintains metadata offsets.
       
   342 
       
   343             TUint totalTimeMs = bufRefPos.iFrameNum*iMsecPerFrame; // total time in the table
       
   344 
       
   345                 DP1(_L("CFrameTable::SubmitTableEntry totalTimeMs[%u]"), totalTimeMs);
       
   346 
       
   347             if (totalTimeMs> 0)
       
   348 
       
   349                 {
       
   350 
       
   351                 // cast calculation to TIn64 or it could lose precision
       
   352 
       
   353                 TUint64 p = pos;
       
   354 
       
   355                 p = p*8*1000;
       
   356 
       
   357                 TUint64 t = totalTimeMs;
       
   358 
       
   359                 iAvgBitrate = p/t;
       
   360 
       
   361                 }
       
   362 
       
   363             }
       
   364 
       
   365         }
       
   366 
       
   367 
       
   368 
       
   369     // need to convert current position to time
       
   370 
       
   371     TInt currentTimeMs = iCurrentFrameCount*iMsecPerFrame + iTimeRefMs; // current time position being played
       
   372 
       
   373     DP3(_L("CFrameTable::SubmitTableEntry current calculated time ms[%u] iCurrentFrameCount[%u] timeref[%u]"), currentTimeMs, iCurrentFrameCount, iTimeRefMs);
       
   374 
       
   375     if (iPosEventMs> 0)
       
   376 
       
   377         { // used for seeking
       
   378 
       
   379         if (currentTimeMs >= iPosEventMs)
       
   380 
       
   381             {
       
   382 
       
   383             iPosEventMs = 0;
       
   384 
       
   385             DP0(_L("CFrameTable::SubmitTableEntry handle event pos reached"));
       
   386 
       
   387             iEventPos = pos;
       
   388 
       
   389             iObserver->HandleFrameTableEvent(EPosReached);
       
   390 
       
   391             }
       
   392 
       
   393         }
       
   394 
       
   395 
       
   396 
       
   397     if (iPlayWindowEndPosEventMs> 0)
       
   398 
       
   399         {
       
   400 
       
   401         if (currentTimeMs >= iPlayWindowEndPosEventMs)
       
   402 
       
   403             {
       
   404 
       
   405             iPlayWindowEndPosEventMs = 0;
       
   406 
       
   407             DP0(_L("CFrameTable::SubmitTableEntry handle event play window end pos reached"));
       
   408 
       
   409             iObserver->HandleFrameTableEvent(EPlayWindowEndPosReached);
       
   410 
       
   411             }
       
   412 
       
   413         }
       
   414 
       
   415 
       
   416 
       
   417     if (iIntervalEvent> 0)
       
   418 
       
   419         {
       
   420 
       
   421         if (iIntervalRef == 0)
       
   422 
       
   423             {
       
   424 
       
   425             iIntervalRef = currentTimeMs;
       
   426 
       
   427             }
       
   428 
       
   429 
       
   430 
       
   431         if ((currentTimeMs - iIntervalRef) >= iIntervalEvent)
       
   432 
       
   433             {
       
   434 
       
   435             iIntervalRef = currentTimeMs;
       
   436 
       
   437             iObserver->HandleFrameTableEvent(EDecodeInterval);
       
   438 
       
   439             }
       
   440 
       
   441         }
       
   442 
       
   443 
       
   444 
       
   445     DP1 (_L ("CFrameTable::SubmitTableEntry, avgBitRate[%u]"), iAvgBitrate);
       
   446 
       
   447     return status;
       
   448 
       
   449     }
       
   450 
       
   451 
       
   452 
       
   453 TInt CFrameTable::SubmitLowResTableEntry(TBufRefPosEntry& aEntry)
       
   454 
       
   455     {
       
   456 
       
   457     TInt status = KErrNone;
       
   458 
       
   459     TBufRefPosEntry lastEntry;
       
   460 
       
   461 
       
   462 
       
   463     TUint numEntries = iLowResFrameTable.Count();
       
   464 
       
   465     if (numEntries == 0)
       
   466 
       
   467         {
       
   468 
       
   469         status = iLowResFrameTable.Append(aEntry);
       
   470 
       
   471         ASSERT(status == KErrNone);
       
   472 
       
   473         return status;
       
   474 
       
   475         }
       
   476 
       
   477 
       
   478 
       
   479     lastEntry = iLowResFrameTable[numEntries-1];
       
   480 
       
   481 
       
   482 
       
   483     ASSERT(aEntry.iFrameNum <= lastEntry.iFrameNum + iFramesPerLowResInterval);
       
   484 
       
   485     // note that 0 position table entries can be submitted to the table before it is initialized.
       
   486 
       
   487     // If this happens, iFramesPerLowResInterval would still be 0 and the same entry might be appended again
       
   488 
       
   489     // so we have a check to make sure that doesn't happen.
       
   490 
       
   491     if ((aEntry.iFrameNum == lastEntry.iFrameNum + iFramesPerLowResInterval) && 
       
   492 
       
   493         (iFramesPerLowResInterval != 0))
       
   494 
       
   495         {
       
   496 
       
   497         DP3 (_L ("CFrameTable::SubmitLowResTableEntry, new entry aEntry.iFrameNum[%u], lastEntry.iFrameNum[%u], iFramesPerLowResInterval[%u]"), aEntry.iFrameNum, lastEntry.iFrameNum, iFramesPerLowResInterval);
       
   498 
       
   499         DP3 (_L ("CFrameTable::SubmitLowResTableEntry, new entry iPos[%u], iFrameNum[%u], cnt[%u]"), aEntry.iPos, aEntry.iFrameNum, numEntries+1);
       
   500 
       
   501 
       
   502 
       
   503         status = iLowResFrameTable.Append(aEntry);
       
   504 
       
   505         ASSERT(status == KErrNone);
       
   506 
       
   507         }
       
   508 
       
   509     else
       
   510 
       
   511         {
       
   512 
       
   513         status = KErrArgument;
       
   514 
       
   515         }
       
   516 
       
   517 
       
   518 
       
   519     return status;
       
   520 
       
   521     }
       
   522 
       
   523 
       
   524 
       
   525 // -----------------------------------------------------------------------------
       
   526 
       
   527 // CFrameTable::FindFramePosFromTime
       
   528 
       
   529 // -----------------------------------------------------------------------------
       
   530 
       
   531 //
       
   532 
       
   533 /*
       
   534 
       
   535  Looks in the table for the frame position associated with the given time.
       
   536 
       
   537  It will return the position and also the time for that frame.
       
   538 
       
   539  If not found, an error will be returned, and the time and position will be
       
   540 
       
   541  the closest available in the table.
       
   542 
       
   543  */
       
   544 
       
   545 EXPORT_C TInt CFrameTable::FindFramePosFromTime(TUint& aTimeMs, TUint& aPos)
       
   546 
       
   547     {
       
   548 
       
   549     DP2(_L("CFrameTable::FindFramePosFromTime time[%u], pos[%u]"), aTimeMs, aPos);
       
   550 
       
   551     TInt stat = KErrNone;
       
   552 
       
   553     // TUint in msec can represent 1193 hours
       
   554 
       
   555     TInt tableIndex;
       
   556 
       
   557 
       
   558 
       
   559     // special case for time = 0
       
   560 
       
   561     if (aTimeMs == 0)
       
   562 
       
   563         {
       
   564 
       
   565         aPos = 0;
       
   566 
       
   567         DP0(_L("CFrameTable::FindFramePosFromTime time=0 pos=0"));
       
   568 
       
   569         return KErrNone;
       
   570 
       
   571         }
       
   572 
       
   573 
       
   574 
       
   575     TUint countlr = iLowResFrameTable.Count();
       
   576 
       
   577     if ((countlr == 0) || (iMsecPerFrame == 0))
       
   578 
       
   579         {
       
   580 
       
   581         DP2(_L("CFrameTable::FindFramePosFromTime not ready countlr[%u] iMsecPerFrame[%u]"), countlr, iMsecPerFrame);
       
   582 
       
   583         return KErrNotReady;
       
   584 
       
   585         }
       
   586 
       
   587     TUint frame = aTimeMs/iMsecPerFrame; // calc frame number
       
   588 
       
   589     DP1(_L("CFrameTable::FindFramePosFromTime looking for frame[%u]"), frame);
       
   590 
       
   591 
       
   592 
       
   593     // check hi-res table first
       
   594 
       
   595     TUint count = iFrameTable.Count();
       
   596 
       
   597     if (count == 0)
       
   598 
       
   599         {
       
   600 
       
   601         stat = KErrNotFound; // use low-res table
       
   602 
       
   603         }
       
   604 
       
   605     else
       
   606 
       
   607         {
       
   608 
       
   609         TUint frame0 = iFrameTable[0].iFrameNum; // first frame available (table can shrink)
       
   610 
       
   611         DP1(_L("CFrameTable::FindFramePosFromTime frame0[%u]"), frame0);
       
   612 
       
   613         if (frame >= frame0) // frame might be in table
       
   614 
       
   615 
       
   616 
       
   617             {
       
   618 
       
   619             tableIndex = frame - frame0; // calc index into table
       
   620 
       
   621             DP1(_L("CFrameTable::FindFramePosFromTime tableIndex[%u]"), tableIndex);
       
   622 
       
   623             if (tableIndex >= count)
       
   624 
       
   625                 {
       
   626 
       
   627                 stat = KErrNotFound; // use low-res table
       
   628 
       
   629                 DP0(_L("CFrameTable::FindFramePosFromTime not found in hi-res"));
       
   630 
       
   631                 }
       
   632 
       
   633             else
       
   634 
       
   635                 {
       
   636 
       
   637                 aPos = iFrameTable[tableIndex].iPos;
       
   638 
       
   639                 iFrameNum = iFrameTable[tableIndex].iFrameNum; // iFrameNum provides frame num after hi-res table is reset
       
   640 
       
   641                 aTimeMs = iFrameNum * iMsecPerFrame;
       
   642 
       
   643                 DP4(_L("CFrameTable::FindFramePosFromTime aTimeMs[%u] iFrameNum[%u] iSamplesPerFrame[%u] iSampleRate[%u]"),
       
   644 
       
   645                         aTimeMs,iFrameNum,iSamplesPerFrame,iSampleRate);
       
   646 
       
   647                 }
       
   648 
       
   649             }
       
   650 
       
   651         else
       
   652 
       
   653             {
       
   654 
       
   655             stat = KErrNotFound; // use low-res table
       
   656 
       
   657             }
       
   658 
       
   659         }
       
   660 
       
   661     if (stat == KErrNotFound)
       
   662 
       
   663         { // check low-res table
       
   664 
       
   665         DP0(_L("CFrameTable::FindFramePosFromTime looking in low-res table"));
       
   666 
       
   667         if (iFramesPerLowResInterval> 0)
       
   668 
       
   669     		{  // first frame is always 0 in low res table - don't need to subtract frame[0]
       
   670 
       
   671             tableIndex = frame/iFramesPerLowResInterval; // calc index into table
       
   672 
       
   673             DP3(_L("CFrameTable::FindFramePosFromTime tableIndex[%d] frame[%u] iFramesPerLowResInterval[%u]"),
       
   674 
       
   675                     tableIndex,frame,iFramesPerLowResInterval);
       
   676 
       
   677             if (tableIndex < countlr)
       
   678 
       
   679                 {
       
   680 
       
   681                 aPos = iLowResFrameTable[tableIndex].iPos;
       
   682 
       
   683                 iFrameNum = iLowResFrameTable[tableIndex].iFrameNum; // iFrameNum provides frame num after hi-res table is reset
       
   684 
       
   685                 aTimeMs = iFrameNum * iMsecPerFrame;
       
   686 
       
   687                 stat = KErrNone;
       
   688 
       
   689                 }
       
   690 
       
   691             }
       
   692 
       
   693         }
       
   694 
       
   695 
       
   696 
       
   697     if (stat == KErrNotFound)
       
   698 
       
   699         { // use last in low-res table
       
   700 
       
   701         aPos = iLowResFrameTable[countlr-1].iPos;
       
   702 
       
   703         iFrameNum = iLowResFrameTable[countlr-1].iFrameNum; // iFrameNum provides frame num after hi-res table is reset
       
   704 
       
   705         aTimeMs = iFrameNum * iMsecPerFrame;
       
   706 
       
   707         }
       
   708 
       
   709     DP4(_L("CFrameTable::FindFramePosFromTime time[%u], pos[%u], stat[%d] iFrameNum sync[%u]"), aTimeMs, aPos, stat, iFrameNum);
       
   710 
       
   711     return stat;
       
   712 
       
   713     }
       
   714 
       
   715 
       
   716 
       
   717 EXPORT_C TInt CFrameTable::FindFrameTimeFromPos(TUint& aTimeMs, TUint& aPos)
       
   718 
       
   719     {
       
   720 
       
   721     DP1(_L("CFrameTable::FindFrameTimeFromPos pos[%u]"), aPos);
       
   722 
       
   723     TInt stat = KErrNotFound;
       
   724 
       
   725     //	TBufRefPosEntry temp; // used for array search
       
   726 
       
   727     //	temp.iFrameNum = 0;
       
   728 
       
   729     //	temp.iPos = aPos;
       
   730 
       
   731 
       
   732 
       
   733     //	stat = iFrameTable.SpecificFindInUnsignedKeyOrder(temp, EArrayFindMode_First);
       
   734 
       
   735     TUint count = iFrameTable.Count();
       
   736 
       
   737     for (TUint i=0; i<count; i++)
       
   738 
       
   739         {
       
   740 
       
   741         if (iFrameTable[i].iPos >= aPos)
       
   742 
       
   743             {
       
   744 
       
   745             stat = i;
       
   746 
       
   747             DP4(_L("CFrameTable::FindFrameTimeFromPos hi-res first[%u] last[%u] count[%u] stat[%d]"),
       
   748 
       
   749                     iFrameTable[0].iPos, iFrameTable[count-1].iPos, count, stat);
       
   750 
       
   751             break;
       
   752 
       
   753             }
       
   754 
       
   755         }
       
   756 
       
   757 #ifdef _DEBUG 
       
   758 
       
   759     if(count == 0)
       
   760 
       
   761         {
       
   762 
       
   763         DP0(_L("CFrameTable::FindFrameTimeFromPos hi-res Frame Table: Empty"));
       
   764 
       
   765         }
       
   766 
       
   767 #endif
       
   768 
       
   769 
       
   770 
       
   771     if (stat == KErrNotFound)
       
   772 
       
   773         {
       
   774 
       
   775         //		stat = iLowResFrameTable.SpecificFindInUnsignedKeyOrder(temp, EArrayFindMode_First);
       
   776 
       
   777         count = iLowResFrameTable.Count();
       
   778 
       
   779         for (TUint i=0; i<count; i++)
       
   780 
       
   781             {
       
   782 
       
   783             if (iLowResFrameTable[i].iPos >= aPos)
       
   784 
       
   785                 {
       
   786 
       
   787                 stat = i;
       
   788 
       
   789                 DP4(_L("CFrameTable::FindFrameTimeFromPos lo-res first[%u] last[%u] count[%u] stat[%d]"),
       
   790 
       
   791                         iLowResFrameTable[0].iPos, iLowResFrameTable[count-1].iPos, count, stat);
       
   792 
       
   793                 break;
       
   794 
       
   795                 }
       
   796 
       
   797             }
       
   798 
       
   799 #ifdef _DEBUG 
       
   800 
       
   801         if(count == 0)
       
   802 
       
   803             {
       
   804 
       
   805             DP0(_L("CFrameTable::FindFrameTimeFromPos lo-res Frame Table: Empty"));
       
   806 
       
   807             }
       
   808 
       
   809 #endif		
       
   810 
       
   811 
       
   812 
       
   813         if (stat != KErrNotFound)
       
   814 
       
   815             {
       
   816 
       
   817             aPos = iLowResFrameTable[stat].iPos;
       
   818 
       
   819             aTimeMs = iLowResFrameTable[stat].iFrameNum * iMsecPerFrame;
       
   820 
       
   821             iFrameNum = iLowResFrameTable[stat].iFrameNum; // iFrameNum provides frame num after hi-res table is reset
       
   822 
       
   823             DP3(_L("CFrameTable::FindFrameTimeFromPos lo-res iFrameNum[%u] indx[%d] iFrameNum sync[%u]"), iLowResFrameTable[stat].iFrameNum, stat, iFrameNum);
       
   824 
       
   825             }
       
   826 
       
   827         }
       
   828 
       
   829     else
       
   830 
       
   831         {
       
   832 
       
   833         aPos = iFrameTable[stat].iPos;
       
   834 
       
   835         aTimeMs = iFrameTable[stat].iFrameNum * iMsecPerFrame;
       
   836 
       
   837         iFrameNum = iFrameTable[stat].iFrameNum; // iFrameNum provides frame num after hi-res table is reset
       
   838 
       
   839         DP3(_L("CFrameTable::FindFrameTimeFromPos hi-res iFrameNum[%u] indx[%d] iFrameNum sync[%u]"), iFrameTable[stat].iFrameNum, stat, iFrameNum);
       
   840 
       
   841         }
       
   842 
       
   843 
       
   844 
       
   845     DP3(_L("CFrameTable::FindFrameTimeFromPos time[%u] pos[%u] indxstat[%d]"), aTimeMs, aPos, stat);
       
   846 
       
   847     if (stat> 0)
       
   848 
       
   849         {
       
   850 
       
   851         stat = KErrNone;
       
   852 
       
   853         }
       
   854 
       
   855     return stat;
       
   856 
       
   857     }
       
   858 
       
   859 
       
   860 
       
   861 // -----------------------------------------------------------------------------
       
   862 
       
   863 // CFrameTable::LastFramePos
       
   864 
       
   865 // -----------------------------------------------------------------------------
       
   866 
       
   867 //
       
   868 
       
   869 EXPORT_C TInt CFrameTable::LastFramePos(TUint& aPos)
       
   870 
       
   871     {
       
   872 
       
   873     TInt stat = KErrNotFound;
       
   874 
       
   875     TInt stat1 = KErrNotFound;
       
   876 
       
   877     TInt stat2 = KErrNotFound;
       
   878 
       
   879     TUint count;
       
   880 
       
   881     TInt pos1 = 0;
       
   882 
       
   883     TInt pos2 = 0;
       
   884 
       
   885 
       
   886 
       
   887     count = iFrameTable.Count();
       
   888 
       
   889     DP1(_L("CFrameTable::LastFramePos count[%u]"), count);
       
   890 
       
   891     if (count> 0)
       
   892 
       
   893         {
       
   894 
       
   895         pos1 = iFrameTable[count-1].iPos;
       
   896 
       
   897         stat1 = KErrNone;
       
   898 
       
   899         DP1(_L("CFrameTable::LastFramePos last pos in hi-res[%d]"), pos1);
       
   900 
       
   901         }
       
   902 
       
   903 
       
   904 
       
   905     count = iLowResFrameTable.Count();
       
   906 
       
   907     DP1(_L("CFrameTable::LastFramePos lr count[%u]"), count);
       
   908 
       
   909     if (count> 0)
       
   910 
       
   911         {
       
   912 
       
   913         pos2 = iLowResFrameTable[count-1].iPos;
       
   914 
       
   915         stat2 = KErrNone;
       
   916 
       
   917         DP1(_L("CFrameTable::LastFramePos last pos in low-res[%d]"), pos2);
       
   918 
       
   919         }
       
   920 
       
   921 
       
   922 
       
   923     if ((stat1 == KErrNone) && (stat2 == KErrNone))
       
   924 
       
   925         {
       
   926 
       
   927         aPos = Max(pos1, pos2);
       
   928 
       
   929         stat = KErrNone;
       
   930 
       
   931         }
       
   932 
       
   933     else if (stat1 == KErrNone)
       
   934 
       
   935         {
       
   936 
       
   937         aPos = pos1;
       
   938 
       
   939         stat = KErrNone;
       
   940 
       
   941         }
       
   942 
       
   943     else if (stat2 == KErrNone)
       
   944 
       
   945         {
       
   946 
       
   947         aPos = pos2;
       
   948 
       
   949         stat = KErrNone;
       
   950 
       
   951         }
       
   952 
       
   953     DP1(_L("CFrameTable::LastFramePos aPos[%d]"), aPos);
       
   954 
       
   955 
       
   956 
       
   957     return stat;
       
   958 
       
   959     }
       
   960 
       
   961 
       
   962 
       
   963 // -----------------------------------------------------------------------------
       
   964 
       
   965 // CFrameTable::LastFrameTime
       
   966 
       
   967 // -----------------------------------------------------------------------------
       
   968 
       
   969 //
       
   970 
       
   971 EXPORT_C TInt CFrameTable::LastFrameTime(TUint& aTimeMs)
       
   972 
       
   973     {
       
   974 
       
   975     DP0(_L("CFrameTable::LastFrameTime"));
       
   976 
       
   977     TInt stat = KErrNotFound;
       
   978 
       
   979     TInt stat1 = KErrNotFound;
       
   980 
       
   981     TInt stat2 = KErrNotFound;
       
   982 
       
   983     TUint count;
       
   984 
       
   985     TUint frameNum = 0;
       
   986 
       
   987     TInt frameNum1 = 0;
       
   988 
       
   989     TInt frameNum2 = 0;
       
   990 
       
   991 
       
   992 
       
   993     count = iFrameTable.Count();
       
   994 
       
   995     if (count> 0)
       
   996 
       
   997         {
       
   998 
       
   999         frameNum1 = iFrameTable[count-1].iFrameNum;
       
  1000 
       
  1001         stat1 = KErrNone;
       
  1002 
       
  1003         }
       
  1004 
       
  1005 
       
  1006 
       
  1007     count = iLowResFrameTable.Count();
       
  1008 
       
  1009     if (count> 0)
       
  1010 
       
  1011         {
       
  1012 
       
  1013         frameNum2 = iLowResFrameTable[count-1].iFrameNum;
       
  1014 
       
  1015         stat2 = KErrNone;
       
  1016 
       
  1017         }
       
  1018 
       
  1019 
       
  1020 
       
  1021     if ((stat1 == KErrNone) && (stat2 == KErrNone))
       
  1022 
       
  1023         {
       
  1024 
       
  1025         frameNum = Max(frameNum1, frameNum2);
       
  1026 
       
  1027         stat = KErrNone;
       
  1028 
       
  1029         }
       
  1030 
       
  1031     else if (stat1 == KErrNone)
       
  1032 
       
  1033         {
       
  1034 
       
  1035         frameNum = frameNum1;
       
  1036 
       
  1037         stat = KErrNone;
       
  1038 
       
  1039         }
       
  1040 
       
  1041     else if (stat2 == KErrNone)
       
  1042 
       
  1043         {
       
  1044 
       
  1045         frameNum = frameNum2;
       
  1046 
       
  1047         stat = KErrNone;
       
  1048 
       
  1049         }
       
  1050 
       
  1051 
       
  1052 
       
  1053     aTimeMs = frameNum * iMsecPerFrame;
       
  1054 
       
  1055     DP2(_L("CFrameTable::LastFrameTime time[%u] frame[%u]"),aTimeMs,frameNum);
       
  1056 
       
  1057 
       
  1058 
       
  1059     return stat;
       
  1060 
       
  1061     }
       
  1062 
       
  1063 
       
  1064 
       
  1065 // -----------------------------------------------------------------------------
       
  1066 
       
  1067 // CFrameTable::ResetTable
       
  1068 
       
  1069 // -----------------------------------------------------------------------------
       
  1070 
       
  1071 //	
       
  1072 
       
  1073 EXPORT_C void CFrameTable::ResetTable()
       
  1074 
       
  1075     {
       
  1076 
       
  1077     DP0(_L("CFrameTable::ResetTable"));
       
  1078 
       
  1079 
       
  1080 
       
  1081     iFrameTable.Reset();
       
  1082 
       
  1083     iBufCnt = 0;
       
  1084 
       
  1085     iOkToShrink = EFalse;
       
  1086 
       
  1087     }
       
  1088 
       
  1089 
       
  1090 
       
  1091 // -----------------------------------------------------------------------------
       
  1092 
       
  1093 // CFrameTable::ShrinkTable
       
  1094 
       
  1095 // -----------------------------------------------------------------------------
       
  1096 
       
  1097 //	
       
  1098 
       
  1099 EXPORT_C void CFrameTable::ShrinkTable()
       
  1100 
       
  1101     { // gets called from controller decoder when switching to next buffer
       
  1102 
       
  1103     DP0(_L("CFrameTable::ShrinkTable"));
       
  1104 
       
  1105     if (iBufCnt < KBuffersToKeep)
       
  1106 
       
  1107         {
       
  1108 
       
  1109         iBufCnt++;
       
  1110 
       
  1111         }
       
  1112 
       
  1113     else
       
  1114 
       
  1115         {
       
  1116 
       
  1117         iOkToShrink = ETrue;
       
  1118 
       
  1119         DP0(_L("CFrameTable::ShrinkTable ok to shrink"));
       
  1120 
       
  1121         }
       
  1122 
       
  1123     }
       
  1124 
       
  1125 
       
  1126 
       
  1127 EXPORT_C TInt CFrameTable::SetSourceReference(TUint aTimeMs, TUint aPos)
       
  1128 
       
  1129     { // if position is unknown it should always be set to 0 as the reference offset and time will be used instead
       
  1130 
       
  1131     // This is used to set the offset which is added to future frame positions submitted
       
  1132 
       
  1133     // This frame table can get reset when seeking and needs to know where it is in the source
       
  1134 
       
  1135     DP2(_L("CFrameTable::SetOffset, aTimeMs[%u], aPos[%u]"), aTimeMs, aPos);
       
  1136 
       
  1137     TInt stat = KErrNone;
       
  1138 
       
  1139     iTimeRefMs = aTimeMs;
       
  1140 
       
  1141     iCurrentFrameCount = 0;
       
  1142 
       
  1143     iIntervalRef = 0;
       
  1144 
       
  1145     iOffset = aPos;
       
  1146 
       
  1147     if (aTimeMs == 0)
       
  1148 
       
  1149         {
       
  1150 
       
  1151         iFrameNum = 0;
       
  1152 
       
  1153         }
       
  1154 
       
  1155     if (iFrameTable.Count() == 0)
       
  1156 
       
  1157         { // this is to make sure the table has at least one entry in case playback looks for a position in the buffers after seeking
       
  1158 
       
  1159         SubmitTableEntry(0);
       
  1160 
       
  1161         //		iCurrentFrameCount--; // since this is not a decoded frame
       
  1162 
       
  1163         }
       
  1164 
       
  1165     return stat;
       
  1166 
       
  1167     }
       
  1168 
       
  1169 
       
  1170 
       
  1171 // -----------------------------------------------------------------------------
       
  1172 
       
  1173 // CFrameTable::RegisterForEvent
       
  1174 
       
  1175 // -----------------------------------------------------------------------------
       
  1176 
       
  1177 //
       
  1178 
       
  1179 EXPORT_C TInt CFrameTable::RegisterForEvent(TFrameTableEvent aEvent,
       
  1180 
       
  1181         MFrameTableEventObserver* aObserver,
       
  1182 
       
  1183         TUint aParam)
       
  1184 
       
  1185     {
       
  1186 
       
  1187     DP2(_L("CFrameTable::RegisterForEvent event[%d] param[%u]"), aEvent, aParam);
       
  1188 
       
  1189 
       
  1190 
       
  1191     TInt status = KErrNone;
       
  1192 
       
  1193     iObserver = aObserver;
       
  1194 
       
  1195 
       
  1196 
       
  1197     switch (aEvent)
       
  1198 
       
  1199         {
       
  1200 
       
  1201         case EPosReached:
       
  1202 
       
  1203         iPosEventMs = aParam;
       
  1204 
       
  1205         break;
       
  1206 
       
  1207 
       
  1208 
       
  1209         case EPlayWindowEndPosReached:
       
  1210 
       
  1211         iPlayWindowEndPosEventMs = aParam;
       
  1212 
       
  1213         break;
       
  1214 
       
  1215 
       
  1216 
       
  1217         case EDecodeInterval:
       
  1218 
       
  1219 
       
  1220 
       
  1221         if (aParam> 0) // msec
       
  1222 
       
  1223 
       
  1224 
       
  1225             {
       
  1226 
       
  1227             iIntervalRef = 0;
       
  1228 
       
  1229             iIntervalEvent = aParam;
       
  1230 
       
  1231             }
       
  1232 
       
  1233         else
       
  1234 
       
  1235         return KErrArgument;
       
  1236 
       
  1237 
       
  1238 
       
  1239         break;
       
  1240 
       
  1241 
       
  1242 
       
  1243         default:
       
  1244 
       
  1245         status = KErrUnknown;
       
  1246 
       
  1247         break;
       
  1248 
       
  1249         }
       
  1250 
       
  1251 
       
  1252 
       
  1253     return status;
       
  1254 
       
  1255     }
       
  1256 
       
  1257 
       
  1258 
       
  1259 // -----------------------------------------------------------------------------
       
  1260 
       
  1261 // CFrameTable::UnRegisterForEvent
       
  1262 
       
  1263 // -----------------------------------------------------------------------------
       
  1264 
       
  1265 //
       
  1266 
       
  1267 EXPORT_C TInt CFrameTable::UnRegisterForEvent(TFrameTableEvent aEvent, MFrameTableEventObserver* /*aObserver*/)
       
  1268 
       
  1269     {
       
  1270 
       
  1271     DP1(_L("CFrameTable::UnRegisterForEvent event[%d]"), aEvent);
       
  1272 
       
  1273 
       
  1274 
       
  1275     TInt status = KErrNone;
       
  1276 
       
  1277 
       
  1278 
       
  1279     switch (aEvent)
       
  1280 
       
  1281         {
       
  1282 
       
  1283         case EPosReached:
       
  1284 
       
  1285         iPosEventMs = 0;
       
  1286 
       
  1287         break;
       
  1288 
       
  1289 
       
  1290 
       
  1291         case EPlayWindowEndPosReached:
       
  1292 
       
  1293         iPlayWindowEndPosEventMs = 0;
       
  1294 
       
  1295         break;
       
  1296 
       
  1297 
       
  1298 
       
  1299         case EDecodeInterval:
       
  1300 
       
  1301         iIntervalEvent = 0;
       
  1302 
       
  1303         break;
       
  1304 
       
  1305 
       
  1306 
       
  1307         default:
       
  1308 
       
  1309         status = KErrUnknown;
       
  1310 
       
  1311         break;
       
  1312 
       
  1313         }
       
  1314 
       
  1315 
       
  1316 
       
  1317     return status;
       
  1318 
       
  1319     }
       
  1320 
       
  1321 
       
  1322 
       
  1323 // -----------------------------------------------------------------------------
       
  1324 
       
  1325 // CFrameTable::Bitrate
       
  1326 
       
  1327 // -----------------------------------------------------------------------------
       
  1328 
       
  1329 //	
       
  1330 
       
  1331 EXPORT_C TInt CFrameTable::Bitrate()
       
  1332 
       
  1333     {
       
  1334 
       
  1335     return iAvgBitrate;
       
  1336 
       
  1337     }
       
  1338 
       
  1339 
       
  1340 
       
  1341 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
  1342 
       
  1343 
       
  1344 
       
  1345 // -----------------------------------------------------------------------------
       
  1346 
       
  1347 // CFrameTable::CalcFrameFromTimeMs
       
  1348 
       
  1349 // -----------------------------------------------------------------------------
       
  1350 
       
  1351 //
       
  1352 
       
  1353 TUint CFrameTable::CalcFrameFromTimeMs(TUint aTimeMs)
       
  1354 
       
  1355     { // TUint in msec can represent 1193 hours
       
  1356 
       
  1357     TUint frame = 0;
       
  1358 
       
  1359 
       
  1360 
       
  1361     if (iMsecPerFrame > 0)
       
  1362 
       
  1363         {
       
  1364 
       
  1365         frame = aTimeMs/iMsecPerFrame;
       
  1366 
       
  1367         }
       
  1368 
       
  1369 
       
  1370 
       
  1371     return frame;
       
  1372 
       
  1373     }
       
  1374 
       
  1375 
       
  1376 
       
  1377 EXPORT_C TInt CFrameTable::IsSeeking(TBool& aIsSeeking)
       
  1378 
       
  1379     {
       
  1380 
       
  1381     aIsSeeking = (iPosEventMs> 0);
       
  1382 
       
  1383     return KErrNone;
       
  1384 
       
  1385     }
       
  1386 
       
  1387 
       
  1388 
       
  1389 EXPORT_C TInt CFrameTable::GetLastPosEvent(TUint& aPos)
       
  1390 
       
  1391     {
       
  1392 
       
  1393     aPos = iEventPos;
       
  1394 
       
  1395     return KErrNone;
       
  1396 
       
  1397     }
       
  1398 
       
  1399 
       
  1400 
       
  1401 // End of File
       
  1402 
       
  1403 
       
  1404