Why postBuffers doesn't work fine sometimes

28 views
Skip to first unread message

Liu Huadong

unread,
Oct 16, 2009, 10:19:05 PM10/16/09
to android-ndk
Hi friends,
I am using SurfaceView to render a image buffer.
The image buffer is generated by a interval timer, what I need to
do is to show the image data in phone.

Surface can finish this work, the following is my steps to show
the image.

in java layer, create a view, which will driver from SurfaceView,
and get the created surface, set the type as
SURFACE_TYPE_PUSH_BUFFERS, pass the surface to JNI.

then register two buffer to this surface, when the data is
coming, will copy the image data to the framebuffer and do postBuffer.

I am puzzled, sometimes it works fine, sometimes no image show.

static void android_media_Player_setSurface(JNIEnv *env, jobject thiz)
{

jobject surface = env->GetObjectField(thiz, fields.surface);
sp<ISurface> iSurface=NULL;
if (surface != NULL)
{
const sp<Surface>& native_surface = get_surface(env, surface);
iSurface = native_surface->getISurface();
if (iSurface == m_iSurface) {
return;
}
m_iSurface.clear();
m_frameHeap.clear();
}
m_iSurface = iSurface;

if (m_iSurface.get())
{
//RGB-565 frames are 2 bytes/pixel
const sp<Surface>& native_surface = get_surface(env, surface);
int x=0; int y=0; int w=0; int h=0; int freeze=0;
m_iSurface->getSurfaceInformation(x, y, w, h, freeze);

m_heigh = h;
m_width = w;

//double buffer
int frameSize = w * h * 2 * 2;
m_frameHeap = new android::MemoryHeapBase(frameSize);
if (m_frameHeap->heapID() < 0) {
return;
}

android::ISurface::BufferHeap buffers(w, h, w, h,
android::PIXEL_FORMAT_RGB_565, m_frameHeap);
android::status_t ret = m_iSurface->registerBuffers(buffers);

m_frameBufferOffset = 0;
}
}

Here is to postBuffers, called by image generation program, we just
copy the whole region
void postBuffer(unsigned char * idata, int offset, int iLen)
{
if(m_iSurface.get())
{
unsigned char* frameAddr = static_cast<unsigned char*>
(m_frameHeap->base());
if(frameAddr != NULL)
{
if(m_frameBufferOffset == 0)
{
m_frameBufferOffset = m_width * m_heigh*2;
}
else
{
m_frameBufferOffset = 0;
}
memcpy(frameAddr + m_frameBufferOffset, idata-offset,
m_width * m_heigh * 2);

m_iSurface->postBuffer(m_frameBufferOffset);
}
}
}


Thanks
Huadong

allstars

unread,
Oct 18, 2009, 11:40:55 PM10/18/09
to android-ndk
hi
you said you use double buffer

but the MemoryHeapBase is allocated for only 1 buffer
right?
>         android::ISurface::BufferHeapbuffers(w, h, w, h,

Liu Huadong

unread,
Oct 20, 2009, 11:19:01 PM10/20/09
to android-ndk
Hi allstars,
Thanks your reply,

Current code allocate two buffer
int frameSize = w * h * 2 * 2;

Regards
Huadong

On Oct 18, 8:40 pm, allstars <allstars....@gmail.com> wrote:
> hi
> you said you use double buffer
>
> but the MemoryHeapBase is allocated for only 1 buffer
> right?
>
> On Oct 17, 10:19 am, Liu Huadong <liuhuadon...@gmail.com> wrote:
>
>
>
> > Hi friends,
> >     I am using SurfaceView to render a image buffer.
> >     The image buffer is generated by a interval timer,  what I need to
> > do is to show the image data in phone.
>
> >     Surface can finish this work,  the following is my steps to show
> > the image.
>
> >     in java layer, create a view, which will driver from SurfaceView,
> > and get the created surface, set the type as
> > SURFACE_TYPE_PUSH_BUFFERS, pass the surface to JNI.
>
> >     then register two buffer to this surface,  when the data is
> > coming, will copy the image data to theframebufferand do postBuffer.
Reply all
Reply to author
Forward
0 new messages