• 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 #ifndef PVMF_DUMMY_FILEINPUT_NODE_H_INCLUDED
20 #define PVMF_DUMMY_FILEINPUT_NODE_H_INCLUDED
21 
22 #ifndef PVMF_NODE_INTERFACE_H_INCLUDED
23 #include "pvmf_node_interface.h"
24 #endif
25 #ifndef PVMF_NODE_UTILS_H_INCLUDED
26 #include "pvmf_node_utils.h"
27 #endif
28 #ifndef OSCL_SCHEDULER_AO_H_INCLUDED
29 #include "oscl_scheduler_ao.h"
30 #endif
31 #ifndef PVMF_FILEINPUT_PORT_H_INCLUDED
32 #include "pvmf_fileinput_port.h"
33 #endif
34 #ifndef PVMF_FILEINPUT_NODE_EXTENSION_H_INCLUDED
35 #include "pvmf_fileinput_node_extension.h"
36 #endif
37 #ifndef PVMF_FILEINPUT_NODE_EVENTS_H_INCLUDED
38 #include "pvmf_fileinput_node_events.h"
39 #endif
40 #ifndef OSCLCONFIG_IO_H_INCLUDED
41 #include "osclconfig_io.h"
42 #endif
43 #ifndef OSCL_FILE_IO_H_INCLUDED
44 #include "oscl_file_io.h"
45 #endif
46 #ifndef PVMF_FILEINPUT_NODE_INTERNAL_H_INCLUDED
47 #include "pvmf_fileinput_node_internal.h"
48 #endif
49 #ifndef PVMF_FILEINPUT_SETTINGS_H_INCLUDED
50 #include "pvmf_fileinput_settings.h"
51 #endif
52 
53 // SEE DESCRIPTION IN pvmf_fileinput_node.cpp
54 //#define FRAGMENTATION_TEST
55 
56 ///////////////////////////////////////////////
57 // Port tags
58 ///////////////////////////////////////////////
59 
60 /** Enumerated list of port tags supported by the node,
61 ** for the port requests.
62 */
63 typedef enum
64 {
65     // chesterc: Convention for now is for input/sink port to have tag value 0
66     // and output/src port to have tag value 1.  Both author and player engines
67     // relies on this assumption, and should be removed later on when capabilities
68     // exchange is implemented on the node.  The engine would then query the node
69     // for the list of supported tags for a given mime type.
70     PVMF_DUMMY_FILEINPUT_NODE_PORT_TYPE_SOURCE = 1
71 } PVMFDummyFileInputNodePortType;
72 
73 ///////////////////////////////////////////////
74 // The PVMFDummyFileInputNode Node Implementation Class
75 ///////////////////////////////////////////////
76 
77 class PVLogger;
78 
79 class PVMFDummyFileInputNode : public PVMFNodeInterface,
80         public OsclTimerObject,
81         public PVMFFileInputNodeExtensionInterface
82         , public OsclMemPoolFixedChunkAllocatorObserver
83 {
84     public:
85         OSCL_IMPORT_REF PVMFDummyFileInputNode(PVMFFileInputSettings* aSettings, int32 aPriority);
86         OSCL_IMPORT_REF ~PVMFDummyFileInputNode();
87 
88         //from PVMFNodeInterface
89         OSCL_IMPORT_REF PVMFStatus ThreadLogon();
90         OSCL_IMPORT_REF PVMFStatus ThreadLogoff();
91         OSCL_IMPORT_REF PVMFStatus GetCapability(PVMFNodeCapability& aNodeCapability);
92         OSCL_IMPORT_REF PVMFPortIter* GetPorts(const PVMFPortFilter* aFilter = NULL);
93         OSCL_IMPORT_REF PVMFCommandId QueryUUID(PVMFSessionId, const PvmfMimeString& aMimeType,
94                                                 Oscl_Vector<PVUuid, PVMFFileInputNodeAllocator>& aUuids,
95                                                 bool aExactUuidsOnly = false,
96                                                 const OsclAny* aContext = NULL);
97         OSCL_IMPORT_REF PVMFCommandId QueryInterface(PVMFSessionId, const PVUuid& aUuid,
98                 PVInterface*& aInterfacePtr,
99                 const OsclAny* aContext = NULL);
100         OSCL_IMPORT_REF PVMFCommandId RequestPort(PVMFSessionId
101                 , int32 aPortTag, const PvmfMimeString* aPortConfig = NULL, const OsclAny* aContext = NULL);
102         OSCL_IMPORT_REF PVMFCommandId ReleasePort(PVMFSessionId, PVMFPortInterface& aPort, const OsclAny* aContext = NULL);
103         OSCL_IMPORT_REF PVMFCommandId Init(PVMFSessionId, const OsclAny* aContext = NULL);
104         OSCL_IMPORT_REF PVMFCommandId Prepare(PVMFSessionId, const OsclAny* aContext = NULL);
105         OSCL_IMPORT_REF PVMFCommandId Start(PVMFSessionId, const OsclAny* aContext = NULL);
106         OSCL_IMPORT_REF PVMFCommandId Stop(PVMFSessionId, const OsclAny* aContext = NULL);
107         OSCL_IMPORT_REF PVMFCommandId Flush(PVMFSessionId, const OsclAny* aContext = NULL);
108         OSCL_IMPORT_REF PVMFCommandId Pause(PVMFSessionId, const OsclAny* aContext = NULL);
109         OSCL_IMPORT_REF PVMFCommandId Reset(PVMFSessionId, const OsclAny* aContext = NULL);
110         OSCL_IMPORT_REF PVMFCommandId CancelAllCommands(PVMFSessionId, const OsclAny* aContextData = NULL);
111         OSCL_IMPORT_REF PVMFCommandId CancelCommand(PVMFSessionId, PVMFCommandId aCmdId, const OsclAny* aContextData = NULL);
112 
113         //from PVMFPortActivityHandler
114         void HandlePortActivity(const PVMFPortActivity& aActivity);
115 
116         //from PVMFDummyFileInputNodeCustomInterface1
117         OSCL_IMPORT_REF PVMFStatus GetStats(PVMFPortInterface* aPort, int32& aNumMsgGenerated, int32& aNumMsgConsumed);
118 
119         // Virtual functions of PVMFFileInputNodeExtensionInterface
120         OSCL_IMPORT_REF void addRef();
121         OSCL_IMPORT_REF void removeRef();
122         OSCL_IMPORT_REF bool queryInterface(const PVUuid& uuid, PVInterface*& iface);
123         OSCL_IMPORT_REF bool GetBitstreamConfig(OsclRefCounterMemFrag& aConfig);
124 
125 
126     private: // private member functions
127 
128         //from OsclActiveObject
129         void Run();
130         void DoCancel();
131 
132         //Command processing
133         PVMFCommandId QueueCommandL(PVMFFileInputNodeCommand&);
134         bool ProcessCommand(PVMFFileInputNodeCommand&);
135         void CommandComplete(PVMFFileInputNodeCmdQ&, PVMFFileInputNodeCommand&, PVMFStatus, OsclAny* aData = NULL);
136         bool FlushPending();
137 
138         //Command handlers.
139         void DoReset(PVMFFileInputNodeCommand&);
140         void DoQueryUuid(PVMFFileInputNodeCommand&);
141         void DoQueryInterface(PVMFFileInputNodeCommand&);
142         void DoRequestPort(PVMFFileInputNodeCommand&);
143         void DoReleasePort(PVMFFileInputNodeCommand&);
144         void DoInit(PVMFFileInputNodeCommand&);
145         void DoPrepare(PVMFFileInputNodeCommand&);
146         void DoStart(PVMFFileInputNodeCommand&);
147         void DoStop(PVMFFileInputNodeCommand&);
148         void DoFlush(PVMFFileInputNodeCommand&);
149         void DoPause(PVMFFileInputNodeCommand&);
150         void DoCancelAllCommands(PVMFFileInputNodeCommand&);
151         void DoCancelCommand(PVMFFileInputNodeCommand&);
152 
153         // Event reporting
154         void ReportErrorEvent(PVMFEventType aEventType, OsclAny* aEventData = NULL);
155         void ReportInfoEvent(PVMFEventType aEventType, OsclAny* aEventData = NULL);
156         void SetState(TPVMFNodeInterfaceState);
157 
158         // Helper functions
159 
160         int32 LocateH263FrameHeader(uint8* video_buffer, int32 vop_size);
161 
162         int32 GetIF2FrameSize(uint8 aFrameType);
163 
164         void  ConstructInputSettings(PVMFFileInputSettings* aSettings);
165         void  CloseInputFile();
166 
167         // Initialization function
168         PVMFStatus Initialize();
169 
170         // Create and send out media messages
171         PVMFStatus GenerateMediaMessage(PVMFSharedMediaMsgPtr& aMediaMsg);
172 #ifdef FRAGMENTATION_TEST
173         // Create and send out media messages
174         PVMFStatus GenerateMediaMessage2(PVMFSharedMediaMsgPtr& aMediaMsg, PVMFSharedMediaMsgPtr& aMediaMsg2);
175 #endif
176 
177         PVMFStatus SendNewMediaMessage();
178 
179     private: // private member variables
180 
181         // Vector of ports contained in this node
182         PVMFPortVector<PVMFFileDummyInputPort, PVMFFileInputNodeAllocator> iPortVector;
183         friend class PVMFFileDummyInputPort;
184 
185         // commands
186         PVMFFileInputNodeCmdQ iInputCommands;
187         PVMFFileInputNodeCmdQ iCurrentCommand;
188 
189         // Allocator
190         OsclMemAllocator iCmdAlloc;
191         OsclMemAllocDestructDealloc<uint8> iAlloc;
192 
193         // Allocator for simple media data buffer
194         OsclMemPoolFixedChunkAllocator* iMediaBufferMemPool;
195         PVMFSimpleMediaBufferCombinedAlloc* iMediaDataAlloc;
196         OsclMemPoolFixedChunkAllocator iMediaDataMemPool;
197 
198         uint8* iAudioData;
199         uint8* iVideoData;
200         PVMFNodeCapability iCapability;
201         PVLogger *iLogger;
202         PVMFFileInputSettings iSettings;
203 
204         // Format specific info
205         OsclRefCounterMemFrag iFormatSpecificInfo;
206         int32 iFormatSpecificInfoSize;
207         bool iSetFormatSpecificInfo;
208 
209         int32 iFileHeaderSize;
210 
211         // Input file
212         Oscl_FileServer iFs;
213         bool iFsOpen;
214         Oscl_File iInputFile;
215         bool iFileOpen;
216 
217         // Counter and size info for file read
218         Oscl_Vector<uint32, OsclMemAllocator> iFrameSizeVector;
219         Oscl_Vector<uint32, OsclMemAllocator> iMilliSecFrameDurationVector;
220         int32 iDataEventCounter;
221         int32 iTotalNumFrames;
222 
223         // Timing
224         int32 iMicroSecondsPerTick;
225         int32 iMilliSecondsPerDataEvent;
226         int32 iMicroSecondsPerDataEvent;
227         int32 iTSForRunIfInactive;
228         PVMFTimestamp iTimeStamp;
229 
230         // Reference counter for extension
231         uint32 iExtensionRefCount;
232 
233 
234         void IncTimestamp();
235 
236         //from OsclMemPoolFixedChunkAllocatorObserver
237         void freechunkavailable(OsclAny* aContextData);
238         bool iWaitingOnFreeChunk;
239         bool iEndOfFileReached;
240 };
241 
242 #endif
243 
244 
245