basic-tutorial-3: Add audioresample

If the sink chosen by autoaudiosink doesn't do resampling internally,
the pipeline may fail. In this specific case, someone on Windows had
configured their sound card to 96000 instead of 48000 and the tutorial
was failing.

Thanks to Olivi55 from IRC for reporting.
This commit is contained in:
Vivia Nikolaidou 2020-01-27 15:53:27 +02:00
parent 218157ffcf
commit b008abee2e

View file

@ -279,6 +279,7 @@ This is a forward reference, to be used later.
/* Create the elements */ /* Create the elements */
data.source = gst_element_factory_make ("uridecodebin", "source"); data.source = gst_element_factory_make ("uridecodebin", "source");
data.convert = gst_element_factory_make ("audioconvert", "convert"); data.convert = gst_element_factory_make ("audioconvert", "convert");
data.resample = gst_element_factory_make ("audioresample", "resample");
data.sink = gst_element_factory_make ("autoaudiosink", "sink"); data.sink = gst_element_factory_make ("autoaudiosink", "sink");
``` ```
@ -293,6 +294,11 @@ making sure that this example will work on any platform, since the
format produced by the audio decoder might not be the same that the format produced by the audio decoder might not be the same that the
audio sink expects. audio sink expects.
`audioresample` is useful for converting between different audio sample rates,
similarly making sure that this example will work on any platform, since the
audio sample rate produced by the audio decoder might not be one that the audio
sink supports.
The `autoaudiosink` is the equivalent of `autovideosink` seen in the The `autoaudiosink` is the equivalent of `autovideosink` seen in the
previous tutorial, for audio. It will render the audio stream to the previous tutorial, for audio. It will render the audio stream to the
audio card. audio card.
@ -401,11 +407,11 @@ if (!g_str_has_prefix (new_pad_type, "audio/x-raw")) {
} }
``` ```
Now we will check the type of data this new pad is going to output, Now we will check the type of data this new pad is going to output, because we
because we are only interested in pads producing audio. We have are only interested in pads producing audio. We have previously created a
previously created a piece of pipeline which deals with audio (an piece of pipeline which deals with audio (an `audioconvert` linked with an
`audioconvert` linked with an `autoaudiosink`), and we will not be able `audioresample` and an `autoaudiosink`), and we will not be able to link it to
to link it to a pad producing video, for example. a pad producing video, for example.
`gst_pad_get_current_caps()` retrieves the current *capabilities* of the pad `gst_pad_get_current_caps()` retrieves the current *capabilities* of the pad
(that is, the kind of data it currently outputs), wrapped in a `GstCaps` (that is, the kind of data it currently outputs), wrapped in a `GstCaps`