edtpdvsrc: create source for EDT PDV frame grabbers

This commit is contained in:
Joshua M. Doe 2013-10-31 16:09:07 -04:00
parent f11372da5a
commit da31713498
7 changed files with 571 additions and 2 deletions

View File

@ -0,0 +1,49 @@
# - Try to find EDT API
# Once done this will define
#
# EDT_FOUND - system has EDT API
# EDT_INCLUDE_DIR - the EDT API include directory
# EDT_LIBRARIES - the libraries needed to use the EDT API
# Copyright (c) 2006, Tim Beaulen <tbscope@gmail.com>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
IF (EDT_INCLUDE_DIR AND EDT_LIBRARIES)
# in cache already
SET(EDT_FIND_QUIETLY TRUE)
ELSE (EDT_INCLUDE_DIR AND EDT_LIBRARIES)
SET(EDT_FIND_QUIETLY FALSE)
ENDIF (EDT_INCLUDE_DIR AND EDT_LIBRARIES)
IF (NOT EDT_DIR)
SET (EDT_DIR "C:/EDT" CACHE PATH "Directory containing EDT API")
ENDIF (NOT EDT_DIR)
FIND_PATH (EDT_INCLUDE_DIR edtinc.h
PATHS
"${EDT_DIR}/pdv"
DOC "Directory containing edtinc.h include file")
FIND_LIBRARY (EDT_LIBRARIES NAMES pdvlib
PATHS
"${EDT_DIR}/lib"
DOC "EDT library to link with")
IF (EDT_INCLUDE_DIR)
#MESSAGE(STATUS "DEBUG: Found Euresys Multicam include dir: ${EDT_INCLUDE_DIR}")
ELSE (EDT_INCLUDE_DIR)
MESSAGE(STATUS "EDT: WARNING: include dir not found")
ENDIF (EDT_INCLUDE_DIR)
IF (EDT_LIBRARIES)
#MESSAGE(STATUS "DEBUG: Found Euresys Multicam library: ${EDT_LIBRARIES}")
ELSE (EDT_LIBRARIES)
MESSAGE(STATUS "EDT: WARNING: library not found")
ENDIF (EDT_LIBRARIES)
INCLUDE (FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS (EDT DEFAULT_MSG EDT_INCLUDE_DIR EDT_LIBRARIES)
MARK_AS_ADVANCED(EDT_INCLUDE_DIR EDT_LIBRARIES)

26
sys/edt/CMakeLists.txt Normal file
View File

@ -0,0 +1,26 @@
add_definitions(-DHAVE_CONFIG_H)
set ( SOURCES
gstedtpdvsrc.c )
set ( HEADERS
gstedtpdvsrc.h )
include_directories ( AFTER
.
${EDT_INCLUDE_DIR} )
add_library ( libgstedt MODULE
${SOURCES}
${HEADERS} )
target_link_libraries ( libgsteuresys
${GLIB2_LIBRARIES}
${GSTREAMER_LIBRARIES}
${GSTREAMER_BASE_LIBRARY}
${GSTREAMER_INTERFACE_LIBRARY}
${GSTREAMER_VIDEO_LIBRARY}
${EDT_LIBRARIES})
install (TARGETS libgsteuresys
LIBRARY DESTINATION lib/gstreamer-0.10)

View File

@ -3,6 +3,7 @@
#endif
#include "gstedtpdvsink.h"
#include "gstedtpdvsrc.h"
#define GST_CAT_DEFAULT gst_gstedt_debug
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
@ -18,6 +19,11 @@ plugin_init (GstPlugin * plugin)
return FALSE;
}
if (!gst_element_register (plugin, "edtpdvsrc", GST_RANK_NONE,
GST_TYPE_EDT_PDV_SRC)) {
return FALSE;
}
return TRUE;
}
@ -25,4 +31,4 @@ GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR,
edt,
"EDT PDV elements",
plugin_init, VERSION, "LGPL", PACKAGE_NAME, GST_PACKAGE_ORIGIN)
plugin_init, VERSION, "LGPL", PACKAGE_NAME, GST_PACKAGE_ORIGIN)

407
sys/edt/gstedtpdvsrc.c Normal file
View File

@ -0,0 +1,407 @@
/* GStreamer
* Copyright (C) 2011 FIXME <fixme@example.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Suite 500,
* Boston, MA 02110-1335, USA.
*/
/**
* SECTION:element-gstedt_pdv_src
*
* The edtpdvsrc element is a source for EDT framegrabbers supported by the EDT PDV library.
*
* <refsect2>
* <title>Example launch line</title>
* |[
* gst-launch -v edtpdvsrc ! ffmpegcolorspace ! autovideosink
* ]|
* Shows video from the default camera source (unit 0, channel 0).
* </refsect2>
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gst/gst.h>
#include <gst/base/gstpushsrc.h>
#include <gst/video/video.h>
#include "gstedtpdvsrc.h"
GST_DEBUG_CATEGORY_STATIC (gst_edt_pdv_src_debug);
#define GST_CAT_DEFAULT gst_edt_pdv_src_debug
/* prototypes */
static void gst_edt_pdv_src_set_property (GObject * object,
guint property_id, const GValue * value, GParamSpec * pspec);
static void gst_edt_pdv_src_get_property (GObject * object,
guint property_id, GValue * value, GParamSpec * pspec);
static void gst_edt_pdv_src_dispose (GObject * object);
static void gst_edt_pdv_src_finalize (GObject * object);
static gboolean gst_edt_pdv_src_start (GstBaseSrc * src);
static gboolean gst_edt_pdv_src_stop (GstBaseSrc * src);
static GstCaps *gst_edt_pdv_src_get_caps (GstBaseSrc * src, GstCaps * filter);
static gboolean gst_edt_pdv_src_set_caps (GstBaseSrc * src, GstCaps * caps);
static GstFlowReturn gst_edt_pdv_src_create (GstPushSrc * src,
GstBuffer ** buf);
static GstCaps *gst_edt_pdv_src_create_caps (GstEdtPdvSrc * src);
static void gst_edt_pdv_src_reset (GstEdtPdvSrc * src);
enum
{
PROP_0,
PROP_UNIT,
PROP_CHANNEL
};
#define DEFAULT_PROP_UNIT 0
#define DEFAULT_PROP_CHANNEL 0
/* pad templates */
static GstStaticPadTemplate gst_edt_pdv_src_src_template =
GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE
("{ GRAY8, GRAY16_LE, GRAY16_BE, RGB }"))
);
/* class initialization */
G_DEFINE_TYPE (GstEdtPdvSrc, gst_edt_pdv_src, GST_TYPE_PUSH_SRC);
static void
gst_edt_pdv_src_class_init (GstEdtPdvSrcClass * klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
GstBaseSrcClass *gstbasesrc_class = GST_BASE_SRC_CLASS (klass);
GstPushSrcClass *gstpushsrc_class = GST_PUSH_SRC_CLASS (klass);
GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "edtpdvsrc", 0,
"EDT PDV Camera Link source");
gobject_class->set_property = gst_edt_pdv_src_set_property;
gobject_class->get_property = gst_edt_pdv_src_get_property;
gobject_class->dispose = gst_edt_pdv_src_dispose;
gobject_class->finalize = gst_edt_pdv_src_finalize;
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&gst_edt_pdv_src_src_template));
gst_element_class_set_static_metadata (gstelement_class,
"EDT PDV Video Source", "Source/Video",
"EDT PDV framegrabber video source", "Joshua M. Doe <oss@nvl.army.mil>");
gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_edt_pdv_src_start);
gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_edt_pdv_src_stop);
gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_edt_pdv_src_get_caps);
gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_edt_pdv_src_set_caps);
gstpushsrc_class->create = GST_DEBUG_FUNCPTR (gst_edt_pdv_src_create);
/* Install GObject properties */
g_object_class_install_property (gobject_class, PROP_UNIT,
g_param_spec_uint ("unit", "Unit", "Unit number", 0, G_MAXUINT,
DEFAULT_PROP_UNIT,
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
GST_PARAM_MUTABLE_READY)));
g_object_class_install_property (gobject_class, PROP_CHANNEL,
g_param_spec_uint ("channel", "Channel", "Channel number (0 for auto)", 0,
G_MAXUINT, DEFAULT_PROP_CHANNEL,
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
GST_PARAM_MUTABLE_READY)));
}
static void
gst_edt_pdv_src_init (GstEdtPdvSrc * src)
{
/* set source as live (no preroll) */
gst_base_src_set_live (GST_BASE_SRC (src), TRUE);
/* override default of BYTES to operate in time mode */
gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME);
/* initialize properties */
src->unit = DEFAULT_PROP_UNIT;
src->channel = DEFAULT_PROP_CHANNEL;
gst_edt_pdv_src_reset (src);
}
static void
gst_edt_pdv_src_reset (GstEdtPdvSrc * src)
{
src->dev = NULL;
src->total_timeouts = 0;
src->acq_started = FALSE;
}
void
gst_edt_pdv_src_set_property (GObject * object, guint property_id,
const GValue * value, GParamSpec * pspec)
{
GstEdtPdvSrc *src;
src = GST_EDT_PDV_SRC (object);
switch (property_id) {
case PROP_UNIT:
src->unit = g_value_get_uint (value);
break;
case PROP_CHANNEL:
src->channel = g_value_get_uint (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
void
gst_edt_pdv_src_get_property (GObject * object, guint property_id,
GValue * value, GParamSpec * pspec)
{
GstEdtPdvSrc *src;
g_return_if_fail (GST_IS_EDT_PDV_SRC (object));
src = GST_EDT_PDV_SRC (object);
switch (property_id) {
case PROP_UNIT:
g_value_set_uint (value, src->unit);
break;
case PROP_CHANNEL:
g_value_set_uint (value, src->channel);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
void
gst_edt_pdv_src_dispose (GObject * object)
{
GstEdtPdvSrc *src;
g_return_if_fail (GST_IS_EDT_PDV_SRC (object));
src = GST_EDT_PDV_SRC (object);
/* clean up as possible. may be called multiple times */
G_OBJECT_CLASS (gst_edt_pdv_src_parent_class)->dispose (object);
}
void
gst_edt_pdv_src_finalize (GObject * object)
{
GstEdtPdvSrc *src;
g_return_if_fail (GST_IS_EDT_PDV_SRC (object));
src = GST_EDT_PDV_SRC (object);
/* clean up object here */
G_OBJECT_CLASS (gst_edt_pdv_src_parent_class)->finalize (object);
}
static gboolean
gst_edt_pdv_src_start (GstBaseSrc * bsrc)
{
GstEdtPdvSrc *src = GST_EDT_PDV_SRC (bsrc);
GST_DEBUG_OBJECT (src, "start");
src->dev = pdv_open_channel (EDT_INTERFACE, src->unit, src->channel);
if (src->dev == NULL) {
GST_ERROR_OBJECT (src, "Failed to open EDT PDV unit %d channel %d)",
src->unit, src->channel);
pdv_perror ("error message");
goto fail;
}
if (pdv_multibuf (src->dev, 4)) {
GST_ERROR_OBJECT (src, "Failed to setup ring buffer");
goto fail;
}
return TRUE;
fail:
if (src->dev) {
pdv_close (src->dev);
src->dev = NULL;
}
return FALSE;
}
static gboolean
gst_edt_pdv_src_stop (GstBaseSrc * bsrc)
{
GstEdtPdvSrc *src = GST_EDT_PDV_SRC (bsrc);
GST_DEBUG_OBJECT (src, "stop");
g_assert (src->dev != NULL);
if (pdv_close (src->dev)) {
GST_ERROR_OBJECT (src, "Failed to close device");
return FALSE;
}
gst_edt_pdv_src_reset (src);
return TRUE;
}
static GstCaps *
gst_edt_pdv_src_get_caps (GstBaseSrc * bsrc, GstCaps * filter)
{
GstEdtPdvSrc *src = GST_EDT_PDV_SRC (bsrc);
GstCaps *caps;
if (src->dev == NULL) {
caps = gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (src));
} else {
gint depth;
GstVideoInfo vinfo;
/* Create video info */
gst_video_info_init (&vinfo);
vinfo.width = pdv_get_width (src->dev);
vinfo.height = pdv_get_height (src->dev);
depth = pdv_get_depth (src->dev);
if (depth <= 8) {
vinfo.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_GRAY8);
caps = gst_video_info_to_caps (&vinfo);
} else if (depth <= 16) {
GValue val = G_VALUE_INIT;
GstStructure *s;
/* TODO: check endianness */
vinfo.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_GRAY16_LE);
caps = gst_video_info_to_caps (&vinfo);
/* set bpp, extra info for GRAY16 so elements can scale properly */
s = gst_caps_get_structure (caps, 0);
g_value_init (&val, G_TYPE_INT);
g_value_set_int (&val, depth);
gst_structure_set_value (s, "bpp", &val);
g_value_unset (&val);
} else if (depth == 24) {
vinfo.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_RGB);
caps = gst_video_info_to_caps (&vinfo);
} else {
GST_ELEMENT_ERROR (src, STREAM, WRONG_TYPE,
(("Unknown or unsupported color format.")), (NULL));
goto Error;
}
}
GST_DEBUG_OBJECT (src, "The caps before filtering are %" GST_PTR_FORMAT,
caps);
if (filter) {
GstCaps *tmp = gst_caps_intersect (caps, filter);
gst_caps_unref (caps);
caps = tmp;
}
GST_DEBUG_OBJECT (src, "The caps after filtering are %" GST_PTR_FORMAT, caps);
return caps;
Error:
return NULL;
}
static gboolean
gst_edt_pdv_src_set_caps (GstBaseSrc * bsrc, GstCaps * caps)
{
GstEdtPdvSrc *src = GST_EDT_PDV_SRC (bsrc);
GstVideoInfo vinfo;
GstStructure *s = gst_caps_get_structure (caps, 0);
GST_DEBUG_OBJECT (src, "The caps being set are %" GST_PTR_FORMAT, caps);
gst_video_info_from_caps (&vinfo, caps);
if (GST_VIDEO_INFO_FORMAT (&vinfo) != GST_VIDEO_FORMAT_UNKNOWN) {
src->gst_stride = GST_VIDEO_INFO_COMP_STRIDE (&vinfo, 0);
src->height = vinfo.height;
} else {
goto unsupported_caps;
}
return TRUE;
unsupported_caps:
GST_ERROR_OBJECT (src, "Unsupported caps: %" GST_PTR_FORMAT, caps);
return FALSE;
}
static GstFlowReturn
gst_edt_pdv_src_create (GstPushSrc * psrc, GstBuffer ** buf)
{
GstEdtPdvSrc *src = GST_EDT_PDV_SRC (psrc);
GstMapInfo minfo;
guint8 *image;
gint timeouts;
if (!src->acq_started) {
/* start freerun/continuous capture */
pdv_start_images (src->dev, 0);
src->acq_started = TRUE;
}
/* TODO: any way to know if this particular image is good? */
/* TODO: use pdv_ wait_image_timed to get rough timestamp */
image = pdv_wait_image (src->dev);
/* TODO: if there are timeouts, do we drop frame, return GST_FLOW_FATAL? */
timeouts = pdv_timeouts (src->dev);
if (timeouts > src->total_timeouts) {
GST_WARNING_OBJECT (src,
"Received timeout, data might be incomplete. Check cables and system bandwidth.");
src->total_timeouts = timeouts;
}
/* TODO: use allocator */
*buf = gst_buffer_new_and_alloc (src->height * src->gst_stride);
/* Copy image to buffer from surface TODO: use orc_memcpy */
gst_buffer_map (*buf, &minfo, GST_MAP_WRITE);
GST_LOG_OBJECT (src,
"GstBuffer size=%d, gst_stride=%d", minfo.size, src->gst_stride);
/* TODO: stride alignment probably isn't a multiple of 4 */
memcpy (minfo.data, image, minfo.size);
//for (i = 0; i < src->height; i++) {
// memcpy (minfo.data + i * src->gst_stride,
// ((guint8 *) buffer.pvAddress) + i * src->px_stride,
// src->gst_stride);
//}
gst_buffer_unmap (*buf, &minfo);
return GST_FLOW_OK;
}

77
sys/edt/gstedtpdvsrc.h Normal file
View File

@ -0,0 +1,77 @@
/* GStreamer
* Copyright (C) 2011 FIXME <fixme@example.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef _GST_EDT_PDV_SRC_H_
#define _GST_EDT_PDV_SRC_H_
#include <gst/base/gstpushsrc.h>
#include <edtinc.h>
G_BEGIN_DECLS
#define GST_TYPE_EDT_PDV_SRC (gst_edt_pdv_src_get_type())
#define GST_EDT_PDV_SRC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_EDT_PDV_SRC,GstEdtPdvSrc))
#define GST_EDT_PDV_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_EDT_PDV_SRC,GstEdtPdvSrcClass))
#define GST_IS_EDT_PDV_SRC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_EDT_PDV_SRC))
#define GST_IS_EDT_PDV_SRC_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_EDT_PDV_SRC))
typedef struct _GstEdtPdvSrc GstEdtPdvSrc;
typedef struct _GstEdtPdvSrcClass GstEdtPdvSrcClass;
/**
* GstEdtPdvSrcConnector:
* @MC_Connector_VID<1..16>: channel is linked to camera at the VID<1..16> input
* @MC_Connector_YC: channel is linked to a camera at the YC input
*
*
* Identifies the connector that the camera is connected to.
*/
typedef enum {
} GstEdtPdvSrcConnector;
struct _GstEdtPdvSrc
{
GstPushSrc base_edt_pdv_src;
/* properties */
guint unit;
guint channel;
PdvDev *dev;
gboolean acq_started;
gint total_timeouts;
gint height;
gint gst_stride;
guint px_stride;
};
struct _GstEdtPdvSrcClass
{
GstPushSrcClass base_edt_pdv_src_class;
};
GType gst_edt_pdv_src_get_type (void);
G_END_DECLS
#endif

View File

@ -131,6 +131,7 @@
<ItemGroup>
<ClCompile Include="..\..\sys\edt\gstedt.c" />
<ClCompile Include="..\..\sys\edt\gstedtpdvsink.c" />
<ClCompile Include="..\..\sys\edt\gstedtpdvsrc.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\sys\edt\gstedtpdvsink.h" />
@ -139,4 +140,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>

View File

@ -21,6 +21,9 @@
<ClCompile Include="..\..\sys\edt\gstedt.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\sys\edt\gstedtpdvsrc.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\sys\edt\gstedtpdvsrc.h">