• 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_ENGINE_H_INCLUDED
19 #define TEST_ENGINE_H_INCLUDED
20 
21 #include "oscl_error.h"
22 #include "oscl_timer.h"
23 #include "oscl_mem.h"
24 #include "oscl_scheduler.h"
25 #include "oscl_utf8conv.h"
26 #include "pvlogger.h"
27 #include "pvlogger_stderr_appender.h"
28 #include "pvlogger_file_appender.h"
29 #include "pvlogger_time_and_id_layout.h"
30 #include "test_case.h"
31 #include "text_test_interpreter.h"
32 #include "pv_2way_interface.h"
33 #include "pv_2way_engine_factory.h"
34 #include "pv_2way_proxy_factory.h"
35 #include "pvmf_media_input_node_factory.h"
36 #include "pv_media_output_node_factory.h"
37 #include "pvmi_media_io_fileoutput.h"
38 #include "pvmi_mio_fileinput_factory.h"
39 #include "pv_engine_observer.h"
40 #include "pv_engine_observer_message.h"
41 #include "tsc_h324m_config_interface.h"
42 
43 #ifndef NO_2WAY_324
44 #include "pv_comms_io_node_factory.h"
45 #include "pvmi_mio_comm_loopback_factory.h"
46 #endif
47 
48 
49 #define RX_LOGGER_TAG _STRLIT_CHAR("pvcommionode.rx.bin")
50 #define TX_LOGGER_TAG _STRLIT_CHAR("pvcommionode.tx.bin")
51 #define PVSIP2WAY_PROFILE _STRLIT_CHAR("pvSIP2Way")
52 #define PVSIPDEMO_ADDRESS _STRLIT_CHAR("sip:pvSIPDemo@")
53 #define PVSIPDEMO2_ADDRESS _STRLIT_CHAR("sip:pvSIPDemo2@")
54 #define PVSIP_DEFAULT_REALM _STRLIT_CHAR("pvrealm")
55 
56 
57 #define TEST_RX_LOG_FILENAME _STRLIT("commrx.bin")
58 #define TEST_TX_LOG_FILENAME _STRLIT("commtx.bin")
59 #define TEST_LOG_FILENAME _STRLIT("test2way.log")
60 #define AUDIO_SOURCE_FILENAME _STRLIT("audio_in.if2")
61 #define AUDIO_SOURCE3_FILENAME _STRLIT("audio_in.amr")
62 #define AUDIO_SOURCE_RAW_FILENAME _STRLIT("pcm16testinput.pcm")
63 #define AUDIO_SINK_FILENAME _STRLIT("audio_if2_out.dat")
64 #define AUDIO_SINK_RAW_FILENAME _STRLIT("audio_pcm16_out.dat")
65 #define AUDIO_SINK2_FILENAME _STRLIT("audio_ietf_out.dat")
66 #define VIDEO_SOURCE_YUV_FILENAME _STRLIT("yuv420video.yuv")
67 #define VIDEO_SOURCE_H263_FILENAME _STRLIT("h263video.h263")
68 #define VIDEO_SOURCE_M4V_FILENAME _STRLIT("m4vvideo.m4v")
69 #define VIDEO_SINK_YUV_FILENAME _STRLIT("video_yuv_out.dat")
70 #define VIDEO_SINK_H263_FILENAME _STRLIT("video_h263_out.dat")
71 #define VIDEO_SINK_M4V_FILENAME _STRLIT("video_m4v_out.dat")
72 #define VIDEO_PREVIEW_FILENAME _STRLIT("video_preview_out.dat")
73 #define RECORDED_CALL_FILENAME _STRLIT("recorded_call.mp4")
74 #define AUDIO_ONLY_PLAY_FILENAME _STRLIT("pv-amr-122_novisual.3gp")
75 #define AUDIO_H263_PLAY_FILENAME _STRLIT("pv-amr-122_h263-64.3gp")
76 #define AUDIO_MPEG4_PLAY_FILENAME _STRLIT("pv2-amr122_mpeg4-rvlcs-64.3gp")
77 #define H263_ONLY_PLAY_FILENAME _STRLIT("pv-noaudio_h263-64.3gp")
78 #define MPEG4_ONLY_PLAY_FILENAME _STRLIT("pv2-noaudio_mpeg4-rvlcs-64.3gp")
79 #define SQCIF_PLAY_FILENAME _STRLIT("sqcif1.3gp")
80 #define QVGA_PLAY_FILENAME _STRLIT("qvga.3gp")
81 
82 
83 
84 extern FILE *fileoutput;
85 
86 
87 template<class DestructClass>
88 class TwoWayLogAppenderDestructDealloc : public OsclDestructDealloc
89 {
90     public:
destruct_and_dealloc(OsclAny * ptr)91         virtual void destruct_and_dealloc(OsclAny *ptr)
92         {
93             delete((DestructClass*)ptr);
94         }
95 };
96 
97 class engine_test_suite : public test_case
98 {
99     public:
100         engine_test_suite();
101 
102     private:
103         void proxy_tests(const bool aProxy);
104         void play_from_file_tests(const bool aProxy,
105                                   const OSCL_wString& aFilename,
106                                   const bool aHasAudio,
107                                   const bool aHasVideo);
108 };
109 
110 class engine_timer;
111 
112 //test function oscl_str_is_valid_utf8
113 class engine_test : public test_case,
114         public OsclActiveObject,
115         public PVCommandStatusObserver,
116         public PVInformationalEventObserver,
117         public PVErrorEventObserver
118 {
119     public:
120         engine_test(bool aUseProxy = false,
121                     int aMaxRuns = 1) : OsclActiveObject(OsclActiveObject::EPriorityNominal, "Test Engine"),
122                 iAudioSourceAdded(false),
123                 iAudioAddSourceId(0),
124                 iAudioRemoveSourceId(0),
125                 iAudioPauseSourceId(0),
126                 iAudioResumeSourceId(0),
127                 iAudioSinkAdded(false),
128                 iAudioAddSinkId(0),
129                 iAudioAddSink2Id(0),
130                 iAudioRemoveSinkId(0),
131                 iAudioPauseSinkId(0),
132                 iAudioResumeSinkId(0),
133                 iVideoSourceAdded(false),
134                 iVideoAddSourceId(0),
135                 iVideoRemoveSourceId(0),
136                 iVideoPauseSourceId(0),
137                 iVideoResumeSourceId(0),
138                 iVideoSinkAdded(false),
139                 iVideoAddSinkId(0),
140                 iVideoAddSink2Id(0),
141                 iVideoRemoveSinkId(0),
142                 iVideoPauseSinkId(0),
143                 iVideoResumeSinkId(0),
144                 iUseProxy(aUseProxy),
145                 iMaxRuns(aMaxRuns),
146                 iCurrentRun(0),
147                 iCommServer(NULL),
148                 iSelAudioSource(NULL),
149                 iSelAudioSink(NULL),
150                 iSelVideoSource(NULL),
151                 iSelVideoSink(NULL),
152 #ifndef NO_2WAY_324
153                 iCommServerIOControl(NULL),
154 #endif
155                 iAudioSource(NULL),
156                 iAudioSourceRaw(NULL),
157                 iAudioSource2(NULL),
158                 iAudioSource3(NULL),
159                 iAudioSourceIOControl(NULL),
160                 iAudioSourceRawIOControl(NULL),
161                 iAudioSource2IOControl(NULL),
162                 iAudioSource3IOControl(NULL),
163                 iGetSessionParamsId(0),
164                 iVideoSourceYUV(NULL),
165                 iVideoSourceH263(NULL),
166                 iVideoSourceM4V(NULL),
167                 iAudioSink(NULL),
168                 iAudioSinkRaw(NULL),
169                 iAudioSink2(NULL),
170                 iVideoSinkYUV(NULL),
171                 iVideoSinkH263(NULL),
172                 iVideoSinkM4V(NULL),
173                 iDuplicatesStarted(false),
174                 iVideoPreview(NULL),
175                 //iVideoPreviewIOControl(NULL),
176                 terminal(NULL),
177                 scheduler(NULL),
178                 timer(NULL),
179                 timer_elapsed(false),
180                 early_close(false),
181                 iTestStatus(true)
182         {
183             iConnectOptions.iLoopbackMode = PV_LOOPBACK_MUX;
184             iRstCmdId = 0;
185             iDisCmdId = 0;
186             iConnectCmdId = 0;
187             iInitCmdId = 0;
188             iCommsAddSourceId = 0;
189         }
190 
~engine_test()191         virtual ~engine_test()
192         {
193         }
194 
195         virtual void test() = 0;
196 
197         virtual void Run() = 0;
198 
199         virtual void DoCancel() = 0;
200 
HandleErrorEvent(const PVAsyncErrorEvent &)201         void HandleErrorEvent(const PVAsyncErrorEvent& /*aEvent*/)
202         {
203         }
204 
205         virtual void HandleInformationalEvent(const PVAsyncInformationalEvent& aEvent) = 0;
206 
207         virtual void CommandCompleted(const PVCmdResponse& aResponse) = 0;
208 
TimerCallback()209         virtual void TimerCallback() {};
210 
211         static char iProfileName[32];
212         static char iPeerAddress[64];
213         static uint32 iMediaPorts[2];
214 
215     protected:
216 
217 
218         PVCommandId iRstCmdId, iDisCmdId, iConnectCmdId, iInitCmdId;
219 
220         PVCommandId iCommsAddSourceId;
221 
222         bool iAudioSourceAdded;
223         PVCommandId iAudioAddSourceId;
224         PVCommandId iAudioAddSource2Id;
225         PVCommandId iAudioRemoveSourceId;
226         PVCommandId iAudioPauseSourceId;
227         PVCommandId iAudioResumeSourceId;
228 
229         bool iAudioSinkAdded;
230         PVCommandId iAudioAddSinkId;
231         PVCommandId iAudioAddSink2Id;
232         PVCommandId iAudioRemoveSinkId;
233         PVCommandId iAudioPauseSinkId;
234         PVCommandId iAudioResumeSinkId;
235 
236         bool iVideoSourceAdded;
237         PVCommandId iVideoAddSourceId;
238         PVCommandId iVideoAddSource2Id;
239         PVCommandId iVideoRemoveSourceId;
240         PVCommandId iVideoPauseSourceId;
241         PVCommandId iVideoResumeSourceId;
242 
243         bool iVideoSinkAdded;
244         PVCommandId iVideoAddSinkId;
245         PVCommandId iVideoAddSink2Id;
246         PVCommandId iVideoRemoveSinkId;
247         PVCommandId iVideoPauseSinkId;
248         PVCommandId iVideoResumeSinkId;
249 
disconnect()250         virtual void disconnect()
251         {
252             int error = 0;
253             OSCL_TRY(error, iDisCmdId = terminal->Disconnect());
254             if (error)
255             {
256                 reset();
257             }
258         }
259 
reset()260         virtual void reset()
261         {
262             int error = 0;
263             OSCL_TRY(error, iRstCmdId = terminal->Reset());
264             if (error)
265             {
266                 RunIfNotReady();
267             }
268         }
269 
connect()270         virtual void connect()
271         {
272             int error = 0;
273             OSCL_TRY(error, iConnectCmdId = terminal->Connect(iConnectOptions, iCommServer));
274             if (error)
275             {
276                 reset();
277             }
278         }
279 
printFormatString(PVMFFormatType aFormatType)280         virtual void printFormatString(PVMFFormatType aFormatType)
281         {
282             fprintf(fileoutput, "%s", aFormatType.getMIMEStrPtr());
283         }
284 
check_audio_started()285         bool check_audio_started()
286         {
287             return (iAudioSourceAdded && iAudioSinkAdded);
288         }
check_audio_stopped()289         bool check_audio_stopped()
290         {
291             return (!iAudioSourceAdded && !iAudioSinkAdded);
292         }
check_video_started()293         bool check_video_started()
294         {
295             return (iVideoSourceAdded && iVideoSinkAdded);
296         }
check_video_stopped()297         bool check_video_stopped()
298         {
299             return (!iVideoSourceAdded && !iVideoSinkAdded);
300         }
301 
302 
303         PVMFNodeInterface *get_audio_source(PVMFFormatType format);
304         PVMFNodeInterface *get_audio_sink(PVMFFormatType format);
305         PVMFNodeInterface *get_video_source(PVMFFormatType format);
306         PVMFNodeInterface *get_video_sink(PVMFFormatType format);
307 
308         void create_sink_source();
309         void destroy_sink_source();
310 
311         void init_mime_strings();
312 
313         bool iUseProxy;
314         int iMaxRuns;
315         int iCurrentRun;
316         PVMFNodeInterface* iCommServer;
317         PVMFNodeInterface* iSelAudioSource;
318         PVMFNodeInterface* iSelAudioSink;
319         PVMFNodeInterface* iSelVideoSource;
320         PVMFNodeInterface* iSelVideoSink;
321 #ifndef NO_2WAY_324
322         PvmiMIOControl* iCommServerIOControl;
323         PvmiMIOCommLoopbackSettings iCommSettings;
324 #endif
325         PV2Way324ConnectOptions iConnectOptions;
326         //CPV2WaySIPConnectInfo iSIPConnectOptions;
327         PV2Way324InitInfo iSdkInitInfo;
328         //CPV2WaySIPInitInfo iSdkSIPInitInfo;
329 
330         PvmiMIOFileInputSettings iAudioSourceRawFileSettings;
331         PvmiMIOFileInputSettings iAudioSource2FileSettings;
332         PvmiMIOFileInputSettings iAudioSource3FileSettings;
333         PvmiMIOFileInputSettings iAudioSourceFileSettings;
334         PVMFNodeInterface* iAudioSource;
335         PVMFNodeInterface* iAudioSourceRaw;
336         PVMFNodeInterface* iAudioSource2;
337         PVMFNodeInterface* iAudioSource3;
338         PvmiMIOControl* iAudioSourceIOControl;
339         PvmiMIOControl* iAudioSourceRawIOControl;
340         PvmiMIOControl* iAudioSource2IOControl;
341         PvmiMIOControl* iAudioSource3IOControl;
342 
343         PVCommandId iGetSessionParamsId;
344         PvmiMIOFileInputSettings iVideoSourceYUVFileSettings;
345         PvmiMIOFileInputSettings iVideoSourceH263FileSettings;
346         PvmiMIOFileInputSettings iVideoSourceM4VFileSettings;
347         PVMFNodeInterface* iVideoSourceYUV;
348         PVMFNodeInterface* iVideoSourceH263;
349         PVMFNodeInterface* iVideoSourceM4V;
350         PvmiMIOControl* iVideoSourceYUVIOControl;
351         PvmiMIOControl* iVideoSourceH263IOControl;
352         PvmiMIOControl* iVideoSourceM4VIOControl;
353 
354 
355         const oscl_wchar* iAudioSinkFileName;
356         const oscl_wchar* iAudioSinkRawFileName;
357         const oscl_wchar* iAudioSink2FileName;
358         PVMFNodeInterface* iAudioSink;
359         PVMFNodeInterface* iAudioSinkRaw;
360         PVMFNodeInterface* iAudioSink2;
361         PVRefFileOutput* iAudioSinkIOControl;
362         PVRefFileOutput* iAudioSinkRawIOControl;
363         PVRefFileOutput* iAudioSink2IOControl;
364 
365         const oscl_wchar* iVideoSinkYUVFileName;
366         const oscl_wchar* iVideoSinkH263FileName;
367         const oscl_wchar* iVideoSinkM4VFileName;
368         PVMFNodeInterface* iVideoSinkYUV;
369         PVMFNodeInterface* iVideoSinkH263;
370         PVMFNodeInterface* iVideoSinkM4V;
371         PVRefFileOutput* iVideoSinkYUVIOControl;
372         PVRefFileOutput* iVideoSinkH263IOControl;
373         PVRefFileOutput* iVideoSinkM4VIOControl;
374         bool iDuplicatesStarted;
375         OSCL_wHeapString<OsclMemAllocator> iVideoPreviewFileName;
376         PVMFNodeInterface* iVideoPreview;
377         //PVRefFileOutput* iVideoPreviewIOControl;
378 
379         CPV2WayInterface *terminal;
380         OsclExecScheduler *scheduler;
381         engine_timer *timer;
382         bool timer_elapsed;
383         bool early_close;
384 
385         CPV2WayH263ConfigInfo iH263ConfigInfo;
386         CPV2WayM4VConfigInfo iM4VConfigInfo;
387 
388         bool iTestStatus;
389 };
390 
391 class engine_timer : public OsclTimerObject
392 {
393     public:
engine_timer(engine_test * aObserver)394         engine_timer(engine_test *aObserver) : OsclTimerObject(OsclActiveObject::EPriorityNominal, "Test Engine Timer"),
395                 iObserver(aObserver)
396         {};
397 
~engine_timer()398         ~engine_timer()
399         {
400             Cancel();
401         }
402 
403     protected:
Run()404         void Run()
405         {
406             iObserver->TimerCallback();
407         }
DoCancel()408         void DoCancel()
409         {
410             OsclTimerObject::DoCancel();
411         };
412 
413         engine_test *iObserver;
414 
415 };
416 
417 
418 
419 #endif
420 
421 
422