Streaming halts but local playback of same file works
Posted: 23 Jun 2009 03:25
I managed to create an adhoc network between two of my laptops and wrote a program to copy a video file from the other machine if one is not available locally. So lets say there are two machines A{1} and B{2} where 1, 2 are the videos that they have. Now, I am redirecting the request of VLC Player (video playing software) to my program after which I am forming my own headers and replying back. The playback works perfectly when the file is played locally. But lets say that B requests for file 1 (which is on A), then there is a small message exchange after which A starts transferring the file and B writes the file into the socket where VLC is listening and the streaming starts.
Now the problem is, after 3-4 seconds, the video playback stops but the file downloading continues. If I hit the pause button and then the playback button after 4-5 seconds, the playback is ok otherwise the picture remains frozen. I am not sure where to start but am guessing the problem has something to do with buffer sizes which are something like this:
When B connects to A, A writes into a buffer of size 1024.
B reads from the socket into a buffer of size 1024.
B then writes into the socket where VLC is listening with a buffer of size 1024.
The snippet where B writes to VLC as well as a file locally is shown here:
Can someone please advice me on where to start troubleshooting for this problem? One useful hint I could gather is that, once the playback is complete, the machine looks first in its local cache so it finds the newly downloaded video and starts playing without any problem....
Now the problem is, after 3-4 seconds, the video playback stops but the file downloading continues. If I hit the pause button and then the playback button after 4-5 seconds, the playback is ok otherwise the picture remains frozen. I am not sure where to start but am guessing the problem has something to do with buffer sizes which are something like this:
When B connects to A, A writes into a buffer of size 1024.
B reads from the socket into a buffer of size 1024.
B then writes into the socket where VLC is listening with a buffer of size 1024.
The snippet where B writes to VLC as well as a file locally is shown here:
Code: Select all
while((bytesRead = is.read(fileByteArray, 0, fileByteArray.length)) > 0) {
out.write(fileByteArray, 0, bytesRead); //Output stream of VLC player socket
bos.write(fileByteArray, 0, bytesRead); //Buffered output stream into a file
}
out.flush();
Can someone please advice me on where to start troubleshooting for this problem? One useful hint I could gather is that, once the playback is complete, the machine looks first in its local cache so it finds the newly downloaded video and starts playing without any problem....