pylonsrc: avoid memcpy by wrapping buffer
This commit is contained in:
parent
2a07d3df60
commit
ef66205b40
@ -38,16 +38,9 @@
|
|||||||
#include "gstpylonsrc.h"
|
#include "gstpylonsrc.h"
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <malloc.h> //malloc
|
|
||||||
#include <string.h> //memcpy, strcmp
|
|
||||||
|
|
||||||
#include "common/genicampixelformat.h"
|
#include "common/genicampixelformat.h"
|
||||||
|
|
||||||
#ifdef HAVE_ORC
|
|
||||||
#include <orc/orc.h>
|
|
||||||
#else
|
|
||||||
#define orc_memcpy(a,b,c) memcpy(a,b,c)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* PylonC */
|
/* PylonC */
|
||||||
_Bool pylonc_reset_camera (GstPylonSrc * src);
|
_Bool pylonc_reset_camera (GstPylonSrc * src);
|
||||||
@ -58,7 +51,6 @@ void pylonc_print_camera_info (GstPylonSrc * src,
|
|||||||
void pylonc_terminate ();
|
void pylonc_terminate ();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* debug category */
|
/* debug category */
|
||||||
GST_DEBUG_CATEGORY_STATIC (gst_pylonsrc_debug_category);
|
GST_DEBUG_CATEGORY_STATIC (gst_pylonsrc_debug_category);
|
||||||
#define GST_CAT_DEFAULT gst_pylonsrc_debug_category
|
#define GST_CAT_DEFAULT gst_pylonsrc_debug_category
|
||||||
@ -2726,15 +2718,38 @@ error:
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
GstPylonSrc *src;
|
||||||
|
PYLON_STREAMBUFFER_HANDLE buffer_handle;
|
||||||
|
} VideoFrame;
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
video_frame_free (void *data)
|
||||||
|
{
|
||||||
|
VideoFrame *frame = (VideoFrame *) data;
|
||||||
|
GstPylonSrc *src = frame->src;
|
||||||
|
GENAPIC_RESULT res;
|
||||||
|
|
||||||
|
// Release frame's memory
|
||||||
|
res =
|
||||||
|
PylonStreamGrabberQueueBuffer (src->streamGrabber, frame->buffer_handle,
|
||||||
|
NULL);
|
||||||
|
PYLONC_CHECK_ERROR (src, res);
|
||||||
|
g_free (frame);
|
||||||
|
|
||||||
|
error:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
gst_pylonsrc_create (GstPushSrc * psrc, GstBuffer ** buf)
|
gst_pylonsrc_create (GstPushSrc * psrc, GstBuffer ** buf)
|
||||||
{
|
{
|
||||||
GstPylonSrc *src = GST_PYLONSRC (psrc);
|
GstPylonSrc *src = GST_PYLONSRC (psrc);
|
||||||
GENAPIC_RESULT res;
|
GENAPIC_RESULT res;
|
||||||
size_t bufferIndex;
|
|
||||||
PylonGrabResult_t grabResult;
|
PylonGrabResult_t grabResult;
|
||||||
_Bool bufferReady;
|
_Bool bufferReady;
|
||||||
GstMapInfo mapInfo;
|
|
||||||
|
|
||||||
if (!src->acquisition_configured) {
|
if (!src->acquisition_configured) {
|
||||||
if (!gst_pylonsrc_configure_start_acquisition (src))
|
if (!gst_pylonsrc_configure_start_acquisition (src))
|
||||||
@ -2776,21 +2791,16 @@ gst_pylonsrc_create (GstPushSrc * psrc, GstBuffer ** buf)
|
|||||||
PYLONC_CHECK_ERROR (src, res);
|
PYLONC_CHECK_ERROR (src, res);
|
||||||
}
|
}
|
||||||
// Process the current buffer
|
// Process the current buffer
|
||||||
bufferIndex = (size_t) grabResult.Context;
|
|
||||||
if (grabResult.Status == Grabbed) {
|
if (grabResult.Status == Grabbed) {
|
||||||
//TODO: See if I can avoid memcopy and record directly into the gst buffer map.
|
VideoFrame *vf = (VideoFrame *) g_malloc0 (sizeof (VideoFrame));
|
||||||
|
|
||||||
// Copy the image into the buffer that will be passed onto the next GStreamer element
|
*buf =
|
||||||
*buf = gst_buffer_new_and_alloc (src->payloadSize);
|
gst_buffer_new_wrapped_full ((GstMemoryFlags) GST_MEMORY_FLAG_READONLY,
|
||||||
gst_buffer_map (*buf, &mapInfo, GST_MAP_WRITE);
|
(gpointer) grabResult.pBuffer, src->payloadSize, 0, src->payloadSize,
|
||||||
orc_memcpy (mapInfo.data, grabResult.pBuffer, mapInfo.size);
|
vf, (GDestroyNotify) video_frame_free);
|
||||||
gst_buffer_unmap (*buf, &mapInfo);
|
|
||||||
|
|
||||||
// Release frame's memory
|
vf->buffer_handle = grabResult.hBuffer;
|
||||||
res =
|
vf->src = src;
|
||||||
PylonStreamGrabberQueueBuffer (src->streamGrabber, grabResult.hBuffer,
|
|
||||||
(void *) bufferIndex);
|
|
||||||
PYLONC_CHECK_ERROR (src, res);
|
|
||||||
} else {
|
} else {
|
||||||
GST_ERROR_OBJECT (src, "Error in the image processing loop. Status=%d",
|
GST_ERROR_OBJECT (src, "Error in the image processing loop. Status=%d",
|
||||||
grabResult.Status);
|
grabResult.Status);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user