klv: add klv library, klvinject and klvinspect elements

Create as a separate library until gst-plugins-base MR124 is merged into tag
This commit is contained in:
Joshua M. Doe 2020-02-06 13:33:56 -05:00
parent 1502c7fa9c
commit ec20592591
14 changed files with 533 additions and 15 deletions

View File

@ -119,6 +119,8 @@ if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
${PREFIX} CACHE PATH "Directory to install plugins, under lib/gstreamer-1.0" FORCE)
endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
add_subdirectory(gst-libs)
# Build the plugins
add_subdirectory(ext)
add_subdirectory(gst)

1
gst-libs/CMakeLists.txt Normal file
View File

@ -0,0 +1 @@
add_subdirectory (klv)

View File

@ -0,0 +1,30 @@
add_definitions(-DBUILDING_GST_KLV)
set (SOURCES
klv.c)
set (HEADERS
klv.h)
include_directories (AFTER
${PROJECT_SOURCE_DIR}/common
)
set (libname libgstklv-1.0-0)
add_library (${libname} SHARED
${SOURCES}
${HEADERS})
target_link_libraries (${libname}
${GLIB2_LIBRARIES}
${GOBJECT_LIBRARIES}
${GSTREAMER_LIBRARY}
${GSTREAMER_BASE_LIBRARY}
${GSTREAMER_VIDEO_LIBRARY})
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}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib)

View File

@ -23,7 +23,14 @@
#include <gst/gst.h>
// FIXME: include this for now until gst-plugins-base MR124 is accepted
#define GST_TAG_API
//#define GST_API_EXPORT __declspec(dllexport) extern
//#define GST_TAG_API GST_API_EXPORT
#ifdef BUILDING_GST_KLV
#define GST_KLV_API __declspec(dllexport) extern
#else
#define GST_KLV_API __declspec(dllimport) extern
#endif
#define GST_TAG_API GST_KLV_API
G_BEGIN_DECLS

View File

@ -3,6 +3,7 @@ if (OPENCV_FOUND)
endif (OPENCV_FOUND)
add_subdirectory (extractcolor)
add_subdirectory (klv)
add_subdirectory (misb)
add_subdirectory (select)
add_subdirectory (videoadjust)

32
gst/klv/CMakeLists.txt Normal file
View File

@ -0,0 +1,32 @@
set (SOURCES
gstklv.c
gstklvinject.c
gstklvinspect.c)
set (HEADERS
gstklvinject.h
gstklvinspect.h)
include_directories (AFTER
${PROJECT_SOURCE_DIR}/common
${PROJECT_SOURCE_DIR}/gst-libs/klv
)
set (libname libgstklv)
add_library (${libname} MODULE
${SOURCES}
${HEADERS})
target_link_libraries (${libname}
${GLIB2_LIBRARIES}
${GOBJECT_LIBRARIES}
${GSTREAMER_LIBRARY}
${GSTREAMER_BASE_LIBRARY}
${GSTREAMER_VIDEO_LIBRARY}
libgstklv-1.0-0)
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)

43
gst/klv/gstklv.c Normal file
View File

@ -0,0 +1,43 @@
/* GStreamer
* Copyright (C) 2016 William Manley <will@williammanley.net>
*
* 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gst/gst.h>
#include "gstklvinject.h"
#include "gstklvinspect.h"
static gboolean
plugin_init (GstPlugin * plugin)
{
return gst_element_register (plugin, "klvinspect", GST_RANK_NONE,
GST_TYPE_KLVINSPECT)
&& gst_element_register (plugin, "klvinject", GST_RANK_NONE,
GST_TYPE_KLVINJECT);
}
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR,
klv,
"Elements for working with KLV data",
plugin_init, GST_PACKAGE_VERSION, GST_PACKAGE_LICENSE, GST_PACKAGE_NAME,
GST_PACKAGE_ORIGIN);

186
gst/klv/gstklvinject.c Normal file
View File

@ -0,0 +1,186 @@
/* GStreamer
* Copyright (C) 2016 William Manley <will@williammanley.net>
*
* 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-gstklvinject
*
* The klvinject element injects KLV metadata on passing buffers.
*
* <refsect2>
* <title>Example launch line</title>
* |[
* gst-launch -v fakesrc ! klvinject ! fakesink
* ]|
* FIXME Describe what the pipeline does.
* </refsect2>
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gst/gst.h>
#include <gst/base/gstbasetransform.h>
#include <gst/base/gstbytewriter.h>
#include "gstklvinject.h"
#include "klv.h"
GST_DEBUG_CATEGORY_STATIC (gst_klvinject_debug_category);
#define GST_CAT_DEFAULT gst_klvinject_debug_category
/* prototypes */
static GstFlowReturn gst_klvinject_transform_ip (GstBaseTransform * trans,
GstBuffer * buf);
enum
{
PROP_0
};
/* pad templates */
#define SRC_CAPS "ANY"
#define SINK_CAPS "ANY"
/* class initialization */
G_DEFINE_TYPE_WITH_CODE (GstKlvInject, gst_klvinject, GST_TYPE_BASE_TRANSFORM,
GST_DEBUG_CATEGORY_INIT (gst_klvinject_debug_category, "klvinject", 0,
"debug category for klvinject element"));
static void
gst_klvinject_class_init (GstKlvInjectClass * klass)
{
GstBaseTransformClass *base_transform_class =
GST_BASE_TRANSFORM_CLASS (klass);
/* Setting up pads and setting metadata should be moved to
base_class_init if you intend to subclass this class. */
gst_element_class_add_pad_template (GST_ELEMENT_CLASS (klass),
gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
gst_caps_from_string (SRC_CAPS)));
gst_element_class_add_pad_template (GST_ELEMENT_CLASS (klass),
gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
gst_caps_from_string (SINK_CAPS)));
gst_element_class_set_static_metadata (GST_ELEMENT_CLASS (klass),
"Inject KLV", "Filter", "Inject KLV metadata",
"Joshua M. Doe <oss@nvl.army.mil>");
base_transform_class->transform_ip =
GST_DEBUG_FUNCPTR (gst_klvinject_transform_ip);
base_transform_class->passthrough_on_same_caps = TRUE;
base_transform_class->transform_ip_on_passthrough = TRUE;
}
static void
gst_klvinject_init (GstKlvInject * filt)
{
}
static void
gst_klvinject_dispose (GstKlvInject * filt)
{
}
static void
gst_klvinject_add_test_meta (GstKlvInject * filt, GstBuffer * buf)
{
/* Add KLV meta for testing, here: Motion Imagery Standards Board (MISB)
* Engineering Guideline MISB EG 0902 - MISB Minimum Metadata Set.
* Also see: SMPTE S336M for KLV specification, also ITU-R BT.1563-1 */
const guint8 klv_header[16] = { 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x0b, 0x01,
0x01, 0x0e, 0x01, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00
};
GDateTime *dt = g_date_time_new_now_utc ();
gint64 ut = g_date_time_to_unix (dt) * 1000000; /* microseconds */
GstByteWriter bw;
ut += g_date_time_get_microsecond (dt);
gst_byte_writer_init (&bw);
/* KLV header */
gst_byte_writer_put_data (&bw, klv_header, 16);
/* Total length in BER long form (verbatim as long as <= 127) */
gst_byte_writer_put_uint8 (&bw,
(1 + 1 + 8) + (1 + 1 + 14) + (1 + 1 + 4) + (1 + 1 + 4) + (1 + 1 + 2));
/* Tag 1: unix timestamp */
gst_byte_writer_put_uint8 (&bw, 2); /* local tag: unix timestamp */
gst_byte_writer_put_uint8 (&bw, 8); /* data length (BER short form) */
gst_byte_writer_put_uint64_be (&bw, ut);
/* Tag 2: Image Coordinate System */
gst_byte_writer_put_uint8 (&bw, 12); /* local tag: unix timestamp */
gst_byte_writer_put_uint8 (&bw, 14); /* data length (BER short form) */
gst_byte_writer_put_data (&bw, (guint8 *) "Geodetic WGS84", 14);
/* Tag 3: Sensor Latitude */
gst_byte_writer_put_uint8 (&bw, 13); /* local tag: latitude */
gst_byte_writer_put_uint8 (&bw, 4); /* data length (BER short form) */
{
/* Map -(2^31-1)..(2^31-1) to +/-90 with 0x80000000 = error */
gdouble latitude = 51.449825;
gint32 val = (gint) ((latitude / 90.0) * 2147483647.0);
gst_byte_writer_put_int32_be (&bw, val);
}
/* Tag 4: Sensor Longitude */
gst_byte_writer_put_uint8 (&bw, 14); /* local tag: longitude */
gst_byte_writer_put_uint8 (&bw, 4); /* data length (BER short form) */
{
/* Map -(2^31-1)..(2^31-1) to +/-180 with 0x80000000 = error */
gdouble longitude = -2.600439;
gint32 val = (gint) ((longitude / 180.0) * 2147483647.0);
gst_byte_writer_put_int32_be (&bw, val);
}
/* Tag 5: Sensor True Altitude (MSL) (elevation) */
gst_byte_writer_put_uint8 (&bw, 15); /* local tag: elevation */
gst_byte_writer_put_uint8 (&bw, 2); /* data length (BER short form) */
{
/* Map 0..(2^16-1) to -900..19000 meters, so resolution 0.303654536m */
gdouble elevation = 10.0;
guint16 val = ((elevation + 900.0 + 0.151827268) / 19900.0) * 65535.0;
gst_byte_writer_put_int16_be (&bw, val);
}
{
gsize klv_size = gst_byte_writer_get_size (&bw);
guint8 *klv_data = gst_byte_writer_reset_and_get_data (&bw);
gst_buffer_add_klv_meta_take_data (buf, klv_data, klv_size);
}
g_date_time_unref (dt);
}
static GstFlowReturn
gst_klvinject_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
{
GstKlvInject *filt = GST_KLVINJECT (trans);
GST_LOG_OBJECT (filt, "Injecting test KLV metadata");
gst_klvinject_add_test_meta (filt, buf);
return GST_FLOW_OK;
}

50
gst/klv/gstklvinject.h Normal file
View File

@ -0,0 +1,50 @@
/* GStreamer
* Copyright (C) 2016 William Manley <will@williammanley.net>
*
* 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 St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef _GST_KLVINJECT_H_
#define _GST_KLVINJECT_H_
#include <gst/base/gstbasetransform.h>
G_BEGIN_DECLS
#define GST_TYPE_KLVINJECT (gst_klvinject_get_type())
#define GST_KLVINJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_KLVINJECT,GstKlvInject))
#define GST_KLVINJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_KLVINJECT,GstKlvInjectClass))
#define GST_IS_KLVINJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_KLVINJECT))
#define GST_IS_KLVINJECT_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_KLVINJECT))
typedef struct _GstKlvInject GstKlvInject;
typedef struct _GstKlvInjectClass GstKlvInjectClass;
struct _GstKlvInject
{
GstBaseTransform base_klvinject;
};
struct _GstKlvInjectClass
{
GstBaseTransformClass base_klvinject_class;
};
GType gst_klvinject_get_type (void);
G_END_DECLS
#endif /* _GST_KLVINJECT_H_ */

124
gst/klv/gstklvinspect.c Normal file
View File

@ -0,0 +1,124 @@
/* GStreamer
* Copyright (C) 2016 William Manley <will@williammanley.net>
*
* 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-gstklvinspect
*
* The klvinspect element inspects KLV metadata on passing buffers.
*
* <refsect2>
* <title>Example launch line</title>
* |[
* gst-launch -v fakesrc ! klvinspect ! fakesink
* ]|
* FIXME Describe what the pipeline does.
* </refsect2>
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gst/gst.h>
#include <gst/base/gstbasetransform.h>
#include "gstklvinspect.h"
#include "klv.h"
GST_DEBUG_CATEGORY_STATIC (gst_klvinspect_debug_category);
#define GST_CAT_DEFAULT gst_klvinspect_debug_category
/* prototypes */
static GstFlowReturn gst_klvinspect_transform_ip (GstBaseTransform * trans,
GstBuffer * buf);
enum
{
PROP_0
};
/* pad templates */
#define SRC_CAPS "ANY"
#define SINK_CAPS "ANY"
/* class initialization */
G_DEFINE_TYPE_WITH_CODE (GstKlvInspect, gst_klvinspect, GST_TYPE_BASE_TRANSFORM,
GST_DEBUG_CATEGORY_INIT (gst_klvinspect_debug_category, "klvinspect", 0,
"debug category for klvinspect element"));
static void
gst_klvinspect_class_init (GstKlvInspectClass * klass)
{
GstBaseTransformClass *base_transform_class =
GST_BASE_TRANSFORM_CLASS (klass);
/* Setting up pads and setting metadata should be moved to
base_class_init if you intend to subclass this class. */
gst_element_class_add_pad_template (GST_ELEMENT_CLASS (klass),
gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
gst_caps_from_string (SRC_CAPS)));
gst_element_class_add_pad_template (GST_ELEMENT_CLASS (klass),
gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
gst_caps_from_string (SINK_CAPS)));
gst_element_class_set_static_metadata (GST_ELEMENT_CLASS (klass),
"Inspect KLV", "Filter", "Inspect KLV metadata",
"Joshua M. Doe <oss@nvl.army.mil>");
base_transform_class->transform_ip =
GST_DEBUG_FUNCPTR (gst_klvinspect_transform_ip);
base_transform_class->passthrough_on_same_caps = TRUE;
base_transform_class->transform_ip_on_passthrough = TRUE;
}
static void
gst_klvinspect_init (GstKlvInspect * filt)
{
}
static void
gst_klvinspect_dispose (GstKlvInspect * filt)
{
}
static GstFlowReturn
gst_klvinspect_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
{
GstKlvInspect *filt = GST_KLVINSPECT (trans);
GstKLVMeta *klv_meta;
gpointer iter = NULL;
gint n_klv_meta_found = 0;
while ((klv_meta = (GstKLVMeta *) gst_buffer_iterate_meta_filtered (buf,
&iter, GST_KLV_META_API_TYPE))) {
gsize klv_size;
const guint8 *klv_data;
klv_data = gst_klv_meta_get_data (klv_meta, &klv_size);
if (klv_data) {
GST_MEMDUMP_OBJECT (filt, "KLV data", klv_data, (guint) klv_size);
++n_klv_meta_found;
}
}
GST_LOG_OBJECT (filt, "Found %d KLV meta", n_klv_meta_found);
return GST_FLOW_OK;
}

50
gst/klv/gstklvinspect.h Normal file
View File

@ -0,0 +1,50 @@
/* GStreamer
* Copyright (C) 2016 William Manley <will@williammanley.net>
*
* 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 St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef _GST_KLVINSPECT_H_
#define _GST_KLVINSPECT_H_
#include <gst/base/gstbasetransform.h>
G_BEGIN_DECLS
#define GST_TYPE_KLVINSPECT (gst_klvinspect_get_type())
#define GST_KLVINSPECT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_KLVINSPECT,GstKlvInspect))
#define GST_KLVINSPECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_KLVINSPECT,GstKlvInspectClass))
#define GST_IS_KLVINSPECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_KLVINSPECT))
#define GST_IS_KLVINSPECT_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_KLVINSPECT))
typedef struct _GstKlvInspect GstKlvInspect;
typedef struct _GstKlvInspectClass GstKlvInspectClass;
struct _GstKlvInspect
{
GstBaseTransform base_klvinspect;
};
struct _GstKlvInspectClass
{
GstBaseTransformClass base_klvinspect_class;
};
GType gst_klvinspect_get_type (void);
G_END_DECLS
#endif /* _GST_KLVINSPECT_H_ */

View File

@ -1,12 +1,10 @@
add_definitions(-D_XKEYCHECK_H)
set (SOURCES
klv.c
gstpleora.cpp
gstpleorasrc.cpp)
set (HEADERS
klv.h
gstpleorasrc.h)
if (Pleora_VERSION_MAJOR GREATER 5)
@ -21,7 +19,10 @@ if (Pleora_VERSION_MAJOR GREATER 5)
endif ()
include_directories (AFTER
${Pleora_INCLUDE_DIR})
${Pleora_INCLUDE_DIR}
${PROJECT_SOURCE_DIR}/common
${PROJECT_SOURCE_DIR}/gst-libs/klv
)
link_directories(${Pleora_LIBRARY_DIR})
@ -36,7 +37,8 @@ target_link_libraries (${libname}
${GOBJECT_LIBRARIES}
${GSTREAMER_LIBRARY}
${GSTREAMER_BASE_LIBRARY}
${GSTREAMER_VIDEO_LIBRARY})
${GSTREAMER_VIDEO_LIBRARY}
libgstklv-1.0-0)
set (pdbfile "${CMAKE_CURRENT_BINARY_DIR}/\${CMAKE_INSTALL_CONFIG_NAME}/${libname}.pdb")
install (FILES ${pdbfile} DESTINATION lib/gstreamer-1.0 COMPONENT pdb)

View File

@ -313,16 +313,6 @@ GByteArray * GstStreamingChannelSource::GetKlvByteArray (GstBuffer * buf)
gpointer iter = NULL;
GByteArray *byte_array;
{
//FIXME put fake data for testing
const guint8 klv_header[18] =
{ 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x0b, 0x01, 0x01, 0x0e, 0x01, 0x03,
0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0xFF };
buf = gst_buffer_make_writable (buf);
gst_buffer_add_klv_meta_from_data (buf, klv_header, sizeof (klv_header));
gst_buffer_add_klv_meta_from_data (buf, klv_header, sizeof (klv_header));
}
/* spec says KLV can all be in one chunk, or multiple chunks, we do one chunk */
byte_array = g_byte_array_new ();
while ((klv_meta = (GstKLVMeta *) gst_buffer_iterate_meta_filtered (buf,