Skip to content
28 changes: 27 additions & 1 deletion src/Context/StreamContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Evenement\EventEmitter;
use PhpBg\DvbPsi\Tables\Pat;
use PhpBg\DvbPsi\Tables\Pmt;
use PhpBg\DvbPsi\Tables\Sdt;

class StreamContext extends EventEmitter
{
Expand All @@ -49,6 +50,12 @@ class StreamContext extends EventEmitter
*/
public $pmts;

/**
* @var Sdt[]
*/
public $sdts;


public function addPat(Pat $pat)
{
if (!isset($this->pat) || $this->pat->version < $pat->version || ($this->pat->version !== 0 && $pat->version === 0)) {
Expand All @@ -59,11 +66,23 @@ public function addPat(Pat $pat)
}
}

public function addSdt(Sdt $sdt)
{
if (!isset($this->sdts[$sdt->transportStreamId])
|| $this->sdts[$sdt->transportStreamId]->versionNumber < $sdt->versionNumber
|| ($this->sdts[$sdt->transportStreamId]->versionNumber !== 0 && $sdt->versionNumber === 0)
) {
$this->sdts[$sdt->transportStreamId] = $sdt;
$this->emit('sdt-update', [$sdt]);
}

}

public function addPmt(Pmt $pmt)
{
if (!isset($this->pmts[$pmt->programNumber]) || $this->pmts[$pmt->programNumber]->version < $pmt->version || ($this->pmts[$pmt->programNumber]->version !== 0 && $pmt->version === 0)) {
$this->pmts[$pmt->programNumber] = $pmt;
$this->emit('pmt-update');
$this->emit('pmt-update', [$pmt]);

$programsCount = count($this->pat->programs);
if (isset($this->pat->programs[0])) {
Expand Down Expand Up @@ -95,6 +114,13 @@ public function __toString()
$str .= "$pmt\n";
}
}

if (!empty($this->sdts)) {
$str .= "SDTs\n";
foreach ($this->sdts as $sdt) {
$str .= "$sdt\n";
}
}
}

if (isset($this->tdtTimestamp)) {
Expand Down
1 change: 1 addition & 0 deletions src/Descriptors/Identifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Identifier extends Enum
const NETWORK_NAME_DESCRIPTOR = 0x40;
const SERVICE_LIST_DESCRIPTOR = 0x41;
const STUFFING_DESCRIPTOR = 0x42;
const SERVICE_DESCRIPTOR = 0x48;
const LINKAGE_DESCRIPTOR = 0x4a;
const SHORT_EVENT_DESCRIPTOR = 0x4d;
const EXTENDED_EVENT_DESCRIPTOR = 0x4e;
Expand Down
78 changes: 78 additions & 0 deletions src/Descriptors/ServiceDescriptor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

/**
* MIT License
*
* Copyright (c) 2018 Samuel CHEMLA
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

namespace PhpBg\DvbPsi\Descriptors;

use PhpBg\DvbPsi\Descriptors\Values\ServiceType;

/**
* Class ServiceList
* @see Final draft ETSI EN 300 468 V1.15.1 (2016-03), 6.2.33 Service descriptor
*/
class ServiceDescriptor
{

/**
* This is an 8-bit field specifying the type of the service. The assignment of service_type value for a
* service is described in annex I.
*/
public $serviceType;
public $serviceProviderName;
public $serviceName;

/**
* ServiceDescriptor constructor.
* @param $data
* @throws \PhpBg\DvbPsi\Exception
*/
public function __construct($data)
{
$pointer = 0;
$serviceType = unpack('C', $data[ $pointer])[1];
$this->serviceType = new ServiceType($serviceType);

$pointer += 1;
$serviceProviderNameLength = unpack('C', $data[$pointer])[1];

$pointer += 1;
$this->serviceProviderName = substr($data, $pointer, $serviceProviderNameLength);

$pointer += $serviceProviderNameLength;
$serviceNameLength = unpack('C', $data[$pointer])[1];

$pointer += 1;
$this->serviceName = substr($data, $pointer, $serviceNameLength);
}

public function __toString()
{
$msg = sprintf("Service type: %s (0x%x)\n", $this->serviceType->getKey(), $this->serviceType->getValue() );
$msg .= "Service provider name: $this->serviceProviderName\n";
$msg .= "Service name: $this->serviceName\n";

return $msg;
}
}
100 changes: 100 additions & 0 deletions src/Descriptors/Values/EsType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php

/**
* MIT License
*
* Copyright (c) 2018 Samuel CHEMLA
Copy link
Owner Author

@phpbg phpbg Apr 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to put your name on the files you created if you want to

*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

namespace PhpBg\DvbPsi\Descriptors\Values;

use MyCLabs\Enum\Enum;
use PhpBg\DvbPsi\Exception;

/**
* Class EsType
* @see https://en.wikipedia.org/wiki/Program-specific_information#Elementary_stream_types
*/
class EsType
{
const ES_TYPES = [
1 =>'ISO/IEC 11172-2 (MPEG-1 video)in a packetized stream',
2 =>'ITU-T Rec. H.262 and ISO/IEC 13818-2 (MPEG-2 higher rate interlaced video) in a packetized stream',
3 =>'ISO/IEC 11172-3 (MPEG-1 audio) in a packetized stream',
4 =>'ISO/IEC 13818-3 (MPEG-2 halved sample rate audio) in a packetized stream',
5 =>'ITU-T Rec. H.222 and ISO/IEC 13818-1 (MPEG-2 tabled data) privately defined',
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)',
7 =>'ISO/IEC 13522 (MHEG) in a packetized stream',
8 =>'ITU-T Rec. H.222 and ISO/IEC 13818-1 DSM CC in a packetized stream',
9 =>'ITU-T Rec. H.222 and ISO/IEC 13818-1/11172-1 auxiliary data in a packetized stream',
10 =>'ISO/IEC 13818-6 DSM CC multiprotocol encapsulation ',
11 =>'ISO/IEC 13818-6 DSM CC U-N messages',
12 =>'ISO/IEC 13818-6 DSM CC stream descriptors',
13 =>'ISO/IEC 13818-6 DSM CC tabled data',
14 =>'ISO/IEC 13818-1 auxiliary data in a packetized stream',
15 =>'ISO/IEC 13818-7 ADTS AAC (MPEG-2 lower bit-rate audio) in a packetized stream',
16 =>'ISO/IEC 14496-2 (MPEG-4 H.263 based video) in a packetized stream',
17 =>'ISO/IEC 14496-3 (MPEG-4 LOAS multi-format framed audio) in a packetized stream',
18 =>'ISO/IEC 14496-1 (MPEG-4 FlexMux) in a packetized stream',
19 =>'ISO/IEC 14496-1 (MPEG-4 FlexMux) in ISO/IEC 14496 tables',
20 =>'ISO/IEC 13818-6 DSM CC synchronized download protocol',
21 =>'Packetized metadata',
22 =>'Sectioned metadata',
23 =>'ISO/IEC 13818-6 DSM CC Data Carousel metadata',
24 =>'ISO/IEC 13818-6 DSM CC Object Carousel metadata',
25 =>'ISO/IEC 13818-6 Synchronized Download Protocol metadata',
26 =>'ISO/IEC 13818-11 IPMP',
27 =>'ITU-T Rec. H.264 and ISO/IEC 14496-10 (lower bit-rate video) in a packetized stream',
28 =>'ISO/IEC 14496-3 (MPEG-4 raw audio) in a packetized stream',
29 =>'ISO/IEC 14496-17 (MPEG-4 text) in a packetized stream',
30 =>'ISO/IEC 23002-3 (MPEG-4 auxiliary video) in a packetized stream',
31 =>'ISO/IEC 14496-10 SVC (MPEG-4 AVC sub-bitstream) in a packetized stream',
32 =>'ISO/IEC 14496-10 MVC (MPEG-4 AVC sub-bitstream) in a packetized stream',
33 =>'ITU-T Rec. T.800 and ISO/IEC 15444 (JPEG 2000 video) in a packetized stream',
36 =>'ITU-T Rec. H.265 and ISO/IEC 23008-2 (Ultra HD video) in a packetized stream',
66 =>'Chinese Video Standard in a packetized stream',
127 =>'ISO/IEC 13818-11 IPMP (DRM) in a packetized stream',
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',
129 =>'Dolby Digital (AC-3) up to six channel audio for ATSC and Blu-ray in a packetized stream',
130 =>'SCTE subtitle or DTS 6 channel audio for Blu-ray in a packetized stream',
131 =>'Dolby TrueHD lossless audio for Blu-ray in a packetized stream',
132 =>'Dolby Digital Plus (enhanced AC-3) up to 16 channel audio for Blu-ray in a packetized stream',
133 =>'DTS 8 channel audio for Blu-ray in a packetized stream',
134 =>'SCTE-35[5] digital program insertion cue message or DTS 8 channel lossless audio for Blu-ray in a packetized stream',
135 =>'Dolby Digital Plus (enhanced AC-3) up to 16 channel audio for ATSC in a packetized stream',
144 =>'Blu-ray Presentation Graphic Stream (subtitling) in a packetized stream',
145 =>'ATSC DSM CC Network Resources table',
192 =>'DigiCipher II text in a packetized stream',
193 =>'Dolby Digital (AC-3) up to six channel audio with AES-128-CBC data encryption in a packetized stream',
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',
207 =>'ISO/IEC 13818-7 ADTS AAC with AES-128-CBC frame encryption in a packetized stream',
209 =>'BBC Dirac (Ultra HD video) in a packetized stream',
210 =>'Audio Video Standard AVS2 (Ultra HD video) in a packetized stream',
211 =>'Audio Video Standard AVS3 Audio in a packetized stream',
212 =>'Audio Video Standard AVS3 Video (Ultra HD video) in a packetized stream',
219 =>'ITU-T Rec. H.264 and ISO/IEC 14496-10 with AES-128-CBC slice encryption in a packetized stream',
234 =>'Microsoft Windows Media Video 9 (lower bit-rate video) in a packetized stream',
];

public static function desc ($type) {
return self::ES_TYPES[$type]??'Unknown';
}
}
98 changes: 98 additions & 0 deletions src/Descriptors/Values/ProgramEsDescriptorTag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

/**
* MIT License
*
* Copyright (c) 2018 Samuel CHEMLA
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

namespace PhpBg\DvbPsi\Descriptors\Values;

use MyCLabs\Enum\Enum;
use PhpBg\DvbPsi\Exception;

/**
* Class EsType
* @see https://en.wikipedia.org/wiki/Program-specific_information#Elementary_stream_types
*/
class ProgramEsDescriptorTag
{
const TAG = [
2 =>'Video stream header parameters for ITU-T Rec. H.262, ISO/IEC 13818-2 and ISO/IEC 11172-2',
3 =>'Audio stream header parameters for ISO/IEC 13818-3 and ISO/IEC 11172-3',
4 =>'Hierarchy for stream selection',
5 =>'Registration of private formats',
6 =>'Data stream alignment for packetized video and audio sync point',
7 =>'Target background grid defines total display area size',
8 =>'Video Window defines position in display area',
9 =>'Conditional access system and EMM/ECM PID',
10 =>'ISO 639 language and audio type',
11 =>'System clock external reference',
12 =>'Multiplex buffer utilization bounds',
13 =>'Copyright identification system and reference',
14 =>'Maximum bit rate',
15 =>'Private data indicator',
16 =>'Smoothing buffer',
17 =>'STD video buffer leak control',
18 =>'IBP video I-frame indicator',
19 =>'ISO/IEC13818-6 DSM CC carousel identifier',
20 =>'ISO/IEC13818-6 DSM CC association tag',
21 =>'ISO/IEC13818-6 DSM CC deferred association tag',
22 =>'ISO/IEC13818-6 DSM CC Reserved.',
23 =>'DSM CC NPT reference',
24 =>'DSM CC NPT endpoint',
25 =>'DSM CC stream mode',
26 =>'DSM CC stream event',
27 =>'Video stream header parameters for ISO/IEC 14496-2 (MPEG-4 H.263 based)',
28 =>'Audio stream header parameters for ISO/IEC 14496-3 (MPEG-4 LOAS multi-format framed)',
29 =>'IOD parameters for ISO/IEC 14496-1',
30 =>'SL parameters for ISO/IEC 14496-1',
31 =>'FMC parameters for ISO/IEC 14496-1',
32 =>'External ES identifier for ISO/IEC 14496-1',
33 =>'MuxCode for ISO/IEC 14496-1',
34 =>'FMX Buffer Size for ISO/IEC 14496-1',
35 =>'Multiplex Buffer for ISO/IEC 14496-1',
36 =>'Content labeling for ISO/IEC 14496-1',
37 =>'Metadata pointer',
38 =>'Metadata',
39 =>'Metadata STD',
40 =>'Video stream header parameters for ITU-T Rec. H.264 and ISO/IEC 14496-10',
41 =>'ISO/IEC 13818-11 IPMP (DRM)',
42 =>'Timing and HRD for ITU-T Rec. H.264 and ISO/IEC 14496-10',
43 =>'Audio stream header parameters for ISO/IEC 13818-7 ADTS AAC',
44 =>'FlexMux Timing for ISO/IEC 14496-1',
45 =>'Text stream header parameters for ISO/IEC 14496',
46 =>'Audio extension stream header parameters for ISO/IEC 14496-3 (MPEG-4 LOAS multi-format framed)',
47 =>'Video auxiliary stream header parameters',
48 =>'Video scalable stream header parameters',
49 =>'Video multi stream header parameters',
50 =>'Video stream header parameters for ITU-T Rec. T.800 and ISO/IEC 15444 (JPEG 2000)',
51 =>'Video multi operation point stream header parameters',
52 =>'Video stereoscopic (3D) stream header parameters for ITU-T Rec. H.262, ISO/IEC 13818-2 and ISO/IEC 11172-2',
53 =>'Program stereoscopic (3D) information',
54 =>'Video stereoscopic (3D) information',
160 =>'VideoLAN FourCC, video size and codec initialization data',
];

public static function desc ($tag) {
return self::TAG[$tag]??'Unknown';
}
}
2 changes: 1 addition & 1 deletion src/Descriptors/Values/ServiceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ public function __construct(int $value)
if ($value < 0 || $value > 0xff) {
throw new Exception("Invalid service type value: $value");
}
$this->value = $value;
parent::__construct($value);
}
}
4 changes: 4 additions & 0 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
* The `eit` event will be emitted when an EIT table is decoded
* The event will receive a single argument: PhpBg\DvbPsi\Tables\Eit instance
*
* sdt event:
* The `sdt` event will be emitted when an SDT table is decoded
* The event will receive a single argument: PhpBg\DvbPsi\Tables\Sdt instance
*
* parserAdd event:
* The `parserAdd` will be emitted when a parser is added
*
Expand Down
2 changes: 2 additions & 0 deletions src/ParserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use PhpBg\DvbPsi\TableParsers\Eit;
use PhpBg\DvbPsi\TableParsers\Nit;
use PhpBg\DvbPsi\TableParsers\Pat;
use PhpBg\DvbPsi\TableParsers\Sdt;
use PhpBg\DvbPsi\TableParsers\Tdt;

class ParserFactory
Expand All @@ -44,6 +45,7 @@ public static function create(): Parser
$parser->registerTableParser(new Nit());
$parser->registerTableParser(new Tdt());
$parser->registerTableParser(new Eit());
$parser->registerTableParser(new Sdt());
return $parser;
}
}
Loading