From 0374f0de5ec881569e463505b232b3870c0fd9d2 Mon Sep 17 00:00:00 2001 From: Lev Zelenskiy Date: Thu, 9 Feb 2012 16:50:30 +1000 Subject: GStreamer backend changes for media probing API. QGstreamerPlayerSession: Using GStreamer buffer probes to access media data. Change-Id: Ibc056283fdedaebba90456cc4e86ab63eae5f5f7 Reviewed-by: Michael Goddard --- src/gsttools/qgstutils.cpp | 87 ++++++++++++++++++++++++++++++++++- src/gsttools/qvideosurfacegstsink.cpp | 23 +++++---- 2 files changed, 99 insertions(+), 11 deletions(-) (limited to 'src/gsttools') diff --git a/src/gsttools/qgstutils.cpp b/src/gsttools/qgstutils.cpp index 5176cd96f..5c1276367 100644 --- a/src/gsttools/qgstutils.cpp +++ b/src/gsttools/qgstutils.cpp @@ -45,6 +45,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -143,7 +144,7 @@ QSize QGstUtils::capsResolution(const GstCaps *caps) /*! Returns aspect ratio corrected resolution of \a caps. - If caps doesn't have a valid size, and ampty QSize is returned. + If caps doesn't have a valid size, an empty QSize is returned. */ QSize QGstUtils::capsCorrectedResolution(const GstCaps *caps) { @@ -166,4 +167,88 @@ QSize QGstUtils::capsCorrectedResolution(const GstCaps *caps) return size; } +/*! + *Returns audio format for caps. + If caps doesn't have a valid audio format, an empty QAudioFormat is returned. +*/ + +QAudioFormat QGstUtils::audioFormatForCaps(const GstCaps *caps) +{ + const GstStructure *structure = gst_caps_get_structure(caps, 0); + + QAudioFormat format; + + if (qstrcmp(gst_structure_get_name(structure), "audio/x-raw-int") == 0) { + + format.setCodec("audio/pcm"); + + int endianness = 0; + gst_structure_get_int(structure, "endianness", &endianness); + if (endianness == 1234) + format.setByteOrder(QAudioFormat::LittleEndian); + else if (endianness == 4321) + format.setByteOrder(QAudioFormat::BigEndian); + + gboolean isSigned = FALSE; + gst_structure_get_boolean(structure, "signed", &isSigned); + if (isSigned) + format.setSampleType(QAudioFormat::SignedInt); + else + format.setSampleType(QAudioFormat::UnSignedInt); + + // Number of bits allocated per sample. + int width = 0; + gst_structure_get_int(structure, "width", &width); + + // The number of bits used per sample. This must be less than or equal to the width. + int depth = 0; + gst_structure_get_int(structure, "depth", &depth); + + if (width != depth) { + // Unsupported sample layout. + return QAudioFormat(); + } + format.setSampleSize(width); + + int rate = 0; + gst_structure_get_int(structure, "rate", &rate); + format.setSampleRate(rate); + + int channels = 0; + gst_structure_get_int(structure, "channels", &channels); + format.setChannelCount(channels); + + } else if (qstrcmp(gst_structure_get_name(structure), "audio/x-raw-float") == 0) { + + format.setCodec("audio/pcm"); + + int endianness = 0; + gst_structure_get_int(structure, "endianness", &endianness); + if (endianness == 1234) + format.setByteOrder(QAudioFormat::LittleEndian); + else if (endianness == 4321) + format.setByteOrder(QAudioFormat::BigEndian); + + format.setSampleType(QAudioFormat::Float); + + int width = 0; + gst_structure_get_int(structure, "width", &width); + + format.setSampleSize(width); + + int rate = 0; + gst_structure_get_int(structure, "rate", &rate); + format.setSampleRate(rate); + + int channels = 0; + gst_structure_get_int(structure, "channels", &channels); + format.setChannelCount(channels); + + } else { + return QAudioFormat(); + } + + return format; +} + QT_END_NAMESPACE diff --git a/src/gsttools/qvideosurfacegstsink.cpp b/src/gsttools/qvideosurfacegstsink.cpp index da11ac74a..89284628c 100644 --- a/src/gsttools/qvideosurfacegstsink.cpp +++ b/src/gsttools/qvideosurfacegstsink.cpp @@ -199,16 +199,7 @@ GstFlowReturn QVideoSurfaceGstDelegate::render(GstBuffer *buffer) m_format.frameSize(), m_format.pixelFormat()); - qint64 startTime = GST_BUFFER_TIMESTAMP(buffer); - - if (startTime >= 0) { - m_frame.setStartTime(startTime/G_GINT64_CONSTANT (1000000)); - - qint64 duration = GST_BUFFER_DURATION(buffer); - - if (duration >= 0) - m_frame.setEndTime((startTime + duration)/G_GINT64_CONSTANT (1000000)); - } + QVideoSurfaceGstSink::setFrameTimeStamps(&m_frame, buffer); m_renderReturn = GST_FLOW_OK; @@ -685,6 +676,18 @@ QVideoSurfaceFormat QVideoSurfaceGstSink::formatForCaps(GstCaps *caps, int *byte return QVideoSurfaceFormat(); } +void QVideoSurfaceGstSink::setFrameTimeStamps(QVideoFrame *frame, GstBuffer *buffer) +{ + qint64 startTime = GST_BUFFER_TIMESTAMP(buffer); + if (startTime >= 0) { + frame->setStartTime(startTime/G_GINT64_CONSTANT (1000000)); + + qint64 duration = GST_BUFFER_DURATION(buffer); + if (duration >= 0) + frame->setEndTime((startTime + duration)/G_GINT64_CONSTANT (1000000)); + } +} + void QVideoSurfaceGstSink::handleShowPrerollChange(GObject *o, GParamSpec *p, gpointer d) { Q_UNUSED(o); -- cgit v1.2.3