GStreamer: fix compilation with version < 0.10.31.

Qt 5.4 and earlier required GStreamer 0.10.24 as minimum version.
Qt 5.5 added code that requires 0.10.31, this code is now ifdef'd
and we now support again 0.10.24.

Task-number: QTBUG-48353
Change-Id: Ie708a33c0515874b003ce26a3400475075d316ca
Reviewed-by: Christian Stromme <christian.stromme@theqtcompany.com>
This commit is contained in:
Yoann Lopes
2015-10-16 14:15:23 +02:00
parent 0cf41ef53f
commit 3d3d2a4967
12 changed files with 147 additions and 30 deletions

View File

@@ -148,9 +148,7 @@ GstElement *QGstreamerVideoOverlay::findBestVideoSink() const
// If none of the known video sinks are available, try to find one that implements the
// GstVideoOverlay interface and has autoplugging rank.
GList *list = gst_element_factory_list_get_elements(GST_ELEMENT_FACTORY_TYPE_SINK | GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO,
GST_RANK_MARGINAL);
GList *list = qt_gst_video_sinks();
for (GList *item = list; item != NULL; item = item->next) {
GstElementFactory *f = GST_ELEMENT_FACTORY(item->data);
@@ -242,12 +240,17 @@ void QGstreamerVideoOverlay::setRenderRectangle(const QRect &rect)
h = rect.height();
}
#if !GST_CHECK_VERSION(1,0,0)
#if GST_CHECK_VERSION(1,0,0)
if (m_videoSink && GST_IS_VIDEO_OVERLAY(m_videoSink))
gst_video_overlay_set_render_rectangle(GST_VIDEO_OVERLAY(m_videoSink), x, y, w, h);
#elif GST_CHECK_VERSION(0, 10, 29)
if (m_videoSink && GST_IS_X_OVERLAY(m_videoSink))
gst_x_overlay_set_render_rectangle(GST_X_OVERLAY(m_videoSink), x, y , w , h);
#else
if (m_videoSink && GST_IS_VIDEO_OVERLAY(m_videoSink))
gst_video_overlay_set_render_rectangle(GST_VIDEO_OVERLAY(m_videoSink), x, y, w, h);
Q_UNUSED(x)
Q_UNUSED(y)
Q_UNUSED(w)
Q_UNUSED(h)
#endif
}

View File

@@ -774,6 +774,7 @@ QSet<QString> QGstUtils::supportedMimeTypes(bool (*isValidFactory)(GstElementFac
return supportedMimeTypes;
}
#if GST_CHECK_VERSION(1, 0, 0)
namespace {
struct ColorFormat { QImage::Format imageFormat; GstVideoFormat gstFormat; };
@@ -786,6 +787,7 @@ static const ColorFormat qt_colorLookup[] =
};
}
#endif
#if GST_CHECK_VERSION(1,0,0)
QImage QGstUtils::bufferToImage(GstBuffer *buffer, const GstVideoInfo &videoInfo)
@@ -1212,6 +1214,7 @@ void QGstUtils::setMetaData(GstElement *element, const QMap<QByteArray, QVariant
tagValue.toDouble(),
NULL);
break;
#if GST_CHECK_VERSION(0, 10, 31)
case QVariant::DateTime: {
QDateTime date = tagValue.toDateTime().toLocalTime();
gst_tag_setter_add_tags(GST_TAG_SETTER(element),
@@ -1223,6 +1226,7 @@ void QGstUtils::setMetaData(GstElement *element, const QMap<QByteArray, QVariant
NULL);
break;
}
#endif
default:
break;
}
@@ -1408,8 +1412,10 @@ GstCaps *qt_gst_pad_get_caps(GstPad *pad)
{
#if GST_CHECK_VERSION(1,0,0)
return gst_pad_query_caps(pad, NULL);
#else
#elif GST_CHECK_VERSION(0, 10, 26)
return gst_pad_get_caps_reffed(pad);
#else
return gst_pad_get_caps(pad);
#endif
}
@@ -1464,6 +1470,67 @@ const gchar *qt_gst_element_get_factory_name(GstElement *element)
return name;
}
gboolean qt_gst_caps_can_intersect(const GstCaps * caps1, const GstCaps * caps2)
{
#if GST_CHECK_VERSION(0, 10, 25)
return gst_caps_can_intersect(caps1, caps2);
#else
GstCaps *intersection = gst_caps_intersect(caps1, caps2);
gboolean res = !gst_caps_is_empty(intersection);
gst_caps_unref(intersection);
return res;
#endif
}
#if !GST_CHECK_VERSION(0, 10, 31)
static gboolean qt_gst_videosink_factory_filter(GstPluginFeature *feature, gpointer)
{
guint rank;
const gchar *klass;
if (!GST_IS_ELEMENT_FACTORY(feature))
return FALSE;
klass = gst_element_factory_get_klass(GST_ELEMENT_FACTORY(feature));
if (!(strstr(klass, "Sink") && strstr(klass, "Video")))
return FALSE;
rank = gst_plugin_feature_get_rank(feature);
if (rank < GST_RANK_MARGINAL)
return FALSE;
return TRUE;
}
static gint qt_gst_compare_ranks(GstPluginFeature *f1, GstPluginFeature *f2)
{
gint diff;
diff = gst_plugin_feature_get_rank(f2) - gst_plugin_feature_get_rank(f1);
if (diff != 0)
return diff;
return strcmp(gst_plugin_feature_get_name(f2), gst_plugin_feature_get_name (f1));
}
#endif
GList *qt_gst_video_sinks()
{
GList *list = NULL;
#if GST_CHECK_VERSION(0, 10, 31)
list = gst_element_factory_list_get_elements(GST_ELEMENT_FACTORY_TYPE_SINK | GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO,
GST_RANK_MARGINAL);
#else
list = gst_registry_feature_filter(gst_registry_get_default(),
(GstPluginFeatureFilter)qt_gst_videosink_factory_filter,
FALSE, NULL);
list = g_list_sort(list, (GCompareFunc)qt_gst_compare_ranks);
#endif
return list;
}
QDebug operator <<(QDebug debug, GstCaps *caps)
{
if (caps) {

View File

@@ -376,9 +376,6 @@ void QVideoSurfaceGstSink::class_init(gpointer g_class, gpointer class_data)
sink_parent_class = reinterpret_cast<GstVideoSinkClass *>(g_type_class_peek_parent(g_class));
GstVideoSinkClass *video_sink_class = reinterpret_cast<GstVideoSinkClass *>(g_class);
video_sink_class->show_frame = QVideoSurfaceGstSink::show_frame;
GstBaseSinkClass *base_sink_class = reinterpret_cast<GstBaseSinkClass *>(g_class);
base_sink_class->get_caps = QVideoSurfaceGstSink::get_caps;
base_sink_class->set_caps = QVideoSurfaceGstSink::set_caps;
@@ -387,6 +384,14 @@ void QVideoSurfaceGstSink::class_init(gpointer g_class, gpointer class_data)
base_sink_class->stop = QVideoSurfaceGstSink::stop;
base_sink_class->unlock = QVideoSurfaceGstSink::unlock;
#if GST_CHECK_VERSION(0, 10, 25)
GstVideoSinkClass *video_sink_class = reinterpret_cast<GstVideoSinkClass *>(g_class);
video_sink_class->show_frame = QVideoSurfaceGstSink::show_frame;
#else
base_sink_class->preroll = QVideoSurfaceGstSink::preroll;
base_sink_class->render = QVideoSurfaceGstSink::render;
#endif
GstElementClass *element_class = reinterpret_cast<GstElementClass *>(g_class);
element_class->change_state = QVideoSurfaceGstSink::change_state;
@@ -674,10 +679,30 @@ gboolean QVideoSurfaceGstSink::unlock(GstBaseSink *base)
return TRUE;
}
#if GST_CHECK_VERSION(0, 10, 25)
GstFlowReturn QVideoSurfaceGstSink::show_frame(GstVideoSink *base, GstBuffer *buffer)
{
VO_SINK(base);
return sink->delegate->render(buffer);
}
#else
GstFlowReturn QVideoSurfaceGstSink::preroll(GstBaseSink *base, GstBuffer *buffer)
{
VO_SINK(base);
gboolean showPrerollFrame = true;
g_object_get(G_OBJECT(sink), "show-preroll-frame", &showPrerollFrame, NULL);
if (showPrerollFrame)
return sink->delegate->render(buffer);
return GST_FLOW_OK;
}
GstFlowReturn QVideoSurfaceGstSink::render(GstBaseSink *base, GstBuffer *buffer)
{
VO_SINK(base);
return sink->delegate->render(buffer);
}
#endif
QT_END_NAMESPACE