ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Ts.php
Go to the documentation of this file.
1 <?php
2 
4 
7 
10 // available at http://getid3.sourceforge.net //
11 // or http://www.getid3.org //
13 // See readme.txt for more details //
15 // //
16 // module.audio-video.ts.php //
17 // module for analyzing MPEG Transport Stream (.ts) files //
18 // dependencies: NONE //
19 // ///
21 
29 class Ts extends BaseHandler
30 {
31 
36  public function analyze()
37  {
38  $info = &$this->getid3->info;
39 
40  fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
41  $TSheader = fread($this->getid3->fp, 19);
42  $magic = "\x47";
43  if (substr($TSheader, 0, 1) != $magic) {
44  $info['error'][] = 'Expecting "'.Helper::PrintHexBytes($magic).'" at '.$info['avdataoffset'].', found '.Helper::PrintHexBytes(substr($TSheader, 0, 1)).' instead.';
45 
46  return false;
47  }
48  $info['fileformat'] = 'ts';
49 
50  // http://en.wikipedia.org/wiki/.ts
51 
52  $offset = 0;
53  $info['ts']['packet']['sync'] = Helper::BigEndian2Int(substr($TSheader, $offset, 1)); $offset += 1;
54  $pid_flags_raw = Helper::BigEndian2Int(substr($TSheader, $offset, 2)); $offset += 2;
55  $SAC_raw = Helper::BigEndian2Int(substr($TSheader, $offset, 1)); $offset += 1;
56  $info['ts']['packet']['flags']['transport_error_indicator'] = (bool) ($pid_flags_raw & 0x8000); // Set by demodulator if can't correct errors in the stream, to tell the demultiplexer that the packet has an uncorrectable error
57  $info['ts']['packet']['flags']['payload_unit_start_indicator'] = (bool) ($pid_flags_raw & 0x4000); // 1 means start of PES data or PSI otherwise zero only.
58  $info['ts']['packet']['flags']['transport_high_priority'] = (bool) ($pid_flags_raw & 0x2000); // 1 means higher priority than other packets with the same PID.
59  $info['ts']['packet']['packet_id'] = ($pid_flags_raw & 0x1FFF) >> 0;
60 
61  $info['ts']['packet']['raw']['scrambling_control'] = ($SAC_raw & 0xC0) >> 6;
62  $info['ts']['packet']['flags']['adaption_field_exists'] = (bool) ($SAC_raw & 0x20);
63  $info['ts']['packet']['flags']['payload_exists'] = (bool) ($SAC_raw & 0x10);
64  $info['ts']['packet']['continuity_counter'] = ($SAC_raw & 0x0F) >> 0; // Incremented only when a payload is present
65  $info['ts']['packet']['scrambling_control'] = $this->TSscramblingControlLookup($info['ts']['packet']['raw']['scrambling_control']);
66 
67  if ($info['ts']['packet']['flags']['adaption_field_exists']) {
68  $AdaptionField_raw = Helper::BigEndian2Int(substr($TSheader, $offset, 2)); $offset += 2;
69  $info['ts']['packet']['adaption']['field_length'] = ($AdaptionField_raw & 0xFF00) >> 8; // Number of bytes in the adaptation field immediately following this byte
70  $info['ts']['packet']['adaption']['flags']['discontinuity'] = (bool) ($AdaptionField_raw & 0x0080); // Set to 1 if current TS packet is in a discontinuity state with respect to either the continuity counter or the program clock reference
71  $info['ts']['packet']['adaption']['flags']['random_access'] = (bool) ($AdaptionField_raw & 0x0040); // Set to 1 if the PES packet in this TS packet starts a video/audio sequence
72  $info['ts']['packet']['adaption']['flags']['high_priority'] = (bool) ($AdaptionField_raw & 0x0020); // 1 = higher priority
73  $info['ts']['packet']['adaption']['flags']['pcr'] = (bool) ($AdaptionField_raw & 0x0010); // 1 means adaptation field does contain a PCR field
74  $info['ts']['packet']['adaption']['flags']['opcr'] = (bool) ($AdaptionField_raw & 0x0008); // 1 means adaptation field does contain an OPCR field
75  $info['ts']['packet']['adaption']['flags']['splice_point'] = (bool) ($AdaptionField_raw & 0x0004); // 1 means presence of splice countdown field in adaptation field
76  $info['ts']['packet']['adaption']['flags']['private_data'] = (bool) ($AdaptionField_raw & 0x0002); // 1 means presence of private data bytes in adaptation field
77  $info['ts']['packet']['adaption']['flags']['extension'] = (bool) ($AdaptionField_raw & 0x0001); // 1 means presence of adaptation field extension
78  if ($info['ts']['packet']['adaption']['flags']['pcr']) {
79  $info['ts']['packet']['adaption']['raw']['pcr'] = Helper::BigEndian2Int(substr($TSheader, $offset, 6)); $offset += 6;
80  }
81  if ($info['ts']['packet']['adaption']['flags']['opcr']) {
82  $info['ts']['packet']['adaption']['raw']['opcr'] = Helper::BigEndian2Int(substr($TSheader, $offset, 6)); $offset += 6;
83  }
84  }
85 
86  $info['error'][] = 'MPEG Transport Stream (.ts) parsing not enabled in this version of GetId3Core() ['.$this->getid3->version().']';
87 
88  return false;
89 
90  }
91 
97  public function TSscramblingControlLookup($raw)
98  {
99  $TSscramblingControlLookup = array(0x00=>'not scrambled', 0x01=>'reserved', 0x02=>'scrambled, even key', 0x03=>'scrambled, odd key');
100 
101  return (isset($TSscramblingControlLookup[$raw]) ? $TSscramblingControlLookup[$raw] : 'invalid');
102  }
103 }
static PrintHexBytes($string, $hex=true, $spaces=true, $htmlencoding='UTF-8')
Definition: Helper.php:36
GetId3() by James Heinrich info@getid3.org //.
Definition: BaseHandler.php:25
GetId3() by James Heinrich info@getid3.org //.
Definition: Ts.php:29
fseek($bytes, $whence=SEEK_SET)
$info
Definition: example_052.php:80
TSscramblingControlLookup($raw)
Definition: Ts.php:97
Create styles array
The data for the language used.
static BigEndian2Int($byteword, $synchsafe=false, $signed=false)
Definition: Helper.php:374