-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
101 lines (85 loc) · 3.22 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Net;
using System.Net.Sockets;
using JMS.DVB;
using JMS.DVB.TS;
namespace TransportStreamSample
{
/// <summary>
/// Repräsentiert den Windows Prozess als Ganzes.
/// </summary>
public static class Program
{
/// <summary>
/// Alle einmaligen Aktualisierungen.
/// </summary>
static Program()
{
// Load DVB.NET runtime from installation directory
RunTimeLoader.Startup();
}
/// <summary>
/// Startet die Anwendung. Dieses Besipiel liest eine TS Datei ein.
/// </summary>
/// <param name="args">Der Empfangsport und der Name der TS Datei.</param>
public static void Main( string[] args )
{
// Be safe
try
{
// Create socket to receive RTP stream
using (var analyser = new RtpTransportStreamAnalyser())
using (var file = new DoubleBufferedFile( args[1], 1000000 ))
using (var socket = new Socket( AddressFamily.InterNetworkV6, SocketType.Dgram, ProtocolType.Udp ) { Blocking = true })
{
// Configure
socket.SetSocketOption( SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, 10000000 );
// Bind it
socket.Bind( new IPEndPoint( IPAddress.IPv6Any, ushort.Parse( args[0] ) ) );
// Buffer to use
var buffer = new byte[10000];
// First send to file
Action<byte[], int, int> sink = file.Write;
// Then to analyse
sink += analyser.Feed;
// Result processor
AsyncCallback whenDone = null;
// Starter
Action asyncRead = () => socket.BeginReceive( buffer, 0, buffer.Length, SocketFlags.None, whenDone, null );
// Define result processor
whenDone =
result =>
{
// Be safe
try
{
// Finish
var bytes = socket.EndReceive( result );
// Try to dispatch
RtpPacketDispatcher.DispatchTSPayload( buffer, 0, bytes, sink );
// Fire next
asyncRead();
}
catch (ObjectDisposedException)
{
}
};
// Process
asyncRead();
// Wait for termination
Console.WriteLine( "Press ENTER to End" );
Console.ReadLine();
// Terminate connection
socket.Close();
}
}
catch (Exception e)
{
// Report
Console.WriteLine( "Error: {0}", e.Message );
}
// Done
Console.ReadLine();
}
}
}