• 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 #ifndef TEST_PV_MEDIAINPUT_AUTHOR_ENGINE_H
19 #define TEST_PV_MEDIAINPUT_AUTHOR_ENGINE_H
20 
21 #ifndef TEST_PV_AUTHOR_ENGINE_TYPEDEFS_H
22 #include "test_pv_author_engine_typedefs.h"
23 #endif
24 
25 #ifndef PV_AVIFILE_H_INCLUDED
26 #include "pv_avifile.h"
27 #endif
28 
29 #ifndef PVWAVFILEPARSER_H_INCLUDED
30 #include "pvwavfileparser.h"
31 #endif
32 
33 #ifndef PVMF_NODE_INTERFACE_H_INCLUDED
34 #include "pvmf_node_interface.h"
35 #endif
36 
37 #ifndef PVMF_MEDIA_INPUT_NODE_FACTORY_H_INCLUDED
38 #include "pvmf_media_input_node_factory.h"
39 #endif
40 
41 #ifndef PVMI_MIO_AVIFILE_FACTORY_H_INCLUDED
42 #include "pvmi_mio_avi_wav_file_factory.h"
43 #endif
44 
45 typedef struct _PVMediaInputTestParam
46 {
47     FILE* iFile;
48     PVMFFormatType  iInputFormat;
49     OSCL_HeapString<OsclMemAllocator> iIPFileInfo;
50     OSCL_HeapString<OsclMemAllocator> iOPFileInfo;
51     OSCL_HeapString<OsclMemAllocator> iVideoEncInfo;
52     OSCL_HeapString<OsclMemAllocator> iAudioEncInfo;
53     OSCL_HeapString<OsclMemAllocator> iComposerInfo;
54     uint32 iLoopTime;
55     bool iRealTimeAuthoring;
56     uint32 iVideoBitrate;
57     uint32 iAudioBitrate;
58     OsclFloat iFrameRate;
59     uint32 iSamplingRate;
60 } PVMediaInputTestParam;
61 
62 typedef struct _PVMediaInputAuthorEngineTestParam
63 {
64     int32 iFirstTest;
65     int32 iLastTest;
66     bool iAsap;
67     PVMediaInputTestParam iMediainputParam;
68 
69 } PVMediaInputAuthorEngineTestParam;
70 
71 class PVMIOControlComp
72 {
73 
74     public:
75         /** constructor */
PVMIOControlComp(PVMFFormatType aType,OsclAny * aFileParser,uint32 aLoopDuration)76         PVMIOControlComp(PVMFFormatType aType, OsclAny* aFileParser, uint32 aLoopDuration)
77         {
78             if (aType == PVMF_MIME_WAVFF)
79             {
80                 iPVWavFile = OSCL_STATIC_CAST(PV_Wav_Parser*, aFileParser);
81                 iPVAviFile = NULL;
82                 PVWAVFileInfo wavFileInfo;
83                 iPVWavFile->RetrieveFileInfo(wavFileInfo);
84                 iFileDuration = (OsclFloat)wavFileInfo.NumSamples / wavFileInfo.SampleRate; //in sec
85             }
86             else if (aType == PVMF_MIME_AVIFF)
87             {
88                 iPVAviFile = OSCL_STATIC_CAST(PVAviFile*, aFileParser);
89                 iPVWavFile = NULL;
90                 iFileDuration = (OsclFloat)iPVAviFile->GetFileDuration(); //in sec
91             }
92 
93             iLogger = PVLogger::GetLoggerObject("PVMIOControlComp");
94             iLoopDuration = aLoopDuration;
95 
96         }
97 
98         /** default constructor */
PVMIOControlComp()99         PVMIOControlComp()
100         {
101             iPVAviFile = NULL;
102             iPVWavFile = NULL;
103             iLogger = NULL;
104             iFileDuration = 0;
105             iLoopDuration = 0;
106         };
107 
108         /** default destructor */
~PVMIOControlComp()109         ~PVMIOControlComp() {}
110 
111         /**
112          * Copy constructor
113          * @param arInput Source object
114          */
PVMIOControlComp(const PVMIOControlComp & arInput)115         PVMIOControlComp(const PVMIOControlComp& arInput)
116         {
117             iMIONode = arInput.iMIONode;
118             iMediaInput = arInput.iMediaInput;
119             iPVAviFile = arInput.iPVAviFile;
120             iPVWavFile = arInput.iPVWavFile;
121             iLogger = arInput.iLogger;
122             iFileDuration = arInput.iFileDuration;
123             iLoopDuration = arInput.iLoopDuration;
124         }
125 
126         /**
127         * Assignment Operator
128         * @param arInput Source object
129         * @return Reference to this object with values copied from the source object
130         */
131         PVMIOControlComp& operator=(const PVMIOControlComp& arInput)
132         {
133             iMIONode = arInput.iMIONode;
134             iMediaInput = arInput.iMediaInput;
135             iPVAviFile = arInput.iPVAviFile;
136             iPVWavFile = arInput.iPVWavFile;
137             iLogger = arInput.iLogger;
138             iFileDuration = arInput.iFileDuration;
139             iLoopDuration = arInput.iLoopDuration;
140             return (*this);
141         }
142 
143         /**
144          * Query whether the specified input type is supported
145          *
146          * @param aType Input type to be supported
147          * @return True if input type is supported, else false
148          */
IsTestInputTypeSupported(PVMFFormatType aType)149         bool IsTestInputTypeSupported(PVMFFormatType aType)
150         {
151             if (aType == PVMF_MIME_WAVFF ||
152                     aType == PVMF_MIME_AVIFF)
153             {
154                 return true;
155             }
156 
157             return false;
158         }
159 
160         /**
161          * Creates an input node of the specified type.  DeleteInputNode() will need to
162          * be called to deallocate the input node.  The default contructor will not
163          * delete the input node created by this method.
164          *
165          * @param aType Type of input node to create
166          * @return True for success, else false
167          */
CreateMIOInputNode(bool aRecMode,PVMFFormatType aType,const OSCL_wString & aFileName)168         int32 CreateMIOInputNode(bool aRecMode, PVMFFormatType aType, const OSCL_wString& aFileName)
169         {
170             OSCL_UNUSED_ARG(aFileName);
171             int32 error = PVMFFailure;
172 
173             if (!IsTestInputTypeSupported(aType))
174             {
175                 return error;
176             }
177 
178             uint32 loopCount = 0;
179             if (iLoopDuration)
180             {
181                 loopCount = iLoopDuration / (uint32)iFileDuration;
182             }
183             if (aType == PVMF_MIME_WAVFF)
184             {
185                 PvmiMIOControl* mediaInput = PvmiMIOAviWavFileFactory::Create(loopCount, aRecMode, 0, (OsclAny*)iPVWavFile, FILE_FORMAT_WAV, error);
186                 if (!mediaInput)
187                 {
188                     PVLOGGER_LOGMSG(PVLOGMSG_INST_REL, iLogger, PVLOGMSG_ERR,
189                                     (0, "CreateMIOInputNode::CreateMIOInputNode: Error - PvmiMIOAviWavFileFactory::Create failed"));
190 
191                     return PVMFFailure;
192                 }
193 
194                 iMediaInput.push_back(mediaInput);
195             }
196             else if (aType == PVMF_MIME_AVIFF)
197             {
198                 for (uint32 ii = 0; ii < iPVAviFile->GetNumStreams(); ii++)
199                 {
200                     PvmiMIOControl* mediaInput = PvmiMIOAviWavFileFactory::Create(loopCount, aRecMode, ii, (OsclAny*)iPVAviFile, FILE_FORMAT_AVI, error);
201                     if (!mediaInput)
202                     {
203                         PVLOGGER_LOGMSG(PVLOGMSG_INST_REL, iLogger, PVLOGMSG_ERR,
204                                         (0, "CreateMIOInputNode::CreateMIOInputNode: Error - PvmiMIOAviWavFileFactory::Create failed"));
205 
206                         return PVMFFailure;
207                     }
208 
209                     if (error != PVMFSuccess)
210                     {
211                         if (mediaInput)
212                         {
213                             PvmiMIOAviWavFileFactory::Delete(mediaInput);
214                         }
215 
216                         return error;
217                     }
218 
219                     iMediaInput.push_back(mediaInput);
220 
221                 }
222             }
223 
224             for (uint32 ii = 0; ii < iMediaInput.size(); ii++)
225             {
226                 PVMFNodeInterface *node = PvmfMediaInputNodeFactory::Create(iMediaInput[ii]);
227                 if (!node)
228                 {
229                     PVLOGGER_LOGMSG(PVLOGMSG_INST_REL, iLogger, PVLOGMSG_ERR,
230                                     (0, "CreateMIOInputNode::CreateMIOInputNode: Error - PvmfMediaInputNodeFactory::Create failed"));
231 
232                     return PVMFFailure;
233                 }
234                 iMIONode.push_back(node);
235             }
236 
237             return error;
238         }
239 
240         /**
241          * Deletes the input node contained by this object
242          */
DeleteInputNode()243         void DeleteInputNode()
244         {
245             uint32 ii = 0;
246             if (iMIONode.size() > 0)
247             {
248                 for (ii = 0; ii < iMIONode.size() ; ii++)
249                 {
250                     PvmfMediaInputNodeFactory::Delete(iMIONode[ii]);
251                 }
252                 iMIONode.destroy();
253             }
254 
255             if (iMediaInput.size() > 0)
256             {
257                 for (ii = 0; ii < iMediaInput.size(); ii++)
258                 {
259                     PvmiMIOAviWavFileFactory::Delete(iMediaInput[ii]);
260                 }
261                 iMediaInput.destroy();
262             }
263 
264         }
265 
266         PVAviFile*                         iPVAviFile;
267         PV_Wav_Parser*                     iPVWavFile;
268         PVLogger*                          iLogger;
269         Oscl_Vector < PVMFNodeInterface*,
270         OsclMemAllocator >    iMIONode;
271         Oscl_Vector < PvmiMIOControl*,
272         OsclMemAllocator >    iMediaInput;
273         uint32                             iLoopDuration;
274         OsclFloat                          iFileDuration;
275 };
276 
277 
278 class PVMediaInputAuthorEngineTest: public test_case,
279         public pvauthor_async_test_observer,
280         public PVLoggerSchedulerSetup
281 {
282     public:
PVMediaInputAuthorEngineTest(PVMediaInputAuthorEngineTestParam aTestParam)283         PVMediaInputAuthorEngineTest(PVMediaInputAuthorEngineTestParam aTestParam):
284                 PVLoggerSchedulerSetup(),
285                 iCurrentTest(NULL),
286 
287                 iFirstTest(aTestParam.iFirstTest),
288                 iLastTest(aTestParam.iLastTest),
289                 iNextTestCase(aTestParam.iFirstTest),
290                 iAsap(aTestParam.iAsap),
291                 iFile(aTestParam.iMediainputParam.iFile),
292                 iMediaInputParam(aTestParam.iMediainputParam)
293         {};
294 
295         // From test_case
296         virtual void test();
297         virtual void CompleteTest(test_case& arTC);
298         void RunTestCases();
299         bool     Set_Default_Params(int32 aTestnum, PVMediaInputTestParam& aMediaInputParam);
300         void Print_TestCase_Name(int32 aTestnum);
301 
302     private:
303         pvauthor_async_test_base* iCurrentTest;
304         int32                     iFirstTest;
305         int32                     iLastTest;
306         int32                     iNextTestCase;
307         bool                      iAsap;
308         FILE*                     iFile;
309         // For test results
310         int                       iTotalSuccess;
311         int                       iTotalError;
312         int                       iTotalFail;
313         // For memory statistics
314         uint32                    iTotalAlloc;
315         uint32                    iTotalBytes;
316         uint32                    iAllocFails;
317         uint32                    iNumAllocs;
318         PVMediaInputTestParam     iMediaInputParam;
319 };
320 
321 class PVMediaInputAuthorEngineTestSuite: public test_case
322 {
323     public:
PVMediaInputAuthorEngineTestSuite(PVMediaInputAuthorEngineTestParam aTestParam)324         PVMediaInputAuthorEngineTestSuite(PVMediaInputAuthorEngineTestParam aTestParam)
325         {
326             adopt_test_case(new PVMediaInputAuthorEngineTest(aTestParam));
327         }
328 
~PVMediaInputAuthorEngineTestSuite()329         ~PVMediaInputAuthorEngineTestSuite() {} ;
330 
331 };
332 
333 #endif //#fidef TEST_PV_MEDIAINPUT_AUTHOR_ENGINE_H
334 
335