private void ProcessFileForServiceNames(string sourceFileName) { const int readFragmentSize = 1316; var stream = File.Open(sourceFileName, FileMode.Open); if (stream == null) { Assert.Fail("Unable to read test file: " + sourceFileName); } var data = new byte[readFragmentSize]; var readCount = stream.Read(data, 0, readFragmentSize); var decoder = new TsDecoder.TransportStream.TsDecoder(); decoder.TableChangeDetected += Decoder_TableChangeDetected; while (readCount > 0) { try { if (readCount < readFragmentSize) { var tmpArr = new byte[readCount]; Buffer.BlockCopy(data, 0, tmpArr, 0, readCount); data = new byte[readCount]; Buffer.BlockCopy(tmpArr, 0, data, 0, readCount); } decoder.AddData(data); if (decoder.ServiceDescriptionTable?.ItemsIncomplete == false) { Console.WriteLine($"Terminating read at position {stream.Position} after detection of embedded service names completed."); break; } if (stream.Position < stream.Length) { readCount = stream.Read(data, 0, readFragmentSize); } else { Assert.Fail("Reached end of file without completing SDT scan"); } } catch (Exception ex) { Assert.Fail($"Problem reading file: {ex.Message}"); } } }
private static void ProcessFileForDescriptors(string sourceFileName) { const int readFragmentSize = 1316; var stream = File.Open(sourceFileName, FileMode.Open); if (stream == null) { Assert.Fail("Unable to read test file: " + sourceFileName); } var data = new byte[readFragmentSize]; var readCount = stream.Read(data, 0, readFragmentSize); var decoder = new TsDecoder.TransportStream.TsDecoder(); while (readCount > 0) { try { if (readCount < readFragmentSize) { var tmpArr = new byte[readCount]; Buffer.BlockCopy(data, 0, tmpArr, 0, readCount); data = new byte[readCount]; Buffer.BlockCopy(tmpArr, 0, data, 0, readCount); } decoder.AddData(data); if (decoder.ServiceDescriptionTable != null && decoder.ServiceDescriptionTable.ItemsIncomplete != true) { if (decoder.ServiceDescriptionTable.TableId != 0x42) { continue; } foreach (var program in decoder.ProgramMapTables) { Console.WriteLine(decoder.GetServiceDescriptorForProgramNumber(program.ProgramNumber).ServiceName); foreach (var esStream in program.EsStreams) { Console.WriteLine($"\t0x{esStream.ElementaryPid:X4} - {DescriptorDictionaries.ShortElementaryStreamTypeDescriptions[esStream.StreamType]}"); //only check type 6 privately defined streams if (esStream.StreamType != 6) { continue; } foreach (var desc in esStream.Descriptors) { if (desc is ExtendedEventDescriptor) { var extDesc = desc as ExtendedEventDescriptor; Console.WriteLine($"{extDesc.TextChar.Value}"); } else { Console.WriteLine($"\t {desc}"); } } } } return; } if (stream.Position < stream.Length) { readCount = stream.Read(data, 0, readFragmentSize); } else { Assert.Fail("Reached end of file without completing descriptor scan"); } } catch (Exception ex) { Assert.Fail($"Problem reading file: {ex.Message}"); } } }
private void ProcessFileForStreams(string sourceFileName) { const int readFragmentSize = 1316; var stream = File.Open(sourceFileName, FileMode.Open); if (stream == null) { Assert.Fail("Unable to read test file: " + sourceFileName); } var data = new byte[readFragmentSize]; var readCount = stream.Read(data, 0, readFragmentSize); var decoder = new TsDecoder.TransportStream.TsDecoder(); while (readCount > 0) { try { if (readCount < readFragmentSize) { var tmpArr = new byte[readCount]; Buffer.BlockCopy(data, 0, tmpArr, 0, readCount); data = new byte[readCount]; Buffer.BlockCopy(tmpArr, 0, data, 0, readCount); } decoder.AddData(data); if (decoder.ProgramMapTables != null && decoder.ProgramMapTables.Count > 0) { foreach (var esStream in decoder.ProgramMapTables[0].EsStreams) { Console.WriteLine($"0x{esStream.ElementaryPid:X4} - {DescriptorDictionaries.ShortElementaryStreamTypeDescriptions[esStream.StreamType]}"); //only check type 6 privately defined streams if (esStream.StreamType != 6) { continue; } var lang = esStream.Descriptors.OfType <Iso639LanguageDescriptor>().FirstOrDefault()?.Language; if (esStream.Descriptors.OfType <RegistrationDescriptor>().FirstOrDefault() != null) { var regDesc = esStream.Descriptors.OfType <RegistrationDescriptor>().First(); var msg = $"0x{esStream.ElementaryPid:X4} - {regDesc.Name} Descriptor: {regDesc.Organization}"; Console.WriteLine(msg); } if (esStream.Descriptors.OfType <Ac3Descriptor>().FirstOrDefault() != null) { var msg = $"0x{esStream.ElementaryPid:X4} - AC3 Audio"; if (!string.IsNullOrWhiteSpace(lang)) { msg += $" [{lang}]"; } Console.WriteLine(msg); } if (esStream.Descriptors.OfType <Eac3Descriptor>().FirstOrDefault() != null) { var msg = $"0x{esStream.ElementaryPid:X4} - EAC3 Audio"; if (!string.IsNullOrWhiteSpace(lang)) { msg += $" [{lang}]"; } Console.WriteLine(msg); } if (esStream.Descriptors.OfType <SubtitlingDescriptor>().FirstOrDefault() != null) { var subDesc = esStream.Descriptors.OfType <SubtitlingDescriptor>().First(); var msg = $"0x{esStream.ElementaryPid:X4} - DVB Subtitles"; foreach (var language in subDesc.Languages) { msg += $" [{language.Iso639LanguageCode}/{language.SubtitlingType}]"; } Console.WriteLine(msg); } if (esStream.Descriptors.OfType <TeletextDescriptor>().FirstOrDefault() != null) { var ttxDesc = esStream.Descriptors.OfType <TeletextDescriptor>().First(); var msg = $"0x{esStream.ElementaryPid:X4} - Teletext Subtitles"; var foundSubs = false; foreach (var language in ttxDesc.Languages) { if (language.TeletextType != 2) { continue; } var magNum = language.TeletextMagazineNumber; if (magNum == 0) { magNum = 8; } msg += $" [{magNum}{language.TeletextPageNumber:X2}-{language.Iso639LanguageCode}/{language.TeletextType}]"; foundSubs = true; } if (foundSubs) { Console.WriteLine(msg); } } } //finished scan return; } if (stream.Position < stream.Length) { readCount = stream.Read(data, 0, readFragmentSize); } else { Assert.Fail("Reached end of file without completing SDT scan"); } } catch (Exception ex) { Assert.Fail($"Problem reading file: {ex.Message}"); } } }