How does seek work in peerflix? - java

i was checking peerflix and it was really awesome that it support seek feature in videos.
i tried to understand how it works , i think it create a stream pipe on HTTP file server and write video data on it when a required piece is downloaded and the video player reads data from other end of pipe.
i tried to do this in java using Pipedinputstream and pipedoutputstream using nanohttpd server but cannot make it work.
is there something i am missing?
peerflix: it is a lib that stream torrent videos , you can watch videos with seek feature. you do not have to wait for the download to finish.

Peerflix selects the biggest file in the torrent or you can select one on your own. Then it begins downloading the file sequentially from the first piece. This file is served on a standard HTTP static file server.
When you seek in a video player, it checks the video container to find which bytes in the video file that corresponds to the given time stamp. The video player then sends a HTTP range request for the bytes corresponding to the video time plus some buffer. Then, Peerflix's HTTP server reads this range request and checks the .torrent file to find which piece corresponds to the requested bytes. It starts downloading sequentially from the requested piece onwards, and responds to the HTTP request when the requested bytes are available.

Related

Queing files for transfer from android device to server using Socket

I have a setup of an android phone connected to a server through a socket, What I need to do is the app will contain a recycler view, each item in the recycler view will have a check-box in it once checked the file that this item represents should be uploaded to the server through a data output stream this will take some time as the files range anywhere between 12-200 MB and a scenario that probably will happen is the user clicking multiple boxes after each other and because I'm using a socket I think I can't send two files at the same time, So I want to queue the files and sort of send each file after the one before it finishes also the files must be sent no matter what the user does f the user exits the app or leaves the app in the background the upload must continue, what approach can I take to achieve this and please answer with code samples of both the queueing the upload in the phone and receiving the files on the server.

C++ to Java socket audio streaming

Hello, I'm trying to build client-server audio streaming app. Server has to be written in C and communicate with client using sockets (TCP). Client will be written in javafx (actually tornadofx, but that doesn't relate to the problem)
My doubts concern the streaming part. Server has several audio files. I want to be able to start, stop, rewind, skip to another song in the client app. Java has AFAIK two classes to play audio - Clip and SourceDataLine. I don't think sending the whole song before playing is the way to go (Clip, large sound files) so I guess I should stick with SourceDataLine. My simple guess is that I should send fairly small portion of audio every time the client comes close to listening the last portion he received. (e.g I send 30 seconds and when client is on 25th second he sends request for more) Is that right? Is that doable in previously mentioned technologies?
Maybe something like ffmpeg could be useful here
https://github.com/avTranscoder/avTranscoder
But again, I have to communicate over tcp sockets only.

Increase connection timeout on Spring MVC server for HTML5 audio

I have a Spring MVC Java web app which plays audio files using the HTML5 audio tag. My MVC controller streams the audio file by writing to response.getOutputStream().
When the audio file is small (< 6mb), the browser will download the entire audio file immediately and play it without issue. When the audio file is larger, the browser will download about 6mb and then wait until playback catches up before requesting more data. It won't close the connection, but just wait before requesting more data from the stream.
The server will then wait for however long connectionTimeout is set on the HTTP connector in Tomcat's server.xml (default 20 seconds). Tomcat then throws a SocketTimeoutException, ending the connection.
The browser will then play until it reaches the end of what it has downloaded and print the error ERR_CONTENT_LENGTH_MISMATCH to the console. This is because the browser requested the entire file but the server terminated the connection before all the data was sent. It makes an HTTP range request for the rest of the data, opening a new connection. This happens seamlessly and the song continues to play. However, it shouldn't have to do this. It should be able to keep the original connection open for the entire duration of the song.
One fix is to increase Tomcat's connectionTimeout in server.xml. However, I would prefer to do this just for the application rather than globally for the Tomcat server. Even better would be just for that one MVC controller method that streams the audio. Is this possible?

Http Header Range (HTML + Java Example)

I have a requirement to load big images into chrome browser, in pieces from the server and after it finishes downloading the file completely, if the user wants to look at the file again, then the browser should load it from its cache.
I have done the following to achieve this:
I have written a HTML file and I will be displaying the big image using 'img' tag.
Whenever the user requests for the image file, I'll make a HEAD request to the server enquiring about the content-length and last-modified-date.
The server replies back with the information based on the request and I divide the size of the file into 10 pieces and then make 10 sequential requests to fetch the image file. (Using for loop).
After chrome downloads the entire file and the next time user wants to look at the file, then I am making chrome to send If-Modified-Since query to the server.
If the server responds back with the code 304, then chrome will understand that it has to fetch the file from its cache.
I am facing the following problems:
1. I am getting about 100 bytes per response. Where should I store it and how should I make my img tag understand that it the client is still downloading the file.3
2. How should I recognize the file from the pool of files present in chrome's cache ?
3. The next time someone comes to view the same image, from where should I display the content from ?
Please Help. Can anyone also provide me with some example code or a link to some sample code.
Thanks and Regards,
Akshay Sahu
I got the way to perform this operation.
I am downloading all the bytes of a file in range and using File API of HTML 5 I am creating a file in the user HDD. Therefore, experiencing a complete resume download experience.
Thanks and Regards,
Akshay Sahu.

Java RTP/HTTP Streaming

i'm decoding and encoding a videofile via Xuggle to FLV-video format and send it via Sockets to my java server (not the entire file, only parts of it every X seconds). On the server-side I get the encoded file as ByteArrayInputStream. Is it possible to stream this ByteArrayInputStream via rtp or http-streaming? Or do i need a finished encoded file for that? I'm creating a video streaming server, where the client encodes the video file and sends it to the server in parts. This is already done. I'm now stuck on the server side, to stream the ByteArrayInputStream via RTP or HTTP, so I can watch it via VLC. Are there any good examples for it?
I've already tested to save the ByteArrayInputStream to file. This works but I don't wanna save the file on the server. I wanna stream it ;)
Thank you
1) See Server implementation
http://cs.anu.edu.au/student/comp3310/2004/Labs/lab6/lab5.html
2) http://code.google.com/p/vlcj/ and see http://code.google.com/p/vlcj/wiki/Streaming

Categories