tdf#125821 don't crash on missing gstreamer plugins

If GStreamer can't auto-detect an audio sink via "autoaudiosink",
it'll return a nullptr. If the volume plugin is missing, then this
currently also results in a crash.

So check the gst_element_factory_make results before using the
objects and change some wrong mpPlaybin checks to the right
mpVolumeControl ones.

This works for me without any audio and volume plugins. Since we
are linked against libgstaudio, I assume the bin is always there.

Change-Id: Ide526363d810ea48d0a62539c0a435553783e34a
Reviewed-on: https://gerrit.libreoffice.org/73848
Tested-by: Jenkins
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
(cherry picked from commit 5e6af47dc87a55fea595c952ea3e59c93d0620db)
Reviewed-on: https://gerrit.libreoffice.org/73919
(cherry picked from commit 142696e71e15db3c112796c43630bdfa6c634fa0)
Reviewed-on: https://gerrit.libreoffice.org/73922
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
diff --git a/avmedia/source/gstreamer/gstplayer.cxx b/avmedia/source/gstreamer/gstplayer.cxx
index e900ed9..4c478e3 100644
--- a/avmedia/source/gstreamer/gstplayer.cxx
+++ b/avmedia/source/gstreamer/gstplayer.cxx
@@ -664,11 +664,18 @@ void Player::preparePlaybin( const OUString& rURL, GstElement *pSink )
    mpVolumeControl = gst_element_factory_make( "volume", nullptr );
    GstElement *pAudioSink = gst_element_factory_make( "autoaudiosink", nullptr );
    GstElement* pAudioOutput = gst_bin_new("audio-output-bin");
    gst_bin_add_many(GST_BIN(pAudioOutput), mpVolumeControl, pAudioSink, nullptr);
    gst_element_link(mpVolumeControl, pAudioSink);
    GstPad *pPad = gst_element_get_static_pad(mpVolumeControl, "sink");
    gst_element_add_pad(GST_ELEMENT(pAudioOutput), gst_ghost_pad_new("sink", pPad));
    gst_object_unref(GST_OBJECT(pPad));
    assert(pAudioOutput);
    if (pAudioSink)
        gst_bin_add(GST_BIN(pAudioOutput), pAudioSink);
    if (mpVolumeControl)
    {
        gst_bin_add(GST_BIN(pAudioOutput), mpVolumeControl);
        if (pAudioSink)
            gst_element_link(mpVolumeControl, pAudioSink);
        GstPad *pPad = gst_element_get_static_pad(mpVolumeControl, "sink");
        gst_element_add_pad(GST_ELEMENT(pAudioOutput), gst_ghost_pad_new("sink", pPad));
        gst_object_unref(GST_OBJECT(pPad));
    }
    g_object_set(G_OBJECT(mpPlaybin), "audio-sink", pAudioOutput, nullptr);

    if( pSink != nullptr ) // used for getting preferred size etc.
@@ -847,7 +854,7 @@ void SAL_CALL Player::setMute( sal_Bool bSet )
    SAL_INFO( "avmedia.gstreamer", AVVERSION "set mute: " << bSet << " muted: " << mbMuted << " unmuted volume: " << mnUnmutedVolume );

    // change the volume to 0 or the unmuted volume
    if(  mpPlaybin && mbMuted != bool(bSet) )
    if (mpVolumeControl && mbMuted != bool(bSet))
    {
        double nVolume = mnUnmutedVolume;
        if( bSet )
@@ -879,7 +886,7 @@ void SAL_CALL Player::setVolumeDB( sal_Int16 nVolumeDB )
    SAL_INFO( "avmedia.gstreamer", AVVERSION "set volume: " << nVolumeDB << " gst volume: " << mnUnmutedVolume );

    // change volume
    if( !mbMuted && mpPlaybin )
    if (mpVolumeControl && !mbMuted)
    {
        g_object_set( G_OBJECT( mpVolumeControl ), "volume", mnUnmutedVolume, nullptr );
    }
@@ -892,7 +899,8 @@ sal_Int16 SAL_CALL Player::getVolumeDB()

    sal_Int16 nVolumeDB(0);

    if( mpPlaybin ) {
    if (mpVolumeControl)
    {
        double nGstVolume = 0.0;

        g_object_get( G_OBJECT( mpVolumeControl ), "volume", &nGstVolume, nullptr );