I am trying write a real-time flv stream demuxer on windows-runtime, for win8.1 and wp8.1's MediaElement.
I've already finish the demux code, flv files can be correctly demuxed into h264 and aac tag-datas.
When I was trying to play network files and streams, I got a very strange network problem:
The same code,
Code for opening the stream:
var uri = new Uri("http://hdl.xxx.com/live/yyyy")
//uri is dymatic
var client = new HttpClient();
var stream = await client.GetStreamAsync(uri);
openStream(stream)
Code for reading the data:
public static byte[] ReadBlocks(this Stream stream, int count)
{
byte[] buffer = new byte[count];
int offset = 0;
int length;
while (offset < count)
{
//a loop statement to guarantee I can get *count* bytes
Debug.WriteLine("read " + (count - offset));
//a debug message show how many bytes do I need
length = stream.Read(buffer, offset, count - offset);
if (length == 0)
{
throw new EndOfStreamException();
}
Debug.WriteLine("got " + length);
//a debug message show how many bytes I got
offset += length;
}
return buffer;
}
For example, when I need to rea 1024 bytes from the flv stream, I run stream.ReadBlocks(1024) under wp8.1, the debug tells me like:
read 1024
got 768
read 256
and then nothing happend any more. I wrote an extra counter, the counter shows once server send a total of 65536 bytes, next Read method of stream will always be choked.
I'm sure the uri is available. I can download some stream data as a flv file by using pc web browser, and this downloaded flv file can be played under wp8.1 as well.
It looks like this problem only happens under wp8.1, android and ios are not affected.
So is it my code's problem or actually the server is not set up properly?
From last three weeks, I've tried every http method that can open a stream, but still got choked at 65536 bytes.
Could someone help me, please?
I just solved the same problem - do NOT use System.Net.HttpClient, but Windows.Web.Http.HttpClient
The one in System.Net uses header Connection: Close by default, which causes the stream to close, reading only 65 kB. It also contains a bug which prevents you to override the header to Keep-Alive (it throws some nonesense exception)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With