Skip to content

Commit bd2f4e9

Browse files
committed
Add NIT support
1 parent 18011e1 commit bd2f4e9

20 files changed

+961
-70
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ It tries to comply with "Digital Video Broadcasting (DVB) - Specification for Se
88
The initial goal is to provide parsing for following tables :
99
* PAT: done
1010
* PMT: mostly
11-
* NIT: not yet planned
11+
* NIT: mostly (missing some descriptors)
1212
* BAT: not yet planned
1313
* SDT: not yet planned
1414
* EIT: mostly (missing some descriptors)
@@ -22,7 +22,7 @@ The initial goal is to provide parsing for following tables :
2222

2323
# Requirements
2424

25-
* PHP7+
25+
* PHP7+ x64
2626
* Composer
2727

2828
Those requirements can be installed on ubuntu 16.04:
@@ -34,6 +34,7 @@ Or on windows:
3434
1. http://php.net/downloads.php
3535
2. https://getcomposer.org/download/
3636

37+
NB: **32bit** will partly work but **should be avoided** because some structures are unsigned 32bit and PHP will store them as signed 32bit. See: http://php.net/manual/en/function.unpack.php#refsect1-function.unpack-notes
3738

3839
# Installation
3940

examples/print-all.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@
4646
$dvbPsiParser->on('error', function ($e) {
4747
echo "PSI parser error: {$e->getMessage()}\n";
4848
});
49-
$dvbPsiParser->on('pat', function ($pat) use ($dvbPsiParser) {
49+
$dvbPsiParser->on('pat', function ($pat) {
5050
echo "PAT\r\n{$pat}\r\n";
5151
});
52+
$dvbPsiParser->on('nit', function ($nit) {
53+
echo "NIT\r\n{$nit}\r\n";
54+
});
5255
$dvbPsiParser->on('tdt', function ($tdt) {
5356
echo "TDT: {$tdt}\n";
5457
});
@@ -59,8 +62,11 @@
5962
echo "PMT\r\n{$pmt}\n";
6063
});
6164

62-
// Prepare mpegts parser
63-
$mpegTsParser = \PhpBg\MpegTs\ParserFactory::createForDvbPsi();
65+
// Create MPEG TS parser and filter all requested PIDs
66+
$mpegTsParser = new \PhpBg\MpegTs\Parser();
67+
foreach($dvbPsiParser->getRegisteredPids() as $pid) {
68+
$mpegTsParser->addPidFilter(new \PhpBg\MpegTs\Pid($pid));
69+
}
6470
$mpegTsParser->on('error', function ($e) {
6571
echo "TS parser error: {$e->getMessage()}\n";
6672
});

examples/print-with-context.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,11 @@
7171
$streamContext->addPmt($pmt);
7272
});
7373

74-
// Prepare mpegts parser
75-
$mpegTsParser = \PhpBg\MpegTs\ParserFactory::createForDvbPsi();
74+
// Create MPEG TS parser and filter all requested PIDs
75+
$mpegTsParser = new \PhpBg\MpegTs\Parser();
76+
foreach($dvbPsiParser->getRegisteredPids() as $pid) {
77+
$mpegTsParser->addPidFilter(new \PhpBg\MpegTs\Pid($pid));
78+
}
7679
$mpegTsParser->on('error', function ($e) {
7780
echo "TS parser error: {$e->getMessage()}\n";
7881
});

src/Descriptors/ExtendedEvent.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ class ExtendedEvent
4242
public $items = [];
4343
public $text;
4444

45+
/**
46+
* ExtendedEvent constructor.
47+
* @param $data
48+
* @throws \PhpBg\DvbPsi\Exception
49+
*/
4550
public function __construct($data)
4651
{
4752
$pointer = 0;

src/Descriptors/Identifier.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@
3434
*/
3535
class Identifier extends Enum
3636
{
37+
const NETWORK_NAME_DESCRIPTOR = 0x40;
38+
const SERVICE_LIST_DESCRIPTOR = 0x41;
3739
const STUFFING_DESCRIPTOR = 0x42;
3840
const LINKAGE_DESCRIPTOR = 0x4a;
3941
const SHORT_EVENT_DESCRIPTOR = 0x4d;
4042
const EXTENDED_EVENT_DESCRIPTOR = 0x4e;
4143
const TIME_SHIFTED_EVENT_DESCRIPTOR = 0x4f;
4244
const COMPONENT_DESCRIPTOR = 0x50;
45+
const TERRESTRIAL_DELIVERY_SYSTEM_DESCRIPTOR = 0x5a;
4346
const CA_IDENTIFIER_DESCRIPTOR = 0x53;
4447
const CONTENT_DESCRIPTOR = 0x54;
4548
const PARENTAL_RATING_DESCRIPTOR = 0x55;

src/Descriptors/NetworkName.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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\TableParsers\Text;
30+
31+
/**
32+
* Class NetworkName
33+
* @see Final draft ETSI EN 300 468 V1.15.1 (2016-03), 6.2.27 Network name descriptor
34+
*/
35+
class NetworkName
36+
{
37+
use Text;
38+
39+
/**
40+
* A string of char fields specify the name of the delivery system about which the NIT informs
41+
* @var string
42+
*/
43+
public $networkName;
44+
45+
/**
46+
* NetworkName constructor.
47+
* @param $data
48+
* @throws \PhpBg\DvbPsi\Exception
49+
*/
50+
public function __construct($data)
51+
{
52+
$this->networkName = $this->toUtf8String($data);
53+
}
54+
55+
public function __toString()
56+
{
57+
return "Network name: $this->networkName";
58+
}
59+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
/**
30+
* Class PrivateDataSpecifier
31+
* @see Final draft ETSI EN 300 468 V1.15.1 (2016-03), 6.2.31 Private data specifier descriptor
32+
*/
33+
class PrivateDataSpecifier
34+
{
35+
/**
36+
* Value of the private data specifier
37+
* Name of the organisation which is responsible for delivering private data in SI streams, e.g “ACME, Inc.”
38+
* @see https://www.dvbservices.com/identifiers/private_data_spec_id
39+
* @var int
40+
*/
41+
public $private_data_specifier;
42+
43+
public function __construct($data)
44+
{
45+
$this->private_data_specifier = unpack('N', $data)[1];
46+
}
47+
48+
public function __toString()
49+
{
50+
return sprintf("PrivateDataSpecifier: 0x%x\n", $this->private_data_specifier);
51+
}
52+
}

src/Descriptors/ServiceList.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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.35 Service list descriptor
34+
*/
35+
class ServiceList
36+
{
37+
/**
38+
* @var array <service id> => <service type>
39+
*/
40+
public $services;
41+
42+
/**
43+
* ServiceList constructor.
44+
* @param $data
45+
* @throws \PhpBg\DvbPsi\Exception
46+
*/
47+
public function __construct($data)
48+
{
49+
$pointer = 0;
50+
$len = strlen($data);
51+
while ($pointer < $len) {
52+
$serviceId = unpack('n', substr($data, $pointer, 2))[1];
53+
$pointer += 2;
54+
$serviceType = unpack('C', $data[$pointer])[1];
55+
$pointer += 1;
56+
$this->services[$serviceId] = new ServiceType($serviceType);
57+
}
58+
}
59+
60+
public function __toString()
61+
{
62+
$msg = "Services:\n";
63+
foreach ($this->services as $serviceId => $serviceType) {
64+
$msg .= sprintf("Service ID: %d (0x%x) => %s\n", $serviceId, $serviceId, $serviceType->getKey());
65+
}
66+
return $msg;
67+
}
68+
}

src/Descriptors/ShortEvent.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ class ShortEvent
4040
public $eventName;
4141
public $text;
4242

43+
/**
44+
* ShortEvent constructor.
45+
* @param $data
46+
* @throws \PhpBg\DvbPsi\Exception
47+
*/
4348
public function __construct($data)
4449
{
4550
$pointer = 0;

0 commit comments

Comments
 (0)