Open yann591 opened 2 years ago
This version of code is only a protoype client (ready only) for MpegTS. That said, with some work, you could use it to take a raw H.264/5 stream and encapsulate it in a MpegTS packet stream that could be sent UDP, TCP, or to file. The use case that spurred the creation of this prototype library was to consume a UDP stream.
By this way I send to 380 Mbit/s, how could I improve this code ?
string tsFile = @"E:\dvb\dvb_lib\27.ts";
byte[] bytes = File.ReadAllBytes(tsFile);
UdpClient outPutUdpClient = new UdpClient { ExclusiveAddressUse=false};
IPAddress outPutIp = IPAddress.Parse("192.168.99.239");
int multicastPort = 1234;
var localEp = new IPEndPoint(outPutIp, multicastPort);
outPutUdpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
outPutUdpClient.Ttl = 3;
outPutUdpClient.Client.Bind(localEp);
var mcastAddr = IPAddress.Parse("239.1.1.1");
outPutUdpClient.Connect(mcastAddr, multicastPort);
for(int i = 1316; i < bytes.Length; i+=1316) // take 7 ts packets per one UDP packet
{
int begin = i-1316;
int end = i;
var sendBytes = bytes[begin..end];
Thread.Sleep(1); <--- NEED Delay 2641 ticks
try
{
outPutUdpClient.Send(sendBytes, sendBytes.Length);
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
}
There is a way to stream MpegTS to UDP ?