2
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4
* Copyright (C) 2005 Luca Ognibene <luogni@tin.it>
5
* Copyright (C) 2006 Martin Zlomek <martin.zlomek@itonis.tv>
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Library General Public
9
* License as published by the Free Software Foundation; either
10
* version 2 of the License, or (at your option) any later version.
12
* This library is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Library General Public License for more details.
17
* You should have received a copy of the GNU Library General Public
18
* License along with this library; if not, write to the
19
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
* Boston, MA 02111-1307, USA.
27
#ifdef HAVE_FFMPEG_UNINSTALLED
30
# include <ffmpeg/avcodec.h>
34
#include <gst/video/video.h>
36
#include "gstffmpeg.h"
37
#include "gstffmpegcodecmap.h"
39
typedef struct _GstFFMpegDeinterlace
43
GstPad *sinkpad, *srcpad;
48
enum PixelFormat pixfmt;
49
AVPicture from_frame, to_frame;
50
} GstFFMpegDeinterlace;
52
typedef struct _GstFFMpegDeinterlaceClass
54
GstElementClass parent_class;
55
} GstFFMpegDeinterlaceClass;
57
#define GST_TYPE_FFMPEGDEINTERLACE \
58
(gst_ffmpegdeinterlace_get_type())
59
#define GST_FFMPEGDEINTERLACE(obj) \
60
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_FFMPEGDEINTERLACE,GstFFMpegDeinterlace))
61
#define GST_FFMPEGDEINTERLACE_CLASS(klass) \
62
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_FFMPEGDEINTERLACE,GstFFMpegDeinterlace))
63
#define GST_IS_FFMPEGDEINTERLACE(obj) \
64
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_FFMPEGDEINTERLACE))
65
#define GST_IS_FFMPEGDEINTERLACE_CLASS(obj) \
66
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_FFMPEGDEINTERLACE))
68
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
71
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("I420"))
74
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
77
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("I420"))
80
GST_BOILERPLATE (GstFFMpegDeinterlace, gst_ffmpegdeinterlace, GstElement,
83
static GstFlowReturn gst_ffmpegdeinterlace_chain (GstPad * pad,
87
gst_ffmpegdeinterlace_base_init (gpointer g_class)
89
static GstElementDetails plugin_details = {
90
"FFMPEG Deinterlace element",
91
"Filter/Converter/Video",
93
"Luca Ognibene <luogni@tin.it>",
95
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
97
gst_element_class_add_pad_template (element_class,
98
gst_static_pad_template_get (&src_factory));
99
gst_element_class_add_pad_template (element_class,
100
gst_static_pad_template_get (&sink_factory));
101
gst_element_class_set_details (element_class, &plugin_details);
105
gst_ffmpegdeinterlace_class_init (GstFFMpegDeinterlaceClass * klass)
110
gst_ffmpegdeinterlace_sink_setcaps (GstPad * pad, GstCaps * caps)
112
GstFFMpegDeinterlace *deinterlace =
113
GST_FFMPEGDEINTERLACE (gst_pad_get_parent (pad));
114
GstStructure *structure = gst_caps_get_structure (caps, 0);
117
if (!gst_structure_get_int (structure, "width", &deinterlace->width))
119
if (!gst_structure_get_int (structure, "height", &deinterlace->height))
122
ctx = avcodec_alloc_context ();
123
ctx->width = deinterlace->width;
124
ctx->height = deinterlace->height;
125
ctx->pix_fmt = PIX_FMT_NB;
126
gst_ffmpeg_caps_with_codectype (CODEC_TYPE_VIDEO, caps, ctx);
127
if (ctx->pix_fmt == PIX_FMT_NB) {
132
deinterlace->pixfmt = ctx->pix_fmt;
136
deinterlace->to_size =
137
avpicture_get_size (deinterlace->pixfmt, deinterlace->width,
138
deinterlace->height);
140
return gst_pad_set_caps (deinterlace->srcpad, caps);
144
gst_ffmpegdeinterlace_init (GstFFMpegDeinterlace * deinterlace,
145
GstFFMpegDeinterlaceClass * klass)
147
deinterlace->sinkpad =
148
gst_pad_new_from_static_template (&sink_factory, "sink");
149
gst_pad_set_setcaps_function (deinterlace->sinkpad,
150
gst_ffmpegdeinterlace_sink_setcaps);
151
gst_pad_set_chain_function (deinterlace->sinkpad,
152
gst_ffmpegdeinterlace_chain);
153
gst_element_add_pad (GST_ELEMENT (deinterlace), deinterlace->sinkpad);
155
deinterlace->srcpad = gst_pad_new_from_static_template (&src_factory, "src");
156
gst_element_add_pad (GST_ELEMENT (deinterlace), deinterlace->srcpad);
158
deinterlace->pixfmt = PIX_FMT_NB;
162
gst_ffmpegdeinterlace_chain (GstPad * pad, GstBuffer * inbuf)
164
GstFFMpegDeinterlace *deinterlace =
165
GST_FFMPEGDEINTERLACE (gst_pad_get_parent (pad));
166
GstBuffer *outbuf = NULL;
167
GstFlowReturn result;
170
gst_pad_alloc_buffer (deinterlace->srcpad, GST_BUFFER_OFFSET_NONE,
171
deinterlace->to_size, GST_PAD_CAPS (deinterlace->srcpad), &outbuf);
172
if (result == GST_FLOW_OK) {
173
gst_ffmpeg_avpicture_fill (&deinterlace->from_frame,
174
GST_BUFFER_DATA (inbuf), deinterlace->pixfmt, deinterlace->width,
175
deinterlace->height);
177
gst_ffmpeg_avpicture_fill (&deinterlace->to_frame, GST_BUFFER_DATA (outbuf),
178
deinterlace->pixfmt, deinterlace->width, deinterlace->height);
180
avpicture_deinterlace (&deinterlace->to_frame, &deinterlace->from_frame,
181
deinterlace->pixfmt, deinterlace->width, deinterlace->height);
183
gst_buffer_stamp (outbuf, inbuf);
185
result = gst_pad_push (deinterlace->srcpad, outbuf);
188
gst_buffer_unref (inbuf);
194
gst_ffmpegdeinterlace_register (GstPlugin * plugin)
196
return gst_element_register (plugin, "ffdeinterlace",
197
GST_RANK_NONE, GST_TYPE_FFMPEGDEINTERLACE);