-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMAFTracksValidation.php
executable file
·867 lines (807 loc) · 59.6 KB
/
CMAFTracksValidation.php
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
867
<?php
/* This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
$CMAFMediaProfileAttributesVideo = array(
"codec" => "",
"profile" => "",
"level" => "",
"height" => "",
"width" => "",
"framerate" => "",
"color_primaries" => "",
"transfer_char" => "",
"matrix_coeff" => "",
"tier" => "",
"brand"=>"");
$CMAFMediaProfileAttributesAudio = array(
"codec" => "",
"profile" => "",
"level" => "",
"channels"=>"",
"sampleRate"=>"",
"brand"=>"");
$CMAFMediaProfileAttributesSubtitle = array(
"codec" => "",
"mimeType" => "",
"mimeSubtype"=>"",
"brand"=>"");
function checkCMAFTracks(){
global $session_dir, $mpd_features, $current_period, $current_adaptation_set, $current_representation,
$adaptation_set_template, $reprsentation_template, $reprsentation_error_log_template, $reprsentation_mdat_template, $profiles, $cmaf_mediaTypes,
$progress_report, $progress_xml, $cmaf_mediaProfiles;
$adapt_dir = str_replace('$AS$', $current_adaptation_set, $adaptation_set_template);
$rep_xml_dir = str_replace(array('$AS$', '$R$'), array($current_adaptation_set, $current_representation), $reprsentation_template);
$rep_xml = $session_dir . '/Period' . $current_period . '/' . $adapt_dir . '/' . $rep_xml_dir . '.xml';
if(file_exists($rep_xml)){
$xml = get_DOM($rep_xml, 'atomlist');
if(!$xml)
return;
$error_file = str_replace(array('$AS$', '$R$'), array($current_adaptation_set, $current_representation), $reprsentation_error_log_template);
if(!($opfile = open_file($session_dir.'/Period'.$current_period.'/'.$error_file.'.txt', 'a'))){
echo 'Error opening/creating CMAF Tracks conformance check file: '.$session_dir.'/'.$error_file.'.txt';
return;
}
$return_array = checkCMAFMessages($error_file);
$messages = '';
$messages_cmf2 = '';
$cmaf_cmfc = $return_array[0];
$cmaf_cmf2 = $return_array[1];
# Store media type for selection set checks later
$cmaf_media_type = $xml->getElementsByTagName('hdlr')->item(0)->getAttribute('handler_type');
$cmaf_mediaTypes[$current_period][$current_adaptation_set][$current_representation] = $cmaf_media_type;
$Adapt = $mpd_features['Period'][$current_period]['AdaptationSet'][$current_adaptation_set];
$errorInTrack=0;
$id = $Adapt['Representation'][$current_representation]['id'];
$xml_moof=$xml->getElementsByTagName('moof');
$xml_num_moofs=$xml_moof->length;
$xml_tfhd=$xml->getElementsByTagName('tfhd');
$xml_trun=$xml->getElementsByTagName('trun');
$xml_tfdt=$xml->getElementsByTagName('tfdt');
/* if($xml_trun[0]->getAttribute('version') ==1){
$firstSampleCompTime=$xml_trun[0]->getAttribute('earliestCompositionTime');
$firstSampleDecTime=$xml_tfdt[0]->getAttribute('baseMediaDecodeTime');
if($firstSampleCompTime!=$firstSampleDecTime)
fprintf($opfile, "**'CMAF check violated: Section 7.5.16- For 'trun' version 1, the composition time of 1st presented sample in a CMAF Segment SHALL be same as 1st Sample decode time, but not found in Rep ".$id." \n");
}*/
// 'trun' version check for CMAF video tracks
$adapt_mime_type = $Adapt['mimeType'];
$rep_mime_type = $Adapt['Representation'][$current_representation]['mimeType'];
if(strpos($rep_mime_type, 'video') !== FALSE || strpos($adapt_mime_type, 'video') !== FALSE){
if(strpos($profiles[$current_period][$current_adaptation_set][$current_representation], 'urn:mpeg:dash:profile:isoff-live:2011') !== FALSE){
for($j=0;$j<$xml_num_moofs;$j++){
$trun_version = $xml_trun->item($j)->getAttribute('version');
if($trun_version != "1")
$messages_cmf2 .= "**'CMAF check 'cmf2' violated: Section 7.7.3- For video CMAF tracks not contained in Track Files, Version 1 SHALL be used', but " . $trun_version . " found for Rep ".$id." Track ".($j+1)."\n";
}
}
$xml_elst = $xml->getElementsByTagName('elst');
if($xml_elst->length != 0) {
$messages_cmf2 .= "**'CMAF check 'cmf2' violated: Section 7.7.2- For video CMAF tracks, the EditListBox SHALL NOT be present', elst box found for Rep $id.\n";
}
}
// 'subs' presence check for TTML image subtitle track with media profile 'im1i'
$rep_codec_type = $Adapt['Representation'][$current_representation]['codec'];
if(strpos($rep_codec_type, 'im1i') !== FALSE){
for($j=0;$j<$xml_num_moofs;$j++){
$temp_moof = $xml_moof[$j];
$xml_subs = $temp_moof->getElementsByTagName('subs');
if($xml_subs->length == 0)
$messages .= "**'CMAF check violated: Section 7.5.20- Each CMAF fragment in a TTML image subtitle track of CMAF media profile 'im1i' SHALL contain a SubSampleInformationBox in the TrackFragmentBox, but " . $xml_subs->length . " found for Rep ".$id." Fragment ".($j+1)."\n";
}
}
for($j=1;$j<$xml_num_moofs;$j++){
//$sampleDurFragPrev=$xml_tfhd[$j-1]->getAttribute('defaultSampleDuration');
//$sampleCountFragPrev=$xml_trun[$j-1]->getAttribute('sampleCount');
$cummulatedSampleDurFragPrev=$xml_trun->item($j-1)->getAttribute('cummulatedSampleDuration');
$decodeTimeFragPrev=$xml_tfdt->item($j-1)->getAttribute('baseMediaDecodeTime');
$decodeTimeFragCurr=$xml_tfdt->item($j)->getAttribute('baseMediaDecodeTime');
if($decodeTimeFragCurr!=$decodeTimeFragPrev+$cummulatedSampleDurFragPrev){//($sampleDurFragPrev*$sampleCountFragPrev)){
$messages .= "**'CMAF check violated: Section 7.3.2.2- Each CMAF Fragment in a CMAF Track SHALL have baseMediaDecodeTime equal to the sum of all prior Fragment durations added to the first Fragment's baseMediaDecodeTime', but not found for Rep ".$id." Fragment ".($j+1)."\n";
$messages .= "**'CMAF check violated: Section 7.3.2.3- CMAF Chunks in a CMAF Track SHALL NOT overlap or have gaps in decode time', overlap or gap found for the Rep/Track $id at Chunk ".($j+1)."\n";
$errorInTrack=1;
}
}
$offsetinfo = 'Period' . $current_period . '/' . str_replace(array('$AS$', '$R$'), array($current_adaptation_set, $current_representation), $reprsentation_mdat_template);
$mdat_file = open_file($session_dir . '/' . $offsetinfo . '.txt', 'r');
for($j=0;$j<$xml_num_moofs;$j++){
if($xml_trun->item($j)->getAttribute('version') ==1){
$firstSampleCompTime=$xml_trun->item($j)->getAttribute('earliestCompositionTime');
$firstDecTime=$xml_tfdt->item(0)->getAttribute('baseMediaDecodeTime');
if($firstSampleCompTime!=$firstDecTime)
$messages .= "**'CMAF check violated: Section 7.5.17- For 'trun' version 1, the composition time of 1st presented sample in a CMAF Segment SHALL be same as 1st Sample decode time (baseMediaDecodeTime), but not found in Rep ".$id." \n";
}
if($mdat_file != NULL){
$mdat_info = array();
if(!feof($mdat_file)){
$mdat_info = explode(" ", fgets($mdat_file));
}
if(!empty($mdat_info)){
$moofFirstByte = $xml_moof->item($j)->getAttribute('offset');
$dataOffset = $xml_trun->item($j)->getAttribute('data_offset');
$trunSampleSize = $xml_trun->item($j)->getAttribute('sampleSizeTotal');
// Check that $dataOffset leads to a position within the mdat and that the total length of content in the trun doesn't, when added to this value, go beyond the end of the mdat.
if(!($moofFirstByte+$dataOffset >= $mdat_info[0] && $moofFirstByte+$dataOffset+$trunSampleSize <= $mdat_info[0]+$mdat_info[1] )) {
$messages .= "**'CMAF check violated: Section 7.3.2.3- All media samples in a CMAF Chunk SHALL be addressed by byte offsets in the TrackRunBox relative to first byte of the MovieFragmentBox', but not found for Rep ".$id." Chunk ".($j+1)."\n";
}
}
}
}
fclose($mdat_file);
if($errorInTrack)
$messages .= "**'CMAF check violated: Section 7.3.2.2- The concatenation of a CMAF Header and all CMAF Fragments in the CMAF Track in consecutive decode order SHALL be a valid fragmented ISOBMFF file', but not found for Rep ".$id."\n";
$xml_hdlr=$xml->getElementsByTagName('hdlr')->item(0);
$xml_handlerType=$xml_hdlr->getAttribute('handler_type');
$xml_elst=$xml->getElementsByTagName('elstEntry');
if($xml_elst->length>0 && $xml_handlerType=='vide'){
$firstSampleCompTime=$xml_trun->item(0)->getAttribute('earliestCompositionTime');
$mediaTime=$xml_elst->item(0)->getAttribute('mediaTime');
if($mediaTime != $firstSampleCompTime)
$messages .= "**'CMAF check violated: Section 7.5.13- In video CMAF track, an EditListBox SHALL be used to adjust the earliest video sample to movie presentation time zero, i.e., media-time equal to composition-time of earliest presented sample in the 1st Fragment', but media-time is not equal to composition-time for Rep ".$id."\n";
}
$xml_meta = $xml->getElementsByTagName('meta');
if($xml_meta->length > 0) {
foreach ($xml_meta as $i => $xml_meta_i) {
if($xml_meta_i->parentNode->nodeName == 'atomlist') {
$messages .= "**'CMAF check violated: Section 7.5.2- When Metadata carried in MetaBox is present, it SHALL NOT occur at the file level', but a meta box found at the file level for Rep ".$id."\n";
}
}
}
$xml_udta = $xml->getElementsByTagName('udta');
if($xml_udta->length > 0) {
foreach ($xml_udta as $i => $xml_udta_i) {
if($xml_udta_i->parentNode->nodeName == 'atomlist') {
$messages .= "**'CMAF check violated: Section 7.5.2- When Metadata carried in UserDataBox is present, it SHALL NOT occur at the file level', but a udta box found at the file level for Rep ".$id."\n";
}
}
}
/*$ParamSetPresent=0;
$xml_videSample=$xml->getElementsByTagName('vide_sampledescription');
if($xml_videSample->length>0){
$sdType=$xml_videSample->item(0)->getAttribute('sdType');
if($sdType == "hvc1"){
$xml_NALUnit=$xml->getElementsByTagName('NALUnit');
if($xml_NALUnit->length==0)
fprintf($opfile, "**'CMAF check violated: Section B.2.1.2. - For a Visual Sample Entry with codingname 'hvc1', SHALL contain one or more decoding parameter sets(Containing VPS,SPS and PPS NALs for HEVC Video), but NALs not found in the Rep/Track ".$id."\n");
else{
for($k=0; $k< ($xml_NALUnit->length); $k++){
$ParamSet=$xml_NALUnit->item($k)->getAttribute('nal_unit_type');
if($ParamSet ==32 || $ParamSet ==33|| $ParamSet ==34)
$ParamSetPresent=1;
}
if($ParamSetPresent==0)
fprintf($opfile, "**'CMAF check violated: Section B.2.1.2. - For a Visual Sample Entry with codingname 'hvc1', SHALL contain one or more decoding parameter sets(Containing VPS,SPS and PPS NALs for HEVC Video), but found none in the Rep/Track ".$id."\n");
}
}
}*/
$xml_videSample=$xml->getElementsByTagName('vide_sampledescription');
if($xml_videSample->length>0){
$sdType=$xml_videSample->item(0)->getAttribute('sdType');
if($sdType == "hvc1" || $sdType =="hev1"){
$xml_hvcc=$xml_videSample->item(0)->getElementsByTagName('hvcC');
if($xml_hvcc->length!=1) {
$messages .= "**'CMAF check violated: Section B.2.3. - The HEVCSampleEntry SHALL contain an HEVCConfigurationBox (hvcC) containing an HEVCDecoderConfigurationRecord, but found ".$xml_hvcc->length." box in the Rep/Track ".$id."\n";
}
}
if( $sdType =="hev1"){
$vui_flag=0;
$xml_NALUnit=$xml->getElementsByTagName('NALUnit');
for($k=0; $k< ($xml_NALUnit->length); $k++){
$ParamSet=$xml_NALUnit->item($k)->getAttribute('nal_unit_type');
if($ParamSet ==33)
$vui_flag=$xml_NALUnit->item($k)->getAttribute('vui_parameters_present_flag');
}
if($vui_flag==0){
$colr=$xml_videSample->item(0)->getElementsByTagName('colr');
$pasp=$xml_videSample->item(0)->getElementsByTagName('pasp');
if($pasp->length==0) {
$messages .= "**'CMAF check violated: Section B.2.3. - The HEVCSampleEntry SHALL contain PixelAspectRatioBox (pasp), but not found in the Rep/Track ".$id."\n";
}
if($colr->length==0) {
$messages .= "**'CMAF check violated: Section B.2.3. - The HEVCSampleEntry SHALL contain ColorInformationBox (colr), but not found in the Rep/Track ".$id."\n";
}
else{
if($colr->item(0)->getAttribute('colrtype') !='nclx'){
$messages .= "**'CMAF check violated: Section B.2.3. - The HEVCSampleEntry SHALL contain ColorInformationBox (colr) with colour_type 'nclx', but this colour_type ".$colr->item(0)->getAttribute('colrtype')." found in the Rep/Track ".$id."\n";
}
}
}
}
}
//Check for metadata required to decode, decrypt, display in CMAF Header.
// $xml_hdlr=$xml->getElementsByTagName('hdlr')[0];
// $xml_handlerType=$xml_hdlr->getAttribute('handler_type');
if($xml_handlerType=='vide' ){
if($sdType =='avc1' || $sdType== 'avc3'){
$width=$xml_videSample->item(0)->getAttribute('width');
$height=$xml_videSample->item(0)->getAttribute('height');
$xml_NALUnit=$xml->getElementsByTagName('NALUnit');
if($xml_NALUnit->length>0){
$xml_NALComment=$xml_NALUnit->item(0)->getElementsByTagName('comment');
$num_ticks=$xml_NALComment->item(0)->getAttribute('num_units_in_tick');
$time_scale=$xml_NALComment->item(0)->getAttribute('time_scale');
$profile_idc=$xml_NALUnit->item(0)->getAttribute('profile_idc');
$level_idc=$xml_NALComment->item(0)->getAttribute('level_idc');
}
if($width== NULL )
$messages .= "**'CMAF check violated: Section 7.3.2.4. - Each CMAF Fragment in combination with its associated Header SHALL contain sufficient metadata to be decoded and displayed when independently accessed, but 'width' missing in the Header of Rep/Track ".$id."\n";
if($height==NULL)
$messages .= "**'CMAF check violated: Section 7.3.2.4. - Each CMAF Fragment in combination with its associated Header SHALL contain sufficient metadata to be decoded and displayed when independently accessed, but 'height' missing in the Header of Rep/Track ".$id."\n";
if($sdType =='avc1' && $profile_idc ==NULL)
$messages .= "**'CMAF check violated: Section 7.3.2.4. - Each CMAF Fragment in combination with its associated Header SHALL contain sufficient metadata to be decoded and displayed when independently accessed, but 'profile_idc' missing in the Header of Rep/Track ".$id."\n";
if($sdType =='avc1' && $level_idc==NULL)
$messages .= "**'CMAF check violated: Section 7.3.2.4. - Each CMAF Fragment in combination with its associated Header SHALL contain sufficient metadata to be decoded and displayed when independently accessed, but 'level_idc' missing in the Header of Rep/Track ".$id."\n";
if($sdType =='avc1' && ($num_ticks==NULL || $time_scale==NULL))
$messages .= "**'CMAF check violated: Section 7.3.2.4. - Each CMAF Fragment in combination with its associated Header SHALL contain sufficient metadata to be decoded and displayed when independently accessed, but FPS info (num_ticks & time_scale) missing in the Header of Rep/Track ".$id."\n";
}
}
if($xml_handlerType=='soun'){
$xml_sounSample=$xml->getElementsByTagName('soun_sampledescription');
$sdType=$xml_sounSample->item(0)->getAttribute('sdType');
$samplingRate=$xml_sounSample->item(0)->getAttribute('sampleRate');
$xml_audioDec=$xml->getElementsByTagName('DecoderSpecificInfo');
if($xml_audioDec->length>0)
$channelConfig=$xml_audioDec->item(0)->getAttribute('channelConfig');
if($sdType==NULL )
$messages .= "**'CMAF check violated: Section 7.3.2.4. - Each CMAF Fragment in combination with its associated Header SHALL contain sufficient metadata to be decoded and displayed when independently accessed, but audio 'sdTtype' missing in the Header of Rep/Track ".$id."\n";
if($samplingRate==NULL)
$messages .= "**'CMAF check violated: Section 7.3.2.4. - Each CMAF Fragment in combination with its associated Header SHALL contain sufficient metadata to be decoded and displayed when independently accessed, but audio 'samplingRate' missing in the Header of Rep/Track ".$id."\n";
if($channelConfig==NULL)
$messages .= "**'CMAF check violated: Section 7.3.2.4. - Each CMAF Fragment in combination with its associated Header SHALL contain sufficient metadata to be decoded and displayed when independently accessed, but audio 'channelConfig' missing in the Header of Rep/Track ".$id."\n";
}
$dash264 = false;
if(strpos($profiles[$current_period][$current_adaptation_set][$current_representation], "http://dashif.org/guidelines/dash264") !== false)
$dash264 = true;
$content_protection_len = (!$Adapt['ContentProtection']) ? sizeof($Adapt['Representation'][$current_representation]['ContentProtection']) : sizeof($Adapt['ContentProtection']);
if($content_protection_len > 0 && $dash264 == true){
if($xml->getElementsByTagName('tenc')->length ==0)
$messages .= "**'CMAF check violated: Section 7.3.2.4. - Each CMAF Fragment in combination with its associated Header SHALL contain sufficient metadata to be decrypted when independently accessed, but missing in the Header of Rep/Track ".$id."\n";
else{
$xml_tenc=$xml->getElementsByTagName('tenc');
$AuxInfoPresent=($xml_tenc->item(0)->getAttribute('default_IV_size')!=0);
if($AuxInfoPresent){
for($j=0;$j<$xml_num_moofs;$j++){
$xml_traf=$xml_moof->item($j)->getElementsByTagName('traf');
$xml_senc=$xml_traf->item(0)->getElementsByTagName('senc');
if($xml_senc->length==0){
$messages .= "**'CMAF check violated: Section 7.4.2. - When Sample Encryption Sample Auxiliary Info is used, 'senc' SHALL be present in each CMAF Fragment, but not found in Rep/Track ".$id." Fragment ".($j+1)."\n";
$messages .= "**'CMAF check violated: Section 7.3.2.4. - Each CMAF Fragment in combination with its associated Header SHALL contain sufficient metadata to be decrypted when independently accessed, but missing in the Fragment ".($j+1)." of Rep/Track ".$id."\n";
}
}
}
}
}
//Segment Index box check.
$sidx=$xml->getElementsByTagName('sidx');
if($sidx->length>0){
for($j=0; $j < $sidx->length; $j++){
$ref_count=$sidx->item($j)->getAttribute('referenceCount');
$syncSampleError=0;
for($z=0; $z<$ref_count; $z++){
$ref_type=$sidx->item($j)->getAttribute('reference_type_'.($z+1));
if($ref_type!=0)
$messages .= "**'CMAF check violated: Section 7.3.3.3. - If SegmentIndexBoxes exist, each subsegment referenced in the SegmentIndexBox SHALL be a single CMAF Fragment contained in the CMAF Track File, but reference to Fragment not found in Rep/Track ".$id.", Segment ".($z+1)."\n";
//Check on non_sync_sample
/* if($xml_handlerType=='vide'){
$sap_type=intval($sidx[$j]->getAttribute('SAP_type_'.($z+1)));
$sample_count=$xml_trun[max($z,$j)]->getAttribute('sampleCount');
for($a=0;$a<$sample_count;$a++){
$sample_flag=intval($xml_trun[$z]->getAttribute('sample_flags_'.($a+1)));
// non_sync_sample is the 16th bit from MSB in 32-bit.
$sample_flag=$sample_flag & hexdec("00010000");//0x00010000;
if($sap_type ==1 || $sap_type==2){
if($sample_flag !=0)
$syncSampleError=1;
//fprintf($opfile, "**'CMAF check violated: Section 7.5.16. - Within a video CMAF Track, TrackRunBox SHALL identify non-sync pictures with sample_is_non_sync_sample as 0 for SAP type 1 or 2, but not found in Rep/Track ".$id.", Fragment ".($z+1)."\n");
}else if(sample_flag!=hexdec("10000")){//0x10000
$syncSampleError=1;
//fprintf($opfile, "**'CMAF check violated: Section 7.5.16. - Within a video CMAF Track, TrackRunBox SHALL identify non-sync pictures with sample_is_non_sync_sample as 1 for SAP type other than 1 or 2, but not found in Rep/Track ".$id.", Fragment ".($z+1)."\n");
}
} //This is to avoid printing for each sample in trun- it makes output log huge.
if($syncSampleError)
fprintf($opfile, "**'CMAF check violated: Section 7.5.16. - Within a video CMAF Track, TrackRunBox SHALL identify non-sync pictures with sample_is_non_sync_sample as 0 for SAP type 1 or 2, and 1 if not, but not found in Rep/Track ".$id.", Fragment ".(max($z,$j)+1)."\n");
}*/
}
}
}
$cmaf_mediaprofile_res = determineCMAFMediaProfiles($xml);
$cmaf_mediaProfiles[$current_period][$current_adaptation_set][$current_representation]['cmafMediaProfile'] = $cmaf_mediaprofile_res[0];
$messages .= $cmaf_mediaprofile_res[1];
if($messages != '' || !$cmaf_cmfc) {
$cmaf_cmfc = FALSE;
$cmaf_cmf2 = FALSE;
$messages .= $messages_cmf2;
$messages .= "**'CMAF check violated: Section 7.3.2.2. - A CMAF Track SHALL conform to at least one structural brand', conformance to a structural brand is not found for Rep/Track ".$id."\n";
fprintf($opfile, $messages);
fclose($opfile);
}
else {
if(!$cmaf_cmf2) {
fclose($opfile);
$logs_array = explode("\n", file_get_contents($session_dir . '/Period' . $current_period . '/' . $error_file . '.txt'));
$size = sizeof($logs_array);
for($log_index=0; $log_index<$size; $log_index++) {
if(strpos($logs_array[$log_index], "CMAF check 'cmf2' violated: Section 7.7") !== FALSE) {
unset($logs_array[$log_index]);
}
}
$logs = implode("\n", $logs_array);
file_put_contents($session_dir . '/Period' . $current_period . '/' . $error_file . '.txt', $logs);
}
elseif($messages_cmf2 != '') {
$cmaf_cmf2 = FALSE;
}
}
}
## For reporting
$search = file_get_contents($session_dir . '/Period' . $current_period . '/' . $error_file . '.txt'); //Search for errors within log file
if (strpos($search, "Error") == false && strpos($search, "CMAF check violated") == false){
if(strpos($search, "Warning") === false && strpos($search, "WARNING") === false){
$progress_xml->Results[0]->Period[$current_period]->Adaptation[$current_adaptation_set]->Representation[$current_representation] = "noerror";
$file_location[] = "noerror";
}
else{
$progress_xml->Results[0]->Period[$current_period]->Adaptation[$current_adaptation_set]->Representation[$current_representation] = "warning";
$file_location[] = "warning";
}
}
else{
$progress_xml->Results[0]->Period[$current_period]->Adaptation[$current_adaptation_set]->Representation[$current_representation] = "error";
$file_location[] = "error";
}
$progress_xml->asXml(trim($session_dir . '/' . $progress_report));
return $file_location;
}
function checkCMAFMessages($log_file) {
global $session_dir, $current_period;
$cmaf_cmfc = TRUE;
$cmaf_cmf2 = TRUE;
$logs = file_get_contents($session_dir . '/Period' . $current_period . '/' . $log_file . '.txt');
$logs_array = explode("\n", $logs);
$size = sizeof($logs_array);
for($log_index=0; $log_index<$size; $log_index++) {
$log = $logs_array[$log_index];
if(strpos($log, "CMAF check 'cmf2' violated: Section 7.7") !== FALSE) {
$cmaf_cmf2 = FALSE;
}
elseif(strpos($log, 'CMAF check violated') !== FALSE) {
$cmaf_cmfc = FALSE;
$cmaf_cmf2 = FALSE;
}
}
return [$cmaf_cmfc, $cmaf_cmf2];
}
function determineCMAFMediaProfiles($xml){
global $CMAFMediaProfileAttributesVideo, $CMAFMediaProfileAttributesAudio, $CMAFMediaProfileAttributesSubtitle;
$compatible_brands=$xml->getElementsByTagName("ftyp")->item(0)->getAttribute("compatible_brands");
$handler_type=$xml->getElementsByTagName("hdlr")->item(0)->getAttribute("handler_type");
if($handler_type == 'vide'){
$xml_MPParameters= $CMAFMediaProfileAttributesVideo;
$videSampleDes=$xml->getElementsByTagName("vide_sampledescription")->item(0);
$sdType=$videSampleDes->getAttribute("sdType");
if($sdType=='avc1' || $sdType=='avc3'){
$xml_MPParameters['codec'] = 'AVC';
$nal_unit=$xml->getElementsByTagName("NALUnit");
if($nal_unit->length!=0){
for($nal_count=0;$nal_count<$nal_unit->length;$nal_count++){
if($nal_unit->item($nal_count)->getAttribute("nal_type")=="0x07"){
$sps_unit=$nal_count;
break;
}
}
$avcC = $videSampleDes->getElementsByTagName('avcC')->item(0);
$comment=$nal_unit->item($sps_unit)->getElementsByTagName("comment")->item(0);
$xml_MPParameters['profile']=$avcC->getAttribute("profile");
$xml_MPParameters['level']=(float)($comment->getAttribute("level_idc"))/10;
$xml_MPParameters['width']=$videSampleDes->getAttribute("width");
$xml_MPParameters['height']=$videSampleDes->getAttribute("height");
if($comment->getAttribute("vui_parameters_present_flag")=="0x1"){
if($comment->getAttribute("video_signal_type_present_flag")=="0x1"){
if($comment->getAttribute("colour_description_present_flag")=="0x1"){
$xml_MPParameters['color_primaries']=$comment->getAttribute("colour_primaries");
$xml_MPParameters['transfer_char']=$comment->getAttribute("transfer_characteristics");
$xml_MPParameters['matrix_coeff']=$comment->getAttribute("matrix_coefficients");
}
elseif($comment->getAttribute("colour_description_present_flag")=="0x0"){
$xml_MPParameters['color_primaries']="0x1";
$xml_MPParameters['transfer_char']="0x1";
$xml_MPParameters['matrix_coeff']="0x1";
}
}
if($comment->getAttribute("timing_info_present_flag")=="0x1" ){
$num_units_in_tick=$comment->getAttribute("num_units_in_tick");
$time_scale=$comment->getAttribute("time_scale");
$xml_MPParameters['framerate']=$time_scale/(2*$num_units_in_tick);
}
}
$brand_pos=strpos($compatible_brands,"cfsd") || strpos($compatible_brands,"cfhd");
if($brand_pos!==False){
if(strpos($compatible_brands,"cfsd") !== FALSE)
$xml_MPParameters['brand']="cfsd";
if(strpos($compatible_brands,"cfhd") !== FALSE)
$xml_MPParameters['brand']="cfhd";
}
}
}
else if($sdType=='hev1' || $sdType=='hvc1'){
$xml_MPParameters['codec']="HEVC";
$hvcC=$xml->getElementsByTagName("hvcC");
if($hvcC->length>0){
$hvcC=$xml->getElementsByTagName("hvcC")->item(0);
if(($hvcC->getAttribute("profile_idc")=="1") || ($hvcC->getAttribute("compatibility_flag_1"))=="1")
$profile="Main";
elseif(($hvcC->getAttribute("profile_idc")=="2") || ($hvcC->getAttribute("compatibility_flag_2"))=="1")
$profile="Main10";
else
$profile="Other";
$tier=$hvcC->getAttribute("tier_flag");
$xml_MPParameters['tier']=$tier;//Tier=0 is the main-tier.
$xml_MPParameters['profile']=$profile;
$xml_MPParameters['level']=(float)($hvcC->getAttribute("level_idc"))/30; //HEVC std defines level_idc is 30 times of actual level number.
}
$xml_MPParameters['width']=$videSampleDes->getAttribute("width");
$xml_MPParameters['height']=$videSampleDes->getAttribute("height");
$nal_unit=$xml->getElementsByTagName("NALUnit");
if($nal_unit->length!=0){
for($nal_count=0;$nal_count<$nal_unit->length;$nal_count++){
if($nal_unit->item($nal_count)->getAttribute("nal_unit_type")=="33"){
$sps_unit=$nal_count;
break;
}
}
$sps=$nal_unit->item($sps_unit);
if($sps->getAttribute("vui_parameters_present_flag")=="1"){
if($sps->getAttribute("video_signal_type_present_flag")=="1"){
if($sps->getAttribute("colour_description_present_flag")=="1"){
$xml_MPParameters['color_primaries']=$sps->getAttribute("colour_primaries");
$xml_MPParameters['transfer_char']=$sps->getAttribute("transfer_characteristics");
$xml_MPParameters['matrix_coeff']=$sps->getAttribute("matrix_coeffs");
}
elseif($sps->getAttribute("colour_description_present_flag")=="0"){
$xml_MPParameters['color_primaries']="1";
$xml_MPParameters['transfer_char']="1";
$xml_MPParameters['matrix_coeff']="1";
}
}
if($sps->getAttribute("vui_timing_info_present_flag")=="1" ){
$num_units_in_tick=$sps->getAttribute("vui_num_units_in_tick");
$time_scale=$sps->getAttribute("vui_time_scale");
$xml_MPParameters['framerate']=$time_scale/($num_units_in_tick);
}
}
if(strpos($compatible_brands,"chhd"))
$xml_MPParameters['brand']="chhd";
elseif(strpos($compatible_brands,"chh1"))
$xml_MPParameters['brand']="chh1";
elseif(strpos($compatible_brands,"cud8"))
$xml_MPParameters['brand']="cud8";
elseif(strpos($compatible_brands,"cud1"))
$xml_MPParameters['brand']="cud1";
elseif(strpos($compatible_brands,"chd1"))
$xml_MPParameters['brand']="chd1";
elseif(strpos($compatible_brands,"clg1"))
$xml_MPParameters['brand']="clg1";
}
}
$MP = getVideoTrackMediaProfile($xml_MPParameters);
}
elseif($handler_type=='soun'){
$xml_MPParameters= $CMAFMediaProfileAttributesAudio;
$sounSampleDes=$xml->getElementsByTagName("soun_sampledescription")->item(0);
$sdType=$sounSampleDes->getAttribute("sdType");
if($sdType=="mp4a"){
$xml_MPParameters['codec']="AAC";
$decoderSpecInfo=$sounSampleDes->getElementsByTagName("DecoderSpecificInfo")->item(0);
$xml_MPParameters['sampleRate']=$sounSampleDes->getAttribute('sampleRate');
$xml_MPParameters['profile']=$decoderSpecInfo->getAttribute("audioObjectType");
$xml_MPParameters['channels']=$decoderSpecInfo->getAttribute("channelConfig");
$brand_pos=strpos($compatible_brands,"caaa") || strpos($compatible_brands,"caac");
if($brand_pos!==False){
if(strpos($compatible_brands,"caaa") !== FALSE){
$xml_MPParameters['brand']="caaa";
}
elseif(strpos($compatible_brands,"caac")){
$xml_MPParameters['brand']="caac";
}
}
$levelcomment=$xml->getElementsByTagName("iods_OD");
if($levelcomment->length>0){
$profileLevelString=$levelcomment->getAttribute("Comment");
if($profileLevelString!==NULL){
$profileLevel=str_replace("audio profile/level is ", "", $profileLevelString);
$xml_MPParameters['level']==$profileLevel;
}
}
}
$MP = getAudioTrackMediaProfile($xml_MPParameters);
}
elseif($handler_type=='text'){
$xml_MPParameters= $CMAFMediaProfileAttributesSubtitle;
$textSampleDes=$xml->getElementsByTagName("text_sampledescription")->item(0);
$sdType=$textSampleDes->getAttribute("sdType");
if($sdType=='wvtt'){
$xml_MPParameters['codec']="WebVTT";
$brand_pos=strpos($compatible_brands,"cwvt");
if($brand_pos!==False)
$xml_MPParameters['brand']="cwvt";
}
$MP = getSubtitleTrackMediaProfile($xml_MPParameters);
}
elseif($handler_type=='subt'){
$xml_MPParameters= $CMAFMediaProfileAttributesSubtitle;
$subtSampleDes=$xml->getElementsByTagName("subt_sampledescription")->item(0);
$sdType=$subtSampleDes->getAttribute("sdType");
if($sdType=="stpp"){
$mime=$subtSampleDes->getElementsByTagName("mime");
if($mime->length>0){
$contentType=$mime->getAttribute("content_type");
$subtypePosition=strpos($contentType, "ttml+xml")|| strpos($contentType, "mp4");
$codecPosition=strpos($contentType, "im1t")|| strpos($contentType, "im1i");
$xml_MPParameters['mimeType']=(strpos($contentType, "application")!==False ? "application" : "");
$xml_MPParameters['codec']=($codecPosition!==False ? substr($contentType, $codecPosition, $codecPosition+3) : "");
if(strpos($contentType, "ttml+xml")!==False)
$xml_MPParameters['mimeSubtype']="ttml+xml";
elseif(strpos($contentType, "mp4")!==False)
$xml_MPParameters['mimeSubtype']="mp4";
}
$brand_pos=strpos($compatible_brands,"im1t") || strpos($compatible_brands,"im1i");
if($brand_pos!==False){
if(strpos($compatible_brands,"im1t") !== FALSE)
$xml_MPParameters['brand']="im1t";
if(strpos($compatible_brands,"im1i") !== FALSE)
$xml_MPParameters['brand']="im1i";
}
}
$MP = getSubtitleTrackMediaProfile($xml_MPParameters);
}
return $MP;
}
function getVideoTrackMediaProfile($xml_MPParameters){
$videoMediaProfile="unknown"; $errorMsg="";
if($xml_MPParameters['codec']=="AVC"){
if($xml_MPParameters['profile'] <= 100){
if($xml_MPParameters['level'] <= 3.1){
if(($xml_MPParameters['color_primaries']=== "0x1" || $xml_MPParameters['color_primaries']=== "0x5" || $xml_MPParameters['color_primaries']=== "0x6") &&
($xml_MPParameters['transfer_char'] ==="0x1" || $xml_MPParameters['transfer_char'] ==="0x6") &&
($xml_MPParameters['matrix_coeff'] === "0x1" || $xml_MPParameters['matrix_coeff'] === "0x5" || $xml_MPParameters['matrix_coeff'] === "0x6")){
if($xml_MPParameters['height']<=576 && $xml_MPParameters['width']<=864 && $xml_MPParameters['framerate']<=60){
$videoMediaProfile = "AVC SD";
if($xml_MPParameters['brand'] != 'cfsd'){
// $errorMsg .= "'Warning for CMAF check: Section A.2- For a CMAF Track to comply with one of the media profiles in Table A.1, it SHOULD include the CMAF File Brandin the file its CMAF header', but not included.\n";
}
}
else{
$errorMsg .= "**'CMAF check violated: Section A.2- For a CMAF Track to comply with one of the media profiles in Table A.1, it SHALL not exceed the width, height or frame rate listed in the table, even if the AVC Level would permit higher values', but found width='".$xml_MPParameters['width']."', height='".$xml_MPParameters['height']."' and frame rate='".$xml_MPParameters['framerate']."'.\n";
}
}
else{
$errorMsg .= "**'CMAF check violated: Section A.2- For a CMAF Track to comply with one of the media profiles in Table A.1, it SHALL conform to the colour_primaries, transfer_characteristics and matrix_coefficients values from the options listed in the table', but found colour_primaries='".$xml_MPParameters['color_primaries']."', transfer_characteristics='".$xml_MPParameters['transfer_char']."' and matrix_coefficients='".$xml_MPParameters['matrix_coeff']."'.\n";
}
}
elseif($xml_MPParameters['level'] <= 4.0){
if($xml_MPParameters['color_primaries']=== "0x1" && $xml_MPParameters['transfer_char'] ==="0x1" && $xml_MPParameters['matrix_coeff'] === "0x1"){
if($xml_MPParameters['height']<=1080 && $xml_MPParameters['width']<=1920 && $xml_MPParameters['framerate']<=60){
$videoMediaProfile = "AVC HD";
if($xml_MPParameters['brand'] != 'cfhd'){
//$errorMsg .= "'Warning for CMAF check: Section A.2- For a CMAF Track to comply with one of the media profiles in Table A.1, it SHOULD include the CMAF File Brandin the file its CMAF header', but not included.\n";
}
}
else{
$errorMsg .= "**'CMAF check violated: Section A.2- For a CMAF Track to comply with one of the media profiles in Table A.1, it SHALL not exceed the width, height or frame rate listed in the table, even if the AVC Level would permit higher values', but found width='".$xml_MPParameters['width']."', height='".$xml_MPParameters['height']."' and frame rate='".$xml_MPParameters['framerate']."'\n";
}
}
else{
$errorMsg .= "**'CMAF check violated: Section A.2- For a CMAF Track to comply with one of the media profiles in Table A.1, it SHALL conform to the colour_primaries, transfer_characteristics and matrix_coefficients values from the options listed in the table', but found colour_primaries='".$xml_MPParameters['color_primaries']."', transfer_characteristics='".$xml_MPParameters['transfer_char']."' and matrix_coefficients='".$xml_MPParameters['matrix_coeff']."'.\n";
}
}
elseif($xml_MPParameters['level'] <= 4.2){
if($xml_MPParameters['color_primaries']=== "0x1" && $xml_MPParameters['transfer_char'] ==="0x1" && $xml_MPParameters['matrix_coeff'] === "0x1"){
if($xml_MPParameters['height']<=1080 && $xml_MPParameters['width']<=1920 && $xml_MPParameters['framerate']<=60){
$videoMediaProfile = "AVC HDHF";
if($xml_MPParameters['brand'] != 'chdf'){
//$errorMsg .= "'Warning for CMAF check: Section A.2- For a CMAF Track to comply with one of the media profiles in Table A.1, it SHOULD include the CMAF File Brandin the file its CMAF header', but not included.\n";
}
}
else{
$errorMsg .= "**'CMAF check violated: Section A.2- For a CMAF Track to comply with one of the media profiles in Table A.1, it SHALL not exceed the width, height or frame rate listed in the table, even if the AVC Level would permit higher values', but found width='".$xml_MPParameters['width']."', height='".$xml_MPParameters['height']."' and frame rate='".$xml_MPParameters['framerate']."'.\n";
}
}
else{
$errorMsg .= "**'CMAF check violated: Section A.2- For a CMAF Track to comply with one of the media profiles in Table A.1, it SHALL conform to the colour_primaries, transfer_characteristics and matrix_coefficients values from the options listed in the table', but found colour_primaries='".$xml_MPParameters['color_primaries']."', transfer_characteristics='".$xml_MPParameters['transfer_char']."' and matrix_coefficients='".$xml_MPParameters['matrix_coeff']."'.\n";
}
}
else{
$errorMsg .= "**'CMAF check violated: Section A.2- For a CMAF Track to comply with one of the media profiles in Table A.1, it SHALL not exceed the profile or level listed in the table', but level is exceeded with the value of ".$xml_MPParameters['level']."\n";
}
}
else{
$errorMsg .= "**'CMAF check violated: Section A.2- For a CMAF Track to comply with one of the media profiles in Table A.1, it SHALL not exceed the profile or level listed in the table', but profile is exceeded with the value of ".$xml_MPParameters['profile']."\n";
}
}
elseif($xml_MPParameters['codec']=="HEVC"){
if($xml_MPParameters['tier']==0){
if($xml_MPParameters['profile'] == 'Main'){
if($xml_MPParameters['level'] <= 4.1){
if($xml_MPParameters['color_primaries']=== "0x1" && $xml_MPParameters['transfer_char'] ==="0x1" && $xml_MPParameters['matrix_coeff'] === "0x1"){
if($xml_MPParameters['height'] <= 1080 && $xml_MPParameters['width'] <= 1920 && $xml_MPParameters['framerate'] <= 60){
$videoMediaProfile="HEVC HHD8";
if($xml_MPParameters['brand'] != 'chhd'){
//$errorMsg .= "'Warning for CMAF check: Section B.5- For a CMAF Track to comply with one of the media profiles in Table B.1, it SHOULD include the CMAF File Brand listed in its CMAF header', but not included.\n";
}
}
else{
$errorMsg .= "**'CMAF check violated: Section B.5- For a CMAF Track to comply with one of the media profiles in Table B.1, it SHALL not exceed the width, height or frame rate listed in the table, even if the HEVC Level would permit higher values', but found width='".$xml_MPParameters['width']."', height='".$xml_MPParameters['height']."' and frame rate='".$xml_MPParameters['framerate']."'.\n";
}
}
else{
$errorMsg .= "**'CMAF check violated: Section B.5- For a CMAF Track to comply with one of the media profiles in Table B.1, it SHALL conform to the colour_primaries, transfer_characteristics and matrix_coefficients values from the options listed in the table', but found colour_primaries='".$xml_MPParameters['color_primaries']."', transfer_characteristics='".$xml_MPParameters['transfer_char']."' and matrix_coefficients='".$xml_MPParameters['matrix_coeff']."'.\n";
}
}
elseif($xml_MPParameters['level'] <= 5.0){
if($xml_MPParameters['color_primaries']=== "0x1" && $xml_MPParameters['transfer_char'] ==="0x1" && $xml_MPParameters['matrix_coeff'] === "0x1"){
if($xml_MPParameters['height'] <= 2160 && $xml_MPParameters['width'] <= 3840 && $xml_MPParameters['framerate'] <= 60){
$videoMediaProfile="HEVC UHD8";
if($xml_MPParameters['brand'] != 'cud8'){
//$errorMsg .= "'Warning for CMAF check: Section B.5- For a CMAF Track to comply with one of the media profiles in Table B.1, it SHOULD include the CMAF File Brand listed in its CMAF header', but not included.\n";
}
}
else{
$errorMsg .= "**'CMAF check violated: Section B.5- For a CMAF Track to comply with one of the media profiles in Table B.1, it SHALL not exceed the width, height or frame rate listed in the table, even if the HEVC Level would permit higher values', but found width='".$xml_MPParameters['width']."', height='".$xml_MPParameters['height']."' and frame rate='".$xml_MPParameters['framerate']."'.\n";
}
}
else{
$errorMsg .= "**'CMAF check violated: Section B.5- For a CMAF Track to comply with one of the media profiles in Table B.1, it SHALL conform to the colour_primaries, transfer_characteristics and matrix_coefficients values from the options listed in the table', but found colour_primaries='".$xml_MPParameters['color_primaries']."', transfer_characteristics='".$xml_MPParameters['transfer_char']."' and matrix_coefficients='".$xml_MPParameters['matrix_coeff']."'.\n";
}
}
else{
$errorMsg .= "**'CMAF check violated: Section B.5- For a CMAF Track to comply with one of the media profiles in Table B.1, it SHALL conform to the colour_primaries, transfer_characteristics and matrix_coefficients values from the options listed in the table', but found colour_primaries='".$xml_MPParameters['color_primaries']."', transfer_characteristics='".$xml_MPParameters['transfer_char']."' and matrix_coefficients='".$xml_MPParameters['matrix_coeff']."'.\n";
}
}
elseif($xml_MPParameters['profile'] == 'Main10'){
if($xml_MPParameters['level'] <= 4.1){
if($xml_MPParameters['color_primaries']=== "0x1" && $xml_MPParameters['transfer_char'] ==="0x1" && $xml_MPParameters['matrix_coeff'] === "0x1"){
if($xml_MPParameters['height'] <= 1080 && $xml_MPParameters['width'] <= 1920 && $xml_MPParameters['framerate'] <= 60){
$videoMediaProfile="HEVC HHD10";
if($xml_MPParameters['brand'] != 'chh1'){
//$errorMsg .= "'Warning for CMAF check: Section B.5- For a CMAF Track to comply with one of the media profiles in Table B.1, it SHOULD include the CMAF File Brand listed in its CMAF header', but not included.\n";
}
}
else{
$errorMsg .= "**'CMAF check violated: Section B.5- For a CMAF Track to comply with one of the media profiles in Table B.1, it SHALL not exceed the width, height or frame rate listed in the table, even if the HEVC Level would permit higher values', but found width='".$xml_MPParameters['width']."', height='".$xml_MPParameters['height']."' and frame rate='".$xml_MPParameters['framerate']."'.\n";
}
}
else{
$errorMsg .= "**'CMAF check violated: Section B.5- For a CMAF Track to comply with one of the media profiles in Table B.1, it SHALL conform to the colour_primaries, transfer_characteristics and matrix_coefficients values from the options listed in the table', but found colour_primaries='".$xml_MPParameters['color_primaries']."', transfer_characteristics='".$xml_MPParameters['transfer_char']."' and matrix_coefficients='".$xml_MPParameters['matrix_coeff']."'.\n";
}
}
elseif($xml_MPParameters['level'] <= 5.1){
if(($xml_MPParameters['color_primaries']=== "0x1" || $xml_MPParameters['color_primaries']=== "0x9") &&
($xml_MPParameters['transfer_char'] ==="0x1" || $xml_MPParameters['transfer_char'] ==="0x14" || $xml_MPParameters['transfer_char'] ==="0x15") &&
($xml_MPParameters['matrix_coeff'] === "0x1" || $xml_MPParameters['matrix_coeff'] === "0x9" || $xml_MPParameters['matrix_coeff'] === "0x10")){
if($xml_MPParameters['height'] <= 2160 && $xml_MPParameters['width'] <= 3840 && $xml_MPParameters['framerate'] <= 60){
if($xml_MPParameters['brand'] == 'cud1'){
$videoMediaProfile="HEVC UHD10";
}
elseif($xml_MPParameters['brand'] == 'clg1'){
$videoMediaProfile="HEVC HLG10";
}
else{
$videoMediaProfile="HEVC UHD10, HEVC HLG10";
//$errorMsg .= "'Warning for CMAF check: Section B.5- For a CMAF Track to comply with one of the media profiles in Table B.1, it SHOULD include the CMAF File Brand listed in its CMAF header', but not included.\n";
}
}
else{
$errorMsg .= "**'CMAF check violated: Section B.5- For a CMAF Track to comply with one of the media profiles in Table B.1, it SHALL not exceed the width, height or frame rate listed in the table, even if the HEVC Level would permit higher values', but found width='".$xml_MPParameters['width']."', height='".$xml_MPParameters['height']."' and frame rate='".$xml_MPParameters['framerate']."'.\n";
}
}
elseif($xml_MPParameters['color_primaries']=== "0x9" && $xml_MPParameters['transfer_char'] ==="0x16" &&
($xml_MPParameters['matrix_coeff'] === "0x9" || $xml_MPParameters['matrix_coeff'] === "0x10")){
if($xml_MPParameters['height'] <= 2160 && $xml_MPParameters['width'] <= 3840 && $xml_MPParameters['framerate'] <= 60){
$videoMediaProfile="HEVC HDR10";
if($xml_MPParameters['brand'] != 'chd1'){
//$errorMsg .= "'Warning for CMAF check: Section B.5- For a CMAF Track to comply with one of the media profiles in Table B.1, it SHOULD include the CMAF File Brand listed in its CMAF header', but not included.\n";
}
}
else{
$errorMsg .= "**'CMAF check violated: Section B.5- For a CMAF Track to comply with one of the media profiles in Table B.1, it SHALL not exceed the width, height or frame rate listed in the table, even if the HEVC Level would permit higher values', but found width='".$xml_MPParameters['width']."', height='".$xml_MPParameters['height']."' and frame rate='".$xml_MPParameters['framerate']."'.\n";
}
}
elseif($xml_MPParameters['color_primaries']=== "0x9" &&
($xml_MPParameters['transfer_char'] ==="0x14" || $xml_MPParameters['transfer_char'] ==="0x18") &&
$xml_MPParameters['matrix_coeff'] === "0x9"){
if($xml_MPParameters['height'] <= 2160 && $xml_MPParameters['width'] <= 3840 && $xml_MPParameters['framerate'] <= 60){
$videoMediaProfile="HEVC HLG10";
if($xml_MPParameters['brand'] != 'clg1'){
//$errorMsg .= "'Warning for CMAF check: Section B.5- For a CMAF Track to comply with one of the media profiles in Table B.1, it SHOULD include the CMAF File Brand listed in its CMAF header', but not included.\n";
}
}
else{
$errorMsg .= "**'CMAF check violated: Section B.5- For a CMAF Track to comply with one of the media profiles in Table B.1, it SHALL not exceed the width, height or frame rate listed in the table, even if the HEVC Level would permit higher values', but found width='".$xml_MPParameters['width']."', height='".$xml_MPParameters['height']."' and frame rate='".$xml_MPParameters['framerate']."'.\n";
}
}
else{
$errorMsg .= "**'CMAF check violated: Section B.5- For a CMAF Track to comply with one of the media profiles in Table B.1, it SHALL conform to the colour_primaries, transfer_characteristics and matrix_coefficients values from the options listed in the table', but found colour_primaries='".$xml_MPParameters['color_primaries']."', transfer_characteristics='".$xml_MPParameters['transfer_char']."' and matrix_coefficients='".$xml_MPParameters['matrix_coeff']."'.\n";
}
}
else{
$errorMsg .= "**'CMAF check violated: Section B.5- For a CMAF Track to comply with one of the media profiles in Table B.1, it SHALL not exceed the tier, profile or level listed in the table', but level is exceeded with the value of '".$xml_MPParameters['level']."'.\n";
}
}
else{
$errorMsg .= "**'CMAF check violated: Section B.5- For a CMAF Track to comply with one of the media profiles in Table B.1, it SHALL not exceed the tier, profile or level listed in the table', but profile is exceeded with an unknown value.\n";
}
}
else{
$errorMsg .= "**'CMAF check violated: Section B.5- For a CMAF Track to comply with one of the media profiles in Table B.1, it SHALL not exceed the tier, profile or level listed in the table', but tier is exceeded with the value of '".$xml_MPParameters['tier']."'.\n";
}
}
return [$videoMediaProfile,$errorMsg];
}
function getAudioTrackMediaProfile($xml_MPParameters){
$audioMediaProfile="unknown"; $errorMsg="";
if($xml_MPParameters['codec']=="AAC"){
if(in_array($xml_MPParameters['profile'],array("0x02", "0x05", "0x1d"))){
if($xml_MPParameters['level']!=="" && strpos($xml_MPParameters['level'], "AAC@L2")===FALSE){
$errorMsg .= "**'CMAF check violated: Section 10.4- AAC CMAF media profile SHALL conform to the AAC CMAF track format with the following constraints: Each AAC elementary stream SHALL be encoded using MPEG-4 AAC LC, HE-AAC Level 2, or HE-AACv2 Level 2', but level information is not found or non-conforming.\n";
}
else{
if($xml_MPParameters['channels']=="0x1" || $xml_MPParameters['channels']=="0x2"){
if($xml_MPParameters['sampleRate']<=48000){
if($xml_MPParameters['brand'] == 'caaa'){
$audioMediaProfile = "AAC Adaptive";
}
elseif($xml_MPParameters['brand'] == 'caac'){
$audioMediaProfile = "AAC Core";
}
elseif($xml_MPParameters['brand'] == ''){
$audioMediaProfile = "AAC Core";
//$errorMsg .= "'Warning for CMAF check: Section 10.4- AAC CMAF media profile SHALL conform to the AAC CMAF track format with the following constraints: AAC Core/Adaptive Audio FileTypeBox compatibility brand SHOULD be used to indicare CMAF tracks that conform to this (AAC Core/AAC Adaptive) media profile', but compatibility brand is not found.\n";
}
else{
$errorMsg .= "**'CMAF check violated: Section 10.4- AAC CMAF media profile SHALL conform to the AAC CMAF track format with the following constraints: AAC Core/Adaptive Audio FileTypeBox compatibility brand SHALL be 'caac'/'caaa', respectively', but compatibility brand is found to be '".$xml_MPParameters['brand']."'.\n";
}
}
else{
$errorMsg .= "**'CMAF check violated: Section 10.4/10.5- AAC CMAF media profile SHALL conform to the AAC CMAF track format with the following constraints: AAC Core elementary streams SHALL not exceed 48kHz sampling rate', but sampling rate is exceeded with the value of '".$xml_MPParameters['sampleRate']."'.\n";
}
}
else{
$errorMsg .= "**'CMAF check violated: Section 10.4- AAC CMAF media profile SHALL conform to the AAC CMAF track format with the following constraints: AAC Core CMAF tracks SHALL not exceed two audio channels', but number of channels is exceeded with the value of '".$xml_MPParameters['channels']."'.\n";
}
}
}
else{
$errorMsg .= "**'CMAF check violated: Section 10.4- AAC CMAF media profile SHALL conform to the AAC CMAF track format with the following constraints: Each AAC elementary stream SHALL be encoded using MPEG-4 AAC LC, HE-AAC Level 2, or HE-AACv2 Level 2', but non-conforming profile is found.\n";
}
}
return [$audioMediaProfile,$errorMsg];
}
function getSubtitleTrackMediaProfile($xml_MPParameters){
$subtitleMediaProfile="unknown"; $errorMsg="";
if($xml_MPParameters['codec']=="WebVTT"){
if($xml_MPParameters['brand'] == 'cwvt'){
$subtitleMediaProfile = 'WebVTT';
}
}
elseif($xml_MPParameters['mimeType']=="application" && ($xml_MPParameters['mimeSubtype']=="ttml+xml" || $xml_MPParameters['mimeSubtype']=="mp4")){
if($xml_MPParameters['codec']=="im1t"){
$subtitleMediaProfile="TTML_IMSC1_Text";
}
elseif($xml_MPParameters['codec']=="im1i"){
$subtitleMediaProfile="TTML_IMSC1_Image";
}
}
return [$subtitleMediaProfile,$errorMsg];
}
function CMAFFlags(){
global $additional_flags;
$additional_flags .= ' -cmaf';
}