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 #ifndef PV_2WAY_DATAPATH_H_INCLUDED
     19 #define PV_2WAY_DATAPATH_H_INCLUDED
     20 
     21 #ifndef OSCL_ERROR_H_INCLUDED
     22 #include "oscl_error.h"
     23 #endif
     24 
     25 #ifndef OSCL_VECTOR_H_INCLUDED
     26 #include "oscl_vector.h"
     27 #endif
     28 
     29 #ifndef PV_2WAY_ENGINE_H_INCLUDED
     30 #include "pv_2way_engine.h"
     31 #endif
     32 
     33 #ifndef PVMF_NODE_INTERFACE_H_INCLUDED
     34 #include "pvmf_node_interface.h"
     35 #endif
     36 
     37 #ifndef PVMF_PORT_INTERFACE_H_INCLUDED
     38 #include "pvmf_port_interface.h"
     39 #endif
     40 
     41 #define MAX_DATAPATH_NODES 10
     42 #define MAX_PARENT_PATHS 2
     43 #define MAX_DEPENDENT_PATHS 2
     44 
     45 /**
     46  * TPVNodeConfigTimeType enum
     47  *
     48  * An enumeration of when to configure the node
     49  **/
     50 typedef enum
     51 {
     52     EConfigBeforeInit = 0, //Configure node before initialization
     53     EConfigBeforeReqInPort, //Configure node before requesting input port
     54     EConfigBeforeReqOutPort, //Configure node before requesting output port
     55     EConfigBeforePrepare, //Configure node before preparing
     56     EConfigBeforeStart, //Configure node before starting
     57     EMaxConfigTimeTypes
     58 } TPVNodeConfigTimeType;
     59 
     60 /**
     61  * TPV2WayDatapathType enum
     62  *
     63  * An enumeration of types of data paths
     64  **/
     65 typedef enum
     66 {
     67     EUnknownDatapath = 0,
     68     EEncodeDatapath,
     69     EDecodeDatapath,
     70     EMuxDatapath,
     71     ERecDatapath,
     72     EPreviewDatapath,
     73     EMaxDatapathType
     74 } TPV2WayDatapathType;
     75 
     76 /**
     77  * TPV2WayDatapathState enum
     78  *
     79  * An enumeration of broad external states of the data path
     80  **/
     81 typedef enum
     82 {
     83     EClosed = 0,
     84     EOpening,
     85     EOpened,
     86     EPausing,
     87     EPaused,
     88     EUnpausing,
     89     EClosing,
     90     EMaxDataPathStates
     91 } TPV2WayDatapathState;
     92 
     93 /**
     94  * TPVPortFormatSetType enum
     95  *
     96  * An enumeration of how the format type of the port is determined
     97  **/
     98 typedef enum
     99 {
    100     EUserDefined = 0, //User defines format type for port
    101     EConnectedPortFormat, //Format is set to the connecting port's format
    102     EUseOtherNodePortFormat, //Format is set to whatever the other node port is set to (nodes in a datapath have only 2 ports)
    103     EAppDefined, //Format is pre-set during RequestPort.  Does not need to be set
    104     EMaxFormatSetTypes
    105 } TPVPortFormatSetType;
    106 
    107 
    108 /**
    109  * CPV2WayPortPair Class
    110  *
    111  * Specifies a pair of node ports that describe a data connection and the status of the ports.
    112  **/
    113 class CPV2WayPortPair
    114 {
    115     public:
    116         CPV2WayPortPair() : iIsConnected(false) {};
    117 
    118         ~CPV2WayPortPair() {};
    119 
    120         bool Connect();
    121         bool Disconnect();
    122 
    123         CPV2WayPort iSrcPort;
    124         CPV2WayPort iDestPort;
    125         bool iIsConnected;
    126 };
    127 
    128 /**
    129  * CPVDatapathPort Class
    130  *
    131  * Describes how to use a port in a datatpath.
    132  **/
    133 class CPVDatapathPort
    134 {
    135     public:
    136         CPVDatapathPort() : iPortTag(0),
    137                 iRequestPortState(EPVMFNodeInitialized),
    138                 iCanCancelPort(false),
    139                 iPortSetType(EUserDefined),
    140                 iFormatType(PVMF_MIME_FORMAT_UNKNOWN),
    141                 iDefaultFormatType(PVMF_MIME_FORMAT_UNKNOWN),
    142                 iPortPair(NULL)
    143         {
    144         };
    145 
    146         CPVDatapathPort(const CPVDatapathPort &aPort) : iPortTag(aPort.iPortTag),
    147                 iRequestPortState(aPort.iRequestPortState),
    148                 iRequestPortAnytime(aPort.iRequestPortAnytime),
    149                 iCanCancelPort(aPort.iCanCancelPort),
    150                 iPortSetType(aPort.iPortSetType),
    151                 iFormatType(aPort.iFormatType),
    152                 iDefaultFormatType(aPort.iDefaultFormatType),
    153 
    154                 iPortPair(aPort.iPortPair)
    155         {
    156         };
    157 
    158         ~CPVDatapathPort() {};
    159 
    160         CPVDatapathPort& operator=(const CPVDatapathPort& a);
    161 
    162         int32 iPortTag; // The port tag
    163         TPVMFNodeInterfaceState iRequestPortState; //State of node to request/release port
    164         bool iRequestPortAnytime; //Can port be requested in any node state
    165         bool iCanCancelPort; // Can the request port command be cancelled for the port
    166         TPVPortFormatSetType iPortSetType; // How to determine format type for the port
    167         PVMFFormatType iFormatType; // Sets format type for the port
    168         PVMFFormatType iDefaultFormatType; // In the case the CapConfig interface is stupid
    169         CPV2WayPortPair *iPortPair; // The out port will be the iSrcPort of the port pair
    170         // The in port will be the iDestPort of the port pair
    171 };
    172 
    173 /**
    174  * CPVDatapathNode Class
    175  *
    176  * Describes how a node is used in a datatpath.
    177  **/
    178 class CPVDatapathNode
    179 {
    180     public:
    181         CPVDatapathNode() : iConfigure(NULL),
    182                 iConfigTime(EConfigBeforeInit),
    183                 iCanNodePause(false),
    184                 iLoggoffOnReset(false),
    185                 iOriginalState(EPVMFNodeIdle),
    186                 iDatapathCloseState(EPVMFNodeLastState),
    187                 iCommandIssued(false)
    188         {};
    189 
    190         CPVDatapathNode(const CPVDatapathNode &aNode) : iNode(aNode.iNode),
    191                 iConfigure(aNode.iConfigure),
    192                 iConfigTime(aNode.iConfigTime),
    193                 iCanNodePause(aNode.iCanNodePause),
    194                 iLoggoffOnReset(aNode.iLoggoffOnReset),
    195                 iIgnoreNodeState(aNode.iIgnoreNodeState),
    196                 iOriginalState(aNode.iOriginalState),
    197                 iDatapathCloseState(aNode.iDatapathCloseState),
    198                 iInputPort(aNode.iInputPort),
    199                 iOutputPort(aNode.iOutputPort),
    200                 iCommandIssued(aNode.iCommandIssued)
    201         {};
    202 
    203 
    204         ~CPVDatapathNode() {};
    205 
    206         CPVDatapathNode& operator=(const CPVDatapathNode& a);
    207 
    208         bool CloseableState()
    209         {
    210             PVMFNodeInterface * nodeIFace = (PVMFNodeInterface *)iNode;
    211             if (iDatapathCloseState != EPVMFNodeLastState &&
    212                     nodeIFace->GetState() == iDatapathCloseState)
    213                 return true;
    214             if (iDatapathCloseState == EPVMFNodeLastState &&
    215                     nodeIFace->GetState() == iOriginalState)
    216                 return true;
    217             return false;
    218         }
    219 
    220         TPV2WayNode iNode; // Actual node
    221         CPV2WayNodeConfigurationObserver *iConfigure; // Node configuration observer, called when config time is reached
    222         TPVNodeConfigTimeType iConfigTime; // When to configure node
    223         bool iCanNodePause; // Is the node capable of pausing
    224         bool iLoggoffOnReset; // Does node need to logoff after datapath is reset
    225         bool iIgnoreNodeState; // Flag for that specifies whether the datapath changes the state of the node
    226         TPVMFNodeInterfaceState iOriginalState; // The state of the node when it is added to the datapath
    227         TPVMFNodeInterfaceState iDatapathCloseState; // The state in which the node should be in before the
    228         // datapath closes
    229         CPVDatapathPort iInputPort;
    230         CPVDatapathPort iOutputPort;
    231         bool iCommandIssued;
    232 };
    233 
    234 
    235 class CPV2WayDatapath : public HeapBase, public CPV2WayNodeCommandObserver
    236 {
    237     private:
    238         TPV2WayNode* iNode;
    239     public:
    240         CPV2WayDatapath(PVLogger *aLogger,
    241                         TPV2WayDatapathType aType,
    242                         PVMFFormatType aFormat,
    243                         CPV324m2Way *a2Way) : iType(aType),
    244                 iState(EClosed),
    245                 iStateBeforeClose(EClosed),
    246                 iFormat(aFormat),
    247                 iSourceSinkFormat(PVMF_MIME_FORMAT_UNKNOWN),
    248                 i2Way(a2Way),
    249                 iLogger(aLogger),
    250                 iAllPortsConnected(false)
    251         {};
    252 
    253         virtual ~CPV2WayDatapath() {};
    254 
    255         bool IsPortInDatapath(PVMFPortInterface *aPort);
    256         bool IsNodeInDatapath(PVMFNodeInterface *aNode);
    257         bool ResetDatapath();
    258         bool AddNode(const CPVDatapathNode &aNode);
    259         bool Open();
    260         bool Close();
    261         bool Pause();
    262         bool Resume();
    263 
    264         bool AddParentDatapath(CPV2WayDatapath &aDatapath);
    265         bool AddDependentDatapath(CPV2WayDatapath &aDatapath);
    266 
    267         TPV2WayDatapathState GetState()
    268         {
    269             return iState;
    270         }
    271         void SetFormat(PVMFFormatType aFormatType)
    272         {
    273             iFormat = aFormatType;
    274         }
    275         PVMFFormatType GetFormat()
    276         {
    277             return iFormat;
    278         }
    279 
    280         void CommandHandler(PV2WayNodeCmdType aType, const PVMFCmdResp& aResponse);
    281 
    282         void CheckPath();
    283         void SetFormatSpecificInfo(uint8* fsi, uint16 fsi_len);
    284         uint8* GetFormatSpecificInfo(uint32* len);
    285         void SetSourceSinkFormat(PVMFFormatType aFormatType);
    286         PVMFFormatType GetSourceSinkFormat() const;
    287     protected:
    288         void ConstructL();
    289 
    290         bool SendNodeCmd(PV2WayNodeCmdType cmd, int i);
    291         int SetParametersSync(PvmiCapabilityAndConfig * configPtr,
    292                               PvmiKvp* portParams,
    293                               PvmiKvp*& portParamsReturn);
    294         bool CheckNodePorts(bool& aCheckPort, int i);
    295 
    296         void SetPort(CPV2WayPort &aDatapathPort, PVMFPortInterface *aPort)
    297         {
    298             aDatapathPort.SetPort(aPort);
    299         }
    300 
    301         void SetState(TPV2WayDatapathState aState);
    302 
    303         bool IsDatapathNodeClosed(CPVDatapathNode &aNode);
    304         bool CheckNodePortsL(CPVDatapathNode &aNode);
    305         PVMFStatus PortStatusChange(PVMFNodeInterface *aNode, PVMFCommandId aId, PVMFPortInterface *aPort);
    306         CPV2WayPort *RetrievePort(PVMFNodeInterface *aNode, PVMFCommandId aId);
    307         PVMFStatus ReleaseNodePorts(CPVDatapathNode &aNode);
    308         void CloseNodePorts(CPVDatapathNode &aNode);
    309         PVMFCommandId SendNodeCmdL(PV2WayNodeCmdType aCmd,
    310                                    CPVDatapathNode &aNode,
    311                                    void *aParam = NULL);
    312 
    313         PVMFStatus CheckConfig(TPVNodeConfigTimeType aConfigTime, CPVDatapathNode &aNode);
    314 
    315         //Can be overriden in derived datapaths
    316         virtual void CheckOpen();
    317         virtual void CheckPause();
    318         virtual void CheckResume();
    319         virtual void CheckClosed();
    320 
    321         virtual void OpenComplete() = 0;
    322         virtual void PauseComplete() = 0;
    323         virtual void ResumeComplete() = 0;
    324         virtual void CloseComplete() = 0;
    325 
    326         virtual void DatapathError() = 0;
    327 
    328         virtual bool CheckPathSpecificOpen()
    329         {
    330             return true;
    331         }
    332         virtual bool PathSpecificClose()
    333         {
    334             return true;
    335         }
    336         virtual bool CheckPathSpecificStart()
    337         {
    338             return true;
    339         }
    340 
    341         virtual void DependentPathClosed(CPV2WayDatapath *aDependentPath);
    342         bool HaveAllDependentPathsClosed();
    343         bool IsParentClosing();
    344         void NotifyParentPaths();
    345         virtual bool ParentIsClosing();
    346         virtual bool SingleNodeOpen()
    347         {
    348             return false;
    349         }
    350 
    351         PVMFStatus GetKvp(PVMFPortInterface &aPort, bool aInput,
    352                           PvmiKvp*& aKvp, int& aNumKvpElem, OsclAny*& aconfigPtr);
    353         PVMFFormatType GetPortFormatType(PVMFPortInterface& aPort,
    354                                          bool aInput, PVMFPortInterface* aOtherPort);
    355 
    356         TPV2WayDatapathType iType;
    357         TPV2WayDatapathState iState;
    358         TPV2WayDatapathState iStateBeforeClose;
    359         // The codec type associated with this datapath
    360         PVMFFormatType iFormat;
    361         // The format type of the terminating source/sink
    362         PVMFFormatType iSourceSinkFormat;
    363 
    364         CPV324m2Way *i2Way;
    365         PVLogger *iLogger;
    366         bool iAllPortsConnected;
    367 
    368         Oscl_Vector<CPVDatapathNode, BasicAlloc> iNodeList;
    369         Oscl_Vector<CPV2WayPortPair, BasicAlloc> iPortPairList;
    370 
    371         //List of datapaths this datapath depends on
    372         Oscl_Vector<CPV2WayDatapath *, BasicAlloc> iParentPathList;
    373         //List of datapaths that depend on this datapath
    374         Oscl_Vector<CPV2WayDatapath *, BasicAlloc> iDependentPathList;
    375         // Format specific info associated with this datapath
    376         uint8* iFsi;
    377         uint32 iFsiLen;
    378 };
    379 
    380 #endif //PV_2WAY_DATAPATH_H_INCLUDED
    381 
    382 
    383