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

Java Development

Reply
Trusted Contributor
Posts: 224
Registered: ‎08-11-2010
My Device: Not Specified

Media recorder "wastes" around 9300 b/sec or 560 Kb/min ? - Torch device

Environment: Torch, OS 6.0.0337

During our tests on real-time media application we found that native media recorder
"wastes" considerable amount of memory:
* with updateThreshold=20 it "wastes" around 9200 b/sec or 560 Kb/min
* with updateThreshold=40 it "wastes" around 4600 b/sec or 280 Kb/min

By "wastes" I mean that this memory is used and thrown away (and later reclaimed by the GC). We expect that any resource intensive application running in environment with restricted resources should reuse it's memory objects as much as possible, but media recorder does not seem to do so.

Combined with the "partial GC" which is done at the start of every minute, this "waste" of resources means that GC will be run frequently, during which time whole system will be "blocked" (see my other thread).

Has anybody else observed such problem ?

Any suggestions on how to reduced the "wasted" memory ?

P.S. Older OS versions seem to work better, though we have not done extensive testing ...

Trusted Contributor
Posts: 224
Registered: ‎08-11-2010
My Device: Not Specified

Re: Media recorder "wastes" around 9300 b/sec or 560 Kb/min ? - Torch device

Here are some logs that show how free memory decreases over time and how it is reclaimed by the GC (reclaiming it takes over a second during which the whole system is blocked)

 

Every line display free mem, then total change in mem / time from last memory reset, and finally - the average number of bytes reserved every second

 

[2011-02-04 01:47:39 575] [ui/monit]  debug sleep exit - free: 461977864 (19), total: 0 / 0 = 0
[2011-02-04 01:47:47 916] [ui/monit]  debug sleep exit - free: 461901196 (8), total: 76668 / 8 = 9583
......
[2011-02-04 01:53:43 321] [ui/monit]  debug sleep exit - free: 458661976 (12), total: 3315888 / 363 = 9134
[2011-02-04 01:53:51 610] [ui/monit]  debug sleep exit - free: 458587592 (12), total: 3390272 / 372 = 9113
[2011-02-04 01:53:59 876] [ui/monit]  debug sleep exit - free: 458513392 (11), total: 3464472 / 380 = 9117
[2011-02-04 01:54:01 187] [ui/monit] Warning -too long - free: 462165772 (1069), total: 0 / 0 = 0
[2011-02-04 01:54:09 326] [ui/monit]  debug sleep exit - free: 462091736 (8), total: 74036 / 8 = 9254
[2011-02-04 01:54:17 585] [ui/monit]  debug sleep exit - free: 462017536 (8), total: 148236 / 16 = 9264
[2011-02-04 01:54:25 837] [ui/monit]  debug sleep exit - free: 461943336 (4), total: 222436 / 24 = 9268
......
[2011-02-04 01:55:07 044] [ui/monit]  debug sleep exit - free: 461571884 (12), total: 593888 / 65 = 9136
[2011-02-04 01:55:15 295] [ui/monit]  debug sleep exit - free: 461497684 (9), total: 668088 / 74 = 9028
[2011-02-04 01:55:23 554] [ui/monit]  debug sleep exit - free: 461423300 (12), total: 742472 / 82 = 9054
[2011-02-04 01:55:29 270] [ui/monit] Warning -too long - free: 461371632 (421), total: 794140 / 88 = 9024

 

 

Trusted Contributor
Posts: 224
Registered: ‎08-11-2010
My Device: Not Specified

Re: Media recorder "wastes" around 9300 b/sec or 560 Kb/min ? - Torch device

Below is the code that starts the player - note that recorded data is not used - it is redirected to Null stream

 

 

  private void startRecorder()
  {
    iolog("start enter - updateThreshold=20");
    try
    {
      player = javax.microedition.media.Manager.createPlayer("capture://audio?encoding=audio/amr&updateMethod=time&updateThreshold=20");

      player.realize();

      recordControl = (RecordControl)player.getControl("RecordControl");
      recordControl.setRecordStream(new NullOutputStream());

      recordControl.startRecord();
      player.start();
    }
    catch (Throwable x)
    {
      iolog("error in start", x);
    }
    iolog("start exit");
  }

 

 

Trusted Contributor
Posts: 224
Registered: ‎08-11-2010
My Device: Not Specified

Re: Media recorder "wastes" around 9300 b/sec or 560 Kb/min ? - Torch device

Update - I think that I found the main reason for this unneeded object allocation.

 

It believe that  the problem is caused by the following ******** debug snippet which was left in production code.

 

StringBuffer tmpbuf = new StringBuffer();
tmpbuf.append("Stream ");
tmpbuf.append(streamId);
tmpbuf.append(" new data");
System.out.println(tmpbuf.toString());

This code is executed 50 times per second, and creates at least two char arrays and two objects.

 

Does anybody know how  to turn off media engine debug logs (not just the printing, but the generation of the strings that will be printed)  ?

Trusted Contributor
Posts: 224
Registered: ‎08-11-2010
My Device: Not Specified

Re: Media recorder "wastes" around 9300 b/sec or 560 Kb/min ? - Torch device

 

Situation with audio player is even worse - when served with "silence amr" data, audio player seems to "waste" around 20 Kb/sec (or 1.2 Mb/min).
This memory is later reclaimed by GC (which means that whole system is blocked for a couple of seconds)

The worst offenders are two debug messages which were left in production code (see below),
but it seems that there is also some other unneeded object allocation.

 

    StringBuffer tmpbuf1 = new StringBuffer();

    tmpbuf1.append("Stream Streaming session: ");
    tmpbuf1.append(streamId);
    tmpbuf1.append(" wrote ");
    tmpbuf1.append(len);
    System.out.println(tmpbuf1.toString());

    StringBuffer tmpbuf2 = new StringBuffer();
    tmpbuf2.append("Stream ");
    tmpbuf2.append(streamId);
    tmpbuf2.append(" watermark remain=");
    tmpbuf2.append(0);
    tmpbuf2.append(" avail=");
    tmpbuf2.append(65536);
    System.out.println(tmpbuf2.toString());

 

 

Retired
Retired
Posts: 150
Registered: ‎10-19-2010
My Device: Not Specified
My Carrier: Rogers

Re: Media recorder "wastes" around 9300 b/sec or 560 Kb/min ? - Torch device

Hi KraKra!

 

I just read over your thread, and indeed there is debug code that was accidentally left on.  I have fixed it now, so thank you for that! 

 

I'm just curious, aside from the GC 'stutter' is this causing any other issues for your application?

Trusted Contributor
Posts: 224
Registered: ‎08-11-2010
My Device: Not Specified

Re: Media recorder "wastes" around 9300 b/sec or 560 Kb/min ? - Torch device

> I'm just curious, aside from the GC 'stutter' is this causing any other issues for your application?

 

The side effect of this debug code is that partial GC is run every minute.

Which causes the whole system to be "blocked" for several hundreds of milliseconds.

Which causes nasty problems in one of our applications that need to process media data in real time.

See my other thread re thread sleep

 

There is no official API to control media engine buferring, so once the GC is run and media engine detects that buffers are empy - it enters some undesired state.

 

Any idea when this fix will be included in production firmware releases ?

Retired
Retired
Posts: 150
Registered: ‎10-19-2010
My Device: Not Specified
My Carrier: Rogers

Re: Media recorder "wastes" around 9300 b/sec or 560 Kb/min ? - Torch device

> Any idea when this fix will be included in production firmware releases ?

 

Not offhand, I'm afraid those decisions are well beynd me :smileywink: 

 

If I had to guess, I'd say the next point release of the BlackBerry OS, most likely.

Developer
Posts: 18
Registered: ‎08-05-2009
My Device: Blackberry 8320

Re: Media recorder "wastes" around 9300 b/sec or 560 Kb/min ? - Torch device

is there any track issue created for this problem ?

Developer
Posts: 18
Registered: ‎08-05-2009
My Device: Blackberry 8320

Re: Media recorder "wastes" around 9300 b/sec or 560 Kb/min ? - Torch device

https://www.blackberry.com/jira/browse/JAVAAPI-1757

 

 

issue is created for this task