From e06a90743ee8d067b0e83c84dfd24e37b1321741 Mon Sep 17 00:00:00 2001 From: Bart De Vries Date: Mon, 16 Jan 2023 16:29:09 +0100 Subject: [PATCH] [KMediaSession] disable video output for now --- .../mediabackends/gstmediabackend.cpp | 30 ++++++++++++++----- .../mediabackends/vlcmediabackend.cpp | 5 +++- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/kmediasession/mediabackends/gstmediabackend.cpp b/src/kmediasession/mediabackends/gstmediabackend.cpp index 2ffdbec4..12a30e8b 100644 --- a/src/kmediasession/mediabackends/gstmediabackend.cpp +++ b/src/kmediasession/mediabackends/gstmediabackend.cpp @@ -27,6 +27,7 @@ private: GstElement *m_playbin = nullptr; GstElement *m_audioBin = nullptr; GstElement *m_audioSink = nullptr; + GstElement *m_videoBin = nullptr; GstElement *m_videoSink = nullptr; GstElement *m_scaleTempo = nullptr; GstElement *m_audioConvert = nullptr; @@ -86,23 +87,38 @@ GstMediaBackend::GstMediaBackend(QObject *parent) d->m_scaleTempo = gst_element_factory_make("scaletempo", "scale_tempo"); d->m_audioConvert = gst_element_factory_make("audioconvert", "convert"); d->m_audioSink = gst_element_factory_make("autoaudiosink", "audio_sink"); - if (!d->m_scaleTempo || !d->m_audioConvert || !d->m_audioSink) { + d->m_videoSink = gst_element_factory_make("fakevideosink", "video_sink"); + if (!d->m_scaleTempo || !d->m_audioConvert || !d->m_audioSink || !d->m_videoSink) { qCDebug(GstMediaBackendLog) << "Not all elements could be created."; } - /* Create the sink bin, add the elements and link them */ + /* Create the audio sink bin, add the elements and link them */ d->m_audioBin = gst_bin_new("audio_sink_bin"); gst_bin_add_many(GST_BIN(d->m_audioBin), d->m_scaleTempo, d->m_audioConvert, d->m_audioSink, NULL); gst_element_link_many(d->m_scaleTempo, d->m_audioConvert, d->m_audioSink, nullptr); - GstPad *pad = gst_element_get_static_pad(d->m_scaleTempo, "sink"); - GstPad *ghost_pad = gst_ghost_pad_new("sink", pad); - gst_pad_set_active(ghost_pad, TRUE); - gst_element_add_pad(d->m_audioBin, ghost_pad); - gst_object_unref(pad); + GstPad *pad_audio = gst_element_get_static_pad(d->m_scaleTempo, "sink"); + GstPad *ghost_pad_audio = gst_ghost_pad_new("sink", pad_audio); + gst_pad_set_active(ghost_pad_audio, TRUE); + gst_element_add_pad(d->m_audioBin, ghost_pad_audio); + gst_object_unref(pad_audio); /* Set playbin's audio sink to be our sink bin */ g_object_set(GST_OBJECT(d->m_pipeline), "audio-sink", d->m_audioBin, nullptr); + /* Create the video sink bin, add the elements and link them */ + // TODO: handle video (using fakevideosink currently) + d->m_videoBin = gst_bin_new("video_sink_bin"); + gst_bin_add_many(GST_BIN(d->m_audioBin), d->m_videoSink, NULL); + // gst_element_link_many(d->m_videoSink, nullptr); // only needed when > 1 element + GstPad *pad_video = gst_element_get_static_pad(d->m_videoSink, "sink"); + GstPad *ghost_pad_video = gst_ghost_pad_new("sink", pad_video); + gst_pad_set_active(ghost_pad_video, TRUE); + gst_element_add_pad(d->m_videoBin, ghost_pad_video); + gst_object_unref(pad_video); + + /* Set playbin's audio sink to be our sink bin */ + g_object_set(GST_OBJECT(d->m_pipeline), "video-sink", d->m_videoBin, nullptr); + // get bus and connect to get messages sent through callbacks // TODO: implement fallback in case gmainloop support is not available in qt d->m_bus = gst_element_get_bus(d->m_pipeline); diff --git a/src/kmediasession/mediabackends/vlcmediabackend.cpp b/src/kmediasession/mediabackends/vlcmediabackend.cpp index 5be82f35..64b40f29 100644 --- a/src/kmediasession/mediabackends/vlcmediabackend.cpp +++ b/src/kmediasession/mediabackends/vlcmediabackend.cpp @@ -92,7 +92,10 @@ VlcMediaBackend::VlcMediaBackend(QObject *parent) qCDebug(VlcMediaBackendLog) << "VlcMediaBackend::VlcMediaBackend"; d->mKMediaSession = static_cast(parent); d->mParent = this; - d->mInstance = libvlc_new(0, nullptr); + + // TODO: handle video playback + const char *cmdLineOption = "--no-video"; + d->mInstance = libvlc_new(1, &cmdLineOption); libvlc_set_user_agent(d->mInstance, d->mKMediaSession->playerName().toUtf8().constData(), d->mKMediaSession->playerName().toUtf8().constData()); libvlc_set_app_id(d->mInstance, d->mKMediaSession->desktopEntryName().toUtf8().constData(), "1.0", d->mKMediaSession->playerName().toUtf8().constData());