ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
AVCSequenceParameterSetReader.php
Go to the documentation of this file.
1 <?php
2 
4 
6 
9 // available at http://getid3.sourceforge.net //
10 // or http://www.getid3.org //
11 // //
12 // AVCSequenceParameterSetReader //
13 // by Seth Kaufman <seth@whirl-i-gig.com> //
14 // //
16 // //
17 // dependencies: Module Flv //
18 // ///
20 
31 {
32  public $sps;
33  public $start = 0;
34  public $currentBytes = 0;
35  public $currentBits = 0;
36  public $width;
37  public $height;
38 
41  const H264_PROFILE_MAIN = 77;
43  const H264_PROFILE_HIGH = 100;
44  const H264_PROFILE_HIGH10 = 110;
45  const H264_PROFILE_HIGH422 = 122;
46  const H264_PROFILE_HIGH444 = 144;
48 
53  public function __construct($sps)
54  {
55  $this->sps = $sps;
56  }
57 
61  public function readData()
62  {
63  $this->skipBits(8);
64  $this->skipBits(8);
65  $profile = $this->getBits(8); // read profile
66  $this->skipBits(16);
67  $this->expGolombUe(); // read sps id
68  if (in_array($profile,
69  array(self::H264_PROFILE_HIGH, self::H264_PROFILE_HIGH10, self::H264_PROFILE_HIGH422, self::H264_PROFILE_HIGH444, self::H264_PROFILE_HIGH444_PREDICTIVE))) {
70  if ($this->expGolombUe() == 3) {
71  $this->skipBits(1);
72  }
73  $this->expGolombUe();
74  $this->expGolombUe();
75  $this->skipBits(1);
76  if ($this->getBit()) {
77  for ($i = 0; $i < 8; $i++) {
78  if ($this->getBit()) {
79  $size = $i < 6 ? 16 : 64;
80  $lastScale = 8;
81  $nextScale = 8;
82  for ($j = 0; $j < $size; $j++) {
83  if ($nextScale != 0) {
84  $deltaScale = $this->expGolombUe();
85  $nextScale = ($lastScale + $deltaScale + 256) % 256;
86  }
87  if ($nextScale != 0) {
88  $lastScale = $nextScale;
89  }
90  }
91  }
92  }
93  }
94  }
95  $this->expGolombUe();
96  $pocType = $this->expGolombUe();
97  if ($pocType == 0) {
98  $this->expGolombUe();
99  } elseif ($pocType == 1) {
100  $this->skipBits(1);
101  $this->expGolombSe();
102  $this->expGolombSe();
103  $pocCycleLength = $this->expGolombUe();
104  for ($i = 0; $i < $pocCycleLength; $i++) {
105  $this->expGolombSe();
106  }
107  }
108  $this->expGolombUe();
109  $this->skipBits(1);
110  $this->width = ($this->expGolombUe() + 1) * 16;
111  $heightMap = $this->expGolombUe() + 1;
112  $this->height = (2 - $this->getBit()) * $heightMap * 16;
113  }
114 
119  public function skipBits($bits)
120  {
121  $newBits = $this->currentBits + $bits;
122  $this->currentBytes += (int) floor($newBits / 8);
123  $this->currentBits = $newBits % 8;
124  }
125 
130  public function getBit()
131  {
132  $result = (Helper::BigEndian2Int(substr($this->sps,
133  $this->currentBytes,
134  1)) >> (7 - $this->currentBits)) & 0x01;
135  $this->skipBits(1);
136 
137  return $result;
138  }
139 
145  public function getBits($bits)
146  {
147  $result = 0;
148  for ($i = 0; $i < $bits; $i++) {
149  $result = ($result << 1) + $this->getBit();
150  }
151 
152  return $result;
153  }
154 
159  public function expGolombUe()
160  {
161  $significantBits = 0;
162  $bit = $this->getBit();
163  while ($bit == 0) {
164  $significantBits++;
165  $bit = $this->getBit();
166 
167  if ($significantBits > 31) {
168  // something is broken, this is an emergency escape to prevent infinite loops
169  return 0;
170  }
171  }
172 
173  return (1 << $significantBits) + $this->getBits($significantBits) - 1;
174  }
175 
180  public function expGolombSe()
181  {
182  $result = $this->expGolombUe();
183  if (($result & 0x01) == 0) {
184  return -($result >> 1);
185  } else {
186  return ($result + 1) >> 1;
187  }
188  }
189 
194  public function getWidth()
195  {
196  return $this->width;
197  }
198 
203  public function getHeight()
204  {
205  return $this->height;
206  }
207 }
$size
Definition: RandomTest.php:79
$result
Create styles array
The data for the language used.
static BigEndian2Int($byteword, $synchsafe=false, $signed=false)
Definition: Helper.php:374