@@ -1150,7 +1150,7 @@ func newDescriptorTeletext(i *astikit.BytesIterator, offsetEnd int) (d *Descript
11501150 }
11511151
11521152 // Type
1153- itm .Type = uint8 (b ) >> 3
1153+ itm .Type = uint8 (b >> 3 )
11541154
11551155 // Magazine
11561156 itm .Magazine = uint8 (b & 0x7 )
@@ -1443,6 +1443,9 @@ func parseDescriptors(i *astikit.BytesIterator) (o []*Descriptor, err error) {
14431443}
14441444
14451445func calcDescriptorUserDefinedLength (d []byte ) uint8 {
1446+ if d == nil {
1447+ return 0
1448+ }
14461449 return uint8 (len (d ))
14471450}
14481451
@@ -1455,6 +1458,9 @@ func writeDescriptorUserDefined(w *astikit.BitsWriter, d []byte) error {
14551458}
14561459
14571460func calcDescriptorAC3Length (d * DescriptorAC3 ) uint8 {
1461+ if d == nil {
1462+ return 0
1463+ }
14581464 ret := 1 // flags
14591465
14601466 if d .HasComponentType {
@@ -1502,6 +1508,9 @@ func writeDescriptorAC3(w *astikit.BitsWriter, d *DescriptorAC3) error {
15021508}
15031509
15041510func calcDescriptorAVCVideoLength (d * DescriptorAVCVideo ) uint8 {
1511+ if d == nil {
1512+ return 0
1513+ }
15051514 return 4
15061515}
15071516
@@ -1525,6 +1534,9 @@ func writeDescriptorAVCVideo(w *astikit.BitsWriter, d *DescriptorAVCVideo) error
15251534}
15261535
15271536func calcDescriptorComponentLength (d * DescriptorComponent ) uint8 {
1537+ if d == nil {
1538+ return 0
1539+ }
15281540 return uint8 (6 + len (d .Text ))
15291541}
15301542
@@ -1545,6 +1557,9 @@ func writeDescriptorComponent(w *astikit.BitsWriter, d *DescriptorComponent) err
15451557}
15461558
15471559func calcDescriptorContentLength (d * DescriptorContent ) uint8 {
1560+ if d == nil {
1561+ return 0
1562+ }
15481563 return uint8 (2 * len (d .Items ))
15491564}
15501565
@@ -1561,6 +1576,9 @@ func writeDescriptorContent(w *astikit.BitsWriter, d *DescriptorContent) error {
15611576}
15621577
15631578func calcDescriptorDataStreamAlignmentLength (d * DescriptorDataStreamAlignment ) uint8 {
1579+ if d == nil {
1580+ return 0
1581+ }
15641582 return 1
15651583}
15661584
@@ -1573,6 +1591,9 @@ func writeDescriptorDataStreamAlignment(w *astikit.BitsWriter, d *DescriptorData
15731591}
15741592
15751593func calcDescriptorEnhancedAC3Length (d * DescriptorEnhancedAC3 ) uint8 {
1594+ if d == nil {
1595+ return 0
1596+ }
15761597 ret := 1 // flags
15771598
15781599 if d .HasComponentType {
@@ -1642,6 +1663,9 @@ func writeDescriptorEnhancedAC3(w *astikit.BitsWriter, d *DescriptorEnhancedAC3)
16421663}
16431664
16441665func calcDescriptorExtendedEventLength (d * DescriptorExtendedEvent ) (descriptorLength , lengthOfItems uint8 ) {
1666+ if d == nil {
1667+ return 0 , 0
1668+ }
16451669 ret := 1 + 3 + 1 // numbers, language and items length
16461670
16471671 itemsRet := 0
@@ -1687,6 +1711,9 @@ func writeDescriptorExtendedEvent(w *astikit.BitsWriter, d *DescriptorExtendedEv
16871711}
16881712
16891713func calcDescriptorExtensionSupplementaryAudioLength (d * DescriptorExtensionSupplementaryAudio ) int {
1714+ if d == nil {
1715+ return 0
1716+ }
16901717 ret := 1
16911718 if d .HasLanguageCode {
16921719 ret += 3
@@ -1696,6 +1723,9 @@ func calcDescriptorExtensionSupplementaryAudioLength(d *DescriptorExtensionSuppl
16961723}
16971724
16981725func calcDescriptorExtensionLength (d * DescriptorExtension ) uint8 {
1726+ if d == nil {
1727+ return 0
1728+ }
16991729 ret := 1 // tag
17001730
17011731 switch d .Tag {
@@ -1748,6 +1778,9 @@ func writeDescriptorExtension(w *astikit.BitsWriter, d *DescriptorExtension) err
17481778}
17491779
17501780func calcDescriptorISO639LanguageAndAudioTypeLength (d * DescriptorISO639LanguageAndAudioType ) uint8 {
1781+ if d == nil {
1782+ return 0
1783+ }
17511784 return 3 + 1 // language code + type
17521785}
17531786
@@ -1761,6 +1794,9 @@ func writeDescriptorISO639LanguageAndAudioType(w *astikit.BitsWriter, d *Descrip
17611794}
17621795
17631796func calcDescriptorLocalTimeOffsetLength (d * DescriptorLocalTimeOffset ) uint8 {
1797+ if d == nil {
1798+ return 0
1799+ }
17641800 return uint8 (13 * len (d .Items ))
17651801}
17661802
@@ -1789,6 +1825,9 @@ func writeDescriptorLocalTimeOffset(w *astikit.BitsWriter, d *DescriptorLocalTim
17891825}
17901826
17911827func calcDescriptorMaximumBitrateLength (d * DescriptorMaximumBitrate ) uint8 {
1828+ if d == nil {
1829+ return 0
1830+ }
17921831 return 3
17931832}
17941833
@@ -1802,6 +1841,9 @@ func writeDescriptorMaximumBitrate(w *astikit.BitsWriter, d *DescriptorMaximumBi
18021841}
18031842
18041843func calcDescriptorNetworkNameLength (d * DescriptorNetworkName ) uint8 {
1844+ if d == nil {
1845+ return 0
1846+ }
18051847 return uint8 (len (d .Name ))
18061848}
18071849
@@ -1814,6 +1856,9 @@ func writeDescriptorNetworkName(w *astikit.BitsWriter, d *DescriptorNetworkName)
18141856}
18151857
18161858func calcDescriptorParentalRatingLength (d * DescriptorParentalRating ) uint8 {
1859+ if d == nil {
1860+ return 0
1861+ }
18171862 return uint8 (4 * len (d .Items ))
18181863}
18191864
@@ -1829,6 +1874,9 @@ func writeDescriptorParentalRating(w *astikit.BitsWriter, d *DescriptorParentalR
18291874}
18301875
18311876func calcDescriptorPrivateDataIndicatorLength (d * DescriptorPrivateDataIndicator ) uint8 {
1877+ if d == nil {
1878+ return 0
1879+ }
18321880 return 4
18331881}
18341882
@@ -1841,6 +1889,9 @@ func writeDescriptorPrivateDataIndicator(w *astikit.BitsWriter, d *DescriptorPri
18411889}
18421890
18431891func calcDescriptorPrivateDataSpecifierLength (d * DescriptorPrivateDataSpecifier ) uint8 {
1892+ if d == nil {
1893+ return 0
1894+ }
18441895 return 4
18451896}
18461897
@@ -1853,6 +1904,9 @@ func writeDescriptorPrivateDataSpecifier(w *astikit.BitsWriter, d *DescriptorPri
18531904}
18541905
18551906func calcDescriptorRegistrationLength (d * DescriptorRegistration ) uint8 {
1907+ if d == nil {
1908+ return 0
1909+ }
18561910 return uint8 (4 + len (d .AdditionalIdentificationInfo ))
18571911}
18581912
@@ -1866,6 +1920,9 @@ func writeDescriptorRegistration(w *astikit.BitsWriter, d *DescriptorRegistratio
18661920}
18671921
18681922func calcDescriptorServiceLength (d * DescriptorService ) uint8 {
1923+ if d == nil {
1924+ return 0
1925+ }
18691926 ret := 3 // type and lengths
18701927 ret += len (d .Name )
18711928 ret += len (d .Provider )
@@ -1885,6 +1942,9 @@ func writeDescriptorService(w *astikit.BitsWriter, d *DescriptorService) error {
18851942}
18861943
18871944func calcDescriptorShortEventLength (d * DescriptorShortEvent ) uint8 {
1945+ if d == nil {
1946+ return 0
1947+ }
18881948 ret := 3 + 1 + 1 // language code and lengths
18891949 ret += len (d .EventName )
18901950 ret += len (d .Text )
@@ -1906,6 +1966,9 @@ func writeDescriptorShortEvent(w *astikit.BitsWriter, d *DescriptorShortEvent) e
19061966}
19071967
19081968func calcDescriptorStreamIdentifierLength (d * DescriptorStreamIdentifier ) uint8 {
1969+ if d == nil {
1970+ return 0
1971+ }
19091972 return 1
19101973}
19111974
@@ -1918,6 +1981,9 @@ func writeDescriptorStreamIdentifier(w *astikit.BitsWriter, d *DescriptorStreamI
19181981}
19191982
19201983func calcDescriptorSubtitlingLength (d * DescriptorSubtitling ) uint8 {
1984+ if d == nil {
1985+ return 0
1986+ }
19211987 return uint8 (8 * len (d .Items ))
19221988}
19231989
@@ -1935,6 +2001,9 @@ func writeDescriptorSubtitling(w *astikit.BitsWriter, d *DescriptorSubtitling) e
19352001}
19362002
19372003func calcDescriptorTeletextLength (d * DescriptorTeletext ) uint8 {
2004+ if d == nil {
2005+ return 0
2006+ }
19382007 return uint8 (5 * len (d .Items ))
19392008}
19402009
@@ -1953,6 +2022,9 @@ func writeDescriptorTeletext(w *astikit.BitsWriter, d *DescriptorTeletext) error
19532022}
19542023
19552024func calcDescriptorVBIDataLength (d * DescriptorVBIData ) uint8 {
2025+ if d == nil {
2026+ return 0
2027+ }
19562028 return uint8 (3 * len (d .Services ))
19572029}
19582030
@@ -1986,6 +2058,9 @@ func writeDescriptorVBIData(w *astikit.BitsWriter, d *DescriptorVBIData) error {
19862058}
19872059
19882060func calcDescriptorUnknownLength (d * DescriptorUnknown ) uint8 {
2061+ if d == nil {
2062+ return 0
2063+ }
19892064 return uint8 (len (d .Content ))
19902065}
19912066
@@ -2002,10 +2077,6 @@ func calcDescriptorLength(d *Descriptor) uint8 {
20022077 return calcDescriptorUserDefinedLength (d .UserDefined )
20032078 }
20042079
2005- if d .Length == 0 {
2006- return 0
2007- }
2008-
20092080 switch d .Tag {
20102081 case DescriptorTagAC3 :
20112082 return calcDescriptorAC3Length (d .AC3 )
0 commit comments