Home | History | Annotate | Download | only in include
      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 PVMF_OMX_ENC_PORT_H_INCLUDED
     19 #define PVMF_OMX_ENC_PORT_H_INCLUDED
     20 
     21 
     22 #ifndef OSCL_BASE_H_INCLUDED
     23 #include "oscl_base.h"
     24 #endif
     25 
     26 #ifndef PVMF_PORT_INTERFACE_H_INCLUDED
     27 #include "pvmf_node_interface.h"
     28 #endif
     29 
     30 #ifndef PVMF_NODE_UTILS_H_INCLUDED
     31 #include "pvmf_node_utils.h"
     32 #endif
     33 
     34 #ifndef PVMF_PORT_BASE_IMPL_H_INCLUDED
     35 #include "pvmf_port_base_impl.h"
     36 #endif
     37 
     38 #ifndef PVMI_CONFIG_AND_CAPABILITY_UTILS_H_INCLUDED
     39 #include "pvmi_config_and_capability_utils.h"
     40 #endif
     41 
     42 #ifndef OSCL_PRIQUEUE_H_INCLUDED
     43 #include "oscl_priqueue.h"
     44 #endif
     45 
     46 #ifndef PV_MIME_STRING_UTILS_H_INCLUDED
     47 #include "pv_mime_string_utils.h"
     48 #endif
     49 
     50 class PVMFOMXEncNode;
     51 class PVMFOMXEncInputFormatCompareLess;
     52 //Default vector reserve size
     53 #define PVMF_OMX_ENC_NODE_PORT_VECTOR_RESERVE 10
     54 
     55 
     56 
     57 typedef enum
     58 {
     59     PVMF_OMX_ENC_NODE_PORT_TYPE_INPUT,
     60     PVMF_OMX_ENC_NODE_PORT_TYPE_OUTPUT,
     61 } PVMFOMXEncPortType;
     62 
     63 class PVMFOMXEncPort : public PvmfPortBaseImpl
     64         , public PvmiCapabilityAndConfigPortFormatImpl
     65 {
     66     public:
     67         PVMFOMXEncPort(int32 aTag, PVMFNodeInterface* aNode, const char*);
     68         ~PVMFOMXEncPort();
     69 
     70         // Implement pure virtuals from PvmiCapabilityAndConfigPortFormatImpl interface
     71         bool IsFormatSupported(PVMFFormatType);
     72         void FormatUpdated();
     73 
     74         // this port supports config interface
     75         void QueryInterface(const PVUuid &aUuid, OsclAny*&aPtr)
     76         {
     77             if (aUuid == PVMI_CAPABILITY_AND_CONFIG_PVUUID)
     78                 aPtr = (PvmiCapabilityAndConfig*)this;
     79             else
     80                 aPtr = NULL;
     81         }
     82 
     83         bool pvmiSetPortFormatSpecificInfoSync(OsclRefCounterMemFrag& aMemFrag);
     84         bool pvmiGetBufferAllocatorSpecificInfoSync(PvmiKeyType aIdentifier, PvmiKvp*& aParameters, int& aNumParamElements);
     85         bool releaseParametersSync(PvmiKvp*& aParameters, int& aNumParamElements);
     86 
     87         PVMFStatus Connect(PVMFPortInterface* aPort);
     88         void setParametersSync(PvmiMIOSession aSession,
     89                                PvmiKvp* aParameters,
     90                                int num_elements,
     91                                PvmiKvp * & aRet_kvp);
     92 
     93         PVMFStatus verifyParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters, int num_elements);
     94         PVMFStatus verifyConnectedPortParametersSync(const char* aFormatValType, OsclAny* aConfig);
     95         uint32 getTrackConfigSize()
     96         {
     97             return iTrackConfigSize;
     98         }
     99         uint8* getTrackConfig()
    100         {
    101             return iTrackConfig;
    102         }
    103 
    104         OSCL_IMPORT_REF PVMFStatus getParametersSync(PvmiMIOSession session,
    105                 PvmiKeyType identifier,
    106                 PvmiKvp*& parameters,
    107                 int& num_parameter_elements,
    108                 PvmiCapabilityContext context);
    109 
    110         OSCL_IMPORT_REF PVMFStatus releaseParameters(PvmiMIOSession session,
    111                 PvmiKvp* parameters,
    112                 int num_elements);
    113 
    114         // For AVC specific call
    115         void SendSPS_PPS(OsclMemoryFragment *aSPSs, int aNumSPSs, OsclMemoryFragment *aPPSs, int aNumPPSs);
    116 
    117     private:
    118         void Construct();
    119 
    120 /////////////////////////////////////////////////////////////////////////////////////
    121         ///encoder specific
    122         /**
    123         * Synchronous query of input port parameters
    124         */
    125         PVMFStatus GetInputParametersSync(PvmiKeyType identifier, PvmiKvp*& parameters,
    126                                           int& num_parameter_elements);
    127 
    128         /**
    129          * Synchronous query of output port parameters
    130          */
    131         PVMFStatus GetOutputParametersSync(PvmiKeyType identifier, PvmiKvp*& parameters,
    132                                            int& num_parameter_elements);
    133         /**
    134          * Allocate a specified number of key-value pairs and set the keys
    135          *
    136          * @param aKvp Output parameter to hold the allocated key-value pairs
    137          * @param aKey Key for the allocated key-value pairs
    138          * @param aNumParams Number of key-value pairs to be allocated
    139          * @return Completion status
    140          */
    141         PVMFStatus AllocateKvp(PvmiKvp*& aKvp, PvmiKeyType aKey, int32 aNumParams);
    142 
    143         /**
    144          * Verify one key-value pair parameter against capability of the port and
    145          * if the aSetParam flag is set, set the value of the parameter corresponding to
    146          * the key.
    147          *
    148          * @param aKvp Key-value pair parameter to be verified
    149          * @param aSetParam If true, set the value of parameter corresponding to the key.
    150          * @return PVMFSuccess if parameter is supported, else PVMFFailure
    151          */
    152         PVMFStatus VerifyAndSetParameter(PvmiKvp* aKvp, bool aSetParam = false);
    153 
    154         /**
    155          * Negotiates input port settings (format, video size and frame rate) and
    156          * configures the peer port and the container node with these settings
    157          *
    158          * @param aConfig Capability and config object for peer port
    159          * @return PVMFSuccess if settings are successfully negotiated.
    160          */
    161         PVMFStatus NegotiateInputSettings(PvmiCapabilityAndConfig* aConfig);
    162 
    163         /**
    164          * Negotiates output port settings and configures the peer port using settings
    165          * from the container node.
    166          *
    167          * @param aConfig Capability and config object for peer port
    168          * @return PVMFSuccess if settings are successfully negotiated.
    169          */
    170         PVMFStatus NegotiateOutputSettings(PvmiCapabilityAndConfig* aConfig);
    171         int32 Config_ParametersSync(PvmiCapabilityAndConfig*&, PvmiKvp*&, PvmiKvp*&);
    172         int32 PushKVP(OsclPriorityQueue<PvmiKvp*, OsclMemAllocator, Oscl_Vector<PvmiKvp*, OsclMemAllocator>, PVMFOMXEncInputFormatCompareLess>&, PvmiKvp*);
    173 
    174         OsclMemAllocator iAlloc;
    175 //////////////////////////////////////////////////////////////////////////
    176 
    177         PVLogger *iLogger;
    178         uint32 iNumFramesGenerated; //number of source frames generated.
    179         uint32 iNumFramesConsumed; //number of frames consumed & discarded.
    180         uint32 iTrackConfigSize;
    181         uint8* iTrackConfig;
    182         uint32 iTimescale;
    183         friend class PVMFOMXEncNode;
    184         PVMFOMXEncNode* iOMXNode;
    185 };
    186 
    187 class PVMFOMXEncInputFormatCompareLess
    188 {
    189     public:
    190         /**
    191          * The algorithm used in OsclPriorityQueue needs a compare function
    192          * that returns true when A's priority is less than B's
    193          * @return true if A's priority is less than B's, else false
    194          */
    195         int compare(PvmiKvp*& a, PvmiKvp*& b) const
    196         {
    197             return (PVMFOMXEncInputFormatCompareLess::GetPriority(a) <
    198                     PVMFOMXEncInputFormatCompareLess::GetPriority(b));
    199         }
    200 
    201         /**
    202          * Returns the priority of each command
    203          * @return A 0-based priority number. A lower number indicates lower priority.
    204          */
    205         static int GetPriority(PvmiKvp*& aKvp)
    206         {
    207             if (pv_mime_strcmp(aKvp->value.pChar_value, PVMF_MIME_YUV420) == 0)
    208             {
    209                 return 5;
    210             }
    211             else if (pv_mime_strcmp(aKvp->value.pChar_value, PVMF_MIME_YUV422) == 0)
    212             {
    213                 return 4;
    214             }
    215             else if (pv_mime_strcmp(aKvp->value.pChar_value, PVMF_MIME_YUV422_INTERLEAVED_UYVY) == 0)
    216             {
    217                 return 3;
    218             }
    219             else if (pv_mime_strcmp(aKvp->value.pChar_value, PVMF_MIME_YUV422_INTERLEAVED_YUYV) == 0)
    220             {
    221                 return 2;
    222             }
    223             else if (pv_mime_strcmp(aKvp->value.pChar_value, PVMF_MIME_RGB12) == 0)
    224             {
    225                 return 1;
    226             }
    227             else if (pv_mime_strcmp(aKvp->value.pChar_value, PVMF_MIME_RGB24) == 0)
    228             {
    229                 return 0;
    230             }
    231             else
    232             {
    233                 return 0;
    234             }
    235         }
    236 };
    237 #endif // PVMF_OMX_ENC_PORT_H_INCLUDED
    238