Пример #1
0
        public static void AnalyzeMPEGTSPackets(string path, bool includeEIT = true)
        {
            var logger = new FileLoggingService(LoggingLevelEnum.Debug);

            logger.LogFilename = "Log.log";

            Console.Write($"Reading ....... ");

            var bytes   = LoadBytesFromFile(path);
            var packets = MPEGTransportStreamPacket.Parse(bytes);

            Console.WriteLine($" {packets.Count} packets found");

            var packetsByPID = new SortedDictionary <long, List <MPEGTransportStreamPacket> >();

            foreach (var packet in packets)
            {
                if (!packetsByPID.ContainsKey(packet.PID))
                {
                    packetsByPID.Add(packet.PID, new List <MPEGTransportStreamPacket>());
                }

                packetsByPID[packet.PID].Add(packet);
            }

            Console.WriteLine();
            Console.WriteLine($"PID:             Packets count");
            Console.WriteLine("-------------------------------");

            SDTTable sDTTable = null;
            PSITable psiTable = null;

            foreach (var kvp in packetsByPID)
            {
                Console.WriteLine($"{kvp.Key,6} ({"0x" + Convert.ToString(kvp.Key, 16),6}): {kvp.Value.Count,8}");
            }

            if (packetsByPID.ContainsKey(17))
            {
                Console.WriteLine();
                Console.WriteLine($"Service Description Table(SDT):");
                Console.WriteLine($"------------------------------");

                sDTTable = DVBTTable.CreateFromPackets <SDTTable>(packetsByPID[17], 17);  // PID 0x11, Service Description Table (SDT)

                if (sDTTable != null)
                {
                    sDTTable.WriteToConsole();
                }
            }

            if (packetsByPID.ContainsKey(16))
            {
                Console.WriteLine();
                Console.WriteLine($"Network Information Table (NIT):");
                Console.WriteLine($"--------------------------------");


                var niTable = DVBTTable.CreateFromPackets <NITTable>(packetsByPID[16], 16);

                if (niTable != null)
                {
                    niTable.WriteToConsole();
                }
            }

            if (packetsByPID.ContainsKey(0))
            {
                Console.WriteLine();
                Console.WriteLine($"Program Specific Information(PSI):");
                Console.WriteLine($"----------------------------------");

                psiTable = DVBTTable.CreateFromPackets <PSITable>(packetsByPID[0], 0);

                if (psiTable != null)
                {
                    psiTable.WriteToConsole();
                }
            }

            if ((psiTable != null) &&
                (sDTTable != null))
            {
                Console.WriteLine();
                Console.WriteLine($"Program Map Table (PMT):");
                Console.WriteLine($"----------------------------------");
                Console.WriteLine();

                var servicesMapPIDs = MPEGTransportStreamPacket.GetAvailableServicesMapPIDs(sDTTable, psiTable);

                Console.WriteLine($"{"Program name".PadRight(40,' '),40} {"Program number",14} {"     PID",8}");
                Console.WriteLine($"{"------------".PadRight(40,' '),40} {"--------------",14} {"--------"}");

                // scan PMT for each program number
                foreach (var kvp in servicesMapPIDs)
                {
                    Console.WriteLine($"{kvp.Key.ServiceName.PadRight(40, ' ')} {kvp.Key.ProgramNumber,14} {kvp.Value,8}");

                    if (packetsByPID.ContainsKey(Convert.ToInt32(kvp.Value)))
                    {
                        // stream contains this Map PID

                        if (packetsByPID.ContainsKey(kvp.Value))
                        {
                            var mptPacket = DVBTTable.CreateFromPackets <PMTTable>(packetsByPID[kvp.Value], kvp.Value);
                            mptPacket.WriteToConsole();
                        }
                    }
                }
            }


            if (includeEIT)
            {
                if (packetsByPID.ContainsKey(18))
                {
                    Console.WriteLine();
                    Console.WriteLine($"Event Information Table (EIT):");
                    Console.WriteLine($"------------------------------");

                    var eitManager = new EITManager(logger);

                    var packetsEITwithSDT = new List <MPEGTransportStreamPacket>();
                    packetsEITwithSDT.AddRange(packetsByPID[18]);

                    if (packetsByPID.ContainsKey(0))
                    {
                        packetsEITwithSDT.AddRange(packetsByPID[0]);
                    }

                    var eitScanRes = eitManager.Scan(packetsEITwithSDT);

                    if (eitScanRes.UnsupportedEncoding)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Unsupported encoding");
                        Console.WriteLine();
                    }
                    else
                    {
                        Console.WriteLine();
                        Console.WriteLine("Current events");
                        Console.WriteLine();

                        Console.WriteLine($"{"Program number",14} {"Date".PadRight(10, ' '),10} {"From "}-{" To  "} Text");
                        Console.WriteLine($"{"--------------",14} {"----".PadRight(10, '-'),10} {"-----"}-{"-----"} -------------------------------");

                        foreach (var kvp in eitManager.CurrentEvents)
                        {
                            Console.WriteLine(kvp.Value.WriteToString());
                        }


                        Console.WriteLine();
                        Console.WriteLine("Scheduled events");
                        Console.WriteLine();

                        foreach (var programNumber in eitManager.ScheduledEvents.Keys)
                        {
                            foreach (var ev in eitManager.ScheduledEvents[programNumber])
                            {
                                Console.WriteLine(ev.WriteToString());
                            }
                        }

                        Console.WriteLine();
                        Console.WriteLine("Present Events");
                        Console.WriteLine();

                        foreach (var kvp in eitManager.GetEvents(DateTime.Now))
                        {
                            Console.WriteLine($"Program Map PID: {kvp.Key}");

                            foreach (var ev in kvp.Value)
                            {
                                Console.WriteLine(ev.WriteToString());
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            var loggingService = new FileLoggingService();

            loggingService.LogFilename   = "TestConsole.log";
            loggingService.WriteToOutput = true;

            Console.WriteLine("...");


            /*
             * var tvService = new O2TV(loggingService);
             *
             * if (JSONObject.FileExists("O2TV.credentials.json"))
             * {
             *  //credentials.json:
             *  // {
             *  //    "Username": "******",
             *  //    "password": "******"
             *  // }
             *
             *  var credentials = JSONObject.LoadFromFile<Credentials>("O2TV.credentials.json");
             *  tvService.SetConnection(credentials.Username, credentials.Password);
             * }
             */


            var tvService = new KUKITV(loggingService);

            if (JSONObject.FileExists("kuki.json"))
            {
                var conn = JSONObject.LoadFromFile <DeviceConnection>("kuki.json");
                tvService.SetConnection(conn.deviceId, null);
            }


            /*
             * var tvService = new SledovaniTV(loggingService);
             *
             * if (JSONObject.FileExists("credentials.json"))
             * {
             *  var credentials = JSONObject.LoadFromFile<Credentials>("credentials.json");
             *  tvService.SetCredentials(credentials.Username, credentials.Password, credentials.ChildLockPIN);
             * }
             *
             */

            /*
             * if (JSONObject.FileExists("connection.json"))
             * {
             *  var conn = JSONObject.LoadFromFile<DeviceConnection>("connection.json");
             *  tvService.SetConnection(conn.deviceId, conn.password);
             * }
             */


            /*
             * if (JSONObject.FileExists("dvbStreamer.json"))
             * {
             *    var conn = JSONObject.LoadFromFile<DeviceConnection>("dvbStreamer.json");
             *    tvService.SetConnection(conn.deviceId, null);
             * }
             */


            Task.Run(
                async() =>
            {
                await tvService.Login();

                /*
                 * var qualities = await tvService.GetStreamQualities();
                 * foreach (var q in qualities)
                 * {
                 *  Console.WriteLine(q.Name.PadRight(20) + "  " + q.Id.PadLeft(10) + "  " + q.Allowed);
                 * }
                 */

                //await tvService.Unlock();
                //await sledovaniTV.Lock();

                var channels = await tvService.GetChanels();

                foreach (var ch in channels)
                {
                    Console.WriteLine(ch.Name);
                    Console.WriteLine("  ID     :" + ch.Id);
                    Console.WriteLine("  EPGID  :" + ch.EPGId);
                    Console.WriteLine("  Number :" + ch.ChannelNumber);
                    Console.WriteLine("  Locked :" + ch.Locked);
                    Console.WriteLine("  Url    :" + ch.Url);
                    Console.WriteLine("  Type   :" + ch.Type);
                    Console.WriteLine("  Group  :" + ch.Group);
                    Console.WriteLine("  LogoUrl:" + ch.LogoUrl);
                    Console.WriteLine("-----------------------");
                }

                /*
                 * var channelsEPG = await tvService.GetChannelsEPG();
                 * foreach (var epg in channelsEPG)
                 * {
                 *  Console.WriteLine($"  {epg.Key}");
                 *  foreach (var epgItem in epg.Value)
                 *  {
                 *      var time = epgItem.Start.ToString("dd.MM.yyyy HH:mm") + "-" + epgItem.Finish.ToString("HH:mm");
                 *      Console.WriteLine($"   {time}  : {epgItem.Title}   [{epgItem.EPGId}]");
                 *
                 *      // getting EPG detail:
                 *
                 *      var description = await tvService.GetEPGItemDescription(epgItem);
                 *
                 *      Console.WriteLine($"                                   {description}");
                 *  }
                 * }
                 */

                //Console.WriteLine();
                //Console.WriteLine("Press any key");
            });


            Console.ReadKey();
        }
Пример #3
0
 private static void TrackRequest(HttpRequestMessage request, string trackingId, string correlationId, string sessionId)
 {
     FileLoggingService.LogInformational(request, trackingId, correlationId, sessionId);
 }