• 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_PLAYER_ENGINE_TESTSET8_H_INCLUDED
19 #include "test_pv_player_engine_testset8.h"
20 #endif
21 
22 #ifndef OSCL_ERROR_CODES_H_INCLUDED
23 #include "oscl_error_codes.h"
24 #endif
25 
26 #ifndef OSCL_TICKCOUNT_H_INCLUDED
27 #include "oscl_tickcount.h"
28 #endif
29 
30 #ifndef PV_PLAYER_DATASINKFILENAME_H_INCLUDED
31 #include "pv_player_datasinkfilename.h"
32 #endif
33 
34 #ifndef PV_PLAYER_DATASINKPVMFNODE_H_INCLUDED
35 #include "pv_player_datasinkpvmfnode.h"
36 #endif
37 
38 #ifndef PVMI_MEDIA_IO_FILEOUTPUT_H_INCLUDED
39 #include "pvmi_media_io_fileoutput.h"
40 #endif
41 
42 #ifndef PV_MEDIA_OUTPUT_NODE_FACTORY_H_INCLUDED
43 #include "pv_media_output_node_factory.h"
44 #endif
45 
46 #ifndef PVMF_ERRORINFOMESSAGE_EXTENSION_H_INCLUDED
47 #include "pvmf_errorinfomessage_extension.h"
48 #endif
49 
50 #ifndef OSCL_UTF8CONV_H
51 #include "oscl_utf8conv.h"
52 #endif
53 
54 #ifndef PVMI_KVP_H_INCLUDED
55 #include "pvmi_kvp.h"
56 #endif
57 
58 #ifndef PVMI_KVP_UTIL_H_INCLUDED
59 #include "pvmi_kvp_util.h"
60 #endif
61 
62 #ifndef OSCL_MEM_H_INCLUDED
63 #include "oscl_mem.h"
64 #endif
65 
66 #ifndef OSCL_MEM_AUDIT_H_INCLUDED
67 #include "oscl_mem_audit.h"
68 #endif
69 
70 //
71 // pvplayer_async_test_printmetadata section
72 //
StartTest()73 void pvplayer_async_test_printmetadata::StartTest()
74 {
75     AddToScheduler();
76     iState = STATE_CREATE;
77     RunIfNotReady();
78 }
79 
80 
Run()81 void pvplayer_async_test_printmetadata::Run()
82 {
83     int error = 0;
84 
85     switch (iState)
86     {
87         case STATE_CREATE:
88         {
89             iPlayer = NULL;
90 
91             OSCL_TRY(error, iPlayer = PVPlayerFactory::CreatePlayer(this, this, this));
92             if (error)
93             {
94                 PVPATB_TEST_IS_TRUE(false);
95                 iObserver->TestCompleted(*iTestCase);
96             }
97             else
98             {
99                 iState = STATE_ADDDATASOURCE;
100                 RunIfNotReady();
101             }
102         }
103         break;
104 
105         case STATE_ADDDATASOURCE:
106         {
107             iDataSource = new PVPlayerDataSourceURL;
108             oscl_UTF8ToUnicode(iFileName, oscl_strlen(iFileName), iTmpWCharBuffer, 512);
109             iTmpWCharBuffer[511] = '\0';
110             iFileNameWStr = SOURCENAME_PREPEND_WSTRING;
111             iFileNameWStr += iTmpWCharBuffer;
112             /*
113              * In case of HTTP URLs always attempt rollover,
114              * since we donot know if it is a download or a streaming url
115              */
116             if (iFileType == PVMF_MIME_DATA_SOURCE_HTTP_URL)
117             {
118                 iSourceContextData = new PVMFSourceContextData();
119                 iSourceContextData->EnableStreamingSourceContext();
120                 iSourceContextData->EnableCommonSourceContext();
121                 PVInterface* sourceContextStream = NULL;
122 
123                 PVUuid streamingContextUuid(PVMF_SOURCE_CONTEXT_DATA_STREAMING_UUID);
124                 if (iSourceContextData->queryInterface(streamingContextUuid, sourceContextStream))
125                 {
126                     PVMFSourceContextDataStreaming* streamingContext =
127                         OSCL_STATIC_CAST(PVMFSourceContextDataStreaming*, sourceContextStream);
128                     streamingContext->iStreamStatsLoggingURL = iFileNameWStr;
129 
130                     if (iProxyEnabled)
131                     {
132                         streamingContext->iProxyName = _STRLIT_WCHAR("");
133                         streamingContext->iProxyPort = 8080;
134                     }
135                 }
136                 PVInterface* sourceContextDownload = NULL;
137                 iSourceContextData->EnableDownloadHTTPSourceContext();
138                 PVUuid downloadContextUuid(PVMF_SOURCE_CONTEXT_DATA_DOWNLOAD_HTTP_UUID);
139                 if (iSourceContextData->queryInterface(downloadContextUuid, sourceContextDownload))
140                 {
141                     //create the opaque data
142                     iDownloadProxy = _STRLIT_CHAR("");
143                     int32 iDownloadProxyPort = 0;
144                     if (iProxyEnabled)
145                     {
146                         iDownloadProxy = _STRLIT_CHAR("");
147                         iDownloadProxyPort = 8080;
148                     }
149                     iDownloadConfigFilename = OUTPUTNAME_PREPEND_WSTRING;
150                     iDownloadConfigFilename += _STRLIT_WCHAR("mydlconfig");
151                     iDownloadMaxfilesize = 0x7FFFFFFF;
152                     iDownloadFilename = OUTPUTNAME_PREPEND_WSTRING;
153                     iDownloadFilename += _STRLIT_WCHAR("test_ftdownload.dl");
154                     bool aIsNewSession = true;
155 
156                     iSourceContextData->DownloadHTTPData()->bIsNewSession = aIsNewSession;
157                     iSourceContextData->DownloadHTTPData()->iConfigFileName = iDownloadConfigFilename;
158                     iSourceContextData->DownloadHTTPData()->iDownloadFileName = iDownloadFilename;
159                     iSourceContextData->DownloadHTTPData()->iMaxFileSize = iDownloadMaxfilesize;
160                     iSourceContextData->DownloadHTTPData()->iPlaybackControl = PVMFSourceContextDataDownloadHTTP::EAsap;
161                     iSourceContextData->DownloadHTTPData()->iProxyName = iDownloadProxy;
162                     iSourceContextData->DownloadHTTPData()->iProxyPort = iDownloadProxyPort;
163 
164                 }
165                 iDataSource->SetDataSourceContextData((OsclAny*)iSourceContextData);
166 
167                 iDataSource->SetDataSourceFormatType(PVMF_MIME_DATA_SOURCE_MS_HTTP_STREAMING_URL);
168                 iDataSource->SetAlternateSourceFormatType(PVMF_MIME_DATA_SOURCE_HTTP_URL);
169             }
170             else
171             {
172                 iDataSource->SetDataSourceFormatType(iFileType);
173             }
174 
175             iDataSource->SetDataSourceURL(iFileNameWStr);
176 
177             OSCL_TRY(error, iCurrentCmdId = iPlayer->AddDataSource(*iDataSource, (OsclAny*) & iContextObject));
178             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
179         }
180 
181         break;
182 
183         case STATE_INIT:
184         {
185             OSCL_TRY(error, iCurrentCmdId = iPlayer->Init((OsclAny*) & iContextObject));
186             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
187         }
188         break;
189 
190         case STATE_GETMETADATAKEYLIST1:
191         {
192             iMetadataKeyList.clear();
193             OSCL_TRY(error, iCurrentCmdId = iPlayer->GetMetadataKeys(iMetadataKeyList, 0, -1, NULL, (OsclAny*) & iContextObject));
194             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
195         }
196         break;
197 
198         case STATE_GETMETADATAVALUELIST1:
199         {
200             iMetadataValueList.clear();
201             iNumValues = 0;
202             OSCL_TRY(error, iCurrentCmdId = iPlayer->GetMetadataValues(iMetadataKeyList, 0, -1, iNumValues, iMetadataValueList, (OsclAny*) & iContextObject, !iReleaseMetadataByApp));
203             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
204         }
205         break;
206 
207         case STATE_RELEASEMETADATAVALUES1:
208         {
209             PrintMetadataInfo();
210             OSCL_TRY(error, iCurrentCmdId = iPlayer->ReleaseMetadataValues(iMetadataValueList, (OsclAny*) & iContextObject));
211             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
212         }
213         break;
214 
215         case STATE_ADDDATASINK_VIDEO:
216         {
217             OSCL_wHeapString<OsclMemAllocator> videosinkfilename = OUTPUTNAME_PREPEND_WSTRING;
218             videosinkfilename += _STRLIT_WCHAR("test_player_printmetadata_video.dat");
219 
220             iMIOFileOutVideo = iMioFactory->CreateVideoOutput((OsclAny*) & videosinkfilename, MEDIATYPE_VIDEO, iCompressedVideo);
221             iIONodeVideo = PVMediaOutputNodeFactory::CreateMediaOutputNode(iMIOFileOutVideo);
222             iDataSinkVideo = new PVPlayerDataSinkPVMFNode;
223             ((PVPlayerDataSinkPVMFNode*)iDataSinkVideo)->SetDataSinkNode(iIONodeVideo);
224 
225             OSCL_TRY(error, iCurrentCmdId = iPlayer->AddDataSink(*iDataSinkVideo, (OsclAny*) & iContextObject));
226             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
227         }
228         break;
229 
230         case STATE_ADDDATASINK_AUDIO:
231         {
232             OSCL_wHeapString<OsclMemAllocator> audiosinkfilename = OUTPUTNAME_PREPEND_WSTRING;
233             audiosinkfilename += _STRLIT_WCHAR("test_player_printmetadata_audio.dat");
234 
235             iMIOFileOutAudio = iMioFactory->CreateAudioOutput((OsclAny*) & audiosinkfilename, MEDIATYPE_AUDIO, iCompressedAudio);
236             iIONodeAudio = PVMediaOutputNodeFactory::CreateMediaOutputNode(iMIOFileOutAudio);
237             iDataSinkAudio = new PVPlayerDataSinkPVMFNode;
238             ((PVPlayerDataSinkPVMFNode*)iDataSinkAudio)->SetDataSinkNode(iIONodeAudio);
239 
240             OSCL_TRY(error, iCurrentCmdId = iPlayer->AddDataSink(*iDataSinkAudio, (OsclAny*) & iContextObject));
241             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
242         }
243         break;
244 
245         case STATE_ADDDATASINK_TEXT:
246         {
247             OSCL_wHeapString<OsclMemAllocator> textsinkfilename = OUTPUTNAME_PREPEND_WSTRING;
248             textsinkfilename += _STRLIT_WCHAR("test_player_printmetadata_text.dat");
249 
250             iMIOFileOutText = iMioFactory->CreateTextOutput((OsclAny*) & textsinkfilename, MEDIATYPE_TEXT);
251             iIONodeText = PVMediaOutputNodeFactory::CreateMediaOutputNode(iMIOFileOutText);
252             iDataSinkText = new PVPlayerDataSinkPVMFNode;
253             ((PVPlayerDataSinkPVMFNode*)iDataSinkText)->SetDataSinkNode(iIONodeText);
254 
255             OSCL_TRY(error, iCurrentCmdId = iPlayer->AddDataSink(*iDataSinkText, (OsclAny*) & iContextObject));
256             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
257         }
258         break;
259 
260         case STATE_PREPARE:
261         {
262             OSCL_TRY(error, iCurrentCmdId = iPlayer->Prepare((OsclAny*) & iContextObject));
263             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
264         }
265         break;
266 
267         case STATE_START:
268         {
269             OSCL_TRY(error, iCurrentCmdId = iPlayer->Start((OsclAny*) & iContextObject));
270             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
271         }
272         break;
273 
274         case STATE_GETMETADATAKEYLIST2:
275         {
276             iMetadataKeyList.clear();
277             OSCL_TRY(error, iCurrentCmdId = iPlayer->GetMetadataKeys(iMetadataKeyList, 0, 50, NULL, (OsclAny*) & iContextObject));
278             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
279         }
280         break;
281 
282         case STATE_GETMETADATAVALUELIST2:
283         {
284             iMetadataValueList.clear();
285             iNumValues = 0;
286             OSCL_TRY(error, iCurrentCmdId = iPlayer->GetMetadataValues(iMetadataKeyList, 0, 50, iNumValues, iMetadataValueList, (OsclAny*) & iContextObject, !iReleaseMetadataByApp));
287             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
288         }
289         break;
290 
291         case STATE_RELEASEMETADATAVALUES2:
292         {
293             PrintMetadataInfo();
294             OSCL_TRY(error, iCurrentCmdId = iPlayer->ReleaseMetadataValues(iMetadataValueList, (OsclAny*) & iContextObject));
295             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
296         }
297         break;
298 
299         case STATE_STOP:
300         {
301             OSCL_TRY(error, iCurrentCmdId = iPlayer->Stop((OsclAny*) & iContextObject));
302             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
303         }
304         break;
305 
306         case STATE_GETMETADATAKEYLIST3:
307         {
308             iMetadataKeyList.clear();
309             OSCL_TRY(error, iCurrentCmdId = iPlayer->GetMetadataKeys(iMetadataKeyList, 0, 50, NULL, (OsclAny*) & iContextObject));
310             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
311         }
312         break;
313 
314         case STATE_GETMETADATAVALUELIST3:
315         {
316             iMetadataValueList.clear();
317             iNumValues = 0;
318             OSCL_TRY(error, iCurrentCmdId = iPlayer->GetMetadataValues(iMetadataKeyList, 0, 50, iNumValues, iMetadataValueList, (OsclAny*) & iContextObject, !iReleaseMetadataByApp));
319             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
320         }
321         break;
322 
323         case STATE_RELEASEMETADATAVALUES3:
324         {
325             PrintMetadataInfo();
326             OSCL_TRY(error, iCurrentCmdId = iPlayer->ReleaseMetadataValues(iMetadataValueList, (OsclAny*) & iContextObject));
327             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
328         }
329         break;
330 
331         case STATE_REMOVEDATASINK_VIDEO:
332         {
333             OSCL_TRY(error, iCurrentCmdId = iPlayer->RemoveDataSink(*iDataSinkVideo, (OsclAny*) & iContextObject));
334             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
335         }
336         break;
337 
338         case STATE_REMOVEDATASINK_AUDIO:
339         {
340             OSCL_TRY(error, iCurrentCmdId = iPlayer->RemoveDataSink(*iDataSinkAudio, (OsclAny*) & iContextObject));
341             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
342         }
343         break;
344 
345         case STATE_REMOVEDATASINK_TEXT:
346         {
347             OSCL_TRY(error, iCurrentCmdId = iPlayer->RemoveDataSink(*iDataSinkText, (OsclAny*) & iContextObject));
348             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
349         }
350         break;
351 
352         case STATE_RESET:
353         {
354             OSCL_TRY(error, iCurrentCmdId = iPlayer->Reset((OsclAny*) & iContextObject));
355             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
356         }
357         break;
358 
359         case STATE_REMOVEDATASOURCE:
360         {
361             OSCL_TRY(error, iCurrentCmdId = iPlayer->RemoveDataSource(*iDataSource, (OsclAny*) & iContextObject));
362             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
363         }
364         break;
365 
366         case STATE_CLEANUPANDCOMPLETE:
367         {
368             PVPATB_TEST_IS_TRUE(PVPlayerFactory::DeletePlayer(iPlayer));
369             iPlayer = NULL;
370 
371             delete iSourceContextData;
372             iSourceContextData = NULL;
373 
374             delete iDataSource;
375             iDataSource = NULL;
376 
377             delete iDataSinkVideo;
378             iDataSinkVideo = NULL;
379 
380             delete iDataSinkAudio;
381             iDataSinkAudio = NULL;
382 
383             delete iDataSinkText;
384             iDataSinkText = NULL;
385 
386             PVMediaOutputNodeFactory::DeleteMediaOutputNode(iIONodeVideo);
387             iIONodeVideo = NULL;
388 
389             PVMediaOutputNodeFactory::DeleteMediaOutputNode(iIONodeAudio);
390             iIONodeAudio = NULL;
391 
392             PVMediaOutputNodeFactory::DeleteMediaOutputNode(iIONodeText);
393             iIONodeText = NULL;
394 
395             iMioFactory->DestroyVideoOutput(iMIOFileOutVideo);
396             iMIOFileOutVideo = NULL;
397 
398             iMioFactory->DestroyAudioOutput(iMIOFileOutAudio);
399             iMIOFileOutAudio = NULL;
400 
401             iMioFactory->DestroyTextOutput(iMIOFileOutText);
402             iMIOFileOutText = NULL;
403 
404             iObserver->TestCompleted(*iTestCase);
405         }
406         break;
407 
408         default:
409             break;
410 
411     }
412 }
413 
414 
CommandCompleted(const PVCmdResponse & aResponse)415 void pvplayer_async_test_printmetadata::CommandCompleted(const PVCmdResponse& aResponse)
416 {
417     if (aResponse.GetCmdId() != iCurrentCmdId)
418     {
419         // Wrong command ID.
420         PVPATB_TEST_IS_TRUE(false);
421         iState = STATE_CLEANUPANDCOMPLETE;
422         RunIfNotReady();
423         return;
424     }
425 
426     if (aResponse.GetContext() != NULL)
427     {
428         if (aResponse.GetContext() == (OsclAny*)&iContextObject)
429         {
430             if (iContextObject != iContextObjectRefValue)
431             {
432                 // Context data value was corrupted
433                 PVPATB_TEST_IS_TRUE(false);
434                 iState = STATE_CLEANUPANDCOMPLETE;
435                 RunIfNotReady();
436                 return;
437             }
438         }
439         else
440         {
441             // Context data pointer was corrupted
442             PVPATB_TEST_IS_TRUE(false);
443             iState = STATE_CLEANUPANDCOMPLETE;
444             RunIfNotReady();
445             return;
446         }
447     }
448 
449     switch (iState)
450     {
451         case STATE_ADDDATASOURCE:
452             if (aResponse.GetCmdStatus() == PVMFSuccess)
453             {
454                 iState = STATE_INIT;
455                 RunIfNotReady();
456             }
457             else
458             {
459                 // AddDataSource failed
460                 PVPATB_TEST_IS_TRUE(false);
461                 iState = STATE_CLEANUPANDCOMPLETE;
462                 RunIfNotReady();
463             }
464             break;
465 
466         case STATE_INIT:
467             if (aResponse.GetCmdStatus() == PVMFSuccess)
468             {
469                 iState = STATE_GETMETADATAKEYLIST1;
470                 // Uncomment following to skip the first metadata retrieval
471                 //iState=STATE_ADDDATASINK_VIDEO;
472                 RunIfNotReady();
473             }
474             else
475             {
476                 // Init failed
477                 PVPATB_TEST_IS_TRUE(false);
478                 iState = STATE_CLEANUPANDCOMPLETE;
479                 RunIfNotReady();
480             }
481             break;
482 
483         case STATE_GETMETADATAKEYLIST1:
484             if (aResponse.GetCmdStatus() == PVMFSuccess || aResponse.GetCmdStatus() == PVMFErrArgument)
485             {
486                 iState = STATE_GETMETADATAVALUELIST1;
487                 RunIfNotReady();
488             }
489             else
490             {
491                 // GetMetadataKeys failed
492                 PVPATB_TEST_IS_TRUE(false);
493                 iState = STATE_CLEANUPANDCOMPLETE;
494                 RunIfNotReady();
495             }
496             break;
497 
498         case STATE_GETMETADATAVALUELIST1:
499             if (aResponse.GetCmdStatus() == PVMFSuccess || aResponse.GetCmdStatus() == PVMFErrArgument)
500             {
501                 fprintf(iTestMsgOutputFile, "After Init()\n");
502                 if (iReleaseMetadataByApp)
503                 {
504                     iState = STATE_RELEASEMETADATAVALUES1;
505                 }
506                 else
507                 {
508                     PrintMetadataInfo();
509                     iState = STATE_ADDDATASINK_VIDEO;
510                 }
511                 RunIfNotReady();
512             }
513             else
514             {
515                 // GetMetadataValue failed
516                 PVPATB_TEST_IS_TRUE(false);
517                 iState = STATE_CLEANUPANDCOMPLETE;
518                 RunIfNotReady();
519             }
520             break;
521 
522         case STATE_RELEASEMETADATAVALUES1:
523             if (aResponse.GetCmdStatus() == PVMFSuccess)
524             {
525                 iState = STATE_ADDDATASINK_VIDEO;
526                 RunIfNotReady();
527             }
528             else
529             {
530                 // ReleaseMetadataValues failed
531                 PVPATB_TEST_IS_TRUE(false);
532                 iState = STATE_CLEANUPANDCOMPLETE;
533                 RunIfNotReady();
534             }
535             break;
536 
537         case STATE_ADDDATASINK_VIDEO:
538             if (aResponse.GetCmdStatus() == PVMFSuccess)
539             {
540                 iState = STATE_ADDDATASINK_AUDIO;
541                 RunIfNotReady();
542             }
543             else
544             {
545                 // AddDataSink failed
546                 PVPATB_TEST_IS_TRUE(false);
547                 iState = STATE_CLEANUPANDCOMPLETE;
548                 RunIfNotReady();
549             }
550             break;
551 
552         case STATE_ADDDATASINK_AUDIO:
553             if (aResponse.GetCmdStatus() == PVMFSuccess)
554             {
555                 iState = STATE_ADDDATASINK_TEXT;
556                 RunIfNotReady();
557             }
558             else
559             {
560                 // AddDataSink failed
561                 PVPATB_TEST_IS_TRUE(false);
562                 iState = STATE_CLEANUPANDCOMPLETE;
563                 RunIfNotReady();
564             }
565             break;
566 
567         case STATE_ADDDATASINK_TEXT:
568             if (aResponse.GetCmdStatus() == PVMFSuccess)
569             {
570                 iState = STATE_PREPARE;
571                 RunIfNotReady();
572             }
573             else
574             {
575                 // AddDataSink failed
576                 PVPATB_TEST_IS_TRUE(false);
577                 iState = STATE_CLEANUPANDCOMPLETE;
578                 RunIfNotReady();
579             }
580             break;
581 
582         case STATE_PREPARE:
583             if (aResponse.GetCmdStatus() == PVMFSuccess)
584             {
585                 iState = STATE_START;
586                 RunIfNotReady();
587             }
588             else
589             {
590                 // Prepare failed
591                 PVPATB_TEST_IS_TRUE(false);
592                 iState = STATE_CLEANUPANDCOMPLETE;
593                 RunIfNotReady();
594             }
595             break;
596 
597         case STATE_START:
598             if (aResponse.GetCmdStatus() == PVMFSuccess)
599             {
600                 iState = STATE_GETMETADATAKEYLIST2;
601                 // Uncomment following to skip the second metadata retrieval
602                 //iState=STATE_STOP;
603                 RunIfNotReady();
604             }
605             else
606             {
607                 // Start failed
608                 PVPATB_TEST_IS_TRUE(false);
609                 iState = STATE_CLEANUPANDCOMPLETE;
610                 RunIfNotReady();
611             }
612             break;
613 
614         case STATE_GETMETADATAKEYLIST2:
615             if (aResponse.GetCmdStatus() == PVMFSuccess || aResponse.GetCmdStatus() == PVMFErrArgument)
616             {
617                 iState = STATE_GETMETADATAVALUELIST2;
618                 RunIfNotReady();
619             }
620             else
621             {
622                 // GetMetadataKeys failed
623                 PVPATB_TEST_IS_TRUE(false);
624                 iState = STATE_CLEANUPANDCOMPLETE;
625                 RunIfNotReady();
626             }
627             break;
628 
629         case STATE_GETMETADATAVALUELIST2:
630             if (aResponse.GetCmdStatus() == PVMFSuccess || aResponse.GetCmdStatus() == PVMFErrArgument)
631             {
632                 fprintf(iTestMsgOutputFile, "After Start()\n");
633                 if (iReleaseMetadataByApp)
634                 {
635                     iState = STATE_RELEASEMETADATAVALUES2;
636                 }
637                 else
638                 {
639                     PrintMetadataInfo();
640                     iState = STATE_STOP;
641                 }
642                 RunIfNotReady();
643             }
644             else
645             {
646                 // GetMetadataValue failed
647                 PVPATB_TEST_IS_TRUE(false);
648                 iState = STATE_CLEANUPANDCOMPLETE;
649                 RunIfNotReady();
650             }
651             break;
652 
653         case STATE_RELEASEMETADATAVALUES2:
654             if (aResponse.GetCmdStatus() == PVMFSuccess)
655             {
656                 iState = STATE_STOP;
657                 RunIfNotReady();
658             }
659             else
660             {
661                 // ReleaseMetadataValues failed
662                 PVPATB_TEST_IS_TRUE(false);
663                 iState = STATE_CLEANUPANDCOMPLETE;
664                 RunIfNotReady();
665             }
666             break;
667 
668         case STATE_STOP:
669             if (aResponse.GetCmdStatus() == PVMFSuccess)
670             {
671                 iState = STATE_GETMETADATAKEYLIST3;
672                 // Uncomment following to skip the third metadata retrieval
673                 //iState=STATE_REMOVEDATASINK_VIDEO;
674                 RunIfNotReady();
675             }
676             else
677             {
678                 // Stop failed
679                 PVPATB_TEST_IS_TRUE(false);
680                 iState = STATE_CLEANUPANDCOMPLETE;
681                 RunIfNotReady();
682             }
683             break;
684 
685         case STATE_GETMETADATAKEYLIST3:
686             if (aResponse.GetCmdStatus() == PVMFSuccess || aResponse.GetCmdStatus() == PVMFErrArgument)
687             {
688                 iState = STATE_GETMETADATAVALUELIST3;
689                 RunIfNotReady();
690             }
691             else
692             {
693                 // GetMetadataKeys failed
694                 PVPATB_TEST_IS_TRUE(false);
695                 iState = STATE_CLEANUPANDCOMPLETE;
696                 RunIfNotReady();
697             }
698             break;
699 
700         case STATE_GETMETADATAVALUELIST3:
701             if (aResponse.GetCmdStatus() == PVMFSuccess || aResponse.GetCmdStatus() == PVMFErrArgument)
702             {
703                 fprintf(iTestMsgOutputFile, "After Stop()\n");
704                 if (iReleaseMetadataByApp)
705                 {
706                     iState = STATE_RELEASEMETADATAVALUES3;
707                 }
708                 else
709                 {
710                     PrintMetadataInfo();
711                     iState = STATE_REMOVEDATASINK_VIDEO;
712                 }
713                 RunIfNotReady();
714             }
715             else
716             {
717                 // GetMetadataValue failed
718                 PVPATB_TEST_IS_TRUE(false);
719                 iState = STATE_CLEANUPANDCOMPLETE;
720                 RunIfNotReady();
721             }
722             break;
723 
724         case STATE_RELEASEMETADATAVALUES3:
725             if (aResponse.GetCmdStatus() == PVMFSuccess)
726             {
727                 iState = STATE_REMOVEDATASINK_VIDEO;
728                 RunIfNotReady();
729             }
730             else
731             {
732                 // ReleaseMetadataValues failed
733                 PVPATB_TEST_IS_TRUE(false);
734                 iState = STATE_CLEANUPANDCOMPLETE;
735                 RunIfNotReady();
736             }
737             break;
738 
739         case STATE_REMOVEDATASINK_VIDEO:
740             if (aResponse.GetCmdStatus() == PVMFSuccess)
741             {
742                 iState = STATE_REMOVEDATASINK_AUDIO;
743                 RunIfNotReady();
744             }
745             else
746             {
747                 // RemoveDataSink failed
748                 PVPATB_TEST_IS_TRUE(false);
749                 iState = STATE_CLEANUPANDCOMPLETE;
750                 RunIfNotReady();
751             }
752             break;
753 
754         case STATE_REMOVEDATASINK_AUDIO:
755             if (aResponse.GetCmdStatus() == PVMFSuccess)
756             {
757                 iState = STATE_REMOVEDATASINK_TEXT;
758                 RunIfNotReady();
759             }
760             else
761             {
762                 // RemoveDataSink failed
763                 PVPATB_TEST_IS_TRUE(false);
764                 iState = STATE_CLEANUPANDCOMPLETE;
765                 RunIfNotReady();
766             }
767             break;
768 
769         case STATE_REMOVEDATASINK_TEXT:
770             if (aResponse.GetCmdStatus() == PVMFSuccess)
771             {
772                 iState = STATE_RESET;
773                 RunIfNotReady();
774             }
775             else
776             {
777                 // RemoveDataSink failed
778                 PVPATB_TEST_IS_TRUE(false);
779                 iState = STATE_CLEANUPANDCOMPLETE;
780                 RunIfNotReady();
781             }
782             break;
783 
784         case STATE_RESET:
785             if (aResponse.GetCmdStatus() == PVMFSuccess)
786             {
787                 iState = STATE_REMOVEDATASOURCE;
788                 RunIfNotReady();
789             }
790             else
791             {
792                 // Reset failed
793                 PVPATB_TEST_IS_TRUE(false);
794                 iState = STATE_CLEANUPANDCOMPLETE;
795                 RunIfNotReady();
796             }
797             break;
798 
799         case STATE_REMOVEDATASOURCE:
800             if (aResponse.GetCmdStatus() == PVMFSuccess)
801             {
802                 PVPATB_TEST_IS_TRUE(true);
803                 iState = STATE_CLEANUPANDCOMPLETE;
804                 RunIfNotReady();
805             }
806             else
807             {
808                 // RemoveDataSource failed
809                 PVPATB_TEST_IS_TRUE(false);
810                 iState = STATE_CLEANUPANDCOMPLETE;
811                 RunIfNotReady();
812             }
813             break;
814 
815         default:
816         {
817             // Testing error if this is reached
818             PVPATB_TEST_IS_TRUE(false);
819             iState = STATE_CLEANUPANDCOMPLETE;
820             RunIfNotReady();
821         }
822         break;
823     }
824 }
825 
826 
HandleErrorEvent(const PVAsyncErrorEvent & aEvent)827 void pvplayer_async_test_printmetadata::HandleErrorEvent(const PVAsyncErrorEvent& aEvent)
828 {
829     switch (aEvent.GetEventType())
830     {
831         case PVMFErrResourceConfiguration:
832             // Just log the error
833             PVPATB_TEST_IS_TRUE(false);
834             break;
835 
836         case PVMFErrResource:
837             // Just log the error
838             PVPATB_TEST_IS_TRUE(false);
839             break;
840 
841         case PVMFErrCorrupt:
842             // Just log the error
843             PVPATB_TEST_IS_TRUE(false);
844             break;
845 
846         case PVMFErrProcessing:
847             // Just log the error
848             PVPATB_TEST_IS_TRUE(false);
849             break;
850 
851         default:
852             // Unknown error and just log the error
853             PVPATB_TEST_IS_TRUE(false);
854             break;
855     }
856 
857     // Wait for engine to handle the error
858     Cancel();
859 }
860 
861 
HandleInformationalEvent(const PVAsyncInformationalEvent & aEvent)862 void pvplayer_async_test_printmetadata::HandleInformationalEvent(const PVAsyncInformationalEvent& aEvent)
863 {
864     if (aEvent.GetEventType() == PVMFInfoErrorHandlingStart)
865     {
866         fprintf(iTestMsgOutputFile, "PVMFInfoErrorHandlingStart...\n");
867     }
868     if (aEvent.GetEventType() == PVMFInfoErrorHandlingComplete)
869     {
870         fprintf(iTestMsgOutputFile, "PVMFInfoErrorHandlingComplete...\n");
871         iState = STATE_CLEANUPANDCOMPLETE;
872         RunIfNotReady();
873     }
874 }
875 
876 /* PrintCodecSpecificInfo() prints the codec specific information for
877    the respective AUDIO TYPE stream and VIDEO TYPE stream.
878 
879    Please note that the usage of numerical constants for transversing
880    the bytes should not be treated as hard coded values usage, because
881    the starting offset of each filed in codec specific info is fixed and
882    these locations are not tunable. That is why these constants are not
883    defined under #define.
884 
885 */
PrintCodecSpecificInfo(char * aData,uint32 aIndex)886 void pvplayer_async_test_printmetadata::PrintCodecSpecificInfo(char* aData, uint32 aIndex)
887 {
888 
889     if (INDEX_CODEC_SPECIFIC_INFO_AUDIO == aIndex)
890     {
891         uint16 CodecId = ((*(aData + 0))         & 0x000000FF)
892                          + (((*(aData + 1)) << 8)  & 0x0000FF00);
893 
894         fprintf(iTestMsgOutputFile, "	CodecId:%d \n", CodecId);
895 
896         uint16 NumChannels = ((*(aData + 2))         & 0x000000FF)
897                              + (((*(aData + 3)) << 8)  & 0x0000FF00);
898 
899         fprintf(iTestMsgOutputFile, "	NumChannels:%d \n", NumChannels);
900 
901         uint32 SamplesPerSecond = ((*(aData + 4))         & 0x000000FF)
902                                   + (((*(aData + 5)) << 8)  & 0x0000FF00)
903                                   + (((*(aData + 6)) << 16) & 0x00FF0000)
904                                   + (((*(aData + 7)) << 24) & 0xFF000000);
905 
906         fprintf(iTestMsgOutputFile, "	SamplesPerSecond:%d \n", SamplesPerSecond);
907 
908         uint32 AvgNumBytesPerSecond = ((*(aData + 8))          & 0x000000FF)
909                                       + (((*(aData + 9)) << 8)   & 0x0000FF00)
910                                       + (((*(aData + 10)) << 16) & 0x00FF0000)
911                                       + (((*(aData + 11)) << 24) & 0xFF000000);
912 
913         fprintf(iTestMsgOutputFile, "	AvgNumBytesPerSecond:%d \n", AvgNumBytesPerSecond);
914 
915         uint16 BlockAlignment = ((*(aData + 12))         & 0x000000FF)
916                                 + (((*(aData + 13)) << 8)  & 0x0000FF00);
917 
918         fprintf(iTestMsgOutputFile, "	BlockAlignment:%d \n", BlockAlignment);
919 
920         uint16 BitsPerSample = ((*(aData + 14))         & 0x000000FF)
921                                + (((*(aData + 15)) << 8)  & 0x0000FF00);
922 
923         fprintf(iTestMsgOutputFile, "	BitsPerSample:%d \n", BitsPerSample);
924 
925         uint16 CodecSpecificDataSize = ((*(aData + 16))         & 0x000000FF)
926                                        + (((*(aData + 17)) << 8)  & 0x0000FF00);
927 
928         fprintf(iTestMsgOutputFile, "	CodecSpecificDataSize:%d \n", CodecSpecificDataSize);
929 
930         fprintf(iTestMsgOutputFile, "	CodecSpecifcData: \n");
931         fprintf(iTestMsgOutputFile, "\t");
932         for (uint16 ii = 0; ii < CodecSpecificDataSize; ii++)
933         {
934             fprintf(iTestMsgOutputFile, "0x%02x ", (*(aData + 18 + ii) & 0xff));
935 
936         }
937         fprintf(iTestMsgOutputFile, "\n");
938 
939 
940     }
941     else if (INDEX_CODEC_SPECIFIC_INFO_VIDEO == aIndex)
942     {
943         uint32 ImageWidth = ((*(aData + 0))         & 0x000000FF)
944                             + (((*(aData + 1)) << 8)  & 0x0000FF00)
945                             + (((*(aData + 2)) << 16) & 0x00FF0000)
946                             + (((*(aData + 3)) << 24) & 0xFF000000);
947         fprintf(iTestMsgOutputFile, "	ImageWidth:%d \n", ImageWidth);
948 
949         uint32 Imageheight = ((*(aData + 4))         & 0x000000FF)
950                              + (((*(aData + 5)) << 8)  & 0x0000FF00)
951                              + (((*(aData + 6)) << 16) & 0x00FF0000)
952                              + (((*(aData + 7)) << 24) & 0xFF000000);
953         fprintf(iTestMsgOutputFile, "	Imageheight:%d \n", Imageheight);
954 
955         uint8 ReservedFlags = ((*(aData + 8)) & 0x000000FF);
956         fprintf(iTestMsgOutputFile, "	ReservedFlags:%d \n", ReservedFlags);
957 
958         uint16 FormatDataSize = ((*(aData + 9))          & 0x000000FF)
959                                 + (((*(aData + 10)) << 8)  & 0x0000FF00);
960 
961         fprintf(iTestMsgOutputFile, "	FormatDataSize:%d \n", FormatDataSize);
962 
963         uint32 FormatDataFormatDataSize = ((*(aData + 11))         & 0x000000FF)
964                                           + (((*(aData + 12)) << 8)  & 0x0000FF00)
965                                           + (((*(aData + 13)) << 16) & 0x00FF0000)
966                                           + (((*(aData + 14)) << 24) & 0xFF000000);
967         fprintf(iTestMsgOutputFile, "	FormatDataFormatDataSize:%d \n", FormatDataFormatDataSize);
968 
969         uint32 FormatDataImageWidth = ((*(aData + 15))         & 0x000000FF)
970                                       + (((*(aData + 16)) << 8)  & 0x0000FF00)
971                                       + (((*(aData + 17)) << 16) & 0x00FF0000)
972                                       + (((*(aData + 18)) << 24) & 0xFF000000);
973         fprintf(iTestMsgOutputFile, "	FormatDataImageWidth:%d \n", FormatDataImageWidth);
974 
975         uint32 FormatDataImageHeight = ((*(aData + 19))         & 0x000000FF)
976                                        + (((*(aData + 20)) << 8)  & 0x0000FF00)
977                                        + (((*(aData + 21)) << 16) & 0x00FF0000)
978                                        + (((*(aData + 22)) << 24) & 0xFF000000);
979         fprintf(iTestMsgOutputFile, "	FormatDataImageHeight:%d \n", FormatDataImageHeight);
980 
981         uint16 FormatDataReserved = ((*(aData + 23))         & 0x000000FF)
982                                     + (((*(aData + 24)) << 8)  & 0x0000FF00);
983 
984         fprintf(iTestMsgOutputFile, "	FormatDataReserved:%d \n", FormatDataReserved);
985 
986         uint16 FormatDataBitsPerPixelCount = ((*(aData + 25))         & 0x000000FF)
987                                              + (((*(aData + 26)) << 8)  & 0x0000FF00);
988 
989         fprintf(iTestMsgOutputFile, "	FormatDataBitsPerPixelCount:%d \n", FormatDataBitsPerPixelCount);
990 
991         uint32 FormatDataCompressionId = ((*(aData + 27))         & 0x000000FF)
992                                          + (((*(aData + 28)) << 8)  & 0x0000FF00)
993                                          + (((*(aData + 29)) << 16) & 0x00FF0000)
994                                          + (((*(aData + 30)) << 24) & 0xFF000000);
995 
996         fprintf(iTestMsgOutputFile, "	FormatDataCompressionId:%d \n", FormatDataCompressionId);
997 
998         uint32 FormatDataImageSize = ((*(aData + 31))         & 0x000000FF)
999                                      + (((*(aData + 32)) << 8)  & 0x0000FF00)
1000                                      + (((*(aData + 33)) << 16) & 0x00FF0000)
1001                                      + (((*(aData + 34)) << 24) & 0xFF000000);
1002 
1003         fprintf(iTestMsgOutputFile, "	FormatDataImageSize:%d \n", FormatDataImageSize);
1004 
1005         uint32 FormatDataHorizontalPixelsPerMeter = ((*(aData + 35))         & 0x000000FF)
1006                 + (((*(aData + 36)) << 8)  & 0x0000FF00)
1007                 + (((*(aData + 37)) << 16) & 0x00FF0000)
1008                 + (((*(aData + 38)) << 24) & 0xFF000000);
1009 
1010         fprintf(iTestMsgOutputFile, "	FormatDataHorizontalPixelsPerMeter:%d \n", FormatDataHorizontalPixelsPerMeter);
1011 
1012         uint32 FormatDataVerticalPixelsPerMeter = ((*(aData + 39))         & 0x000000FF)
1013                 + (((*(aData + 40)) << 8)  & 0x0000FF00)
1014                 + (((*(aData + 41)) << 16) & 0x00FF0000)
1015                 + (((*(aData + 42)) << 24) & 0xFF000000);
1016 
1017         fprintf(iTestMsgOutputFile, "	FormatDataVerticalPixelsPerMeter:%d \n", FormatDataVerticalPixelsPerMeter);
1018 
1019         uint32 FormatDataColorsUsedCount = ((*(aData + 43))         & 0x000000FF)
1020                                            + (((*(aData + 44)) << 8)  & 0x0000FF00)
1021                                            + (((*(aData + 45)) << 16) & 0x00FF0000)
1022                                            + (((*(aData + 46)) << 24) & 0xFF000000);
1023 
1024         fprintf(iTestMsgOutputFile, "	FormatDataColorsUsedCount:%d \n", FormatDataColorsUsedCount);
1025 
1026         uint32 FormatDataImportantColorsCount = ((*(aData + 47))         & 0x000000FF)
1027                                                 + (((*(aData + 48)) << 8)  & 0x0000FF00)
1028                                                 + (((*(aData + 49)) << 16) & 0x00FF0000)
1029                                                 + (((*(aData + 50)) << 24) & 0xFF000000);
1030 
1031         fprintf(iTestMsgOutputFile, "	FormatDataImportantColorsCount:%d \n", FormatDataImportantColorsCount);
1032 
1033         fprintf(iTestMsgOutputFile, "	CodecSpecifcData: \n");
1034         fprintf(iTestMsgOutputFile, "\t");
1035         for (uint16 ii = 0; ii < (FormatDataSize - SIZE_FORMATDATA_VIDEO); ii++)
1036         {
1037             fprintf(iTestMsgOutputFile, "0x%02x ", (*(aData + 51 + ii) & 0xff));
1038 
1039         }
1040         fprintf(iTestMsgOutputFile, "\n");
1041     }
1042     else
1043     {
1044         fprintf(iTestMsgOutputFile, "Codec Specific Info with index %d not supported\n", aIndex);
1045 
1046     }
1047 
1048 }
1049 
GetIndexParamValues(const char * aString,uint32 & aStartIndex,uint32 & aEndIndex)1050 PVMFStatus pvplayer_async_test_printmetadata::GetIndexParamValues(const char* aString,
1051         uint32& aStartIndex,
1052         uint32& aEndIndex)
1053 {
1054     /*
1055      * This parses a string of the form "index=N1...N2" and extracts the integers N1 and N2.
1056      * If string is of the format "index=N1" then N2=N1
1057      */
1058     if (NULL == aString)
1059     {
1060         return PVMFErrArgument;
1061     }
1062 
1063     /* Go to end of "index=" */
1064     char* pN1string = (char*)aString + 6;
1065     const char ch = 'd';
1066     PV_atoi(pN1string, ch, (int32)oscl_strlen(pN1string), (uint32&)aStartIndex);
1067     const char* pN2string = oscl_strstr(aString, _STRLIT_CHAR("..."));
1068     if (NULL == pN2string)
1069     {
1070         aEndIndex = aStartIndex;
1071     }
1072     else
1073     {
1074         /* Go to end of "index=N1..." */
1075         pN2string += 3;
1076         PV_atoi(pN2string, ch, (int32)oscl_strlen(pN2string), (uint32&)aEndIndex);
1077     }
1078     return PVMFSuccess;
1079 }
1080 
PrintMetadataInfo()1081 void pvplayer_async_test_printmetadata::PrintMetadataInfo()
1082 {
1083     uint32 i = 0, StartIndex = 0, EndIndex = 0, nCnt = 0, jj = 0;
1084     iCodecSpecificInfoAudioIndex = INDEX_CODEC_SPECIFIC_INFO_UNDEFINED;
1085     iCodecSpecificInfoVideoIndex = INDEX_CODEC_SPECIFIC_INFO_UNDEFINED;
1086     CodecSpecificInfo  sCSI[MAX_CODEC_SPECIFIC_INFO_SUPPORTED];
1087     for (jj = 0; jj < MAX_CODEC_SPECIFIC_INFO_SUPPORTED; jj++)
1088     {
1089         sCSI[jj].CodecSpecificInfoIndex     = -1;
1090         sCSI[jj].MetadataKeyIndex           = -1;
1091         sCSI[jj].ValueIndex                 = -1;
1092     }
1093 
1094     fprintf(iTestMsgOutputFile, "Metadata key list (count=%d):\n", iMetadataKeyList.size());
1095     for (i = 0; i < iMetadataKeyList.size(); ++i)
1096     {
1097         fprintf(iTestMsgOutputFile, "Key %d: %s\n", (i + 1), iMetadataKeyList[i].get_cstr());
1098     }
1099 
1100     fprintf(iTestMsgOutputFile, "\nMetadata value list (count=%d):\n", iMetadataValueList.size());
1101     for (i = 0; i < iMetadataValueList.size(); ++i)
1102     {
1103 
1104         // Skip the logging of metadata if it is track-info/codec-specific-info, it will require track-info to be extracted first
1105         // And as the track-info matches, the startindex is extracted and compared to
1106         // iCodecSpecificInfoAudioIndex/ iCodecSpecificInfoVideoIndex to print the respective codec-specific-info.
1107 
1108         if ((oscl_strncmp(iMetadataValueList[i].key, PVMF_ASF_PARSER_NODE_TRACKINFO_CODEC_DATA_KEY, oscl_strlen(PVMF_ASF_PARSER_NODE_TRACKINFO_CODEC_DATA_KEY)) == 0))
1109         {
1110             char *pIndexPtr = (char*)oscl_strstr(iMetadataValueList[i].key, "track-info/codec-specific-info;valtype=uint8*;");
1111             if (NULL != pIndexPtr)
1112             {
1113                 pIndexPtr = (char *)oscl_strstr(pIndexPtr, "index=");
1114                 GetIndexParamValues(pIndexPtr, StartIndex, EndIndex);
1115                 sCSI[nCnt].CodecSpecificInfoIndex = StartIndex;
1116                 sCSI[nCnt].MetadataKeyIndex = i;
1117                 sCSI[nCnt].ValueIndex = (i + 1);
1118                 nCnt++;
1119 
1120                 if ((int32)StartIndex == iCodecSpecificInfoAudioIndex)
1121                 {
1122                     fprintf(iTestMsgOutputFile, "Value %d:\n", (i + 1));
1123                     fprintf(iTestMsgOutputFile, "   Key string: %s\n", iMetadataValueList[sCSI[jj].MetadataKeyIndex].key);
1124                     PrintCodecSpecificInfo(iMetadataValueList[i].value.pChar_value, INDEX_CODEC_SPECIFIC_INFO_AUDIO);
1125                 }
1126                 else if ((int32)StartIndex == iCodecSpecificInfoVideoIndex)
1127                 {
1128                     fprintf(iTestMsgOutputFile, "Value %d:\n", (i + 1));
1129                     fprintf(iTestMsgOutputFile, "   Key string: %s\n", iMetadataValueList[sCSI[jj].MetadataKeyIndex].key);
1130                     PrintCodecSpecificInfo(iMetadataValueList[i].value.pChar_value, INDEX_CODEC_SPECIFIC_INFO_VIDEO);
1131                 }
1132             }
1133             continue;
1134         }
1135 
1136 
1137         fprintf(iTestMsgOutputFile, "Value %d:\n", (i + 1));
1138         fprintf(iTestMsgOutputFile, "   Key string: %s\n", iMetadataValueList[i].key);
1139 
1140         switch (GetValTypeFromKeyString(iMetadataValueList[i].key))
1141         {
1142             case PVMI_KVPVALTYPE_CHARPTR:
1143 
1144             {
1145                 fprintf(iTestMsgOutputFile, "   Value:%s\n", iMetadataValueList[i].value.pChar_value);
1146                 fprintf(iTestMsgOutputFile, "   Length:%d  Capacity:%d\n", iMetadataValueList[i].length, iMetadataValueList[i].capacity);
1147 
1148                 // Checks whether the iMetadataValueList[i].key matches the track-info/type.
1149                 // If matches, then it checks for the index value, extracts the index and stores it in startindex.
1150                 // Then it verifies for WMA/WMV and accordingly prints the codec-specific-info.
1151                 // And if it does not match then it continues till it matches.
1152 
1153                 char *pIndexPtr = (char *)oscl_strstr(iMetadataValueList[i].key, "track-info/type;valtype=char*;");
1154                 if (NULL != pIndexPtr)
1155                 {
1156                     pIndexPtr = (char *)oscl_strstr(iMetadataValueList[i].key, "index=");
1157                     GetIndexParamValues(pIndexPtr, StartIndex, EndIndex);
1158                     if ((oscl_strncmp(iMetadataValueList[i].value.pChar_value, "audio/x-ms-wma", oscl_strlen("audio/x-ms-wma")) == 0))
1159                     {
1160                         iCodecSpecificInfoAudioIndex = (int32)StartIndex;
1161                         for (uint32 jj = 0; jj <= nCnt; jj++)
1162                         {
1163                             if ((uint32)sCSI[jj].CodecSpecificInfoIndex == StartIndex)
1164                             {
1165                                 fprintf(iTestMsgOutputFile, "Value %d:\n", sCSI[jj].ValueIndex);
1166                                 fprintf(iTestMsgOutputFile, "   Key string: %s\n", iMetadataValueList[sCSI[jj].MetadataKeyIndex].key);
1167                                 fprintf(iTestMsgOutputFile, "   Value: UNKNOWN VALUE TYPE\n");
1168                                 fprintf(iTestMsgOutputFile, "   Length:%d  Capacity:%d\n", iMetadataValueList[sCSI[jj].MetadataKeyIndex].length, iMetadataValueList[sCSI[jj].MetadataKeyIndex].capacity);
1169                                 PrintCodecSpecificInfo(iMetadataValueList[sCSI[jj].MetadataKeyIndex].value.pChar_value, INDEX_CODEC_SPECIFIC_INFO_AUDIO);
1170                                 break;
1171                             }
1172                         }
1173                     }
1174 
1175                     else if ((oscl_strncmp(iMetadataValueList[i].value.pChar_value, "video/x-ms-wmv", oscl_strlen("video/x-ms-wmv")) == 0))
1176                     {
1177                         iCodecSpecificInfoVideoIndex = StartIndex;
1178                         for (uint jj = 0; jj <= nCnt; jj++)
1179                         {
1180                             if ((uint32)sCSI[jj].CodecSpecificInfoIndex == StartIndex)
1181                             {
1182                                 fprintf(iTestMsgOutputFile, "Value %d:\n", sCSI[jj].ValueIndex);
1183                                 fprintf(iTestMsgOutputFile, "   Key string: %s\n", iMetadataValueList[sCSI[jj].MetadataKeyIndex].key);
1184                                 fprintf(iTestMsgOutputFile, "   Value: UNKNOWN VALUE TYPE\n");
1185                                 fprintf(iTestMsgOutputFile, "   Length:%d  Capacity:%d\n", iMetadataValueList[sCSI[jj].MetadataKeyIndex].length, iMetadataValueList[sCSI[jj].MetadataKeyIndex].capacity);
1186                                 PrintCodecSpecificInfo(iMetadataValueList[sCSI[jj].MetadataKeyIndex].value.pChar_value, INDEX_CODEC_SPECIFIC_INFO_VIDEO);
1187                                 break;
1188                             }
1189                         }
1190                     }
1191 
1192                 }
1193 
1194             }
1195             break;
1196 
1197             case PVMI_KVPVALTYPE_WCHARPTR:
1198             {
1199                 // Assume string is in UCS-2 encoding so convert to UTF-8
1200                 char tmpstr[65];
1201                 oscl_UnicodeToUTF8(iMetadataValueList[i].value.pWChar_value,
1202                                    oscl_strlen(iMetadataValueList[i].value.pWChar_value), tmpstr, 65);
1203                 tmpstr[64] = '\0';
1204                 fprintf(iTestMsgOutputFile, "   Value(in UTF-8, first 64 chars):%s\n", tmpstr);
1205             }
1206             fprintf(iTestMsgOutputFile, "   Length:%d  Capacity:%d\n", iMetadataValueList[i].length, iMetadataValueList[i].capacity);
1207             break;
1208 
1209             case PVMI_KVPVALTYPE_UINT32:
1210                 fprintf(iTestMsgOutputFile, "   Value:%d\n", iMetadataValueList[i].value.uint32_value);
1211                 fprintf(iTestMsgOutputFile, "   Length:%d  Capacity:%d\n", iMetadataValueList[i].length, iMetadataValueList[i].capacity);
1212                 break;
1213 
1214             case PVMI_KVPVALTYPE_INT32:
1215                 fprintf(iTestMsgOutputFile, "   Value:%d\n", iMetadataValueList[i].value.int32_value);
1216                 fprintf(iTestMsgOutputFile, "   Length:%d  Capacity:%d\n", iMetadataValueList[i].length, iMetadataValueList[i].capacity);
1217                 break;
1218 
1219             case PVMI_KVPVALTYPE_UINT8:
1220                 fprintf(iTestMsgOutputFile, "   Value:%d\n", iMetadataValueList[i].value.uint8_value);
1221                 fprintf(iTestMsgOutputFile, "   Length:%d  Capacity:%d\n", iMetadataValueList[i].length, iMetadataValueList[i].capacity);
1222                 break;
1223 
1224             case PVMI_KVPVALTYPE_FLOAT:
1225                 fprintf(iTestMsgOutputFile, "   Value:%f\n", iMetadataValueList[i].value.float_value);
1226                 fprintf(iTestMsgOutputFile, "   Length:%d  Capacity:%d\n", iMetadataValueList[i].length, iMetadataValueList[i].capacity);
1227                 break;
1228 
1229             case PVMI_KVPVALTYPE_DOUBLE:
1230                 fprintf(iTestMsgOutputFile, "   Value:%f\n", iMetadataValueList[i].value.double_value);
1231                 fprintf(iTestMsgOutputFile, "   Length:%d  Capacity:%d\n", iMetadataValueList[i].length, iMetadataValueList[i].capacity);
1232                 break;
1233 
1234             case PVMI_KVPVALTYPE_BOOL:
1235                 if (iMetadataValueList[i].value.bool_value)
1236                 {
1237                     fprintf(iTestMsgOutputFile, "   Value:true(1)\n");
1238                 }
1239                 else
1240                 {
1241                     fprintf(iTestMsgOutputFile, "   Value:false(0)\n");
1242                 }
1243                 fprintf(iTestMsgOutputFile, "   Length:%d  Capacity:%d\n", iMetadataValueList[i].length, iMetadataValueList[i].capacity);
1244                 break;
1245 
1246             default:
1247                 fprintf(iTestMsgOutputFile, "   Value: UNKNOWN VALUE TYPE\n");
1248                 fprintf(iTestMsgOutputFile, "   Length:%d  Capacity:%d\n", iMetadataValueList[i].length, iMetadataValueList[i].capacity);
1249                 break;
1250         }
1251 
1252 
1253     }
1254 
1255     fprintf(iTestMsgOutputFile, "\n\n");
1256 }
1257 
1258 
1259 //
1260 // pvplayer_async_test_printmemstats section
1261 //
StartTest()1262 void pvplayer_async_test_printmemstats::StartTest()
1263 {
1264     AddToScheduler();
1265     iState = STATE_CREATE;
1266     RunIfNotReady();
1267 }
1268 
1269 
Run()1270 void pvplayer_async_test_printmemstats::Run()
1271 {
1272     int error = 0;
1273 
1274     switch (iState)
1275     {
1276         case STATE_CREATE:
1277         {
1278 #if !(OSCL_BYPASS_MEMMGT)
1279             // Obtain the current mem stats
1280             OsclAuditCB auditCB;
1281             OsclMemInit(auditCB);
1282             if (auditCB.pAudit)
1283             {
1284                 MM_Stats_t* stats = auditCB.pAudit->MM_GetStats("");
1285                 if (stats)
1286                 {
1287                     iInitialNumBytes = stats->numBytes;
1288                     iInitialNumAllocs = stats->numAllocs;
1289                     fprintf(iTestMsgOutputFile, "Initial memstats: %d allocs, %d bytes\n", iInitialNumAllocs, iInitialNumBytes);
1290                 }
1291                 else
1292                 {
1293                     fprintf(iTestMsgOutputFile, "Retrieving initial memory statistics failed! Memory statistics result would be invalid.\n");
1294                 }
1295             }
1296             else
1297             {
1298                 fprintf(iTestMsgOutputFile, "Memory audit not available! Memory statistics result would be invalid.\n");
1299             }
1300 #else
1301             fprintf(iTestMsgOutputFile, "MEMORY AUDIT DISABLED\n");
1302 #endif
1303 
1304             iPlayer = NULL;
1305 
1306             OSCL_TRY(error, iPlayer = PVPlayerFactory::CreatePlayer(this, this, this));
1307             if (error)
1308             {
1309                 PVPATB_TEST_IS_TRUE(false);
1310                 iObserver->TestCompleted(*iTestCase);
1311             }
1312             else
1313             {
1314                 fprintf(iTestMsgOutputFile, "After player instantiation: ");
1315                 PrintMemStats();
1316                 iState = STATE_ADDDATASOURCE;
1317                 RunIfNotReady();
1318             }
1319         }
1320         break;
1321 
1322         case STATE_ADDDATASOURCE:
1323         {
1324             iDataSource = new PVPlayerDataSourceURL;
1325             oscl_UTF8ToUnicode(iFileName, oscl_strlen(iFileName), iTmpWCharBuffer, 512);
1326             iTmpWCharBuffer[511] = '\0';
1327             iFileNameWStr = SOURCENAME_PREPEND_WSTRING;
1328             iFileNameWStr += iTmpWCharBuffer;
1329             /*
1330              * In case of HTTP URLs always attempt rollover,
1331              * since we donot know if it is a download or a streaming url
1332              */
1333             if (iFileType == PVMF_MIME_DATA_SOURCE_HTTP_URL)
1334             {
1335                 iSourceContextData = new PVMFSourceContextData();
1336                 iSourceContextData->EnableStreamingSourceContext();
1337                 iSourceContextData->EnableCommonSourceContext();
1338                 PVInterface* sourceContextStream = NULL;
1339 
1340                 PVUuid streamingContextUuid(PVMF_SOURCE_CONTEXT_DATA_STREAMING_UUID);
1341                 if (iSourceContextData->queryInterface(streamingContextUuid, sourceContextStream))
1342                 {
1343                     PVMFSourceContextDataStreaming* streamingContext =
1344                         OSCL_STATIC_CAST(PVMFSourceContextDataStreaming*, sourceContextStream);
1345                     streamingContext->iStreamStatsLoggingURL = iFileNameWStr;
1346 
1347                     if (iProxyEnabled)
1348                     {
1349                         streamingContext->iProxyName = _STRLIT_WCHAR("");
1350                         streamingContext->iProxyPort = 8080;
1351                     }
1352                 }
1353                 PVInterface* sourceContextDownload = NULL;
1354                 iSourceContextData->EnableDownloadHTTPSourceContext();
1355                 PVUuid downloadContextUuid(PVMF_SOURCE_CONTEXT_DATA_DOWNLOAD_HTTP_UUID);
1356                 if (iSourceContextData->queryInterface(downloadContextUuid, sourceContextDownload))
1357                 {
1358                     //create the opaque data
1359                     iDownloadProxy = _STRLIT_CHAR("");
1360                     int32 iDownloadProxyPort = 0;
1361                     if (iProxyEnabled)
1362                     {
1363                         iDownloadProxy = _STRLIT_CHAR("");
1364                         iDownloadProxyPort = 8080;
1365                     }
1366                     iDownloadConfigFilename = OUTPUTNAME_PREPEND_WSTRING;
1367                     iDownloadConfigFilename += _STRLIT_WCHAR("mydlconfig");
1368                     iDownloadMaxfilesize = 0x7FFFFFFF;
1369                     iDownloadFilename = OUTPUTNAME_PREPEND_WSTRING;
1370                     iDownloadFilename += _STRLIT_WCHAR("test_ftdownload.dl");
1371                     bool aIsNewSession = true;
1372 
1373                     iSourceContextData->DownloadHTTPData()->bIsNewSession = aIsNewSession;
1374                     iSourceContextData->DownloadHTTPData()->iConfigFileName = iDownloadConfigFilename;
1375                     iSourceContextData->DownloadHTTPData()->iDownloadFileName = iDownloadFilename;
1376                     iSourceContextData->DownloadHTTPData()->iMaxFileSize = iDownloadMaxfilesize;
1377                     iSourceContextData->DownloadHTTPData()->iPlaybackControl = PVMFSourceContextDataDownloadHTTP::EAsap;
1378                     iSourceContextData->DownloadHTTPData()->iProxyName = iDownloadProxy;
1379                     iSourceContextData->DownloadHTTPData()->iProxyPort = iDownloadProxyPort;
1380 
1381                 }
1382                 iDataSource->SetDataSourceContextData((OsclAny*)iSourceContextData);
1383 
1384                 iDataSource->SetDataSourceFormatType(PVMF_MIME_DATA_SOURCE_MS_HTTP_STREAMING_URL);
1385                 iDataSource->SetAlternateSourceFormatType(PVMF_MIME_DATA_SOURCE_HTTP_URL);
1386             }
1387             else
1388             {
1389                 iDataSource->SetDataSourceFormatType(iFileType);
1390             }
1391 
1392             iDataSource->SetDataSourceURL(iFileNameWStr);
1393 
1394             OSCL_TRY(error, iCurrentCmdId = iPlayer->AddDataSource(*iDataSource, (OsclAny*) & iContextObject));
1395             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
1396         }
1397 
1398         break;
1399 
1400         case STATE_INIT:
1401         {
1402             OSCL_TRY(error, iCurrentCmdId = iPlayer->Init((OsclAny*) & iContextObject));
1403             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
1404         }
1405         break;
1406 
1407         case STATE_GETMETADATAKEYLIST:
1408         {
1409             iMetadataKeyList.clear();
1410             OSCL_TRY(error, iCurrentCmdId = iPlayer->GetMetadataKeys(iMetadataKeyList, 0, -1, NULL, (OsclAny*) & iContextObject));
1411             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
1412         }
1413         break;
1414 
1415         case STATE_GETMETADATAVALUELIST:
1416         {
1417             iMetadataValueList.clear();
1418             iNumValues = 0;
1419             OSCL_TRY(error, iCurrentCmdId = iPlayer->GetMetadataValues(iMetadataKeyList, 0, -1, iNumValues, iMetadataValueList, (OsclAny*) & iContextObject));
1420             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
1421         }
1422         break;
1423 
1424         case STATE_ADDDATASINK_VIDEO:
1425         {
1426             OSCL_wHeapString<OsclMemAllocator> videosinkfilename = OUTPUTNAME_PREPEND_WSTRING;
1427             videosinkfilename += _STRLIT_WCHAR("test_player_printmemstats_video.dat");
1428 
1429             iMIOFileOutVideo = iMioFactory->CreateVideoOutput((OsclAny*) & videosinkfilename, MEDIATYPE_VIDEO, iCompressedVideo);
1430             iIONodeVideo = PVMediaOutputNodeFactory::CreateMediaOutputNode(iMIOFileOutVideo);
1431             iDataSinkVideo = new PVPlayerDataSinkPVMFNode;
1432             ((PVPlayerDataSinkPVMFNode*)iDataSinkVideo)->SetDataSinkNode(iIONodeVideo);
1433 
1434             OSCL_TRY(error, iCurrentCmdId = iPlayer->AddDataSink(*iDataSinkVideo, (OsclAny*) & iContextObject));
1435             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
1436         }
1437         break;
1438 
1439         case STATE_ADDDATASINK_AUDIO:
1440         {
1441             OSCL_wHeapString<OsclMemAllocator> audiosinkfilename = OUTPUTNAME_PREPEND_WSTRING;
1442             audiosinkfilename += _STRLIT_WCHAR("test_player_printmemstats_audio.dat");
1443 
1444             iMIOFileOutAudio = iMioFactory->CreateAudioOutput((OsclAny*) & audiosinkfilename, MEDIATYPE_AUDIO, iCompressedAudio);
1445             iIONodeAudio = PVMediaOutputNodeFactory::CreateMediaOutputNode(iMIOFileOutAudio);
1446             iDataSinkAudio = new PVPlayerDataSinkPVMFNode;
1447             ((PVPlayerDataSinkPVMFNode*)iDataSinkAudio)->SetDataSinkNode(iIONodeAudio);
1448 
1449             OSCL_TRY(error, iCurrentCmdId = iPlayer->AddDataSink(*iDataSinkAudio, (OsclAny*) & iContextObject));
1450             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
1451         }
1452         break;
1453 
1454         case STATE_PREPARE:
1455         {
1456             OSCL_TRY(error, iCurrentCmdId = iPlayer->Prepare((OsclAny*) & iContextObject));
1457             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
1458         }
1459         break;
1460 
1461         case STATE_START:
1462         {
1463             OSCL_TRY(error, iCurrentCmdId = iPlayer->Start((OsclAny*) & iContextObject));
1464             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
1465         }
1466         break;
1467 
1468         case STATE_PRINTMEMSTATS:
1469         {
1470             PVPPlaybackPosition curpos;
1471             curpos.iPosValue.millisec_value = 0;
1472             curpos.iPosUnit = PVPPBPOSUNIT_MILLISEC;
1473             iPlayer->GetCurrentPositionSync(curpos);
1474             fprintf(iTestMsgOutputFile, "After playing %d ms: ", curpos.iPosValue.millisec_value);
1475             PrintMemStats();
1476 
1477             ++iPlayTimeCtr;
1478             if (iPlayTimeCtr < 20)
1479             {
1480                 iState = STATE_PRINTMEMSTATS;
1481                 RunIfNotReady(1000000);
1482             }
1483             else
1484             {
1485                 iState = STATE_STOP;
1486                 RunIfNotReady();
1487             }
1488         }
1489         break;
1490 
1491         case STATE_STOP:
1492         {
1493             OSCL_TRY(error, iCurrentCmdId = iPlayer->Stop((OsclAny*) & iContextObject));
1494             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
1495         }
1496         break;
1497 
1498         case STATE_REMOVEDATASINK_VIDEO:
1499         {
1500             OSCL_TRY(error, iCurrentCmdId = iPlayer->RemoveDataSink(*iDataSinkVideo, (OsclAny*) & iContextObject));
1501             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
1502         }
1503         break;
1504 
1505         case STATE_REMOVEDATASINK_AUDIO:
1506         {
1507             OSCL_TRY(error, iCurrentCmdId = iPlayer->RemoveDataSink(*iDataSinkAudio, (OsclAny*) & iContextObject));
1508             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
1509         }
1510         break;
1511 
1512         case STATE_RESET:
1513         {
1514             OSCL_TRY(error, iCurrentCmdId = iPlayer->Reset((OsclAny*) & iContextObject));
1515             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
1516         }
1517         break;
1518 
1519         case STATE_REMOVEDATASOURCE:
1520         {
1521             OSCL_TRY(error, iCurrentCmdId = iPlayer->RemoveDataSource(*iDataSource, (OsclAny*) & iContextObject));
1522             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
1523         }
1524         break;
1525 
1526         case STATE_CLEANUPANDCOMPLETE:
1527         {
1528             PVPATB_TEST_IS_TRUE(PVPlayerFactory::DeletePlayer(iPlayer));
1529             iPlayer = NULL;
1530 
1531             fprintf(iTestMsgOutputFile, "After player destruction: ");
1532             PrintMemStats();
1533 
1534             delete iSourceContextData;
1535             iSourceContextData = NULL;
1536 
1537             delete iDataSource;
1538             iDataSource = NULL;
1539 
1540             delete iDataSinkVideo;
1541             iDataSinkVideo = NULL;
1542 
1543             delete iDataSinkAudio;
1544             iDataSinkAudio = NULL;
1545 
1546             PVMediaOutputNodeFactory::DeleteMediaOutputNode(iIONodeVideo);
1547             iIONodeVideo = NULL;
1548 
1549             PVMediaOutputNodeFactory::DeleteMediaOutputNode(iIONodeAudio);
1550             iIONodeAudio = NULL;
1551 
1552             iMioFactory->DestroyVideoOutput(iMIOFileOutVideo);
1553             iMIOFileOutVideo = NULL;
1554 
1555             iMioFactory->DestroyAudioOutput(iMIOFileOutAudio);
1556             iMIOFileOutAudio = NULL;
1557 
1558             fprintf(iTestMsgOutputFile, "After cleanup: ");
1559             PrintMemStats();
1560 
1561             iObserver->TestCompleted(*iTestCase);
1562         }
1563         break;
1564 
1565         default:
1566             break;
1567 
1568     }
1569 }
1570 
1571 
CommandCompleted(const PVCmdResponse & aResponse)1572 void pvplayer_async_test_printmemstats::CommandCompleted(const PVCmdResponse& aResponse)
1573 {
1574     if (aResponse.GetCmdId() != iCurrentCmdId)
1575     {
1576         // Wrong command ID.
1577         PVPATB_TEST_IS_TRUE(false);
1578         iState = STATE_CLEANUPANDCOMPLETE;
1579         RunIfNotReady();
1580         return;
1581     }
1582 
1583     if (aResponse.GetContext() != NULL)
1584     {
1585         if (aResponse.GetContext() == (OsclAny*)&iContextObject)
1586         {
1587             if (iContextObject != iContextObjectRefValue)
1588             {
1589                 // Context data value was corrupted
1590                 PVPATB_TEST_IS_TRUE(false);
1591                 iState = STATE_CLEANUPANDCOMPLETE;
1592                 RunIfNotReady();
1593                 return;
1594             }
1595         }
1596         else
1597         {
1598             // Context data pointer was corrupted
1599             PVPATB_TEST_IS_TRUE(false);
1600             iState = STATE_CLEANUPANDCOMPLETE;
1601             RunIfNotReady();
1602             return;
1603         }
1604     }
1605 
1606     switch (iState)
1607     {
1608         case STATE_ADDDATASOURCE:
1609             if (aResponse.GetCmdStatus() == PVMFSuccess)
1610             {
1611                 fprintf(iTestMsgOutputFile, "After AddDataSource(): ");
1612                 PrintMemStats();
1613 
1614                 iState = STATE_INIT;
1615                 RunIfNotReady();
1616             }
1617             else
1618             {
1619                 // AddDataSource failed
1620                 PVPATB_TEST_IS_TRUE(false);
1621                 iState = STATE_CLEANUPANDCOMPLETE;
1622                 RunIfNotReady();
1623             }
1624             break;
1625 
1626         case STATE_INIT:
1627             if (aResponse.GetCmdStatus() == PVMFSuccess)
1628             {
1629                 fprintf(iTestMsgOutputFile, "After Init(): ");
1630                 PrintMemStats();
1631 
1632                 iState = STATE_GETMETADATAKEYLIST;
1633                 RunIfNotReady();
1634             }
1635             else
1636             {
1637                 // Init failed
1638                 PVPATB_TEST_IS_TRUE(false);
1639                 iState = STATE_CLEANUPANDCOMPLETE;
1640                 RunIfNotReady();
1641             }
1642             break;
1643 
1644         case STATE_GETMETADATAKEYLIST:
1645             if (aResponse.GetCmdStatus() == PVMFSuccess)
1646             {
1647                 fprintf(iTestMsgOutputFile, "After GetMetadataKeys(): ");
1648                 PrintMemStats();
1649 
1650                 iState = STATE_GETMETADATAVALUELIST;
1651                 RunIfNotReady();
1652             }
1653             else
1654             {
1655                 // GetMetadataKeys failed
1656                 PVPATB_TEST_IS_TRUE(false);
1657                 iState = STATE_CLEANUPANDCOMPLETE;
1658                 RunIfNotReady();
1659             }
1660             break;
1661 
1662         case STATE_GETMETADATAVALUELIST:
1663             if (aResponse.GetCmdStatus() == PVMFSuccess)
1664             {
1665                 fprintf(iTestMsgOutputFile, "After GetMetadataValue(): ");
1666                 PrintMemStats();
1667 
1668                 iState = STATE_ADDDATASINK_VIDEO;
1669                 RunIfNotReady();
1670             }
1671             else
1672             {
1673                 // GetMetadataValue failed
1674                 PVPATB_TEST_IS_TRUE(false);
1675                 iState = STATE_CLEANUPANDCOMPLETE;
1676                 RunIfNotReady();
1677             }
1678             break;
1679 
1680         case STATE_ADDDATASINK_VIDEO:
1681             if (aResponse.GetCmdStatus() == PVMFSuccess)
1682             {
1683                 fprintf(iTestMsgOutputFile, "After AddDataSink() video: ");
1684                 PrintMemStats();
1685 
1686                 iState = STATE_ADDDATASINK_AUDIO;
1687                 RunIfNotReady();
1688             }
1689             else
1690             {
1691                 // AddDataSink failed
1692                 PVPATB_TEST_IS_TRUE(false);
1693                 iState = STATE_CLEANUPANDCOMPLETE;
1694                 RunIfNotReady();
1695             }
1696             break;
1697 
1698         case STATE_ADDDATASINK_AUDIO:
1699             if (aResponse.GetCmdStatus() == PVMFSuccess)
1700             {
1701                 fprintf(iTestMsgOutputFile, "After AddDataSink() audio: ");
1702                 PrintMemStats();
1703 
1704                 iState = STATE_PREPARE;
1705                 RunIfNotReady();
1706             }
1707             else
1708             {
1709                 // AddDataSink failed
1710                 PVPATB_TEST_IS_TRUE(false);
1711                 iState = STATE_CLEANUPANDCOMPLETE;
1712                 RunIfNotReady();
1713             }
1714             break;
1715 
1716         case STATE_PREPARE:
1717             if (aResponse.GetCmdStatus() == PVMFSuccess)
1718             {
1719                 fprintf(iTestMsgOutputFile, "After Prepare(): ");
1720                 PrintMemStats();
1721 
1722                 iState = STATE_START;
1723                 RunIfNotReady();
1724             }
1725             else
1726             {
1727                 // Prepare failed
1728                 PVPATB_TEST_IS_TRUE(false);
1729                 iState = STATE_CLEANUPANDCOMPLETE;
1730                 RunIfNotReady();
1731             }
1732             break;
1733 
1734         case STATE_START:
1735             if (aResponse.GetCmdStatus() == PVMFSuccess)
1736             {
1737                 fprintf(iTestMsgOutputFile, "After Start(): ");
1738                 PrintMemStats();
1739 
1740                 iState = STATE_PRINTMEMSTATS;
1741                 RunIfNotReady(1000000);
1742             }
1743             else
1744             {
1745                 // Start failed
1746                 PVPATB_TEST_IS_TRUE(false);
1747                 iState = STATE_CLEANUPANDCOMPLETE;
1748                 RunIfNotReady();
1749             }
1750             break;
1751 
1752         case STATE_STOP:
1753             if (aResponse.GetCmdStatus() == PVMFSuccess)
1754             {
1755                 fprintf(iTestMsgOutputFile, "After Stop(): ");
1756                 PrintMemStats();
1757 
1758                 iState = STATE_REMOVEDATASINK_VIDEO;
1759                 RunIfNotReady();
1760             }
1761             else
1762             {
1763                 // Stop failed
1764                 PVPATB_TEST_IS_TRUE(false);
1765                 iState = STATE_CLEANUPANDCOMPLETE;
1766                 RunIfNotReady();
1767             }
1768             break;
1769 
1770         case STATE_REMOVEDATASINK_VIDEO:
1771             if (aResponse.GetCmdStatus() == PVMFSuccess)
1772             {
1773                 fprintf(iTestMsgOutputFile, "After RemoveDataSink() video: ");
1774                 PrintMemStats();
1775 
1776                 iState = STATE_REMOVEDATASINK_AUDIO;
1777                 RunIfNotReady();
1778             }
1779             else
1780             {
1781                 // RemoveDataSink failed
1782                 PVPATB_TEST_IS_TRUE(false);
1783                 iState = STATE_CLEANUPANDCOMPLETE;
1784                 RunIfNotReady();
1785             }
1786             break;
1787 
1788         case STATE_REMOVEDATASINK_AUDIO:
1789             if (aResponse.GetCmdStatus() == PVMFSuccess)
1790             {
1791                 fprintf(iTestMsgOutputFile, "After RemoveDataSink() audio: ");
1792                 PrintMemStats();
1793 
1794                 iState = STATE_RESET;
1795                 RunIfNotReady();
1796             }
1797             else
1798             {
1799                 // RemoveDataSink failed
1800                 PVPATB_TEST_IS_TRUE(false);
1801                 iState = STATE_CLEANUPANDCOMPLETE;
1802                 RunIfNotReady();
1803             }
1804             break;
1805 
1806         case STATE_RESET:
1807             if (aResponse.GetCmdStatus() == PVMFSuccess)
1808             {
1809                 fprintf(iTestMsgOutputFile, "After Reset(): ");
1810                 PrintMemStats();
1811 
1812                 iState = STATE_REMOVEDATASOURCE;
1813                 RunIfNotReady();
1814             }
1815             else
1816             {
1817                 // Reset failed
1818                 PVPATB_TEST_IS_TRUE(false);
1819                 iState = STATE_CLEANUPANDCOMPLETE;
1820                 RunIfNotReady();
1821             }
1822             break;
1823 
1824         case STATE_REMOVEDATASOURCE:
1825             if (aResponse.GetCmdStatus() == PVMFSuccess)
1826             {
1827                 fprintf(iTestMsgOutputFile, "After RemoveDataSource(): ");
1828                 PrintMemStats();
1829 
1830                 PVPATB_TEST_IS_TRUE(true);
1831                 iState = STATE_CLEANUPANDCOMPLETE;
1832                 RunIfNotReady();
1833             }
1834             else
1835             {
1836                 // RemoveDataSource failed
1837                 PVPATB_TEST_IS_TRUE(false);
1838                 iState = STATE_CLEANUPANDCOMPLETE;
1839                 RunIfNotReady();
1840             }
1841             break;
1842 
1843         default:
1844         {
1845             // Testing error if this is reached
1846             PVPATB_TEST_IS_TRUE(false);
1847             iState = STATE_CLEANUPANDCOMPLETE;
1848             RunIfNotReady();
1849         }
1850         break;
1851     }
1852 }
1853 
1854 
HandleErrorEvent(const PVAsyncErrorEvent & aEvent)1855 void pvplayer_async_test_printmemstats::HandleErrorEvent(const PVAsyncErrorEvent& aEvent)
1856 {
1857     switch (aEvent.GetEventType())
1858     {
1859         case PVMFErrResourceConfiguration:
1860             // Just log the error
1861             PVPATB_TEST_IS_TRUE(false);
1862             break;
1863 
1864         case PVMFErrResource:
1865             // Just log the error
1866             PVPATB_TEST_IS_TRUE(false);
1867             break;
1868 
1869         case PVMFErrCorrupt:
1870             // Just log the error
1871             PVPATB_TEST_IS_TRUE(false);
1872             break;
1873 
1874         case PVMFErrProcessing:
1875             // Just log the error
1876             PVPATB_TEST_IS_TRUE(false);
1877             break;
1878 
1879         default:
1880             // Unknown error and just log the error
1881             PVPATB_TEST_IS_TRUE(false);
1882             break;
1883     }
1884 
1885     // Wait for engine to handle the error
1886     Cancel();
1887 }
1888 
1889 
HandleInformationalEvent(const PVAsyncInformationalEvent & aEvent)1890 void pvplayer_async_test_printmemstats::HandleInformationalEvent(const PVAsyncInformationalEvent& aEvent)
1891 {
1892     if (aEvent.GetEventType() == PVMFInfoErrorHandlingStart)
1893     {
1894         fprintf(iTestMsgOutputFile, "PVMFInfoErrorHandlingStart...\n");
1895     }
1896     if (aEvent.GetEventType() == PVMFInfoErrorHandlingComplete)
1897     {
1898         fprintf(iTestMsgOutputFile, "PVMFInfoErrorHandlingComplete...\n");
1899         iState = STATE_CLEANUPANDCOMPLETE;
1900         RunIfNotReady();
1901     }
1902 }
1903 
1904 
PrintMemStats()1905 void pvplayer_async_test_printmemstats::PrintMemStats()
1906 {
1907 #if !(OSCL_BYPASS_MEMMGT)
1908     // Obtain the current mem stats
1909     OsclAuditCB auditCB;
1910     OsclMemInit(auditCB);
1911     if (auditCB.pAudit)
1912     {
1913         MM_Stats_t* stats = auditCB.pAudit->MM_GetStats("");
1914         if (stats)
1915         {
1916             fprintf(iTestMsgOutputFile, "In use %d allocs, %d bytes.\n", stats->numAllocs - iInitialNumAllocs, stats->numBytes - iInitialNumBytes);
1917         }
1918         else
1919         {
1920             fprintf(iTestMsgOutputFile, "Retrieving memory statistics failed! Memory statistics result would be invalid.\n");
1921         }
1922     }
1923     else
1924     {
1925         fprintf(iTestMsgOutputFile, "Memory audit not available! Memory statistics result would be invalid.\n");
1926     }
1927 #else
1928     fprintf(iTestMsgOutputFile, "MEMORY AUDIT DISABLED\n");
1929 #endif
1930 }
1931 
1932 
1933 //
1934 // pvplayer_async_test_playuntileos section
1935 //
StartTest()1936 void pvplayer_async_test_playuntileos::StartTest()
1937 {
1938     AddToScheduler();
1939     iState = STATE_CREATE;
1940     RunIfNotReady();
1941 }
1942 
1943 
Run()1944 void pvplayer_async_test_playuntileos::Run()
1945 {
1946     int error = 0;
1947 
1948     switch (iState)
1949     {
1950         case STATE_CREATE:
1951         {
1952             iPlayer = NULL;
1953 
1954             OSCL_TRY(error, iPlayer = PVPlayerFactory::CreatePlayer(this, this, this));
1955             if (error)
1956             {
1957                 PVPATB_TEST_IS_TRUE(false);
1958                 iObserver->TestCompleted(*iTestCase);
1959             }
1960             else
1961             {
1962                 iState = STATE_ADDDATASOURCE;
1963                 RunIfNotReady();
1964             }
1965         }
1966         break;
1967 
1968         case STATE_ADDDATASOURCE:
1969         {
1970             iDataSource = new PVPlayerDataSourceURL;
1971             oscl_UTF8ToUnicode(iFileName, oscl_strlen(iFileName), iTmpWCharBuffer, 512);
1972             iFileNameWStr.set(iTmpWCharBuffer, oscl_strlen(iTmpWCharBuffer));
1973             /*
1974              * In case of HTTP URLs always attempt rollover,
1975              * since we donot know if it is a download or a streaming url
1976              */
1977             if (iFileType == PVMF_MIME_DATA_SOURCE_HTTP_URL)
1978             {
1979                 iSourceContextData = new PVMFSourceContextData();
1980                 iSourceContextData->EnableStreamingSourceContext();
1981                 iSourceContextData->EnableCommonSourceContext();
1982                 PVInterface* sourceContextStream = NULL;
1983 
1984                 PVUuid streamingContextUuid(PVMF_SOURCE_CONTEXT_DATA_STREAMING_UUID);
1985                 if (iSourceContextData->queryInterface(streamingContextUuid, sourceContextStream))
1986                 {
1987                     PVMFSourceContextDataStreaming* streamingContext =
1988                         OSCL_STATIC_CAST(PVMFSourceContextDataStreaming*, sourceContextStream);
1989                     streamingContext->iStreamStatsLoggingURL = iFileNameWStr;
1990 
1991                     if (iProxyEnabled)
1992                     {
1993                         streamingContext->iProxyName = _STRLIT_WCHAR("");
1994                         streamingContext->iProxyPort = 8080;
1995                     }
1996                 }
1997                 PVInterface* sourceContextDownload = NULL;
1998                 iSourceContextData->EnableDownloadHTTPSourceContext();
1999                 PVUuid downloadContextUuid(PVMF_SOURCE_CONTEXT_DATA_DOWNLOAD_HTTP_UUID);
2000                 if (iSourceContextData->queryInterface(downloadContextUuid, sourceContextDownload))
2001                 {
2002                     //create the opaque data
2003                     iDownloadProxy = _STRLIT_CHAR("");
2004                     int32 iDownloadProxyPort = 0;
2005                     if (iProxyEnabled)
2006                     {
2007                         iDownloadProxy = _STRLIT_CHAR("");
2008                         iDownloadProxyPort = 8080;
2009                     }
2010                     iDownloadConfigFilename = OUTPUTNAME_PREPEND_WSTRING;
2011                     iDownloadConfigFilename += _STRLIT_WCHAR("mydlconfig");
2012                     iDownloadMaxfilesize = 0x7FFFFFFF;
2013                     iDownloadFilename = OUTPUTNAME_PREPEND_WSTRING;
2014                     iDownloadFilename += _STRLIT_WCHAR("test_ftdownload.dl");
2015                     bool aIsNewSession = true;
2016 
2017                     iSourceContextData->DownloadHTTPData()->bIsNewSession = aIsNewSession;
2018                     iSourceContextData->DownloadHTTPData()->iConfigFileName = iDownloadConfigFilename;
2019                     iSourceContextData->DownloadHTTPData()->iDownloadFileName = iDownloadFilename;
2020                     iSourceContextData->DownloadHTTPData()->iMaxFileSize = iDownloadMaxfilesize;
2021                     iSourceContextData->DownloadHTTPData()->iPlaybackControl = PVMFSourceContextDataDownloadHTTP::EAsap;
2022                     iSourceContextData->DownloadHTTPData()->iProxyName = iDownloadProxy;
2023                     iSourceContextData->DownloadHTTPData()->iProxyPort = iDownloadProxyPort;
2024 
2025                 }
2026                 iDataSource->SetDataSourceContextData((OsclAny*)iSourceContextData);
2027 
2028                 iDataSource->SetDataSourceFormatType(PVMF_MIME_DATA_SOURCE_MS_HTTP_STREAMING_URL);
2029                 iDataSource->SetAlternateSourceFormatType(PVMF_MIME_DATA_SOURCE_HTTP_URL);
2030             }
2031             else
2032             {
2033                 iDataSource->SetDataSourceFormatType(iFileType);
2034             }
2035 
2036             iDataSource->SetDataSourceURL(iFileNameWStr);
2037 
2038             OSCL_TRY(error, iCurrentCmdId = iPlayer->AddDataSource(*iDataSource, (OsclAny*) & iContextObject));
2039             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
2040         }
2041 
2042         break;
2043 
2044         case STATE_INIT:
2045         {
2046             OSCL_TRY(error, iCurrentCmdId = iPlayer->Init((OsclAny*) & iContextObject));
2047             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
2048         }
2049         break;
2050 
2051         case STATE_ADDDATASINK_VIDEO:
2052         {
2053             OSCL_wHeapString<OsclMemAllocator> sinkfilename;
2054             sinkfilename = OUTPUTNAME_PREPEND_WSTRING;
2055             sinkfilename += _STRLIT_WCHAR("test_player_playuntileos_");
2056             if (iCompressedVideo)
2057             {
2058                 sinkfilename += _STRLIT_WCHAR("compressed_");
2059             }
2060             OSCL_wHeapString<OsclMemAllocator> inputfilename;
2061             RetrieveFilename(iFileNameWStr.get_str(), inputfilename);
2062             sinkfilename += inputfilename;
2063             sinkfilename += _STRLIT_WCHAR("_video.dat");
2064 
2065             iMIOFileOutVideo = iMioFactory->CreateVideoOutput((OsclAny*) & sinkfilename, MEDIATYPE_VIDEO, iCompressedVideo);
2066             iIONodeVideo = PVMediaOutputNodeFactory::CreateMediaOutputNode(iMIOFileOutVideo);
2067             iDataSinkVideo = new PVPlayerDataSinkPVMFNode;
2068             ((PVPlayerDataSinkPVMFNode*)iDataSinkVideo)->SetDataSinkNode(iIONodeVideo);
2069 
2070             OSCL_TRY(error, iCurrentCmdId = iPlayer->AddDataSink(*iDataSinkVideo, (OsclAny*) & iContextObject));
2071             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
2072         }
2073         break;
2074 
2075         case STATE_ADDDATASINK_AUDIO:
2076         {
2077             OSCL_wHeapString<OsclMemAllocator> sinkfilename;
2078             sinkfilename = OUTPUTNAME_PREPEND_WSTRING;
2079             sinkfilename += _STRLIT_WCHAR("test_player_playuntileos_");
2080             if (iCompressedAudio)
2081             {
2082                 sinkfilename += _STRLIT_WCHAR("compressed_");
2083             }
2084             OSCL_wHeapString<OsclMemAllocator> inputfilename;
2085             RetrieveFilename(iFileNameWStr.get_str(), inputfilename);
2086             sinkfilename += inputfilename;
2087             sinkfilename += _STRLIT_WCHAR("_audio.dat");
2088 
2089             iMIOFileOutAudio = iMioFactory->CreateAudioOutput((OsclAny*) & sinkfilename, MEDIATYPE_AUDIO, iCompressedAudio);
2090             iIONodeAudio = PVMediaOutputNodeFactory::CreateMediaOutputNode(iMIOFileOutAudio);
2091             iDataSinkAudio = new PVPlayerDataSinkPVMFNode;
2092             ((PVPlayerDataSinkPVMFNode*)iDataSinkAudio)->SetDataSinkNode(iIONodeAudio);
2093 
2094             OSCL_TRY(error, iCurrentCmdId = iPlayer->AddDataSink(*iDataSinkAudio, (OsclAny*) & iContextObject));
2095             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
2096         }
2097         break;
2098 
2099         case STATE_ADDDATASINK_TEXT:
2100         {
2101             OSCL_wHeapString<OsclMemAllocator> sinkfilename;
2102             sinkfilename = OUTPUTNAME_PREPEND_WSTRING;
2103             sinkfilename += _STRLIT_WCHAR("test_player_playuntileos_");
2104             OSCL_wHeapString<OsclMemAllocator> inputfilename;
2105             RetrieveFilename(iFileNameWStr.get_str(), inputfilename);
2106             sinkfilename += inputfilename;
2107             sinkfilename += _STRLIT_WCHAR("_text.dat");
2108 
2109             iMIOFileOutText = iMioFactory->CreateTextOutput((OsclAny*) & sinkfilename, MEDIATYPE_TEXT);
2110             iIONodeText = PVMediaOutputNodeFactory::CreateMediaOutputNode(iMIOFileOutText);
2111             iDataSinkText = new PVPlayerDataSinkPVMFNode;
2112             ((PVPlayerDataSinkPVMFNode*)iDataSinkText)->SetDataSinkNode(iIONodeText);
2113 
2114             OSCL_TRY(error, iCurrentCmdId = iPlayer->AddDataSink(*iDataSinkText, (OsclAny*) & iContextObject));
2115             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
2116         }
2117         break;
2118 
2119         case STATE_PREPARE:
2120         {
2121             OSCL_TRY(error, iCurrentCmdId = iPlayer->Prepare((OsclAny*) & iContextObject));
2122             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
2123         }
2124         break;
2125 
2126         case STATE_START:
2127         {
2128             OSCL_TRY(error, iCurrentCmdId = iPlayer->Start((OsclAny*) & iContextObject));
2129             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
2130         }
2131         break;
2132 
2133         case STATE_STOP:
2134         {
2135             OSCL_TRY(error, iCurrentCmdId = iPlayer->Stop((OsclAny*) & iContextObject));
2136             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
2137         }
2138         break;
2139 
2140         case STATE_REMOVEDATASINK_VIDEO:
2141         {
2142             OSCL_TRY(error, iCurrentCmdId = iPlayer->RemoveDataSink(*iDataSinkVideo, (OsclAny*) & iContextObject));
2143             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
2144         }
2145         break;
2146 
2147         case STATE_REMOVEDATASINK_AUDIO:
2148         {
2149             OSCL_TRY(error, iCurrentCmdId = iPlayer->RemoveDataSink(*iDataSinkAudio, (OsclAny*) & iContextObject));
2150             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
2151         }
2152         break;
2153 
2154         case STATE_REMOVEDATASINK_TEXT:
2155         {
2156             OSCL_TRY(error, iCurrentCmdId = iPlayer->RemoveDataSink(*iDataSinkText, (OsclAny*) & iContextObject));
2157             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
2158         }
2159         break;
2160 
2161         case STATE_RESET:
2162         {
2163             OSCL_TRY(error, iCurrentCmdId = iPlayer->Reset((OsclAny*) & iContextObject));
2164             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
2165         }
2166         break;
2167 
2168         case STATE_REMOVEDATASOURCE:
2169         {
2170             OSCL_TRY(error, iCurrentCmdId = iPlayer->RemoveDataSource(*iDataSource, (OsclAny*) & iContextObject));
2171             OSCL_FIRST_CATCH_ANY(error, PVPATB_TEST_IS_TRUE(false); iState = STATE_CLEANUPANDCOMPLETE; RunIfNotReady());
2172         }
2173         break;
2174 
2175         case STATE_CLEANUPANDCOMPLETE:
2176         {
2177             PVPATB_TEST_IS_TRUE(PVPlayerFactory::DeletePlayer(iPlayer));
2178             iPlayer = NULL;
2179 
2180             delete iSourceContextData;
2181             iSourceContextData = NULL;
2182 
2183             delete iDataSource;
2184             iDataSource = NULL;
2185 
2186             delete iDataSinkVideo;
2187             iDataSinkVideo = NULL;
2188 
2189             delete iDataSinkAudio;
2190             iDataSinkAudio = NULL;
2191 
2192             delete iDataSinkText;
2193             iDataSinkText = NULL;
2194 
2195             PVMediaOutputNodeFactory::DeleteMediaOutputNode(iIONodeVideo);
2196             iIONodeVideo = NULL;
2197 
2198             PVMediaOutputNodeFactory::DeleteMediaOutputNode(iIONodeAudio);
2199             iIONodeAudio = NULL;
2200 
2201             PVMediaOutputNodeFactory::DeleteMediaOutputNode(iIONodeText);
2202             iIONodeText = NULL;
2203 
2204             iMioFactory->DestroyVideoOutput(iMIOFileOutVideo);
2205             iMIOFileOutVideo = NULL;
2206 
2207             iMioFactory->DestroyAudioOutput(iMIOFileOutAudio);
2208             iMIOFileOutAudio = NULL;
2209 
2210             iMioFactory->DestroyTextOutput(iMIOFileOutText);
2211             iMIOFileOutText = NULL;
2212 
2213             iObserver->TestCompleted(*iTestCase);
2214         }
2215         break;
2216 
2217         default:
2218             break;
2219 
2220     }
2221 }
2222 
2223 
CommandCompleted(const PVCmdResponse & aResponse)2224 void pvplayer_async_test_playuntileos::CommandCompleted(const PVCmdResponse& aResponse)
2225 {
2226     if (aResponse.GetCmdId() != iCurrentCmdId)
2227     {
2228         // Wrong command ID.
2229         PVPATB_TEST_IS_TRUE(false);
2230         iState = STATE_CLEANUPANDCOMPLETE;
2231         RunIfNotReady();
2232         return;
2233     }
2234 
2235     if (aResponse.GetContext() != NULL)
2236     {
2237         if (aResponse.GetContext() == (OsclAny*)&iContextObject)
2238         {
2239             if (iContextObject != iContextObjectRefValue)
2240             {
2241                 // Context data value was corrupted
2242                 PVPATB_TEST_IS_TRUE(false);
2243                 iState = STATE_CLEANUPANDCOMPLETE;
2244                 RunIfNotReady();
2245                 return;
2246             }
2247         }
2248         else
2249         {
2250             // Context data pointer was corrupted
2251             PVPATB_TEST_IS_TRUE(false);
2252             iState = STATE_CLEANUPANDCOMPLETE;
2253             RunIfNotReady();
2254             return;
2255         }
2256     }
2257 
2258     switch (iState)
2259     {
2260         case STATE_ADDDATASOURCE:
2261             if (aResponse.GetCmdStatus() == PVMFSuccess)
2262             {
2263                 iState = STATE_INIT;
2264                 RunIfNotReady();
2265             }
2266             else
2267             {
2268                 // AddDataSource failed
2269                 PVPATB_TEST_IS_TRUE(false);
2270                 iState = STATE_CLEANUPANDCOMPLETE;
2271                 RunIfNotReady();
2272             }
2273             break;
2274 
2275         case STATE_INIT:
2276             if (aResponse.GetCmdStatus() == PVMFSuccess)
2277             {
2278                 iState = STATE_ADDDATASINK_VIDEO;
2279                 RunIfNotReady();
2280             }
2281             else
2282             {
2283                 // Init failed
2284                 PVPATB_TEST_IS_TRUE(false);
2285                 iState = STATE_CLEANUPANDCOMPLETE;
2286                 RunIfNotReady();
2287             }
2288             break;
2289 
2290         case STATE_ADDDATASINK_VIDEO:
2291             if (aResponse.GetCmdStatus() == PVMFSuccess)
2292             {
2293                 iState = STATE_ADDDATASINK_AUDIO;
2294                 RunIfNotReady();
2295             }
2296             else
2297             {
2298                 // AddDataSink failed
2299                 PVPATB_TEST_IS_TRUE(false);
2300                 iState = STATE_CLEANUPANDCOMPLETE;
2301                 RunIfNotReady();
2302             }
2303             break;
2304 
2305         case STATE_ADDDATASINK_AUDIO:
2306             if (aResponse.GetCmdStatus() == PVMFSuccess)
2307             {
2308                 iState = STATE_ADDDATASINK_TEXT;
2309                 RunIfNotReady();
2310             }
2311             else
2312             {
2313                 // AddDataSink failed
2314                 PVPATB_TEST_IS_TRUE(false);
2315                 iState = STATE_CLEANUPANDCOMPLETE;
2316                 RunIfNotReady();
2317             }
2318             break;
2319 
2320         case STATE_ADDDATASINK_TEXT:
2321             if (aResponse.GetCmdStatus() == PVMFSuccess)
2322             {
2323                 iState = STATE_PREPARE;
2324                 RunIfNotReady();
2325             }
2326             else
2327             {
2328                 // AddDataSink failed
2329                 PVPATB_TEST_IS_TRUE(false);
2330                 iState = STATE_CLEANUPANDCOMPLETE;
2331                 RunIfNotReady();
2332             }
2333             break;
2334 
2335         case STATE_PREPARE:
2336             if (aResponse.GetCmdStatus() == PVMFSuccess)
2337             {
2338                 iState = STATE_START;
2339                 // The delay is added between Prepare and Start to test that player
2340                 // does not start the clock and send playstatus events prior to start.
2341                 RunIfNotReady(PVPLAYER_ASYNC_TEST_PLAYUNTILEOS_DELAY_AFTER_PREPARE);
2342             }
2343             else
2344             {
2345                 // Prepare failed
2346                 PVPATB_TEST_IS_TRUE(false);
2347                 iState = STATE_CLEANUPANDCOMPLETE;
2348                 RunIfNotReady();
2349             }
2350             break;
2351 
2352         case STATE_START:
2353             if (aResponse.GetCmdStatus() == PVMFSuccess)
2354             {
2355                 // Do nothing and wait for EOS event
2356                 fprintf(iTestMsgOutputFile, "Playback started.\n");
2357             }
2358             else
2359             {
2360                 // Start failed
2361                 PVPATB_TEST_IS_TRUE(false);
2362                 iState = STATE_CLEANUPANDCOMPLETE;
2363                 RunIfNotReady();
2364             }
2365             break;
2366 
2367         case STATE_STOP:
2368             if (aResponse.GetCmdStatus() == PVMFSuccess)
2369             {
2370                 iState = STATE_REMOVEDATASINK_VIDEO;
2371                 RunIfNotReady();
2372             }
2373             else
2374             {
2375                 // Stop failed
2376                 PVPATB_TEST_IS_TRUE(false);
2377                 iState = STATE_CLEANUPANDCOMPLETE;
2378                 RunIfNotReady();
2379             }
2380             break;
2381 
2382         case STATE_REMOVEDATASINK_VIDEO:
2383             if (aResponse.GetCmdStatus() == PVMFSuccess)
2384             {
2385                 iState = STATE_REMOVEDATASINK_AUDIO;
2386                 RunIfNotReady();
2387             }
2388             else
2389             {
2390                 // RemoveDataSink failed
2391                 PVPATB_TEST_IS_TRUE(false);
2392                 iState = STATE_CLEANUPANDCOMPLETE;
2393                 RunIfNotReady();
2394             }
2395             break;
2396 
2397         case STATE_REMOVEDATASINK_AUDIO:
2398             if (aResponse.GetCmdStatus() == PVMFSuccess)
2399             {
2400                 iState = STATE_REMOVEDATASINK_TEXT;
2401                 RunIfNotReady();
2402             }
2403             else
2404             {
2405                 // RemoveDataSink failed
2406                 PVPATB_TEST_IS_TRUE(false);
2407                 iState = STATE_CLEANUPANDCOMPLETE;
2408                 RunIfNotReady();
2409             }
2410             break;
2411 
2412         case STATE_REMOVEDATASINK_TEXT:
2413             if (aResponse.GetCmdStatus() == PVMFSuccess)
2414             {
2415                 iState = STATE_RESET;
2416                 RunIfNotReady();
2417             }
2418             else
2419             {
2420                 // RemoveDataSink failed
2421                 PVPATB_TEST_IS_TRUE(false);
2422                 iState = STATE_CLEANUPANDCOMPLETE;
2423                 RunIfNotReady();
2424             }
2425             break;
2426 
2427         case STATE_RESET:
2428             if (aResponse.GetCmdStatus() == PVMFSuccess)
2429             {
2430                 iState = STATE_REMOVEDATASOURCE;
2431                 RunIfNotReady();
2432             }
2433             else
2434             {
2435                 // Reset failed
2436                 PVPATB_TEST_IS_TRUE(false);
2437                 iState = STATE_CLEANUPANDCOMPLETE;
2438                 RunIfNotReady();
2439             }
2440             break;
2441 
2442         case STATE_REMOVEDATASOURCE:
2443             if (aResponse.GetCmdStatus() == PVMFSuccess)
2444             {
2445                 PVPATB_TEST_IS_TRUE(true);
2446                 iState = STATE_CLEANUPANDCOMPLETE;
2447                 RunIfNotReady();
2448             }
2449             else
2450             {
2451                 // RemoveDataSource failed
2452                 PVPATB_TEST_IS_TRUE(false);
2453                 iState = STATE_CLEANUPANDCOMPLETE;
2454                 RunIfNotReady();
2455             }
2456             break;
2457 
2458         default:
2459         {
2460             // Testing error if this is reached
2461             PVPATB_TEST_IS_TRUE(false);
2462             iState = STATE_CLEANUPANDCOMPLETE;
2463             RunIfNotReady();
2464         }
2465         break;
2466     }
2467 }
2468 
2469 
HandleErrorEvent(const PVAsyncErrorEvent & aEvent)2470 void pvplayer_async_test_playuntileos::HandleErrorEvent(const PVAsyncErrorEvent& aEvent)
2471 {
2472     switch (aEvent.GetEventType())
2473     {
2474         case PVMFErrResourceConfiguration:
2475             // Just log the error
2476             PVPATB_TEST_IS_TRUE(false);
2477             break;
2478 
2479         case PVMFErrResource:
2480             // Just log the error
2481             PVPATB_TEST_IS_TRUE(false);
2482             break;
2483 
2484         case PVMFErrCorrupt:
2485             // Just log the error
2486             PVPATB_TEST_IS_TRUE(false);
2487             break;
2488 
2489         case PVMFErrProcessing:
2490             // Just log the error
2491             PVPATB_TEST_IS_TRUE(false);
2492             break;
2493 
2494         default:
2495             // Unknown error and just log the error
2496             PVPATB_TEST_IS_TRUE(false);
2497             break;
2498     }
2499 
2500     // Wait for engine to handle the error
2501     Cancel();
2502 }
2503 
2504 
HandleInformationalEvent(const PVAsyncInformationalEvent & aEvent)2505 void pvplayer_async_test_playuntileos::HandleInformationalEvent(const PVAsyncInformationalEvent& aEvent)
2506 {
2507     if (aEvent.GetEventType() == PVMFInfoErrorHandlingStart)
2508     {
2509         fprintf(iTestMsgOutputFile, "PVMFInfoErrorHandlingStart...\n");
2510     }
2511     if (aEvent.GetEventType() == PVMFInfoErrorHandlingComplete)
2512     {
2513         fprintf(iTestMsgOutputFile, "PVMFInfoErrorHandlingComplete...\n");
2514         iState = STATE_CLEANUPANDCOMPLETE;
2515         RunIfNotReady();
2516     }
2517 
2518     // Check for stop time reached event
2519     if (aEvent.GetEventType() == PVMFInfoEndOfData)
2520     {
2521         PVInterface* iface = (PVInterface*)(aEvent.GetEventExtensionInterface());
2522         if (iface == NULL)
2523         {
2524             return;
2525         }
2526         PVUuid infomsguuid = PVMFErrorInfoMessageInterfaceUUID;
2527         PVMFErrorInfoMessageInterface* infomsgiface = NULL;
2528         if (iface->queryInterface(infomsguuid, (PVInterface*&)infomsgiface) == true)
2529         {
2530             int32 infocode;
2531             PVUuid infouuid;
2532             infomsgiface->GetCodeUUID(infocode, infouuid);
2533             if ((infouuid == PVPlayerErrorInfoEventTypesUUID) && (infocode == PVPlayerInfoEndOfClipReached))
2534             {
2535                 fprintf(iTestMsgOutputFile, "EOS received. Stopping playback.\n");
2536                 iState = STATE_STOP;
2537                 Cancel();
2538                 RunIfNotReady();
2539             }
2540         }
2541     }
2542     // Check and print out playback position status
2543     else if (aEvent.GetEventType() == PVMFInfoPositionStatus)
2544     {
2545         PVPlayerState pstate;
2546         iPlayer->GetPVPlayerStateSync(pstate);
2547         if (pstate != PVP_STATE_STARTED)
2548         {
2549             fprintf(iTestMsgOutputFile, "Playback status recived in Wrong Engine State\n");
2550             PVPATB_TEST_IS_TRUE(false);
2551             iState = STATE_CLEANUPANDCOMPLETE;
2552             RunIfNotReady();
2553             return;
2554         }
2555 
2556         PVInterface* iface = (PVInterface*)(aEvent.GetEventExtensionInterface());
2557         if (iface == NULL)
2558         {
2559             return;
2560         }
2561         PVUuid infomsguuid = PVMFErrorInfoMessageInterfaceUUID;
2562         PVMFErrorInfoMessageInterface* infomsgiface = NULL;
2563         if (iface->queryInterface(infomsguuid, (PVInterface*&)infomsgiface) == true)
2564         {
2565             int32 infocode;
2566             PVUuid infouuid;
2567             infomsgiface->GetCodeUUID(infocode, infouuid);
2568             if ((infouuid == PVPlayerErrorInfoEventTypesUUID) && (infocode == PVPlayerInfoPlaybackPositionStatus))
2569             {
2570                 uint8* localbuf = aEvent.GetLocalBuffer();
2571                 uint32 pbpos = 0;
2572                 oscl_memcpy(&pbpos, &(localbuf[4]), 4);
2573                 fprintf(iTestMsgOutputFile, "Playback status(time) %d ms\n", pbpos);
2574             }
2575         }
2576 
2577         PVPPlaybackPosition curpos;
2578 
2579         curpos.iPosValue.percent_value = 0;
2580         curpos.iPosUnit = PVPPBPOSUNIT_PERCENT;
2581         if (iPlayer->GetCurrentPositionSync(curpos) == PVMFSuccess)
2582         {
2583             fprintf(iTestMsgOutputFile, "Playback status(percentage) %d%%\n", curpos.iPosValue.percent_value);
2584         }
2585 
2586 
2587         curpos.iPosValue.samplenum_value = 0;
2588         curpos.iPosUnit = PVPPBPOSUNIT_SAMPLENUMBER;
2589         if (iPlayer->GetCurrentPositionSync(curpos) == PVMFSuccess)
2590         {
2591             fprintf(iTestMsgOutputFile, "Playback status(sample number) %d\n", curpos.iPosValue.samplenum_value);
2592         }
2593 
2594         curpos.iPosValue.datapos_value = 0;
2595         curpos.iPosUnit = PVPPBPOSUNIT_DATAPOSITION;
2596         if (iPlayer->GetCurrentPositionSync(curpos) == PVMFSuccess)
2597         {
2598             fprintf(iTestMsgOutputFile, "Playback status(data position) %d bytes\n", curpos.iPosValue.datapos_value);
2599         }
2600 
2601         fprintf(iTestMsgOutputFile, "------------------------------\n");
2602     }
2603 }
2604 
2605 
2606 
2607 
2608 
2609 
2610