khronosfws/openmax_al/src/mmf_adaptation/cmmfbackendengine.cpp
changeset 21 2ed61feeead6
parent 20 b67dd1fc57c5
child 25 6f7ceef7b1d1
equal deleted inserted replaced
20:b67dd1fc57c5 21:2ed61feeead6
   118     if (func == ERecord)
   118     if (func == ERecord)
   119         {
   119         {
   120         if (iRecordState == ERecorderNotReady)
   120         if (iRecordState == ERecorderNotReady)
   121             {
   121             {
   122             iFileFormat = format;
   122             iFileFormat = format;
   123             iAPIBeingUsed = DetermineAPIToUse(uri, EPlay);
   123             iAPIBeingUsed = DetermineAPIToUse(uri, ERecord);
   124             err = XA_RESULT_INTERNAL_ERROR;
   124             err = XA_RESULT_INTERNAL_ERROR;
   125             if (iAPIBeingUsed == EAudioRecorderUtility)
   125             if (iAPIBeingUsed == EAudioRecorderUtility)
   126                 {
   126                 {
   127                 /* Initialize URI as needed by MMF utilities */
   127                 /* Initialize URI as needed by MMF utilities */
   128                 err = InitializeURIForMMFUtil(uri);
   128                 err = InitializeURIForMMFUtil(uri);
   129                 RET_IF_ERR(err, XA_RESULT_INTERNAL_ERROR);
   129                 RET_IF_ERR(err, XA_RESULT_INTERNAL_ERROR);
   130                 /* Initalize Recorder related objects */
   130                 /* Initalize Recorder related objects */
   131                 TRAP(err, InitAudioRecorderUtilityL());
   131                 TRAP(err, InitAudioRecorderUtilityL());
   132                 RET_IF_ERR(err, XA_RESULT_INTERNAL_ERROR);
   132                 RET_IF_ERR(err, XA_RESULT_INTERNAL_ERROR);
   133     
   133     
   134                 TRAP(err, iAudioRecorder->OpenFileL(iFileName));
   134                 TRAP(err, iAudioRecorder->OpenFileL(iUriPtr));
   135                 RET_IF_ERR(err, XA_RESULT_INTERNAL_ERROR);
   135                 RET_IF_ERR(err, XA_RESULT_INTERNAL_ERROR);
   136                 /* Wait until we receive moscostatechanged callback */
   136                 /* Wait until we receive moscostatechanged callback */
   137                 if(!iActiveSchedulerWait->IsStarted())
   137                 if(!iActiveSchedulerWait->IsStarted())
   138                     {
   138                     {
   139                     iActiveSchedulerWait->Start();
   139                     iActiveSchedulerWait->Start();
   181                 RET_IF_ERR(err, XA_RESULT_INTERNAL_ERROR);
   181                 RET_IF_ERR(err, XA_RESULT_INTERNAL_ERROR);
   182                 /* Initalize Player related objects */
   182                 /* Initalize Player related objects */
   183                 TRAP(err, InitVideoPlayerUtilityL());
   183                 TRAP(err, InitVideoPlayerUtilityL());
   184                 RET_IF_ERR(err, XA_RESULT_INTERNAL_ERROR);
   184                 RET_IF_ERR(err, XA_RESULT_INTERNAL_ERROR);
   185 
   185 
   186                 /* Open file */
   186                 if(iUriType == ELocal)
   187                 TAG_TIME_PROFILING_BEGIN;
   187                     {
   188                 TRAP(err, iVideoPlayer->OpenFileL(iUriPtr));
   188                     /* Open file */
   189                 RET_IF_ERR(err, XA_RESULT_INTERNAL_ERROR);
   189                     TAG_TIME_PROFILING_BEGIN;
   190                 TAG_TIME_PROFILING_END;
   190                     TRAP(err, iVideoPlayer->OpenFileL(iUriPtr));
   191                 PRINT_TO_CONSOLE_TIME_DIFF;
   191                     RET_IF_ERR(err, XA_RESULT_INTERNAL_ERROR);
   192 
   192                     TAG_TIME_PROFILING_END;
       
   193                     PRINT_TO_CONSOLE_TIME_DIFF;
       
   194                     }
       
   195                 else
       
   196                     {
       
   197                     /* Open URL */
       
   198                     TAG_TIME_PROFILING_BEGIN;
       
   199                     TRAP(err, iVideoPlayer->OpenUrlL(iUriPtr));
       
   200                     RET_IF_ERR(err, XA_RESULT_INTERNAL_ERROR);
       
   201                     TAG_TIME_PROFILING_END;
       
   202                     PRINT_TO_CONSOLE_TIME_DIFF;
       
   203                     }
   193                 /* Wait until we receive  MvpuoOpenComplete */
   204                 /* Wait until we receive  MvpuoOpenComplete */
   194                 PRINT_TO_CONSOLE_HOME_TIME;
   205                 PRINT_TO_CONSOLE_HOME_TIME;
   195                 if (!iActiveSchedulerWait->IsStarted())
   206                 if (!iActiveSchedulerWait->IsStarted())
   196                     {
   207                     {
   197                     iActiveSchedulerWait->Start();
   208                     iActiveSchedulerWait->Start();
   225     {
   236     {
   226     char* dotPtr = NULL;
   237     char* dotPtr = NULL;
   227     char ext[MAX_EXTENSION_SIZE] = { 0 };
   238     char ext[MAX_EXTENSION_SIZE] = { 0 };
   228     int extLen;
   239     int extLen;
   229 
   240 
       
   241     int colpos;
       
   242     char urischeme[MAX_EXTENSION_SIZE] = { 0 };
       
   243     int urischemeLen;
       
   244 
   230     dotPtr = strrchr(uri, (int)'.');
   245     dotPtr = strrchr(uri, (int)'.');
   231     if (!dotPtr)
   246     if (!dotPtr)
   232         {
   247         {
   233         return KErrNotFound;
   248         return KErrNotFound;
   234         }
   249         }
   240     for(unsigned int i=0; i < extLen; i++)
   255     for(unsigned int i=0; i < extLen; i++)
   241         {
   256         {
   242         ext[i] = tolower(ext[i]);
   257         ext[i] = tolower(ext[i]);
   243         }
   258         }
   244 
   259 
       
   260     colpos = strcspn(uri,":");
       
   261 
       
   262     strncpy(urischeme, uri, colpos+1);
       
   263     /*Null terminate the string*/
       
   264     urischeme[colpos+1] = '\0';
       
   265     urischemeLen = sizeof(urischeme);
       
   266     for(unsigned int i=0; i < urischemeLen; i++)
       
   267         {
       
   268         urischeme[i] = tolower(urischeme[i]);
       
   269         }
       
   270     
       
   271     
       
   272     
   245     if (aFunc == ERecord)
   273     if (aFunc == ERecord)
   246         {
   274         {
   247         return EAudioRecorderUtility;
   275         return EAudioRecorderUtility;
   248         }
   276         }
   249     else
   277     else
   250         {
   278         {
   251         if (!strcasecmp(ext, ".mp3") ||
   279         if(!strcasecmp(urischeme, "file:"))
   252            !strcasecmp(ext, ".amr") ||
   280             {
   253            !strcasecmp(ext, ".aac") ||
   281             if (!strcasecmp(ext, ".mp3") ||
   254            !strcasecmp(ext, ".mid") ||
   282                !strcasecmp(ext, ".amr") ||
   255 		   !strcasecmp(ext, ".wav") ||
   283                !strcasecmp(ext, ".aac") ||
   256            !strcasecmp(ext, ".awb"))
   284                !strcasecmp(ext, ".mid") ||
   257             {
   285                !strcasecmp(ext, ".wav") ||
   258             return EAudioPlayerUtility;
   286                !strcasecmp(ext, ".awb"))
   259             }
   287                 {
   260           else
   288                 return EAudioPlayerUtility;
       
   289                 }
       
   290               else
       
   291                 {
       
   292                 return EVideoPlayerUtility;
       
   293                 }
       
   294             }
       
   295         else
   261             {
   296             {
   262             return EVideoPlayerUtility;
   297             return EVideoPlayerUtility;
   263             }
   298             }
   264         }
   299         }
   265     }
   300     }
   461         if (iErrorCode == KErrNone)
   496         if (iErrorCode == KErrNone)
   462             {
   497             {
   463             if (iPreviousRecordState == CMdaAudioClipUtility::ENotReady)
   498             if (iPreviousRecordState == CMdaAudioClipUtility::ENotReady)
   464                 {
   499                 {
   465                 //RDebug::Print(_L("CMMFBackendEngine::MoscoStateChangeEvent 2"));
   500                 //RDebug::Print(_L("CMMFBackendEngine::MoscoStateChangeEvent 2"));
   466                 TRAP(err,iaudioInputRecord = CAudioInput::NewL( *iAudioRecorder ));
   501                 TRAP(err,iAudioInputRecord = CAudioInput::NewL( *iAudioRecorder ));
   467                 RArray<CAudioInput::TAudioInputPreference> inputArray;
   502                 if(err == KErrNone)
   468                 inputArray.Append( CAudioInput::EDefaultMic );
   503                     {
   469                 // Set Audio Input
   504                     RArray<CAudioInput::TAudioInputPreference> inputArray;
   470                 iaudioInputRecord->SetAudioInputL( inputArray.Array( ) );
   505                     inputArray.Append( CAudioInput::EDefaultMic );
   471                 inputArray.Close();
   506                     // Set Audio Input
       
   507                     TRAP(err, iAudioInputRecord->SetAudioInputL( inputArray.Array( ) ));
       
   508                     inputArray.Close();
       
   509                     }
   472                 TMMFMessageDestination destination(KUidMetaDataWriteCustomCommand);
   510                 TMMFMessageDestination destination(KUidMetaDataWriteCustomCommand);
   473                 TMMFMessageDestinationPckg pckg = TMMFMessageDestinationPckg(destination);
   511                 TMMFMessageDestinationPckg pckg = TMMFMessageDestinationPckg(destination);
   474                 TInt ret = iAudioRecorder->RecordControllerCustomCommandSync(pckg, 0, KNullDesC8, KNullDesC8);
   512                 TInt ret = iAudioRecorder->RecordControllerCustomCommandSync(pckg, 0, KNullDesC8, KNullDesC8);
   475                 //RDebug::Print(_L("CMMFBackendEngine::MoscoStateChangeEvent 3 [%d]"),ret);
   513                 //RDebug::Print(_L("CMMFBackendEngine::MoscoStateChangeEvent 3 [%d]"),ret);
   476                 if (ret != KErrNone && iFileFormat == XA_CONTAINERTYPE_MP4)
   514                 if (ret != KErrNone && iFileFormat == XA_CONTAINERTYPE_MP4)
   563             case EPlayerClosed:
   601             case EPlayerClosed:
   564             default:
   602             default:
   565                 break;
   603                 break;
   566             };
   604             };
   567         }
   605         }
   568 
   606     
       
   607     // deleting the AudioInput object
       
   608     if(iAudioInputRecord)
       
   609         {
       
   610           delete iAudioInputRecord;
       
   611           iAudioInputRecord = NULL;
       
   612         }
       
   613     
   569     if (iBaseAudioPlayer && iAudioPlayer)
   614     if (iBaseAudioPlayer && iAudioPlayer)
   570         {
   615         {
   571         iAudioPlayer->Close();
   616         iAudioPlayer->Close();
   572         }
   617         }
   573 
   618 
   598     delete iPlayItfPositionUpdateTimer;
   643     delete iPlayItfPositionUpdateTimer;
   599     iPlayItfPositionUpdateTimer = NULL;
   644     iPlayItfPositionUpdateTimer = NULL;
   600     delete iBaseVideoPlayer;
   645     delete iBaseVideoPlayer;
   601     iBaseVideoPlayer = NULL;
   646     iBaseVideoPlayer = NULL;
   602     iVideoPlayer = NULL;
   647     iVideoPlayer = NULL;
   603     delete iaudioInputRecord;
       
   604     iaudioInputRecord = NULL;
       
   605     delete iBaseAudioPlayer;
   648     delete iBaseAudioPlayer;
   606     iBaseAudioPlayer = NULL;
   649     iBaseAudioPlayer = NULL;
   607     iAudioPlayer = NULL;
   650     iAudioPlayer = NULL;
   608     delete iBaseAudioRecorder;
   651     delete iBaseAudioRecorder;
   609     iBaseAudioRecorder = NULL;
   652     iBaseAudioRecorder = NULL;
   711         if(iRecordState != CMMFBackendEngine::ERecorderNotReady)
   754         if(iRecordState != CMMFBackendEngine::ERecorderNotReady)
   712             {
   755             {
   713             TRAP(err, sr = iAudioRecorder->DestinationSampleRateL());
   756             TRAP(err, sr = iAudioRecorder->DestinationSampleRateL());
   714             if(err == KErrNone)
   757             if(err == KErrNone)
   715                 {
   758                 {
   716                 *samplerate = sr;
   759                 *samplerate = sr*1000;
   717                 }
   760                 }
   718             }
   761             }
   719         }
   762         }
   720     else if(iAPIBeingUsed == EAudioPlayerUtility)
   763     else if(iAPIBeingUsed == EAudioPlayerUtility)
   721         {
   764         {
   728                                                         KNullDesC8,
   771                                                         KNullDesC8,
   729                                                         KNullDesC8,
   772                                                         KNullDesC8,
   730                                                         configPackage);
   773                                                         configPackage);
   731             if(err == KErrNone)
   774             if(err == KErrNone)
   732                 {
   775                 {
   733                 *samplerate = configPackage().iSampleRate;
   776                 *samplerate = configPackage().iSampleRate*1000;
   734                 }
   777                 }
   735             }
   778             }
   736         }
   779         }
   737     return err;
   780     return err;
   738     }
   781     }
   789 TInt CMMFBackendEngine::SetDestinationSampleRate(XAmilliHertz* samplerate)
   832 TInt CMMFBackendEngine::SetDestinationSampleRate(XAmilliHertz* samplerate)
   790     {
   833     {
   791     TInt err(KErrNone);
   834     TInt err(KErrNone);
   792     if(iRecordState == CMMFBackendEngine::ERecorderOpen)
   835     if(iRecordState == CMMFBackendEngine::ERecorderOpen)
   793         {
   836         {
   794         TRAP(err, iAudioRecorder->SetDestinationSampleRateL(*samplerate));
   837         TRAP(err, iAudioRecorder->SetDestinationSampleRateL(*samplerate/1000));
   795         if(err != KErrNone)
   838         if(err != KErrNone)
   796             {
   839             {
   797             return XA_RESULT_PARAMETER_INVALID;
   840             return XA_RESULT_PARAMETER_INVALID;
   798             }
   841             }
   799         }
   842         }
  1440     if (err != KErrNone)
  1483     if (err != KErrNone)
  1441         return err;
  1484         return err;
  1442 
  1485 
  1443     iUriPtr.Set(iUri->Des());
  1486     iUriPtr.Set(iUri->Des());
  1444     iUriPtr.Copy(uriParam); /* Copy data*/
  1487     iUriPtr.Copy(uriParam); /* Copy data*/
  1445     iUriPtr.LowerCase();
  1488     //iUriPtr.LowerCase();
  1446 
  1489 
  1447     /* For file scheme convert from file:///c:/folder/file.ext
  1490     /* For file scheme convert from file:///c:/folder/file.ext
  1448      * format to c:\\folder\\file.ext using TUriParser. */
  1491      * format to c:\\folder\\file.ext using TUriParser. */
  1449     _LIT(KFileScheme,"file:///");
  1492     _LIT(KFileScheme,"file:///");
  1450     if (iUriPtr.Find(KFileScheme) >= 0)
  1493     if (iUriPtr.Find(KFileScheme) >= 0)
  1451         {
  1494         {
       
  1495         iUriType = ELocal;
  1452         TPtr tmp(const_cast<TUint16 *>(iUriPtr.Ptr()) + KFileScheme().Length(),
  1496         TPtr tmp(const_cast<TUint16 *>(iUriPtr.Ptr()) + KFileScheme().Length(),
  1453                 iUriPtr.Length(),
  1497                 iUriPtr.Length(),
  1454                 iUriPtr.Length());
  1498                 iUriPtr.Length());
  1455         /* Convert from c:/folder/file.ext format to
  1499         /* Convert from c:/folder/file.ext format to
  1456          * c:\\folder\\file.ext using TUriParser.
  1500          * c:\\folder\\file.ext using TUriParser.
  1475         iUriPtr.Copy(file->Des());
  1519         iUriPtr.Copy(file->Des());
  1476         delete file;
  1520         delete file;
  1477         file = NULL;
  1521         file = NULL;
  1478 
  1522 
  1479         }
  1523         }
       
  1524     else
       
  1525         {
       
  1526         iUriType = EStreaming;
       
  1527         }
  1480     return err;
  1528     return err;
  1481     }
  1529     }
  1482 
  1530 
  1483 
  1531 
  1484 XAresult CMMFBackendEngine::SetVolume(XAuint32 volume)
  1532 XAresult CMMFBackendEngine::SetVolume(XAuint32 volume)