1 /* GStreamer
2 * Copyright (C) 2016 Carlos Rafael Giani <dv@pseudoterminal.org>
3 *
4 * gstunalignedvideoparse.c:
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22 #include <string.h>
23 #include <stdio.h>
24 #include <gst/gst.h>
25 #include <gst/video/video.h>
26 #include "gstunalignedvideoparse.h"
27 #include "gstrawparseelements.h"
28 #include "unalignedvideo.h"
29
30 GST_DEBUG_CATEGORY (unaligned_video_parse_debug);
31 #define GST_CAT_DEFAULT unaligned_video_parse_debug
32
33 struct _GstUnalignedVideoParse
34 {
35 GstBin parent;
36 GstElement *inner_parser;
37 };
38
39 static GstStaticPadTemplate static_sink_template =
40 GST_STATIC_PAD_TEMPLATE ("sink",
41 GST_PAD_SINK,
42 GST_PAD_ALWAYS,
43 GST_STATIC_CAPS (GST_UNALIGNED_RAW_VIDEO_CAPS)
44 );
45
46 static GstStaticPadTemplate static_src_template =
47 GST_STATIC_PAD_TEMPLATE ("src",
48 GST_PAD_SRC,
49 GST_PAD_ALWAYS,
50 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (GST_VIDEO_FORMATS_ALL))
51 );
52
53 G_DEFINE_TYPE (GstUnalignedVideoParse, gst_unaligned_video_parse, GST_TYPE_BIN);
54 GST_ELEMENT_REGISTER_DEFINE (unalignedvideoparse,
55 "unalignedvideoparse", GST_RANK_MARGINAL, GST_TYPE_UNALIGNED_VIDEO_PARSE);
56
57 static void
gst_unaligned_video_parse_class_init(GstUnalignedVideoParseClass * klass)58 gst_unaligned_video_parse_class_init (GstUnalignedVideoParseClass * klass)
59 {
60 GstElementClass *element_class;
61
62 GST_DEBUG_CATEGORY_INIT (unaligned_video_parse_debug, "unalignedvideoparse",
63 0, "Unaligned raw video parser");
64
65 element_class = GST_ELEMENT_CLASS (klass);
66
67 gst_element_class_add_pad_template (element_class,
68 gst_static_pad_template_get (&static_sink_template));
69 gst_element_class_add_pad_template (element_class,
70 gst_static_pad_template_get (&static_src_template));
71
72 gst_element_class_set_static_metadata (element_class,
73 "unalignedvideoparse",
74 "Codec/Parser/Bin/Video",
75 "Parse unaligned raw video data",
76 "Carlos Rafael Giani <dv@pseudoterminal.org>");
77 }
78
79 static void
gst_unaligned_video_parse_init(GstUnalignedVideoParse * unaligned_video_parse)80 gst_unaligned_video_parse_init (GstUnalignedVideoParse * unaligned_video_parse)
81 {
82 GstPad *inner_pad;
83 GstPad *ghostpad;
84
85 unaligned_video_parse->inner_parser =
86 gst_element_factory_make ("rawvideoparse", "inner_parser");
87 g_assert (unaligned_video_parse->inner_parser != NULL);
88
89 g_object_set (G_OBJECT (unaligned_video_parse->inner_parser),
90 "use-sink-caps", TRUE, NULL);
91
92 gst_bin_add (GST_BIN (unaligned_video_parse),
93 unaligned_video_parse->inner_parser);
94
95 inner_pad =
96 gst_element_get_static_pad (unaligned_video_parse->inner_parser, "sink");
97 ghostpad =
98 gst_ghost_pad_new_from_template ("sink", inner_pad,
99 gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS
100 (unaligned_video_parse), "sink"));
101 gst_element_add_pad (GST_ELEMENT (unaligned_video_parse), ghostpad);
102 gst_object_unref (GST_OBJECT (inner_pad));
103
104 inner_pad = gst_element_get_static_pad (unaligned_video_parse->inner_parser,
105 "src");
106 ghostpad =
107 gst_ghost_pad_new_from_template ("src", inner_pad,
108 gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS
109 (unaligned_video_parse), "src"));
110 gst_element_add_pad (GST_ELEMENT (unaligned_video_parse), ghostpad);
111 gst_object_unref (GST_OBJECT (inner_pad));
112 }
113