views:

213

answers:

2

Hi -

My company makes DVRs that specialize in streaming live and recorded video. The video is encoded using standard MPEG-4 codecs so the codecs in Android should have no trouble with them. However, the video is recorded using non-standard file formats and is streamed using our proprietary protocol (among other things we embed additional data such as watermarks with each frame of video). Is there any way I can take my stream pull out the frames and have it play on an Android device?

Thanks!

A: 

Android has java.net.Socket, so in theory you can write a client for the proprietary stream. However, I don't know how you could take advantage the existing Android playback functionality (e.g. MediaPlayer). It only seems to support playing a file or a URL. InputStream is noticeably missing.

Matthew Flaschen
A: 

You can create a socket, take it's "file descriptor", and give that to the MediaPlayer.setDataSource().

I have actually done something similiar to this a while back, so this approach is tested in the field.

I forget exactly how to extract the file descriptor from a socket, but I think that using reflection - or more likely native code - you can get an 'impl' member on the socket which is a LocalSocket or something, and has a 'fd' member. Googling has not found anyone describing this, so you'll have to explore the exact member names and details yourself.

The container format will have to be something that is recognised by the Android system; if necessary you can use native code to create a pipe so that you can repackage your custom container into something that Android supports on-the-fly using a thread.

It occurs to me that there's a good chance that Android plays 'raw' H.263 and H.264BP or whatever, but I have not tested this. AVI is obviously not ideal for streaming - you might have to split your video up into short chunks of AVI, and keep swapping these blocks - or you might explore if FLV or Matroska is supported, but be cautious - the exact mix of supported container formats might differ from device to device, or from release to release.

Will