private void ProcessChunk byte data int len bool headerRead headerRead

 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
private void ProcessChunk(byte[] data, int len)
{
bool headerRead = headerReader.Read(data, len);
if (!headerRead)
{
return;
}
IList<MediaContext> successSubscribers = new List<MediaContext>();
int count = subscribers.Count;
while (count > 0)
{
MediaContext subscriber;
if (subscribers.TryDequeue(out subscriber))
{
try
{
var networkStream = subscriber.Client.GetStream();
if (subscriber.Status == MediaContextStatus.Initial)
{
networkStream.Write(headerReader.Head, 0, headerReader.Head.Length);
subscriber.Status = MediaContextStatus.Active;
}
networkStream.Write(data, 0, len);
successSubscribers.Add(subscriber);
}
catch (Exception)
{
logger.Error("Failed to send data to subscriber. Channel={0}", channel);
}
}
--count;
}
foreach (MediaContext subscriber in successSubscribers)
{
subscribers.Enqueue(subscriber);
}
}