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 QueryInterface(const PVUuid & aUuid,OsclAny * & aPtr)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 85 PVMFStatus Connect(PVMFPortInterface* aPort); 86 void setParametersSync(PvmiMIOSession aSession, 87 PvmiKvp* aParameters, 88 int num_elements, 89 PvmiKvp * & aRet_kvp); 90 91 PVMFStatus verifyParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters, int num_elements); 92 PVMFStatus verifyConnectedPortParametersSync(const char* aFormatValType, OsclAny* aConfig); getTrackConfigSize()93 uint32 getTrackConfigSize() 94 { 95 return iTrackConfigSize; 96 } getTrackConfig()97 uint8* getTrackConfig() 98 { 99 return iTrackConfig; 100 } 101 102 OSCL_IMPORT_REF PVMFStatus getParametersSync(PvmiMIOSession session, 103 PvmiKeyType identifier, 104 PvmiKvp*& parameters, 105 int& num_parameter_elements, 106 PvmiCapabilityContext context); 107 108 OSCL_IMPORT_REF PVMFStatus releaseParameters(PvmiMIOSession session, 109 PvmiKvp* parameters, 110 int num_elements); 111 112 // For AVC specific call 113 void SendSPS_PPS(OsclMemoryFragment *aSPSs, int aNumSPSs, OsclMemoryFragment *aPPSs, int aNumPPSs); 114 115 private: 116 void Construct(); 117 118 ///////////////////////////////////////////////////////////////////////////////////// 119 ///encoder specific 120 /** 121 * Synchronous query of input port parameters 122 */ 123 PVMFStatus GetInputParametersSync(PvmiKeyType identifier, PvmiKvp*& parameters, 124 int& num_parameter_elements); 125 126 /** 127 * Synchronous query of output port parameters 128 */ 129 PVMFStatus GetOutputParametersSync(PvmiKeyType identifier, PvmiKvp*& parameters, 130 int& num_parameter_elements); 131 /** 132 * Allocate a specified number of key-value pairs and set the keys 133 * 134 * @param aKvp Output parameter to hold the allocated key-value pairs 135 * @param aKey Key for the allocated key-value pairs 136 * @param aNumParams Number of key-value pairs to be allocated 137 * @return Completion status 138 */ 139 PVMFStatus AllocateKvp(PvmiKvp*& aKvp, PvmiKeyType aKey, int32 aNumParams); 140 141 /** 142 * Verify one key-value pair parameter against capability of the port and 143 * if the aSetParam flag is set, set the value of the parameter corresponding to 144 * the key. 145 * 146 * @param aKvp Key-value pair parameter to be verified 147 * @param aSetParam If true, set the value of parameter corresponding to the key. 148 * @return PVMFSuccess if parameter is supported, else PVMFFailure 149 */ 150 PVMFStatus VerifyAndSetParameter(PvmiKvp* aKvp, bool aSetParam = false); 151 152 /** 153 * Negotiates input port settings (format, video size and frame rate) and 154 * configures the peer port and the container node with these settings 155 * 156 * @param aConfig Capability and config object for peer port 157 * @return PVMFSuccess if settings are successfully negotiated. 158 */ 159 PVMFStatus NegotiateInputSettings(PvmiCapabilityAndConfig* aConfig); 160 161 /** 162 * Negotiates output port settings and configures the peer port using settings 163 * from the container node. 164 * 165 * @param aConfig Capability and config object for peer port 166 * @return PVMFSuccess if settings are successfully negotiated. 167 */ 168 PVMFStatus NegotiateOutputSettings(PvmiCapabilityAndConfig* aConfig); 169 int32 Config_ParametersSync(PvmiCapabilityAndConfig*&, PvmiKvp*&, PvmiKvp*&); 170 int32 PushKVP(OsclPriorityQueue<PvmiKvp*, OsclMemAllocator, Oscl_Vector<PvmiKvp*, OsclMemAllocator>, PVMFOMXEncInputFormatCompareLess>&, PvmiKvp*); 171 172 OsclMemAllocator iAlloc; 173 ////////////////////////////////////////////////////////////////////////// 174 175 PVLogger *iLogger; 176 uint32 iNumFramesGenerated; //number of source frames generated. 177 uint32 iNumFramesConsumed; //number of frames consumed & discarded. 178 uint32 iTrackConfigSize; 179 uint8* iTrackConfig; 180 uint32 iTimescale; 181 friend class PVMFOMXEncNode; 182 PVMFOMXEncNode* iOMXNode; 183 }; 184 185 class PVMFOMXEncInputFormatCompareLess 186 { 187 public: 188 /** 189 * The algorithm used in OsclPriorityQueue needs a compare function 190 * that returns true when A's priority is less than B's 191 * @return true if A's priority is less than B's, else false 192 */ compare(PvmiKvp * & a,PvmiKvp * & b)193 int compare(PvmiKvp*& a, PvmiKvp*& b) const 194 { 195 return (PVMFOMXEncInputFormatCompareLess::GetPriority(a) < 196 PVMFOMXEncInputFormatCompareLess::GetPriority(b)); 197 } 198 199 /** 200 * Returns the priority of each command 201 * @return A 0-based priority number. A lower number indicates lower priority. 202 */ GetPriority(PvmiKvp * & aKvp)203 static int GetPriority(PvmiKvp*& aKvp) 204 { 205 if (pv_mime_strcmp(aKvp->value.pChar_value, PVMF_MIME_YUV420) == 0) 206 { 207 return 3; 208 } 209 else if (pv_mime_strcmp(aKvp->value.pChar_value, PVMF_MIME_YUV422) == 0) 210 { 211 return 2; 212 } 213 else if (pv_mime_strcmp(aKvp->value.pChar_value, PVMF_MIME_RGB12) == 0) 214 { 215 return 1; 216 } 217 else if (pv_mime_strcmp(aKvp->value.pChar_value, PVMF_MIME_RGB24) == 0) 218 { 219 return 0; 220 } 221 else 222 { 223 return 0; 224 } 225 } 226 }; 227 #endif // PVMF_OMX_ENC_PORT_H_INCLUDED 228