Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 580
Registered: ‎04-01-2009
My Device: Z10, PlayBook
My Carrier: NA
Accepted Solution

Threading, PlayBook performance, etc.

I'm in the middle of making my fist NDK PlayBook app...

 

I have three threads in addition to the main thread:

 

1) A graphics thread decoding and displaying images.

2) An audio thread playing a WAV file.

3) A network thread downloading data.

 

As I've been working on this app, up until now I've only had the graphics thread and the network thread running. That worked great. I get a nice frame rate.

 

I then started working on the audio thread, and likewise, that seemed to work along side the network thread.

 

However, when I have all three threads running, everything falls apart.  The audio constantly cuts out.  The video constantly freezes, etc, etc.

 

This is the first time I've tried creating such a demanding app, and I was really hoping the PlayBook was up to it given that it's C code, and the PlayBook is dual core.  For example, I wouldn't think that playing a WAV file would be very much work for a thread, so I was hoping the network transfers and audio could be handled easily by 1 CPU core, while the jpeg decoding could be handled by the other.

 

Any thoughts / recommendations?

 

Any help would be most appreciated.

 

Thanks,

Daniel

Developer
Posts: 101
Registered: ‎02-25-2011
My Device: Playbook, q5, z10
My Carrier: TM

Re: Threading, PlayBook performance, etc.

how do you play audio ?

do you use a framework for it ? if you use a framework, which one?

________________
mappau Dev Team
blackberry@mappau.com
twitter: mappau
Highlighted
Developer
Posts: 580
Registered: ‎04-01-2009
My Device: Z10, PlayBook
My Carrier: NA

Re: Threading, PlayBook performance, etc.

I'm using the code from the "PlayWav" example app:

 

https://bdsc.webapps.blackberry.com/native/sampleapps

 

... except that I've adapted it to read from an in-memory buffer instead of a file stream.

Developer
Posts: 101
Registered: ‎02-25-2011
My Device: Playbook, q5, z10
My Carrier: TM

Re: Threading, PlayBook performance, etc.

i'm using openAl without any loss of frames (50-60 fps), also during rendering and some network connection in the background.

 

________________
mappau Dev Team
blackberry@mappau.com
twitter: mappau
BlackBerry Development Advisor
Posts: 668
Registered: ‎11-29-2011
My Device: developer
My Carrier: other

Re: Threading, PlayBook performance, etc.

Have you tried tuning your thread priorities?  Give the audio thread higher priority.

Scheduling is round-robin if the threads are all at the same priority, and if you have 3 threads on 2 cores, 2 threads will be competing at some point.

 

Read up on using pthread_attr_t with pthread_create().  See pthread_attr_setschedpolicy() and pthread_attr_setschedparam().  Setting priority to getprio(getpid()) + 1  will probably be sufficient.

 

I would also suggest investigating using larger audio block sizes, but it looks like the PlayWav example may already be using the max frag size advertised by the pcm device.  Smaller block sizes means your thread has to wake up more often in order to keep the pcm pipeline full.

 

Cheers,

Sean

Developer
Posts: 580
Registered: ‎04-01-2009
My Device: Z10, PlayBook
My Carrier: NA

Re: Threading, PlayBook performance, etc.