Skip to content

Commit 61fc1e1

Browse files
phpbgtolich
andauthored
Add SDT (#2)
* Init * SDT parser * SDT identifier * SDT parser improve * SDT parser improve * SDT parser improve * SDT parser improve * SDT parser improve * SDT parser improve * SDT parser improve * SDT parser improve * PMT parser improve * Parse descriptors improve * Parse descriptors improve * SDT parser improve. Add test for SDT * register SDT parser * fixed event name sdt-update, added sdt output to StreamContext toString * Passing an object in an update event --------- Co-authored-by: tolich <[email protected]>
1 parent b35564b commit 61fc1e1

22 files changed

+929
-9
lines changed

src/Context/StreamContext.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use Evenement\EventEmitter;
3131
use PhpBg\DvbPsi\Tables\Pat;
3232
use PhpBg\DvbPsi\Tables\Pmt;
33+
use PhpBg\DvbPsi\Tables\Sdt;
3334

3435
class StreamContext extends EventEmitter
3536
{
@@ -49,6 +50,12 @@ class StreamContext extends EventEmitter
4950
*/
5051
public $pmts;
5152

53+
/**
54+
* @var Sdt[]
55+
*/
56+
public $sdts;
57+
58+
5259
public function addPat(Pat $pat)
5360
{
5461
if (!isset($this->pat) || $this->pat->version < $pat->version || ($this->pat->version !== 0 && $pat->version === 0)) {
@@ -59,11 +66,23 @@ public function addPat(Pat $pat)
5966
}
6067
}
6168

69+
public function addSdt(Sdt $sdt)
70+
{
71+
if (!isset($this->sdts[$sdt->transportStreamId])
72+
|| $this->sdts[$sdt->transportStreamId]->versionNumber < $sdt->versionNumber
73+
|| ($this->sdts[$sdt->transportStreamId]->versionNumber !== 0 && $sdt->versionNumber === 0)
74+
) {
75+
$this->sdts[$sdt->transportStreamId] = $sdt;
76+
$this->emit('sdt-update', [$sdt]);
77+
}
78+
79+
}
80+
6281
public function addPmt(Pmt $pmt)
6382
{
6483
if (!isset($this->pmts[$pmt->programNumber]) || $this->pmts[$pmt->programNumber]->version < $pmt->version || ($this->pmts[$pmt->programNumber]->version !== 0 && $pmt->version === 0)) {
6584
$this->pmts[$pmt->programNumber] = $pmt;
66-
$this->emit('pmt-update');
85+
$this->emit('pmt-update', [$pmt]);
6786

6887
$programsCount = count($this->pat->programs);
6988
if (isset($this->pat->programs[0])) {
@@ -95,6 +114,13 @@ public function __toString()
95114
$str .= "$pmt\n";
96115
}
97116
}
117+
118+
if (!empty($this->sdts)) {
119+
$str .= "SDTs\n";
120+
foreach ($this->sdts as $sdt) {
121+
$str .= "$sdt\n";
122+
}
123+
}
98124
}
99125

100126
if (isset($this->tdtTimestamp)) {

src/Descriptors/Identifier.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Identifier extends Enum
3737
const NETWORK_NAME_DESCRIPTOR = 0x40;
3838
const SERVICE_LIST_DESCRIPTOR = 0x41;
3939
const STUFFING_DESCRIPTOR = 0x42;
40+
const SERVICE_DESCRIPTOR = 0x48;
4041
const LINKAGE_DESCRIPTOR = 0x4a;
4142
const SHORT_EVENT_DESCRIPTOR = 0x4d;
4243
const EXTENDED_EVENT_DESCRIPTOR = 0x4e;
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
/**
4+
* MIT License
5+
*
6+
* Copyright (c) 2018 Samuel CHEMLA
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in all
16+
* copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+
* SOFTWARE.
25+
*/
26+
27+
namespace PhpBg\DvbPsi\Descriptors;
28+
29+
use PhpBg\DvbPsi\Descriptors\Values\ServiceType;
30+
31+
/**
32+
* Class ServiceList
33+
* @see Final draft ETSI EN 300 468 V1.15.1 (2016-03), 6.2.33 Service descriptor
34+
*/
35+
class ServiceDescriptor
36+
{
37+
38+
/**
39+
* This is an 8-bit field specifying the type of the service. The assignment of service_type value for a
40+
* service is described in annex I.
41+
*/
42+
public $serviceType;
43+
public $serviceProviderName;
44+
public $serviceName;
45+
46+
/**
47+
* ServiceDescriptor constructor.
48+
* @param $data
49+
* @throws \PhpBg\DvbPsi\Exception
50+
*/
51+
public function __construct($data)
52+
{
53+
$pointer = 0;
54+
$serviceType = unpack('C', $data[ $pointer])[1];
55+
$this->serviceType = new ServiceType($serviceType);
56+
57+
$pointer += 1;
58+
$serviceProviderNameLength = unpack('C', $data[$pointer])[1];
59+
60+
$pointer += 1;
61+
$this->serviceProviderName = substr($data, $pointer, $serviceProviderNameLength);
62+
63+
$pointer += $serviceProviderNameLength;
64+
$serviceNameLength = unpack('C', $data[$pointer])[1];
65+
66+
$pointer += 1;
67+
$this->serviceName = substr($data, $pointer, $serviceNameLength);
68+
}
69+
70+
public function __toString()
71+
{
72+
$msg = sprintf("Service type: %s (0x%x)\n", $this->serviceType->getKey(), $this->serviceType->getValue() );
73+
$msg .= "Service provider name: $this->serviceProviderName\n";
74+
$msg .= "Service name: $this->serviceName\n";
75+
76+
return $msg;
77+
}
78+
}

src/Descriptors/Values/EsType.php

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
3+
/**
4+
* MIT License
5+
*
6+
* Copyright (c) 2018 Samuel CHEMLA
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in all
16+
* copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+
* SOFTWARE.
25+
*/
26+
27+
namespace PhpBg\DvbPsi\Descriptors\Values;
28+
29+
use MyCLabs\Enum\Enum;
30+
use PhpBg\DvbPsi\Exception;
31+
32+
/**
33+
* Class EsType
34+
* @see https://en.wikipedia.org/wiki/Program-specific_information#Elementary_stream_types
35+
*/
36+
class EsType
37+
{
38+
const ES_TYPES = [
39+
1 =>'ISO/IEC 11172-2 (MPEG-1 video)in a packetized stream',
40+
2 =>'ITU-T Rec. H.262 and ISO/IEC 13818-2 (MPEG-2 higher rate interlaced video) in a packetized stream',
41+
3 =>'ISO/IEC 11172-3 (MPEG-1 audio) in a packetized stream',
42+
4 =>'ISO/IEC 13818-3 (MPEG-2 halved sample rate audio) in a packetized stream',
43+
5 =>'ITU-T Rec. H.222 and ISO/IEC 13818-1 (MPEG-2 tabled data) privately defined',
44+
6 =>'ITU-T Rec. H.222 and ISO/IEC 13818-1 (MPEG-2 packetized data) privately defined (i.e., DVB subtitles/VBI and AC-3)',
45+
7 =>'ISO/IEC 13522 (MHEG) in a packetized stream',
46+
8 =>'ITU-T Rec. H.222 and ISO/IEC 13818-1 DSM CC in a packetized stream',
47+
9 =>'ITU-T Rec. H.222 and ISO/IEC 13818-1/11172-1 auxiliary data in a packetized stream',
48+
10 =>'ISO/IEC 13818-6 DSM CC multiprotocol encapsulation ',
49+
11 =>'ISO/IEC 13818-6 DSM CC U-N messages',
50+
12 =>'ISO/IEC 13818-6 DSM CC stream descriptors',
51+
13 =>'ISO/IEC 13818-6 DSM CC tabled data',
52+
14 =>'ISO/IEC 13818-1 auxiliary data in a packetized stream',
53+
15 =>'ISO/IEC 13818-7 ADTS AAC (MPEG-2 lower bit-rate audio) in a packetized stream',
54+
16 =>'ISO/IEC 14496-2 (MPEG-4 H.263 based video) in a packetized stream',
55+
17 =>'ISO/IEC 14496-3 (MPEG-4 LOAS multi-format framed audio) in a packetized stream',
56+
18 =>'ISO/IEC 14496-1 (MPEG-4 FlexMux) in a packetized stream',
57+
19 =>'ISO/IEC 14496-1 (MPEG-4 FlexMux) in ISO/IEC 14496 tables',
58+
20 =>'ISO/IEC 13818-6 DSM CC synchronized download protocol',
59+
21 =>'Packetized metadata',
60+
22 =>'Sectioned metadata',
61+
23 =>'ISO/IEC 13818-6 DSM CC Data Carousel metadata',
62+
24 =>'ISO/IEC 13818-6 DSM CC Object Carousel metadata',
63+
25 =>'ISO/IEC 13818-6 Synchronized Download Protocol metadata',
64+
26 =>'ISO/IEC 13818-11 IPMP',
65+
27 =>'ITU-T Rec. H.264 and ISO/IEC 14496-10 (lower bit-rate video) in a packetized stream',
66+
28 =>'ISO/IEC 14496-3 (MPEG-4 raw audio) in a packetized stream',
67+
29 =>'ISO/IEC 14496-17 (MPEG-4 text) in a packetized stream',
68+
30 =>'ISO/IEC 23002-3 (MPEG-4 auxiliary video) in a packetized stream',
69+
31 =>'ISO/IEC 14496-10 SVC (MPEG-4 AVC sub-bitstream) in a packetized stream',
70+
32 =>'ISO/IEC 14496-10 MVC (MPEG-4 AVC sub-bitstream) in a packetized stream',
71+
33 =>'ITU-T Rec. T.800 and ISO/IEC 15444 (JPEG 2000 video) in a packetized stream',
72+
36 =>'ITU-T Rec. H.265 and ISO/IEC 23008-2 (Ultra HD video) in a packetized stream',
73+
66 =>'Chinese Video Standard in a packetized stream',
74+
127 =>'ISO/IEC 13818-11 IPMP (DRM) in a packetized stream',
75+
128 =>'ITU-T Rec. H.262 and ISO/IEC 13818-2 with DES-64-CBC encryption for DigiCipher II or PCM audio for Blu-ray in a packetized stream',
76+
129 =>'Dolby Digital (AC-3) up to six channel audio for ATSC and Blu-ray in a packetized stream',
77+
130 =>'SCTE subtitle or DTS 6 channel audio for Blu-ray in a packetized stream',
78+
131 =>'Dolby TrueHD lossless audio for Blu-ray in a packetized stream',
79+
132 =>'Dolby Digital Plus (enhanced AC-3) up to 16 channel audio for Blu-ray in a packetized stream',
80+
133 =>'DTS 8 channel audio for Blu-ray in a packetized stream',
81+
134 =>'SCTE-35[5] digital program insertion cue message or DTS 8 channel lossless audio for Blu-ray in a packetized stream',
82+
135 =>'Dolby Digital Plus (enhanced AC-3) up to 16 channel audio for ATSC in a packetized stream',
83+
144 =>'Blu-ray Presentation Graphic Stream (subtitling) in a packetized stream',
84+
145 =>'ATSC DSM CC Network Resources table',
85+
192 =>'DigiCipher II text in a packetized stream',
86+
193 =>'Dolby Digital (AC-3) up to six channel audio with AES-128-CBC data encryption in a packetized stream',
87+
194 =>'ATSC DSM CC synchronous data or Dolby Digital Plus up to 16 channel audio with AES-128-CBC data encryption in a packetized stream',
88+
207 =>'ISO/IEC 13818-7 ADTS AAC with AES-128-CBC frame encryption in a packetized stream',
89+
209 =>'BBC Dirac (Ultra HD video) in a packetized stream',
90+
210 =>'Audio Video Standard AVS2 (Ultra HD video) in a packetized stream',
91+
211 =>'Audio Video Standard AVS3 Audio in a packetized stream',
92+
212 =>'Audio Video Standard AVS3 Video (Ultra HD video) in a packetized stream',
93+
219 =>'ITU-T Rec. H.264 and ISO/IEC 14496-10 with AES-128-CBC slice encryption in a packetized stream',
94+
234 =>'Microsoft Windows Media Video 9 (lower bit-rate video) in a packetized stream',
95+
];
96+
97+
public static function desc ($type) {
98+
return self::ES_TYPES[$type]??'Unknown';
99+
}
100+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
/**
4+
* MIT License
5+
*
6+
* Copyright (c) 2018 Samuel CHEMLA
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in all
16+
* copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+
* SOFTWARE.
25+
*/
26+
27+
namespace PhpBg\DvbPsi\Descriptors\Values;
28+
29+
use MyCLabs\Enum\Enum;
30+
use PhpBg\DvbPsi\Exception;
31+
32+
/**
33+
* Class EsType
34+
* @see https://en.wikipedia.org/wiki/Program-specific_information#Elementary_stream_types
35+
*/
36+
class ProgramEsDescriptorTag
37+
{
38+
const TAG = [
39+
2 =>'Video stream header parameters for ITU-T Rec. H.262, ISO/IEC 13818-2 and ISO/IEC 11172-2',
40+
3 =>'Audio stream header parameters for ISO/IEC 13818-3 and ISO/IEC 11172-3',
41+
4 =>'Hierarchy for stream selection',
42+
5 =>'Registration of private formats',
43+
6 =>'Data stream alignment for packetized video and audio sync point',
44+
7 =>'Target background grid defines total display area size',
45+
8 =>'Video Window defines position in display area',
46+
9 =>'Conditional access system and EMM/ECM PID',
47+
10 =>'ISO 639 language and audio type',
48+
11 =>'System clock external reference',
49+
12 =>'Multiplex buffer utilization bounds',
50+
13 =>'Copyright identification system and reference',
51+
14 =>'Maximum bit rate',
52+
15 =>'Private data indicator',
53+
16 =>'Smoothing buffer',
54+
17 =>'STD video buffer leak control',
55+
18 =>'IBP video I-frame indicator',
56+
19 =>'ISO/IEC13818-6 DSM CC carousel identifier',
57+
20 =>'ISO/IEC13818-6 DSM CC association tag',
58+
21 =>'ISO/IEC13818-6 DSM CC deferred association tag',
59+
22 =>'ISO/IEC13818-6 DSM CC Reserved.',
60+
23 =>'DSM CC NPT reference',
61+
24 =>'DSM CC NPT endpoint',
62+
25 =>'DSM CC stream mode',
63+
26 =>'DSM CC stream event',
64+
27 =>'Video stream header parameters for ISO/IEC 14496-2 (MPEG-4 H.263 based)',
65+
28 =>'Audio stream header parameters for ISO/IEC 14496-3 (MPEG-4 LOAS multi-format framed)',
66+
29 =>'IOD parameters for ISO/IEC 14496-1',
67+
30 =>'SL parameters for ISO/IEC 14496-1',
68+
31 =>'FMC parameters for ISO/IEC 14496-1',
69+
32 =>'External ES identifier for ISO/IEC 14496-1',
70+
33 =>'MuxCode for ISO/IEC 14496-1',
71+
34 =>'FMX Buffer Size for ISO/IEC 14496-1',
72+
35 =>'Multiplex Buffer for ISO/IEC 14496-1',
73+
36 =>'Content labeling for ISO/IEC 14496-1',
74+
37 =>'Metadata pointer',
75+
38 =>'Metadata',
76+
39 =>'Metadata STD',
77+
40 =>'Video stream header parameters for ITU-T Rec. H.264 and ISO/IEC 14496-10',
78+
41 =>'ISO/IEC 13818-11 IPMP (DRM)',
79+
42 =>'Timing and HRD for ITU-T Rec. H.264 and ISO/IEC 14496-10',
80+
43 =>'Audio stream header parameters for ISO/IEC 13818-7 ADTS AAC',
81+
44 =>'FlexMux Timing for ISO/IEC 14496-1',
82+
45 =>'Text stream header parameters for ISO/IEC 14496',
83+
46 =>'Audio extension stream header parameters for ISO/IEC 14496-3 (MPEG-4 LOAS multi-format framed)',
84+
47 =>'Video auxiliary stream header parameters',
85+
48 =>'Video scalable stream header parameters',
86+
49 =>'Video multi stream header parameters',
87+
50 =>'Video stream header parameters for ITU-T Rec. T.800 and ISO/IEC 15444 (JPEG 2000)',
88+
51 =>'Video multi operation point stream header parameters',
89+
52 =>'Video stereoscopic (3D) stream header parameters for ITU-T Rec. H.262, ISO/IEC 13818-2 and ISO/IEC 11172-2',
90+
53 =>'Program stereoscopic (3D) information',
91+
54 =>'Video stereoscopic (3D) information',
92+
160 =>'VideoLAN FourCC, video size and codec initialization data',
93+
];
94+
95+
public static function desc ($tag) {
96+
return self::TAG[$tag]??'Unknown';
97+
}
98+
}

src/Descriptors/Values/ServiceType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ public function __construct(int $value)
7272
if ($value < 0 || $value > 0xff) {
7373
throw new Exception("Invalid service type value: $value");
7474
}
75-
$this->value = $value;
75+
parent::__construct($value);
7676
}
7777
}

src/Parser.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@
5656
* The `eit` event will be emitted when an EIT table is decoded
5757
* The event will receive a single argument: PhpBg\DvbPsi\Tables\Eit instance
5858
*
59+
* sdt event:
60+
* The `sdt` event will be emitted when an SDT table is decoded
61+
* The event will receive a single argument: PhpBg\DvbPsi\Tables\Sdt instance
62+
*
5963
* parserAdd event:
6064
* The `parserAdd` will be emitted when a parser is added
6165
*

src/ParserFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use PhpBg\DvbPsi\TableParsers\Eit;
3030
use PhpBg\DvbPsi\TableParsers\Nit;
3131
use PhpBg\DvbPsi\TableParsers\Pat;
32+
use PhpBg\DvbPsi\TableParsers\Sdt;
3233
use PhpBg\DvbPsi\TableParsers\Tdt;
3334

3435
class ParserFactory
@@ -44,6 +45,7 @@ public static function create(): Parser
4445
$parser->registerTableParser(new Nit());
4546
$parser->registerTableParser(new Tdt());
4647
$parser->registerTableParser(new Eit());
48+
$parser->registerTableParser(new Sdt());
4749
return $parser;
4850
}
4951
}

0 commit comments

Comments
 (0)