Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [SOLVED] JOAL & Streaming = memory leaking?  (Read 2474 times)
0 Members and 1 Guest are viewing this topic.
Offline ho

Senior Newbie





« Posted 2006-07-21 14:00:12 »

hi, i hope someone of you guys can help me or point me in the right direction.

first here's my setup:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
      

//if it's the first time we pass this section here the source is initialised with 2 buffers (this two buffers are different to the buffers which are used for the queuing)
if (!environmentSource.isInit()){
   System.out.println("Init");
        //This function inits the buffers with the start data of a wav file
  queueBuffers = ressMan.getBufferInitQueue(2, sourceID, queueBuffers);
   //Then i queue the buffers up on the source          
  environmentSource.queueBuffers(queueBuffers);          
    environmentSource.setInit(true);
}


//Here's the part where the things go wrong
//I made it similar to the update() method in http://home.halden.net/tombr/ogg/OggPlayer.java        
if ((environmentSource.getBuffersProcessed()>0)){

      //This is the buffer which will be queued next on the source (do i need a existing one here, or can i use a newly generated?)
     environmentSource.queueBuffer = OpenALFactory.generateBuffers(1);            
   
     //Now i trie to unqueue the new generated buffer          
     environmentSource.unqueueBuffers(environmentSource.queueBuffer);
   
     //Load data to the buffer            
    ressMan.getBufferQueue(1, sourceID, environmentSource.queueBuffer);
   
     //Queue the buffer          
    environmentSource.queueBuffers( environmentSource.queueBuffer);
}


as u can see i'm using some functions from the Audio3D package provided with JOAL (i extendet them a little bit, just for my needs).
all buffer variables are Sound3D.Buffers, the loading of the data from the wav file works really fine. i also hear the sound and the streaming works but
i get a linear increase of memory usage because of calling:

1  
environmentSource.queueBuffer = OpenALFactory.generateBuffers(1);


every time the source processed a buffer, but the unqeue function isn't releasing the memory of the Buffer, i also tried to reuse the buffer but with the effect that only the data from the initialisation is queued each time?

it would be very helpful if someone could explain me what the alSourceUnqueueBuffers() really does (and how to use it in JOAL)?
 and maybe how the streaming really works! And please don't point me to tutorials which are written in C++, i already read them and they're all using pointers to queue the buffers on the sources, since there are no pointers in java, this won't help me, unless you know how to do something simillar in java.

it would really help me if you could port me this 2 functions to JOAL
 
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
bool ogg_stream::update()
{
    int processed;
    bool active = true;
 
    alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed);
 
    while(processed--)
    {
        ALuint buffer;
       
        alSourceUnqueueBuffers(source, 1, &buffer);
        check();
 
        active = stream(buffer);
 
        alSourceQueueBuffers(source, 1, &buffer);
        check();
    }
 
    return active;
}


bool ogg_stream::stream(ALuint buffer)
{
    char data[BUFFER_SIZE];
    int  size = 0;
    int  section;
    int  result;
 
    while(size < BUFFER_SIZE)
    {
        result = ov_read(&oggStream, data + size, BUFFER_SIZE - size, 0, 2, 1, & section);
   
        if(result > 0)
            size += result;
        else
            if(result < 0)
                throw oggString(result);
            else
                break;
    }
   
    if(size == 0)
        return false;
 
    alBufferData(buffer, format, data, size, vorbisInfo->rate);
    check();
 
    return false;
}


i really hope someone can explain it to me!
thanks in advance
martin
Offline Ken Russell

JGO Coder




Java games rock!


« Reply #1 - Posted 2006-07-21 22:53:06 »

Just FYI, when you see a C OpenAL routine passing a pointer to an int or similar, in order to call the same routine from JOAL you need to allocate a 1-element int[], put your value as element 0 of that array, and pass the array (plus a 0 "offset" argument) to the associated Java binding.
Offline Ultraq

Junior Member




That's what she said


« Reply #2 - Posted 2006-07-21 23:56:35 »

it would be very helpful if someone could explain me what the alSourceUnqueueBuffers() really does (and how to use it in JOAL)?

Taken from the OpenAL 1.1 Programmer's Guide w/ EFX SDK:

Quote
[size=10pt]
alSourceUnqueueBuffers

Description
This function unqueues a set of buffers attached to a source. The number of processed buffers can be detected using an alSourcei call to retrieve AL_BUFFERS_PROCESSED, which is the maximum number of buffers that can be unqueued using this call.

void alSourceUnqueueBuffers(
    ALuint source,
    ALsizei n,
    ALuint* buffers
);

Parameters
source - the name of the source to unqueue buffers from
n - the number of buffers to be unqueued
buffers - a pointer to an array of buffer names that were removed

Possible Error States
AL_INVALID_VALUE - At least one buffer can not be unqueued because it has not been processed yet.
AL_INVALID_NAME - The specified source name is not valid.
AL_INVALID_OPERATION - There is no current context.

Version Requirements
OpenAL 1.0 or higher

Remarks
The unqueue operation will only take place if all n buffers can be removed from the queue.[/size]

My understanding from this description is that unqueue buffers pulls-off buffers from what the source will play, only if the buffer has already been processed.
The thing is, unqueueing a buffer will not free-up memory.  Memory can only be freed if a source or buffer is destroyed.  Maybe, once the buffer has been played, you can unqueue it and then destroy the buffer.

Ultraq's Final MooCow
Bits and Pieces by Emanuel Rabina
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ho

Senior Newbie





« Reply #3 - Posted 2006-07-22 08:35:59 »

thank you guys for your answers, they should help me a lot!

as far as i understand now things should work like this:

1. i have to initialise the source with an array of int values, bind some data to them, and queue them up on the source using alSourceQueueBuffers()
2. i check if a buffer has been processed by the source via the alGetSourcei() method
3. if a buffer has been processed i can now call the alSourceUnqueueBuffers() method with a new int [] array which the function fills with the id from the unqueued buffer
4. i can  bind some new data to it using the al.alBufferData()
5. i queue the new initialised buffer to the source using alSourceQueueBuffers()
6. repeat steps 2-6 until there is no more data to stream from a file.

i hope i now understand it in the right way.

thanks very much
martin
Offline ho

Senior Newbie





« Reply #4 - Posted 2006-07-22 12:24:09 »

as i described in the previous post, this is how it works.  Smiley

thank you Ken & Ultraq for pointing me in the right direction!
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (21 views)
2014-09-12 09:08:26

Norakomi (55 views)
2014-09-10 13:57:51

TehJavaDev (66 views)
2014-09-10 06:39:09

Tekkerue (33 views)
2014-09-09 02:24:56

mitcheeb (54 views)
2014-09-08 06:06:29

BurntPizza (38 views)
2014-09-07 01:13:42

Longarmx (24 views)
2014-09-07 01:12:14

Longarmx (30 views)
2014-09-07 01:11:22

Longarmx (28 views)
2014-09-07 01:10:19

mitcheeb (37 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!