1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13 * express or implied.
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
17 */
18 /**
19 * @file pvmi_mio_avi_wavfile.cpp
20 * @brief PV Media IO interface implementation using file input
21 */
22
23 #ifndef PVMI_MIO_AVIFILE_H_INCLUDED
24 #include "pvmi_mio_avi_wav_file.h"
25 #endif
26 #ifndef OSCL_MIME_STRING_UTILS_H
27 #include "pv_mime_string_utils.h"
28 #endif
29 #ifndef OSCL_DLL_H_INCLUDED
30 #include "oscl_dll.h"
31 #endif
32
33 // Define entry point for this DLL
OSCL_DLL_ENTRY_POINT_DEFAULT()34 OSCL_DLL_ENTRY_POINT_DEFAULT()
35
36 #define PVMIOFILEIN_MEDIADATA_POOLNUM 8
37
38 // Logging macros
39 #define LOG_STACK_TRACE(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, m)
40 #define LOG_DEBUG(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, m)
41 #define LOG_ERR(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,iLogger,PVLOGMSG_ERR,m)
42 #define LOGDATATRAFFIC(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,iDataPathLogger,PVLOGMSG_INFO,m);
43 #define LOGDIAGNOSTICS_AVI_FF(m) PVLOGGER_LOGMSG(PVLOGMSG_INST_REL,iDiagnosticsLoggerAVIFF,PVLOGMSG_INFO,m);
44
45 ////////////////////////////////////////////////////////////////////////////
46 OSCL_EXPORT_REF PvmiMIOControl* PvmiMIOAviWavFileFactory::Create(uint32 aNumLoops, bool aRecordingMode, uint32 aStreamNo, OsclAny* aFileParser, FileFormatType aFileType, int32& arError)
47 {
48 PvmiMIOControl *mioFilein = (PvmiMIOControl*) OSCL_NEW(PvmiMIOAviWavFile, (aNumLoops, aRecordingMode, aStreamNo, aFileParser, aFileType, arError));
49
50 return mioFilein;
51 }
52
53 ////////////////////////////////////////////////////////////////////////////
Delete(PvmiMIOControl * aMio)54 OSCL_EXPORT_REF bool PvmiMIOAviWavFileFactory::Delete(PvmiMIOControl* aMio)
55 {
56 PvmiMIOAviWavFile* mioFilein = (PvmiMIOAviWavFile*)aMio;
57 if (!mioFilein)
58 {
59 return false;
60 }
61 OSCL_DELETE(mioFilein);
62
63 mioFilein = NULL;
64 return true;
65
66 }
67
68 ////////////////////////////////////////////////////////////////////////////
~PvmiMIOAviWavFile()69 PvmiMIOAviWavFile::~PvmiMIOAviWavFile()
70 {
71 #if PROFILING_ON
72 if (!oDiagnosticsLogged)
73 LogDiagnostics();
74 #endif
75
76 if (iMediaBufferMemPool)
77 {
78 if (iSentMediaData.size() > 0)
79 {
80 for (int ii = iSentMediaData.size() - 1; ii >= 0; ii--)
81 {
82 iMediaBufferMemPool->deallocate(iSentMediaData[ii].iData);
83 }
84 }
85 if (iData)
86 {
87 iMediaBufferMemPool->deallocate(iData);
88 iData = NULL;
89 iDataSize = 0;
90 }
91 OSCL_DELETE(iMediaBufferMemPool);
92 iMediaBufferMemPool = NULL;
93 }
94 }
95
96 ////////////////////////////////////////////////////////////////////////////
connect(PvmiMIOSession & aSession,PvmiMIOObserver * aObserver)97 OSCL_EXPORT_REF PVMFStatus PvmiMIOAviWavFile::connect(PvmiMIOSession& aSession, PvmiMIOObserver* aObserver)
98 {
99 if (!aObserver)
100 {
101 return PVMFFailure;
102 }
103
104 int32 err = 0;
105 OSCL_TRY(err, iObservers.push_back(aObserver));
106 OSCL_FIRST_CATCH_ANY(err, return PVMFErrNoMemory);
107 aSession = (PvmiMIOSession)(iObservers.size() - 1); // Session ID is the index of observer in the vector
108 return PVMFSuccess;
109 }
110
111 ////////////////////////////////////////////////////////////////////////////
disconnect(PvmiMIOSession aSession)112 OSCL_EXPORT_REF PVMFStatus PvmiMIOAviWavFile::disconnect(PvmiMIOSession aSession)
113 {
114 uint32 index = (uint32)aSession;
115 if (index >= iObservers.size())
116 {
117 // Invalid session ID
118 return PVMFFailure;
119 }
120
121 iObservers.erase(iObservers.begin() + index);
122 return PVMFSuccess;
123 }
124
125 ////////////////////////////////////////////////////////////////////////////
createMediaTransfer(PvmiMIOSession & aSession,PvmiKvp * aRead_formats,int32 aRead_flags,PvmiKvp * aWrite_formats,int32 aWrite_flags)126 OSCL_EXPORT_REF PvmiMediaTransfer* PvmiMIOAviWavFile::createMediaTransfer(PvmiMIOSession& aSession,
127 PvmiKvp* aRead_formats,
128 int32 aRead_flags,
129 PvmiKvp* aWrite_formats,
130 int32 aWrite_flags)
131 {
132 OSCL_UNUSED_ARG(aRead_formats);
133 OSCL_UNUSED_ARG(aRead_flags);
134 OSCL_UNUSED_ARG(aWrite_formats);
135 OSCL_UNUSED_ARG(aWrite_flags);
136
137 uint32 index = (uint32)aSession;
138 if (index >= iObservers.size())
139 {
140 // Invalid session ID
141 OSCL_LEAVE(OsclErrArgument);
142 return NULL;
143 }
144
145 return (PvmiMediaTransfer*)this;
146 }
147
148 ////////////////////////////////////////////////////////////////////////////
deleteMediaTransfer(PvmiMIOSession & aSession,PvmiMediaTransfer * aMediaTransfer)149 OSCL_EXPORT_REF void PvmiMIOAviWavFile::deleteMediaTransfer(PvmiMIOSession& aSession,
150 PvmiMediaTransfer* aMediaTransfer)
151 {
152 uint32 index = (uint32)aSession;
153 if (!aMediaTransfer || index >= iObservers.size())
154 {
155 // Invalid session ID
156 OSCL_LEAVE(OsclErrArgument);
157 }
158 }
159
160 ////////////////////////////////////////////////////////////////////////////
QueryUUID(const PvmfMimeString & aMimeType,Oscl_Vector<PVUuid,OsclMemAllocator> & aUuids,bool aExactUuidsOnly,const OsclAny * aContext)161 OSCL_EXPORT_REF PVMFCommandId PvmiMIOAviWavFile::QueryUUID(const PvmfMimeString& aMimeType,
162 Oscl_Vector<PVUuid, OsclMemAllocator>& aUuids,
163 bool aExactUuidsOnly,
164 const OsclAny* aContext)
165 {
166 OSCL_UNUSED_ARG(aMimeType);
167 OSCL_UNUSED_ARG(aExactUuidsOnly);
168
169 int32 err = 0;
170 OSCL_TRY(err, aUuids.push_back(PVMI_CAPABILITY_AND_CONFIG_PVUUID););
171 OSCL_FIRST_CATCH_ANY(err, OSCL_LEAVE(OsclErrNoMemory););
172
173 return AddCmdToQueue(CMD_QUERY_UUID, aContext);
174 }
175
176 ////////////////////////////////////////////////////////////////////////////
QueryInterface(const PVUuid & aUuid,PVInterface * & aInterfacePtr,const OsclAny * aContext)177 OSCL_EXPORT_REF PVMFCommandId PvmiMIOAviWavFile::QueryInterface(const PVUuid& aUuid,
178 PVInterface*& aInterfacePtr,
179 const OsclAny* aContext)
180 {
181 if (PVMI_CAPABILITY_AND_CONFIG_PVUUID == aUuid)
182 {
183 PvmiCapabilityAndConfig* myInterface = OSCL_STATIC_CAST(PvmiCapabilityAndConfig*, this);
184 aInterfacePtr = OSCL_STATIC_CAST(PVInterface*, myInterface);
185 }
186 else
187 {
188 aInterfacePtr = NULL;
189 }
190
191 return AddCmdToQueue(CMD_QUERY_INTERFACE, aContext, (OsclAny*)&aInterfacePtr);
192 }
193
194 ////////////////////////////////////////////////////////////////////////////
Init(const OsclAny * aContext)195 OSCL_EXPORT_REF PVMFCommandId PvmiMIOAviWavFile::Init(const OsclAny* aContext)
196 {
197 if (iState != STATE_IDLE && iState != STATE_INITIALIZED)
198 {
199 OSCL_LEAVE(OsclErrInvalidState);
200 return -1;
201 }
202
203 return AddCmdToQueue(CMD_INIT, aContext);
204 }
205
206
207 ////////////////////////////////////////////////////////////////////////////
Start(const OsclAny * aContext)208 OSCL_EXPORT_REF PVMFCommandId PvmiMIOAviWavFile::Start(const OsclAny* aContext)
209 {
210 if (iState != STATE_INITIALIZED
211 && iState != STATE_PAUSED
212 && iState != STATE_STARTED)
213 {
214 OSCL_LEAVE(OsclErrInvalidState);
215 return -1;
216 }
217
218 return AddCmdToQueue(CMD_START, aContext);
219 }
220
221 ////////////////////////////////////////////////////////////////////////////
Pause(const OsclAny * aContext)222 OSCL_EXPORT_REF PVMFCommandId PvmiMIOAviWavFile::Pause(const OsclAny* aContext)
223 {
224 if (iState != STATE_STARTED && iState != STATE_PAUSED)
225 {
226 OSCL_LEAVE(OsclErrInvalidState);
227 return -1;
228 }
229
230 return AddCmdToQueue(CMD_PAUSE, aContext);
231 }
232
233 ////////////////////////////////////////////////////////////////////////////
Flush(const OsclAny * aContext)234 OSCL_EXPORT_REF PVMFCommandId PvmiMIOAviWavFile::Flush(const OsclAny* aContext)
235 {
236 if (iState != STATE_STARTED || iState != STATE_PAUSED)
237 {
238 OSCL_LEAVE(OsclErrInvalidState);
239 return -1;
240 }
241
242 return AddCmdToQueue(CMD_FLUSH, aContext);
243 }
244
245 ////////////////////////////////////////////////////////////////////////////
Reset(const OsclAny * aContext)246 OSCL_EXPORT_REF PVMFCommandId PvmiMIOAviWavFile::Reset(const OsclAny* aContext)
247 {
248 return AddCmdToQueue(CMD_RESET, aContext);
249 }
250
251 ////////////////////////////////////////////////////////////////////////////
DiscardData(PVMFTimestamp aTimestamp,const OsclAny * aContext)252 OSCL_EXPORT_REF PVMFCommandId PvmiMIOAviWavFile::DiscardData(PVMFTimestamp aTimestamp, const OsclAny* aContext)
253 {
254 OSCL_UNUSED_ARG(aContext);
255 OSCL_UNUSED_ARG(aTimestamp);
256 OSCL_LEAVE(OsclErrNotSupported);
257 return -1;
258 }
259
260 ////////////////////////////////////////////////////////////////////////////
DiscardData(const OsclAny * aContext)261 OSCL_EXPORT_REF PVMFCommandId PvmiMIOAviWavFile::DiscardData(const OsclAny* aContext)
262 {
263 OSCL_UNUSED_ARG(aContext);
264 OSCL_LEAVE(OsclErrNotSupported);
265 return -1;
266 }
267
268
269 ////////////////////////////////////////////////////////////////////////////
Stop(const OsclAny * aContext)270 OSCL_EXPORT_REF PVMFCommandId PvmiMIOAviWavFile::Stop(const OsclAny* aContext)
271 {
272 if (iState != STATE_STARTED
273 && iState != STATE_PAUSED
274 && iState != STATE_STOPPED)
275 {
276 OSCL_LEAVE(OsclErrInvalidState);
277 return -1;
278 }
279
280 return AddCmdToQueue(CMD_STOP, aContext);
281 }
282
283 ////////////////////////////////////////////////////////////////////////////
ThreadLogon()284 OSCL_EXPORT_REF void PvmiMIOAviWavFile::ThreadLogon()
285 {
286
287 if (!iThreadLoggedOn)
288 {
289 if (iSettings.iRecModeSyncWithClock)
290 {
291 iMioClock = OSCL_NEW(PVMFMediaClock, ());
292 iMioClock->SetClockTimebase(iClockTimeBase);
293 uint32 start = 0;
294 bool overflowFlag = false;
295 iMioClock->SetStartTime32(start, PVMF_MEDIA_CLOCK_MSEC, overflowFlag);
296 }
297 AddToScheduler();
298 iThreadLoggedOn = true;
299
300 }
301 }
302
303 ////////////////////////////////////////////////////////////////////////////
ThreadLogoff()304 OSCL_EXPORT_REF void PvmiMIOAviWavFile::ThreadLogoff()
305 {
306 if (iThreadLoggedOn)
307 {
308 if (iSettings.iRecModeSyncWithClock && iMioClock != NULL)
309 {
310 OSCL_DELETE(iMioClock);
311 }
312 RemoveFromScheduler();
313 iLogger = NULL;
314 iDataPathLogger = NULL;
315 iThreadLoggedOn = false;
316 }
317
318 }
319
320
321
322 ////////////////////////////////////////////////////////////////////////////
CancelAllCommands(const OsclAny * aContext)323 OSCL_EXPORT_REF PVMFCommandId PvmiMIOAviWavFile::CancelAllCommands(const OsclAny* aContext)
324 {
325 OSCL_UNUSED_ARG(aContext);
326 OSCL_LEAVE(OsclErrNotSupported);
327 return -1;
328 }
329
330 ////////////////////////////////////////////////////////////////////////////
CancelCommand(PVMFCommandId aCmdId,const OsclAny * aContext)331 OSCL_EXPORT_REF PVMFCommandId PvmiMIOAviWavFile::CancelCommand(PVMFCommandId aCmdId, const OsclAny* aContext)
332 {
333 OSCL_UNUSED_ARG(aCmdId);
334 OSCL_UNUSED_ARG(aContext);
335 OSCL_LEAVE(OsclErrNotSupported);
336 return -1;
337 }
338
339 ////////////////////////////////////////////////////////////////////////////
setPeer(PvmiMediaTransfer * aPeer)340 OSCL_EXPORT_REF void PvmiMIOAviWavFile::setPeer(PvmiMediaTransfer* aPeer)
341 {
342 iPeer = aPeer;
343 }
344
345 ////////////////////////////////////////////////////////////////////////////
useMemoryAllocators(OsclMemAllocator * aWrite_alloc)346 OSCL_EXPORT_REF void PvmiMIOAviWavFile::useMemoryAllocators(OsclMemAllocator* aWrite_alloc)
347 {
348 OSCL_UNUSED_ARG(aWrite_alloc);
349 OSCL_LEAVE(OsclErrNotSupported);
350 }
351
352 ////////////////////////////////////////////////////////////////////////////
writeAsync(uint8 aFormatType,int32 aFormatIndex,uint8 * aData,uint32 aDataLen,const PvmiMediaXferHeader & aData_header_info,OsclAny * aContext)353 OSCL_EXPORT_REF PVMFCommandId PvmiMIOAviWavFile::writeAsync(uint8 aFormatType, int32 aFormatIndex,
354 uint8* aData, uint32 aDataLen,
355 const PvmiMediaXferHeader& aData_header_info,
356 OsclAny* aContext)
357 {
358 OSCL_UNUSED_ARG(aFormatType);
359 OSCL_UNUSED_ARG(aFormatIndex);
360 OSCL_UNUSED_ARG(aData);
361 OSCL_UNUSED_ARG(aDataLen);
362 OSCL_UNUSED_ARG(aData_header_info);
363 OSCL_UNUSED_ARG(aContext);
364 // This is an active data source. writeAsync is not supported.
365 OSCL_LEAVE(OsclErrNotSupported);
366 return -1;
367 }
368
369 ////////////////////////////////////////////////////////////////////////////
writeComplete(PVMFStatus aStatus,PVMFCommandId aWrite_cmd_id,OsclAny * aContext)370 OSCL_EXPORT_REF void PvmiMIOAviWavFile::writeComplete(PVMFStatus aStatus, PVMFCommandId aWrite_cmd_id,
371 OsclAny* aContext)
372 {
373 OSCL_UNUSED_ARG(aContext);
374 if ((aStatus != PVMFSuccess) && (aStatus != PVMFErrCancelled))
375 {
376 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR,
377 (0, "PvmiMIOAviWavFile::writeComplete: Error - writeAsync failed. aStatus=%d", aStatus));
378 OSCL_LEAVE(OsclErrGeneral);
379 }
380
381 for (int ii = iSentMediaData.size() - 1; ii >= 0; ii--)
382 {
383 if (iSentMediaData[ii].iId == aWrite_cmd_id)
384 {
385 iMediaBufferMemPool->deallocate(iSentMediaData[ii].iData);
386 iSentMediaData.erase(&iSentMediaData[ii]);
387 return;
388 }
389 }
390
391 // Error: unmatching ID.
392 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR,
393 (0, "PvmiMIOAviWavFile::writeComplete: Error - unmatched cmdId %d failed. QSize %d", aWrite_cmd_id, iSentMediaData.size()));
394 }
395
396 ////////////////////////////////////////////////////////////////////////////
readAsync(uint8 * aData,uint32 aMax_data_len,OsclAny * aContext,int32 * aFormats,uint16 aNum_formats)397 OSCL_EXPORT_REF PVMFCommandId PvmiMIOAviWavFile::readAsync(uint8* aData, uint32 aMax_data_len,
398 OsclAny* aContext, int32* aFormats, uint16 aNum_formats)
399 {
400 OSCL_UNUSED_ARG(aData);
401 OSCL_UNUSED_ARG(aMax_data_len);
402 OSCL_UNUSED_ARG(aContext);
403 OSCL_UNUSED_ARG(aFormats);
404 OSCL_UNUSED_ARG(aNum_formats);
405 // This is an active data source. readAsync is not supported.
406 OSCL_LEAVE(OsclErrNotSupported);
407 return -1;
408 }
409
410 ////////////////////////////////////////////////////////////////////////////
readComplete(PVMFStatus aStatus,PVMFCommandId aRead_cmd_id,int32 aFormat_index,const PvmiMediaXferHeader & aData_header_info,OsclAny * aContext)411 OSCL_EXPORT_REF void PvmiMIOAviWavFile::readComplete(PVMFStatus aStatus, PVMFCommandId aRead_cmd_id,
412 int32 aFormat_index, const PvmiMediaXferHeader& aData_header_info,
413 OsclAny* aContext)
414 {
415 OSCL_UNUSED_ARG(aStatus);
416 OSCL_UNUSED_ARG(aRead_cmd_id);
417 OSCL_UNUSED_ARG(aFormat_index);
418 OSCL_UNUSED_ARG(aData_header_info);
419 OSCL_UNUSED_ARG(aContext);
420 // This is an active data source. readComplete is not supported.
421 OSCL_LEAVE(OsclErrNotSupported);
422 return;
423 }
424
425 ////////////////////////////////////////////////////////////////////////////
statusUpdate(uint32 aStatus_flags)426 OSCL_EXPORT_REF void PvmiMIOAviWavFile::statusUpdate(uint32 aStatus_flags)
427 {
428 if (aStatus_flags == PVMI_MEDIAXFER_STATUS_WRITE)
429 {
430 iWriteState = EWriteOK;
431 iMicroSecondsPerDataEvent = 0;
432 AddDataEventToQueue(iMicroSecondsPerDataEvent);
433 }
434 else
435 {
436 // Ideally this routine should update the status of media input component.
437 // It should check then for the status. If media input buffer is consumed,
438 // media input object should be resheduled.
439 // Since the Media avifile component is designed with single buffer, two
440 // asynchronous reads are not possible. So this function will not be required
441 // and hence not been implemented.
442 OSCL_LEAVE(OsclErrNotSupported);
443 }
444 }
445
446
447 ////////////////////////////////////////////////////////////////////////////
cancelCommand(PVMFCommandId aCmdId)448 OSCL_EXPORT_REF void PvmiMIOAviWavFile::cancelCommand(PVMFCommandId aCmdId)
449 {
450 OSCL_UNUSED_ARG(aCmdId);
451 // This cancel command ( with a small "c" in cancel ) is for the media transfer interface.
452 // implementation is similar to the cancel command of the media I/O interface.
453 OSCL_LEAVE(OsclErrNotSupported);
454 }
455
456 ////////////////////////////////////////////////////////////////////////////
cancelAllCommands()457 OSCL_EXPORT_REF void PvmiMIOAviWavFile::cancelAllCommands()
458 {
459 OSCL_LEAVE(OsclErrNotSupported);
460 }
461
462 ////////////////////////////////////////////////////////////////////////////
setObserver(PvmiConfigAndCapabilityCmdObserver * aObserver)463 OSCL_EXPORT_REF void PvmiMIOAviWavFile::setObserver(PvmiConfigAndCapabilityCmdObserver* aObserver)
464 {
465 OSCL_UNUSED_ARG(aObserver);
466 }
467
468 ////////////////////////////////////////////////////////////////////////////
getParametersSync(PvmiMIOSession aSession,PvmiKeyType aIdentifier,PvmiKvp * & aParameters,int & aNum_parameter_elements,PvmiCapabilityContext aContext)469 OSCL_EXPORT_REF PVMFStatus PvmiMIOAviWavFile::getParametersSync(PvmiMIOSession aSession,
470 PvmiKeyType aIdentifier,
471 PvmiKvp*& aParameters,
472 int& aNum_parameter_elements,
473 PvmiCapabilityContext aContext)
474 {
475 LOG_STACK_TRACE((0, "PvmiMIOAviWavFile::getParametersSync"));
476 OSCL_UNUSED_ARG(aSession);
477 OSCL_UNUSED_ARG(aContext);
478
479 aParameters = NULL;
480 aNum_parameter_elements = 0;
481 PVMFStatus status = PVMFFailure;
482
483 if (pv_mime_strcmp(aIdentifier, OUTPUT_FORMATS_CAP_QUERY) == 0 ||
484 pv_mime_strcmp(aIdentifier, OUTPUT_FORMATS_CUR_QUERY) == 0)
485 {
486 aNum_parameter_elements = 1;
487 status = AllocateKvp(aParameters, (PvmiKeyType)OUTPUT_FORMATS_VALTYPE, aNum_parameter_elements);
488 if (status != PVMFSuccess)
489 {
490 LOG_ERR((0, "PvmiMIOAviWavFile::GetOutputParametersSync: Error - AllocateKvp failed. status=%d", status));
491 }
492 else
493 {
494 aParameters[0].value.pChar_value = (char*)iSettings.iMediaFormat.getMIMEStrPtr();
495
496 }
497 }
498 else if (pv_mime_strcmp(aIdentifier, VIDEO_OUTPUT_WIDTH_CUR_QUERY) == 0)
499 {
500 aNum_parameter_elements = 1;
501 status = AllocateKvp(aParameters, (PvmiKeyType)VIDEO_OUTPUT_WIDTH_CUR_VALUE, aNum_parameter_elements);
502 if (status != PVMFSuccess)
503 {
504 LOG_ERR((0, "PvmiMIOAviWavFile::GetOutputParametersSync: Error - AllocateKvp failed. status=%d", status));
505 return status;
506 }
507
508 aParameters[0].value.uint32_value = iSettings.iFrameWidth;
509 }
510 else if (pv_mime_strcmp(aIdentifier, VIDEO_FRAME_ORIENTATION_CUR_QUERY) == 0)
511 {
512 aNum_parameter_elements = 1;
513 status = AllocateKvp(aParameters, (PvmiKeyType)VIDEO_FRAME_ORIENTATION_CUR_VALUE, aNum_parameter_elements);
514 if (status != PVMFSuccess)
515 {
516 LOG_ERR((0, "PvmiMIOAviWavFile::GetOutputParametersSync: Error - AllocateKvp failed. status=%d", status));
517 return status;
518 }
519
520 aParameters[0].value.uint8_value = iSettings.iPicBottomUp;
521
522 }
523 else if (pv_mime_strcmp(aIdentifier, VIDEO_OUTPUT_HEIGHT_CUR_QUERY) == 0)
524 {
525 aNum_parameter_elements = 1;
526 status = AllocateKvp(aParameters, (PvmiKeyType)VIDEO_OUTPUT_HEIGHT_CUR_VALUE, aNum_parameter_elements);
527 if (status != PVMFSuccess)
528 {
529 LOG_ERR((0, "PvmiMIOAviWavFile::GetOutputParametersSync: Error - AllocateKvp failed. status=%d", status));
530 return status;
531 }
532
533 aParameters[0].value.uint32_value = iSettings.iFrameHeight;
534 }
535 else if (pv_mime_strcmp(aIdentifier, VIDEO_OUTPUT_FRAME_RATE_CUR_QUERY) == 0)
536 {
537 aNum_parameter_elements = 1;
538 status = AllocateKvp(aParameters, (PvmiKeyType)VIDEO_OUTPUT_FRAME_RATE_CUR_VALUE, aNum_parameter_elements);
539 if (status != PVMFSuccess)
540 {
541 LOG_ERR((0, "PvmiMIOAviWavFile::GetOutputParametersSync: Error - AllocateKvp failed. status=%d", status));
542 return status;
543 }
544
545 aParameters[0].value.float_value = iSettings.iFrameRate;
546 }
547 else if (pv_mime_strcmp(aIdentifier, AUDIO_OUTPUT_SAMPLING_RATE_CUR_QUERY) == 0)
548 {
549 aNum_parameter_elements = 1;
550 status = AllocateKvp(aParameters, (PvmiKeyType)AUDIO_OUTPUT_SAMPLING_RATE_CUR_VALUE, aNum_parameter_elements);
551 if (status != PVMFSuccess)
552 {
553 LOG_ERR((0, "PvmiMIOAviWavFile::GetOutputParametersSync: Error - AllocateKvp failed. status=%d", status));
554 return status;
555 }
556
557 aParameters[0].value.uint32_value = (uint32)iSettings.iSamplingFrequency;
558 }
559 else if (pv_mime_strcmp(aIdentifier, AUDIO_OUTPUT_NUM_CHANNELS_CUR_QUERY) == 0)
560 {
561 aNum_parameter_elements = 1;
562 status = AllocateKvp(aParameters, (PvmiKeyType)AUDIO_OUTPUT_NUM_CHANNELS_CUR_VALUE, aNum_parameter_elements);
563 if (status != PVMFSuccess)
564 {
565 LOG_ERR((0, "PvmiMIOAviWavFile::GetOutputParametersSync: Error - AllocateKvp failed. status=%d", status));
566 return status;
567 }
568
569 aParameters[0].value.uint32_value = (uint32)iSettings.iNumChannels;
570 }
571 else if (pv_mime_strcmp(aIdentifier, OUTPUT_TIMESCALE_CUR_QUERY) == 0)
572 {
573 aNum_parameter_elements = 1;
574 status = AllocateKvp(aParameters, (PvmiKeyType)OUTPUT_TIMESCALE_CUR_VALUE, aNum_parameter_elements);
575 if (status != PVMFSuccess)
576 {
577 LOG_ERR((0, "PVMFVideoEncPort::GetOutputParametersSync: Error - AllocateKvp failed. status=%d", status));
578 return status;
579 }
580 else
581 {
582 if (iSettings.iMediaFormat.isAudio())
583 {
584 aParameters[0].value.uint32_value = (uint32)iSettings.iSamplingFrequency;
585 }
586 else
587 {
588 aParameters[0].value.uint32_value = iSettings.iTimescale;
589 }
590 }
591 }
592
593 return status;
594 }
595
596 ////////////////////////////////////////////////////////////////////////////
releaseParameters(PvmiMIOSession aSession,PvmiKvp * aParameters,int aNum_elements)597 OSCL_EXPORT_REF PVMFStatus PvmiMIOAviWavFile::releaseParameters(PvmiMIOSession aSession,
598 PvmiKvp* aParameters,
599 int aNum_elements)
600 {
601 OSCL_UNUSED_ARG(aSession);
602 OSCL_UNUSED_ARG(aNum_elements);
603
604 if (aParameters)
605 {
606 iAlloc.deallocate((OsclAny*)aParameters);
607 return PVMFSuccess;
608 }
609 else
610 {
611 return PVMFFailure;
612 }
613 }
614
615 ////////////////////////////////////////////////////////////////////////////
createContext(PvmiMIOSession aSession,PvmiCapabilityContext & aContext)616 OSCL_EXPORT_REF void PvmiMIOAviWavFile::createContext(PvmiMIOSession aSession, PvmiCapabilityContext& aContext)
617 {
618 OSCL_UNUSED_ARG(aSession);
619 OSCL_UNUSED_ARG(aContext);
620 }
621
622 ////////////////////////////////////////////////////////////////////////////
setContextParameters(PvmiMIOSession aSession,PvmiCapabilityContext & aContext,PvmiKvp * aParameters,int aNum_parameter_elements)623 OSCL_EXPORT_REF void PvmiMIOAviWavFile::setContextParameters(PvmiMIOSession aSession,
624 PvmiCapabilityContext& aContext,
625 PvmiKvp* aParameters, int aNum_parameter_elements)
626 {
627 OSCL_UNUSED_ARG(aSession);
628 OSCL_UNUSED_ARG(aContext);
629 OSCL_UNUSED_ARG(aParameters);
630 OSCL_UNUSED_ARG(aNum_parameter_elements);
631 }
632
633 ////////////////////////////////////////////////////////////////////////////
DeleteContext(PvmiMIOSession aSession,PvmiCapabilityContext & aContext)634 OSCL_EXPORT_REF void PvmiMIOAviWavFile::DeleteContext(PvmiMIOSession aSession, PvmiCapabilityContext& aContext)
635 {
636 OSCL_UNUSED_ARG(aSession);
637 OSCL_UNUSED_ARG(aContext);
638 }
639
640 ////////////////////////////////////////////////////////////////////////////
setParametersSync(PvmiMIOSession aSession,PvmiKvp * aParameters,int aNum_elements,PvmiKvp * & aRet_kvp)641 OSCL_EXPORT_REF void PvmiMIOAviWavFile::setParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters,
642 int aNum_elements, PvmiKvp*& aRet_kvp)
643 {
644 OSCL_UNUSED_ARG(aSession);
645 PVMFStatus status = PVMFSuccess;
646 aRet_kvp = NULL;
647
648 for (int32 ii = 0; ii < aNum_elements; ii++)
649 {
650 status = VerifyAndSetParameter(&(aParameters[ii]), true);
651 if (status != PVMFSuccess)
652 {
653 LOG_ERR((0, "PvmiMIOAviWavFile::setParametersSync: Error - VerifiyAndSetParameter failed on parameter #%d", ii));
654 aRet_kvp = &(aParameters[ii]);
655 OSCL_LEAVE(OsclErrArgument);
656 }
657 }
658 }
659
660 ////////////////////////////////////////////////////////////////////////////
setParametersAsync(PvmiMIOSession aSession,PvmiKvp * aParameters,int aNum_elements,PvmiKvp * & aRet_kvp,OsclAny * aContext)661 OSCL_EXPORT_REF PVMFCommandId PvmiMIOAviWavFile::setParametersAsync(PvmiMIOSession aSession,
662 PvmiKvp* aParameters,
663 int aNum_elements,
664 PvmiKvp*& aRet_kvp,
665 OsclAny* aContext)
666 {
667 OSCL_UNUSED_ARG(aSession);
668 OSCL_UNUSED_ARG(aParameters);
669 OSCL_UNUSED_ARG(aNum_elements);
670 OSCL_UNUSED_ARG(aRet_kvp);
671 OSCL_UNUSED_ARG(aContext);
672 OSCL_LEAVE(OsclErrNotSupported);
673 return -1;
674 }
675
676 ////////////////////////////////////////////////////////////////////////////
getCapabilityMetric(PvmiMIOSession aSession)677 OSCL_EXPORT_REF uint32 PvmiMIOAviWavFile::getCapabilityMetric(PvmiMIOSession aSession)
678 {
679 OSCL_UNUSED_ARG(aSession);
680 return 0;
681 }
682
683 ////////////////////////////////////////////////////////////////////////////
verifyParametersSync(PvmiMIOSession aSession,PvmiKvp * aParameters,int aNum_elements)684 OSCL_EXPORT_REF PVMFStatus PvmiMIOAviWavFile::verifyParametersSync(PvmiMIOSession aSession,
685 PvmiKvp* aParameters, int aNum_elements)
686 {
687 OSCL_UNUSED_ARG(aSession);
688 OSCL_UNUSED_ARG(aParameters);
689 OSCL_UNUSED_ARG(aNum_elements);
690 return PVMFErrNotSupported;
691 }
692
693 ////////////////////////////////////////////////////////////////////////////
694 // Private methods
695 ////////////////////////////////////////////////////////////////////////////
PvmiMIOAviWavFile(uint32 aNumLoops,bool aRecordingMode,uint32 aStreamNo,OsclAny * aFileParser,FileFormatType aFileType,int32 & arError)696 PvmiMIOAviWavFile::PvmiMIOAviWavFile(uint32 aNumLoops, bool aRecordingMode, uint32 aStreamNo, OsclAny* aFileParser,
697 FileFormatType aFileType, int32& arError)
698 : OsclTimerObject(OsclActiveObject::EPriorityNominal, "PvmiMIOAviWavFile"),
699 iCmdIdCounter(0),
700 iPeer(NULL),
701 iThreadLoggedOn(false),
702 iDataEventCounter(0),
703 iTotalNumFrames(0),
704 iFileHeaderSize(0),
705 iMilliSecondsPerDataEvent(0),
706 iMicroSecondsPerDataEvent(0),
707 iMediaBufferMemPool(NULL),
708 iLogger(NULL),
709 iDataPathLogger(NULL),
710 iState(STATE_IDLE),
711 iWaitingOnClock(false),
712 iTimeStamp(0),
713 iStreamDuration(0),
714 iCurrentTimeStamp(0),
715 iWriteState(EWriteOK),
716 iData(NULL),
717 iNoMemBufferData(false)
718 {
719 #if PROFILING_ON
720 iNumEarlyFrames = 0;
721 iNumLateFrames = 0;
722 iTotalFrames = 0;
723 iPercFramesDropped = 0;
724 iMaxDataSize = 0;
725 iMinDataSize = 0;
726 iMaxFileReadTime = 0;
727 iMinFileReadTime = 0;
728 oDiagnosticsLogged = false;
729 #endif
730 iSettings.iNumLoops = aNumLoops;
731 iSettings.iStreamNumber = aStreamNo;
732 iSettings.iRecModeSyncWithClock = aRecordingMode;
733 arError = InitComp(aFileParser, aFileType);
734
735 iLogger = PVLogger::GetLoggerObject("PvmiMIOAviWavFile");
736 iDiagnosticsLogger = PVLogger::GetLoggerObject("pvauthordiagnostics.mio.aviwav");
737 iDiagnosticsLoggerAVIFF = PVLogger::GetLoggerObject("pvauthordiagnostics.mio.aviwav.ff");
738 iDataPathLogger = PVLogger::GetLoggerObject("datapath.mio.aviwav");
739 }
740
IsYUVFormat_Supported(uint32 aFcc)741 bool PvmiMIOAviWavFile::IsYUVFormat_Supported(uint32 aFcc)
742 {
743 uint32 ii;
744 bool pattern_found = false;
745
746 for (ii = 0 ; ii < NUM_YUV_FMT; ii++)
747 {
748 if (YUV_FMT[ii] == aFcc)
749 {
750 pattern_found = true;
751 break;
752 }
753 }
754
755 return pattern_found;
756 }
757 ////////////////////////////////////////////////////////////////////////////
InitComp(OsclAny * aFileParser,FileFormatType aFileType)758 int32 PvmiMIOAviWavFile::InitComp(OsclAny* aFileParser, FileFormatType aFileType)
759 {
760
761 switch (aFileType)
762 {
763 case FILE_FORMAT_AVI:
764 {
765 iPVAviFile = OSCL_STATIC_CAST(PVAviFile*, aFileParser);
766 iPVWavFile = NULL;
767 iSettings.iFrameDuration = iPVAviFile->GetFrameDuration();
768 uint32 ii = iSettings.iStreamNumber;
769 iStreamDuration = iPVAviFile->GetStreamDuration(ii);
770 iPVAviFile->GetFormatSpecificInfo(ii, iFormatSpecificDataFrag);
771
772 if (oscl_strstr((iPVAviFile->GetStreamMimeType(ii)).get_cstr(), "video"))
773 {
774 iSettings.iFrameHeight = iPVAviFile->GetHeight(iSettings.iPicBottomUp, ii);
775 iSettings.iFrameWidth = iPVAviFile->GetWidth(ii);
776 iSettings.iFrameRate = iPVAviFile->GetFrameRate(ii);
777 iSettings.iTimescale = iPVAviFile->GetScale(ii);
778 uint8 fmtType[4] = {0};
779 uint32 size = 4;
780
781 iPVAviFile->GetVideoFormatType((uint8*)fmtType, size, ii);
782
783 uint32 temp = MAKE_FOURCC(fmtType[0], fmtType[1], fmtType[2], fmtType[3]);
784
785 BitmapInfoHhr* videoHdr = OSCL_STATIC_CAST(BitmapInfoHhr*, iFormatSpecificDataFrag.getMemFragPtr());
786
787 if (!oscl_strncmp((char*)fmtType, "DIB ", size))
788 {
789
790 if (BITS_PER_SAMPLE12 == videoHdr->BiBitCount)
791 {
792 iSettings.iMediaFormat = PVMF_MIME_RGB12;
793 iSettings.iMimeType = PVMF_MIME_RGB12;
794 iSettings.iSampleSize = videoHdr->BiBitCount;
795 }
796 else if (BITS_PER_SAMPLE24 == videoHdr->BiBitCount)
797 {
798 iSettings.iMediaFormat = PVMF_MIME_RGB24;
799 iSettings.iMimeType = PVMF_MIME_RGB24;
800
801 iSettings.iSampleSize = videoHdr->BiBitCount;
802 }
803 else
804 {
805 return PVMFErrNotSupported;
806 }
807 }
808 else if (IsYUVFormat_Supported(temp))
809 {
810 iSettings.iMediaFormat = PVMF_MIME_YUV420;
811 iSettings.iMimeType = PVMF_MIME_YUV420;
812
813 }
814 else
815 {
816 return PVMFErrNotSupported;
817 }
818 }
819
820 if (oscl_strstr((iPVAviFile->GetStreamMimeType(ii)).get_cstr(), "audio"))
821 {
822 iSettings.iNumChannels = iPVAviFile->GetNumAudioChannels(ii);
823 iSettings.iSamplingFrequency = iPVAviFile->GetFrameRate(ii);
824
825 WaveFormatExStruct* audioHdr = OSCL_STATIC_CAST(WaveFormatExStruct*,
826 iFormatSpecificDataFrag.getMemFragPtr());
827
828 iSettings.iSampleSize = audioHdr->BitsPerSample;
829 iSettings.iByteRate = audioHdr->AvgBytesPerSec;
830
831 if (WAVE_FORMAT_PCM == audioHdr->FormatTag)
832 {
833 if (BITS_PER_SAMPLE8 == audioHdr->BitsPerSample)
834 {
835 iSettings.iMediaFormat = PVMF_MIME_PCM8;
836 iSettings.iMimeType = PVMF_MIME_PCM8;
837 }
838 else if (BITS_PER_SAMPLE16 == audioHdr->BitsPerSample)
839 {
840 iSettings.iMediaFormat = PVMF_MIME_PCM16;
841 iSettings.iMimeType = PVMF_MIME_PCM16;
842 }
843 else
844 {
845 return PVMFErrNotSupported;
846 }
847 }
848 else
849 {
850 return PVMFErrNotSupported;
851 }
852 }
853 }
854 break;
855
856 case FILE_FORMAT_WAV:
857 {
858 iPVAviFile = NULL;
859 iPVWavFile = OSCL_STATIC_CAST(PV_Wav_Parser*, aFileParser);
860 PVWAVFileInfo wavFileInfo;
861 iPVWavFile->RetrieveFileInfo(wavFileInfo);
862
863 if ((PVWAV_ITU_G711_ALAW == wavFileInfo.AudioFormat)
864 || (PVWAV_ITU_G711_ULAW == wavFileInfo.AudioFormat))
865 {
866 if (iPVWavFile->SetOutputToUncompressedPCM())
867 {
868 wavFileInfo.AudioFormat = PVWAV_PCM_AUDIO_FORMAT;
869 wavFileInfo.BitsPerSample = BITS_PER_SAMPLE16;
870 wavFileInfo.BytesPerSample = BITS_PER_SAMPLE16 / BYTE_COUNT;
871 }
872 }
873
874 iSettings.iNumChannels = wavFileInfo.NumChannels;
875 iSettings.iSamplingFrequency = (OsclFloat)wavFileInfo.SampleRate;
876 iSettings.iSampleSize = wavFileInfo.BitsPerSample;
877 iSettings.iByteRate = wavFileInfo.ByteRate;
878 iStreamDuration = (1000000 / wavFileInfo.SampleRate) * wavFileInfo.NumSamples;
879
880 if (BITS_PER_SAMPLE16 == wavFileInfo.BitsPerSample)
881 {
882 iSettings.iMediaFormat = PVMF_MIME_PCM16;
883 iSettings.iMimeType = PVMF_MIME_PCM16;
884 }
885 else if (BITS_PER_SAMPLE8 == wavFileInfo.BitsPerSample)
886 {
887 iSettings.iMediaFormat = PVMF_MIME_PCM8;
888 iSettings.iMimeType = PVMF_MIME_PCM8;
889 }
890 else
891 {
892 return PVMFErrNotSupported;
893 }
894
895 }
896 break;
897
898 default:
899 return PVMFErrNotSupported;
900
901 } // end switch
902
903 return PVMFSuccess;
904 }
905
906 ////////////////////////////////////////////////////////////////////////////
Run()907 void PvmiMIOAviWavFile::Run()
908 {
909 if (!iCmdQueue.empty())
910 {
911 PvmiMIOAviWavFileCmd cmd = iCmdQueue[0];
912 iCmdQueue.erase(iCmdQueue.begin());
913
914 switch (cmd.iType)
915 {
916
917 case CMD_INIT:
918 DoRequestCompleted(cmd, DoInit());
919 break;
920
921 case CMD_START:
922 DoRequestCompleted(cmd, DoStart());
923 break;
924
925 case CMD_PAUSE:
926 DoRequestCompleted(cmd, DoPause());
927 break;
928
929 case CMD_FLUSH:
930 DoRequestCompleted(cmd, DoFlush());
931 break;
932
933 case CMD_RESET:
934 DoRequestCompleted(cmd, DoReset());
935 break;
936
937 case CMD_STOP:
938 DoRequestCompleted(cmd, DoStop());
939 break;
940
941 case DATA_EVENT:
942 DoRead();
943 break;
944
945 case CMD_QUERY_UUID:
946 case CMD_QUERY_INTERFACE:
947 DoRequestCompleted(cmd, PVMFSuccess);
948 break;
949
950 case CMD_CANCEL_ALL_COMMANDS:
951 case CMD_CANCEL_COMMAND:
952 DoRequestCompleted(cmd, PVMFFailure);
953 break;
954
955 default:
956 break;
957 }
958 }
959
960 if (!iCmdQueue.empty())
961 {
962 // Run again if there are more things to process
963 RunIfNotReady();
964 }
965 }
966
967 ////////////////////////////////////////////////////////////////////////////
AddCmdToQueue(PvmiMIOAviWavFileCmdType aType,const OsclAny * aContext,OsclAny * aData1)968 PVMFCommandId PvmiMIOAviWavFile::AddCmdToQueue(PvmiMIOAviWavFileCmdType aType,
969 const OsclAny* aContext, OsclAny* aData1)
970 {
971 if (DATA_EVENT == aType)
972 {
973 OSCL_LEAVE(OsclErrArgument);
974 }
975
976 PvmiMIOAviWavFileCmd cmd;
977 cmd.iType = aType;
978 cmd.iContext = OSCL_STATIC_CAST(OsclAny*, aContext);
979 cmd.iData1 = aData1;
980 cmd.iId = iCmdIdCounter;
981 ++iCmdIdCounter;
982
983 if (CMD_RESET == aType)
984 iCmdQueue.push_front(cmd);
985 else
986 iCmdQueue.push_back(cmd);
987
988 RunIfNotReady();
989 return cmd.iId;
990 }
991
992 ////////////////////////////////////////////////////////////////////////////
AddDataEventToQueue(uint32 aMicroSecondsToEvent)993 void PvmiMIOAviWavFile::AddDataEventToQueue(uint32 aMicroSecondsToEvent)
994 {
995 PvmiMIOAviWavFileCmd cmd;
996 cmd.iType = DATA_EVENT;
997 iCmdQueue.push_back(cmd);
998 RunIfNotReady(aMicroSecondsToEvent);
999 }
1000
1001 ////////////////////////////////////////////////////////////////////////////
DoRequestCompleted(const PvmiMIOAviWavFileCmd & aCmd,PVMFStatus aStatus,OsclAny * aEventData)1002 void PvmiMIOAviWavFile::DoRequestCompleted(const PvmiMIOAviWavFileCmd& aCmd, PVMFStatus aStatus, OsclAny* aEventData)
1003 {
1004 PVMFCmdResp response(aCmd.iId, aCmd.iContext, aStatus, aEventData);
1005
1006 for (uint32 ii = 0; ii < iObservers.size(); ii++)
1007 {
1008 iObservers[ii]->RequestCompleted(response);
1009 }
1010 }
1011
1012 ////////////////////////////////////////////////////////////////////////////
DoInit()1013 PVMFStatus PvmiMIOAviWavFile::DoInit()
1014 {
1015 if (STATE_INITIALIZED == iState)
1016 {
1017 return PVMFSuccess;
1018 }
1019 iDataEventCounter = 0;
1020 // Create memory pool for the media data, using the maximum frame size found earlier
1021 int32 err = 0;
1022 OSCL_TRY(err,
1023 if (iMediaBufferMemPool)
1024 {
1025 OSCL_DELETE(iMediaBufferMemPool);
1026 iMediaBufferMemPool = NULL;
1027 }
1028 iMediaBufferMemPool = OSCL_NEW(OsclMemPoolFixedChunkAllocator,
1029 (PVMIOFILEIN_MEDIADATA_POOLNUM));
1030
1031 if (!iMediaBufferMemPool)
1032 {
1033 OSCL_LEAVE(OsclErrNoMemory);
1034 }
1035
1036 );
1037
1038 OSCL_FIRST_CATCH_ANY(err, return PVMFErrNoMemory);
1039
1040 //set chunk size
1041 uint32 dataSize = GetDataSize();
1042 //add bytes in 1 msec
1043 dataSize += (uint32)(iSettings.iSampleSize / BYTE_COUNT * iSettings.iSamplingFrequency / 1000);
1044 iSettings.iDataBufferSize = dataSize;
1045
1046 uint8* data = (uint8*)iMediaBufferMemPool->allocate(dataSize);
1047 iMediaBufferMemPool->deallocate(data);
1048 iState = STATE_INITIALIZED;
1049 return PVMFSuccess;
1050 }
1051
1052 ////////////////////////////////////////////////////////////////////////////
DoStart()1053 PVMFStatus PvmiMIOAviWavFile::DoStart()
1054 {
1055 iState = STATE_STARTED;
1056 AddDataEventToQueue(0);
1057 return PVMFSuccess;
1058 }
1059
1060 ////////////////////////////////////////////////////////////////////////////
DoPause()1061 PVMFStatus PvmiMIOAviWavFile::DoPause()
1062 {
1063 iState = STATE_PAUSED;
1064 if ((iMioClock) && (iSettings.iRecModeSyncWithClock))
1065 {
1066 iMioClock->Pause();
1067 }
1068 return PVMFSuccess;
1069 }
1070
DoReset()1071 PVMFStatus PvmiMIOAviWavFile::DoReset()
1072 {
1073 while (!iCmdQueue.empty())
1074 iCmdQueue.erase(&iCmdQueue.front());
1075
1076 iWriteState = EWriteOK;
1077 #if PROFILING_ON
1078 if (!oDiagnosticsLogged)
1079 LogDiagnostics();
1080 #endif
1081
1082 return PVMFSuccess;
1083 }
1084
1085 ////////////////////////////////////////////////////////////////////////////
DoFlush()1086 PVMFStatus PvmiMIOAviWavFile::DoFlush()
1087 {
1088 // This method should stop capturing media data but continue to send captured
1089 // media data that is already in buffer and then go to stopped state.
1090 // However, in this case of file input we do not have such a buffer for
1091 // captured data, so this behaves the same way as stop.
1092 return DoStop();
1093 }
1094
1095 ////////////////////////////////////////////////////////////////////////////
DoStop()1096 PVMFStatus PvmiMIOAviWavFile::DoStop()
1097 {
1098 iWriteState = EWriteOK;
1099 iDataEventCounter = 0;
1100 iState = STATE_STOPPED;
1101 if ((iMioClock != NULL) && (iSettings.iRecModeSyncWithClock))
1102 {
1103 iMioClock->Stop();
1104 }
1105 #if PROFILING_ON
1106 if (!oDiagnosticsLogged)
1107 LogDiagnostics();
1108 #endif
1109
1110 iState = STATE_STOPPED;
1111 return PVMFSuccess;
1112 }
1113
1114 ////////////////////////////////////////////////////////////////////////////
GetDataSize()1115 uint32 PvmiMIOAviWavFile::GetDataSize()
1116 {
1117 uint32 size = 0;
1118 if (iPVAviFile != NULL)
1119 {
1120 size = iPVAviFile->GetStreamSuggestedBufferSize(iSettings.iStreamNumber);
1121 }
1122 else if (iPVWavFile != NULL)
1123 {
1124 //number of samples in data buffer
1125 uint32 numSamples = (uint32)(iSettings.iSamplingFrequency * PVWAV_MSEC_PER_BUFFER) / 1000;
1126 size = numSamples * iSettings.iNumChannels * (iSettings.iSampleSize / BYTE_COUNT); // in bytes
1127 }
1128 else
1129 {
1130 return 0;
1131 }
1132
1133 return size;
1134 }
1135
1136 ////////////////////////////////////////////////////////////////////////////
GetMediaData(uint8 * aData,uint32 & aDataSize,uint32 & aTimeStamp)1137 PVMFStatus PvmiMIOAviWavFile::GetMediaData(uint8* aData, uint32& aDataSize, uint32& aTimeStamp)
1138 {
1139 aTimeStamp = iCurrentTimeStamp;
1140 uint32 iNptTS = 0;
1141 // Read data from file
1142 if (iPVAviFile != NULL)
1143 {
1144 PV_AVI_FILE_PARSER_ERROR_TYPE error = PV_AVI_FILE_PARSER_SUCCESS;
1145
1146 uint32 currticks = 0;
1147 currticks = OsclTickCount::TickCount();
1148 uint32 starttime = 0;
1149 starttime = OsclTickCount::TicksToMsec(currticks);
1150
1151 error = iPVAviFile->GetNextStreamMediaSample(iSettings.iStreamNumber, aData, aDataSize, iNptTS);
1152
1153 currticks = OsclTickCount::TickCount();
1154 uint32 endtime = 0;
1155 endtime = OsclTickCount::TicksToMsec(currticks);
1156
1157 LOGDIAGNOSTICS_AVI_FF((0, "PvmiMIOAviWavFile::GetMediaData:"
1158 "StreamNum=%d, NptTS=%d, Size=%d, TimeToRead=%d, MimeType=%s",
1159 iSettings.iStreamNumber, iNptTS, aDataSize, (endtime - starttime),
1160 iSettings.iMimeType.get_cstr()));
1161
1162 if (error != PV_AVI_FILE_PARSER_SUCCESS)
1163 {
1164 if (PV_AVI_FILE_PARSER_EOS_REACHED == error)
1165 {
1166 // Loop or report end of data now...
1167 if (iSettings.iNumLoops)
1168 {
1169 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR,
1170 (0, "PvmiMIOAviWavFile::LoopInputFile"));
1171
1172 iPVAviFile->Reset(iSettings.iStreamNumber);
1173 iSettings.iNumLoops--;
1174 //retrieve sample again
1175 PV_AVI_FILE_PARSER_ERROR_TYPE error = PV_AVI_FILE_PARSER_SUCCESS;
1176
1177 uint32 currticks = 0;
1178 currticks = OsclTickCount::TickCount();
1179 uint32 starttime = 0;
1180 starttime = OsclTickCount::TicksToMsec(currticks);
1181
1182 error = iPVAviFile->GetNextStreamMediaSample(iSettings.iStreamNumber, aData, aDataSize, iNptTS);
1183
1184 currticks = OsclTickCount::TickCount();
1185 uint32 endtime = 0;
1186 endtime = OsclTickCount::TicksToMsec(currticks);
1187
1188 LOGDIAGNOSTICS_AVI_FF((0, "PvmiMIOAviWavFile::GetMediaData:"
1189 "StreamNum=%d, NptTS=%d, Size=%d, TimeToRead=%d, MimeType=%s",
1190 iSettings.iStreamNumber, iNptTS, aDataSize, (endtime - starttime),
1191 iSettings.iMimeType.get_cstr()));
1192
1193 if (error != PV_AVI_FILE_PARSER_SUCCESS)
1194 {
1195 return PVMFFailure;
1196 }
1197 else
1198 {
1199 UpdateCurrentTimeStamp(aDataSize);
1200 return PVMFSuccess;
1201 }
1202 }
1203 else
1204 {
1205 UpdateCurrentTimeStamp(aDataSize);
1206 return PVMFInfoEndOfData;
1207 }
1208 }
1209 else
1210 {
1211 return PVMFFailure;
1212 }
1213 }
1214 }
1215 else //WAV file
1216 {
1217 uint32 samplesRead = 0;
1218 uint32 numSamples = (uint32)(iSettings.iSamplingFrequency * PVWAV_MSEC_PER_BUFFER) / 1000;
1219 PVWavParserReturnCode retcode = iPVWavFile->GetPCMData(aData, aDataSize, numSamples, samplesRead);
1220 if (PVWAVPARSER_OK == retcode)
1221 {
1222 if (samplesRead > 0)
1223 {
1224 aDataSize = samplesRead * iSettings.iNumChannels * (iSettings.iSampleSize / BYTE_COUNT);
1225 }
1226 }
1227 else if (PVWAVPARSER_END_OF_FILE == retcode)
1228 {
1229 if (iSettings.iNumLoops)
1230 {
1231 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR,
1232 (0, "PvmiMIOAviWavFile::LoopInputFile Not Supported"));
1233
1234 iPVWavFile->SeekPCMSample(0);
1235 iSettings.iNumLoops--;
1236 PVWavParserReturnCode retcode = iPVWavFile->GetPCMData(aData, aDataSize, numSamples, samplesRead);
1237 if (PVWAVPARSER_OK == retcode)
1238 {
1239 if (samplesRead > 0)
1240 {
1241 aDataSize = samplesRead * iSettings.iNumChannels * (iSettings.iSampleSize / BYTE_COUNT);
1242 }
1243 UpdateCurrentTimeStamp(aDataSize);
1244 return PVMFSuccess;
1245 }
1246 else
1247 {
1248 return PVMFFailure;
1249 }
1250 }
1251 else
1252 {
1253 UpdateCurrentTimeStamp(aDataSize);
1254 return PVMFInfoEndOfData;
1255 }
1256 }
1257 else
1258 {
1259 return PVMFFailure;
1260 }
1261 }
1262 UpdateCurrentTimeStamp(aDataSize);
1263 return PVMFSuccess;
1264 }
1265 ////////////////////////////////////////////////////////////////////////////
UpdateCurrentTimeStamp(uint32 aDataSize)1266 void PvmiMIOAviWavFile::UpdateCurrentTimeStamp(uint32 aDataSize)
1267 {
1268 if (iPVAviFile != NULL)
1269 {
1270 if (oscl_strstr((iPVAviFile->GetStreamMimeType(iSettings.iStreamNumber)).get_cstr(), "video"))
1271 {
1272 iCurrentTimeStamp += (iPVAviFile->GetFrameDuration() / 1000); //in msec
1273 }
1274 else if (oscl_strstr((iPVAviFile->GetStreamMimeType(iSettings.iStreamNumber)).get_cstr(), "audio"))
1275 {
1276 uint32 numSamples = aDataSize * BYTE_COUNT / iSettings.iSampleSize;
1277 iCurrentTimeStamp = (uint32)((OsclFloat)iCurrentTimeStamp + (OsclFloat)(numSamples * 1000) / iSettings.iSamplingFrequency);
1278 }
1279 }
1280 else //WAV File
1281 {
1282 iCurrentTimeStamp += PVWAV_MSEC_PER_BUFFER;
1283 }
1284
1285
1286 }
1287
1288 ////////////////////////////////////////////////////////////////////////////
DoRead()1289 PVMFStatus PvmiMIOAviWavFile::DoRead()
1290 {
1291 // Just copy from PVMFAviFileNode::HandleEventPortActivity. The only difference
1292 // is that data buffer is allocated by calling iMediaBufferMemPool->allocate(bytesToRead)
1293 // and there's no need to wrap it in a PVMFSharedMediaDataPtr. Also, you'll need to
1294 // keep track of the data pointer and the write command id received from peer->writeAsync
1295 // and put it in the iSentMediaData queue
1296
1297 if (iState != STATE_STARTED)
1298 {
1299 return PVMFSuccess;
1300 }
1301
1302 uint32 dataSize = 0;
1303 uint32 timeStamp = 0;
1304 uint8* data = NULL;
1305 uint32 writeAsyncID = 0;
1306
1307 PVMFStatus error = PVMFSuccess;
1308
1309 dataSize = iSettings.iDataBufferSize;
1310
1311 if (dataSize <= 0)
1312 {
1313 return PVMFErrArgument;
1314 }
1315
1316 // for realtime recording, read new media data only if not iWaitingOnClock.
1317 // otherwise process previously read data
1318 int32 err = 0;
1319
1320 //process new data only if previous data has been send to MIO node.
1321 if ((!iWaitingOnClock) && (iWriteState == EWriteOK))
1322 {
1323 // Create new media data buffer
1324 data = AllocateMemPool(iMediaBufferMemPool, dataSize, err);
1325
1326 if (err)
1327 {
1328 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_ERR,
1329 (0, "PvmiMIOAviWavFile::No buffer available, wait till next data event"));
1330
1331 if (iSettings.iRecModeSyncWithClock)
1332 CalcMicroSecPerDataEvent(dataSize);
1333 else
1334 iMicroSecondsPerDataEvent = 0;
1335
1336 AddDataEventToQueue(iMicroSecondsPerDataEvent);
1337 return PVMFSuccess;
1338 }
1339
1340 if (iNoMemBufferData)//check added for ErrorHandling test case for no memory buffer
1341 {
1342 iMediaBufferMemPool->deallocate(iData);
1343 iData = NULL;
1344 iDataSize = 0;
1345 iNoMemBufferData = false;
1346 }
1347 else
1348 {
1349 iData = NULL;
1350 iDataSize = 0;
1351 iTimeStamp = 0;
1352 }
1353
1354 bool senddata = false;
1355
1356
1357 while (!senddata)
1358 {
1359
1360 #if PROFILING_ON
1361 uint32 start = OsclTickCount::TickCount();
1362 #endif
1363 //read media data
1364 error = GetMediaData(data, dataSize, timeStamp);
1365
1366 #if PROFILING_ON
1367 uint32 stop = OsclTickCount::TickCount();
1368 uint32 freadTime = OsclTickCount::TicksToMsec(stop - start);
1369
1370 if (error == PVMFSuccess)
1371 {
1372 if (iMaxDataSize < dataSize)
1373 {
1374 iMaxDataSize = dataSize;
1375 }
1376 if ((iMinDataSize > dataSize) || (0 == iMinDataSize))
1377 {
1378 iMinDataSize = dataSize;
1379 }
1380 if (iMaxFileReadTime < freadTime)
1381 {
1382 iMaxFileReadTime = freadTime;
1383 }
1384 if ((iMinFileReadTime > freadTime) || (0 == iMinFileReadTime))
1385 {
1386 iMinFileReadTime = freadTime;
1387 }
1388 }
1389 #endif
1390 if (error != PVMFSuccess)
1391 {
1392 if (PVMFInfoEndOfData == error) //EOS Reached
1393 {
1394 //free the allocated data buffer
1395 iMediaBufferMemPool->deallocate(data);
1396 data = NULL;
1397
1398 PvmiMediaXferHeader data_hdr;
1399 data_hdr.seq_num = iDataEventCounter - 1;
1400 data_hdr.timestamp = timeStamp;
1401 data_hdr.flags = 0;
1402 data_hdr.duration = 0;
1403 data_hdr.stream_id = iSettings.iStreamNumber;
1404 dataSize = 0;
1405 //send EOS information to MIO Node
1406 error = WriteAsyncDataHdr(writeAsyncID, iPeer, dataSize, data_hdr, NULL, PVMI_MEDIAXFER_FMT_TYPE_NOTIFICATION, PVMI_MEDIAXFER_FMT_INDEX_END_OF_STREAM);
1407
1408 if (error)
1409 {
1410 if (iSettings.iRecModeSyncWithClock)
1411 CalcMicroSecPerDataEvent(dataSize);
1412 else
1413 iMicroSecondsPerDataEvent = 0;
1414
1415 //some error occured, retry sending EOS next time.
1416 AddDataEventToQueue(iMicroSecondsPerDataEvent);
1417 return PVMFSuccess;
1418 }
1419 iWriteState = EWriteOK;
1420
1421 LOGDATATRAFFIC((0, "PvmiMIOAviWavFile::DoRead - EOS Sent:"
1422 "StreamID=%d, TS=%d, SN=%d, MimeType=%s",
1423 data_hdr.stream_id, data_hdr.timestamp,
1424 data_hdr.seq_num, iSettings.iMimeType.get_cstr()));
1425 //EOS message was sent so PAUSE MIO Component.
1426 AddCmdToQueue(CMD_PAUSE, NULL);
1427
1428 return PVMFSuccess;
1429 }
1430 else
1431 {
1432 //free the allocated data buffer
1433 iMediaBufferMemPool->deallocate(data);
1434 data = NULL;
1435 AddCmdToQueue(CMD_STOP, NULL);
1436 return error;
1437 }
1438 }
1439
1440 #if PROFILING_ON
1441 iTotalFrames++;
1442 #endif
1443 if (iSettings.iRecModeSyncWithClock)
1444 {
1445
1446 uint32 clockTime32 = 0;
1447 uint32 clockTimeBase32 = 0;
1448 bool overflowFlag = false;
1449
1450 if (iMioClock->GetState() != PVMFMediaClock::RUNNING)
1451 {
1452 iMioClock->SetStartTime32(timeStamp, PVMF_MEDIA_CLOCK_MSEC, overflowFlag);
1453 iMioClock->Start();
1454 }
1455
1456
1457 //Compare with Clock time to pass data forward.
1458 iMioClock->GetCurrentTime32(clockTime32, overflowFlag, PVMF_MEDIA_CLOCK_MSEC, clockTimeBase32);
1459
1460 if (timeStamp > clockTime32)
1461 {
1462 uint32 delta = timeStamp - clockTime32;
1463 //store data info to be send forward in next callback.
1464 iData = data;
1465 iDataSize = dataSize;
1466 iTimeStamp = timeStamp;
1467 AddDataEventToQueue(delta * 1000); //delta in microseconds.
1468 iWaitingOnClock = true;
1469 #if PROFILING_ON
1470 iNumEarlyFrames++;
1471 #endif
1472 return PVMFSuccess;
1473 }
1474
1475 if (timeStamp < clockTime32)
1476 {
1477 #if PROFILING_ON
1478 iNumLateFrames++;
1479 #endif
1480 dataSize = iSettings.iDataBufferSize;
1481
1482 if (dataSize <= 0)
1483 {
1484 return PVMFErrArgument;
1485 }
1486 }
1487
1488 if (timeStamp == clockTime32)
1489 {
1490 senddata = true;
1491 }
1492
1493 } // if (iSettings.iRecModeSyncWithClock)
1494 else
1495 {
1496 senddata = true;
1497 }
1498 } // while (!senddata)
1499 } // if (!iWaitingOnClock)
1500
1501 iWaitingOnClock = false;
1502
1503 if (iData != NULL)
1504 {
1505 data = iData;
1506 dataSize = iDataSize;
1507 timeStamp = iTimeStamp;
1508 iData = NULL;
1509 }
1510
1511 // send data to Peer & store the id
1512 PvmiMediaXferHeader data_hdr;
1513 data_hdr.seq_num = iDataEventCounter - 1;
1514 data_hdr.timestamp = timeStamp;
1515 data_hdr.flags = 0;
1516 data_hdr.duration = 0;
1517 data_hdr.stream_id = iSettings.iStreamNumber;
1518
1519 if (!iPeer)
1520 {
1521 return PVMFSuccess;
1522 }
1523 err = WriteAsyncDataHdr(writeAsyncID, iPeer, dataSize, data_hdr, data, PVMI_MEDIAXFER_FMT_TYPE_DATA, 0);
1524 if (!err)
1525 {
1526 LOGDATATRAFFIC((0, "PvmiMIOAviWavFile::DoRead:"
1527 "StreamID=%d, TS=%d, Size=%d, SN=%d, MimeType=%s",
1528 data_hdr.stream_id, data_hdr.timestamp, dataSize,
1529 data_hdr.seq_num, iSettings.iMimeType.get_cstr()));
1530
1531 // Save the id and data pointer on iSentMediaData queue for writeComplete call
1532 PvmiMIOAviWavFileMediaData sentData;
1533 sentData.iId = writeAsyncID;
1534 sentData.iData = data;
1535 iSentMediaData.push_back(sentData);
1536 iMicroSecondsPerDataEvent = 0;
1537 // Queue the next data event
1538 AddDataEventToQueue(iMicroSecondsPerDataEvent);
1539 }
1540 else if (err == OsclErrBusy)
1541 {
1542 iData = data;
1543 iDataSize = dataSize;
1544 iTimeStamp = timeStamp;
1545 iWriteState = EWriteBusy;
1546 iNoMemBufferData = true;
1547 }
1548 else
1549 {
1550 iMediaBufferMemPool->deallocate(data);
1551 }
1552
1553 return PVMFSuccess;
1554 }
1555
CalcMicroSecPerDataEvent(uint32 aDataSize)1556 PVMFStatus PvmiMIOAviWavFile::CalcMicroSecPerDataEvent(uint32 aDataSize)
1557 {
1558 //calculate time for a buffer to fill
1559 if (iSettings.iMediaFormat == PVMF_MIME_YUV420)
1560 {
1561 //calculate time for a buffer to fill
1562 iMilliSecondsPerDataEvent = (int32)(1000 / iSettings.iFrameRate);
1563
1564 iMicroSecondsPerDataEvent = (int32)(1000000 / iSettings.iFrameRate);
1565 }
1566 else if (iSettings.iMediaFormat == PVMF_MIME_RGB16 ||
1567 iSettings.iMediaFormat == PVMF_MIME_RGB24)
1568 {
1569 //calculate time for a buffer to fill
1570 iMilliSecondsPerDataEvent = (int32)(1000 / iSettings.iFrameRate);
1571 iMicroSecondsPerDataEvent = (int32)(1000000 / iSettings.iFrameRate);
1572 }
1573 else if (iSettings.iMediaFormat == PVMF_MIME_PCM16 ||
1574 iSettings.iMediaFormat == PVMF_MIME_PCM8)
1575 {
1576 OsclFloat chunkrate = (OsclFloat)((OsclFloat)iSettings.iByteRate / (OsclFloat)aDataSize);
1577 iMilliSecondsPerDataEvent = (uint32)(1000 / chunkrate);
1578 iMicroSecondsPerDataEvent = iMilliSecondsPerDataEvent * 1000;
1579 }
1580 else
1581 {
1582 return PVMFErrArgument;
1583 }
1584
1585 return PVMFSuccess;
1586 }
1587
1588 ////////////////////////////////////////////////////////////////////////////
AllocateKvp(PvmiKvp * & aKvp,PvmiKeyType aKey,int32 aNumParams)1589 PVMFStatus PvmiMIOAviWavFile::AllocateKvp(PvmiKvp*& aKvp, PvmiKeyType aKey, int32 aNumParams)
1590 {
1591 LOG_STACK_TRACE((0, "PvmiMIOAviWavFile::AllocateKvp"));
1592 uint8* buf = NULL;
1593 uint32 keyLen = oscl_strlen(aKey) + 1;
1594 int32 err = 0;
1595
1596 OSCL_TRY(err,
1597 buf = (uint8*)iAlloc.allocate(aNumParams * (sizeof(PvmiKvp) + keyLen));
1598 if (!buf)
1599 {
1600 OSCL_LEAVE(OsclErrNoMemory);
1601 }
1602 );
1603
1604 OSCL_FIRST_CATCH_ANY(err,
1605 LOG_ERR((0, "PvmiMIOAviWavFile::AllocateKvp: Error - kvp allocation failed"));
1606 return PVMFErrNoMemory;
1607 );
1608
1609 int32 ii = 0;
1610 PvmiKvp* curKvp = aKvp = OSCL_PLACEMENT_NEW(buf, PvmiKvp);
1611 buf += sizeof(PvmiKvp);
1612 for (ii = 1; ii < aNumParams; ii++)
1613 {
1614 curKvp += ii;
1615 curKvp = OSCL_PLACEMENT_NEW(buf, PvmiKvp);
1616 buf += sizeof(PvmiKvp);
1617 }
1618
1619 for (ii = 0; ii < aNumParams; ii++)
1620 {
1621 aKvp[ii].key = (char*)buf;
1622 oscl_strncpy(aKvp[ii].key, aKey, keyLen);
1623 buf += keyLen;
1624 }
1625
1626 return PVMFSuccess;
1627 }
1628
1629 ////////////////////////////////////////////////////////////////////////////
VerifyAndSetParameter(PvmiKvp * aKvp,bool aSetParam)1630 PVMFStatus PvmiMIOAviWavFile::VerifyAndSetParameter(PvmiKvp* aKvp, bool aSetParam)
1631 {
1632 OSCL_UNUSED_ARG(aSetParam);
1633 LOG_STACK_TRACE((0, "PvmiMIOAviWavFile::VerifyAndSetParameter: aKvp=0x%x, aSetParam=%d", aKvp, aSetParam));
1634
1635 if (!aKvp)
1636 {
1637 LOG_ERR((0, "PvmiMIOAviWavFile::VerifyAndSetParameter: Error - Invalid key-value pair"));
1638 return PVMFFailure;
1639 }
1640
1641 if (pv_mime_strcmp(aKvp->key, OUTPUT_FORMATS_VALTYPE) == 0)
1642 {
1643 if (aKvp->value.pChar_value == (char*)iSettings.iMediaFormat.getMIMEStrPtr())
1644 {
1645 return PVMFSuccess;
1646 }
1647 else
1648 {
1649 LOG_ERR((0, "PvmiMIOAviWavFile::VerifyAndSetParameter: Error - Unsupported format %d",
1650 aKvp->value.uint32_value));
1651 return PVMFFailure;
1652 }
1653 }
1654
1655 LOG_ERR((0, "PvmiMIOAviWavFile::VerifyAndSetParameter: Error - Unsupported parameter"));
1656 return PVMFFailure;
1657 }
1658
LogDiagnostics()1659 void PvmiMIOAviWavFile::LogDiagnostics()
1660 {
1661 #if PROFILING_ON
1662 oDiagnosticsLogged = true;
1663 if (iPVAviFile)
1664 {
1665 PVLOGGER_LOGMSG(PVLOGMSG_INST_MLDBG, iDiagnosticsLogger, PVLOGMSG_DEBUG,
1666 (0, "PvmiMIOAviWavFile Stats: Stream :%s\n",
1667 (iPVAviFile->GetStreamMimeType(iSettings.iStreamNumber)).get_cstr()));
1668 }
1669 uint32 framerate = 0;
1670
1671 if (iCurrentTimeStamp > 0)
1672 {
1673 framerate = (iTotalFrames * 1000) / iCurrentTimeStamp;
1674 }
1675 PVLOGGER_LOGMSG(PVLOGMSG_INST_MLDBG, iDiagnosticsLogger, PVLOGMSG_DEBUG,
1676 (0, "PvmiMIOAviWavFile Stats: File read duration(Max:%d, Min:%d), Data Size read(Max:%d, Min:%d), Total frames send: %d, Frame Rate: %d\n", iMaxFileReadTime, iMinFileReadTime, iMaxDataSize, iMinDataSize, iTotalFrames, framerate));
1677
1678 //Log status of early and late frames for real time authoring
1679 if (iSettings.iRecModeSyncWithClock)
1680 {
1681
1682 if (iTotalFrames > 0)
1683 {
1684 iPercFramesDropped = (iNumLateFrames * 100) / iTotalFrames;
1685 }
1686
1687 PVLOGGER_LOGMSG(PVLOGMSG_INST_MLDBG, iDiagnosticsLogger, PVLOGMSG_DEBUG,
1688 (0, "PvmiMIOAviWavFile Stats: Num Early frames:%d, Num late frames:%d, Total Frames:%d, percent Late frames:%d\n", iNumEarlyFrames, iNumLateFrames, iTotalFrames, iPercFramesDropped));
1689 }
1690 #endif
1691 }
1692
AllocateMemPool(OsclMemPoolFixedChunkAllocator * & aMediaBufferMemPool,uint32 aDataSize,int32 & aErr)1693 uint8* PvmiMIOAviWavFile::AllocateMemPool(OsclMemPoolFixedChunkAllocator*& aMediaBufferMemPool, uint32 aDataSize, int32 &aErr)
1694 {
1695 uint8* data = NULL;;
1696 OSCL_TRY(aErr, data = (uint8*)aMediaBufferMemPool->allocate(aDataSize););
1697 return data;
1698 }
1699
WriteAsyncDataHdr(uint32 & aWriteAsyncID,PvmiMediaTransfer * & aPeer,uint32 & aBytesToRead,PvmiMediaXferHeader & aData_hdr,uint8 * aData,uint32 aFormatType,uint32 aFormatIndex)1700 int32 PvmiMIOAviWavFile::WriteAsyncDataHdr(uint32& aWriteAsyncID, PvmiMediaTransfer*& aPeer, uint32& aBytesToRead, PvmiMediaXferHeader& aData_hdr, uint8* aData, uint32 aFormatType, uint32 aFormatIndex)
1701 {
1702 int err = 0;
1703 OSCL_TRY(err, aWriteAsyncID = aPeer->writeAsync(aFormatType, aFormatIndex, aData, aBytesToRead, aData_hdr););
1704 return err;
1705 }
1706