diff options
author | Lev Zelenskiy <lev.zelenskiy@nokia.com> | 2012-02-16 16:54:46 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-17 07:27:55 +0100 |
commit | 6468334eb922af18f02ea196d2ac0aff00c71a74 (patch) | |
tree | e77ba31cbaf0d4c48c8621e3e3d1387ab1554e37 /src/gsttools/qgstutils.cpp | |
parent | 4c07c6330dbce356c4e7ad33cf1bfcf2a9aa07c7 (diff) |
GStreamer backend for audio decoder service.
Includes basic integration test.
Change-Id: I4c6d1dbefa1f27e107b3556a3d4da58811eeb122
Reviewed-by: Michael Goddard <michael.goddard@nokia.com>
Diffstat (limited to 'src/gsttools/qgstutils.cpp')
-rw-r--r-- | src/gsttools/qgstutils.cpp | 64 |
1 files changed, 63 insertions, 1 deletions
diff --git a/src/gsttools/qgstutils.cpp b/src/gsttools/qgstutils.cpp index 5c1276367..03c31fbdf 100644 --- a/src/gsttools/qgstutils.cpp +++ b/src/gsttools/qgstutils.cpp @@ -168,7 +168,7 @@ QSize QGstUtils::capsCorrectedResolution(const GstCaps *caps) } /*! - *Returns audio format for caps. + Returns audio format for caps. If caps doesn't have a valid audio format, an empty QAudioFormat is returned. */ @@ -251,4 +251,66 @@ QAudioFormat QGstUtils::audioFormatForCaps(const GstCaps *caps) return format; } + +/*! + Returns audio format for a buffer. + If the buffer doesn't have a valid audio format, an empty QAudioFormat is returned. +*/ + +QAudioFormat QGstUtils::audioFormatForBuffer(GstBuffer *buffer) +{ + GstCaps* caps = gst_buffer_get_caps(buffer); + if (!caps) + return QAudioFormat(); + + QAudioFormat format = QGstUtils::audioFormatForCaps(caps); + gst_caps_unref(caps); + return format; +} + + +/*! + Builds GstCaps for an audio format. + Returns 0 if the audio format is not valid. + Caller must unref GstCaps. +*/ + +GstCaps *QGstUtils::capsForAudioFormat(QAudioFormat format) +{ + GstStructure *structure = 0; + + if (format.isValid()) { + if (format.sampleType() == QAudioFormat::SignedInt || format.sampleType() == QAudioFormat::UnSignedInt) { + structure = gst_structure_new("audio/x-raw-int", NULL); + } else if (format.sampleType() == QAudioFormat::Float) { + structure = gst_structure_new("audio/x-raw-float", NULL); + } + } + + GstCaps *caps = 0; + + if (structure) { + gst_structure_set(structure, "rate", G_TYPE_INT, format.sampleRate(), NULL); + gst_structure_set(structure, "channels", G_TYPE_INT, format.channelCount(), NULL); + gst_structure_set(structure, "width", G_TYPE_INT, format.sampleSize(), NULL); + gst_structure_set(structure, "depth", G_TYPE_INT, format.sampleSize(), NULL); + + if (format.byteOrder() == QAudioFormat::LittleEndian) + gst_structure_set(structure, "endianness", G_TYPE_INT, 1234, NULL); + else if (format.byteOrder() == QAudioFormat::BigEndian) + gst_structure_set(structure, "endianness", G_TYPE_INT, 4321, NULL); + + if (format.sampleType() == QAudioFormat::SignedInt) + gst_structure_set(structure, "signed", G_TYPE_BOOLEAN, TRUE, NULL); + else if (format.sampleType() == QAudioFormat::UnSignedInt) + gst_structure_set(structure, "signed", G_TYPE_BOOLEAN, FALSE, NULL); + + caps = gst_caps_new_empty(); + Q_ASSERT(caps); + gst_caps_append_structure(caps, structure); + } + + return caps; +} + QT_END_NAMESPACE |