views:

47

answers:

1

Hi,

I have a image file stored at a remote server (i.e http://example.com/images).The images in this folder are getting updated at the rate of 1 image per 100 milliseconds Think of ip cams that transmit MJPEG images .

I am using apache HTTP client api to connect to my remote server .I am getting a stream of the content

HttpClient httpClient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet("http://example.com/images/screenshot.jpg");
    HttpResponse response = httpClient.execute(httpget);
    HttpEntity entity = response.getEntity();
    if (entity != null) {
    InputStream instream = entity.getContent();

I am wrapping up the input stream in BufferedInputStream for faster I/O .But since the images are getting generated at very fast rate and they are on an average 250kb in size.

I would like to use the NIO features like FileChannel as well as MemoryMappedBuffers to improve the I/O performance as well access generated image files on remote server in non blocking mode.

But whatever samples I have seen talk about creating FileInputStream / RandomAccessFiles which take File Object as parameter.

I am getting the InputStream as response from remote server which I am unable to convert to FileInputStream to get FileChannel.

I would like to know if there is any implementation in apache http client api that gives fileChannels.

Or should i explore sockets to get the channel access. I have also exlored javax.imageIO , but not sure if it will meet my requirement of faster I/O

A: 

Your limiting factor is going to be the network. If you have a 1mbps line, that means your practical max transfer will probably be about 100 kilobytes per second (I realise 8 bits to the byte, but given communication overhead the typical observed transfer tends to be 10-to-1).

If you're looking to pull down 10 images per second, and each image is 250k, you need a 25 mbps network connection.

Sockets might offer minor improvements, but it will still not achieve what you want. Have you considered compression? E.g. on server, assemble several images into a compressed archive, download, and uncompress. This still will not get you 10 250k images per second, but could get you closer.

Another option may be to use a video stream, unless you absolutely need images.

If you absolutely need 10 images per second, you need to either increase the speed of your connection to the server or reduce the size of the images, or some combination of both.

Taylor
Note the "B"s and "b"s
belisarius
I noted them, but the tricky thing there is most don't know the difference or often get it wrong, so it's not always trustworthy.Even so, if he can get downloads of ~1 mega byte per second, it's still an insufficient data rate.
Taylor
@Taylor In one case he is tight, but it the other is impossible
belisarius
For stream handling i would have to use open source servers live red5,I have programming experience on Java but have very limited exp on C/C++ , otherwise i could have explored ffmpeg and other libs that are a wrapper on ffmpeg.Image handling is easy as compared to streams.If bandwidth becomes such a big bottlebneck, I will reduce the size(will have to use wireshark or something I guess to see packets,that control the image size from cameras admin panel).What i want to know is that Is there a way to play with fileChannels on input stream? Please let me know if you require more details
anuj singh
If needed i can also share my test code with you guys
anuj singh
I don't think so, file streams tend to be specific to files. Typically you can get network input into input streams (but not file input streams) which will allow you to use things like memory mapped buffers, but not file-specific optimizations like file channels. Still, your limiting factor will be the bandwidth.
Taylor
thanks for the reply @Taylor , bandwidth will definitely be a limiting factor .I intend to use Executor framework to obtain multiple connections to the cameras and see if i can improve upon the current rate of fetching images.
anuj singh