diff options
Diffstat (limited to 'src')
4 files changed, 50 insertions, 34 deletions
diff --git a/src/plugins/multimedia/gstreamer/common/qgst_handle_types_p.h b/src/plugins/multimedia/gstreamer/common/qgst_handle_types_p.h index 0e3525c14..af43bd4d6 100644 --- a/src/plugins/multimedia/gstreamer/common/qgst_handle_types_p.h +++ b/src/plugins/multimedia/gstreamer/common/qgst_handle_types_p.h @@ -198,6 +198,30 @@ struct QGstHandleHelper using UniqueHandle = QUniqueHandle<QGstSafeObjectHandleTraits>; }; +template <typename GstType> +struct QGstMiniObjectHandleHelper +{ + struct Traits + { + using Type = GstType *; + static constexpr Type invalidValue() noexcept { return nullptr; } + static bool close(Type handle) noexcept + { + gst_mini_object_unref(GST_MINI_OBJECT_CAST(handle)); + return true; + } + + static Type ref(Type handle) noexcept + { + gst_mini_object_ref(GST_MINI_OBJECT_CAST(handle)); + return handle; + } + }; + + using SharedHandle = QSharedHandle<Traits>; + using UniqueHandle = QUniqueHandle<Traits>; +}; + } // namespace QGstImpl using QGstClockHandle = QGstImpl::QGstHandleHelper<GstClock>::UniqueHandle; @@ -214,6 +238,7 @@ using QUniqueGstStructureHandle = QUniqueHandle<QGstImpl::QUniqueGstStructureHan using QUniqueGStringHandle = QUniqueHandle<QGstImpl::QUniqueGStringHandleTraits>; using QUniqueGErrorHandle = QUniqueHandle<QGstImpl::QUniqueGErrorHandleTraits>; using QFileDescriptorHandle = QUniqueHandle<QGstImpl::QFileDescriptorHandleTraits>; +using QGstContextHandle = QGstImpl::QGstMiniObjectHandleHelper<GstContext>::UniqueHandle; #if QT_CONFIG(gstreamer_gl) using QGstGLContextHandle = QGstImpl::QGstHandleHelper<GstGLContext>::UniqueHandle; diff --git a/src/plugins/multimedia/gstreamer/common/qgstreamermediaplayer.cpp b/src/plugins/multimedia/gstreamer/common/qgstreamermediaplayer.cpp index 92ead9eb7..df8592d8c 100644 --- a/src/plugins/multimedia/gstreamer/common/qgstreamermediaplayer.cpp +++ b/src/plugins/multimedia/gstreamer/common/qgstreamermediaplayer.cpp @@ -374,37 +374,32 @@ bool QGstreamerMediaPlayer::processBusMessage(const QGstreamerMessage &message) break; } case GST_MESSAGE_ERROR: { - GError *err; - gchar *debug; + QUniqueGErrorHandle err; + QUniqueGStringHandle debug; gst_message_parse_error(gm, &err, &debug); - if (err->domain == GST_STREAM_ERROR && err->code == GST_STREAM_ERROR_CODEC_NOT_FOUND) + if (err.get()->domain == GST_STREAM_ERROR + && err.get()->code == GST_STREAM_ERROR_CODEC_NOT_FOUND) emit error(QMediaPlayer::FormatError, tr("Cannot play stream of type: <unknown>")); else - emit error(QMediaPlayer::ResourceError, QString::fromUtf8(err->message)); + emit error(QMediaPlayer::ResourceError, QString::fromUtf8(err.get()->message)); playerPipeline.dumpGraph("error"); mediaStatusChanged(QMediaPlayer::InvalidMedia); - g_error_free(err); - g_free(debug); break; } case GST_MESSAGE_WARNING: { - GError *err; - gchar *debug; + QUniqueGErrorHandle err; + QUniqueGStringHandle debug; gst_message_parse_warning (gm, &err, &debug); qCWarning(qLcMediaPlayer) << "Warning:" << err; playerPipeline.dumpGraph("warning"); - g_error_free (err); - g_free (debug); break; } case GST_MESSAGE_INFO: { if (qLcMediaPlayer().isDebugEnabled()) { - GError *err; - gchar *debug; + QUniqueGErrorHandle err; + QUniqueGStringHandle debug; gst_message_parse_info (gm, &err, &debug); qCDebug(qLcMediaPlayer) << "Info:" << err; - g_error_free (err); - g_free (debug); } break; } diff --git a/src/plugins/multimedia/gstreamer/common/qgstreamervideosink.cpp b/src/plugins/multimedia/gstreamer/common/qgstreamervideosink.cpp index 66971a9a5..6c06ed067 100644 --- a/src/plugins/multimedia/gstreamer/common/qgstreamervideosink.cpp +++ b/src/plugins/multimedia/gstreamer/common/qgstreamervideosink.cpp @@ -4,6 +4,7 @@ #include "qgstreamervideosink_p.h" #include "qgstvideorenderersink_p.h" #include "qgstsubtitlesink_p.h" +#include <qgst_debug_p.h> #include <qgstutils_p.h> #include <rhi/qrhi.h> @@ -167,12 +168,8 @@ void QGstreamerVideoSink::updateSinkElement() void QGstreamerVideoSink::unrefGstContexts() { - if (m_gstGlDisplayContext) - gst_context_unref(m_gstGlDisplayContext); - m_gstGlDisplayContext = nullptr; - if (m_gstGlLocalContext) - gst_context_unref(m_gstGlLocalContext); - m_gstGlLocalContext = nullptr; + m_gstGlDisplayContext.close(); + m_gstGlLocalContext.close(); m_eglDisplay = nullptr; m_eglImageTargetTexture2D = nullptr; } @@ -244,26 +241,24 @@ void QGstreamerVideoSink::updateGstContexts() if (!appContext) qWarning() << "Could not create wrappped context for platform:" << glPlatform; - GError *error = nullptr; + QUniqueGErrorHandle error; QGstGLContextHandle displayContext; gst_gl_display_create_context(gstGlDisplay.get(), appContext.get(), &displayContext, &error); - if (error) { - qWarning() << "Could not create display context:" << error->message; - g_clear_error(&error); - } + if (error) + qWarning() << "Could not create display context:" << error; appContext.close(); - m_gstGlDisplayContext = gst_context_new(GST_GL_DISPLAY_CONTEXT_TYPE, false); - gst_context_set_gl_display(m_gstGlDisplayContext, gstGlDisplay.get()); + m_gstGlDisplayContext.reset(gst_context_new(GST_GL_DISPLAY_CONTEXT_TYPE, false)); + gst_context_set_gl_display(m_gstGlDisplayContext.get(), gstGlDisplay.get()); - m_gstGlLocalContext = gst_context_new("gst.gl.local_context", false); - GstStructure *structure = gst_context_writable_structure(m_gstGlLocalContext); + m_gstGlLocalContext.reset(gst_context_new("gst.gl.local_context", false)); + GstStructure *structure = gst_context_writable_structure(m_gstGlLocalContext.get()); gst_structure_set(structure, "context", GST_TYPE_GL_CONTEXT, displayContext.get(), nullptr); displayContext.close(); if (!gstPipeline.isNull()) - gst_element_set_context(gstPipeline.element(), m_gstGlLocalContext); + gst_element_set_context(gstPipeline.element(), m_gstGlLocalContext.get()); #endif // #if QT_CONFIG(gstreamer_gl) } diff --git a/src/plugins/multimedia/gstreamer/common/qgstreamervideosink_p.h b/src/plugins/multimedia/gstreamer/common/qgstreamervideosink_p.h index 730f692a1..0f27d2351 100644 --- a/src/plugins/multimedia/gstreamer/common/qgstreamervideosink_p.h +++ b/src/plugins/multimedia/gstreamer/common/qgstreamervideosink_p.h @@ -48,8 +48,8 @@ public: void setPipeline(QGstPipeline pipeline); bool inStoppedState() const; - GstContext *gstGlDisplayContext() const { return m_gstGlDisplayContext; } - GstContext *gstGlLocalContext() const { return m_gstGlLocalContext; } + GstContext *gstGlDisplayContext() const { return m_gstGlDisplayContext.get(); } + GstContext *gstGlLocalContext() const { return m_gstGlLocalContext.get(); } Qt::HANDLE eglDisplay() const { return m_eglDisplay; } QFunctionPointer eglImageTargetTexture2D() const { return m_eglImageTargetTexture2D; } @@ -73,8 +73,9 @@ private: Qt::HANDLE m_eglDisplay = nullptr; QFunctionPointer m_eglImageTargetTexture2D = nullptr; - GstContext *m_gstGlLocalContext = nullptr; - GstContext *m_gstGlDisplayContext = nullptr; + + QGstContextHandle m_gstGlLocalContext; + QGstContextHandle m_gstGlDisplayContext; }; QT_END_NAMESPACE |