• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 pv_comms_io_node.h
20  * @brief
21  */
22 
23 #ifndef PV_COMMS_IO_NODE_H_INCLUDED
24 #define PV_COMMS_IO_NODE_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 OSCL_PRIQUEUE_H_INCLUDED
33 #include "oscl_priqueue.h"
34 #endif
35 #ifndef PVLOGGER_H_INCLUDED
36 #include "pvlogger.h"
37 #endif
38 #ifndef PVMF_RETURN_CODES_H_INCLUDED
39 #include "pvmf_return_codes.h"
40 #endif
41 #ifndef PVMF_NODE_INTERFACE_H_INCLUDED
42 #include "pvmf_node_interface.h"
43 #endif
44 #ifndef PVMF_NODE_UTILS_H_INCLUDED
45 #include "pvmf_node_utils.h"
46 #endif
47 #ifndef PVMF_PORT_INTERFACE_H_INCLUDED
48 #include "pvmf_port_interface.h"
49 #endif
50 #ifndef PVMI_MIO_CONTROL_H_INCLUDED
51 #include "pvmi_mio_control.h"
52 #endif
53 #ifndef PVMI_MEDIA_IO_OBSERVER_H_INCLUDED
54 #include "pvmi_media_io_observer.h"
55 #endif
56 #ifndef PVMI_CONFIG_AND_CAPABILITY_H_INCLUDED
57 #include "pvmi_config_and_capability.h"
58 #endif
59 #ifndef PVMF_NODES_SYNC_CONTROL_H_INCLUDED
60 #include "pvmf_nodes_sync_control.h"
61 #endif
62 #ifndef PV_COMMS_IO_NODE_PORT_H_INCLUDED
63 #include "pv_comms_io_node_port.h"
64 #endif
65 #ifndef PV_COMMS_IO_NODE_EVENTS_H_INCLUDED
66 #include "pv_comms_io_node_events.h"
67 #endif
68 
69 /** Port tags.  For now engine must use these directly since
70 * port tag query is not yet implemented
71 */
72 enum PVCommsIONodePortTags
73 {
74     PVMF_COMMSIO_NODE_OUTPUT_PORT_TAG = 0x01,
75     PVMF_COMMSIO_NODE_INPUT_PORT_TAG = 0x02,
76     PVMF_COMMSIO_NODE_IO_PORT_TAG = 0x03, //bitwise OR of previous two tags
77 };
78 
79 const PVMFStatus PVMFInfoEndOfInputPortData = PVMFInfoLast + 1;
80 const PVMFStatus PVMFInfoEndOfOutputPortData = PVMFInfoLast + 2;
81 
82 class MIOControlContextElement
83 {
84 
85     public:
MIOControlContextElement()86         MIOControlContextElement()
87         {
88             iControl = NULL;
89             iMediaSession = 0;
90             iMediaIOConfig = NULL;
91         };
92         bool operator== (const MIOControlContextElement &context)
93         {
94             return (iControl == context.iControl);
95         }
96         MIOControlContextElement &operator= (const MIOControlContextElement &context)
97         {
98             Copy(context);
99             return (*this);
100         }
isValid()101         bool isValid()
102         {
103             return iControl ? true : false;
104         };
hasConfig()105         bool hasConfig()
106         {
107             return iMediaIOConfig ? true : false;
108         };
ThreadLogon()109         void ThreadLogon()
110         {
111             if (iControl)
112                 iControl->ThreadLogon();
113         };
ThreadLogoff()114         void ThreadLogoff()
115         {
116             if (iControl)
117             {
118                 iControl->ThreadLogoff();
119                 iControl->disconnect(iMediaSession);
120             }
121         };
122 
123         PvmiMIOControl *iControl;
124         PvmiMIOSession iMediaSession;
125         PvmiCapabilityAndConfig *iMediaIOConfig;
126     private:
Copy(const MIOControlContextElement & aSettings)127         void Copy(const MIOControlContextElement &aSettings)
128         {
129             iControl = aSettings.iControl;
130             iMediaSession = aSettings.iMediaSession;
131             iMediaIOConfig = aSettings.iMediaIOConfig;
132         }
133 };
134 
135 class MIOControlContextSet
136 {
137     public:
MIOControlContextSet()138         MIOControlContextSet(): iMediaInputElement(NULL), iMediaOutputElement(NULL) {};
isUni()139         bool isUni()
140         {
141             return (iMediaInputElement == NULL || iMediaOutputElement == NULL);
142         };
isIOProxy()143         bool isIOProxy()
144         {
145             return (!isUni() && iMediaInputElement == iMediaOutputElement);
146         };
isEmpty()147         bool isEmpty()
148         {
149             return (iMediaInputElement == NULL && iMediaOutputElement == NULL);
150         };
151         MIOControlContextElement *iMediaInputElement;
152         MIOControlContextElement *iMediaOutputElement;
153 };
154 
155 /**
156  * Command queue for internal use in the node
157  */
158 
159 //command type enums.  This node has one extra async command.
160 enum PVCommsIONodeCmdType
161 {
162     PVMF_COMMSIONODE_SKIPMEDIADATA = PVMF_GENERIC_NODE_COMMAND_LAST
163     , PVMF_COMMSIONODE_STARTMIO
164     //startmio command is generated internally by the input ports.
165 };
166 
167 //command class
168 class PVCommsIONodeCmd: public PVMFGenericNodeCommand<OsclMemAllocator>
169 {
170     public:
171 
172         //this holds an event code associated with the command status
173         PVMFStatus iEventCode;
174         MIOControlContextElement *iControlContext;
175 
176         //need to override base construct routine due to additional parameter.
BaseConstruct(PVMFSessionId s,int32 aCmd,const OsclAny * aContext)177         void BaseConstruct(PVMFSessionId s, int32 aCmd, const OsclAny* aContext)
178         {
179             PVMFGenericNodeCommand<OsclMemAllocator>::BaseConstruct(s, aCmd, aContext);
180             iEventCode = PVCommsIONodeErr_First;
181             iControlContext = NULL;
182         }
183         //need to override base copy routine due to additional parameter
Copy(PVCommsIONodeCmd & aCmd)184         void Copy(PVCommsIONodeCmd& aCmd)
185         {
186             PVMFGenericNodeCommand<OsclMemAllocator>::Copy(aCmd);
187             iEventCode = aCmd.iEventCode;
188             iControlContext = aCmd.iControlContext;
189         }
190 
191 
192 };
193 //define a synonym for the base class.
194 //a typedef creates compiler warnings so use #define
195 #define PVCommsIONodeCmdBase PVMFGenericNodeCommand<OsclMemAllocator>
196 
197 //command queue type
198 typedef PVMFNodeCommandQueue<PVCommsIONodeCmd, OsclMemAllocator> PVCommsIONodeCmdQ;
199 
200 
201 /**
202  * class PVCommsIONode is a node wrapper around the io interface
203  */
204 class PVCommsIONode : public OsclActiveObject,
205         public PVMFNodeInterface,
206         public PvmiMIOObserver
207 {
208     public:
209         static PVMFNodeInterface* Create(PvmiMIOControl* aMIOControl, bool logBitstream = false);
210         static PVMFNodeInterface* Create(PvmiMIOControl* aMIOInputControl,
211                                          PvmiMIOControl* aMIOOutputControl, bool logBitstream = false);
212         static void Release(PVMFNodeInterface*);
213 
214         // PVMFNodeInterface implementation
215         OSCL_IMPORT_REF PVMFStatus ThreadLogon();
216         OSCL_IMPORT_REF PVMFStatus ThreadLogoff();
217         OSCL_IMPORT_REF PVMFStatus GetCapability(PVMFNodeCapability& aNodeCapability);
218         OSCL_IMPORT_REF PVMFPortIter* GetPorts(const PVMFPortFilter* aFilter = NULL);
219         OSCL_IMPORT_REF PVMFCommandId QueryUUID(PVMFSessionId aSession
220                                                 , const PvmfMimeString& aMimeType
221                                                 , Oscl_Vector<PVUuid, OsclMemAllocator>& aUuids
222                                                 , bool aExactUuidsOnly = false
223                                                                          , const OsclAny* aContext = NULL) ;
224         OSCL_IMPORT_REF PVMFCommandId QueryInterface(PVMFSessionId aSession
225                 , const PVUuid& aUuid
226                 , PVInterface*& aInterfacePtr
227                 , const OsclAny* aContext = NULL) ;
228         OSCL_IMPORT_REF PVMFCommandId RequestPort(PVMFSessionId aSession
229                 , int32 aPortTag
230                 , const PvmfMimeString* aPortConfig = NULL
231                                                       , const OsclAny* aContext = NULL);
232         OSCL_IMPORT_REF PVMFCommandId ReleasePort(PVMFSessionId aSession
233                 , PVMFPortInterface& aPort
234                 , const OsclAny* aContext = NULL);
235         OSCL_IMPORT_REF PVMFCommandId Init(PVMFSessionId aSession
236                                            , const OsclAny* aContext = NULL);
237         OSCL_IMPORT_REF PVMFCommandId Prepare(PVMFSessionId aSession
238                                               , const OsclAny* aContext = NULL);
239         OSCL_IMPORT_REF PVMFCommandId Start(PVMFSessionId aSession
240                                             , const OsclAny* aContext = NULL);
241         OSCL_IMPORT_REF PVMFCommandId Stop(PVMFSessionId aSession
242                                            , const OsclAny* aContext = NULL);
243         OSCL_IMPORT_REF PVMFCommandId Flush(PVMFSessionId aSession
244                                             , const OsclAny* aContext = NULL);
245         OSCL_IMPORT_REF PVMFCommandId Pause(PVMFSessionId aSession
246                                             , const OsclAny* aContext = NULL);
247         OSCL_IMPORT_REF PVMFCommandId Reset(PVMFSessionId aSession
248                                             , const OsclAny* aContext = NULL);
249         OSCL_IMPORT_REF PVMFCommandId CancelAllCommands(PVMFSessionId aSession
250                 , const OsclAny* aContextData = NULL) ;
251         OSCL_IMPORT_REF PVMFCommandId CancelCommand(PVMFSessionId aSession
252                 , PVMFCommandId aCmdId
253                 , const OsclAny* aContextData = NULL) ;
HandlePortActivity(const PVMFPortActivity & aActivity)254         void HandlePortActivity(const PVMFPortActivity& aActivity)
255         {
256             OSCL_UNUSED_ARG(aActivity);
257         }
258 
259         // Pure virtual from PvInterface
260         OSCL_IMPORT_REF void addRef();
261         OSCL_IMPORT_REF void removeRef();
262         OSCL_IMPORT_REF bool queryInterface(const PVUuid& uuid, PVInterface*& iface);
263 
264         // PvmiMIOObserver implementation
265         OSCL_IMPORT_REF void RequestCompleted(const PVMFCmdResp& aResponse);
266         OSCL_IMPORT_REF void ReportErrorEvent(PVMFEventType aEventType, PVInterface* aExtMsg = NULL);
267         OSCL_IMPORT_REF void ReportInfoEvent(PVMFEventType aEventType, PVInterface* aExtMsg = NULL);
268 
269         friend class PVCommsIONodePort;
270 
271     private:
272         typedef enum
273         {
274             ENone
275             , EQueryCapability
276             , EInit
277             , EStart
278             , EPause
279             , EStop
280         } EMioRequest;
281 
282         PVCommsIONode(bool iLogBitstream);
283         ~PVCommsIONode();
284         void ConstructL(PvmiMIOControl* aIOInterfacePtr);
285         void ConstructL(PvmiMIOControl* aMediaInputPtr, PvmiMIOControl* aMediaOutputPtr);
286 
287         //from OsclActiveObject
288         void Run();
289 
290         //Command processing
291         PVMFCommandId QueueCommandL(PVCommsIONodeCmd&);
292         void ProcessCommand();
293         void CommandComplete(PVCommsIONodeCmdQ& aCmdQ, PVCommsIONodeCmd& aCmd, PVMFStatus aStatus, OsclAny*aEventData = NULL);
294 
295         //generic node Command handlers.
296         PVMFStatus DoQueryUuid(PVCommsIONodeCmd&);
297         PVMFStatus DoQueryInterface(PVCommsIONodeCmd&);
298         PVMFStatus DoRequestPort(PVCommsIONodeCmd&, OsclAny*&);
299         PVMFStatus DoReleasePort(PVCommsIONodeCmd&);
300         PVMFStatus DoInit(PVCommsIONodeCmd&);
301         PVMFStatus DoPrepare(PVCommsIONodeCmd&);
302         PVMFStatus DoStart(PVCommsIONodeCmd&);
303         PVMFStatus DoStop(PVCommsIONodeCmd&);
304         PVMFStatus DoFlush(PVCommsIONodeCmd&);
305         bool IsFlushPending();
306         void FlushComplete();
307         PVMFStatus DoPause(PVCommsIONodeCmd&);
308         PVMFStatus DoReset(PVCommsIONodeCmd&);
309         PVMFStatus DoCancelAllCommands(PVCommsIONodeCmd&);
310         PVMFStatus DoCancelCommand(PVCommsIONodeCmd&);
311 
312         bool ReRunCommandForNextMIO(PVCommsIONodeCmd&);
313         // Returns contexts according to the initialization
314         // sequence
315         bool GetNextContextInSequence(PVCommsIONodeCmd&);
316         // Returns context associated with given port tag
317         MIOControlContextSet ContextSetFromTag(int32 aTag);
318         //PvmiCapabilityAndConfig *GetConfig(int32 aPortTag);
319         bool CreateMediaTransfer(int32 aPortTag, PvmiMediaTransfer *&aInputTransfer, PvmiMediaTransfer *&aOutputTransfer);
320         void DeleteMediaTransfer(int32 aPortTag, PvmiMediaTransfer *aInputTransfer, PvmiMediaTransfer *aOutputTransfer);
321         bool MIOSupportsPortTag(int32 aTag, MIOControlContextSet &aSet);
322         bool ValidatePortTagRequest(int32 aTag);
323 
324 
325         // Media IO commands
326         PVMFStatus SendMioRequest(PVCommsIONodeCmd& aCmd, EMioRequest);
327         PVMFStatus CancelMioRequest(PVCommsIONodeCmd& aCmd);
328         void MioConfigured(int32 aPortTag);
329 
330         // Event reporting
331         void ReportErrorEvent(PVMFEventType aEventType, OsclAny* aEventData = NULL, PVMFStatus aEventCode = PVCommsIONodeErr_First);
332         void ReportInfoEvent(PVMFEventType aEventType, OsclAny* aEventData = NULL, PVMFStatus aEventCode = PVCommsIONodeErr_First);
333         void SetState(TPVMFNodeInterfaceState);
334 
335         bool PortQueuesEmpty();
336         void Assert(bool condition);
337 
338         // Node capability.
339         PVMFNodeCapability iCapability;
340 
341         // COmmand queues
342         PVCommsIONodeCmdQ iInputCommands;
343         PVCommsIONodeCmdQ iCurrentCommand;
344         PVCommsIONodeCmdQ iCancelCommand;
345 
346         // Media IO control
347         MIOControlContextElement iMediaInputContext;
348         MIOControlContextElement iMediaOutputContext;
349 
350         enum
351         {
352             MIO_STATE_IDLE
353             , MIO_STATE_INITIALIZED
354             , MIO_STATE_STARTED
355             , MIO_STATE_PAUSED
356         } iMediaIOState;
357 
358         EMioRequest iMediaIORequest;
359         PVMFCommandId iMediaIOCmdId;
360         PVMFCommandId iMediaIOCancelCmdId;
361         bool iMediaIOCancelPending;
362 
363         // Ports
364         PVMFPortVector<PVCommsIONodePort, OsclMemAllocator> iPortVector;
365         int32 iPortActivity;
366 
367         // Events
368         PVUuid iEventUuid;
369 
370         // Extension reference counter
371         uint32 iExtensionRefCount;
372 
373         // Counter for number of callbacks for skip media data completion
374         uint32 iSkipMediaDataResponse;
375 
376         //logger
377         PVLogger* iLogger;
378         bool iLogBitstream;
379         // for removing type-punned warning
380         PVInterface * iTempCapConfigInterface;
381 };
382 
383 #endif // PV_COMMS_IO_NODE_H_INCLUDED
384 
385 
386 
387 
388 
389