Home | History | Annotate | Download | only in src
      1 /* ------------------------------------------------------------------
      2  * Copyright (C) 1998-2009 PacketVideo
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
     13  * express or implied.
     14  * See the License for the specific language governing permissions
     15  * and limitations under the License.
     16  * -------------------------------------------------------------------
     17  */
     18 #include "pv_player_node_registry.h"
     19 
     20 #include "pvmi_datastreamsyncinterface_ref_factory.h"
     21 
     22 #ifdef USE_LOADABLE_MODULES
     23 #include "oscl_shared_library.h"
     24 #include "oscl_library_list.h"
     25 #include "oscl_configfile_list.h"
     26 #include "osclconfig_lib.h"
     27 #include "oscl_shared_lib_interface.h"
     28 
     29 #include "pvmf_node_shared_lib_interface.h"
     30 
     31 #endif //USE_LOADABLE_MODULES
     32 
     33 #include "pvmf_omx_videodec_factory.h"
     34 
     35 #if BUILD_VIDEO_DEC_NODE
     36 #include "pvmf_videodec_factory.h"
     37 #endif
     38 
     39 
     40 void PVPlayerRegistryPopulator::Populate(PVPlayerNodeRegistry& aNode, PVPlayerRecognizerRegistry& aRec)
     41 {
     42 
     43 #ifdef USE_LOADABLE_MODULES
     44     //add loadable modules
     45 
     46     OsclConfigFileList aCfgList;
     47     // collects all config files from the project specified directory
     48     if (NULL != PV_DYNAMIC_LOADING_CONFIG_FILE_PATH)
     49     {
     50         OSCL_HeapString<OsclMemAllocator> configFilePath = PV_DYNAMIC_LOADING_CONFIG_FILE_PATH;
     51         aCfgList.Populate(configFilePath);
     52     }
     53     // populate libraries from all config files
     54     for (uint k = 0; k < aCfgList.Size(); k++)
     55     {
     56         aNode.AddLoadableModules(aCfgList.GetConfigfileAt(k));
     57         aRec.AddLoadableModules(aCfgList.GetConfigfileAt(k));
     58     }
     59 #endif
     60 
     61     //add static modules
     62     PVPlayerRegistryPopulator pop;
     63     pop.RegisterAllNodes(&aNode, aNode.iStaticPopulatorContext);
     64     pop.RegisterAllRecognizers(&aRec, aRec.iStaticPopulatorContext);
     65 
     66 }
     67 
     68 void PVPlayerRegistryPopulator::Depopulate(PVPlayerNodeRegistry& aNode, PVPlayerRecognizerRegistry& aRec)
     69 {
     70     aNode.RemoveLoadableModules();
     71     aRec.RemoveLoadableModules();
     72 
     73     PVPlayerRegistryPopulator pop;
     74     pop.UnregisterAllNodes(&aNode, aNode.iStaticPopulatorContext);
     75     pop.UnregisterAllRecognizers(&aRec, aRec.iStaticPopulatorContext);
     76 }
     77 
     78 
     79 PVPlayerNodeRegistry::PVPlayerNodeRegistry()
     80 {
     81     iType.reserve(20);
     82     iLogger = PVLogger::GetLoggerObject("pvplayerengine.playernoderegistry");
     83 }
     84 
     85 
     86 PVPlayerNodeRegistry::~PVPlayerNodeRegistry()
     87 {
     88     iType.clear();
     89     iLogger = NULL;
     90 }
     91 
     92 void PVPlayerNodeRegistry::AddLoadableModules(const OSCL_String& aConfigFilePath)
     93 {
     94     PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "PVPlayerNodeRegistry::AddLoadableModules() IN"));
     95 #ifdef USE_LOADABLE_MODULES
     96 
     97     OsclLibraryList libList;
     98     libList.Populate(PV_NODE_REGISTRY_POPULATOR_INTERFACE, aConfigFilePath);
     99 
    100     for (unsigned int i = 0; i < libList.Size(); i++)
    101     {
    102         OsclSharedLibrary* lib = OSCL_NEW(OsclSharedLibrary, ());
    103         if (lib->LoadLib(libList.GetLibraryPathAt(i)) == OsclLibSuccess)
    104         {
    105             OsclAny* interfacePtr = NULL;
    106             OsclLibStatus result = lib->QueryInterface(PV_NODE_REGISTRY_POPULATOR_INTERFACE, (OsclAny*&)interfacePtr);
    107             if (result == OsclLibSuccess && interfacePtr != NULL)
    108             {
    109                 struct PVPlayerEngineNodeSharedLibInfo *libInfo = (struct PVPlayerEngineNodeSharedLibInfo *)oscl_malloc(sizeof(struct PVPlayerEngineNodeSharedLibInfo));
    110                 if (NULL != libInfo)
    111                 {
    112                     libInfo->iLib = lib;
    113 
    114                     NodeRegistryPopulatorInterface* nodeIntPtr = OSCL_DYNAMIC_CAST(NodeRegistryPopulatorInterface*, interfacePtr);
    115                     libInfo->iNodeLibIfacePtr = nodeIntPtr;
    116                     nodeIntPtr->RegisterAllNodes(this,  libInfo->iContext);
    117 
    118                     // save for depopulation later
    119                     iNodeLibInfoList.push_front(libInfo);
    120                     continue;
    121                 }
    122             }
    123             else
    124             {
    125                 PVLOGGER_LOGMSG(PVLOGMSG_INST_MLDBG, iLogger, PVLOGMSG_ERR,
    126                                 (0, "PVPlayerNodeRegistry::AddLoadableModules() QueryInterface() of PV_NODE_POPULATOR_INTERFACE for library %s failed.",
    127                                 libList.GetLibraryPathAt(i).get_cstr()));
    128             }
    129         }
    130         else
    131         {
    132             PVLOGGER_LOGMSG(PVLOGMSG_INST_MLDBG, iLogger, PVLOGMSG_ERR,
    133                             (0, "PVPlayerNodeRegistry::AddLoadableModules() LoadLib() of library %s failed.",
    134                             libList.GetLibraryPathAt(i).get_cstr()));
    135 
    136         }
    137         lib->Close();
    138         OSCL_DELETE(lib);
    139     }
    140 #else
    141     OSCL_UNUSED_ARG(aConfigFilePath);
    142 #endif
    143     PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "PVPlayerNodeRegistry::AddLoadableModules() OUT"));
    144 }
    145 
    146 void PVPlayerNodeRegistry::RemoveLoadableModules()
    147 {
    148     PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "PVPlayerNodeRegistry::RemoveLoadableModules() IN"));
    149 #ifdef USE_LOADABLE_MODULES
    150     // remove all dynamic nodes now
    151     // unregister node one by one
    152     while (!iNodeLibInfoList.empty())
    153     {
    154         struct PVPlayerEngineNodeSharedLibInfo *libInfo = iNodeLibInfoList.front();
    155         iNodeLibInfoList.erase(iNodeLibInfoList.begin());
    156 
    157         OsclSharedLibrary* lib = libInfo->iLib;
    158         NodeRegistryPopulatorInterface* nodeIntPtr = libInfo->iNodeLibIfacePtr;
    159         OsclAny* context = libInfo->iContext;
    160         oscl_free(libInfo);
    161 
    162         nodeIntPtr->UnregisterAllNodes(this, context);
    163 
    164         lib->Close();
    165         OSCL_DELETE(lib);
    166     }
    167 #endif
    168     PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "PVPlayerNodeRegistry::RemoveLoadableModules() OUT"));
    169 }
    170 
    171 
    172 PVMFStatus PVPlayerNodeRegistry::QueryRegistry(PVMFFormatType& aInputType, PVMFFormatType& aOutputType, Oscl_Vector<PVUuid, OsclMemAllocator>& aUuids)
    173 {
    174     PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "PVPlayerNodeRegistry::QueryRegistry() IN"));
    175     uint32 SearchCount = 0;
    176     bool matchfound = false;
    177 
    178     // Find all nodes that support the specified input and ouput format pair
    179     while (SearchCount < iType.size())
    180     {
    181         uint32 inputsearchcount = 0, outputsearchcount = 0;
    182         bool iInputFoundFlag = false, iOutputFoundFlag = false;
    183 
    184         while (inputsearchcount < iType[SearchCount].iInputTypes.size())
    185         {
    186             // Check if the input format matches
    187             if (iType[SearchCount].iInputTypes[inputsearchcount] == aInputType)
    188             {
    189                 // Set the the input flag to true since we found the match in the search
    190                 iInputFoundFlag = true;
    191                 break;
    192             }
    193             inputsearchcount++;
    194         }
    195 
    196         //Check the flag of input format if it is true check for the output format, if not return failure
    197         if (iInputFoundFlag)
    198         {
    199             while (outputsearchcount < iType[SearchCount].iOutputType.size())
    200             {
    201                 if (iType[SearchCount].iOutputType[outputsearchcount] == aOutputType)
    202                 {
    203                     //set the the output flag to true since we found the match in the search
    204                     iOutputFoundFlag = true;
    205                     break;
    206                 }
    207 
    208                 outputsearchcount++;
    209             }
    210 
    211             if (iOutputFoundFlag)
    212             {
    213                 // There's a match so add this node UUID to the list.
    214                 aUuids.push_back(iType[SearchCount].iNodeUUID);
    215                 matchfound = true;
    216             }
    217         }
    218 
    219         SearchCount++;
    220     }
    221 
    222     PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "PVPlayerNodeRegistry::QueryRegistry() OUT"));
    223     if (matchfound)
    224     {
    225         return PVMFSuccess;
    226     }
    227     else
    228     {
    229         return PVMFFailure;
    230     }
    231 }
    232 
    233 
    234 PVMFNodeInterface* PVPlayerNodeRegistry::CreateNode(PVUuid& aUuid, bool aHwAccelerated)
    235 {
    236     PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "PVPlayerNodeRegistry::CreateNode() IN"));
    237     bool iFoundFlag = false;
    238     uint32 NodeSearchCount = 0;
    239 
    240     while (NodeSearchCount < iType.size())
    241     {
    242         //Search if the UUID's will match
    243         if (iType[NodeSearchCount].iNodeUUID == aUuid)
    244         {
    245             //Since the UUID's match set the flag to true
    246             iFoundFlag = true;
    247             break;
    248         }
    249 
    250         NodeSearchCount++;
    251 
    252     }
    253 
    254     if (iFoundFlag)
    255     {
    256         OsclActiveObject::OsclActivePriority priority = OsclActiveObject::EPriorityNominal;
    257         PVPlayerNodeInfo* nodeInfo = &iType[NodeSearchCount];
    258         PVMFNodeInterface* nodeInterface = NULL;
    259 
    260 #if VIDEO_DEC_NODE_LOW_PRIORITY
    261         //Call the appropriate Node creation function & return Node pointer
    262         if (KPVMFOMXVideoDecNodeUuid == aUuid)
    263         {
    264             priority = OsclActiveObject::EPriorityLow;
    265         }
    266 #endif
    267         if (NULL != nodeInfo->iNodeCreateFunc)
    268         {
    269             if (KPVMFOMXVideoDecNodeUuid == aUuid)
    270             {
    271                 // FIXME:
    272                 // for now, we care about whether it is hardware-based or not only when it is a video decoder node.
    273                 // do a cast on the fucntion pointer
    274                 PVMFNodeInterface*(*aVideoDecNodeCreateFunc)(int32, bool);
    275                 aVideoDecNodeCreateFunc = (PVMFNodeInterface*(*)(int32, bool)) (iType[NodeSearchCount].iNodeCreateFunc);
    276                 nodeInterface = (*(aVideoDecNodeCreateFunc))(priority, aHwAccelerated);
    277             }
    278             else
    279             {
    280                 nodeInterface = (*(iType[NodeSearchCount].iNodeCreateFunc))(priority);
    281             }
    282         }
    283 
    284         PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "PVPlayerNodeRegistry::CreateNode() OUT"));
    285         return nodeInterface;
    286     }
    287     else
    288     {
    289         PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "PVPlayerNodeRegistry::CreateNode() OUT"));
    290         return NULL;
    291     }
    292 
    293 
    294 }
    295 
    296 bool PVPlayerNodeRegistry::ReleaseNode(PVUuid& aUuid, PVMFNodeInterface* aNode)
    297 {
    298     PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "PVPlayerNodeRegistry::ReleaseNode() IN"));
    299     bool iFoundFlag = false;
    300     uint32 NodeSearchCount = 0;
    301 
    302     while (NodeSearchCount < iType.size())
    303     {
    304         //Search if the UUID's will match
    305         if (iType[NodeSearchCount].iNodeUUID == aUuid)
    306         {
    307             //Since the UUID's match set the flag to true
    308             iFoundFlag = true;
    309             break;
    310         }
    311 
    312         NodeSearchCount++;
    313 
    314     }
    315 
    316     if (iFoundFlag)
    317     {
    318         //Call the appropriate Node release function
    319         bool del_stat = (*(iType[NodeSearchCount].iNodeReleaseFunc))(aNode);
    320         PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "PVPlayerNodeRegistry::ReleaseNode() OUT"));
    321         return del_stat;
    322     }
    323 
    324     PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "PVPlayerNodeRegistry::ReleaseNode() OUT"));
    325     return false;
    326 }
    327 
    328 
    329 PVPlayerRecognizerRegistry::PVPlayerRecognizerRegistry()
    330         : OsclTimerObject(OsclActiveObject::EPriorityNominal, "PVPlayerRecognizerRegistry")
    331 {
    332     AddToScheduler();
    333 
    334     iRecSessionId = 0;
    335     iRecognizerResult.reserve(4);
    336     iFileDataStreamFactory = NULL;
    337     iDataStreamFactory = NULL;
    338     iSourceFormatType = PVMF_MIME_FORMAT_UNKNOWN;
    339     iObserver = NULL;
    340     iCmdContext = NULL;
    341     iCancelQuery = false;
    342     iCancelCmdContext = NULL;
    343 
    344     if (PVMFRecognizerRegistry::Init() != PVMFSuccess)
    345     {
    346         OSCL_ASSERT(false);
    347         return;
    348     }
    349 
    350     iLogger = PVLogger::GetLoggerObject("pvplayerengine.playerrecognizerregistry");
    351 }
    352 
    353 
    354 PVPlayerRecognizerRegistry::~PVPlayerRecognizerRegistry()
    355 {
    356     if (iFileDataStreamFactory)
    357     {
    358         OSCL_DELETE(OSCL_STATIC_CAST(PVMIDataStreamSyncInterfaceRefFactory*, iFileDataStreamFactory));
    359         iFileDataStreamFactory = NULL;
    360     }
    361 
    362     PVMFRecognizerRegistry::Cleanup();
    363     iLogger = NULL;
    364 }
    365 
    366 void PVPlayerRecognizerRegistry::AddLoadableModules(const OSCL_String& aConfigFilePath)
    367 {
    368     PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "PVPlayerRecognizerRegistry::AddLoadableModules() IN"));
    369 #ifdef USE_LOADABLE_MODULES
    370     OsclLibraryList libList;
    371     libList.Populate(PV_RECOGNIZER_POPULATOR_INTERFACE, aConfigFilePath);
    372 
    373     for (unsigned int i = 0; i < libList.Size(); i++)
    374     {
    375         OsclSharedLibrary* lib = OSCL_NEW(OsclSharedLibrary, ());
    376         if (lib->LoadLib(libList.GetLibraryPathAt(i)) == OsclLibSuccess)
    377         {
    378             OsclAny* interfacePtr = NULL;
    379             OsclLibStatus result = lib->QueryInterface(PV_RECOGNIZER_POPULATOR_INTERFACE, (OsclAny*&)interfacePtr);
    380             if (result == OsclLibSuccess && interfacePtr != NULL)
    381             {
    382                 struct PVPlayerEngineRecognizerSharedLibInfo *libInfo = (struct PVPlayerEngineRecognizerSharedLibInfo *)oscl_malloc(sizeof(struct PVPlayerEngineRecognizerSharedLibInfo));
    383                 if (NULL != libInfo)
    384                 {
    385                     libInfo->iLib = lib;
    386 
    387                     RecognizerPopulatorInterface* recognizerIntPtr = OSCL_DYNAMIC_CAST(RecognizerPopulatorInterface*, interfacePtr);
    388 
    389                     libInfo->iRecognizerLibIfacePtr = recognizerIntPtr;
    390 
    391                     recognizerIntPtr->RegisterAllRecognizers(this, libInfo->iContext);
    392 
    393                     // save for depopulation later
    394                     iRecognizerLibInfoList.push_front(libInfo);
    395                     continue;
    396                 }
    397             }
    398         }
    399         lib->Close();
    400         OSCL_DELETE(lib);
    401     }
    402 #else
    403     OSCL_UNUSED_ARG(aConfigFilePath);
    404 #endif
    405     PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "PVPlayerRecognizerRegistry::AddLoadableModules() OUT"));
    406 }
    407 
    408 void PVPlayerRecognizerRegistry::RemoveLoadableModules()
    409 {
    410     PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "PVPlayerRecognizerRegistry::RemoveLoadableModules() IN"));
    411 #ifdef USE_LOADABLE_MODULES
    412     // remove all the dynamic plugins now
    413     // unregister the plugins one by one
    414     while (!iRecognizerLibInfoList.empty())
    415     {
    416         struct PVPlayerEngineRecognizerSharedLibInfo *libInfo = iRecognizerLibInfoList.front();
    417         iRecognizerLibInfoList.erase(iRecognizerLibInfoList.begin());
    418 
    419         OsclSharedLibrary* lib = libInfo->iLib;
    420         RecognizerPopulatorInterface* recognizerIntPtr = libInfo->iRecognizerLibIfacePtr;
    421         OsclAny* context = libInfo->iContext;
    422         oscl_free(libInfo);
    423 
    424         recognizerIntPtr->UnregisterAllRecognizers(this, context);
    425 
    426         lib->Close();
    427         OSCL_DELETE(lib);
    428     }
    429 #endif
    430     PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "PVPlayerRecognizerRegistry::RemoveLoadableModules() OUT"));
    431 }
    432 
    433 PVMFStatus PVPlayerRecognizerRegistry::QueryFormatType(OSCL_wString& aSourceURL, PVPlayerRecognizerRegistryObserver& aObserver, OsclAny* aCmdContext)
    434 {
    435     PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "PVPlayerRecognizerRegistry::QueryFormatType() IN"));
    436     if (iObserver != NULL)
    437     {
    438         // Previous query still ongoing
    439         return PVMFErrBusy;
    440     }
    441     iObserver = &aObserver;
    442     iCmdContext = aCmdContext;
    443 
    444     // Create a datastream wrapper factory for standard file
    445     if (iFileDataStreamFactory)
    446     {
    447         OSCL_DELETE(OSCL_STATIC_CAST(PVMIDataStreamSyncInterfaceRefFactory*, iFileDataStreamFactory));
    448         iFileDataStreamFactory = NULL;
    449     }
    450     int32 leavecode = 0;
    451     OSCL_TRY(leavecode, iFileDataStreamFactory = OSCL_STATIC_CAST(PVMFDataStreamFactory*, OSCL_NEW(PVMIDataStreamSyncInterfaceRefFactory, (aSourceURL))));
    452     OSCL_FIRST_CATCH_ANY(leavecode,
    453                          return PVMFErrNoMemory;
    454                         );
    455 
    456     // Open the session with recognizer
    457     PVMFRecognizerRegistry::OpenSession(iRecSessionId, *this);
    458 
    459     // Request file recognition
    460     iRecognizerResult.clear();
    461     iRecognizeCmdId = PVMFRecognizerRegistry::Recognize(iRecSessionId, *iFileDataStreamFactory, NULL, iRecognizerResult, NULL);
    462 
    463     PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "PVPlayerRecognizerRegistry::QueryFormatType() OUT"));
    464     return PVMFSuccess;
    465 }
    466 
    467 PVMFStatus PVPlayerRecognizerRegistry::QueryFormatType(PVMFCPMPluginAccessInterfaceFactory* aDataStreamFactory, PVPlayerRecognizerRegistryObserver& aObserver, OsclAny* aCmdContext)
    468 {
    469     PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "PVPlayerRecognizerRegistry::QueryFormatType() IN"));
    470     if (iObserver != NULL)
    471     {
    472         // Previous query still ongoing
    473         return PVMFErrBusy;
    474     }
    475 
    476     if (aDataStreamFactory == NULL)
    477     {
    478         return PVMFErrArgument;
    479     }
    480 
    481     iObserver = &aObserver;
    482     iCmdContext = aCmdContext;
    483 
    484     // delete the previous DataStreamFactory created by PVPlayerRecognizerRegistry
    485     if (iFileDataStreamFactory)
    486     {
    487         OSCL_DELETE(OSCL_STATIC_CAST(PVMIDataStreamSyncInterfaceRefFactory*, iFileDataStreamFactory));
    488         iFileDataStreamFactory = NULL;
    489     }
    490 
    491     iDataStreamFactory = aDataStreamFactory;
    492 
    493     // Open the session with recognizer
    494     PVMFRecognizerRegistry::OpenSession(iRecSessionId, *this);
    495 
    496     // Request file recognition
    497     iRecognizerResult.clear();
    498     iRecognizeCmdId = PVMFRecognizerRegistry::Recognize(iRecSessionId, *iDataStreamFactory, NULL, iRecognizerResult, NULL);
    499 
    500     PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "PVPlayerRecognizerRegistry::QueryFormatType() OUT"));
    501     return PVMFSuccess;
    502 }
    503 
    504 
    505 void PVPlayerRecognizerRegistry::CancelQuery(OsclAny* aContext)
    506 {
    507     if (iObserver == NULL)
    508     {
    509         // No pending recognize request
    510         OSCL_LEAVE(OsclErrInvalidState);
    511         return;
    512     }
    513 
    514     iCancelQuery = true;
    515     iCancelCmdContext = aContext;
    516 
    517     if (!IsBusy())
    518     {
    519         // The recognition pending so cancel it
    520         PVMFRecognizerRegistry::CancelCommand(iRecSessionId, iRecognizeCmdId);
    521     }
    522     // Else the recognition already completed so just cancel it in the Run()
    523 }
    524 
    525 
    526 void PVPlayerRecognizerRegistry::Run()
    527 {
    528     // Close the session with recognizer
    529     PVMFRecognizerRegistry::CloseSession(iRecSessionId);
    530 
    531     // Destroy the data stream wrapper factory for standard file
    532     if (iFileDataStreamFactory)
    533     {
    534         OSCL_DELETE(OSCL_STATIC_CAST(PVMIDataStreamSyncInterfaceRefFactory*, iFileDataStreamFactory));
    535         iFileDataStreamFactory = NULL;
    536     }
    537 
    538     // Tell the engine the result
    539     if (iObserver)
    540     {
    541         iObserver->RecognizeCompleted(iSourceFormatType, iCmdContext);
    542 
    543         if (iCancelQuery)
    544         {
    545             iObserver->RecognizeCompleted(iSourceFormatType, iCancelCmdContext);
    546             iCancelQuery = false;
    547             iCancelCmdContext = NULL;
    548         }
    549     }
    550     iObserver = NULL;
    551     iCmdContext = NULL;
    552 }
    553 
    554 void PVPlayerRecognizerRegistry::RecognizerCommandCompleted(const PVMFCmdResp& aResponse)
    555 {
    556     PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "PVPlayerRecognizerRegistry::RecognizerCommandCompleted() IN"));
    557     iSourceFormatType = PVMF_MIME_FORMAT_UNKNOWN;
    558 
    559     if (aResponse.GetCmdId() == iRecognizeCmdId)
    560     {
    561         // Recognize() command completed
    562         if (aResponse.GetCmdStatus() == PVMFSuccess)
    563         {
    564             PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "PVPlayerRecognizerRegistry::RecognizeCommandCompleted() - Recognize returned Success"));
    565             Oscl_Vector<PVMFRecognizerResult, OsclMemAllocator>::iterator it;
    566             for (it = iRecognizerResult.begin(); it != iRecognizerResult.end(); it++)
    567             {
    568                 if (it->iRecognitionConfidence == PVMFRecognizerConfidenceCertain)
    569                 {   //@TODO: validate whether there are more than one claims Certain.
    570                     iSourceFormatType = it->iRecognizedFormat.get_str();
    571                     break;
    572                 }
    573                 if (it->iRecognitionConfidence == PVMFRecognizerConfidencePossible)
    574                 {
    575                     iSourceFormatType = it->iRecognizedFormat.get_str();
    576                 }
    577             }
    578         }
    579         else if (aResponse.GetCmdStatus() == PVMFErrCancelled)
    580         {
    581             // If cancelled, need to wait for the cancel command to complete before
    582             // calling Run
    583             PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "PVPlayerRecognizerRegistry::RecognizerCommandCompleted() - Recognize returned Cancelled - OUT"));
    584             return;
    585         }
    586     }
    587 
    588     RunIfNotReady();
    589     PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "PVPlayerRecognizerRegistry::RecognizerCommandCompleted() OUT"));
    590 }
    591 
    592 
    593 
    594 
    595 
    596