From deab3d26ba41b3c76cf3c73c6ac77f814fb22571 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ole=20Andr=C3=A9=20Vadla=20Ravn=C3=A5s?= Date: Wed, 7 May 2008 14:56:22 +0000 Subject: [PATCH] sys/directdraw/gstdirectdrawsink.c Original commit message from CVS: * sys/directdraw/gstdirectdrawsink.c (gst_directdraw_sink_buffer_alloc): Make it so that gst_directdraw_sink_buffer_alloc uses the right width/height. Especially when looking through the pool of buffers, make sure that the width/height of caps is used instead of the already negotiated dimensions. For example if a buffer with different caps is requested, i.e. higher resolution, the caller would get a buffer with the old dimensions and thus corrupt the heap. --- ChangeLog | 14 ++++++++++++++ sys/directdraw/gstdirectdrawsink.c | 18 +++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7d8619a..84e5b66 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,20 @@ * sys/directdraw/gstdirectdrawsink.c (gst_directdraw_sink_buffer_alloc): + Make it so that gst_directdraw_sink_buffer_alloc uses the right + width/height. + + Especially when looking through the pool of buffers, make sure that + the width/height of caps is used instead of the already negotiated + dimensions. + For example if a buffer with different caps is requested, i.e. + higher resolution, the caller would get a buffer with the old + dimensions and thus corrupt the heap. + +2008-05-07 Ole André Vadla Ravnås + + * sys/directdraw/gstdirectdrawsink.c + (gst_directdraw_sink_buffer_alloc): Clear the flags on recycled buffers from buffer_alloc. Partially fixes #520885. diff --git a/sys/directdraw/gstdirectdrawsink.c b/sys/directdraw/gstdirectdrawsink.c index a39e033..9d34cf2 100644 --- a/sys/directdraw/gstdirectdrawsink.c +++ b/sys/directdraw/gstdirectdrawsink.c @@ -572,6 +572,8 @@ gst_directdraw_sink_buffer_alloc (GstBaseSink * bsink, guint64 offset, guint size, GstCaps * caps, GstBuffer ** buf) { GstDirectDrawSink *ddrawsink = GST_DIRECTDRAW_SINK (bsink); + GstStructure *structure; + gint width, height; GstDDrawSurface *surface = NULL; GstFlowReturn ret = GST_FLOW_OK; GstCaps *buffer_caps = caps; @@ -580,6 +582,14 @@ gst_directdraw_sink_buffer_alloc (GstBaseSink * bsink, guint64 offset, GST_CAT_INFO_OBJECT (directdrawsink_debug, ddrawsink, "a buffer of %u bytes was requested", size); + structure = gst_caps_get_structure (caps, 0); + if (!gst_structure_get_int (structure, "width", &width) || + !gst_structure_get_int (structure, "height", &height)) { + GST_WARNING_OBJECT (ddrawsink, "invalid caps for buffer allocation %" + GST_PTR_FORMAT, caps); + return GST_FLOW_UNEXPECTED; + } + g_mutex_lock (ddrawsink->pool_lock); /* Inspect our buffer pool */ @@ -591,8 +601,8 @@ gst_directdraw_sink_buffer_alloc (GstBaseSink * bsink, guint64 offset, ddrawsink->buffer_pool); /* If the surface is invalid for our need, destroy */ - if ((surface->width != ddrawsink->video_width) || - (surface->height != ddrawsink->video_height) || + if ((surface->width != width) || + (surface->height != height) || (memcmp (&surface->dd_pixel_format, &ddrawsink->dd_pixel_format, sizeof (DDPIXELFORMAT)) || !gst_directdraw_sink_surface_check (ddrawsink, surface)) @@ -615,9 +625,7 @@ gst_directdraw_sink_buffer_alloc (GstBaseSink * bsink, guint64 offset, HRESULT hres; DDSURFACEDESC2 surface_desc; DDSURFACEDESC2 *sd; - GstStructure *structure = NULL; - structure = gst_caps_get_structure (caps, 0); if (!gst_structure_get_int (structure, "depth", &depth)) { GST_CAT_DEBUG_OBJECT (directdrawsink_debug, ddrawsink, "Can't get depth from buffer_alloc caps"); @@ -673,7 +681,7 @@ gst_directdraw_sink_buffer_alloc (GstBaseSink * bsink, guint64 offset, buffer_caps = copy_caps; buffercaps_unref = TRUE; /* update buffer size needed to store video frames according to new caps */ - size = ddrawsink->video_width * ddrawsink->video_height * (bpp / 8); + size = width * height * (bpp / 8); /* update our member pixel format */ gst_ddrawvideosink_get_format_from_caps (ddrawsink, buffer_caps, -- 2.7.4