-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClass1.cs
More file actions
171 lines (146 loc) · 6.01 KB
/
Copy pathClass1.cs
File metadata and controls
171 lines (146 loc) · 6.01 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using Silicondust.HDHomeRun;
using HdHomerunLib.MpegTSParser;
// KTVU (FOX) 2 [SD] qam:79,1
// KRON (IND) 4 [SD] qam:79,2
// KPIX (CBS) 5 [SD] qam:79,3
// KGO (ABC) 7 [SD] qam:79,4
// KQED (PBS) 9 [SD] qam:79,5
// KOFY 13 [SD] qam:79,7
// KBCW (CW) 12 [SD] qam:79,10
// KNTV (NBC) 4 [SD] qam:84,1
// KICU 6 [SD] qam:84,2
// KTEH (PBS) 10 [SD] qam:84,4
// ABC 7 [HD] qam:117,1
// KQED (PBS) 9 [HD] qam:117,2
// WGN (IND) [SD] qam:118,4
// ??? [SD] qam:120,4
// KPIX (CBS) [HD] qam:122,1
// KTVU (FOX) [HD] qam:122,2
// KTVU (FOX) [SD] qam:122,3
// Discovery [SD] qam:129,3
namespace HdHomerunLib
{
public class Class1
{
bool done = false;
static void DoQuery(MultiTuner hd, string query)
{
System.Console.WriteLine("\n=== {0} ===========================================", query);
System.Console.WriteLine(hd.Get(query));
}
static void DoSet(MultiTuner hd, string name, string value)
{
System.Console.WriteLine("\n===SET=== {0} TO {1} =====================================", name, value);
System.Console.WriteLine(hd.Set(name, value));
}
public static string GetLocalIP()
{
// Get host name
string strHostName = Dns.GetHostName();
Console.WriteLine("Host Name: " + strHostName);
// Find host by name
IPHostEntry iphostentry1 = Dns.GetHostEntry(strHostName);
IPHostEntry iphostentry = Dns.GetHostByName(strHostName);
// Enumerate IP addresses
int nIP = 0;
foreach (IPAddress ipaddress in iphostentry.AddressList)
{
Console.WriteLine("IP #" + ++nIP + ": " +
ipaddress.ToString());
}
//! Need to set preferred network interface and remember this
//! We could also eventually have different networked QAM tuners
//! available on different networks.
return iphostentry.AddressList[0].ToString();
}
void ReceiveThread()
{
const int udpPort = 6502;
UdpClient client = new UdpClient(udpPort);
IPEndPoint receivePoint;
TransportStreamParser parser = new TransportStreamParser();
TSDemux accumulator = new TSDemux(parser);
FileStream capture = new FileStream(string.Format(@"c:\ts-capture-{0}.mpg", DateTime.Now.ToFileTime()), FileMode.Create);
receivePoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), udpPort);
int bytes = 0;
int nextMeg = 1024 * 1024;
// while (bytes < 25 * 1024 * 1024)
while (true)
{
byte[] data = client.Receive(ref receivePoint);
// capture.Write(data, 0, data.Length);
bytes += data.Length;
if (bytes > nextMeg)
{
// System.Console.WriteLine("Bytes read: {0}", bytes);
nextMeg += 1024 * 1024;
}
#if true
int offset = 0;
while (offset < data.Length)
{
byte[] tsp = new byte[ParseUtils.MPEG_TS_PACKET_SIZE];
Buffer.BlockCopy(data, offset, tsp, 0, ParseUtils.MPEG_TS_PACKET_SIZE);
try
{
TSPacket packet = new TSPacket(tsp);
packet.ParseData();
parser.AcceptPacket(packet);
}
catch (Exception)
{ }
offset += ParseUtils.MPEG_TS_PACKET_SIZE;
}
#endif
}
capture.Close();
done = true;
}
public void DoStuff()
{
Collection<Device> devices = Network.FindDevices();
System.Threading.Thread thread = new System.Threading.Thread(ReceiveThread);
thread.Start();
foreach (Device dev in devices)
{
MultiTuner multi = (MultiTuner)dev;
Tuner tuner = multi.Tuners[0];
Channel channel = tuner.Channel;
// DoSet(multi, "/tuner1/channel", "qam:84");
DoSet(multi, "/tuner1/channel", "qam:129");
// DoSet(multi, "/tuner1/program", "4");
DoSet(multi, "/tuner1/target", string.Format("{0}:{1}", GetLocalIP(), "6502"));
// DoSet(multi, "/tuner1/filter", "0x0000-0x00FF 0x07C0-0x07C1 0x1FF0-0x1FFF");
// DoSet(multi, "/tuner1/channel", "qam:92");
DoSet(multi, "/tuner1/filter", "0x0000-0x007F 0x0800-0x080F 0x0C00-0x1FFE");
DoQuery(multi, "/tuner1/channel");
DoQuery(multi, "/tuner1/channelmap");
DoQuery(multi, "/tuner1/status");
DoQuery(multi, "/tuner1/streaminfo");
DoQuery(multi, "/tuner1/filter");
System.Console.WriteLine(dev);
while (!done)
{
System.Threading.Thread.Sleep(2000);
#if false
DoQuery(multi, "/tuner1/channel");
DoQuery(multi, "/tuner1/channelmap");
DoQuery(multi, "/tuner1/program");
DoQuery(multi, "/tuner1/status");
DoQuery(multi, "/tuner1/streaminfo");
DoQuery(multi, "/tuner1/filter");
#endif
}
System.Console.WriteLine("Exiting");
}
}
}
}