add aptinasrc, a source element for Aptina Imaging (ON) cameras
This commit is contained in:
parent
6a4f3fe058
commit
4f326fce02
@ -64,6 +64,9 @@ macro_log_feature(FREEIMAGE_FOUND "FreeImage" "Required to build FreeImage plugi
|
||||
find_package(OpenCV)
|
||||
macro_log_feature(OPENCV_FOUND "OpenCV" "Required to build sensorfx plugin" "http://opencv.willowgarage.com/" FALSE)
|
||||
|
||||
find_package(Aptina)
|
||||
macro_log_feature(APTINA_FOUND "Aptina" "Required to build aptinasrc source element" "http://www.onsemi.com/" FALSE)
|
||||
|
||||
find_package(EDT)
|
||||
macro_log_feature(EDT_FOUND "EDT" "Required to build EDT PDV source element" "http://www.edt.com/" FALSE)
|
||||
|
||||
|
||||
34
cmake/modules/FindAptina.cmake
Normal file
34
cmake/modules/FindAptina.cmake
Normal file
@ -0,0 +1,34 @@
|
||||
# - Try to find Aptina SDK
|
||||
# Once done this will define
|
||||
#
|
||||
# APTINA_FOUND - system has Aptina SDK
|
||||
# APTINA_INCLUDE_DIR - the Aptina SDK include directory
|
||||
# APTINA_LIBRARIES - the libraries needed to use Aptina SDK
|
||||
|
||||
# Copyright (c) 2006, Tim Beaulen <tbscope@gmail.com>
|
||||
# Copyright (c) 2017 outside US, United States Government, Joshua M. Doe <oss@nvl.army.mil>
|
||||
#
|
||||
# Redistribution and use is allowed according to the terms of the BSD license.
|
||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||
|
||||
if (NOT APTINA_DIR)
|
||||
set (APTINA_DIR "C:/Aptina Imaging" CACHE PATH "Directory containing Aptina SDK includes and libraries")
|
||||
endif ()
|
||||
|
||||
if (CMAKE_SIZEOF_VOID_P MATCHES "8")
|
||||
set(_LIB_NAME "apbase_64")
|
||||
else ()
|
||||
set(_LIB_NAME "apbase")
|
||||
endif ()
|
||||
|
||||
find_path (APTINA_INCLUDE_DIR apbase.h
|
||||
PATHS
|
||||
"${APTINA_DIR}/include"
|
||||
DOC "Directory containing Aptina include files")
|
||||
|
||||
find_library (APTINA_LIBRARIES NAMES ${_LIB_NAME}
|
||||
PATHS
|
||||
"${APTINA_DIR}/lib")
|
||||
|
||||
include (FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args (APTINA DEFAULT_MSG APTINA_INCLUDE_DIR APTINA_LIBRARIES)
|
||||
@ -1,3 +1,7 @@
|
||||
if (APTINA_FOUND)
|
||||
add_subdirectory(aptina)
|
||||
endif (APTINA_FOUND)
|
||||
|
||||
if (BITFLOW_FOUND)
|
||||
add_subdirectory(bitflow)
|
||||
endif (BITFLOW_FOUND)
|
||||
|
||||
31
sys/aptina/CMakeLists.txt
Normal file
31
sys/aptina/CMakeLists.txt
Normal file
@ -0,0 +1,31 @@
|
||||
add_definitions(-DHAVE_ORC=TRUE)
|
||||
|
||||
set (SOURCES
|
||||
gstaptinasrc.c)
|
||||
|
||||
set (HEADERS
|
||||
gstaptinasrc.h)
|
||||
|
||||
include_directories (AFTER
|
||||
${ORC_INCLUDE_DIR}
|
||||
${APTINA_INCLUDE_DIR})
|
||||
|
||||
set (libname libgstaptina)
|
||||
|
||||
add_library (${libname} MODULE
|
||||
${SOURCES}
|
||||
${HEADERS})
|
||||
|
||||
target_link_libraries (${libname}
|
||||
${ORC_LIBRARIES}
|
||||
${GLIB2_LIBRARIES}
|
||||
${GOBJECT_LIBRARIES}
|
||||
${GSTREAMER_LIBRARY}
|
||||
${GSTREAMER_BASE_LIBRARY}
|
||||
${GSTREAMER_VIDEO_LIBRARY}
|
||||
${APTINA_LIBRARIES})
|
||||
|
||||
set (pdbfile "${CMAKE_CURRENT_BINARY_DIR}/\${CMAKE_INSTALL_CONFIG_NAME}/${libname}.pdb")
|
||||
install (FILES ${pdbfile} DESTINATION lib/gstreamer-1.0 COMPONENT pdb)
|
||||
install(TARGETS ${libname}
|
||||
LIBRARY DESTINATION lib/gstreamer-1.0)
|
||||
555
sys/aptina/gstaptinasrc.c
Normal file
555
sys/aptina/gstaptinasrc.c
Normal file
@ -0,0 +1,555 @@
|
||||
/* 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-gstaptinasrc
|
||||
*
|
||||
* The aptinasrc element is a source for Aptina dev kits.
|
||||
*
|
||||
* <refsect2>
|
||||
* <title>Example launch line</title>
|
||||
* |[
|
||||
* gst-launch -v aptinasrc ! videoconvert ! autovideosink
|
||||
* ]|
|
||||
* Shows video from the default Aptina dev kit
|
||||
* </refsect2>
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/base/gstpushsrc.h>
|
||||
#include <gst/video/video.h>
|
||||
|
||||
#ifdef HAVE_ORC
|
||||
#include <orc/orc.h>
|
||||
#else
|
||||
#define orc_memcpy memcpy
|
||||
#endif
|
||||
|
||||
#include "gstaptinasrc.h"
|
||||
|
||||
GST_DEBUG_CATEGORY_STATIC (gst_aptinasrc_debug);
|
||||
#define GST_CAT_DEFAULT gst_aptinasrc_debug
|
||||
|
||||
/* prototypes */
|
||||
static void gst_aptinasrc_set_property (GObject * object,
|
||||
guint property_id, const GValue * value, GParamSpec * pspec);
|
||||
static void gst_aptinasrc_get_property (GObject * object,
|
||||
guint property_id, GValue * value, GParamSpec * pspec);
|
||||
static void gst_aptinasrc_dispose (GObject * object);
|
||||
static void gst_aptinasrc_finalize (GObject * object);
|
||||
|
||||
static gboolean gst_aptinasrc_start (GstBaseSrc * src);
|
||||
static gboolean gst_aptinasrc_stop (GstBaseSrc * src);
|
||||
static GstCaps *gst_aptinasrc_get_caps (GstBaseSrc * src, GstCaps * filter);
|
||||
static gboolean gst_aptinasrc_set_caps (GstBaseSrc * src, GstCaps * caps);
|
||||
static gboolean gst_aptinasrc_unlock (GstBaseSrc * src);
|
||||
static gboolean gst_aptinasrc_unlock_stop (GstBaseSrc * src);
|
||||
|
||||
static GstFlowReturn gst_aptinasrc_create (GstPushSrc * src, GstBuffer ** buf);
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_DEVICE_INDEX,
|
||||
PROP_CONFIG_FILE,
|
||||
PROP_CONFIG_PRESET,
|
||||
};
|
||||
|
||||
#define DEFAULT_PROP_DEVICE_INDEX 0
|
||||
#define DEFAULT_PROP_CONFIG_FILE ""
|
||||
#define DEFAULT_PROP_CONFIG_PRESET ""
|
||||
|
||||
/* pad templates */
|
||||
|
||||
static GstStaticPadTemplate gst_aptinasrc_src_template =
|
||||
GST_STATIC_PAD_TEMPLATE ("src",
|
||||
GST_PAD_SRC,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ BGRx }"))
|
||||
);
|
||||
|
||||
/* class initialization */
|
||||
|
||||
G_DEFINE_TYPE (GstAptinaSrc, gst_aptinasrc, GST_TYPE_PUSH_SRC);
|
||||
|
||||
static void
|
||||
gst_aptinasrc_class_init (GstAptinaSrcClass * 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);
|
||||
|
||||
gobject_class->set_property = gst_aptinasrc_set_property;
|
||||
gobject_class->get_property = gst_aptinasrc_get_property;
|
||||
gobject_class->dispose = gst_aptinasrc_dispose;
|
||||
gobject_class->finalize = gst_aptinasrc_finalize;
|
||||
|
||||
gst_element_class_add_pad_template (gstelement_class,
|
||||
gst_static_pad_template_get (&gst_aptinasrc_src_template));
|
||||
|
||||
gst_element_class_set_static_metadata (gstelement_class,
|
||||
"Aptina Video Source", "Source/Video",
|
||||
"Aptina Imaging video source", "Joshua M. Doe <oss@nvl.army.mil>");
|
||||
|
||||
gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_aptinasrc_start);
|
||||
gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_aptinasrc_stop);
|
||||
gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (gst_aptinasrc_get_caps);
|
||||
//gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_aptinasrc_set_caps);
|
||||
gstbasesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_aptinasrc_unlock);
|
||||
gstbasesrc_class->unlock_stop = GST_DEBUG_FUNCPTR (gst_aptinasrc_unlock_stop);
|
||||
|
||||
gstpushsrc_class->create = GST_DEBUG_FUNCPTR (gst_aptinasrc_create);
|
||||
|
||||
/* Install GObject properties */
|
||||
g_object_class_install_property (gobject_class, PROP_DEVICE_INDEX,
|
||||
g_param_spec_int ("device", "Device index",
|
||||
"Device index", 0, 254, DEFAULT_PROP_DEVICE_INDEX,
|
||||
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
||||
g_object_class_install_property (gobject_class, PROP_CONFIG_FILE,
|
||||
g_param_spec_string ("config-file", "Config file",
|
||||
"Filepath of the INI file",
|
||||
DEFAULT_PROP_CONFIG_FILE,
|
||||
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
|
||||
GST_PARAM_MUTABLE_READY)));
|
||||
g_object_class_install_property (gobject_class, PROP_CONFIG_PRESET,
|
||||
g_param_spec_string ("config-preset", "Config preset",
|
||||
"Name of the preset in the INI file to run",
|
||||
DEFAULT_PROP_CONFIG_PRESET,
|
||||
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
|
||||
GST_PARAM_MUTABLE_READY)));
|
||||
}
|
||||
|
||||
static void
|
||||
gst_aptinasrc_reset (GstAptinaSrc * src)
|
||||
{
|
||||
src->framesize = 0;
|
||||
|
||||
src->is_started = FALSE;
|
||||
|
||||
src->last_frame_count = 0;
|
||||
src->total_dropped_frames = 0;
|
||||
|
||||
if (src->caps) {
|
||||
gst_caps_unref (src->caps);
|
||||
src->caps = NULL;
|
||||
}
|
||||
|
||||
if (src->buffer) {
|
||||
g_free (src->buffer);
|
||||
src->buffer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_aptinasrc_init (GstAptinaSrc * 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 member variables */
|
||||
src->camera_index = DEFAULT_PROP_DEVICE_INDEX;
|
||||
src->config_file = g_strdup (DEFAULT_PROP_CONFIG_FILE);
|
||||
src->config_preset = g_strdup (DEFAULT_PROP_CONFIG_PRESET);
|
||||
|
||||
src->apbase = NULL;
|
||||
src->stop_requested = FALSE;
|
||||
src->caps = NULL;
|
||||
src->buffer = NULL;
|
||||
|
||||
gst_aptinasrc_reset (src);
|
||||
}
|
||||
|
||||
void
|
||||
gst_aptinasrc_set_property (GObject * object, guint property_id,
|
||||
const GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
GstAptinaSrc *src;
|
||||
|
||||
src = GST_APTINA_SRC (object);
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_DEVICE_INDEX:
|
||||
src->camera_index = g_value_get_int (value);
|
||||
break;
|
||||
case PROP_CONFIG_FILE:
|
||||
g_free (src->config_file);
|
||||
src->config_file = g_strdup (g_value_get_string (value));
|
||||
break;
|
||||
case PROP_CONFIG_PRESET:
|
||||
g_free (src->config_preset);
|
||||
src->config_preset = g_strdup (g_value_get_string (value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gst_aptinasrc_get_property (GObject * object, guint property_id,
|
||||
GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
GstAptinaSrc *src;
|
||||
|
||||
g_return_if_fail (GST_IS_APTINA_SRC (object));
|
||||
src = GST_APTINA_SRC (object);
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_DEVICE_INDEX:
|
||||
g_value_set_int (value, src->camera_index);
|
||||
break;
|
||||
case PROP_CONFIG_FILE:
|
||||
g_value_set_string (value, src->config_file);
|
||||
break;
|
||||
case PROP_CONFIG_PRESET:
|
||||
g_value_set_string (value, src->config_preset);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gst_aptinasrc_dispose (GObject * object)
|
||||
{
|
||||
GstAptinaSrc *src;
|
||||
|
||||
g_return_if_fail (GST_IS_APTINA_SRC (object));
|
||||
src = GST_APTINA_SRC (object);
|
||||
|
||||
/* clean up as possible. may be called multiple times */
|
||||
|
||||
G_OBJECT_CLASS (gst_aptinasrc_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
void
|
||||
gst_aptinasrc_finalize (GObject * object)
|
||||
{
|
||||
GstAptinaSrc *src;
|
||||
|
||||
g_return_if_fail (GST_IS_APTINA_SRC (object));
|
||||
src = GST_APTINA_SRC (object);
|
||||
|
||||
/* clean up object here */
|
||||
|
||||
g_free (src->config_file);
|
||||
g_free (src->config_preset);
|
||||
|
||||
if (src->caps) {
|
||||
gst_caps_unref (src->caps);
|
||||
src->caps = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (gst_aptinasrc_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
ap_s32
|
||||
handle_error_message (void *pContext, const char *szMessage,
|
||||
unsigned int mbType)
|
||||
{
|
||||
GstAptinaSrc *src = GST_APTINA_SRC (pContext);
|
||||
GST_DEBUG_OBJECT (src, "ApBase error: %s", szMessage);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_aptinasrc_calculate_caps (GstAptinaSrc * src)
|
||||
{
|
||||
ap_u32 ret;
|
||||
ap_u32 rgb_width = 0, rgb_height = 0, rgb_depth = 0;
|
||||
guint8 *unpacked;
|
||||
GstVideoInfo vinfo;
|
||||
char image_type[64];
|
||||
gint framesize;
|
||||
|
||||
framesize = ap_GrabFrame (src->apbase, NULL, 0);
|
||||
if (framesize != src->framesize) {
|
||||
src->framesize = framesize;
|
||||
if (src->buffer) {
|
||||
g_free (src->buffer);
|
||||
}
|
||||
src->buffer = (guint8 *) g_malloc (src->framesize);
|
||||
}
|
||||
|
||||
ret = ap_GrabFrame (src->apbase, src->buffer, src->framesize);
|
||||
if (ret == 0) {
|
||||
GST_ELEMENT_ERROR (src, RESOURCE, FAILED,
|
||||
("Grabbing failed with error %d", ap_GetLastError ()), (NULL));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
ap_GetImageFormat (src->apbase, NULL, NULL, image_type, sizeof (image_type));
|
||||
GST_DEBUG_OBJECT (src, "Image type is '%s', but will be converted to BGRx",
|
||||
image_type);
|
||||
|
||||
unpacked =
|
||||
ap_ColorPipe (src->apbase, src->buffer, src->framesize, &rgb_width,
|
||||
&rgb_height, &rgb_depth);
|
||||
if (rgb_depth != 32) {
|
||||
GST_ELEMENT_ERROR (src, STREAM, WRONG_TYPE,
|
||||
("Depth is %d, but only 32-bit supported currently.", rgb_depth),
|
||||
(NULL));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gst_video_info_init (&vinfo);
|
||||
gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_BGRx, rgb_width,
|
||||
rgb_height);
|
||||
if (src->caps) {
|
||||
gst_caps_unref (src->caps);
|
||||
}
|
||||
src->caps = gst_video_info_to_caps (&vinfo);
|
||||
gst_base_src_set_caps (GST_BASE_SRC (src), src->caps);
|
||||
GST_DEBUG_OBJECT (src, "Created caps %" GST_PTR_FORMAT, src->caps);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_aptinasrc_start (GstBaseSrc * bsrc)
|
||||
{
|
||||
GstAptinaSrc *src = GST_APTINA_SRC (bsrc);
|
||||
ap_s32 ret;
|
||||
gchar *ini_file, *preset;
|
||||
|
||||
GST_DEBUG_OBJECT (src, "start");
|
||||
|
||||
//src->apbase = ap_CreateFromImageFile("C:\\temp\\1.jpg");
|
||||
src->apbase = ap_Create (src->camera_index);
|
||||
if (!src->apbase) {
|
||||
GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND,
|
||||
("Failed to open camera"), (NULL));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
ap_SetCallback_ErrorMessage (src->apbase, handle_error_message, src);
|
||||
|
||||
//ap_SetState(src->apbase, "Sensor Reset", 1);
|
||||
//g_usleep(1000000);
|
||||
//ap_SetState(src->apbase, "Sensor Reset", 0);
|
||||
//g_usleep(1000000);
|
||||
|
||||
if (!src->config_file || strlen (src->config_file) == 0) {
|
||||
ini_file = NULL;
|
||||
} else {
|
||||
if (!g_file_test (src->config_file, G_FILE_TEST_EXISTS)) {
|
||||
GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND,
|
||||
("Camera file does not exist: %s", src->config_file), (NULL));
|
||||
return FALSE;
|
||||
}
|
||||
ini_file = g_strdup (src->config_file);
|
||||
}
|
||||
|
||||
if (!src->config_preset || strlen (src->config_preset) == 0) {
|
||||
preset = NULL;
|
||||
} else {
|
||||
preset = g_strdup (src->config_preset);
|
||||
}
|
||||
|
||||
ret = ap_LoadIniPreset (src->apbase, ini_file, preset);
|
||||
g_free (ini_file);
|
||||
g_free (preset);
|
||||
|
||||
if (ret != AP_INI_SUCCESS) {
|
||||
GST_ELEMENT_ERROR (src, RESOURCE, FAILED,
|
||||
("Failed to load INI preset"), (NULL));
|
||||
return FALSE;
|
||||
}
|
||||
//ap_CheckSensorState(src->apbase, 0);
|
||||
|
||||
if (!gst_aptinasrc_calculate_caps (src)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_aptinasrc_stop (GstBaseSrc * bsrc)
|
||||
{
|
||||
GstAptinaSrc *src = GST_APTINA_SRC (bsrc);
|
||||
|
||||
GST_DEBUG_OBJECT (src, "stop");
|
||||
|
||||
ap_Destroy (src->apbase);
|
||||
ap_Finalize ();
|
||||
|
||||
gst_aptinasrc_reset (src);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static GstCaps *
|
||||
gst_aptinasrc_get_caps (GstBaseSrc * bsrc, GstCaps * filter)
|
||||
{
|
||||
GstAptinaSrc *src = GST_APTINA_SRC (bsrc);
|
||||
GstCaps *caps;
|
||||
|
||||
if (src->caps) {
|
||||
caps = gst_caps_copy (src->caps);
|
||||
} else {
|
||||
caps = gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (src));
|
||||
}
|
||||
|
||||
GST_DEBUG_OBJECT (src, "The caps before filtering are %" GST_PTR_FORMAT,
|
||||
caps);
|
||||
|
||||
if (filter && caps) {
|
||||
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;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_aptinasrc_set_caps (GstBaseSrc * bsrc, GstCaps * caps)
|
||||
{
|
||||
GstAptinaSrc *src = GST_APTINA_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) {
|
||||
goto unsupported_caps;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
||||
unsupported_caps:
|
||||
GST_ERROR_OBJECT (src, "Unsupported caps: %" GST_PTR_FORMAT, caps);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_aptinasrc_unlock (GstBaseSrc * bsrc)
|
||||
{
|
||||
GstAptinaSrc *src = GST_APTINA_SRC (bsrc);
|
||||
|
||||
GST_LOG_OBJECT (src, "unlock");
|
||||
|
||||
src->stop_requested = TRUE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_aptinasrc_unlock_stop (GstBaseSrc * bsrc)
|
||||
{
|
||||
GstAptinaSrc *src = GST_APTINA_SRC (bsrc);
|
||||
|
||||
GST_LOG_OBJECT (src, "unlock_stop");
|
||||
|
||||
src->stop_requested = FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static GstFlowReturn
|
||||
gst_aptinasrc_create (GstPushSrc * psrc, GstBuffer ** buf)
|
||||
{
|
||||
GstAptinaSrc *src = GST_APTINA_SRC (psrc);
|
||||
ap_s32 ret;
|
||||
GstMapInfo minfo;
|
||||
GstClock *clock;
|
||||
GstClockTime clock_time;
|
||||
char *pBuffer = NULL;
|
||||
static int temp_ugly_buf_index = 0;
|
||||
guint8 *unpacked;
|
||||
ap_u32 rgb_width = 0, rgb_height = 0, rgb_depth = 0;
|
||||
|
||||
GST_LOG_OBJECT (src, "create");
|
||||
|
||||
if (!src->is_started) {
|
||||
/* TODO: check timestamps on buffers vs start time */
|
||||
src->acq_start_time =
|
||||
gst_clock_get_time (gst_element_get_clock (GST_ELEMENT (src)));
|
||||
|
||||
src->is_started = TRUE;
|
||||
}
|
||||
|
||||
ret = ap_GrabFrame (src->apbase, src->buffer, src->framesize);
|
||||
if (ret == 0) {
|
||||
GST_ELEMENT_ERROR (src, RESOURCE, FAILED,
|
||||
("Grabbing failed with error %d", ap_GetLastError ()), (NULL));
|
||||
return GST_FLOW_ERROR;
|
||||
}
|
||||
|
||||
unpacked =
|
||||
ap_ColorPipe (src->apbase, src->buffer, src->framesize, &rgb_width,
|
||||
&rgb_height, &rgb_depth);
|
||||
|
||||
clock = gst_element_get_clock (GST_ELEMENT (src));
|
||||
clock_time = gst_clock_get_time (clock);
|
||||
gst_object_unref (clock);
|
||||
|
||||
/* TODO: use allocator or use from pool */
|
||||
*buf = gst_buffer_new_and_alloc (rgb_width * rgb_height * rgb_depth / 8);
|
||||
gst_buffer_map (*buf, &minfo, GST_MAP_WRITE);
|
||||
orc_memcpy (minfo.data, unpacked, minfo.size);
|
||||
gst_buffer_unmap (*buf, &minfo);
|
||||
|
||||
GST_BUFFER_TIMESTAMP (*buf) =
|
||||
GST_CLOCK_DIFF (gst_element_get_base_time (GST_ELEMENT (src)),
|
||||
clock_time);
|
||||
GST_BUFFER_OFFSET (*buf) = temp_ugly_buf_index++;
|
||||
|
||||
if (src->stop_requested) {
|
||||
if (*buf != NULL) {
|
||||
gst_buffer_unref (*buf);
|
||||
*buf = NULL;
|
||||
}
|
||||
return GST_FLOW_FLUSHING;
|
||||
}
|
||||
|
||||
return GST_FLOW_OK;
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
plugin_init (GstPlugin * plugin)
|
||||
{
|
||||
GST_DEBUG_CATEGORY_INIT (gst_aptinasrc_debug, "aptinasrc", 0,
|
||||
"debug category for aptinasrc element");
|
||||
gst_element_register (plugin, "aptinasrc", GST_RANK_NONE,
|
||||
gst_aptinasrc_get_type ());
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
||||
GST_VERSION_MINOR,
|
||||
aptina,
|
||||
"Aptina camera source",
|
||||
plugin_init, GST_PACKAGE_VERSION, GST_PACKAGE_LICENSE, GST_PACKAGE_NAME,
|
||||
GST_PACKAGE_ORIGIN)
|
||||
70
sys/aptina/gstaptinasrc.h
Normal file
70
sys/aptina/gstaptinasrc.h
Normal file
@ -0,0 +1,70 @@
|
||||
/* 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_APTINA_SRC_H_
|
||||
#define _GST_APTINA_SRC_H_
|
||||
|
||||
#include <gst/base/gstpushsrc.h>
|
||||
|
||||
#include "apbase.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GST_TYPE_APTINA_SRC (gst_aptinasrc_get_type())
|
||||
#define GST_APTINA_SRC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_APTINA_SRC,GstAptinaSrc))
|
||||
#define GST_APTINA_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_APTINA_SRC,GstAptinaSrcClass))
|
||||
#define GST_IS_APTINA_SRC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_APTINA_SRC))
|
||||
#define GST_IS_APTINA_SRC_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_APTINA_SRC))
|
||||
|
||||
typedef struct _GstAptinaSrc GstAptinaSrc;
|
||||
typedef struct _GstAptinaSrcClass GstAptinaSrcClass;
|
||||
|
||||
struct _GstAptinaSrc
|
||||
{
|
||||
GstPushSrc base_aptinasrc;
|
||||
|
||||
AP_HANDLE apbase;
|
||||
gboolean is_started;
|
||||
|
||||
/* properties */
|
||||
gint camera_index;
|
||||
gchar *config_file;
|
||||
gchar *config_preset;
|
||||
|
||||
GstClockTime acq_start_time;
|
||||
guint32 last_frame_count;
|
||||
guint32 total_dropped_frames;
|
||||
|
||||
GstCaps *caps;
|
||||
gint framesize;
|
||||
guint8 *buffer;
|
||||
|
||||
gboolean stop_requested;
|
||||
};
|
||||
|
||||
struct _GstAptinaSrcClass
|
||||
{
|
||||
GstPushSrcClass base_aptinasrc_class;
|
||||
};
|
||||
|
||||
GType gst_aptinasrc_get_type (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
||||
Loading…
x
Reference in New Issue
Block a user