ios – Is there anyway to check if a camera device is available for the application to use on Android?

This question applies to Android phones, but I may have the same question for ios and UWP in the future. So a solution to my problem regarding the other platforms would be appreciated, but not required.

I am using the camera2 package to try to develop a camera application for Android phones and using Kotlin for it. One of the things I’m trying to do is to have the app find a camera device that is available for use at the current moment so it can initialize it and start doing camera stuff.

I see that the function getCameraIdList will return an array of camera devices currently connected to the device. However, the array will include those that are currently in use by other applications or API clients. Those camera devices in use can’t be used by a different application until it’s released by the original client. I was thinking that maybe I can use a loop to iterate over the string array returned by that function (starting with the camera device on the back of the phone) until the application finds one that is available. I can’t find a way however.

I see that there is a class called AvailabilityCallback that could notify if a certain camera device is available. Although it seems that this callback would be used if the camera device was unavailable before. Also I wouldn’t know if this is the right approach.

With StateCallback, which is a parameter for openCamera, contains a method for what the computer should do if an error occurs; and it would be ERROR_CAMERA_IN_USE in this case. The code below would be something like this:

callback: StateCallback() {
     onClosed(camera: CameraDevice){
         //do stuff
     onDisconnected(camera: CameraDevice){
         //do stuff
     onError(camera: CameraDevice){
         //Try a different camera device when ERROR_CAMERA_IN_USE occurs
     onOpened(camera: CameraDevice){
         //do stuff

fun openCamera(cameraId: String, callback, handler: Handler?){

I don’t know if this is the right approach either.

I also thought about having the application use openCamera more than once if the first camera wasn’t available but I imagine it would be expensive for it to do.

Knowing how to find and use an available camera device using camera2 is what I’m trying to do. Thank you everyone for your help.

4.0 ice cream sandwich – How do I get an Android 4.0 device to stream camera to local network or act as usb webcam?

I have an old android device that I’d like to keep using rather than sending it to a recycler. I have it secured on my network with a MAC address block such that it is only capable of communicating with local 192.168.1.* addresses. It cannot be upgraded beyond android 4.0 due to manufacturer limitations.

What I would like to do is sideload any kind of application that would allow me to stream video from the camera to either a locally hosted rtmp server (already configured and working) or to ffmpeg. Currently I’ve looked at an application called ‘spydroid’, ‘wificam’, ‘droid ip cam’ and ‘rtsp stream app’, but none of these applications are capable of providing this feature in a way that works (none of them can stream to an existing rtmp server or to ffmpeg).

Is there an app that allows me to stream my camera to the local network that will work with android version 4.0? If not, is it possible to configure it to act as a USB webcam?

Can I use lens brand X on interchangeable lens camera brand Y?

For the most part, no, you can’t mix’n’match lenses from different brands of cameras, because they’ll usually use different mount systems. The mount system specifies how the lens and camera body physically link, and may also specify electronic communication between the lens and camera. If the lens and camera are not in the same mount system, you cannot use the lens directly on the camera without some kind of adapting–and most such adapting may only take care of the physical link, not the electronic one. The only different-brands same-mount situations that may arise are Olympus/Panasonic both making gear in the four-thirds dSLR and micro four-thirds mirrorless mounts, and Sony’s A-mount being the same as Minolta’s AF mount. Or 3rd-party lens makers like Sigma, Tamron, Tokina, Zeiss, Cosina Voigtländer, Vivitar, Samyang, etc. making lenses for multiple camera mounts.

You often see people talking about how much cheaper it is to adapt older glass. Well, if all you want to use are 50mm lenses, maybe so. But the days of bargains in vintage glass pretty much disappeared when dSLRS began to do HD video and film students around the globe wanted cheap manual focus lenses of high quality (e.g., Zeiss) for their projects. And given crop factors, wide and fast are going to cost you, no matter the mount. If the lens isn’t a 50mm f/2 or f/1.8 prime and it’s supercheap, it’ll probably be one that’s tough to adapt to a dSLR mount, or has something wrong with it. And if you do save money, trust us when we tell you, you’ll be paying that savings back in inconvenience. You really really want to ask yourself if a current autofocus native-mount lens might not be a better use for your cash.

If, however, you’re into vintage collecting, or you just want to see if you can do it, and you’ve got a good sense of how to pick up vintage gear in good condition (not fungus eaten), and like doing delicate glass & metal disassembly/repair/reassembly work or know of an affordable CLA guy, maybe this will be rewarding enough to pursue. Here are the main factors to consider:

Brand is not enough to identify a lens mount. A lot of camera companies made (and make) a variety of cameras and lenses (e.g., see the Canon Camera Museum website’s Lens Hall). A lot of companies have done not just SLR lenses, but also rangefinder or possibly even medium format lenses as well. And for dSLR mounts, some companies make completely different (and incompatible) manual focus, autofocus, and/or digital mounts. Or make both mirrorless and dSLR/dSLT systems (e.g. Canon EOS vs. EOS-M, Sony A-mount vs. E-mount, etc.). In addition 3rd-party brands, such as Vivitar, also made lenses for multiple brands. Be sure that you identify the specific mounts for X and Y.

See: for a good pictorial guide on identifying common SLR lens mounts.

Typically, unless you’re happy to put up with severe vignetting, you can never adapt from a smaller system to a larger one, because the image circle the lens is designed to project is too small to cover the sensor. That is, 135 format (aka 35mm or “full-frame”) lenses can’t be adapted to medium format cameras; but medium format lenses can be adapted for 35mm/full-frame cameras. 35mm cine lenses can’t be adapted to 135 format. Some micro 4/3 users are happy to slap C-mount 1″ video lenses on their 4/3″ format cameras, because they can get f/0.95 lenses for cheap that way. But this is more of an exception than a rule. With 35mm format lenses, the other rule to remember is that you can adapt SLR lenses to rangefinders, but not rangefinders to SLRs (or mirrorless to dSLRs). This is because of registration distance.

(or, as Wikipedia puts it, “Flange Focal Distance”) is simply the mount depth. It’s how far you hold the lens away from the image plane. Each mount system is designed with a specific distance, and lenses cannot achieve focus to infinity without being held at this specific distance. If the lens is held closer, its close focusing is compromised and it may focus past infinity. If the lens is held farther away, its close focusing is enhanced, but it cannot focus to infinity (think: macro extension tubes).

Ideally, you want to maintain the full focus range of the lens by adapting from a deeper mount to a shallower one with a simple ring adapter that makes up the difference in distances and provides a physical linkage for differing bayonet flanges and/or screw threads. You can look up the registration distance for a specific mount on the Wikipedia page linked to above.

Your worst bet with dSLRs is Nikon, because Nikon’s registration distance is the second largest, (only Leica R is larger). To use most film SLR lenses, you’ll need glass element adapters or lens mount replacement kits (see Modifying Mounts section below).

With dSLRS, your best bets are Canon EOS and Olympus or Panasonic four-thirds camera mounts, which can use simple rings to adapt Nikon-F, Leica-R, Contax/Yashica, Olympus OM, Pentax K, and M42 lenses. (Actually, theoretically, four-thirds can adapt far more, but being a less popular mount system, these are the only six mounts you’ll easily find adapter rings for).

But the best bet of all are mirrorless cameras, because they have very shallow registration distances. Mirrorless mounts can adapt all dSLR mount lenses, as well as most rangefinder lenses (however, sensor stack thickness may become an issue).

But a simple ring adapter with infinity focus isn’t possible if X’s registration distance is shallower than Y’s. And may not be possible even if X is deeper than Y, because the depth difference has to be thick enough that a ring can be reliably machined to hold up.

If you try to adapt a shallower mount lens to a deeper mount body with a simple ring, this often means the lens can’t focus past 10′. If you’re not doing macro or close portrait photography with this lens and want to focus past that point, then you’re going to have to do one of two things: modify the lens’s (or camera’s) mount, or use an adapter with a glass element in it to achieve focus to infinity.

Modifying Mounts

This is actually something of a sport among vintage lens collectors. Many vintage lens enthusiasts have spanner wrenches and machine shops at their disposal and think nothing of replacing a lens’s mount with a modified adapter ring and experimenting with shims to get the proper registration distance. However, for those not willing to go quite that far, there are the Leitax lens mount replacement kits for specific lens combinations that are more popular among enthusiasts (e.g., Leica-R and Zeiss C/Y lenses to Nikon, etc.) But only a small set of X/Y combinations are liable to be found there because of this.

Adapters with Glass Elements

The other way around the registration distance issue is to use an adapter with a glass element to act like a short teleconverter. The negatives to this are that the glass acts like a short teleconverter: your focal length increases, your maximum aperture decreases, and if you get a cheap one, you’ll add softness to the image. That doesn’t mean these aren’t usable. There are a lot of happy people who use adapters with glass elements for older lenses, but these are generally folks who are willing to compromise on image quality for cost. Depending on the lens you want to adapt (say, a cheap 50mm f/2 lens vs. a US$8300 Leica-M Noctilux 50mm f/1.0), this may or may not be worth your time.

And there are, of course, a lot of other possible gotchas.

Adapter Accuracy

Remember that an adapter ring is a mechanical thing. Making one perfectly flat, a specific thickness, etc. are all going to rely heavily on the manufacturing process. These things vary. Some adapter rings have a looser fit than others. The quality you get from an adapted lens can vary depending on the precision of the adapter you’re using, and even the best of them may still have image quality compromises. See Roger Cicala’s blog entry: “There Is No Free Lunch, Episode 763: Lens Adapters”.

Mount Throat

While registration distance is important, it’s not the only factor–particularly if you’re adapting to Sony A-mount (once called the Alpha mount) dSLTs. While the Sony dSLTs have the same registration distance as Canon’s EOS mount, they cannot use those same six mounts that Canon EOS dSLRs can, because the mount throat is smaller than Canon’s, forcing the lenses to be held farther away. The only simple ring adapters for Sony A-mount you’ll find are for Leica-R and M42 (M42 is much smaller in diameter than the bayonet-type SLR mounts).

Mirror Clearance

Not all dSLRs have the same mirror clearance as their film counterparts. A lot of eager-beaver adapters for the Canon full-frame prosumer bodies discovered that some Contax/Yashica and Leica-R lenses have back elements that collide with the mirror on a 5D (all marks) or 6D body while being clear of the mirror on a crop-body or 1-series pro body. You can get around this by grinding down or “shaving” the mirror, but it’s easy to damage a body and you’ll definitely reduce its resale value by doing so–particularly if you grind down far enough for it to be seen in the viewfinder.

Obviously, if you’re shooting mirrorless, this doesn’t apply to you. Sensor stack thickness, however, does.

Sensor Stack Thickness

Roger Cicala is the one who figured this puzzler out. Certain lenses known to be great performers on film and that test as top performers (e.g., Leica-M rangefinder lenses), when adapted onto mirrorless camera bodies were showing image quality problems–particularly wide angle Leica rangefinder glass on the Sony A7 cameras. Also new mirrorless lenses that tested great on mirrorless cameras didn’t test so well on his optical test bench. He did experimentation and research into the issue, and wrote a three-part series on the sensor stack issue: “The Glass in the Path: Sensor Stacks and Adapted Lenses”, “Sensor Stack Thickness: When Does It Matter?” and “Sensor Stack Thickness Part III: The Summary”

In essence, the thickness of the glass protecting the sensor, in proportion to how far the lens’s exit pupil is from the sensor, has an effect on optical performance. He also found that his test bench didn’t have anything like a sensor stack in the optical path, and that adding one made the results of the test bench more accurate. Some mirrorless cameras (most notably micro four-thirds) have thicker stacks than you’d expect, and rangefinder lenses have much shorter entrance pupil differences, and particularly with faster lenses, there can be a notable performance drop off.

Aperture Rings

If you want to adapt to another mount, because of the lack of electronic communication (unless, say, you’re using a Metabones autofocus adapter), you lose aperture control from the camera. Regaining it is extraordinarily problematic if the lens you’re adapting doesn’t have an aperture ring (e.g., Canon EOS, micro four-thirds, Minolta AF, or Nikon G lenses). There are ways around this (with a Canon EOS lens, for example, you can mount it on a Canon body, adjust the aperture, hold down the DoF preview button, and then unmount and remount it on the adapted body, and it will retain its aperture setting), or use an adapter with a built-in iris, but they tend to be less than optimal.

Upshot: you really want an aperture ring on the lens you’re trying to adapt.

Stop-Down Metering

Because of the lack of aperture control, you may lose accurate metering. Entry level Nikon bodies cannot accurately meter with non-CPU lenses. And if your camera body does perform stop-down metering, then the lens actually has to be stopped down when getting the metering. This may require the adapter to have a pin in it that holds down a lever to stop the lens down to the aperture set with the lens ring (e.g., some Olympus OM adapter rings do this; some don’t). And no matter what happens, when you stop the lens down, the view in the viewfinder gets darker. You may need to use liveview to compose.

Manual Focusing Aids

Most modern digital system cameras are designed with autofocus in mind, and this extends to the viewfinder. If you are using a dSLR with an optical viewfinder, the focusing aids that made manual focus lenses fine for use on manual film SLRs are no longer there. Split circles and prism collars can be added, but can darken or go black in the viewfinder with slower (f/5.6) lenses. If you have an entry-level dSLR or one with an LCD overlay in the viewfinder, replacing the focusing screen is problematic at best. Your best bet may be to use liveview and features such as focus peaking or magnification, but this also makes using a manual adapted lens far less spontaneous than with a modern autofocusing native mount lens. Some adapter rings are chipped to provide AF confirmation, but user reports are varied on the efficacy of this.


Even if you get an autofocus-capable adapter that can translate and communicate the autofocus and aperture information between the lens and the camera, chances are good that the autofocus performance could be compromised (e.g., Metabones Sony A to Sony E mount adapter; Conurus Contax N to EOS adapter).


Not only do you lose aperture control and wide-open metering, but you also lose lens EXIF information such as your aperture setting or the lens’s name and focal length. Some of this information can be supplied to the camera body with a chipped adapter ring, but may require some manual setting of the aperture in each and every shot.

X=Y Special Cases

Your two best bets for using older vintage glass in the same brand directly on a current digital mount are Nikon F and Pentax K. Even the older manual focus lenses, albeit with a few restrictions, still work on those cameras.

Canon EOS and Minolta AF (aka Sony A-mount) OEM lenses from the mid-80s forward are compatible with current dSLR bodies (although 3rd party lenses may need to be rechipped); however manual focus Canon FD/FL and Minolta MD/MC have shallower mounts than EOS and Sony A, respectively.

Olympus completely changed its mount system between film cameras and digital ones, so OM mount lenses require an adapter, either for four-thirds dSLRs or micro four-thirds mirrorless.

See also:

lens – A nikkor 18-140mm AF-S vs 18-55 AF-P, 70-300mm AF-P all with VR for a camera without a focus motor?

Hi I’m getting this deal where I can either get one

  • Nikon AF-S DX NIKKOR 18-140 mm F/3.5-5.6 G ED VR

Or these two

for almost the same price as kit lenses with a nikon 5600D.

I’m pretty new to photography and I’m extremely confused between these two. Since the camera doesn’t have a built in motor all these lenses are good.

Which one would you get.

Sorry if this is too obvious, I’m new and don’t know much.

How to draw chunks of a map within view of camera

I want to draw chunks of a map in the screen when it’s visible by the camera.

I can draw a single chunk using:

map(celx, cely, screenx, screeny, 16, 16)

This draws the chunk celx cely to the screen position screenx screeny.

I can move this map where it’s drawn using:

camera(camx, camy)

This will offset the map by vector camx camy.

This is basic PICO-8 api.

For my problem, I define a world by chunks of the map:

pworld = {
   0, 1, 2, 0, 3, 4, 0, 1, 2,
   0, 3, 4, 0, 3, 4, 0, 3, 4,
   0, 1, 2, 0, 1, 2, 0, 1, 2,
   0, 1, 2, 0, 1, 2, 0, 1, 2

World is laid out by chunks of 8×4 units.

0 means chunk where celx=0 cely=0
1 means chunk where celx=1 cely=0 and so on.

Now when the camera is at say x=10,y=10 I have to draw the portion of the world indexes 1,2,9,10:
I tried to calculate this using:

function v_map(x, y)
   local i = pworld(flr(y/16)*8+flr(x/16)+1)

   local my = flr(i/8)
   local mx = i%8

   return {

and draw using:

function _draw()

  camera(cam.x, cam.y)

  local vm = v_map(camx, camy)
  map(vm(1).x, vm(1).y, 0, 0, 16, 16)
  map(vm(2).x, vm(2).y, 0, 0, 16, 16)
  map(vm(3).x, vm(3).y, 0, 0, 16, 16)
  map(vm(4).x, vm(4).y, 0, 0, 16, 16)

But this is wrong and I don’t understand how this even should work.
How do I know the indexes of the chunks to draw?
How do I know at what screen position to draw the chunks?
How does this work well with moving the camera?