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
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2006-01-20 14:17:16 +00:00
|
|
|
# include "config.h"
|
2005-05-15 19:21:04 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_FFMPEG_UNINSTALLED
|
2006-01-20 14:17:16 +00:00
|
|
|
# include <avcodec.h>
|
2005-05-15 19:21:04 +00:00
|
|
|
#else
|
2008-10-30 12:05:45 +00:00
|
|
|
# include <libavcodec/avcodec.h>
|
2005-05-15 19:21:04 +00:00
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
2005-05-15 19:21:04 +00:00
|
|
|
#include "gstffmpeg.h"
|
|
|
|
#include "gstffmpegcodecmap.h"
|
2009-04-15 20:33:16 +00:00
|
|
|
#include "gstffmpegutils.h"
|
2005-05-15 19:21:04 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
enum PixelFormat pixfmt;
|
|
|
|
AVPicture from_frame, to_frame;
|
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);
|
|
|
|
|
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,
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("I420"))
|
|
|
|
);
|
|
|
|
|
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,
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("I420"))
|
|
|
|
);
|
|
|
|
|
2006-01-20 14:17:16 +00:00
|
|
|
GST_BOILERPLATE (GstFFMpegDeinterlace, gst_ffmpegdeinterlace, GstElement,
|
|
|
|
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,
|
|
|
|
GstBuffer * inbuf);
|
2005-05-15 19:21:04 +00:00
|
|
|
|
2006-01-20 14:17:16 +00:00
|
|
|
static void
|
|
|
|
gst_ffmpegdeinterlace_base_init (gpointer g_class)
|
2005-05-15 19:21:04 +00:00
|
|
|
{
|
2006-01-20 14:17:16 +00:00
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
2005-05-15 19:21:04 +00:00
|
|
|
|
2006-01-20 14:17:16 +00:00
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&src_factory));
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&sink_factory));
|
2010-03-24 10:51:26 +00:00
|
|
|
gst_element_class_set_details_simple (element_class,
|
2010-12-16 09:05:03 +00:00
|
|
|
"FFMPEG Deinterlace element", "Filter/Effect/Video/Deinterlace",
|
2010-03-24 10:51:26 +00:00
|
|
|
"Deinterlace video", "Luca Ognibene <luogni@tin.it>");
|
2006-01-20 14:17:16 +00:00
|
|
|
}
|
2005-05-15 19:21:04 +00:00
|
|
|
|
2006-01-20 14:17:16 +00:00
|
|
|
static void
|
|
|
|
gst_ffmpegdeinterlace_class_init (GstFFMpegDeinterlaceClass * klass)
|
|
|
|
{
|
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);
|
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
|
|
|
|
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
|
|
|
|
|
|
|
ctx = avcodec_alloc_context ();
|
2006-01-20 14:17:16 +00:00
|
|
|
ctx->width = deinterlace->width;
|
|
|
|
ctx->height = deinterlace->height;
|
2005-05-15 19:21:04 +00:00
|
|
|
ctx->pix_fmt = PIX_FMT_NB;
|
|
|
|
gst_ffmpeg_caps_with_codectype (CODEC_TYPE_VIDEO, caps, ctx);
|
|
|
|
if (ctx->pix_fmt == PIX_FMT_NB) {
|
|
|
|
av_free (ctx);
|
2006-01-20 14:17:16 +00:00
|
|
|
return FALSE;
|
2005-05-15 19:21:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
deinterlace->pixfmt = ctx->pix_fmt;
|
|
|
|
|
2006-01-20 14:17:16 +00:00
|
|
|
av_free (ctx);
|
2005-05-15 19:21:04 +00:00
|
|
|
|
2006-01-20 14:17:16 +00:00
|
|
|
deinterlace->to_size =
|
|
|
|
avpicture_get_size (deinterlace->pixfmt, deinterlace->width,
|
|
|
|
deinterlace->height);
|
2005-05-15 19:21:04 +00:00
|
|
|
|
2010-07-18 19:15:32 +00:00
|
|
|
src_caps = gst_caps_copy (caps);
|
|
|
|
gst_caps_set_simple (src_caps, "interlaced", G_TYPE_BOOLEAN, FALSE, NULL);
|
|
|
|
ret = gst_pad_set_caps (deinterlace->srcpad, src_caps);
|
|
|
|
gst_caps_unref (src_caps);
|
2010-06-25 14:26:00 +00:00
|
|
|
|
|
|
|
return ret;
|
2005-05-15 19:21:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-01-20 14:17:16 +00:00
|
|
|
gst_ffmpegdeinterlace_init (GstFFMpegDeinterlace * deinterlace,
|
|
|
|
GstFFMpegDeinterlaceClass * klass)
|
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");
|
|
|
|
gst_pad_set_setcaps_function (deinterlace->sinkpad,
|
|
|
|
gst_ffmpegdeinterlace_sink_setcaps);
|
|
|
|
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);
|
|
|
|
|
|
|
|
deinterlace->pixfmt = PIX_FMT_NB;
|
|
|
|
}
|
|
|
|
|
2006-01-20 14:17:16 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_ffmpegdeinterlace_chain (GstPad * pad, GstBuffer * inbuf)
|
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));
|
2005-05-15 19:21:04 +00:00
|
|
|
GstBuffer *outbuf = NULL;
|
2006-01-20 14:17:16 +00:00
|
|
|
GstFlowReturn result;
|
2005-05-15 19:21:04 +00:00
|
|
|
|
2006-01-20 14:17:16 +00:00
|
|
|
result =
|
|
|
|
gst_pad_alloc_buffer (deinterlace->srcpad, GST_BUFFER_OFFSET_NONE,
|
|
|
|
deinterlace->to_size, GST_PAD_CAPS (deinterlace->srcpad), &outbuf);
|
|
|
|
if (result == GST_FLOW_OK) {
|
|
|
|
gst_ffmpeg_avpicture_fill (&deinterlace->from_frame,
|
|
|
|
GST_BUFFER_DATA (inbuf), deinterlace->pixfmt, deinterlace->width,
|
|
|
|
deinterlace->height);
|
2005-05-15 19:21:04 +00:00
|
|
|
|
2006-01-20 14:17:16 +00:00
|
|
|
gst_ffmpeg_avpicture_fill (&deinterlace->to_frame, GST_BUFFER_DATA (outbuf),
|
|
|
|
deinterlace->pixfmt, deinterlace->width, deinterlace->height);
|
2005-05-15 19:21:04 +00:00
|
|
|
|
2006-01-20 14:17:16 +00:00
|
|
|
avpicture_deinterlace (&deinterlace->to_frame, &deinterlace->from_frame,
|
|
|
|
deinterlace->pixfmt, deinterlace->width, deinterlace->height);
|
2005-05-15 19:21:04 +00:00
|
|
|
|
2007-07-12 11:13:13 +00:00
|
|
|
gst_buffer_copy_metadata (outbuf, inbuf, GST_BUFFER_COPY_TIMESTAMPS);
|
2005-05-15 19:21:04 +00:00
|
|
|
|
2006-01-20 14:17:16 +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)
|
|
|
|
{
|
|
|
|
return gst_element_register (plugin, "ffdeinterlace",
|
|
|
|
GST_RANK_NONE, GST_TYPE_FFMPEGDEINTERLACE);
|
|
|
|
}
|