2005-05-15 19:21:04 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* This file:
|
|
|
|
* Copyright (C) 2005 Luca Ognibene <luogni@tin.it>
|
2006-01-20 14:17:16 +00:00
|
|
|
* Copyright (C) 2006 Martin Zlomek <martin.zlomek@itonis.tv>
|
2005-05-15 19:21:04 +00:00
|
|
|
*
|
|
|
|
* 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
|
2012-11-04 00:22:16 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2005-05-15 19:21:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2006-01-20 14:17:16 +00:00
|
|
|
# include "config.h"
|
2005-05-15 19:21:04 +00:00
|
|
|
#endif
|
|
|
|
|
2012-09-10 15:08:00 +00:00
|
|
|
#include <libavcodec/avcodec.h>
|
2016-01-19 07:42:47 +00:00
|
|
|
#include <libavutil/imgutils.h>
|
2015-11-04 20:16:18 +00:00
|
|
|
#include <libavfilter/avfilter.h>
|
|
|
|
#include <libavfilter/buffersrc.h>
|
|
|
|
#include <libavfilter/buffersink.h>
|
2005-05-15 19:21:04 +00:00
|
|
|
|
2006-01-20 14:17:16 +00:00
|
|
|
#include <gst/gst.h>
|
2005-05-15 19:21:04 +00:00
|
|
|
#include <gst/video/video.h>
|
2006-01-20 14:17:16 +00:00
|
|
|
|
2012-09-10 15:53:54 +00:00
|
|
|
#include "gstav.h"
|
|
|
|
#include "gstavcodecmap.h"
|
|
|
|
#include "gstavutils.h"
|
2005-05-15 19:21:04 +00:00
|
|
|
|
2011-08-12 08:06:03 +00:00
|
|
|
|
|
|
|
/* Properties */
|
|
|
|
|
|
|
|
#define DEFAULT_MODE GST_FFMPEGDEINTERLACE_MODE_AUTO
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_MODE,
|
|
|
|
PROP_LAST
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
GST_FFMPEGDEINTERLACE_MODE_AUTO,
|
|
|
|
GST_FFMPEGDEINTERLACE_MODE_INTERLACED,
|
|
|
|
GST_FFMPEGDEINTERLACE_MODE_DISABLED
|
|
|
|
} GstFFMpegDeinterlaceMode;
|
|
|
|
|
|
|
|
#define GST_TYPE_FFMPEGDEINTERLACE_MODES (gst_ffmpegdeinterlace_modes_get_type ())
|
|
|
|
static GType
|
|
|
|
gst_ffmpegdeinterlace_modes_get_type (void)
|
|
|
|
{
|
|
|
|
static GType deinterlace_modes_type = 0;
|
|
|
|
|
|
|
|
static const GEnumValue modes_types[] = {
|
|
|
|
{GST_FFMPEGDEINTERLACE_MODE_AUTO, "Auto detection", "auto"},
|
|
|
|
{GST_FFMPEGDEINTERLACE_MODE_INTERLACED, "Force deinterlacing",
|
|
|
|
"interlaced"},
|
|
|
|
{GST_FFMPEGDEINTERLACE_MODE_DISABLED, "Run in passthrough mode",
|
|
|
|
"disabled"},
|
|
|
|
{0, NULL, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!deinterlace_modes_type) {
|
|
|
|
deinterlace_modes_type =
|
2012-04-12 17:41:52 +00:00
|
|
|
g_enum_register_static ("GstLibAVDeinterlaceModes", modes_types);
|
2011-08-12 08:06:03 +00:00
|
|
|
}
|
|
|
|
return deinterlace_modes_type;
|
|
|
|
}
|
|
|
|
|
2006-01-20 14:17:16 +00:00
|
|
|
typedef struct _GstFFMpegDeinterlace
|
2005-05-15 19:21:04 +00:00
|
|
|
{
|
|
|
|
GstElement element;
|
|
|
|
|
|
|
|
GstPad *sinkpad, *srcpad;
|
|
|
|
|
|
|
|
gint width, height;
|
2006-01-20 14:17:16 +00:00
|
|
|
gint to_size;
|
2005-05-15 19:21:04 +00:00
|
|
|
|
2011-08-12 08:06:03 +00:00
|
|
|
GstFFMpegDeinterlaceMode mode;
|
|
|
|
|
|
|
|
gboolean interlaced; /* is input interlaced? */
|
|
|
|
gboolean passthrough;
|
|
|
|
|
|
|
|
gboolean reconfigure;
|
|
|
|
GstFFMpegDeinterlaceMode new_mode;
|
|
|
|
|
2015-11-04 20:18:56 +00:00
|
|
|
enum AVPixelFormat pixfmt;
|
2018-06-29 02:52:02 +00:00
|
|
|
AVFrame from_frame, to_frame;
|
2015-11-04 20:16:18 +00:00
|
|
|
|
|
|
|
AVFilterContext *buffersink_ctx;
|
|
|
|
AVFilterContext *buffersrc_ctx;
|
|
|
|
AVFilterGraph *filter_graph;
|
|
|
|
AVFrame *filter_frame;
|
|
|
|
int last_width, last_height;
|
|
|
|
enum AVPixelFormat last_pixfmt;
|
|
|
|
|
2006-01-20 14:17:16 +00:00
|
|
|
} GstFFMpegDeinterlace;
|
2005-05-15 19:21:04 +00:00
|
|
|
|
2006-01-20 14:17:16 +00:00
|
|
|
typedef struct _GstFFMpegDeinterlaceClass
|
2005-05-15 19:21:04 +00:00
|
|
|
{
|
|
|
|
GstElementClass parent_class;
|
2006-01-20 14:17:16 +00:00
|
|
|
} GstFFMpegDeinterlaceClass;
|
2005-05-15 19:21:04 +00:00
|
|
|
|
2006-01-20 14:17:16 +00:00
|
|
|
#define GST_TYPE_FFMPEGDEINTERLACE \
|
|
|
|
(gst_ffmpegdeinterlace_get_type())
|
|
|
|
#define GST_FFMPEGDEINTERLACE(obj) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_FFMPEGDEINTERLACE,GstFFMpegDeinterlace))
|
|
|
|
#define GST_FFMPEGDEINTERLACE_CLASS(klass) \
|
|
|
|
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_FFMPEGDEINTERLACE,GstFFMpegDeinterlace))
|
|
|
|
#define GST_IS_FFMPEGDEINTERLACE(obj) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_FFMPEGDEINTERLACE))
|
2006-09-16 22:19:40 +00:00
|
|
|
#define GST_IS_FFMPEGDEINTERLACE_CLASS(klass) \
|
2006-01-20 14:17:16 +00:00
|
|
|
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_FFMPEGDEINTERLACE))
|
2005-05-15 19:21:04 +00:00
|
|
|
|
2010-03-24 11:07:28 +00:00
|
|
|
GType gst_ffmpegdeinterlace_get_type (void);
|
|
|
|
|
2011-08-12 08:06:03 +00:00
|
|
|
static void gst_ffmpegdeinterlace_set_property (GObject * self, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_ffmpegdeinterlace_get_property (GObject * self, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
|
2006-01-20 14:17:16 +00:00
|
|
|
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
2005-05-15 19:21:04 +00:00
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2011-06-20 08:42:30 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("I420"))
|
2005-05-15 19:21:04 +00:00
|
|
|
);
|
|
|
|
|
2006-01-20 14:17:16 +00:00
|
|
|
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
|
2005-05-15 19:21:04 +00:00
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2011-06-20 08:42:30 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("I420"))
|
2005-05-15 19:21:04 +00:00
|
|
|
);
|
|
|
|
|
2011-04-19 17:04:36 +00:00
|
|
|
G_DEFINE_TYPE (GstFFMpegDeinterlace, gst_ffmpegdeinterlace, GST_TYPE_ELEMENT);
|
2005-05-15 19:21:04 +00:00
|
|
|
|
2006-01-20 14:17:16 +00:00
|
|
|
static GstFlowReturn gst_ffmpegdeinterlace_chain (GstPad * pad,
|
2011-11-17 11:49:33 +00:00
|
|
|
GstObject * parent, GstBuffer * inbuf);
|
2005-05-15 19:21:04 +00:00
|
|
|
|
2015-11-04 20:16:18 +00:00
|
|
|
static void gst_ffmpegdeinterlace_dispose (GObject * obj);
|
|
|
|
|
2006-01-20 14:17:16 +00:00
|
|
|
static void
|
2011-04-19 17:04:36 +00:00
|
|
|
gst_ffmpegdeinterlace_class_init (GstFFMpegDeinterlaceClass * klass)
|
2005-05-15 19:21:04 +00:00
|
|
|
{
|
2011-08-12 08:06:03 +00:00
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
2011-04-19 17:04:36 +00:00
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
2005-05-15 19:21:04 +00:00
|
|
|
|
2011-08-12 08:06:03 +00:00
|
|
|
gobject_class->set_property = gst_ffmpegdeinterlace_set_property;
|
|
|
|
gobject_class->get_property = gst_ffmpegdeinterlace_get_property;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GstFFMpegDeinterlace:mode
|
|
|
|
*
|
|
|
|
* This selects whether the deinterlacing methods should
|
|
|
|
* always be applied or if they should only be applied
|
|
|
|
* on content that has the "interlaced" flag on the caps.
|
|
|
|
*
|
|
|
|
* Since: 0.10.13
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_MODE,
|
|
|
|
g_param_spec_enum ("mode", "Mode", "Deinterlace Mode",
|
|
|
|
GST_TYPE_FFMPEGDEINTERLACE_MODES,
|
|
|
|
DEFAULT_MODE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)
|
|
|
|
);
|
2011-09-28 11:29:08 +00:00
|
|
|
|
2016-03-04 07:42:03 +00:00
|
|
|
gst_element_class_add_static_pad_template (element_class, &src_factory);
|
|
|
|
gst_element_class_add_static_pad_template (element_class, &sink_factory);
|
2011-04-19 17:04:36 +00:00
|
|
|
|
2012-04-09 23:53:43 +00:00
|
|
|
gst_element_class_set_static_metadata (element_class,
|
2012-04-12 17:41:52 +00:00
|
|
|
"libav Deinterlace element", "Filter/Effect/Video/Deinterlace",
|
2010-03-24 10:51:26 +00:00
|
|
|
"Deinterlace video", "Luca Ognibene <luogni@tin.it>");
|
2015-11-04 20:16:18 +00:00
|
|
|
|
|
|
|
gobject_class->dispose = gst_ffmpegdeinterlace_dispose;
|
2006-01-20 14:17:16 +00:00
|
|
|
}
|
2005-05-15 19:21:04 +00:00
|
|
|
|
2011-08-12 08:06:03 +00:00
|
|
|
static void
|
|
|
|
gst_ffmpegdeinterlace_update_passthrough (GstFFMpegDeinterlace * deinterlace)
|
|
|
|
{
|
|
|
|
deinterlace->passthrough =
|
|
|
|
(deinterlace->mode == GST_FFMPEGDEINTERLACE_MODE_DISABLED
|
|
|
|
|| (!deinterlace->interlaced
|
|
|
|
&& deinterlace->mode != GST_FFMPEGDEINTERLACE_MODE_INTERLACED));
|
|
|
|
GST_DEBUG_OBJECT (deinterlace, "Passthrough: %d", deinterlace->passthrough);
|
2005-05-15 19:21:04 +00:00
|
|
|
}
|
|
|
|
|
2006-01-20 14:17:16 +00:00
|
|
|
static gboolean
|
|
|
|
gst_ffmpegdeinterlace_sink_setcaps (GstPad * pad, GstCaps * caps)
|
2005-05-15 19:21:04 +00:00
|
|
|
{
|
2006-01-20 14:17:16 +00:00
|
|
|
GstFFMpegDeinterlace *deinterlace =
|
|
|
|
GST_FFMPEGDEINTERLACE (gst_pad_get_parent (pad));
|
|
|
|
GstStructure *structure = gst_caps_get_structure (caps, 0);
|
2012-07-17 11:31:52 +00:00
|
|
|
const gchar *imode;
|
2005-05-15 19:21:04 +00:00
|
|
|
AVCodecContext *ctx;
|
2010-07-18 19:15:32 +00:00
|
|
|
GstCaps *src_caps;
|
|
|
|
gboolean ret;
|
2005-05-15 19:21:04 +00:00
|
|
|
|
2012-07-17 11:31:52 +00:00
|
|
|
/* FIXME: use GstVideoInfo etc. */
|
2006-01-20 14:17:16 +00:00
|
|
|
if (!gst_structure_get_int (structure, "width", &deinterlace->width))
|
|
|
|
return FALSE;
|
|
|
|
if (!gst_structure_get_int (structure, "height", &deinterlace->height))
|
|
|
|
return FALSE;
|
2005-05-15 19:21:04 +00:00
|
|
|
|
2011-08-12 08:06:03 +00:00
|
|
|
deinterlace->interlaced = FALSE;
|
2012-07-17 11:31:52 +00:00
|
|
|
imode = gst_structure_get_string (structure, "interlace-mode");
|
|
|
|
if (imode && (!strcmp (imode, "interleaved") || !strcmp (imode, "mixed"))) {
|
|
|
|
deinterlace->interlaced = TRUE;
|
|
|
|
}
|
2011-08-12 08:06:03 +00:00
|
|
|
gst_ffmpegdeinterlace_update_passthrough (deinterlace);
|
|
|
|
|
2012-11-19 14:25:42 +00:00
|
|
|
ctx = avcodec_alloc_context3 (NULL);
|
2006-01-20 14:17:16 +00:00
|
|
|
ctx->width = deinterlace->width;
|
|
|
|
ctx->height = deinterlace->height;
|
2015-03-10 09:17:45 +00:00
|
|
|
ctx->pix_fmt = AV_PIX_FMT_NB;
|
2011-04-19 17:29:57 +00:00
|
|
|
gst_ffmpeg_caps_with_codectype (AVMEDIA_TYPE_VIDEO, caps, ctx);
|
2015-03-10 09:17:45 +00:00
|
|
|
if (ctx->pix_fmt == AV_PIX_FMT_NB) {
|
2014-01-15 09:02:33 +00:00
|
|
|
gst_ffmpeg_avcodec_close (ctx);
|
2005-05-15 19:21:04 +00:00
|
|
|
av_free (ctx);
|
2006-01-20 14:17:16 +00:00
|
|
|
return FALSE;
|
2005-05-15 19:21:04 +00:00
|
|
|
}
|
2011-06-08 16:04:07 +00:00
|
|
|
|
2005-05-15 19:21:04 +00:00
|
|
|
deinterlace->pixfmt = ctx->pix_fmt;
|
2011-06-08 16:04:07 +00:00
|
|
|
|
2006-01-20 14:17:16 +00:00
|
|
|
av_free (ctx);
|
2011-06-08 16:04:07 +00:00
|
|
|
|
2006-01-20 14:17:16 +00:00
|
|
|
deinterlace->to_size =
|
2016-01-19 07:42:47 +00:00
|
|
|
av_image_get_buffer_size (deinterlace->pixfmt, deinterlace->width,
|
|
|
|
deinterlace->height, 1);
|
2011-06-08 16:04:07 +00:00
|
|
|
|
2010-07-18 19:15:32 +00:00
|
|
|
src_caps = gst_caps_copy (caps);
|
2012-07-17 11:33:16 +00:00
|
|
|
gst_caps_set_simple (src_caps, "interlace-mode", G_TYPE_STRING,
|
|
|
|
deinterlace->interlaced ? "progressive" : imode, NULL);
|
2010-07-18 19:15:32 +00:00
|
|
|
ret = gst_pad_set_caps (deinterlace->srcpad, src_caps);
|
|
|
|
gst_caps_unref (src_caps);
|
2011-06-08 16:04:07 +00:00
|
|
|
|
2010-06-25 14:26:00 +00:00
|
|
|
return ret;
|
2005-05-15 19:21:04 +00:00
|
|
|
}
|
2011-06-08 16:04:07 +00:00
|
|
|
|
2011-09-28 11:29:08 +00:00
|
|
|
static gboolean
|
2011-11-17 11:49:33 +00:00
|
|
|
gst_ffmpegdeinterlace_sink_event (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event)
|
2011-09-28 11:29:08 +00:00
|
|
|
{
|
2011-11-17 11:49:33 +00:00
|
|
|
GstFFMpegDeinterlace *deinterlace = GST_FFMPEGDEINTERLACE (parent);
|
2011-09-28 11:29:08 +00:00
|
|
|
gboolean ret = FALSE;
|
2011-06-08 16:04:07 +00:00
|
|
|
|
2011-09-28 11:29:08 +00:00
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_CAPS:
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
2011-06-08 16:04:07 +00:00
|
|
|
|
2011-09-28 11:29:08 +00:00
|
|
|
gst_event_parse_caps (event, &caps);
|
|
|
|
ret = gst_ffmpegdeinterlace_sink_setcaps (pad, caps);
|
2011-06-08 16:04:07 +00:00
|
|
|
gst_event_unref (event);
|
|
|
|
break;
|
2011-09-28 11:29:08 +00:00
|
|
|
}
|
2011-06-08 16:04:07 +00:00
|
|
|
default:
|
2011-09-28 11:29:08 +00:00
|
|
|
ret = gst_pad_push_event (deinterlace->srcpad, event);
|
2011-06-08 16:04:07 +00:00
|
|
|
break;
|
2005-05-15 19:21:04 +00:00
|
|
|
}
|
|
|
|
|
2010-06-25 14:26:00 +00:00
|
|
|
return ret;
|
2005-05-15 19:21:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-04-19 17:04:36 +00:00
|
|
|
gst_ffmpegdeinterlace_init (GstFFMpegDeinterlace * deinterlace)
|
2005-05-15 19:21:04 +00:00
|
|
|
{
|
2006-01-20 14:17:16 +00:00
|
|
|
deinterlace->sinkpad =
|
|
|
|
gst_pad_new_from_static_template (&sink_factory, "sink");
|
2011-06-08 16:04:07 +00:00
|
|
|
gst_pad_set_event_function (deinterlace->sinkpad,
|
|
|
|
gst_ffmpegdeinterlace_sink_event);
|
2006-01-20 14:17:16 +00:00
|
|
|
gst_pad_set_chain_function (deinterlace->sinkpad,
|
|
|
|
gst_ffmpegdeinterlace_chain);
|
2005-05-15 19:21:04 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (deinterlace), deinterlace->sinkpad);
|
|
|
|
|
2006-01-20 14:17:16 +00:00
|
|
|
deinterlace->srcpad = gst_pad_new_from_static_template (&src_factory, "src");
|
2005-05-15 19:21:04 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (deinterlace), deinterlace->srcpad);
|
|
|
|
|
2015-03-10 09:17:45 +00:00
|
|
|
deinterlace->pixfmt = AV_PIX_FMT_NB;
|
2011-08-12 08:06:03 +00:00
|
|
|
|
|
|
|
deinterlace->interlaced = FALSE;
|
|
|
|
deinterlace->passthrough = FALSE;
|
|
|
|
deinterlace->reconfigure = FALSE;
|
|
|
|
deinterlace->mode = DEFAULT_MODE;
|
|
|
|
deinterlace->new_mode = -1;
|
2015-11-04 20:16:18 +00:00
|
|
|
deinterlace->last_width = -1;
|
|
|
|
deinterlace->last_height = -1;
|
|
|
|
deinterlace->last_pixfmt = AV_PIX_FMT_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
delete_filter_graph (GstFFMpegDeinterlace * deinterlace)
|
|
|
|
{
|
|
|
|
if (deinterlace->filter_graph) {
|
|
|
|
av_frame_free (&deinterlace->filter_frame);
|
|
|
|
avfilter_graph_free (&deinterlace->filter_graph);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_ffmpegdeinterlace_dispose (GObject * obj)
|
|
|
|
{
|
|
|
|
GstFFMpegDeinterlace *deinterlace = GST_FFMPEGDEINTERLACE (obj);
|
2016-01-16 14:43:16 +00:00
|
|
|
|
2015-11-04 20:16:18 +00:00
|
|
|
delete_filter_graph (deinterlace);
|
2016-01-16 14:43:16 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gst_ffmpegdeinterlace_parent_class)->dispose (obj);
|
2015-11-04 20:16:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
init_filter_graph (GstFFMpegDeinterlace * deinterlace,
|
|
|
|
enum AVPixelFormat pixfmt, int width, int height)
|
|
|
|
{
|
|
|
|
AVFilterInOut *inputs = NULL, *outputs = NULL;
|
|
|
|
char args[512];
|
|
|
|
int res;
|
|
|
|
|
|
|
|
delete_filter_graph (deinterlace);
|
|
|
|
deinterlace->filter_graph = avfilter_graph_alloc ();
|
|
|
|
snprintf (args, sizeof (args),
|
|
|
|
"buffer=video_size=%dx%d:pix_fmt=%d:time_base=1/1:pixel_aspect=0/1[in];"
|
|
|
|
"[in]yadif[out];" "[out]buffersink", width, height, pixfmt);
|
|
|
|
res =
|
|
|
|
avfilter_graph_parse2 (deinterlace->filter_graph, args, &inputs,
|
|
|
|
&outputs);
|
|
|
|
if (res < 0)
|
|
|
|
return res;
|
|
|
|
if (inputs || outputs)
|
|
|
|
return -1;
|
|
|
|
res = avfilter_graph_config (deinterlace->filter_graph, NULL);
|
|
|
|
if (res < 0)
|
|
|
|
return res;
|
|
|
|
|
|
|
|
deinterlace->buffersrc_ctx =
|
|
|
|
avfilter_graph_get_filter (deinterlace->filter_graph, "Parsed_buffer_0");
|
|
|
|
deinterlace->buffersink_ctx =
|
|
|
|
avfilter_graph_get_filter (deinterlace->filter_graph,
|
|
|
|
"Parsed_buffersink_2");
|
|
|
|
if (!deinterlace->buffersrc_ctx || !deinterlace->buffersink_ctx)
|
|
|
|
return -1;
|
|
|
|
deinterlace->filter_frame = av_frame_alloc ();
|
|
|
|
deinterlace->last_width = width;
|
|
|
|
deinterlace->last_height = height;
|
|
|
|
deinterlace->last_pixfmt = pixfmt;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2018-06-29 02:52:02 +00:00
|
|
|
process_filter_graph (GstFFMpegDeinterlace * deinterlace, AVFrame * dst,
|
|
|
|
const AVFrame * src, enum AVPixelFormat pixfmt, int width, int height)
|
2015-11-04 20:16:18 +00:00
|
|
|
{
|
|
|
|
int res;
|
|
|
|
|
|
|
|
if (!deinterlace->filter_graph || width != deinterlace->last_width ||
|
|
|
|
height != deinterlace->last_height
|
|
|
|
|| pixfmt != deinterlace->last_pixfmt) {
|
|
|
|
res = init_filter_graph (deinterlace, pixfmt, width, height);
|
|
|
|
if (res < 0)
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy (deinterlace->filter_frame->data, src->data, sizeof (src->data));
|
|
|
|
memcpy (deinterlace->filter_frame->linesize, src->linesize,
|
|
|
|
sizeof (src->linesize));
|
|
|
|
deinterlace->filter_frame->width = width;
|
|
|
|
deinterlace->filter_frame->height = height;
|
|
|
|
deinterlace->filter_frame->format = pixfmt;
|
|
|
|
res =
|
|
|
|
av_buffersrc_add_frame (deinterlace->buffersrc_ctx,
|
|
|
|
deinterlace->filter_frame);
|
|
|
|
if (res < 0)
|
|
|
|
return res;
|
|
|
|
res =
|
|
|
|
av_buffersink_get_frame (deinterlace->buffersink_ctx,
|
|
|
|
deinterlace->filter_frame);
|
|
|
|
if (res < 0)
|
|
|
|
return res;
|
2018-06-29 02:52:02 +00:00
|
|
|
av_image_copy (dst->data, dst->linesize,
|
|
|
|
(const uint8_t **) deinterlace->filter_frame->data,
|
|
|
|
deinterlace->filter_frame->linesize, pixfmt, width, height);
|
2015-11-04 20:16:18 +00:00
|
|
|
av_frame_unref (deinterlace->filter_frame);
|
|
|
|
|
|
|
|
return 0;
|
2005-05-15 19:21:04 +00:00
|
|
|
}
|
|
|
|
|
2006-01-20 14:17:16 +00:00
|
|
|
static GstFlowReturn
|
2011-11-17 11:49:33 +00:00
|
|
|
gst_ffmpegdeinterlace_chain (GstPad * pad, GstObject * parent,
|
|
|
|
GstBuffer * inbuf)
|
2005-05-15 19:21:04 +00:00
|
|
|
{
|
2011-11-17 11:49:33 +00:00
|
|
|
GstFFMpegDeinterlace *deinterlace = GST_FFMPEGDEINTERLACE (parent);
|
2005-05-15 19:21:04 +00:00
|
|
|
GstBuffer *outbuf = NULL;
|
2006-01-20 14:17:16 +00:00
|
|
|
GstFlowReturn result;
|
2012-01-24 13:40:37 +00:00
|
|
|
GstMapInfo from_map, to_map;
|
2005-05-15 19:21:04 +00:00
|
|
|
|
2011-08-12 08:06:03 +00:00
|
|
|
GST_OBJECT_LOCK (deinterlace);
|
|
|
|
if (deinterlace->reconfigure) {
|
2016-02-23 16:19:18 +00:00
|
|
|
GstCaps *caps;
|
|
|
|
|
2013-12-16 05:17:26 +00:00
|
|
|
if ((gint) deinterlace->new_mode != -1)
|
2011-08-12 08:06:03 +00:00
|
|
|
deinterlace->mode = deinterlace->new_mode;
|
|
|
|
deinterlace->new_mode = -1;
|
|
|
|
|
|
|
|
deinterlace->reconfigure = FALSE;
|
|
|
|
GST_OBJECT_UNLOCK (deinterlace);
|
2016-02-23 16:19:18 +00:00
|
|
|
if ((caps = gst_pad_get_current_caps (deinterlace->srcpad))) {
|
2011-09-28 11:29:08 +00:00
|
|
|
gst_ffmpegdeinterlace_sink_setcaps (deinterlace->sinkpad, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
}
|
2011-08-12 08:06:03 +00:00
|
|
|
} else {
|
|
|
|
GST_OBJECT_UNLOCK (deinterlace);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (deinterlace->passthrough)
|
|
|
|
return gst_pad_push (deinterlace->srcpad, inbuf);
|
|
|
|
|
2011-04-29 16:35:55 +00:00
|
|
|
outbuf = gst_buffer_new_and_alloc (deinterlace->to_size);
|
2005-05-15 19:21:04 +00:00
|
|
|
|
2012-01-24 13:40:37 +00:00
|
|
|
gst_buffer_map (inbuf, &from_map, GST_MAP_READ);
|
|
|
|
gst_ffmpeg_avpicture_fill (&deinterlace->from_frame, from_map.data,
|
2011-04-29 16:35:55 +00:00
|
|
|
deinterlace->pixfmt, deinterlace->width, deinterlace->height);
|
2011-04-04 11:18:13 +00:00
|
|
|
|
2012-01-24 13:40:37 +00:00
|
|
|
gst_buffer_map (outbuf, &to_map, GST_MAP_WRITE);
|
|
|
|
gst_ffmpeg_avpicture_fill (&deinterlace->to_frame, to_map.data,
|
2011-04-29 16:35:55 +00:00
|
|
|
deinterlace->pixfmt, deinterlace->width, deinterlace->height);
|
2005-05-15 19:21:04 +00:00
|
|
|
|
2015-11-04 20:16:18 +00:00
|
|
|
process_filter_graph (deinterlace, &deinterlace->to_frame,
|
|
|
|
&deinterlace->from_frame, deinterlace->pixfmt, deinterlace->width,
|
|
|
|
deinterlace->height);
|
2012-01-24 13:40:37 +00:00
|
|
|
gst_buffer_unmap (outbuf, &to_map);
|
|
|
|
gst_buffer_unmap (inbuf, &from_map);
|
2005-05-15 19:21:04 +00:00
|
|
|
|
2011-04-29 16:35:55 +00:00
|
|
|
gst_buffer_copy_into (outbuf, inbuf, GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
|
2005-05-15 19:21:04 +00:00
|
|
|
|
2011-04-29 16:35:55 +00:00
|
|
|
result = gst_pad_push (deinterlace->srcpad, outbuf);
|
2005-05-15 19:21:04 +00:00
|
|
|
|
2006-01-20 14:17:16 +00:00
|
|
|
gst_buffer_unref (inbuf);
|
2005-05-15 19:21:04 +00:00
|
|
|
|
2006-01-20 14:17:16 +00:00
|
|
|
return result;
|
2005-05-15 19:21:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_ffmpegdeinterlace_register (GstPlugin * plugin)
|
|
|
|
{
|
2012-04-12 17:41:52 +00:00
|
|
|
return gst_element_register (plugin, "avdeinterlace",
|
2005-05-15 19:21:04 +00:00
|
|
|
GST_RANK_NONE, GST_TYPE_FFMPEGDEINTERLACE);
|
|
|
|
}
|
2011-08-12 08:06:03 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_ffmpegdeinterlace_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstFFMpegDeinterlace *self;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_FFMPEGDEINTERLACE (object));
|
|
|
|
self = GST_FFMPEGDEINTERLACE (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_MODE:{
|
|
|
|
gint new_mode;
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (self);
|
|
|
|
new_mode = g_value_get_enum (value);
|
2011-09-28 11:29:08 +00:00
|
|
|
if (self->mode != new_mode && gst_pad_has_current_caps (self->srcpad)) {
|
2011-08-12 08:06:03 +00:00
|
|
|
self->reconfigure = TRUE;
|
|
|
|
self->new_mode = new_mode;
|
|
|
|
} else {
|
|
|
|
self->mode = new_mode;
|
|
|
|
gst_ffmpegdeinterlace_update_passthrough (self);
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (self);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, prop_id, pspec);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_ffmpegdeinterlace_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstFFMpegDeinterlace *self;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_FFMPEGDEINTERLACE (object));
|
|
|
|
self = GST_FFMPEGDEINTERLACE (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_MODE:
|
|
|
|
g_value_set_enum (value, self->mode);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|