Add AJA source

This commit is contained in:
Sebastian Dröge 2021-02-08 20:31:22 +02:00
parent 577e9f936b
commit 453f482c0b
8 changed files with 1711 additions and 0 deletions

View file

@ -471,6 +471,67 @@ GType gst_aja_reference_source_get_type(void) {
return (GType)id;
}
GType gst_aja_input_source_get_type(void) {
static gsize id = 0;
static const GEnumValue modes[] = {
{GST_AJA_INPUT_SOURCE_AUTO, "auto", "Auto (based on selected channel)"},
{GST_AJA_INPUT_SOURCE_ANALOG1, "analog-1", "Analog Input 1"},
{GST_AJA_INPUT_SOURCE_SDI1, "sdi-1", "SDI Input 1"},
{GST_AJA_INPUT_SOURCE_SDI2, "sdi-2", "SDI Input 2"},
{GST_AJA_INPUT_SOURCE_SDI3, "sdi-3", "SDI Input 3"},
{GST_AJA_INPUT_SOURCE_SDI4, "sdi-4", "SDI Input 4"},
{GST_AJA_INPUT_SOURCE_SDI5, "sdi-5", "SDI Input 5"},
{GST_AJA_INPUT_SOURCE_SDI6, "sdi-6", "SDI Input 6"},
{GST_AJA_INPUT_SOURCE_SDI7, "sdi-7", "SDI Input 7"},
{GST_AJA_INPUT_SOURCE_SDI8, "sdi-8", "SDI Input 8"},
{GST_AJA_INPUT_SOURCE_HDMI1, "hdmi-1", "HDMI Input 1"},
{GST_AJA_INPUT_SOURCE_HDMI2, "hdmi-2", "HDMI Input 2"},
{GST_AJA_INPUT_SOURCE_HDMI3, "hdmi-3", "HDMI Input 3"},
{GST_AJA_INPUT_SOURCE_HDMI4, "hdmi-4", "HDMI Input 4"},
{0, NULL, NULL}};
if (g_once_init_enter(&id)) {
GType tmp = g_enum_register_static("GstAjaInputSource", modes);
g_once_init_leave(&id, tmp);
}
return (GType)id;
}
GType gst_aja_video_format_get_type(void) {
static gsize id = 0;
static const GEnumValue modes[] = {
// TODO: Implement: {GST_AJA_VIDEO_FORMAT_AUTO, "auto", "Autodetect"},
{GST_AJA_VIDEO_FORMAT_1080i_5000, "1080i-5000", "1080i 5000"},
{GST_AJA_VIDEO_FORMAT_1080i_5994, "1080i-5994", "1080i 5994"},
{GST_AJA_VIDEO_FORMAT_1080i_6000, "1080i-6000", "1080i 6000"},
{GST_AJA_VIDEO_FORMAT_720p_5994, "720p-5994", "720p 5994"},
{GST_AJA_VIDEO_FORMAT_720p_6000, "720p-6000", "720p 6000"},
{GST_AJA_VIDEO_FORMAT_1080p_2997, "1080p-2997", "1080p 2997"},
{GST_AJA_VIDEO_FORMAT_1080p_3000, "1080p-3000", "1080p 3000"},
{GST_AJA_VIDEO_FORMAT_1080p_2500, "1080p-2500", "1080p 2500"},
{GST_AJA_VIDEO_FORMAT_1080p_2398, "1080p-2398", "1080p 2398"},
{GST_AJA_VIDEO_FORMAT_1080p_2400, "1080p-2400", "1080p 2400"},
{GST_AJA_VIDEO_FORMAT_720p_5000, "720p-5000", "720p 5000"},
{GST_AJA_VIDEO_FORMAT_720p_2398, "720p-2398", "720p 2398"},
{GST_AJA_VIDEO_FORMAT_720p_2500, "720p-2500", "720p 2500"},
{GST_AJA_VIDEO_FORMAT_1080p_5000_A, "1080p-5000-a", "1080p 5000 A"},
{GST_AJA_VIDEO_FORMAT_1080p_5994_A, "1080p-5994-a", "1080p 5994 A"},
{GST_AJA_VIDEO_FORMAT_1080p_6000_A, "1080p-6000-a", "1080p 6000 A"},
{GST_AJA_VIDEO_FORMAT_625_5000, "625-5000", "625 5000"},
{GST_AJA_VIDEO_FORMAT_525_5994, "525-5994", "525 5994"},
{GST_AJA_VIDEO_FORMAT_525_2398, "525-2398", "525 2398"},
{GST_AJA_VIDEO_FORMAT_525_2400, "525-2400", "525 2400"},
{0, NULL, NULL}};
if (g_once_init_enter(&id)) {
GType tmp = g_enum_register_static("GstAjaVideoFormat", modes);
g_once_init_leave(&id, tmp);
}
return (GType)id;
}
void gst_aja_common_init(void) {
GST_DEBUG_CATEGORY_INIT(gst_aja_debug, "aja", 0,
"Debug category for AJA plugin");

View file

@ -156,6 +156,55 @@ typedef enum {
G_GNUC_INTERNAL
GType gst_aja_reference_source_get_type(void);
typedef enum {
GST_AJA_INPUT_SOURCE_AUTO,
GST_AJA_INPUT_SOURCE_ANALOG1,
GST_AJA_INPUT_SOURCE_HDMI1,
GST_AJA_INPUT_SOURCE_HDMI2,
GST_AJA_INPUT_SOURCE_HDMI3,
GST_AJA_INPUT_SOURCE_HDMI4,
GST_AJA_INPUT_SOURCE_SDI1,
GST_AJA_INPUT_SOURCE_SDI2,
GST_AJA_INPUT_SOURCE_SDI3,
GST_AJA_INPUT_SOURCE_SDI4,
GST_AJA_INPUT_SOURCE_SDI5,
GST_AJA_INPUT_SOURCE_SDI6,
GST_AJA_INPUT_SOURCE_SDI7,
GST_AJA_INPUT_SOURCE_SDI8,
} GstAjaInputSource;
#define GST_TYPE_AJA_INPUT_SOURCE (gst_aja_input_source_get_type())
G_GNUC_INTERNAL
GType gst_aja_input_source_get_type(void);
typedef enum {
// TODO: Implement: GST_AJA_VIDEO_FORMAT_AUTO,
GST_AJA_VIDEO_FORMAT_1080i_5000,
GST_AJA_VIDEO_FORMAT_1080i_5994,
GST_AJA_VIDEO_FORMAT_1080i_6000,
GST_AJA_VIDEO_FORMAT_720p_5994,
GST_AJA_VIDEO_FORMAT_720p_6000,
GST_AJA_VIDEO_FORMAT_1080p_2997,
GST_AJA_VIDEO_FORMAT_1080p_3000,
GST_AJA_VIDEO_FORMAT_1080p_2500,
GST_AJA_VIDEO_FORMAT_1080p_2398,
GST_AJA_VIDEO_FORMAT_1080p_2400,
GST_AJA_VIDEO_FORMAT_720p_5000,
GST_AJA_VIDEO_FORMAT_720p_2398,
GST_AJA_VIDEO_FORMAT_720p_2500,
GST_AJA_VIDEO_FORMAT_1080p_5000_A,
GST_AJA_VIDEO_FORMAT_1080p_5994_A,
GST_AJA_VIDEO_FORMAT_1080p_6000_A,
GST_AJA_VIDEO_FORMAT_625_5000,
GST_AJA_VIDEO_FORMAT_525_5994,
GST_AJA_VIDEO_FORMAT_525_2398,
GST_AJA_VIDEO_FORMAT_525_2400,
} GstAjaVideoFormat;
#define GST_TYPE_AJA_VIDEO_FORMAT (gst_aja_video_format_get_type())
G_GNUC_INTERNAL
GType gst_aja_video_format_get_type(void);
G_GNUC_INTERNAL
void gst_aja_common_init(void);

1280
gstajasrc.cpp Normal file

File diff suppressed because it is too large Load diff

90
gstajasrc.h Normal file
View file

@ -0,0 +1,90 @@
/* GStreamer
* Copyright (C) 2021 Sebastian Dröge <sebastian@centricular.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 St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#pragma once
#include <gst/base/base.h>
#include <gst/gst.h>
#include <gst/video/video.h>
#include "gstajacommon.h"
G_BEGIN_DECLS
#define GST_TYPE_AJA_SRC (gst_aja_src_get_type())
#define GST_AJA_SRC(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_AJA_SRC, GstAjaSrc))
#define GST_AJA_SRC_CAST(obj) ((GstAjaSrc *)obj)
#define GST_AJA_SRC_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_AJA_SRC, GstAjaSrcClass))
#define GST_IS_AJA_SRC(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_AJA_SRC))
#define GST_IS_AJA_SRC_CLASS(obj) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_AJA_SRC))
typedef struct _GstAjaSrc GstAjaSrc;
typedef struct _GstAjaSrcClass GstAjaSrcClass;
struct _GstAjaSrc {
GstPushSrc parent;
// Everything below protected by queue lock
GMutex queue_lock;
GCond queue_cond;
GstQueueArray *queue;
gboolean playing;
gboolean shutdown;
gboolean flushing;
GstAjaDevice *device;
NTV2DeviceID device_id;
GstAllocator *allocator;
GstBufferPool *buffer_pool;
GstBufferPool *audio_buffer_pool;
GstBufferPool *anc_buffer_pool;
// Properties
gchar *device_identifier;
NTV2Channel channel;
GstAjaAudioSystem audio_system_setting;
GstAjaVideoFormat video_format_setting;
GstAjaInputSource input_source;
GstAjaReferenceSource reference_source;
guint queue_size;
guint capture_cpu_core;
NTV2AudioSystem audio_system;
NTV2VideoFormat video_format;
guint32 f2_start_line;
GstCaps *configured_caps;
GstVideoInfo configured_info;
gint configured_audio_channels;
AJAThread *capture_thread;
};
struct _GstAjaSrcClass {
GstPushSrcClass parent_class;
};
G_GNUC_INTERNAL
GType gst_aja_src_get_type(void);
G_END_DECLS

162
gstajasrcdemux.cpp Normal file
View file

@ -0,0 +1,162 @@
/* GStreamer
* Copyright (C) 2021 Sebastian Dröge <sebastian@centricular.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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gst/audio/audio.h>
#include "gstajacommon.h"
#include "gstajasrcdemux.h"
GST_DEBUG_CATEGORY_STATIC(gst_aja_src_demux_debug);
#define GST_CAT_DEFAULT gst_aja_src_demux_debug
static GstStaticPadTemplate video_src_template = GST_STATIC_PAD_TEMPLATE(
"video", GST_PAD_SRC, GST_PAD_ALWAYS, GST_STATIC_CAPS("video/x-raw"));
static GstStaticPadTemplate audio_src_template = GST_STATIC_PAD_TEMPLATE(
"audio", GST_PAD_SRC, GST_PAD_ALWAYS, GST_STATIC_CAPS("audio/x-raw"));
static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE(
"sink", GST_PAD_SINK, GST_PAD_ALWAYS, GST_STATIC_CAPS("video/x-raw"));
static GstFlowReturn gst_aja_src_demux_sink_chain(GstPad *pad,
GstObject *parent,
GstBuffer *buffer);
static gboolean gst_aja_src_demux_sink_event(GstPad *pad, GstObject *parent,
GstEvent *event);
#define parent_class gst_aja_src_demux_parent_class
G_DEFINE_TYPE(GstAjaSrcDemux, gst_aja_src_demux, GST_TYPE_ELEMENT);
static void gst_aja_src_demux_class_init(GstAjaSrcDemuxClass *klass) {
GstElementClass *element_class = GST_ELEMENT_CLASS(klass);
gst_element_class_add_static_pad_template(element_class, &sink_template);
gst_element_class_add_static_pad_template(element_class, &video_src_template);
gst_element_class_add_static_pad_template(element_class, &audio_src_template);
gst_element_class_set_static_metadata(
element_class, "AJA audio/video source demuxer", "Audio/Video/Demux",
"Demuxes audio/video from video buffers",
"Sebastian Dröge <sebastian@centricular.com>");
GST_DEBUG_CATEGORY_INIT(gst_aja_src_demux_debug, "ajasrcdemux", 0,
"AJA source demuxer");
}
static void gst_aja_src_demux_init(GstAjaSrcDemux *self) {
self->sink = gst_pad_new_from_static_template(&sink_template, "sink");
gst_pad_set_chain_function(self->sink,
GST_DEBUG_FUNCPTR(gst_aja_src_demux_sink_chain));
gst_pad_set_event_function(self->sink,
GST_DEBUG_FUNCPTR(gst_aja_src_demux_sink_event));
gst_element_add_pad(GST_ELEMENT(self), self->sink);
self->audio_src =
gst_pad_new_from_static_template(&audio_src_template, "audio");
gst_pad_use_fixed_caps(self->audio_src);
gst_element_add_pad(GST_ELEMENT(self), self->audio_src);
self->video_src =
gst_pad_new_from_static_template(&video_src_template, "video");
gst_pad_use_fixed_caps(self->video_src);
gst_element_add_pad(GST_ELEMENT(self), self->video_src);
}
static GstFlowReturn gst_aja_src_demux_sink_chain(GstPad *pad,
GstObject *parent,
GstBuffer *buffer) {
GstAjaSrcDemux *self = GST_AJA_SRC_DEMUX(parent);
GstAjaAudioMeta *meta = gst_buffer_get_aja_audio_meta(buffer);
GstFlowReturn audio_flow_ret = GST_FLOW_OK;
GstFlowReturn video_flow_ret = GST_FLOW_OK;
if (meta) {
GstBuffer *audio_buffer;
buffer = gst_buffer_make_writable(buffer);
meta = gst_buffer_get_aja_audio_meta(buffer);
audio_buffer = gst_buffer_ref(meta->buffer);
gst_buffer_remove_meta(buffer, GST_META_CAST(meta));
audio_flow_ret = gst_pad_push(self->audio_src, audio_buffer);
} else {
GstEvent *event =
gst_event_new_gap(GST_BUFFER_PTS(buffer), GST_BUFFER_DURATION(buffer));
gst_pad_push_event(self->audio_src, event);
}
video_flow_ret = gst_pad_push(self->video_src, buffer);
// Combine flows the way it makes sense
if (video_flow_ret == GST_FLOW_NOT_LINKED &&
audio_flow_ret == GST_FLOW_NOT_LINKED)
return GST_FLOW_NOT_LINKED;
if (video_flow_ret == GST_FLOW_EOS && audio_flow_ret == GST_FLOW_EOS)
return GST_FLOW_EOS;
if (video_flow_ret == GST_FLOW_FLUSHING ||
video_flow_ret <= GST_FLOW_NOT_NEGOTIATED)
return video_flow_ret;
if (audio_flow_ret == GST_FLOW_FLUSHING ||
audio_flow_ret <= GST_FLOW_NOT_NEGOTIATED)
return audio_flow_ret;
return GST_FLOW_OK;
}
static gboolean gst_aja_src_demux_sink_event(GstPad *pad, GstObject *parent,
GstEvent *event) {
GstAjaSrcDemux *self = GST_AJA_SRC_DEMUX(parent);
switch (GST_EVENT_TYPE(event)) {
case GST_EVENT_CAPS: {
GstCaps *caps;
GstStructure *s;
GstAudioInfo audio_info;
gint audio_channels = 0;
gst_event_parse_caps(event, &caps);
s = gst_caps_get_structure(caps, 0);
gst_structure_get_int(s, "audio-channels", &audio_channels);
GstCaps *audio_caps, *video_caps;
gst_audio_info_init(&audio_info);
gst_audio_info_set_format(&audio_info, GST_AUDIO_FORMAT_S32LE, 48000,
audio_channels ? audio_channels : 1, NULL);
audio_caps = gst_audio_info_to_caps(&audio_info);
gst_pad_set_caps(self->audio_src, audio_caps);
gst_caps_unref(audio_caps);
video_caps = gst_caps_ref(caps);
gst_event_unref(event);
video_caps = gst_caps_make_writable(video_caps);
s = gst_caps_get_structure(video_caps, 0);
gst_structure_remove_field(s, "audio-channels");
gst_pad_set_caps(self->video_src, video_caps);
gst_caps_unref(video_caps);
return TRUE;
}
default:
return gst_pad_event_default(pad, parent, event);
}
}

59
gstajasrcdemux.h Normal file
View file

@ -0,0 +1,59 @@
/* GStreamer
* Copyright (C) 2021 Sebastian Dröge <sebastian@centricular.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 St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#pragma once
#include <gst/base/base.h>
#include <gst/gst.h>
#include <gst/video/video.h>
#include "gstajacommon.h"
G_BEGIN_DECLS
#define GST_TYPE_AJA_SRC_DEMUX (gst_aja_src_demux_get_type())
#define GST_AJA_SRC_DEMUX(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_AJA_SRC_DEMUX, GstAjaSrcDemux))
#define GST_AJA_SRC_DEMUX_CAST(obj) ((GstAjaSrcDemux *)obj)
#define GST_AJA_SRC_DEMUX_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_AJA_SRC_DEMUX, \
GstAjaSrcDemuxClass))
#define GST_IS_AJA_SRC_DEMUX(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_AJA_SRC_DEMUX))
#define GST_IS_AJA_SRC_DEMUX_CLASS(obj) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_AJA_SRC_DEMUX))
typedef struct _GstAjaSrcDemux GstAjaSrcDemux;
typedef struct _GstAjaSrcDemuxClass GstAjaSrcDemuxClass;
struct _GstAjaSrcDemux {
GstElement parent;
GstPad *sink;
GstPad *video_src, *audio_src;
};
struct _GstAjaSrcDemuxClass {
GstElementClass parent_class;
};
G_GNUC_INTERNAL
GType gst_aja_src_demux_get_type(void);
G_END_DECLS

View file

@ -82,6 +82,8 @@ gstaja = library('gstaja',
'gstajacommon.cpp',
'gstajasink.cpp',
'gstajasinkcombiner.cpp',
'gstajasrc.cpp',
'gstajasrcdemux.cpp',
],
cpp_args : [
aja_includedirs,

View file

@ -17,15 +17,23 @@
* Boston, MA 02110-1335, USA.
*/
#include <ajabase/system/debug.h>
#include <gst/gst.h>
#include "gstajacommon.h"
#include "gstajasink.h"
#include "gstajasinkcombiner.h"
#include "gstajasrc.h"
#include "gstajasrcdemux.h"
static gboolean plugin_init(GstPlugin* plugin) {
AJADebug::Open();
gst_aja_common_init();
gst_element_register(plugin, "ajasrc", GST_RANK_NONE, GST_TYPE_AJA_SRC);
gst_element_register(plugin, "ajasrcdemux", GST_RANK_NONE,
GST_TYPE_AJA_SRC_DEMUX);
gst_element_register(plugin, "ajasink", GST_RANK_NONE, GST_TYPE_AJA_SINK);
gst_element_register(plugin, "ajasinkcombiner", GST_RANK_NONE,
GST_TYPE_AJA_SINK_COMBINER);