forked from aosp-mirror/platform_external_opencore
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pvmf_parsernode_impl.cpp
868 lines (750 loc) · 31.4 KB
/
pvmf_parsernode_impl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
/* ------------------------------------------------------------------
* Copyright (C) 1998-2010 PacketVideo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied.
* See the License for the specific language governing permissions
* and limitations under the License.
* -------------------------------------------------------------------
*/
#ifndef PVMF_PARSERNODE_IMPL_H_INCLUDED
#include "pvmf_parsernode_impl.h"
#endif
#ifndef PVMF_AMR_PARSER_H_INCLUDED
#include "pvmf_amr_parser.h"
#endif
#ifndef PVMF_WAV_PARSER_H_INCLUDED
#include "pvmf_wav_parser.h"
#endif
#ifndef PVMI_DS_BASIC_INTERFACE_H_INCLUDED
#include "pvmi_ds_basic_interface.h"
#endif
#ifndef PVMF_RESIZABLE_SIMPLE_MEDIAMSG_H_INCLUDED
#include "pvmf_resizable_simple_mediamsg.h"
#endif
#ifndef __MEDIA_CLOCK_CONVERTER_H
#include "media_clock_converter.h"
#endif
#ifndef PVMF_DURATION_INFOMESSAGE_H_INCLUDED
#include "pvmf_duration_infomessage.h"
#endif
#ifndef PVLOGGER_H_INCLUDED
#include "pvlogger.h"
#endif
#ifndef PVMI_KVP_UTIL_H_INCLUDED
#include "pvmi_kvp_util.h"
#endif
#define NUM_SUPPORTED_KEYS 2
PVMFParserNodeImpl::PVMFParserNodeImpl(int32 aPriority)
: PVMFNodeInterfaceImpl(aPriority, "PVMFParserNodeImpl")
{
ipDataStream = NULL;
ipParser = NULL;
iClipFmtType = PVMF_MIME_FORMAT_UNKNOWN;
iClipDuration = 0;
iClipTimescale = 0;
ipGau = NULL;
ipLogger = PVLogger::GetLoggerObject("PVMFParserNodeImpl");
ipDatapathLog = PVLogger::GetLoggerObject("datapath.sourcenode.commonparsernode");
}
PVMFParserNodeImpl::~PVMFParserNodeImpl()
{
// Clear the track port info
if (!iTrkPortInfoVec.empty())
ClearTrackPortInfo();
// Delete the GAU structure
if (ipGau)
{
PVMF_BASE_NODE_DELETE(ipGau);
ipGau = NULL;
}
// Delete the parser
if (ipParser)
{
PVMF_BASE_NODE_DELETE(ipParser);
ipParser = NULL;
}
}
void PVMFParserNodeImpl::addRef()
{
iExtensionRefCount++;
}
void PVMFParserNodeImpl::removeRef()
{
iExtensionRefCount--;
}
bool PVMFParserNodeImpl::queryInterface(const PVUuid& uuid, PVInterface*& iface)
{
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipLogger, PVLOGMSG_STACK_TRACE, (0, "PVMFParserNodeImpl::queryInterface: In"));
if (uuid == PVMF_DATASTREAM_INIT_INTERFACE_UUID)
{
PVMFDataStreamInitExtension* myInf = OSCL_STATIC_CAST(PVMFDataStreamInitExtension*, this);
iface = OSCL_STATIC_CAST(PVInterface*, myInf);
}
else if (uuid == PVMF_DATA_SOURCE_INIT_INTERFACE_UUID)
{
PVMFDataSourceInitializationExtensionInterface* myInf = OSCL_STATIC_CAST(PVMFDataSourceInitializationExtensionInterface*, this);
iface = OSCL_STATIC_CAST(PVInterface*, myInf);
}
else if (uuid == PVMF_TRACK_SELECTION_INTERFACE_UUID)
{
PVMFTrackSelectionExtensionInterface* myInf = OSCL_STATIC_CAST(PVMFTrackSelectionExtensionInterface*, this);
iface = OSCL_STATIC_CAST(PVInterface*, myInf);
}
else if (uuid == PvmfDataSourcePlaybackControlUuid)
{
PvmfDataSourcePlaybackControlInterface* myInf = OSCL_STATIC_CAST(PvmfDataSourcePlaybackControlInterface*, this);
iface = OSCL_STATIC_CAST(PVInterface*, myInf);
}
else if (uuid == KPVMFMetadataExtensionUuid)
{
PVMFMetadataExtensionInterface* myInf = OSCL_STATIC_CAST(PVMFMetadataExtensionInterface*, this);
iface = OSCL_STATIC_CAST(PVInterface*, myInf);
}
else
{
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipLogger, PVLOGMSG_STACK_TRACE, (0, "PVMFParserNodeImpl::queryInterface: Not Supported UUID Out"));
return false;
}
addRef();
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipLogger, PVLOGMSG_STACK_TRACE, (0, "PVMFParserNodeImpl::queryInterface: Out"));
return true;
}
PVMFStatus PVMFParserNodeImpl::InitializeDataStreamData(PvmiDataStreamInterface* aDataStream, PVMFFormatType& aSourceFormat)
{
ipDataStream = aDataStream;
iClipFmtType = aSourceFormat;
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipLogger, PVLOGMSG_STACK_TRACE,
(0, "PVMFParserNodeImpl::InitializeDataStreamData: DataStream %p, Source Format %s", ipDataStream, iClipFmtType.getMIMEStrPtr()));
return PVMFSuccess;
}
PVMFStatus PVMFParserNodeImpl::GetMediaPresentationInfo(PVMFMediaPresentationInfo& aInfo)
{
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipLogger, PVLOGMSG_STACK_TRACE, (0, "PVMFParserNodeImpl::GetMediaPresentationInfo: In"));
PVMFStatus status = PVMFSuccess;
// Audio Only contents have 1 track
uint32 numTracks = ipParser->GetNumTracks();
OSCL_FastString mimeType = _STRLIT_CHAR(PVMF_MIME_FORMAT_UNKNOWN);
ipParser->RetrieveFileInfo(iFileInfo);
if (iFileInfo.AudioPresent)
{
// Check the Track type and set mime type and BufferLen to retrieve data
if (PVMF_AMR_NB == iFileInfo.AudioTrkInfo.AudioFmt)
{
mimeType = _STRLIT_CHAR(PVMF_MIME_AMR_IETF);
iTrackPortInfo.iBufferlen = PVMF_NUM_FRAMES_AMR * PVMF_MAX_FRAME_SIZE_AMR_NB;
}
else if (PVMF_AMR_WB == iFileInfo.AudioTrkInfo.AudioFmt)
{
mimeType = _STRLIT_CHAR(PVMF_MIME_AMRWB_IETF);
iTrackPortInfo.iBufferlen = PVMF_NUM_FRAMES_AMR * PVMF_MAX_FRAME_SIZE_AMR_WB;
}
else if (PVMF_WAV_PCM == iFileInfo.AudioTrkInfo.AudioFmt)
{
if (8 == (iFileInfo.AudioTrkInfo.BitRate / iFileInfo.AudioTrkInfo.SamplingRate))
mimeType = _STRLIT_CHAR(PVMF_MIME_PCM8);
else if (iFileInfo.AudioTrkInfo.LittleEndian)
mimeType = _STRLIT_CHAR(PVMF_MIME_PCM16);
else
mimeType = _STRLIT_CHAR(PVMF_MIME_PCM16_BE);
}
else if (PVMF_WAV_ALAW == iFileInfo.AudioTrkInfo.AudioFmt)
mimeType = _STRLIT_CHAR(PVMF_MIME_ALAW);
else if (PVMF_WAV_MULAW == iFileInfo.AudioTrkInfo.AudioFmt)
mimeType = _STRLIT_CHAR(PVMF_MIME_ULAW);
else
status = PVMFErrNotSupported;
if (0 == iTrackPortInfo.iBufferlen)
{
// Just set it for WAV parser
uint32 bytesPerSample = ((iFileInfo.AudioTrkInfo.BitRate / iFileInfo.AudioTrkInfo.SamplingRate) + 7) / 8;
iTrackPortInfo.iBufferlen = PVMF_NUM_FRAMES_WAV * iFileInfo.AudioTrkInfo.NoOfChannels * bytesPerSample;
}
}
aInfo.setDurationValue(iClipDuration);
aInfo.setDurationTimeScale(iClipTimescale);
PVMFTrackInfo trackInfo;
trackInfo.setTrackMimeType(mimeType);
trackInfo.setTrackID(numTracks);
trackInfo.setPortTag(PVMF_PARSER_NODE_PORT_TYPE_OUTPUT);
trackInfo.setTrackDurationValue(iFileInfo.AudioTrkInfo.TrackDuration);
trackInfo.setTrackDurationTimeScale(iFileInfo.AudioTrkInfo.TrackTimescale);
trackInfo.setTrackBitRate(iFileInfo.AudioTrkInfo.BitRate);
aInfo.addTrackInfo(trackInfo);
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipLogger, PVLOGMSG_STACK_TRACE, (0, "PVMFParserNodeImpl::GetMediaPresentationInfo: Out"));
return status;
}
PVMFStatus PVMFParserNodeImpl::SelectTracks(PVMFMediaPresentationInfo& aInfo)
{
OSCL_UNUSED_ARG(aInfo);
return PVMFSuccess;
}
PVMFCommandId PVMFParserNodeImpl::SetDataSourcePosition(PVMFSessionId aSessionId,
PVMFTimestamp aTargetNPT,
PVMFTimestamp& aActualNPT,
PVMFTimestamp& aActualMediaDataTS,
bool aSeekToSyncPoint,
uint32 aStreamID,
OsclAny * aContext)
{
PVMFNodeCommand cmd;
cmd.Construct(aSessionId, PVMF_GENERIC_NODE_SET_DATASOURCE_POSITION, aTargetNPT, &aActualNPT, &aActualMediaDataTS, aSeekToSyncPoint, aStreamID, aContext);
return QueueCommandL(cmd);
}
PVMFCommandId PVMFParserNodeImpl::QueryDataSourcePosition(PVMFSessionId aSessionId,
PVMFTimestamp aTargetNPT,
PVMFTimestamp& aActualNPT,
bool aSeekToSyncPoint,
OsclAny * aContext)
{
PVMFNodeCommand cmd;
cmd.Construct(aSessionId, PVMF_GENERIC_NODE_QUERY_DATASOURCE_POSITION, aTargetNPT, &aActualNPT, aSeekToSyncPoint, aContext);
return QueueCommandL(cmd);
}
PVMFCommandId PVMFParserNodeImpl::QueryDataSourcePosition(PVMFSessionId aSessionId,
PVMFTimestamp aTargetNPT,
PVMFTimestamp& aSyncBeforeTargetNPT,
PVMFTimestamp& aSyncAfterTargetNPT,
OsclAny* aContext,
bool aSeekToSyncPoint)
{
PVMFNodeCommand cmd;
cmd.Construct(aSessionId, PVMF_GENERIC_NODE_QUERY_DATASOURCE_POSITION, aTargetNPT, aSyncBeforeTargetNPT, aSyncAfterTargetNPT, aContext, aSeekToSyncPoint);
return QueueCommandL(cmd);
}
PVMFCommandId PVMFParserNodeImpl::SetDataSourceRate(PVMFSessionId aSessionId,
int32 aRate,
PVMFTimebase* aTimebase,
OsclAny * aContext)
{
PVMFNodeCommand cmd;
cmd.Construct(aSessionId, PVMF_GENERIC_NODE_SET_DATASOURCE_RATE, aRate, aTimebase, aContext);
return QueueCommandL(cmd);
}
PVMFStatus PVMFParserNodeImpl::SetMetadataClipIndex(uint32 aClipIndex)
{
// Since Playlist is not supported in this node as of now
OSCL_UNUSED_ARG(aClipIndex);
return PVMFSuccess;
}
uint32 PVMFParserNodeImpl::GetNumMetadataValues(PVMFMetadataList& aKeyList)
{
return NUM_SUPPORTED_KEYS;
}
PVMFCommandId PVMFParserNodeImpl::GetNodeMetadataValues(PVMFSessionId aSessionId,
PVMFMetadataList& aKeyList,
Oscl_Vector<PvmiKvp, OsclMemAllocator>& aValueList,
uint32 aStartingValueIndex,
int32 aMaxValueEntries,
const OsclAny* aContextData)
{
PVMFNodeCommand cmd;
cmd.Construct(aSessionId, PVMF_GENERIC_NODE_GETNODEMETADATAVALUES, aKeyList, aValueList, aStartingValueIndex, aMaxValueEntries, aContextData);
return QueueCommandL(cmd);
}
PVMFStatus PVMFParserNodeImpl::ReleaseNodeMetadataValues(Oscl_Vector<PvmiKvp, OsclMemAllocator>& aValueList,
uint32 aStartingValueIndex,
uint32 aEndValueIndex)
{
while (!aValueList.empty())
aValueList.erase(&aValueList[0]);
return PVMFSuccess;
}
PVMFStatus PVMFParserNodeImpl::HandleExtensionAPICommands()
{
PVMFStatus status = PVMFFailure;
switch (iCurrentCommand.iCmd)
{
case PVMF_GENERIC_NODE_SET_DATASOURCE_POSITION:
status = DoSetDataSourcePosition();
break;
case PVMF_GENERIC_NODE_QUERY_DATASOURCE_POSITION:
case PVMF_GENERIC_NODE_SET_DATASOURCE_RATE:
status = PVMFErrNotSupported;
break;
case PVMF_GENERIC_NODE_GETNODEMETADATAVALUES:
status = DoGetNodeMetadataValues();
break;
default:
break;
}
return status;
}
PVMFStatus PVMFParserNodeImpl::CancelCurrentCommand()
{
return PVMFSuccess;
}
PVMFStatus PVMFParserNodeImpl::DoQueryInterface()
{
PVUuid* uuid;
PVInterface** inf;
iCurrentCommand.PVMFNodeCommandBase::Parse(uuid, inf);
if (queryInterface(*uuid, *inf))
return PVMFSuccess;
return PVMFErrNotSupported;
}
PVMFStatus PVMFParserNodeImpl::DoInit()
{
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipLogger, PVLOGMSG_STACK_TRACE, (0, "PVMFParserNodeImpl::DoInit: In"));
// Create the parser based on ClipFmtType
if (iClipFmtType == PVMF_MIME_AMRFF)
ipParser = PVMF_BASE_NODE_NEW(PVMFAmrParser, ());
else if (iClipFmtType == PVMF_MIME_WAVFF)
ipParser = PVMF_BASE_NODE_NEW(PVMFWavParser, ());
else
ipParser = NULL;
ipGau = PVMF_BASE_NODE_NEW(GAU, ());
if (NULL == ipParser || NULL == ipGau)
{
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipLogger, PVLOGMSG_STACK_TRACE, (0, "PVMFParserNodeImpl::DoInit: Error No Memory"));
return PVMFErrNoMemory;
}
if (!ipParser->Init(ipDataStream, iClipDuration, iClipTimescale))
{
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipLogger, PVLOGMSG_STACK_TRACE, (0, "PVMFParserNodeImpl::DoInit: Init on Parser Failed"));
return PVMFFailure;
}
uint64 duration = iClipDuration;
if (1000 != iClipTimescale)
{
// Use the media clock converter class to calculate duration with the given timescale
MediaClockConverter mcc;
mcc.update_clock((uint64)iClipDuration);
duration = mcc.get_converted_ts64(iClipTimescale);
}
PVMFDurationInfoMessage* durInfoMsg = OSCL_NEW(PVMFDurationInfoMessage, (duration));
uint8 local[4] = {0, 0, 0, 0};
PVMFAsyncEvent async(PVMFInfoEvent, PVMFInfoDurationAvailable, NULL, ((PVInterface*)durInfoMsg), NULL, local, 4);
ReportInfoEvent(async);
if (durInfoMsg)
{
durInfoMsg->removeRef();
}
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipLogger, PVLOGMSG_STACK_TRACE, (0, "PVMFParserNodeImpl::DoInit: Out"));
return PVMFSuccess;
}
PVMFStatus PVMFParserNodeImpl::DoRequestPort(PVMFPortInterface*& aPort)
{
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipLogger, PVLOGMSG_STACK_TRACE, (0, "PVMFParserNodeImpl::DoRequestPort: In"));
int32 portTag;
OSCL_String* mimeType;
iCurrentCommand.PVMFNodeCommandBase::Parse(portTag, mimeType);
if ((PVMF_PARSER_NODE_PORT_TYPE_OUTPUT != portTag) || (NULL == mimeType))
{
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipLogger, PVLOGMSG_STACK_TRACE, (0, "PVMFParserNodeImpl::DoRequestPort: Invalid PortTag or MimeType"));
return PVMFErrArgument;
}
PVMFFormatType formatType = mimeType->get_cstr();
if (formatType == PVMF_MIME_FORMAT_UNKNOWN)
{
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipLogger, PVLOGMSG_STACK_TRACE, (0, "PVMFParserNodeImpl::DoRequestPort: Unknown Format Type"));
return PVMFErrArgument;
}
OSCL_StackString<40> portName;
if (formatType.isAudio())
{
portName = "CommonParserPort(Audio)";
}
else if (formatType.isVideo())
{
portName = "CommonParserPort(Video)";
}
bool memErr = false;
PVMFPortInterface* parserPort = NULL;
MediaClockConverter* clockConv = NULL;
OsclMemPoolResizableAllocator* resizeableMemPoolAllocator = NULL;
PVMFResizableSimpleMediaMsgAlloc* resizeableSimpleMediaMsg = NULL;
parserPort = PVMF_BASE_NODE_NEW(PVMFParserNodePort, (portTag, this, portName.get_cstr()));
clockConv = PVMF_BASE_NODE_NEW(MediaClockConverter, (iClipTimescale));
resizeableMemPoolAllocator = PVMF_BASE_NODE_NEW(OsclMemPoolResizableAllocator, (20 * 1024, 20));
resizeableSimpleMediaMsg = PVMF_BASE_NODE_NEW(PVMFResizableSimpleMediaMsgAlloc, (resizeableMemPoolAllocator));
if (!parserPort || !clockConv || !resizeableMemPoolAllocator || !resizeableSimpleMediaMsg)
memErr = true;
if (memErr)
{
if (parserPort)
PVMF_BASE_NODE_DELETE(parserPort);
if (clockConv)
PVMF_BASE_NODE_DELETE(clockConv);
if (resizeableMemPoolAllocator)
{
resizeableMemPoolAllocator->removeRef();
resizeableMemPoolAllocator = NULL;
}
if (resizeableSimpleMediaMsg)
PVMF_BASE_NODE_DELETE(resizeableSimpleMediaMsg);
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipLogger, PVLOGMSG_STACK_TRACE, (0, "PVMFParserNodeImpl::DoRequestPort: Error No Memory"));
return PVMFErrNoMemory;
}
resizeableMemPoolAllocator->enablenullpointerreturn();
iTrackPortInfo.iTrackId = portTag;
iTrackPortInfo.ipMimeString = (char*)mimeType->get_cstr();
iTrackPortInfo.ipNode = this;
iTrackPortInfo.ipPort = parserPort;
iTrackPortInfo.ipClockConv = clockConv;
iTrackPortInfo.ipResizeableMemPoolAllocator = resizeableMemPoolAllocator;
iTrackPortInfo.ipResizeableSimpleMediaMsg = resizeableSimpleMediaMsg;
iTrkPortInfoVec.push_back(iTrackPortInfo);
aPort = parserPort;
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipLogger, PVLOGMSG_STACK_TRACE, (0, "PVMFParserNodeImpl::DoRequestPort: Out"));
return PVMFSuccess;
}
PVMFStatus PVMFParserNodeImpl::DoStop()
{
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipLogger, PVLOGMSG_STACK_TRACE, (0, "PVMFParserNodeImpl::DoStop: In"));
if (!iTrkPortInfoVec.empty())
(&iTrkPortInfoVec[0])->reset();
// Reset the tracks
int64 seekTo = 0;
ipParser->Seek(0, seekTo);
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipLogger, PVLOGMSG_STACK_TRACE, (0, "PVMFParserNodeImpl::DoStop: Out"));
return PVMFSuccess;
}
PVMFStatus PVMFParserNodeImpl::DoReleasePort()
{
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipLogger, PVLOGMSG_STACK_TRACE, (0, "PVMFParserNodeImpl::DoReleasePort: In"));
ClearTrackPortInfo();
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipLogger, PVLOGMSG_STACK_TRACE, (0, "PVMFParserNodeImpl::DoReleasePort: Out"));
return PVMFSuccess;
}
PVMFStatus PVMFParserNodeImpl::DoReset()
{
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipLogger, PVLOGMSG_STACK_TRACE, (0, "PVMFParserNodeImpl::DoReset: In"));
ClearTrackPortInfo();
// Delete the GAU structure
if (ipGau)
{
PVMF_BASE_NODE_DELETE(ipGau);
ipGau = NULL;
}
// Delete the parser
if (ipParser)
{
PVMF_BASE_NODE_DELETE(ipParser);
ipParser = NULL;
}
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipLogger, PVLOGMSG_STACK_TRACE, (0, "PVMFParserNodeImpl::DoReset: Out"));
return PVMFSuccess;
}
void PVMFParserNodeImpl::Run()
{
if (!iInputCommands.empty())
ProcessCommand();
if (EPVMFNodeStarted == iInterfaceState)
{
PVMFParserNodeTrackPortInfo* trackPortInfo = &iTrkPortInfoVec[0];
if (!trackPortInfo->iOutgoingQueueBusy)
ProcessPortActivity(trackPortInfo);
if (trackPortInfo->iProcessOutgoingMsg)
if (PVMFSuccess != (trackPortInfo->ipPort->Send()))
trackPortInfo->iProcessOutgoingMsg = false;
if (!trackPortInfo->iOutgoingQueueBusy || trackPortInfo->iProcessOutgoingMsg)
RunIfNotReady();
}
}
void PVMFParserNodeImpl::HandlePortActivity(const PVMFPortActivity& aActivity)
{
switch (aActivity.iType)
{
case PVMF_PORT_ACTIVITY_CREATED:
ReportInfoEvent(PVMFInfoPortCreated, (OsclAny*)aActivity.iPort);
break;
case PVMF_PORT_ACTIVITY_DELETED:
ReportInfoEvent(PVMFInfoPortDeleted, (OsclAny*)aActivity.iPort);
break;
case PVMF_PORT_ACTIVITY_CONNECT:
case PVMF_PORT_ACTIVITY_DISCONNECT:
break;
case PVMF_PORT_ACTIVITY_INCOMING_MSG:
// There cannot be any Incoming msg for source node, log the Error
break;
case PVMF_PORT_ACTIVITY_OUTGOING_MSG:
{
// There is a msg in the outgoing queue send it to the connected port
PVMFParserNodeTrackPortInfo* trackPortInfo = &iTrkPortInfoVec[0];
if (!trackPortInfo->iProcessOutgoingMsg)
if (PVMFErrBusy == (trackPortInfo->ipPort->Send()))
trackPortInfo->iProcessOutgoingMsg = false;
}
break;
case PVMF_PORT_ACTIVITY_CONNECTED_PORT_BUSY:
(&iTrkPortInfoVec[0])->iProcessOutgoingMsg = false;
break;
case PVMF_PORT_ACTIVITY_CONNECTED_PORT_READY:
{
PVMFParserNodeTrackPortInfo* trackPortInfo = &iTrkPortInfoVec[0];
trackPortInfo->iProcessOutgoingMsg = true;
if (PVMFSuccess != (trackPortInfo->ipPort->Send()))
ReportInfoEvent(PVMFErrPortProcessing);
RunIfNotReady();
}
break;
case PVMF_PORT_ACTIVITY_OUTGOING_QUEUE_BUSY:
(&iTrkPortInfoVec[0])->iOutgoingQueueBusy = true;
break;
case PVMF_PORT_ACTIVITY_OUTGOING_QUEUE_READY:
{
PVMFParserNodeTrackPortInfo* trackPortInfo = &iTrkPortInfoVec[0];
trackPortInfo->iOutgoingQueueBusy = false;
ProcessPortActivity(trackPortInfo);
RunIfNotReady();
}
break;
default:
break;
}
}
void PVMFParserNodeImpl::ProcessPortActivity(PVMFParserNodeTrackPortInfo* aTrackPortInfo)
{
if (aTrackPortInfo->iEosSent)
{
// EOS has already been sent, just return and reset the booleans controlling data flow on port queues
aTrackPortInfo->iOutgoingQueueBusy = true;
return;
}
if (aTrackPortInfo->iSendBos)
{
// Send the BOS first
if (SendBeginOfMediaStreamCommand(aTrackPortInfo->ipPort, iStreamID, aTrackPortInfo->iTimestamp))
aTrackPortInfo->iSendBos = false;
else
{
// Queue is not ready to accept any more data, set the boolean iOutgoingQueueBusy as true
// and wait for Queues to signal when they are ready
aTrackPortInfo->iOutgoingQueueBusy = true;
return;
}
}
if (!aTrackPortInfo->iSendEos)
{
// Can Retrieve and Queue the media sample
PVMFStatus status = QueueMediaSample(aTrackPortInfo);
if (PVMFSuccess != status && PVMFErrNoMemory != status)
// Report Processing Error Event
ReportInfoEvent(PVMFErrPortProcessing);
}
if (aTrackPortInfo->iSendEos)
{
if (SendEndOfTrackCommand(aTrackPortInfo->ipPort, iStreamID, aTrackPortInfo->iTimestamp, aTrackPortInfo->iSeqNum, 0, 10))
{
// EOS sent successfully, reset booleans controlling data flow on port queues
aTrackPortInfo->iEosSent = true;
aTrackPortInfo->iOutgoingQueueBusy = true;
}
}
}
PVMFStatus PVMFParserNodeImpl::QueueMediaSample(PVMFParserNodeTrackPortInfo* aTrackPortInfo)
{
// Create a Media data pool
OsclSharedPtr<PVMFMediaDataImpl> mediaDataImpl;
mediaDataImpl = aTrackPortInfo->ipResizeableSimpleMediaMsg->allocate(aTrackPortInfo->iBufferlen);
if (NULL == mediaDataImpl.GetRep())
{
OsclMemPoolResizableAllocatorObserver* resizableMemPoolAllocObs =
OSCL_STATIC_CAST(OsclMemPoolResizableAllocatorObserver*, aTrackPortInfo);
aTrackPortInfo->ipResizeableMemPoolAllocator->notifyfreeblockavailable(*resizableMemPoolAllocObs, aTrackPortInfo->iBufferlen);
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipDatapathLog, PVLOGMSG_STACK_TRACE, (0, "PVMFParserNodeImpl::QueueMediaSample: No Memory available"));
return PVMFErrNoMemory;
}
// Now create the pvmf media from pool
PVMFSharedMediaDataPtr mediaDataPtr;
mediaDataPtr = PVMFMediaData::createMediaData(mediaDataImpl, aTrackPortInfo->ipResizeableMemPoolAllocator);
if (NULL == mediaDataPtr.GetRep())
{
OsclMemPoolResizableAllocatorObserver* resizableMemPoolAllocObs =
OSCL_STATIC_CAST(OsclMemPoolResizableAllocatorObserver*, aTrackPortInfo);
aTrackPortInfo->ipResizeableMemPoolAllocator->notifyfreeblockavailable(*resizableMemPoolAllocObs, aTrackPortInfo->iBufferlen);
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipDatapathLog, PVLOGMSG_STACK_TRACE, (0, "PVMFParserNodeImpl::QueueMediaSample: No Memory available"));
return PVMFErrNoMemory;
}
// Retrieve Memory Fragment to write to
OsclRefCounterMemFrag refCntrMemFrag;
mediaDataPtr->getMediaFragment(0, refCntrMemFrag);
if (iClipFmtType == PVMF_MIME_AMRFF)
{
ipGau->MediaBuffer = NULL;
ipGau->NumberOfFrames = PVMF_NUM_FRAMES_AMR;
ipGau->BufferLen = aTrackPortInfo->iBufferlen;
}
else if (iClipFmtType == PVMF_MIME_WAVFF)
{
ipGau->MediaBuffer = (uint8*)refCntrMemFrag.getMemFragPtr();
ipGau->BufferLen = aTrackPortInfo->iBufferlen;
ipGau->NumberOfFrames = PVMF_NUM_FRAMES_WAV;
}
PVMFStatus status = PVMFSuccess;
PVMFParserReturnCode code;
code = ipParser->GetNextAccessUnits(ipGau);
if (code == PVMFParserEverythingFine || code == PVMFParserInSufficientData)
{
if (iClipFmtType == PVMF_MIME_AMRFF)
oscl_memcpy(refCntrMemFrag.getMemFragPtr(), ipGau->MediaBuffer, ipGau->BufferLen);
// Set the actual size
mediaDataPtr->setMediaFragFilledLen(0, ipGau->BufferLen);
// Resize Memory Fragment
aTrackPortInfo->ipResizeableSimpleMediaMsg->ResizeMemoryFragment(mediaDataImpl);
// Special handling for first frame after seek
if (aTrackPortInfo->iFirstFrameAfterSeek)
{
aTrackPortInfo->iSampleNPT = ipGau->info[0].ts;
aTrackPortInfo->iFirstFrameAfterSeek = false;
}
// Sample Duration of first sample after seek will be zero. The duration can only be known once node
// has retrieved atleast 2 samples.
aTrackPortInfo->iSampleDur = ipGau->info[0].ts - aTrackPortInfo->iSampleNPT;
aTrackPortInfo->iTimestamp += aTrackPortInfo->iSampleDur;
aTrackPortInfo->iSampleNPT = ipGau->info[0].ts;
// Set the parameters
mediaDataPtr->setStreamID(iStreamID);
mediaDataPtr->setTimestamp(aTrackPortInfo->iTimestamp);
mediaDataPtr->setSeqNum(aTrackPortInfo->iSeqNum);
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipDatapathLog, PVLOGMSG_STACK_TRACE,
(0, "PVMFParserNodeImpl::QueueMediaSample: StreamId %d, Timestamp %d, SeqNum %d, Length %d"
, iStreamID, aTrackPortInfo->iTimestamp, aTrackPortInfo->iSeqNum, ipGau->BufferLen));
aTrackPortInfo->iSeqNum++;
// Set M bit to 1 always
uint32 markerInfo = 0;
markerInfo |= PVMF_MEDIA_DATA_MARKER_INFO_M_BIT;
mediaDataImpl->setMarkerInfo(markerInfo);
// Now queue the media sample to the Outgoing queue
PVMFSharedMediaMsgPtr mediaMsgPtr;
convertToPVMFMediaMsg(mediaMsgPtr, mediaDataPtr);
status = aTrackPortInfo->ipPort->QueueOutgoingMsg(mediaMsgPtr);
if (code == PVMFParserInSufficientData)
{
// For local content treat it as EOS
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipDatapathLog, PVLOGMSG_STACK_TRACE,
(0, "PVMFParserNodeImpl::QueueMediaSample: Parser returned Insufficient Data for local content, Send EOS StreamId %d"
, iStreamID));
aTrackPortInfo->iSendEos = true;
}
}
else
{
// Send the EOS msg now
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipDatapathLog, PVLOGMSG_STACK_TRACE,
(0, "PVMFParserNodeImpl::QueueMediaSample: Send EOS StreamId %d", iStreamID));
aTrackPortInfo->iSendEos = true;
}
return status;
}
PVMFStatus PVMFParserNodeImpl::DoSetDataSourcePosition()
{
// Parse the command
PVMFTimestamp targetNPT = 0;
PVMFTimestamp* actualNPT, *actualMediaDataTS = NULL;
bool seekToSyncPoint = false;
uint32 streamId = 0;
iCurrentCommand.Parse(targetNPT, actualNPT, actualMediaDataTS, seekToSyncPoint, streamId);
// Verify the streamID
if ((streamId == iStreamID) && (EPVMFNodeStarted == iInterfaceState))
return PVMFErrArgument;
iStreamID = streamId;
bool sendBosEos = false;
PVMFTimestamp minTs = 0x7FFFFFFF;
// Check the Target Position if greater than Clip Duration
if (targetNPT >= iClipDuration)
{
// Reset the Parser to the beginning
targetNPT = 0;
sendBosEos = true;
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipDatapathLog, PVLOGMSG_STACK_TRACE,
(0, "PVMFParserNodeImpl::DoSetDataSourcePosition: Target Greater than Duration, Do BOS-EOS, Reset tracks to zero"));
}
for (uint32 ii = 0; ii < iTrkPortInfoVec.size(); ii++)
{
// New stream reset booleans for BOS-EOS and start the data flow
iTrkPortInfoVec[ii].iSendBos = true;
iTrkPortInfoVec[ii].iSendEos = false;
iTrkPortInfoVec[ii].iEosSent = false;
iTrkPortInfoVec[ii].iOutgoingQueueBusy = false;
iTrkPortInfoVec[ii].iFirstFrameAfterSeek = true;
if (sendBosEos)
// Since the target position was beyond clip duration source just needs
// to send EOS after BOS, so set the boolean for EOS
iTrkPortInfoVec[ii].iSendEos = true;
// Get the Timestamp for actualMediaDataTs
if (iTrkPortInfoVec[ii].iTimestamp < minTs)
minTs = iTrkPortInfoVec[ii].iTimestamp;
}
*actualMediaDataTS = minTs;
*actualNPT = targetNPT;
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipDatapathLog, PVLOGMSG_STACK_TRACE,
(0, "PVMFParserNodeImpl::DoSetDataSourcePosition: TargetPos %d, ActualMediaDataTS %d"
, targetNPT, *actualMediaDataTS));
// Seek parser to targetNPT
PVMFParserReturnCode retVal;
retVal = ipParser->Seek((int64)targetNPT, (int64&) * actualNPT);
// Set the timestamp for playback
for (uint32 j = 0; j < iTrkPortInfoVec.size(); j++)
iTrkPortInfoVec[j].iTimestamp = *actualMediaDataTS + (targetNPT - *actualNPT);
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipDatapathLog, PVLOGMSG_STACK_TRACE,
(0, "PVMFParserNodeImpl::DoSetDataSourcePosition: New StreamId %d, ActualPos %d"
, iStreamID, *actualNPT));
return (PVMFParserEverythingFine == retVal ? PVMFSuccess : PVMFFailure);
}
void PVMFParserNodeImpl::ClearTrackPortInfo()
{
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipLogger, PVLOGMSG_STACK_TRACE, (0, "PVMFParserNodeImpl::ClearTrackPortInfo: In"));
while (!iTrkPortInfoVec.empty())
{
PVMFParserNodeTrackPortInfo* trackPortInfo = &iTrkPortInfoVec[0];
if (trackPortInfo)
{
trackPortInfo->reset();
trackPortInfo->ipMimeString = NULL;
if (trackPortInfo->ipPort)
PVMF_BASE_NODE_DELETE(trackPortInfo->ipPort);
if (trackPortInfo->ipClockConv)
PVMF_BASE_NODE_DELETE(trackPortInfo->ipClockConv);
if (trackPortInfo->ipResizeableMemPoolAllocator)
{
trackPortInfo->ipResizeableMemPoolAllocator->CancelFreeChunkAvailableCallback();
trackPortInfo->ipResizeableMemPoolAllocator->removeRef();
trackPortInfo->ipResizeableMemPoolAllocator = NULL;
}
if (trackPortInfo->ipResizeableSimpleMediaMsg)
PVMF_BASE_NODE_DELETE(trackPortInfo->ipResizeableSimpleMediaMsg);
// Erase the element from the vector
iTrkPortInfoVec.erase(trackPortInfo);
}
}
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipLogger, PVLOGMSG_STACK_TRACE, (0, "PVMFParserNodeImpl::ClearTrackPortInfo: In"));
}
PVMFStatus PVMFParserNodeImpl::DoGetNodeMetadataValues()
{
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipLogger, PVLOGMSG_STACK_TRACE, (0, "PVMFParserNodeImpl::DoGetNodeMetadataValues: In"));
// Parse the command
PVMFMetadataList* keyList = NULL;
Oscl_Vector<PvmiKvp, OsclMemAllocator>* valueList = NULL;
uint32 startingIndex = 0;
int32 maxEntries = 0;
iCurrentCommand.Parse(keyList, valueList, startingIndex, maxEntries);
if (NULL == keyList || NULL == valueList)
return PVMFFailure;
if (iTrkPortInfoVec.size() > 0)
{
// @TODO Once the GetMetaDataValue API is available at the Fileformat interface level,
// the meta data retireval will be moved from the node to the different fileformats.
// For now just push the mime string for the app to recognise the type of content
// and random-access-denied to allow seek functionality
PvmiKvp kvp;
kvp.key = NULL;
PVMFCreateKVPUtils::CreateKVPForCharStringValue(kvp, PVMETADATA_TRACKINFO_AUDIO_FORMAT_KEY, iTrkPortInfoVec[0].ipMimeString);
valueList->push_back(kvp);
kvp.key = NULL;
bool seekDenied = false;
PVMFCreateKVPUtils::CreateKVPForBoolValue(kvp, PVMF_COMMON_PARSER_NODE_RANDOM_ACCESS_DENIED_KEY, seekDenied);
valueList->push_back(kvp);
}
PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, ipLogger, PVLOGMSG_STACK_TRACE, (0, "PVMFParserNodeImpl::DoGetNodeMetadataValues: Out"));
return PVMFSuccess;
}