summaryrefslogtreecommitdiffstats
path: root/src/gsttools
diff options
context:
space:
mode:
authorYoann Lopes <yoann.lopes@qt.io>2016-07-14 16:34:11 +0200
committerYoann Lopes <yoann.lopes@qt.io>2016-08-23 09:17:52 +0000
commite84c511702bb53517378fa451d40aa5b25217a2a (patch)
treedfaebb8874c8682f677cdefcebde5df110d17dd6 /src/gsttools
parent155aa8555b436f547fb73c4de11164d4d166e80d (diff)
GStreamer: move suggestedFileExtension() out of camerabin plugin
Now in QGstUtils, in order to be used from other places. Change-Id: Id8beae1b804fa22bd648e254a1ff2a1f1e455a02 Reviewed-by: Christian Stromme <christian.stromme@qt.io>
Diffstat (limited to 'src/gsttools')
-rw-r--r--src/gsttools/qgstutils.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/gsttools/qgstutils.cpp b/src/gsttools/qgstutils.cpp
index a2b35073c..902c71013 100644
--- a/src/gsttools/qgstutils.cpp
+++ b/src/gsttools/qgstutils.cpp
@@ -1429,6 +1429,40 @@ QPair<qreal, qreal> QGstUtils::structureFrameRateRange(const GstStructure *s)
return rate;
}
+typedef QMap<QString, QString> FileExtensionMap;
+Q_GLOBAL_STATIC(FileExtensionMap, fileExtensionMap)
+
+QString QGstUtils::fileExtensionForMimeType(const QString &mimeType)
+{
+ if (fileExtensionMap->isEmpty()) {
+ //extension for containers hard to guess from mimetype
+ fileExtensionMap->insert("video/x-matroska", "mkv");
+ fileExtensionMap->insert("video/quicktime", "mov");
+ fileExtensionMap->insert("video/x-msvideo", "avi");
+ fileExtensionMap->insert("video/msvideo", "avi");
+ fileExtensionMap->insert("audio/mpeg", "mp3");
+ fileExtensionMap->insert("application/x-shockwave-flash", "swf");
+ fileExtensionMap->insert("application/x-pn-realmedia", "rm");
+ }
+
+ //for container names like avi instead of video/x-msvideo, use it as extension
+ if (!mimeType.contains('/'))
+ return mimeType;
+
+ QString format = mimeType.left(mimeType.indexOf(','));
+ QString extension = fileExtensionMap->value(format);
+
+ if (!extension.isEmpty() || format.isEmpty())
+ return extension;
+
+ QRegExp rx("[-/]([\\w]+)$");
+
+ if (rx.indexIn(format) != -1)
+ extension = rx.cap(1);
+
+ return extension;
+}
+
void qt_gst_object_ref_sink(gpointer object)
{
#if GST_CHECK_VERSION(0,10,24)