Camera callbacks failing with cannot map BpMemoryHeap

1,330 views
Skip to first unread message

Onur Cinar

unread,
Jun 3, 2010, 6:41:54 PM6/3/10
to android-ndk
Hi All,

I'm working on a real-time communication application on Android
platform. Due to the nature of the application, I am accessing the
Camera device from the native space by using the Android CameraService
using the interface provided by ui/Camera.h .

On Motorola Droid, I can register the CameraListener callback, and
receive both the Preview and the Record frames without any problem.
So everything is working fine for me on Droid.

Now I'm trying to get the application running on HTC Nexus One phone.
I can still receive the callbacks, but when I try to access the actual
frame bytes through:

sp<IMemoryHeap> heap = dataPtr->getMemory(&offset, &size);

I'm getting the following errors on the log:

E/IMemory ( 451): cannot map BpMemoryHeap (binder=0x38e408),
size=1851392, fd=44 (Invalid argument)

I searched the Android platform code for the error, I found out that
it is occurring in the:

platform/frameworks/base/libs/binder/IMemory.cpp line: 319

when the mmap fails.

Since mmap was returning EINVAL, I tried to identify which actual file/
pipe/socket is the fd=44 assigned to. I looked into /proc/451/fd,
and I found out that the file descriptor 44 is not even open when I'm
getting those errors. Which clarified the reason for mmap failing, but
not why the file is no longer open.

I repeated the same test on Droid, and I looked into the list of file
descriptors, and there was no gap.

The log messages does not give any clue, so I just wanted to ask if
anyone had a similar problem before?

The strange thing is that, when I initialize the Camera, if I set the
preview callback flag FRAME_CALLBACK_FLAG_COPY_OUT_MASK, then I can
receive frames on HTC Nexus One as well (only in postData callback).
But this is something I don't want to do since the copy out is
actually doing a memcpy internally for every frame and it is big
performance issue for the application.

Thanks in advance for your help.

Regards,

-Onur



---
www.zdo.com





David Turner

unread,
Jun 3, 2010, 8:00:02 PM6/3/10
to andro...@googlegroups.com
On Thu, Jun 3, 2010 at 3:41 PM, Onur Cinar <onur....@gmail.com> wrote:
Hi All,

I'm working on a real-time communication application on Android
platform. Due to the nature of the application, I am accessing the
Camera device from the native space by using the Android CameraService
using the interface provided by ui/Camera.h .


You are accessing a private API that is likely to change between platform releases.
In other words, you are shooting yourself in the foot. Don't !

There is no supported way to access the camera from native code, sorry.
Use Java instead.
 





--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


Onur Cinar

unread,
Jun 3, 2010, 8:23:14 PM6/3/10
to android-ndk

Hi David,

The frame rate on Java is now suitable for the type of the
application, and also the engine is running in the native space and
I'm trying to avoid the JNI calls to preserve the CPU cycles as much
as I can.

Using the private API is perfectly fine for me, since the application
is not for end users.

Do you have any suggestion on the actual issue?

Regards,

-onur

On Jun 3, 5:00 pm, David Turner <di...@android.com> wrote:
> > android-ndk...@googlegroups.com<android-ndk%2Bunsu...@googlegroups.com>
> > .

David Turner

unread,
Jun 3, 2010, 8:30:59 PM6/3/10
to andro...@googlegroups.com
On Thu, Jun 3, 2010 at 5:23 PM, Onur Cinar <onur....@gmail.com> wrote:

Hi David,

The frame rate on Java is now suitable for the type of the
application, and also the engine is running in the native space and
I'm trying to avoid the JNI calls to preserve the CPU cycles as much
as I can.

I understand that, there is no supported way to do that though.
 
Using the private API is perfectly fine for me, since the application
is not for end users.

famous last words :-)
 
Do you have any suggestion on the actual issue?

it may be a permission problem, or simply that the Nexus One camera driver/hardware
doesn't allow you to map the bytes in system memory (really).

 
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.

Onur Cinar

unread,
Jun 3, 2010, 8:41:51 PM6/3/10
to android-ndk

Hi David,

On Motorola Droid, it is working perfectly fine. The mmap succeeds for
all frames, and I can access the frame bytes without any problem. The
problem is only happening with HTC devices so far. I don't know if
that's a permission issue.

I also checked the opencore library, and it seems like it is doing the
exact same method calls that I'm doing. May be there is some flag that
I'm forgetting for HTC.

I'm now experimenting with QualcommCameraHardware.cpp source file. In
case I found a solution, I will post it here.

Regards,

-onur











---
www.zdo.com

Nachiket

unread,
Jul 2, 2010, 2:32:21 PM7/2/10
to android-ndk
Hi Onur,

Can you please specify how did you access camera using the ui/Camera.h
file? I am starting up with a camera based AR application and I want
to access camera through native codes as well..!

Thanks,


On Jun 3, 5:41 pm, Onur Cinar <onur.ci...@gmail.com> wrote:
> Hi David,
>
> On Motorola Droid, it is working perfectly fine. The mmap succeeds for
> all frames, and I canaccessthe frame bytes without any problem. The

Dianne Hackborn

unread,
Jul 2, 2010, 5:06:57 PM7/2/10
to andro...@googlegroups.com
Hi,

Discussion about using private APIs really does not belong on the NDK list.  You could try on android-porting or other lists related to platform implementation.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.




--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

Dianne Hackborn

unread,
Jul 2, 2010, 5:07:53 PM7/2/10
to andro...@googlegroups.com
On Fri, Jul 2, 2010 at 11:32 AM, Nachiket <nachik...@gmail.com> wrote:
Can you please specify how did you access camera using the ui/Camera.h
file? I am starting up with a camera based AR application and I want
to access camera through native codes as well..!

So we'll say again...  an app doing this will break.  Maybe later, maybe sooner, maybe on every different phone you try it on.

Don't do this.

Onur Cinar

unread,
Jul 2, 2010, 5:31:19 PM7/2/10
to andro...@googlegroups.com

Hi Nachiket,

The ui/Camera.h is the Camera interface in the Private API of Android code. So it will make your code not portable between Android OS revisions. 

However, if you have a Motorola Droid phone,  then you can use the Video 4 Linux (V4L2) interface to access the camera, by using the linux/videodev2.h header file that is available through the NDK.   This is currently the only direct way of accessing the Camera hardware from the native space (besides JNI wrappers, etc.).   If you setup the DMA buffers and settings correctly, it will give you a good frame rate video capture,  however,  it won't do any auto adjustments for you.  But you can give it a try to see if it is sufficient for your application.

If you still would like to use the "Private API", the ui/Camera.h,  then you will need to grab the git://android.git.kernel.org/platform/frameworks/base.git for the header files.

Regards,

-onur





On Fri, Jul 2, 2010 at 11:32 AM, Nachiket <nachik...@gmail.com> wrote:

RBK

unread,
Jul 28, 2010, 6:13:44 AM7/28/10
to android-ndk
Hi Onur,

Could you please elaborate on how to setup the DMA buffers and other
settings?

Thanks and regards,
~rbk
> > android-ndk...@googlegroups.com<android-ndk%2Bunsubscribe@googlegr oups.com>
> > .

Onur Cinar

unread,
Jul 30, 2010, 1:27:18 PM7/30/10
to andro...@googlegroups.com

Hi RBK,

If you search for V4L2, or Video 4 Linux, you will find really good documentation on this interface; however, let me try to itemize the steps and the necessary V4L2 calls briefly here:

First you will need to open(2) the Camera hardware. On Motorola devices, it is the /dev/video0 device. Then you can set the resolution, etc.

To request the DMA buffers, you will need to fill the v4l2_requestbuffers stuct, and do a VIDIOC_REQBUFS ioctl request.

If you specified MMAP buffers, then for each buffer, you will need to fill v4l2_buffer struct and query with VIDIOC_QUERYBUF ioctl, and then do a mmap.

Then you will need to queue the buffers before you start streaming using VIDIOC_QBUF ioctl call.

After you start streaming, you can capture each frame with the VIDIOC_DQBUF ioctl, and then you need to return the buffer back VIDIOC_QBUF ioctl call.

V4L2 provides many other ioctl calls to do other things on the device, such as adjusting the brightness, etc. You can also query those.

The header file for V4L2 is currently distributed with the NDK, however, so far it only works with Motorola devices. You can't use this interface with HTC devices.

Regards,

-onur


To unsubscribe from this group, send email to android-ndk...@googlegroups.com.

David Turner

unread,
Jul 30, 2010, 1:53:00 PM7/30/10
to andro...@googlegroups.com
And keep in mind that Motorola is free to remove the v4l2 device driver support and replace it with anything else in a future OTA.
Also, Moto could change their v4l2 implementation if they wish so, rendering your code unusable.

In other words, be very wary about the limitations of what you are doing.
Reply all
Reply to author
Forward
0 new messages