Volume in pipeline

I wanted to change the volume in the first tutorial.
So I added the following lines.
But nil is thrown back to me.

pipeline = gst_parse_launch("playbin uri=https://gstreamer.freedesktop.org/data/media/sintel_trailer-480p.webm", NULL);
// new lines
GstElement *volume;
volume = gst_bin_get_by_name (GST_BIN (pipeline), "volume0");
if (volume == NULL) {
  g_print ("Please give a pipeline with a 'volume' element in it\n");
  return 1;
}

Tutorial:
https://gstreamer.freedesktop.org/documentation/tutorials/basic/hello-world.html?gi-language=c

I used the following example as a template.

Does anyone have any idea what I’m doing wrong?

In the example you linked, there is an explicit volume element in the pipeline, and it looks that up using gst_bin_get_by_name() and sets the volume on it.

While playbin provides a mechanism to set the volume of the audio stream, it does not guarantee that it will do so using a volume element. For example, on Linux, you might use pulsesink by default, and that allows you to set the volume on the stream using the PulseAudio API instead.

You want to use the GstStreamVolume interface that is provided by playbin, which will make it use whatever underlying mechanism makes sense for your pipeline.

I’ve come a step further. If I do it like this, at least

volume = gst_bin_get_by_name(GST_BIN(pipeline), "volume0");

at least there’s no more nil. But the volume doesn’t change.

pipeline := gst_parse_launch("playbin uri=file:/n4800/DATEN/Programmierung/mit_GIT/Lazarus/Tutorial/GTK4/gstreamer/Konsole/gstramer_laz/test.wav ! volume", 0);

If I create the pipeline like this, then it works.

pipeline = gst_parse_launch("filesrc location=../test.wav ! wavparse ! audioconvert ! volume ! autoaudiosink", 0);

Is it possible to adjust the volume in the URI version somehow?

playbin has a property volume. Try to use it to change volume.

Would it not be easier to get the volume by using
volume = gst_bin_get_by_interface(GST_BIN( pipeline), GST_TYPE_STREAM_VOLUME);

GST_TYPE_STREAM_VOLUME not found

...../main.c|23|error: ‘GST_TYPE_STREAM_VOLUME’ undeclared (first use in this function); did you mean ‘GST_TYPE_STREAM_FLAGS’?|

You missing an include.

No GST_TYPE_STREAM_VOLUME is defined in
gst/audio/streamvolume.h

// gcc main.c -o main `pkg-config --cflags --libs gstreamer-1.0`

#include <gst/gst.h>
#include <gst/audio/streamvolume.h>

int main () {
  GstElement * pipeline = gst_pipeline_new("audio-player");
  gst_bin_get_by_interface(GST_BIN( pipeline), GST_TYPE_STREAM_VOLUME);
}

With this code it at least compiles.
But the linker is still complaining.

gcc main.c -o main `pkg-config --cflags --libs gstreamer-1.0 gstreamer-1.0`
/usr/bin/ld: /tmp/ccN7xvZQ.o: in function `main':
main.c:(.text+0x21): undefined reference to `gst_stream_volume_get_type'
collect2: error: ld returned 1 exit status

I also have the appropriate lib on the PC

ls /usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstvolume.so
/usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstvolume.so

So I tried the following, with a -lgstvolume, but it doesn’t find it.

gcc main.c -o main `pkg-config --cflags --libs gstreamer-1.0` -lgstvolume
/usr/bin/ld: -lgstvolume cannot be found: File or directory not found
collect2: error: ld returned 1 exit status

Anyone have any idea what is still going wrong?

This is a plugin, not a lib. You can not add it with ‘-lgstvolume’.

I asked ChatGPT and it gave me the following and it was linked without errors.

gcc main.c -o main `pkg-config --cflags --libs gstreamer-1.0 gstreamer-audio-1.0`

It compiled and linked,
Did it run?
In your main function i don’t see gst_init
this is needed to get the plugins and other initialisations.