Page 1 of 1
LibVLC custom audio output
Posted: 10 May 2011 20:14
by Rémi Denis-Courmont
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.
Re: LibVLC custom audio output
Posted: 30 May 2011 13:45
by Rémi Denis-Courmont
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.
Re: LibVLC custom audio output
Posted: 13 Jun 2011 22:03
by wetneb
It seems nice, exactly what I needed a few months ago.
I'll check this and report.
Re: LibVLC custom audio output
Posted: 24 Jun 2011 08:42
by roman808
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
Re: LibVLC custom audio output
Posted: 24 Jun 2011 09:59
by Rémi Denis-Courmont
Looks correct. What's the verbose log?
Re: LibVLC custom audio output
Posted: 25 Jun 2011 11:05
by roman808
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
Re: LibVLC custom audio output
Posted: 30 Jun 2011 13:23
by shashaanktulsyan
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.
Re: LibVLC custom audio output
Posted: 04 Aug 2011 18:41
by Rémi Denis-Courmont
May be fixed as of today. Not tested though.
Re: LibVLC custom audio output
Posted: 13 Aug 2011 11:19
by roman808
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
Re: LibVLC custom audio output
Posted: 13 Aug 2011 21:09
by Rémi Denis-Courmont
This is utterly useless informations for me. Sorry.
Re: LibVLC custom audio output
Posted: 15 Aug 2011 20:51
by sherington
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.
Re: LibVLC custom audio output
Posted: 16 Aug 2011 20:57
by roman808
Yep, indeed works great
I didn't notice the changes made in the API. Thanks fro the update