LibVLC custom audio output

This forum is about all development around libVLC.
Rémi Denis-Courmont
Developer
Developer
Posts: 15323
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

LibVLC custom audio output

Postby Rémi Denis-Courmont » 10 May 2011 20:14

Hello,

I just added three new functions to make LibVLC route decoded audio samples to custom application functions: libvlc_audio_set_format, libvlc_audio_set_format_callbacks, libvlc_audio_set_callbacks. They are conceptually very similar to the existing video callbacks.

Currently, this is limited to signed 16-bits native endian samples, and the number of channels cannot be changed. But there is room for fixing that without breaking the interface. Nevertheless, if you think you'd need something else, or this is not an acceptable limitation, or you found bugs, please let me know. We still have time to adjust the interface until it gets frozen in stone with the VLC 1.2.0 release.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

Rémi Denis-Courmont
Developer
Developer
Posts: 15323
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: LibVLC custom audio output

Postby Rémi Denis-Courmont » 30 May 2011 13:45

Zero feedback this far.

Don't come and whine if it is not working the way you want after VLC 1.2.0 goes out.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

wetneb
Blank Cone
Blank Cone
Posts: 16
Joined: 07 Apr 2010 09:35

Re: LibVLC custom audio output

Postby wetneb » 13 Jun 2011 22:03

It seems nice, exactly what I needed a few months ago.
I'll check this and report.

roman808
New Cone
New Cone
Posts: 6
Joined: 28 Mar 2011 21:31

Re: LibVLC custom audio output

Postby roman808 » 24 Jun 2011 08:42

Hi,

Thanks for the new addition.
I tried to use the new API and only the setup callback gets called and the play callback never executed.
I tried it with the version from 20.6

m_instance = libvlc_new (0, NULL);
m_player = libvlc_media_player_new(m_instance);
libvlc_audio_set_callbacks(m_player , &play_cb, &set_volume_cb, NULL);
libvlc_audio_set_format_callbacks(m_player , &setup_cb, &cleanup_cb);
m_media = libvlc_media_new_path(m_player , fileName);
libvlc_media_player_set_media (m_player , m_media);
libvlc_media_player_play (m_player );

and the callbacks defined as follows:

static void set_volume_cb(void *data, float volume, bool mute)
{

}

static void play_cb(void *data, const void *samples, unsigned count, int64_t pts)
{

}

static int setup_cb(void **data, char *format, unsigned *rate, unsigned *channels)
{
return 0;
}

static void cleanup_cb(void *data)
{

}

Am I doing something wrong ?

Thanks

Rémi Denis-Courmont
Developer
Developer
Posts: 15323
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: LibVLC custom audio output

Postby Rémi Denis-Courmont » 24 Jun 2011 09:59

Looks correct. What's the verbose log?
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

roman808
New Cone
New Cone
Posts: 6
Joined: 28 Mar 2011 21:31

Re: LibVLC custom audio output

Postby roman808 » 25 Jun 2011 11:05

I am using the library on WIndows with VS2010 and log verbosity of 2 gives one and only record:

2011-06-25 11:59:13.6683 Error Failed to set on top main

shashaanktulsyan
New Cone
New Cone
Posts: 8
Joined: 10 Oct 2007 20:19
VLC version: 1.2
Operating System: Win7/KUbuntu/Mac10.5

Re: LibVLC custom audio output

Postby shashaanktulsyan » 30 Jun 2011 13:23

Same here
[051b85bc] main vout display error: Failed to set on top

The play callback function is not called at all.
BTW, I was playing with this on java using vlcj.

If someone could provide a small example it would be appreciated.

Rémi Denis-Courmont
Developer
Developer
Posts: 15323
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: LibVLC custom audio output

Postby Rémi Denis-Courmont » 04 Aug 2011 18:41

May be fixed as of today. Not tested though.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

roman808
New Cone
New Cone
Posts: 6
Joined: 28 Mar 2011 21:31

Re: LibVLC custom audio output

Postby roman808 » 13 Aug 2011 11:19

Hi Remi,

Thanks for the update
It still does not work. The setup is called and when the playback starts the application crashes.
There is nothing in the log, and the only info I have is from the Windows Event Log:

Faulting module name: unknown, version: 0.0.0.0, time stamp: 0x00000000
Exception code: 0xc0000005
Fault offset: 0x05e6e938
Faulting process id: 0x17e0
Faulting application start time: 0x01cc59995ac894f2
Faulting module path: unknown

Rémi Denis-Courmont
Developer
Developer
Posts: 15323
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: LibVLC custom audio output

Postby Rémi Denis-Courmont » 13 Aug 2011 21:09

This is utterly useless informations for me. Sorry.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

sherington
Cone that earned his stripes
Cone that earned his stripes
Posts: 491
Joined: 10 Sep 2008 11:57
VLC version: master
Operating System: Linux

Re: LibVLC custom audio output

Postby sherington » 15 Aug 2011 20:51

I can confirm that this does seem to work. In my own code I do see the play() callback being invoked repeatedly with what look like reasonable values.

This is what I do (it's Java code, but the principle would be the same for other languages of course):

Code: Select all

libvlc.libvlc_audio_set_format(mediaPlayerInstance, "S16N", 44100, 2); // play_cb is basically a function pointer in JNA libvlc_audio_play_cb play_cb = new libvlc_audio_play_cb() { @Override public void play(Pointer data, Pointer samples, int count, long pts) { Logger.info("play(data=" + data + ",samples=" + samples + ",count=" + count + ",pts=" + pts + ")"); Pointer[] sampleArray = samples.getPointerArray(0, count); for(Pointer sample : sampleArray) { // Presumably get the byte[] from the sample pointer and send it to JavaSound or somewhere else } } }; libvlc.libvlc_audio_set_callbacks( mediaPlayerInstance, play_cb, null, null, null, null, null ); } // ...then invoke play() on the media player...
I don't really use this myself, nor do I know what the use cases are - I just wanted to see if it worked, and indeed it does seem to.

roman808
New Cone
New Cone
Posts: 6
Joined: 28 Mar 2011 21:31

Re: LibVLC custom audio output

Postby roman808 » 16 Aug 2011 20:57

Yep, indeed works great :)

I didn't notice the changes made in the API. Thanks fro the update


Return to “Development around libVLC”

Who is online

Users browsing this forum: MagnetUser and 7 guests