Skip to content

Commit

Permalink
Add crop
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Clark committed Jan 15, 2012
1 parent fafa4b5 commit eacf590
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
41 changes: 37 additions & 4 deletions plugins/multimedia/gstreamer/qvideosurfacegstsink.cpp
Expand Up @@ -384,7 +384,7 @@ void QVideoSurfaceGstSink::class_init(gpointer g_class, gpointer class_data)
base_sink_class->start = QVideoSurfaceGstSink::start;
base_sink_class->stop = QVideoSurfaceGstSink::stop;
// base_sink_class->unlock = QVideoSurfaceGstSink::unlock; // Not implemented.
// base_sink_class->event = QVideoSurfaceGstSink::event; // Not implemented.
base_sink_class->event = QVideoSurfaceGstSink::event;
base_sink_class->preroll = QVideoSurfaceGstSink::preroll;
base_sink_class->render = QVideoSurfaceGstSink::render;

Expand Down Expand Up @@ -727,10 +727,43 @@ gboolean QVideoSurfaceGstSink::unlock(GstBaseSink *base)

gboolean QVideoSurfaceGstSink::event(GstBaseSink *base, GstEvent *event)
{
Q_UNUSED(base);
Q_UNUSED(event);
GstEventType type = GST_EVENT_TYPE (event);
VO_SINK(base);

return TRUE;
#define GST_CROP_EXTENSION
#ifdef GST_CROP_EXTENSION
if (type == GST_EVENT_CROP) {
int bytesPerLine = sink->delegate->m_bytesPerLine;
QVideoSurfaceFormat format = sink->delegate->m_format;
gint top, left, width, height;

gst_event_parse_crop (event, &top, &left, &width, &height);

format.setViewport(QRect(left, top, width, height));

if (sink->delegate->isActive()) {
sink->delegate->stop();
}

#ifdef DEBUG_VIDEO_SURFACE_SINK
qDebug() << "Cropping video surface, format:";
qDebug() << format;
#endif

if (sink->delegate->start(format, bytesPerLine))
return TRUE;
else
qWarning() << "Failed to start video surface";

return TRUE;
}
#endif

if (GST_BASE_SINK_CLASS(sink_parent_class)->event) {
return GST_BASE_SINK_CLASS(sink_parent_class)->event (base, event);
} else {
return TRUE;
}
}

GstFlowReturn QVideoSurfaceGstSink::preroll(GstBaseSink *base, GstBuffer *buffer)
Expand Down
5 changes: 3 additions & 2 deletions plugins/multimedia/gstreamer/qvideosurfacegstsink.h
Expand Up @@ -80,6 +80,9 @@ class QVideoSurfaceGstDelegate : public QObject

GstFlowReturn render(GstBuffer *buffer);

QVideoSurfaceFormat m_format;
int m_bytesPerLine;

private slots:
void queuedStart();
void queuedStop();
Expand All @@ -94,10 +97,8 @@ private slots:
QMutex m_mutex;
QWaitCondition m_setupCondition;
QWaitCondition m_renderCondition;
QVideoSurfaceFormat m_format;
QVideoFrame m_frame;
GstFlowReturn m_renderReturn;
int m_bytesPerLine;
bool m_started;
};

Expand Down

0 comments on commit eacf590

Please sign in to comment.