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 * @file pvmp4ffcn_port.h 20 * @brief Port for PVMp4FFComposerNode 21 */ 22 23 #ifndef PVMP4FFCN_PORT_H_INCLUDED 24 #define PVMP4FFCN_PORT_H_INCLUDED 25 26 #ifndef OSCL_BASE_H_INCLUDED 27 #include "oscl_base.h" 28 #endif 29 #ifndef OSCL_SCHEDULER_AO_H_INCLUDED 30 #include "oscl_scheduler_ao.h" 31 #endif 32 #ifndef PVMF_PORT_BASE_IMPL_H_INCLUDED 33 #include "pvmf_port_base_impl.h" 34 #endif 35 #ifndef PVMF_NODE_INTERFACE_H_INCLUDED 36 #include "pvmf_node_interface.h" 37 #endif 38 #ifndef PVMI_CONFIG_AND_CAPABILITY_H_INCLUDED 39 #include "pvmi_config_and_capability.h" 40 #endif 41 #ifndef TEXTSAMPLEDESCINFO_H 42 #include "textsampledescinfo.h" 43 #endif 44 45 class PVMp4FFComposerNode; 46 class PVLogger; 47 48 typedef enum 49 { 50 PVMP4FFCN_RATE_CONTROL_UNKNOWN = 0, 51 PVMP4FFCN_RATE_CONTROL_CBR = 1, 52 PVMP4FFCN_RATE_CONTROL_VBR = 2, 53 PVMP4FFCN_RATE_CONTROL_LOW_DELAY = 3 54 } PVMP4FFCNRateControlType; 55 56 struct PVMP4FFCNFormatSpecificConfig 57 { 58 uint32 iBitrate; 59 uint32 iTimescale; 60 61 // Video configuration 62 OsclFloat iFrameRate; 63 uint32 iIFrameInterval; 64 uint32 iWidth; 65 uint32 iHeight; 66 PVMP4FFCNRateControlType iRateControlType; 67 68 // H263 configuration 69 uint8 iH263Profile; 70 uint8 iH263Level; 71 72 // Audio Encode Params 73 uint32 iNumberOfChannels; 74 uint32 iBitsPerSample; 75 uint32 iSamplingRate; 76 }; 77 78 class PVMp4FFComposerPort : public PvmfPortBaseImpl, 79 public PvmiCapabilityAndConfig, 80 public PVMFPortActivityHandler, 81 public OsclActiveObject 82 { 83 public: 84 PVMp4FFComposerPort(int32 aTag, PVMp4FFComposerNode* aNode, int32 aPriority, const char* aName = NULL); 85 ~PVMp4FFComposerPort(); 86 87 // Overload PvmfPortBaseImpl methods 88 OSCL_IMPORT_REF PVMFStatus Connect(PVMFPortInterface* aPort); 89 OSCL_IMPORT_REF PVMFStatus PeerConnect(PVMFPortInterface* aPort); 90 OSCL_IMPORT_REF void QueryInterface(const PVUuid& aUuid, OsclAny*& aPtr); 91 92 // Implement pure virtuals from PvmiCapabilityAndConfig interface 93 OSCL_IMPORT_REF void setObserver(PvmiConfigAndCapabilityCmdObserver* aObserver); 94 OSCL_IMPORT_REF PVMFStatus getParametersSync(PvmiMIOSession aSession, PvmiKeyType aIdentifier, 95 PvmiKvp*& aParameters, int& num_parameter_elements, 96 PvmiCapabilityContext aContext); 97 OSCL_IMPORT_REF PVMFStatus releaseParameters(PvmiMIOSession aSession, PvmiKvp* aParameters, int num_elements); 98 OSCL_IMPORT_REF void createContext(PvmiMIOSession aSession, PvmiCapabilityContext& aContext); 99 OSCL_IMPORT_REF void setContextParameters(PvmiMIOSession aSession, PvmiCapabilityContext& aContext, 100 PvmiKvp* aParameters, int num_parameter_elements); 101 OSCL_IMPORT_REF void DeleteContext(PvmiMIOSession aSession, PvmiCapabilityContext& aContext); 102 OSCL_IMPORT_REF void setParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters, 103 int num_elements, PvmiKvp * & aRet_kvp); 104 OSCL_IMPORT_REF PVMFCommandId setParametersAsync(PvmiMIOSession aSession, PvmiKvp* aParameters, 105 int num_elements, PvmiKvp*& aRet_kvp, OsclAny* context = NULL); 106 OSCL_IMPORT_REF uint32 getCapabilityMetric(PvmiMIOSession aSession); 107 OSCL_IMPORT_REF PVMFStatus verifyParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters, int num_elements); 108 109 // For node to notify the port that it's ready to process incoming message 110 void ProcessIncomingMsgReady(); 111 112 // From PVMFPortActivityHandler 113 void HandlePortActivity(const PVMFPortActivity& aActivity); 114 115 // Track ID 116 void SetTrackId(int32 aTrackId) 117 { 118 iTrackId = aTrackId; 119 } 120 int32 GetTrackId() 121 { 122 return iTrackId; 123 } 124 125 // Provide port configuration to node 126 void SetFormat(PVMFFormatType aFormat) 127 { 128 iFormat = aFormat; 129 iMimeType = aFormat.getMIMEStrPtr(); 130 } 131 PVMFFormatType GetFormat() 132 { 133 return iFormat; 134 } 135 OSCL_String& GetMimeType() 136 { 137 return iMimeType; 138 } 139 void SetCodecType(int32 aCodecType) 140 { 141 iCodecType = aCodecType; 142 } 143 int32 GetCodecType() 144 { 145 return iCodecType; 146 } 147 PVMP4FFCNFormatSpecificConfig* GetFormatSpecificConfig() 148 { 149 PvmiCapabilityAndConfig* config = NULL; 150 if (iConnectedPort) 151 { 152 OsclAny* temp = NULL; 153 iConnectedPort->QueryInterface(PVMI_CAPABILITY_AND_CONFIG_PVUUID, temp); 154 config = OSCL_STATIC_CAST(PvmiCapabilityAndConfig*, temp); 155 if (config) 156 { 157 GetInputParametersFromPeer(config); 158 } 159 } 160 return &iFormatSpecificConfig; 161 } 162 163 164 // Reference track settings 165 void SetReferencePort(PVMp4FFComposerPort* aPort) 166 { 167 iReferencePort = aPort; 168 } 169 const PVMp4FFComposerPort* GetReferencePort() 170 { 171 return iReferencePort; 172 } 173 174 // Real-time TS routines 175 uint32 GetLastTS() 176 { 177 return iLastTS; 178 } 179 void SetLastTS(uint32 aTS) 180 { 181 iLastTS = aTS; 182 } 183 184 friend class PVMp4FFComposerNode; 185 private: 186 // Implement pure virtuals from OsclActiveObject 187 void Run(); 188 189 /** 190 * Allocate a specified number of key-value pairs and set the keys 191 * 192 * @param aKvp Output parameter to hold the allocated key-value pairs 193 * @param aKey Key for the allocated key-value pairs 194 * @param aNumParams Number of key-value pairs to be allocated 195 * @return Completion status 196 */ 197 PVMFStatus AllocateKvp(PvmiKvp*& aKvp, PvmiKeyType aKey, int32 aNumParams); 198 199 /** 200 * Verify one key-value pair parameter against capability of the port and 201 * if the aSetParam flag is set, set the value of the parameter corresponding to 202 * the key. 203 * 204 * @param aKvp Key-value pair parameter to be verified 205 * @param aSetParam If true, set the value of parameter corresponding to the key. 206 * @return PVMFSuccess if parameter is supported, else PVMFFailure 207 */ 208 PVMFStatus VerifyAndSetParameter(PvmiKvp* aKvp, bool aSetParam = false); 209 210 /** 211 * Negotiates input port settings (format, video size and frame rate) and 212 * configures the peer port and the container node with these settings 213 * 214 * @param aConfig Capability and config object for peer port 215 * @return PVMFSuccess if settings are successfully negotiated. 216 */ 217 PVMFStatus NegotiateInputSettings(PvmiCapabilityAndConfig* aConfig); 218 219 /** 220 * Query peer port for properties of incoming data. 221 * @return Completion status 222 */ 223 PVMFStatus GetInputParametersFromPeer(PvmiCapabilityAndConfig* aConfig); 224 225 /** 226 * Query peer port for properties of incoming data. 227 * @return Completion status 228 */ 229 PVMFStatus GetVideoInputParametersFromPeer(PvmiCapabilityAndConfig* aConfig); 230 231 private: 232 233 // Container node 234 PVMp4FFComposerNode* iNode; 235 236 // Port configuration 237 int32 iTrackId; 238 PVMFFormatType iFormat; 239 int32 iCodecType; //integer value to avoid formatype comparisons 240 PVMP4FFCNFormatSpecificConfig iFormatSpecificConfig; 241 PVMp4FFComposerPort* iReferencePort; 242 OsclMemoryFragment* memfrag_sps; 243 OsclMemoryFragment* memfrag_pps; 244 // Real-time TS 245 uint32 iLastTS; 246 247 OsclMemAllocator iAlloc; 248 PVLogger* iLogger; 249 bool iEndOfDataReached; 250 251 //logging 252 OSCL_HeapString<OsclMemAllocator> iMimeType; 253 }; 254 255 #endif // PVMP4FFCN_PORT_H_INCLUDED 256