Telemetry Extractor SDK  Version 1.0.1
Sample Code - Klv Metadata extraction
using System;
using System.Collections.Generic;
using System.Linq;
using StTelemetryExt;
using System.Threading;
namespace TelemetryExtractorTestApp
{
class Program
{
static StanagTelemetryExtractor extractor;
static object ConsoleLock = new object();
static void Main(string[] args)
{
Console.WriteLine(@"Usage: TelemetryExtractorTestApp.exe C:\Movie\KLV\ScottKlv.ts");
if (args.Count() == 0)
{
Console.WriteLine("Please provide file path");
Console.ReadKey(true);
return;
}
// Create extractor instance
extractor = new StanagTelemetryExtractor();
if (extractor.Activate("TelemetryExtractor", @"C:\MyLicenseFile.lic", "505536B2-1ABF5491-3F28B6D0-AF46D13B") == false)
ReportError("License not valid. Demo mode activated. Only 10 first packets will be processed");
else
Console.WriteLine("License Ok");
// Setup events
extractor.MetadataPidDetectionCompleteEvent += new MetadataPidDetectionCompleteHandler(extractor_MetadataPidDetectionCompleteEvent);
extractor.PacketReadyEvent += new StTelemetryExtractor.PacketReadyHandler(extractor_ExtractorPacketReadyEvent);
extractor.SegmentProcessingEvent += new SegmentProcessingHandler(extractor_SegmentProcessingEvent);
extractor.ExtractorErrorEvent += new StTelemetryExtractor.ExtractorErrorHandler(extractor_ExtractorErrorEvent);
extractor.ExtractorMessageEvent += new StTelemetryExtractor.ExtractorMessageHandler(extractor_ExtractorMessageEvent);
extractor.ExtractorCompleteEvent += new StTelemetryExtractor.ExtractorCompleteHandler(extractor_ExtractorCompleteEvent);
// Configure
extractor.ValidateChecksum = true;
// Add some files
foreach( var f in args)
{
Console.WriteLine("Add File {0}", f);
extractor.AddFile( f, null ); // We provide file path only. Klv Pid will be detected automatically.
}
Console.WriteLine(Environment.NewLine);
Console.WriteLine("\nS - Start Processing.");
Console.WriteLine("\nE - Stop Processing.");
Console.WriteLine("\nESC/Q - Quit.");
Console.WriteLine(Environment.NewLine);
ConsoleKeyInfo cki = new ConsoleKeyInfo();
do
{
cki = Console.ReadKey(true);
switch (cki.Key)
{
case ConsoleKey.S:
Console.WriteLine("\nStart Processing.");
// Start KlvProcessing
extractor.Start();
break;
case ConsoleKey.E:
Console.WriteLine("\nStop KlvProcessing");
// Stop KlvProcessing
extractor.Stop();
break;
}
Thread.Sleep(200);
} while (cki.Key != ConsoleKey.Q && cki.Key != ConsoleKey.Escape);
// Stop Extractor (if it is running) and exit.
extractor.Stop();
}
// Raised when extractor completes Klv metadata PID detection
static void extractor_MetadataPidDetectionCompleteEvent(MetadataPidDetectionCompleteArgs e)
{
lock (ConsoleLock)
{
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine("Detection complete. {0} Klv Pid(s) found:", e.pids.Count());
Console.ResetColor();
foreach (var pid in e.pids)
{
Console.WriteLine(string.Format("{0} (0x{1})", pid.ToString(), pid.ToString("X3")));
}
}
}
// Raised when a new metadata packet is ready
static void extractor_ExtractorPacketReadyEvent(List<EG601Item> pckt, Int64 offset)
{
lock (ConsoleLock)
{
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.Write("Packet {0} klvs\t received\t ", pckt.Count);
Console.ResetColor();
Console.Write("Time {0}. Offset {1}\n", pckt[0].ConvertedValueStr, offset);
}
}
// Raised on Segment processing start or completion
static void extractor_SegmentProcessingEvent(SegmentProcessingArgs e)
{
lock (ConsoleLock)
{
Console.ForegroundColor = ConsoleColor.Yellow;
if(e.State == SegmentProcessingState.STARTED)
Console.Write("Segment {0} processing started.", e.Path);
else
Console.Write("Segment {0} processing complete. {1} klv packets processed.", e.Path, e.PacketCount);
Console.ResetColor();
Console.WriteLine(Environment.NewLine);
}
}
// Raised when all entires in the list have been processed
static void extractor_ExtractorCompleteEvent()
{
lock (ConsoleLock)
{
Console.WriteLine("Extraction complete. {0} packets processed", extractor.TotalKlvPacketsProcessed);
}
}
// Raised on Extractor notification message
static void extractor_ExtractorMessageEvent(StTelemetryExtractor.ExtractorMessageArgs e)
{
lock (ConsoleLock)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(e.Message);
Console.ResetColor();
}
}
// Raised on Extractor error
static void extractor_ExtractorErrorEvent(StTelemetryExtractor.ExtractorErrorArgs e)
{
ReportError(e.Message);
}
static void ReportError(string format, params object[] args)
{
lock (ConsoleLock)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(format, args);
Console.WriteLine(Environment.NewLine);
Console.ResetColor();
}
}
}
}


TestApp.png
Figure 1. Console Test Application.


Untitled 1




 Copyright 2013,    IMPLEOTV SYSTEMS LTD