5

This is what I'd like to achieve. I have 2 android devices, I would like to access the camera of the second via bluetooth and display the preview on the first one.

Any hints how to do this?

Basically I would like to get a camera instance of another android device via bluetooth.

Philipp Jahoda
  • 50,880
  • 24
  • 180
  • 187
Manza
  • 3,427
  • 4
  • 36
  • 57

1 Answers1

5

Short Answer:

You can't get a direct instance this way. That is - you're not going to get a Camera Object which you'll be able to use normally. Instead you're going to have to fake it a fair amount.

Long Answer:

You're going to have to set up a bluetooth client/host relationship between the two devices. After you've done that you're going to set one up as the "control" aspect of this relationship, and the other as the camera. We'll call these 1 and 2.

1 will have a UI (take picture button etc). When a button is pressed, a command will travel down the line to 2.

2 will then do as the command requests and pass some data back to 1.

In the case of taking a picture:

User presses take picture button in 1. 1 Sends command "take a pic" to 2. 2 then uses this command to take a photo as per your instruction. 2 then sends the file result of this picture back over the bluetooth.

For doing image preview - that is seeing what the image is before you actually click "capture" - I don't think you're going to have much luck. You could do this following the above pattern, but I'm doubtful that it would be a smooth experience.

EDIT:

After some discussion with Alex in comments, and some thinking on this I have a few ideas for preview.

Concerns:

If you can get around 10-15 fps from 2 to 1 you can have a reasonable preview. Depending on your needs/use case even less might be possible.

You need to implement

Camera.PreviewCallback:

onPreviewFrame(byte[] data, Camera camera); :

http://developer.android.com/reference/android/hardware/Camera.PreviewCallback.html#onPreviewFrame(byte[], android.hardware.Camera), and register your callback with

Camera

setPreviewCallback(Camera.PreviewCallback cb)

You need to downsample (likely, I'm not sure on the sizes of what's provided in onPreviewFrame) to keep content size low.

4) Send.

I'm not entirely sure this would work as I haven't tested it, but thats the most straightforward route that I see.

Another Option:

Go into the JNI and handle the entire thing there. You could almost certainly make this work at that level in terms of speed. I have vague ideas on how to do this but it would be a fairly substantial undertaking.

Nathaniel D. Waggoner
  • 2,856
  • 2
  • 19
  • 41
  • To my first upvoter - thanks for getting me over 1k =) – Nathaniel D. Waggoner Mar 12 '14 at 19:27
  • 1
    To have live preview of reasonable quality, you need say VGA resolution at 15 FPS. This gives less than 1Mbps (see http://www.stardot.com/bandwidth-and-storage-calculator), and fits into bandwidth of Bluetooth Basic Rate (BR). But you need h264 codec. – Alex Cohn Mar 12 '14 at 22:35
  • Not saying it's impossible, but 15 fps is on the very bottom end of what I would call a "smooth" experience. Additionally - the standard Android Camera API isn't going to provide you frames in VGA resolution. – Nathaniel D. Waggoner Mar 12 '14 at 22:40
  • VGA is kind of least common denominator these days. For photo viewfinder on a 4" phone, even less may be enough. You would be surprised to see how smooth 15 FPS actually feels (but we are not speaking about recording video at this rate and resolution). – Alex Cohn Mar 12 '14 at 22:46
  • 1
    I just watched some video at 15 fps and you're right, it's not terrible. Also yea, VGA is LCD no argument there. Again - I think it's doable, but its going to take a lot of finesing to get a decent preview across bluetooth. Additionally the built in preview mechanisms don't give a direct pathway to do the preview image transfer. – Nathaniel D. Waggoner Mar 12 '14 at 22:59
  • I wonder how hard it would be to use WebRTC to do the heavylifting. – Alex Cohn Mar 12 '14 at 23:17
  • Edited the answer to address our discussion. Thanks btw Alex, gave me some good ideas. – Nathaniel D. Waggoner Mar 13 '14 at 02:45
  • Thanks for your answers. I knew it doesn't look a easy task. Well, I'll try and keep the post updated if I figure out something – Manza Mar 13 '14 at 20:57
  • Honestly I think the roadmap is there. I can give you the links to the bluetooth and camera docs but you should be able to find these. It's actually not as terrible as I had originally thought. I'd say two weeks of good work for a demo if you're skilled but not an android expert. – Nathaniel D. Waggoner Mar 13 '14 at 21:04
  • Thank you very much for all the answers, I'm still trying to figure out how to. I'll update post when I'll know smth. – Manza Mar 20 '14 at 23:53
  • So I'm going to post a basic impl of this to github tomorrow. I'll share it with you once it's up. I'm also looking into how to do it in the JNI. It's DEFINITELY the way to go. – Nathaniel D. Waggoner Mar 21 '14 at 02:26
  • I'm having a very hard times with this guys. I've faced many problems - Bluetooth is extremely slow and definitely not good for this kind of things. - I'm gonna try with USB connection and JNI – Manza Apr 01 '14 at 16:25
  • Did anyone find solution for this? I am not getting how to show byte[] data in a surface view, any help? If anyone solved this pls post the answer. Thanks. – Shivaraj Patil Feb 01 '16 at 21:42
  • @ShivarajPatil public static Bitmap decodeByteArray (byte[] data, int offset, int length, BitmapFactory.Options opts) – Nathaniel D. Waggoner Feb 01 '16 at 22:00
  • nop it wont work. bitmap is null, trying this https://github.com/ikkiChung/MyRealTimeImageProcessing trying – Shivaraj Patil Feb 01 '16 at 23:12
  • k... i think you should open a new question. Your issue isn't the same as what was asked in this quesiton. – Nathaniel D. Waggoner Feb 01 '16 at 23:14
  • Thanks, as you said I have created new question please have a look at it http://stackoverflow.com/questions/35146652/android-how-to-show-camera-preview-on-other-device-over-bluetooth – Shivaraj Patil Feb 02 '16 at 10:28