LibVLC Set Output Device not working (C++, R.Pi, Analog Out)

This forum is about all development around libVLC.
DrDooom
New Cone
New Cone
Posts: 5
Joined: 29 Jul 2018 13:22

LibVLC Set Output Device not working (C++, R.Pi, Analog Out)

Postby DrDooom » 30 Jul 2018 10:50

Hello everybody,

I turn to you because I need help.

I'd like to tell the LibVLC library that Alsa Sound should be used instead of PulseAudio. But this does not work / take effect.

My project:
I use the RaspberryPi with Raspian and CodeLite and C ++ (gcc). In the project I use oled display, analogue audio, nfc, ky040 rotary encoders, lis3dh accel., Rgb led, etc and everything is already wired and the classes all work.

Except with the analog audio over LibVLC I still have problems.

First, LibVLC made crackling at the beginning of playback. In addition, I could not change the audio output to "analog audio". Something has set the output exclusively to HDMI (no matter if HDMI was connected / not connected).

After some searching (I am new on the RaspberryPi) I have identified and uninstalled PulseAudio as source. The problem was solved.


But: When playing mp3 files with LibVLC I get the message:
pulse audio output error: PulseAudio server connection failure: Connection refused

of course, its not installed anymore (but sound is playing).



I use this function to load a file and create the madiaplayer + switching to alsa sound modul:

Code: Select all

libvlc_media_t *media; media = libvlc_media_new_path(inst, filename.c_str());// create a new item if(media!=NULL){ mp = libvlc_media_player_new_from_media(media);// create a media play playing environment libvlc_audio_output_set(mp, "alsa"); libvlc_audio_output_device_set(mp, "alsa", "default:CARD=ALSA"); }

I have checked if the output module and the output device are present:

Code: Select all

libvlc_audio_output_t* audio_output = libvlc_audio_output_list_get(inst); while(audio_output!=NULL){ printf("AudioOutput: %s (%s)\n", audio_output->psz_name, audio_output->psz_description); libvlc_audio_output_device_t* audio_output_device = libvlc_audio_output_device_list_get(inst, audio_output->psz_name); while(audio_output_device!=NULL){ printf(" - %s (%s)\n", audio_output_device->psz_device, audio_output_device->psz_description); audio_output_device = audio_output_device->p_next; } libvlc_audio_output_device_list_release(audio_output_device); audio_output = audio_output->p_next; } libvlc_audio_output_list_release(audio_output);

I get the following modules and devices:

Code: Select all

AudioOutput: amem (Audio memory output) AudioOutput: sndio (OpenBSD sndio audio output) AudioOutput: pulse (Pulseaudio audio output) AudioOutput: alsa (ALSA audio output) - null (Discard all samples (playback) or generate zero samples (capture)) - default:CARD=ALSA (bcm2835 ALSA, bcm2835 ALSA Default Audio Device) - sysdefault:CARD=ALSA (bcm2835 ALSA, bcm2835 ALSA Default Audio Device) - dmix:CARD=ALSA,DEV=0 (bcm2835 ALSA, bcm2835 ALSA Direct sample mixing device) - dmix:CARD=ALSA,DEV=1 (bcm2835 ALSA, bcm2835 IEC958/HDMI Direct sample mixing device) - dsnoop:CARD=ALSA,DEV=0 (bcm2835 ALSA, bcm2835 ALSA Direct sample snooping device) - dsnoop:CARD=ALSA,DEV=1 (bcm2835 ALSA, bcm2835 IEC958/HDMI Direct sample snooping device) - hw:CARD=ALSA,DEV=0 (bcm2835 ALSA, bcm2835 ALSA Direct hardware device without any conversions) - hw:CARD=ALSA,DEV=1 (bcm2835 ALSA, bcm2835 IEC958/HDMI Direct hardware device without any conversions) - plughw:CARD=ALSA,DEV=0 (bcm2835 ALSA, bcm2835 ALSA Hardware device with all software conversions) - plughw:CARD=ALSA,DEV=1 (bcm2835 ALSA, bcm2835 IEC958/HDMI Hardware device with all software conversions) - default (Default) AudioOutput: adummy (Dummy audio output) AudioOutput: afile (File audio output)


So why does libvlc_audio_output_set and libvlc_audio_output_device_set not work as it should? PulseAudio should no longer be used when playing (and thus produce no error message).

chouquette
Developer
Developer
Posts: 291
Joined: 15 Apr 2010 00:54

Re: LibVLC Set Output Device not working (C++, R.Pi, Analog Out)

Postby chouquette » 30 Jul 2018 14:54

Hi,

Most likely alsa is probbed but not selected, but we need the VLC logs to know why.

As a side note,

Code: Select all

libvlc_audio_output_device_t* audio_output_device = libvlc_audio_output_device_list_get(inst, audio_output->psz_name); while(audio_output_device!=NULL){ printf(" - %s (%s)\n", audio_output_device->psz_device, audio_output_device->psz_description); audio_output_device = audio_output_device->p_next; } libvlc_audio_output_device_list_release(audio_output_device);
will not release anything, since audio_output_device is NULL when you're calling libvlc_audio_output_device_list_release

DrDooom
New Cone
New Cone
Posts: 5
Joined: 29 Jul 2018 13:22

Re: LibVLC Set Output Device not working (C++, R.Pi, Analog Out)

Postby DrDooom » 30 Jul 2018 18:13

Thank you for the fast answer.

Oh I did not know that there is a log function.

I have activated these as follows immediately after initializing the libvlc instance:

Code: Select all

libvlc_instance_t *inst = libvlc_new(0, NULL);// load the vlc engine //.................. FILE *logfile = fopen("libvlc_logfile.log", "w"); libvlc_log_set_file(inst, logfile);
PulseAudio is noted only in two lines (4. and 9.) - row 4. '--enable-pulse' and row 9. the error:

Code: Select all

VLC media player - 2.2.6 Umbrella Copyright © 1996-2017 the VideoLAN team revision 2.2.6-0-g1aae78981c configured with ./configure '--build=arm-linux-gnueabihf' '--prefix=/usr' '--includedir=${prefix}/include' '--mandir=${prefix}/share/man' '--infodir=${prefix}/share/info' '--sysconfdir=/etc' '--localstatedir=/var' '--disable-silent-rules' '--libdir=${prefix}/lib/arm-linux-gnueabihf' '--libexecdir=${prefix}/lib/arm-linux-gnueabihf' '--disable-maintainer-mode' '--disable-dependency-tracking' '--config-cache' '--disable-update-check' '--enable-fast-install' '--docdir=/usr/share/doc/vlc-data' '--with-binary-version=2.2.6-1~deb9u1+rpi1' '--enable-a52' '--enable-aa' '--enable-bluray' '--enable-bonjour' '--enable-caca' '--enable-chromaprint' '--enable-dbus' '--enable-dca' '--enable-directfb' '--enable-dvbpsi' '--enable-dvdnav' '--enable-faad' '--enable-flac' '--enable-fluidsynth' '--enable-freerdp' '--enable-freetype' '--enable-fribidi' '--enable-gles1' '--enable-gles2' '--enable-gnutls' '--enable-jack' '--enable-kate' '--enable-libass' '--enable-libmpeg2' '--enable-libxml2' '--enable-lirc' '--enable-live555' '--enable-mad' '--enable-mkv' '--enable-mod' '--enable-mpc' '--enable-mtp' '--enable-mux_ogg' '--enable-ncurses' '--enable-notify' '--enable-ogg' '--enable-opus' '--enable-pulse' '--enable-qt' '--enable-realrtsp' '--enable-samplerate' '--enable-sdl' '--enable-sdl-image' '--enable-sftp' '--enable-shine' '--enable-shout' '--enable-skins2' '--enable-sndio' '--enable-speex' '--enable-svg' '--enable-svgdec' '--enable-taglib' '--enable-theora' '--enable-twolame' '--enable-upnp' '--enable-vcdx' '--enable-vdpau' '--enable-vnc' '--enable-vorbis' '--enable-x264' '--enable-x265' '--enable-zvbi' '--with-kde-solid=/usr/share/solid/actions/' '--disable-decklink' '--disable-dxva2' '--disable-fdkaac' '--disable-gnomevfs' '--disable-goom' '--disable-gst-decode' '--disable-libtar' '--disable-mfx' '--disable-opencv' '--disable-projectm' '--disable-schroedinger' '--disable-telx' '--disable-vpx' '--disable-vsxu' '--disable-wasapi' '--enable-alsa' '--enable-atmo' '--enable-dc1394' '--enable-dv1394' '--enable-linsys' '--enable-omxil' '--enable-udev' '--enable-v4l2' '--enable-libva' '--enable-vcd' '--enable-smbclient' '--disable-oss' '--disable-crystalhd' '--disable-mmx' '--disable-sse' '--disable-neon' '--disable-altivec' '--enable-merge-ffmpeg' 'build_alias=arm-linux-gnueabihf' 'CFLAGS=-g -O2 -fdebug-prefix-map=/vlc-2.2.6=. -fstack-protector-strong -Wformat -Werror=format-security ' 'LDFLAGS=-Wl,-z,relro -Wl,--as-needed' 'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2' 'CXXFLAGS=-g -O2 -fdebug-prefix-map=/vlc-2.2.6=. -fstack-protector-strong -Wformat -Werror=format-security ' 'OBJCFLAGS=-g -O2 -fdebug-prefix-map=/vlc-2.2.6=. -fstack-protector-strong -Wformat -Werror=format-security' 'PKG_CONFIG_PATH=/vlc-2.2.6/ffmpeg/install/lib/pkgconfig' creating audio output looking for audio output module matching "any": 6 candidates using library version 10.0.0 (compiled with version 10.0.0, protocol 32) PulseAudio server connection failure: Connection refused Available ALSA PCM devices: Discard all samples (playback) or generate zero samples (capture) (null) default (default) bcm2835 ALSA, bcm2835 ALSA Default Audio Device (sysdefault:CARD=ALSA) bcm2835 ALSA, bcm2835 ALSA Direct sample mixing device (dmix:CARD=ALSA,DEV=0) bcm2835 ALSA, bcm2835 IEC958/HDMI Direct sample mixing device (dmix:CARD=ALSA,DEV=1) bcm2835 ALSA, bcm2835 ALSA Direct sample snooping device (dsnoop:CARD=ALSA,DEV=0) bcm2835 ALSA, bcm2835 IEC958/HDMI Direct sample snooping device (dsnoop:CARD=ALSA,DEV=1) bcm2835 ALSA, bcm2835 ALSA Direct hardware device without any conversions (hw:CARD=ALSA,DEV=0) bcm2835 ALSA, bcm2835 IEC958/HDMI Direct hardware device without any conversions (hw:CARD=ALSA,DEV=1) bcm2835 ALSA, bcm2835 ALSA Hardware device with all software conversions (plughw:CARD=ALSA,DEV=0) bcm2835 ALSA, bcm2835 IEC958/HDMI Hardware device with all software conversions (plughw:CARD=ALSA,DEV=1) using audio output module "alsa" keeping audio output removing module "alsa" creating audio output looking for audio output module matching "alsa,none": 6 candidates Available ALSA PCM devices: Discard all samples (playback) or generate zero samples (capture) (null) default (default) bcm2835 ALSA, bcm2835 ALSA Default Audio Device (sysdefault:CARD=ALSA) bcm2835 ALSA, bcm2835 ALSA Direct sample mixing device (dmix:CARD=ALSA,DEV=0) bcm2835 ALSA, bcm2835 IEC958/HDMI Direct sample mixing device (dmix:CARD=ALSA,DEV=1) bcm2835 ALSA, bcm2835 ALSA Direct sample snooping device (dsnoop:CARD=ALSA,DEV=0) bcm2835 ALSA, bcm2835 IEC958/HDMI Direct sample snooping device (dsnoop:CARD=ALSA,DEV=1) bcm2835 ALSA, bcm2835 ALSA Direct hardware device without any conversions (hw:CARD=ALSA,DEV=0) bcm2835 ALSA, bcm2835 IEC958/HDMI Direct hardware device without any conversions (hw:CARD=ALSA,DEV=1) bcm2835 ALSA, bcm2835 ALSA Hardware device with all software conversions (plughw:CARD=ALSA,DEV=0) bcm2835 ALSA, bcm2835 IEC958/HDMI Hardware device with all software conversions (plughw:CARD=ALSA,DEV=1) using audio output module "alsa" keeping audio output Creating an input for 'audio.mp3' using timeshift granularity of 50 MiB, in path '/tmp' `file:///home/pi/tinybox_cpp/Debug/./Audio/audio.mp3' gives access `file' demux `' path `/home/pi/tinybox_cpp/Debug/./Audio/audio.mp3' specified demux `any' creating demux: access='file' demux='any' location='/home/pi/tinybox_cpp/Debug/./Audio/audio.mp3' file='/home/pi/tinybox_cpp/Debug/./Audio/audio.mp3' looking for access_demux module matching "file": 16 candidates no access_demux modules matched creating access 'file' location='/home/pi/tinybox_cpp/Debug/./Audio/audio.mp3', path='/home/pi/tinybox_cpp/Debug/./Audio/audio.mp3' looking for access module matching "file": 25 candidates opening file `/home/pi/tinybox_cpp/Debug/./Audio/audio.mp3' using access module "filesystem" Using stream method for AStream* starting pre-buffering received first data after 0 ms pre-buffering done 1024 bytes in 0s - 32258 KiB/s looking for stream_filter module matching "any": 9 candidates no stream_filter modules matched looking for stream_filter module matching "record": 9 candidates using stream_filter module "record" creating demux: access='file' demux='any' location='/home/pi/tinybox_cpp/Debug/./Audio/audio.mp3' file='/home/pi/tinybox_cpp/Debug/./Audio/audio.mp3' ID3v2.3 revision 0 tag found, skipping 315 bytes looking for demux module matching "any": 67 candidates detected format mpga looking for packetizer module matching "any": 23 candidates using packetizer module "mpeg_audio" MPGA channels:2 samplerate:48000 bitrate:320 selecting program id=0 using demux module "es" looking for a subtitle file in /home/pi/tinybox_cpp/Debug/./Audio/ looking for decoder module matching "any": 40 candidates using decoder module "mpeg_audio" looking for meta reader module matching "any": 2 candidates using meta reader module "taglib" removing module "taglib" `file:///home/pi/tinybox_cpp/Debug/./Audio/audio.mp3' successfully opened Buffering 0% Buffering 8% MPGA channels:2 samplerate:48000 bitrate:320 Buffering 16% reusing audio output Buffering 24% Buffering 32% Buffering 40% Buffering 48% Buffering 56% Buffering 64% Buffering 72% Buffering 80% Buffering 88% Buffering 96% Stream buffering done (312 ms in 0 ms) using ALSA device: default Hardware PCM card 0 'bcm2835 ALSA' device 0 subdevice 0 device name : bcm2835 ALSA device ID : bcm2835 ALSA subdevice name: subdevice #0 initial hardware setup: ACCESS: MMAP_INTERLEAVED RW_INTERLEAVED FORMAT: U8 S16_LE SUBFORMAT: STD SAMPLE_BITS: [8 16] FRAME_BITS: [8 32] CHANNELS: [1 2] RATE: [8000 48000] PERIOD_TIME: (5333 16384000] PERIOD_SIZE: [256 131072] PERIOD_BYTES: [1024 131072] PERIODS: [1 128] BUFFER_TIME: (5333 16384000] BUFFER_SIZE: [256 131072] BUFFER_BYTES: [1024 131072] TICK_TIME: ALL channels map not provided final HW setup: ACCESS: RW_INTERLEAVED FORMAT: S16_LE SUBFORMAT: STD SAMPLE_BITS: 16 FRAME_BITS: 32 CHANNELS: 2 RATE: 48000 PERIOD_TIME: 40000 PERIOD_SIZE: 1920 PERIOD_BYTES: 7680 PERIODS: (17 18) BUFFER_TIME: (682666 682667) BUFFER_SIZE: 32768 BUFFER_BYTES: 131072 TICK_TIME: 0 initial software parameters: tstamp_mode: NONE tstamp_type: MONOTONIC period_step: 1 avail_min: 1920 start_threshold: 1 stop_threshold: 32768 silence_threshold: 0 silence_size: 0 boundary: 1073741824 final software parameters: tstamp_mode: NONE tstamp_type: MONOTONIC period_step: 1 avail_min: 1920 start_threshold: 1 stop_threshold: 32768 silence_threshold: 0 silence_size: 0 boundary: 1073741824 device cannot be paused output 's16l' 48000 Hz Stereo frame=1 samples/4 bytes looking for audio volume module matching "any": 2 candidates using audio volume module "integer_mixer" input 'mpga' 48000 Hz Stereo frame=1152 samples/969 bytes looking for audio filter module matching "scaletempo": 14 candidates format: 48000 rate, 2 nch, 4 bps, fl32 params: 30 stride, 0.200 overlap, 14 search 1.000 scale, 1440.000 stride_in, 1440 stride_out, 1152 standing, 288 overlap, 672 search, 2400 queue, fl32 mode using audio filter module "scaletempo" conversion: 'mpga'->'f32l' 48000 Hz->48000 Hz Stereo->Stereo looking for audio converter module matching "any": 12 candidates no audio converter modules matched looking for audio converter module matching "any": 12 candidates mpga->f32l, bits per sample: 32 using audio converter module "mpgatofixed32" conversion pipeline complete conversion: 'f32l'->'s16l' 48000 Hz->48000 Hz Stereo->Stereo looking for audio converter module matching "any": 12 candidates f32l->s16l, bits per sample: 0->16 using audio converter module "audio_format" conversion pipeline complete looking for audio resampler module matching "any": 3 candidates using audio resampler module "ugly_resampler" End of audio preroll Decoder wait done in 11 ms inserting 470 zeroes
Then I think that the message is not displayed because VLC PulseAudio wants to use.....but because when initializing with parameter '--enable-pulse' is specified and is trying to load/init PulseAudio -> Error?

But how can I change these parameters? I have not specified this anywhere.

by the way: many thanks with the tip to the list and release. :O)

mfkl
Developer
Developer
Posts: 740
Joined: 13 Jun 2017 10:41

Re: LibVLC Set Output Device not working (C++, R.Pi, Analog Out)

Postby mfkl » 31 Jul 2018 04:48

how can I change these parameters?
I believe those are build/configure parameters, so you have to rebuild probably.
VLC media player - 2.2.6 Umbrella
Strongly advise to use 3.0+
https://mfkl.github.io

DrDooom
New Cone
New Cone
Posts: 5
Joined: 29 Jul 2018 13:22

Re: LibVLC Set Output Device not working (C++, R.Pi, Analog Out)

Postby DrDooom » 31 Jul 2018 09:39

I believe those are build/configure parameters, so you have to rebuild probably.
Ok, but do I have to change the parameters before?

I have seen that there is a file configure.ac:
The file looks to me as layman like an AutoConfig (ac) file which checks if PulseAudio is present and sets the parameter depending on it.

If I'm right I would just recompile?

(I'm on my way, test it later)

configure.ac:

Code: Select all

........................ EXTEND_HELP_STRING([Audio plugins:]) dnl dnl Pulseaudio module dnl AC_ARG_ENABLE(pulse, [AS_HELP_STRING([--enable-pulse], [use the PulseAudio client library (default auto)])]) have_pulse="no" AS_IF([test "${enable_pulse}" != "no"], [ PKG_CHECK_MODULES([PULSE], [libpulse >= 1.0], [ have_pulse="yes" ], [ AS_IF([test "x${enable_pulse}" != "x"], [ AC_MSG_ERROR([$PULSE_PKG_ERRORS. PulseAudio 1.0 or later required.]) ]) ]) ]) AM_CONDITIONAL([HAVE_PULSE], [test "${have_pulse}" = "yes"]) ........................
Strongly advise to use 3.0+
....thanks.... did get it via gitclone. thought it would be the latest libvlc version.

DrDooom
New Cone
New Cone
Posts: 5
Joined: 29 Jul 2018 13:22

Re: LibVLC Set Output Device not working (C++, R.Pi, Analog Out)

Postby DrDooom » 01 Aug 2018 17:33

Dont know how i got LibVLC 2.6.6...but compiling LibVLC 3 does not work. :o(

I have several problems with this ("sudo apt-get build-dep vlc" fails because of a missing url in sources.list, ./configure fails because missing libav / FFmpeg).

Is there a way to get LibVLC 3.x.x without compiling it by myself? Even if then pulseaudio must continue to be active.



By the way: Installing VLC via "sudo apt-get install vlc" install's the 'newest' Version 2.6.6!

mfkl
Developer
Developer
Posts: 740
Joined: 13 Jun 2017 10:41

Re: LibVLC Set Output Device not working (C++, R.Pi, Analog Out)

Postby mfkl » 02 Aug 2018 06:23

Is there a way to get LibVLC 3.x.x without compiling it by myself?
Not sure. Maybe just install vlc with apt-get and get libvlc from there?

Otherwise have a look at the docker files, maybe that helps https://code.videolan.org/videolan/docker-images

Though compiling vlc 3 on raspberry pi looks like problems: https://forum.videolan.org/viewtopic.php?f=13&t=142905
https://mfkl.github.io

DrDooom
New Cone
New Cone
Posts: 5
Joined: 29 Jul 2018 13:22

Re: LibVLC Set Output Device not working (C++, R.Pi, Analog Out)

Postby DrDooom » 02 Aug 2018 09:39

Not sure. Maybe just install vlc with apt-get and get libvlc from there?
Yes, i allready did that (see my previous post). I only get Version 2.6.6.

Can you explain something to the docker files. I only know Docker as a container technique under Linux. However, it seems that regular builds are being created under these Docker. But these do not seem to be downloadable.

mfkl
Developer
Developer
Posts: 740
Joined: 13 Jun 2017 10:41

Re: LibVLC Set Output Device not working (C++, R.Pi, Analog Out)

Postby mfkl » 02 Aug 2018 11:05

They're not downloadable, you need to build using docker.
https://mfkl.github.io


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 17 guests