gdk: cleanups and fix rowstride
Fix the output rowstride, we need to take the stride of the output video frame. Since we are also dealing with planes, take the plane data and stride. Don't store the same info twice in different variables.
This commit is contained in:
parent
4d8002e9c4
commit
1f0cf56c8b
@ -93,14 +93,13 @@ gst_gdk_pixbuf_sink_setcaps (GstGdkPixbuf * filter, GstCaps * caps)
|
|||||||
s = gst_caps_get_structure (caps, 0);
|
s = gst_caps_get_structure (caps, 0);
|
||||||
|
|
||||||
if ((framerate = gst_structure_get_value (s, "framerate")) != NULL) {
|
if ((framerate = gst_structure_get_value (s, "framerate")) != NULL) {
|
||||||
filter->framerate_numerator = gst_value_get_fraction_numerator (framerate);
|
filter->in_fps_n = gst_value_get_fraction_numerator (framerate);
|
||||||
filter->framerate_denominator =
|
filter->in_fps_d = gst_value_get_fraction_denominator (framerate);
|
||||||
gst_value_get_fraction_denominator (framerate);
|
|
||||||
GST_DEBUG_OBJECT (filter, "got framerate of %d/%d fps => packetized mode",
|
GST_DEBUG_OBJECT (filter, "got framerate of %d/%d fps => packetized mode",
|
||||||
filter->framerate_numerator, filter->framerate_denominator);
|
filter->in_fps_n, filter->in_fps_d);
|
||||||
} else {
|
} else {
|
||||||
filter->framerate_numerator = 0;
|
filter->in_fps_n = 0;
|
||||||
filter->framerate_denominator = 1;
|
filter->in_fps_d = 1;
|
||||||
GST_DEBUG_OBJECT (filter, "no framerate, assuming single image");
|
GST_DEBUG_OBJECT (filter, "no framerate, assuming single image");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,9 +276,10 @@ gst_gdk_pixbuf_flush (GstGdkPixbuf * filter)
|
|||||||
int y;
|
int y;
|
||||||
guint8 *out_pix;
|
guint8 *out_pix;
|
||||||
guint8 *in_pix;
|
guint8 *in_pix;
|
||||||
int in_rowstride;
|
int in_rowstride, out_rowstride;
|
||||||
GstFlowReturn ret;
|
GstFlowReturn ret;
|
||||||
GstCaps *caps = NULL;
|
GstCaps *caps = NULL;
|
||||||
|
gint width, height;
|
||||||
gint n_channels;
|
gint n_channels;
|
||||||
GstVideoFrame frame;
|
GstVideoFrame frame;
|
||||||
|
|
||||||
@ -287,13 +287,14 @@ gst_gdk_pixbuf_flush (GstGdkPixbuf * filter)
|
|||||||
if (pixbuf == NULL)
|
if (pixbuf == NULL)
|
||||||
goto no_pixbuf;
|
goto no_pixbuf;
|
||||||
|
|
||||||
if (filter->width == 0) {
|
width = gdk_pixbuf_get_width (pixbuf);
|
||||||
|
height = gdk_pixbuf_get_height (pixbuf);
|
||||||
|
|
||||||
|
if (GST_VIDEO_INFO_FORMAT (&filter->info) == GST_VIDEO_FORMAT_UNKNOWN) {
|
||||||
GstVideoInfo info;
|
GstVideoInfo info;
|
||||||
GstVideoFormat fmt;
|
GstVideoFormat fmt;
|
||||||
|
|
||||||
filter->width = gdk_pixbuf_get_width (pixbuf);
|
GST_DEBUG ("Set size to %dx%d", width, height);
|
||||||
filter->height = gdk_pixbuf_get_height (pixbuf);
|
|
||||||
GST_DEBUG ("Set size to %dx%d", filter->width, filter->height);
|
|
||||||
|
|
||||||
n_channels = gdk_pixbuf_get_n_channels (pixbuf);
|
n_channels = gdk_pixbuf_get_n_channels (pixbuf);
|
||||||
switch (n_channels) {
|
switch (n_channels) {
|
||||||
@ -309,13 +310,11 @@ gst_gdk_pixbuf_flush (GstGdkPixbuf * filter)
|
|||||||
|
|
||||||
|
|
||||||
gst_video_info_init (&info);
|
gst_video_info_init (&info);
|
||||||
gst_video_info_set_format (&info, fmt, filter->width, filter->height);
|
gst_video_info_set_format (&info, fmt, width, height);
|
||||||
info.fps_n = filter->framerate_numerator;
|
info.fps_n = filter->in_fps_n;
|
||||||
info.fps_d = filter->framerate_denominator;
|
info.fps_d = filter->in_fps_d;
|
||||||
caps = gst_video_info_to_caps (&info);
|
caps = gst_video_info_to_caps (&info);
|
||||||
|
|
||||||
filter->channels = n_channels;
|
|
||||||
filter->rowstride = GST_VIDEO_INFO_COMP_STRIDE (&info, 0);
|
|
||||||
filter->info = info;
|
filter->info = info;
|
||||||
|
|
||||||
gst_pad_set_caps (filter->srcpad, caps);
|
gst_pad_set_caps (filter->srcpad, caps);
|
||||||
@ -335,12 +334,13 @@ gst_gdk_pixbuf_flush (GstGdkPixbuf * filter)
|
|||||||
in_rowstride = gdk_pixbuf_get_rowstride (pixbuf);
|
in_rowstride = gdk_pixbuf_get_rowstride (pixbuf);
|
||||||
|
|
||||||
gst_video_frame_map (&frame, &filter->info, outbuf, GST_MAP_WRITE);
|
gst_video_frame_map (&frame, &filter->info, outbuf, GST_MAP_WRITE);
|
||||||
out_pix = GST_VIDEO_FRAME_COMP_DATA (&frame, 0);
|
out_pix = GST_VIDEO_FRAME_PLANE_DATA (&frame, 0);
|
||||||
|
out_rowstride = GST_VIDEO_FRAME_PLANE_STRIDE (&frame, 0);
|
||||||
|
|
||||||
for (y = 0; y < filter->height; y++) {
|
for (y = 0; y < height; y++) {
|
||||||
memcpy (out_pix, in_pix, filter->width * filter->channels);
|
memcpy (out_pix, in_pix, width * GST_VIDEO_FRAME_COMP_PSTRIDE (&frame, 0));
|
||||||
in_pix += in_rowstride;
|
in_pix += in_rowstride;
|
||||||
out_pix += filter->rowstride;
|
out_pix += out_rowstride;
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_video_frame_unmap (&frame);
|
gst_video_frame_unmap (&frame);
|
||||||
@ -457,7 +457,7 @@ gst_gdk_pixbuf_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
|
|||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
/* packetised mode? */
|
/* packetised mode? */
|
||||||
if (filter->framerate_numerator != 0) {
|
if (filter->in_fps_n != 0) {
|
||||||
gdk_pixbuf_loader_close (filter->pixbuf_loader, NULL);
|
gdk_pixbuf_loader_close (filter->pixbuf_loader, NULL);
|
||||||
ret = gst_gdk_pixbuf_flush (filter);
|
ret = gst_gdk_pixbuf_flush (filter);
|
||||||
g_object_unref (filter->pixbuf_loader);
|
g_object_unref (filter->pixbuf_loader);
|
||||||
@ -490,8 +490,9 @@ gst_gdk_pixbuf_change_state (GstElement * element, GstStateChange transition)
|
|||||||
switch (transition) {
|
switch (transition) {
|
||||||
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
||||||
/* default to single image mode, setcaps function might not be called */
|
/* default to single image mode, setcaps function might not be called */
|
||||||
dec->framerate_numerator = 0;
|
dec->in_fps_n = 0;
|
||||||
dec->framerate_denominator = 1;
|
dec->in_fps_d = 1;
|
||||||
|
gst_video_info_init (&dec->info);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -503,8 +504,8 @@ gst_gdk_pixbuf_change_state (GstElement * element, GstStateChange transition)
|
|||||||
|
|
||||||
switch (transition) {
|
switch (transition) {
|
||||||
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
||||||
dec->framerate_numerator = 0;
|
dec->in_fps_n = 0;
|
||||||
dec->framerate_denominator = 0;
|
dec->in_fps_d = 0;
|
||||||
if (dec->pool) {
|
if (dec->pool) {
|
||||||
gst_buffer_pool_set_active (dec->pool, FALSE);
|
gst_buffer_pool_set_active (dec->pool, FALSE);
|
||||||
gst_object_replace ((GstObject **) & dec->pool, NULL);
|
gst_object_replace ((GstObject **) & dec->pool, NULL);
|
||||||
|
@ -49,16 +49,10 @@ struct _GstGdkPixbuf
|
|||||||
GstClockTime last_timestamp;
|
GstClockTime last_timestamp;
|
||||||
GdkPixbufLoader *pixbuf_loader;
|
GdkPixbufLoader *pixbuf_loader;
|
||||||
|
|
||||||
int width;
|
gint in_fps_n, in_fps_d;
|
||||||
int height;
|
|
||||||
int rowstride;
|
|
||||||
int channels;
|
|
||||||
|
|
||||||
GstVideoInfo info;
|
GstVideoInfo info;
|
||||||
GstBufferPool *pool;
|
GstBufferPool *pool;
|
||||||
|
|
||||||
gint framerate_numerator;
|
|
||||||
gint framerate_denominator;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstGdkPixbufClass
|
struct _GstGdkPixbufClass
|
||||||
|
Loading…
x
Reference in New Issue
Block a user