Load sound from TMemoryStream

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
78 messages Options
1234
Reply | Threaded
Open this post in threaded view
|

Re: Load sound from TMemoryStream

Phoenix
Hello,
yes, definitely is the "Result: = -1" to be changed in "Result: = 0" (for linux) but at this point it is better the earlier version.
I do not know if there is a case where offset is actually greater than 0.
Why so it also works:

function mpg_seek_url (aHandle: Pointer; Offset: Integer;
  whence: Integer): Integer; cdecl;
begin
  Result: = 0;
end;

But to be sure the old code is the best choice
Reply | Threaded
Open this post in threaded view
|

Re: Load sound from TMemoryStream

fredvs
Administrator
Hello.

OK. (but are you able to seek a url stream? With all other players that I know (example vlc), seeking is not working (stream not seekable)).

Fre;D
Reply | Threaded
Open this post in threaded view
|

Re: Load sound from TMemoryStream

Phoenix
As for "soFromEnd" it is impossible because you do not know the term.
In the current version there is "soFromCurrent".
But in theory according to the documentation:
http://www.freepascal.org/docs-html/fcl/pipes/tinputpipestream.seek.html
Also "soFromBeginning" is supportable (but I do not know what could serve).
I wanted to see if you could but some benefit but I have no ideas.

changing the topic..

1) uos_CreatePlayer(0);

2) load a file or stream

3) for some reason the user does not press the button to play

4) uos_FreePlayer(0)

= Memory Leak
Reply | Threaded
Open this post in threaded view
|

Re: Load sound from TMemoryStream

fredvs
Administrator
> = Memory Leak

OK, I will take a look (asap).

Thanks to note it.

Fre;D
Reply | Threaded
Open this post in threaded view
|

Re: Load sound from TMemoryStream

fredvs
Administrator
In reply to this post by Phoenix
> = Memory Leak

OK, fixed in last commit: 9b1e8b3..f4ffcc7

Thanks to note it.

Fre;D
Reply | Threaded
Open this post in threaded view
|

Re: Load sound from TMemoryStream

Phoenix
Hello,
Excuse for the problem of memory leak, you need an example (because there is still something)
 
Type
  TTestClass = class
   private
    line: Integer;

    procedure LoadLib;
    procedure CreateLine;

   public
    constructor Create;
    destructor Destroy; override;

    procedure LoadToLine(path: String);
    procedure PlayLine;
    procedure StopLine;
    procedure FreeLine;

  end;

  constructor TTestClass.Create;
  begin
   inherited Create;

   line:= 0;
   LoadLib;
   CreateLine;
  end;

  destructor TTestClass.Destroy;
  begin
   uos_free();

   inherited Destroy;
  end;

  procedure TTestClass.LoadLib;
  Const
   path_link = 'c:\test_data\uos\';
  Var
   fnPortAudio,
   fnSndFile: PChar;
  begin
   fnPortAudio:= PChar(path_link +'Windows\32bit\LibPortaudio-32.dll');
   fnSndFile:= PChar(path_link +'Windows\32bit\LibSndFile-32.dll');
   if uos_loadlib(fnPortAudio,fnSndFile,nil,nil,nil,nil) <> 0 then
    raise Exception.Create('');
  end;

  procedure TTestClass.CreateLine;
  begin
   uos_CreatePlayer(line);
  end;

  procedure TTestClass.LoadToLine(path: String);
  Var
   input,output: Integer;
  begin
   input:= uos_AddFromFile(line, PChar(path));
   if input = -1 then
    raise Exception.Create('');

   output:= uos_AddIntoDevOut(line,-1,-1,
             uos_InputGetSampleRate(line,input),
             uos_InputGetChannels(line,input), 0,-1);
   if output = -1 then
    raise Exception.Create('');

   uos_InputSetLevelEnable(line,input, 2);
   uos_InputAddDSPVolume(line,input, 1,1);
   uos_InputSetPositionEnable(line,input,1);
  end;

  procedure TTestClass.PlayLine;
  begin
   uos_PlayNoFree(line);
  end;

  procedure TTestClass.StopLine;
  begin
   uos_Stop(line);
  end;

  procedure TTestClass.FreeLine;
  begin
   uos_FreePlayer(line);
  end;

procedure TSSoundUOS.Test_MemoryLeak;
Var
 tc: TTestClass;
begin
 tc:= TTestClass.Create;
 try
  tc.LoadToLine('c:\test_data\uos\test.flac');

  (* IF PLAYER NOT CALL PLAY > MEMORY LEAK
  tc.PlayLine;
  Sleep(3000);
  tc.StopLine;
  *)

  Sleep(1000);
  tc.FreeLine;

 finally
  Sleep(1000);
  tc.Free;
 end;
end;  

  Thanks    
Reply | Threaded
Open this post in threaded view
|

Re: Load sound from TMemoryStream

fredvs
Administrator
Hello Phoenix.

Yes, indeed, there is still memory leak.

OK, I will re-investigate.

Write you later.

Fre;D
Reply | Threaded
Open this post in threaded view
|

Re: Load sound from TMemoryStream

fredvs
Administrator
Hello.

Could you try with last commit : 301375f..59f01b3.

If you use uos_FreePlayer() inside program or uos_Free() at end it should not have any memory leak. (I hope)

Fre;D
Reply | Threaded
Open this post in threaded view
|

Re: Load sound from TMemoryStream

Phoenix
This post was updated on .
Hello,

It works correctly

> If you use uos_FreePlayer() inside program or uos_Free() at end ...
In the case in the example, it can work even without using "tc.FreeLine;"?

 Thanks!!
Reply | Threaded
Open this post in threaded view
|

Re: Load sound from TMemoryStream

fredvs
Administrator
> In the case in the example, it can work even without using "tc.FreeLine;"?

Yes, (but you will have some memory used (for nothing) until you call uos_Free().)

Fre;D
Reply | Threaded
Open this post in threaded view
|

Re: Load sound from TMemoryStream

Phoenix
Then there is a problem: if I remove "tc.FreeLine;" crashes
Reply | Threaded
Open this post in threaded view
|

Re: Load sound from TMemoryStream

fredvs
Administrator
> Then there is a problem: if I remove "tc.FreeLine;" crashes

Where does it crash ?
Reply | Threaded
Open this post in threaded view
|

Re: Load sound from TMemoryStream

Phoenix
This post was updated on .
Hello,
I just sent you an email with all the source to see the problem

NOTE1: if you run "project1.exe" does not appear, but running on Lazarus yes

NOTE2: if you comment this code no crash
  (*
  output:= uos_AddIntoDevOut(line,-1,-1,
                  uos_InputGetSampleRate(line,input),
                  uos_InputGetChannels(line,input), 0,-1);
  if output = -1 then
   raise Exception.Create('');
  *)
Reply | Threaded
Open this post in threaded view
|

Re: Load sound from TMemoryStream

fredvs
Administrator
> I just sent you an email with all the source to see the problem

Hello.

Huh, I do not receive your mail ;-(

Fre;D
Reply | Threaded
Open this post in threaded view
|

Re: Load sound from TMemoryStream

Phoenix
Sorry, you're right was refused. I had not noticed.
I had to remove the .exe compiled to send it successfully.
Reply | Threaded
Open this post in threaded view
|

Re: Load sound from TMemoryStream

fredvs
Administrator
Hello.

Maybe try with fiensproto@gmail.com

PS: I still do not get anything from fiens@hotmail.com

Fre;D

Reply | Threaded
Open this post in threaded view
|

Re: Load sound from TMemoryStream

Phoenix
Hello, I saw your email and in theory it should go but I do not know why on my computer is not working properly.
I created an external test just to rule out other possible causes like my bug.
Probably there is something outside of uos.
Even I used FPC 3.0.2 32bit.
When I find the reason I'll let you know.

  Thank you
Reply | Threaded
Open this post in threaded view
|

Re: Load sound from TMemoryStream

fredvs
Administrator
Did you test with debugger on ?

For me, when there are lot of calculs (like with sound programs) debugger does not work properly.

Fre;D
Reply | Threaded
Open this post in threaded view
|

Re: Load sound from TMemoryStream

fredvs
Administrator
In reply to this post by Phoenix
Re-hello.

Did you try the exe that I sent you by mail ?
If yes, do you have problem too with it ?

Fre;D
Reply | Threaded
Open this post in threaded view
|

Re: Load sound from TMemoryStream

Phoenix
This post was updated on .
In reply to this post by fredvs
I tried everything
Uninstallation, 32 / 64bit, debugger,..
(I also tried it on a Win Vista 32-bit computer)
In linux it works, but in Windows ...

I eventually found a compromise

I tried to find an alternative solution for the memory leak that depended on the lack call of Thread.Start (= no destroy).
If you find interesting:

(A)
in class TuosPlayer add var "isExecute: Boolean;"
in  Tuos_Player.Create add "isExecute:= False;"
in Tuos_Player.Execute add for first:

if isExecute then
 Exit //not can call execute again
else
 isExecute:= True;

(B) modified method
Procedure Tuos_Player.FreePlayer();
begin
 if (isAssigned = True) then
 begin
  if isExecute then
  begin
   NoFree:= False;
   RTLeventSetEvent(evPause);
   Status:= 0;
  end
  //if the thread has not been started..
  else
  begin
   //..force the immediate termination to destroy
   isExecute:= True;
   Start;
  end;
 end;
end;  


I tested different combinations and it seems to work (no crash, no memory leak).
As an added also solves my problem (mystery crash) with the "play () stop () (Tuos_Player.FreePlayer())" consecutive.

> Did you try the exe that I sent you by mail ?
> If yes, do you have problem too with it ?

it works perfectly, Thanks (also my compiled works, but crash if you run it through lazarus: so I do not feel safe)
1234