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 * 20 * @file pvmf_loopback_node.h 21 * @brief Simple loopback node. Incoming data is immediately routed to outport if it exists 22 * 23 */ 24 25 #ifndef PVMF_LOOPBACK_NODE_H_INCLUDED 26 #define PVMF_LOOPBACK_NODE_H_INCLUDED 27 28 #ifndef OSCL_BASE_H_INCLUDED 29 #include "oscl_base.h" 30 #endif 31 #ifndef OSCLCONFIG_IO_H_INCLUDED 32 #include "osclconfig_io.h" 33 #endif 34 #ifndef OSCL_FILE_IO_H_INCLUDED 35 #include "oscl_file_io.h" 36 #endif 37 #ifndef OSCL_PRIQUEUE_H_INCLUDED 38 #include "oscl_priqueue.h" 39 #endif 40 #ifndef OSCL_SCHEDULER_AO_H_INCLUDED 41 #include "oscl_scheduler_ao.h" 42 #endif 43 44 #ifndef PVMF_FORMAT_TYPE_H_INCLUDED 45 #include "pvmf_format_type.h" 46 #endif 47 48 #ifndef PVMF_SIMPLE_MEDIA_BUFFER_H_INCLUDED 49 #include "pvmf_simple_media_buffer.h" 50 #endif 51 52 #ifndef PVMF_MEDIA_DATA_H_INCLUDED 53 #include "pvmf_media_data.h" 54 #endif 55 56 #ifndef PVMF_NODE_INTERFACE_H_INCLUDED 57 #include "pvmf_node_interface.h" 58 #endif 59 60 #ifndef PVMF_NODE_UTIL_H_INCLUDED 61 #include "pvmf_node_utils.h" 62 #endif 63 64 #ifndef PVMF_LOOPBACK_IOPORT_H_INCLUDED 65 #include "pvmf_loopback_ioport.h" 66 #endif 67 68 #ifndef OSCL_MEM_MEMPOOL_H_INCLUDED 69 #include "oscl_mem_mempool.h" 70 #endif 71 72 #ifndef PVMF_MEDIA_DATA_H_INCLUDED 73 #include "pvmf_media_data.h" 74 #endif 75 76 #ifndef PVMF_SIMPLE_MEDIA_BUFFER_H_INCLUDED 77 #include "pvmf_simple_media_buffer.h" 78 #endif 79 80 //////////////////////////////////////////////////////////////////////////// 81 82 83 //Default vector reserve size 84 #define PVMF_LOOPBACK_NODE_COMMAND_VECTOR_RESERVE 10 85 86 //Starting value for command IDs 87 #define PVMF_LOOPBACK_NODE_COMMAND_ID_START 6000 88 89 90 typedef enum 91 { 92 PVMF_LOOPBACKNODE_PORT_TYPE_LOOPBACK = 3 93 } PVMFLoopbackNodePortType; 94 95 //memory allocator type for this node. 96 typedef OsclMemAllocator PVMFLoopbackNodeAllocator; 97 98 /////////////////////////////////////////////////////////////////////////// 99 class PVMFLoopbackAlloc : public Oscl_DefAlloc 100 { 101 public: 102 void* allocate(const uint32 size) 103 { 104 void* tmp = (void*)oscl_malloc(size); 105 return tmp; 106 } 107 108 void deallocate(void* p) 109 { 110 oscl_free(p); 111 } 112 }; 113 114 115 typedef PVMFGenericNodeCommand<PVMFLoopbackNodeAllocator> PVMFLoopbackNodeCommandBase; 116 class PVMFLoopbackNodeCmd: public PVMFGenericNodeCommand<PVMFLoopbackNodeAllocator> 117 { 118 public: 119 //constructor for Custom2 command 120 void Construct(PVMFSessionId s, int32 cmd, int32 arg1, int32 arg2, int32& arg3, const OsclAny*aContext) 121 { 122 PVMFLoopbackNodeCommandBase::Construct(s, cmd, aContext); 123 iParam1 = (OsclAny*)arg1; 124 iParam2 = (OsclAny*)arg2; 125 iParam3 = (OsclAny*) & arg3; 126 } 127 void Parse(int32&arg1, int32&arg2, int32*&arg3) 128 { 129 arg1 = (int32)iParam1; 130 arg2 = (int32)iParam2; 131 arg3 = (int32*)iParam3; 132 } 133 }; 134 135 enum PVMFLoopbackNodeCmdType 136 { 137 PVMFLOOPBACK_NODE_CMD_INIT, 138 PVMFLOOPBACK_NODE_CMD_REQUESTPORT, 139 PVMFLOOPBACK_NODE_CMD_START, 140 PVMFLOOPBACK_NODE_CMD_PAUSE, 141 PVMFLOOPBACK_NODE_CMD_STOP, 142 PVMFLOOPBACK_NODE_CMD_RELEASEPORT, 143 PVMFLOOPBACK_NODE_CMD_RESET, 144 PVMFLOOPBACK_NODE_CMD_PREPARE, 145 PVMFLOOPBACK_NODE_CMD_FLUSH, 146 PVMFLOOPBACK_NODE_CMD_CANCELCMD, 147 PVMFLOOPBACK_NODE_CMD_CANCELALL, 148 PVMFLOOPBACK_NODE_CMD_INVALID 149 }; 150 151 typedef PVMFNodeCommandQueue<PVMFLoopbackNodeCmd, PVMFLoopbackNodeAllocator> PVMFLoopbackNodeCmdQ; 152 153 154 // Forward declaration 155 class PVMFLoopbackIOPort; 156 157 //////////////////////////////////////////////////////////////////////////// 158 class PVMFLoopbackNode : public PVMFNodeInterface 159 , public OsclActiveObject 160 { 161 public: 162 163 OSCL_IMPORT_REF static PVMFNodeInterface* Create(); 164 OSCL_IMPORT_REF ~PVMFLoopbackNode(); 165 166 // Virtual functions of PVMFNodeInterface 167 //from PVMFNodeInterface 168 OSCL_IMPORT_REF PVMFStatus ThreadLogon(); 169 OSCL_IMPORT_REF PVMFStatus ThreadLogoff(); 170 OSCL_IMPORT_REF PVMFStatus GetCapability(PVMFNodeCapability& aNodeCapability); 171 OSCL_IMPORT_REF PVMFPortIter* GetPorts(const PVMFPortFilter* aFilter = NULL) 172 { 173 OSCL_UNUSED_ARG(aFilter); 174 return &iPortVector; 175 } 176 OSCL_IMPORT_REF PVMFCommandId QueryUUID(PVMFSessionId, const PvmfMimeString& aMimeType, 177 Oscl_Vector<PVUuid, PVMFLoopbackNodeAllocator>& aUuids, 178 bool aExactUuidsOnly = false, 179 const OsclAny* aContext = NULL); 180 OSCL_IMPORT_REF PVMFCommandId QueryInterface(PVMFSessionId, const PVUuid& aUuid, 181 PVInterface*& aInterfacePtr, 182 const OsclAny* aContext = NULL); 183 184 OSCL_IMPORT_REF PVMFCommandId RequestPort(PVMFSessionId 185 , int32 aPortTag, const PvmfMimeString* aPortConfig = NULL, const OsclAny* aContext = NULL); 186 OSCL_IMPORT_REF PVMFCommandId ReleasePort(PVMFSessionId, PVMFPortInterface& aPort, const OsclAny* aContext = NULL); 187 188 OSCL_IMPORT_REF PVMFCommandId Init(PVMFSessionId, const OsclAny* aContext = NULL); 189 OSCL_IMPORT_REF PVMFCommandId Prepare(PVMFSessionId, const OsclAny* aContext = NULL); 190 OSCL_IMPORT_REF PVMFCommandId Start(PVMFSessionId, const OsclAny* aContext = NULL); 191 OSCL_IMPORT_REF PVMFCommandId Stop(PVMFSessionId, const OsclAny* aContext = NULL); 192 OSCL_IMPORT_REF PVMFCommandId Flush(PVMFSessionId, const OsclAny* aContext = NULL); 193 OSCL_IMPORT_REF PVMFCommandId Pause(PVMFSessionId, const OsclAny* aContext = NULL); 194 OSCL_IMPORT_REF PVMFCommandId Reset(PVMFSessionId, const OsclAny* aContext = NULL); 195 OSCL_IMPORT_REF PVMFCommandId CancelAllCommands(PVMFSessionId, const OsclAny* aContextData = NULL); 196 OSCL_IMPORT_REF PVMFCommandId CancelCommand(PVMFSessionId, PVMFCommandId aCmdId, const OsclAny* aContextData = NULL); 197 198 199 // For input port to access private function / data 200 friend class PVMFLoopbackIOPort; 201 //from PVMFPortActivityHandler. 202 void HandlePortActivity(const PVMFPortActivity& aActivity) 203 { 204 OSCL_UNUSED_ARG(aActivity); 205 }; 206 207 PVMFPortVector<PVMFLoopbackIOPort, PVMFLoopbackNodeAllocator> iPortVector; 208 209 private: 210 PVMFLoopbackNode(int32 aPriority); 211 void DoCancel(); 212 void Run(); 213 214 //Command processing 215 PVMFCommandId QueueCommandL(PVMFLoopbackNodeCmd&); 216 bool ProcessCommand(PVMFLoopbackNodeCmd&); 217 void CommandComplete(PVMFLoopbackNodeCmdQ&, PVMFLoopbackNodeCmd&, PVMFStatus, OsclAny* aData = NULL); 218 bool FlushPending(); 219 PVMFLoopbackNodeCmdQ iInputCommands; 220 PVMFLoopbackNodeCmdQ iCurrentCommand; 221 222 //Command handlers. 223 void DoReset(PVMFLoopbackNodeCmd&); 224 void DoRequestPort(PVMFLoopbackNodeCmd&); 225 void DoReleasePort(PVMFLoopbackNodeCmd&); 226 void DoInit(PVMFLoopbackNodeCmd&); 227 void DoPrepare(PVMFLoopbackNodeCmd&); 228 void DoStart(PVMFLoopbackNodeCmd&); 229 void DoStop(PVMFLoopbackNodeCmd&); 230 void DoFlush(PVMFLoopbackNodeCmd&); 231 void DoPause(PVMFLoopbackNodeCmd&); 232 233 // Event reporting 234 void ReportErrorEvent(PVMFEventType aEventType, OsclAny* aEventData = NULL); 235 void ReportInfoEvent(PVMFEventType aEventType, OsclAny* aEventData = NULL); 236 void SetState(TPVMFNodeInterfaceState); 237 238 239 PVMFCommandId iCmdIdCounter; 240 241 // Input port 242 PVMFLoopbackIOPort* iIOPort; 243 244 PVMFNodeCapability iCapability; 245 PVLogger *iLogger; 246 247 PVMFNodeCmdStatusObserver *iObserver; 248 }; 249 250 #endif // PVMF_LOOPBACK_NODE_H_INCLUDED 251