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 
     19 #ifndef PV_OMX_PROXIED_INTERFACE_H_INCLUDED
     20 #define PV_OMX_PROXIED_INTERFACE_H_INCLUDED
     21 
     22 
     23 #ifndef OSCL_BASE_H_INCLUDED
     24 #include "oscl_base.h"
     25 #endif
     26 #ifndef PV_UUID_H_INCLUDED
     27 #include "pv_uuid.h"
     28 #endif
     29 #ifndef PV_INTERFACE_H_INCLUDED
     30 #include "pv_interface.h"
     31 #endif
     32 #ifndef PV_OMXDEFS_H_INCLUDED
     33 #include "pv_omxdefs.h"
     34 #endif
     35 
     36 #define PVUidOMXProxiedInterface  PVUuid(0xf7076653,0x6088,0x47c6,0x88,0xc1,0xb7,0xed,0x28,0xe7,0x2b,0xeb)
     37 #if PROXY_INTERFACE
     38 
     39 class PVProxiedInterface_OMX;
     40 class PVProxiedInterfaceClient_OMX;
     41 class PVProxiedInterfaceServer_OMX;
     42 class PVProxiedEngine_OMX;
     43 
     44 typedef int32 TPVProxyId;
     45 typedef int32 TPVProxyMsgId;
     46 typedef PVUuid TPVProxyUUID;
     47 
     48 //Added command id to identify the openmax commands
     49 typedef int32 TPVCommandId;
     50 
     51 /**
     52 ** Main proxy class.  This class defines the public interface
     53 ** to the PV proxy.
     54 */
     55 class PVMainProxy_OMX
     56 {
     57     public:
     58         virtual ~PVMainProxy_OMX() {}
     59 
     60         /**
     61         ** This call registers a proxied interface with the main
     62         ** proxy and assigns a unique interface ID.
     63         ** Interfaces may be registered at any time during
     64         ** the life of the main proxy.
     65         **
     66         ** @return aProxyId: the ID of this interface pair.
     67         ** @param aServer: server side (PV Thread) implementation.
     68         ** @param aClient: client side (app thread) implementation.
     69         ** This function will leave if memory allocation fails.
     70         */
     71         virtual TPVProxyId RegisterProxiedInterface(
     72             PVProxiedInterfaceServer_OMX& aServer,
     73             PVProxiedInterfaceClient_OMX& aClient) = 0;
     74 
     75         /**
     76         ** This call un-registers a proxied interface with the main
     77         ** proxy.  During this call, the main proxy will de-queue all
     78         ** undelivered messages belonging to this interface and will
     79         ** call their memory cleanup routine.
     80         ** If the interface is not currently registered, this call
     81         ** will have no effect.
     82         ** Interfaces may be un-registered at any time during the
     83         ** life of the main proxy.
     84         **
     85         ** @param aProxyId: the ID of this interface pair.
     86         ** @return : result code
     87         **/
     88         virtual void UnregisterProxiedInterface(TPVProxyId aProxyId) = 0;
     89 
     90         /**
     91         ** This API adds message to the command queue.  This would
     92         ** typically be called from a PVProxiedInterfaceClient
     93         ** module.  The message will be delivered asynchronously under
     94         ** the PV thread.
     95         **
     96         ** @param aProxyId: the ID of this interface pair.
     97         ** @param aCmd: the command.
     98         ** @return: a unique message ID, assigned by the proxy.
     99         ** This function will leave if memory allocation fails.
    100         **/
    101         virtual TPVProxyMsgId SendCommand(TPVProxyId aProxyId, TPVCommandId cmdid, OsclAny* aCmd) = 0;
    102 
    103         /**
    104         ** This API will cancel a command that was previously sent
    105         ** and may still be queued.  This is a synchronous operation.
    106         ** The proxy will de-queue the message and call its memory cleanup
    107         ** routine.  If the message is no longer queued, this call will
    108         ** have no effect.
    109         **
    110         ** @param aProxyId: the ID of this interface pair.
    111         ** @param aMsgId: the command's ID, previously returned by SendCommand.
    112         ** @return : result code
    113         */
    114         virtual void CancelCommand(TPVProxyId aProxyId, TPVProxyMsgId aMsgId) = 0;
    115 
    116         /**
    117         ** This API will de-queue and cleanup all commands that were
    118         ** previously sent for an interface and may still be queued.
    119         ** The cancel operation is synchronous.
    120         ** If no commands are queued for the interface, this call has
    121         ** no effect.
    122         **
    123         ** @param aProxyId: the ID of this interface pair.
    124         ** @return : result code
    125         */
    126         virtual void CancelAllCommands(TPVProxyId aProxyId) = 0;
    127 
    128         /**
    129         ** This API adds a message to the notification queue.
    130         ** This would typically be called by a PVProxiedInterfaceServer
    131         ** module.  The message will be delivered asynchronously under
    132         ** the app thread.
    133         **
    134         ** @param aProxyId: the ID of this interface pair.
    135         ** @param aResp: the notification.
    136         ** @return: a unique message ID, assigned by the proxy.
    137         ** This function will leave if memory allocation fails.
    138         **/
    139         virtual TPVProxyMsgId SendNotification(TPVProxyId aProxyId, OsclAny* aResp) = 0;
    140 
    141         /**
    142         ** This API will cancel a notification that was previously sent
    143         ** and may still be queued.  This is a synchronous operation.
    144         ** The proxy will de-queue the message and call its memory cleanup
    145         ** routine.  If the message is no longer queued, this call will
    146         ** have no effect.
    147         **
    148         ** @param aProxyId: the ID of this interface pair.
    149         ** @param aMsgId: the message ID, previously returned by SendNotification.
    150         ** @return : result code
    151         */
    152         virtual void CancelNotification(TPVProxyId aProxyId, TPVProxyMsgId aMsgId) = 0;
    153 
    154         /**
    155         ** This API will de-queue and cleanup all notifications that were
    156         ** previously sent for an interface and may still be queued.
    157         ** The cancel operation is synchronous.
    158         ** If no notifications are queued for the interface, this call has
    159         ** no effect.
    160         **
    161         ** @param aProxyId: the ID of this interface pair.
    162         ** @return : result code
    163         */
    164         virtual void CancelAllNotifications(TPVProxyId aProxyId) = 0;
    165 
    166         /**
    167         ** This API will start the PV thread.  The call will block
    168         ** until the thread starts up and the engine thread logon
    169         ** completes.
    170         **
    171         **  @returns: true if thread creation succeeded-- false otherwise.
    172         */
    173         virtual bool StartPVThread() = 0;
    174 
    175         /**
    176         ** This API will stop the PV thread's scheduler and block
    177         ** until the thread cleanup is complete.  During the thread
    178         ** cleanup, the scheduler is stopped, all un-sent messages
    179         ** are automatically cleaned up, and the engine Thread Logoff
    180         ** routine is called.
    181         **
    182         ** Calling this API under the PV thread context is an error
    183         ** and will leave.
    184         */
    185         virtual void StopPVThread() = 0;
    186 
    187         /**
    188         ** This API may be used to run the client-side of the proxy
    189         ** in a non-blocking mode, for cases where there is no Oscl
    190         ** scheduler or native scheduler running in the application
    191         ** thread.
    192         ** The proxy client will run until all pending notifications
    193         ** have been sent, or else the max count of notifications has
    194         ** been reached.  This API also returns the count of notifications
    195         ** still pending after the processing is complete.
    196         ** Any call to this API from within the PV thread context is
    197         ** an error and will leave.
    198         **
    199         ** @param aMaxCount: (input param) the maximum of pending
    200         **   notifications to process during the call.
    201         ** @param aPendingCount: (output param) number of pending
    202         **   notifications still remaining on the queue.
    203         */
    204         virtual void DeliverNotifications(int32 aMaxCount, int32& aPendingCount) = 0;
    205 };
    206 
    207 /**
    208 ** A proxied engine must implement this class
    209 */
    210 class PVProxiedEngine_OMX
    211 {
    212     public:
    213         virtual ~PVProxiedEngine_OMX() {}
    214 
    215         /**
    216         ** Create PV logger appenders for the PV thread.
    217         ** Creating appenders in this call is optional and
    218         ** allows logging by the PV thread related to thread
    219         ** and scheduler initialization that occurs before
    220         ** the thread logon.
    221         **/
    222         virtual void CreateLoggerAppenders() = 0;
    223 
    224         /**
    225         ** Perform all thread-specific engine creation and
    226         ** initialization.
    227         ** This call is made by the main proxy from the PV
    228         ** Thread after Oscl has been initialized
    229         ** in the thread, but before starting the scheduler.
    230         **
    231         ** @param proxy: reference to the caller.  The app
    232         **   may save this pointer and use it to make calls
    233         **   to the main proxy.
    234         */
    235         virtual void PVThreadLogon(PVMainProxy_OMX &proxy) = 0;
    236 
    237         /**
    238         ** Perform all thread-specific engine cleanup.
    239         ** This call is made by the main proxy from the PV thread
    240         ** after the scheduler has exited, but before Oscl has been
    241         ** cleaned up.
    242         **
    243         ** @param proxy: reference to the caller.  The app
    244         **   may save this pointer and use it to make calls
    245         **   to the main proxy.
    246         */
    247         virtual void PVThreadLogoff(PVMainProxy_OMX &proxy) = 0;
    248 };
    249 
    250 /**
    251 ** Proxied interface modules may implement this class
    252 ** in order to provide a common interface query mechanism.
    253 */
    254 class PVProxiedInterface_OMX : public PVInterface
    255 {
    256     public:
    257         /**
    258         ** To query for supported (proxied) interfaces.
    259         **
    260         ** @param aUuid (input): the requested UUID
    261         ** @param aInterfacePtr (output): a pointer to
    262         **    the interface implementation, or NULL if not available.
    263         **
    264         ** The holder of the interface pointer must call
    265         ** "removeRef" when it is done with the pointer.
    266         */
    267         virtual void QueryProxiedInterface(const TPVProxyUUID& aUuid, PVInterface*& aInterfacePtr) = 0;
    268         /**
    269         ** May be used to pass the main proxy pointer to
    270         ** the implementation.
    271         */
    272         virtual void SetMainProxy(PVMainProxy_OMX*) = 0;
    273 };
    274 
    275 
    276 /**
    277 ** Proxied interface modules must implement this class on the
    278 ** PV thread side.
    279 */
    280 class PVProxiedInterfaceServer_OMX
    281 {
    282     public:
    283         virtual ~PVProxiedInterfaceServer_OMX() {}
    284 
    285         /**
    286         ** PVMainProxy calls this under the PV thread to process a
    287         ** command off the queue.
    288         **
    289         ** @param aId: the message ID assigned by the SendCommand call.
    290         ** @param aMsg: the command data.
    291         */
    292         //Added one more argument to identify the openmax command
    293         virtual void HandleCommand(TPVProxyMsgId aMsgId, TPVCommandId, OsclAny* aMsg) = 0;
    294 
    295         /**
    296         ** PVMainProxy calls this to cleanup an un-sent or canceled
    297         ** notification.  The server module should clean up any
    298         ** allocated memory.  The cleanup operation must be synchronous
    299         ** and thread-safe.
    300         **
    301         ** @param aId: the message ID assigned by the SendNotification call.
    302         ** @param aMsg: the notification data.
    303         */
    304         virtual void CleanupNotification(TPVProxyMsgId aId, OsclAny* aMsg) = 0;
    305 };
    306 
    307 /**
    308 ** Proxied interface pairs must implement this class on the
    309 ** app thread side.
    310 */
    311 class PVProxiedInterfaceClient_OMX
    312 {
    313     public:
    314         virtual ~PVProxiedInterfaceClient_OMX() {}
    315 
    316         /**
    317         ** PVMainProxy calls this to process a notification off the
    318         ** queue.
    319         ** @param aId: the message ID assigned by the SendNotification call.
    320         ** @param aMsg: the notification data.
    321         */
    322         virtual void HandleNotification(TPVProxyMsgId aId, OsclAny* aMsg) = 0;
    323 
    324         /**
    325         ** PVMainProxy calls this to cleanup an un-sent or canceled
    326         ** command.  The client module should clean up any allocated
    327         ** memory.  The cleanup operation must be synchronous
    328         ** and thread-safe.
    329         **
    330         ** @param aId: the message ID assigned by the SendCommand call.
    331         ** @param aMsg: the command data.
    332         */
    333         virtual void CleanupCommand(TPVProxyMsgId aId, OsclAny* aMsg) = 0;
    334 };
    335 
    336 /**
    337 //A basic implemention of PVProxiedInterface.
    338 //Interface implementations
    339 //can derive from this.
    340 */
    341 template<class Alloc>
    342 class PVProxiedInterfaceImpl_OMX : public PVProxiedInterface_OMX
    343 {
    344     public:
    345         PVProxiedInterfaceImpl_OMX(const PVUuid& uuid)
    346                 : iRefCounter(1)
    347                 , iUuid(uuid)
    348                 , iMainProxy(NULL)
    349         {}
    350         void SetUuid(const PVUuid& uuid)
    351         {
    352             iUuid = uuid;
    353         }
    354         bool TestUuid(const PVUuid& uuid)
    355         {
    356             return iUuid == uuid;
    357         }
    358         virtual ~PVProxiedInterfaceImpl_OMX()
    359         {}
    360         void removeRef()
    361         {
    362             --iRefCounter;
    363             if (iRefCounter <= 0)
    364             {
    365                 this->~PVProxiedInterfaceImpl_OMX();
    366                 Alloc alloc;
    367                 alloc.deallocate(this);
    368             }
    369         }
    370         void addRef()
    371         {
    372             iRefCounter++;
    373         }
    374         bool queryInterface(const PVUuid&, PVInterface*&)
    375         {
    376             return false;
    377         }
    378 
    379         void SetMainProxy(PVMainProxy_OMX *p)
    380         {
    381             iMainProxy = p;
    382         }
    383         void QueryProxiedInterface(const TPVProxyUUID& aUuid, PVInterface*& aInterfacePtr)
    384         {
    385             if (aUuid == iUuid)
    386                 aInterfacePtr = (PVInterface*)this;
    387             else
    388                 aInterfacePtr = NULL;
    389         }
    390     protected:
    391         int32 iRefCounter;
    392         PVUuid iUuid;
    393         PVMainProxy_OMX *iMainProxy;
    394 };
    395 
    396 #endif // PROXY_INTERFACE
    397 #endif
    398 
    399 
    400