• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "unalignedvideo.h"
28 
29 GST_DEBUG_CATEGORY (unaligned_video_parse_debug);
30 #define GST_CAT_DEFAULT unaligned_video_parse_debug
31 
32 struct _GstUnalignedVideoParse
33 {
34   GstBin parent;
35   GstElement *inner_parser;
36 };
37 
38 struct _GstUnalignedVideoParseClass
39 {
40   GstBinClass parent_class;
41 };
42 
43 static GstStaticPadTemplate static_sink_template =
44 GST_STATIC_PAD_TEMPLATE ("sink",
45     GST_PAD_SINK,
46     GST_PAD_ALWAYS,
47     GST_STATIC_CAPS (GST_UNALIGNED_RAW_VIDEO_CAPS)
48     );
49 
50 static GstStaticPadTemplate static_src_template =
51 GST_STATIC_PAD_TEMPLATE ("src",
52     GST_PAD_SRC,
53     GST_PAD_ALWAYS,
54     GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (GST_VIDEO_FORMATS_ALL))
55     );
56 
57 G_DEFINE_TYPE (GstUnalignedVideoParse, gst_unaligned_video_parse, GST_TYPE_BIN);
58 
59 static void
gst_unaligned_video_parse_class_init(GstUnalignedVideoParseClass * klass)60 gst_unaligned_video_parse_class_init (GstUnalignedVideoParseClass * klass)
61 {
62   GstElementClass *element_class;
63 
64   GST_DEBUG_CATEGORY_INIT (unaligned_video_parse_debug, "unalignedvideoparse",
65       0, "Unaligned raw video parser");
66 
67   element_class = GST_ELEMENT_CLASS (klass);
68 
69   gst_element_class_add_pad_template (element_class,
70       gst_static_pad_template_get (&static_sink_template));
71   gst_element_class_add_pad_template (element_class,
72       gst_static_pad_template_get (&static_src_template));
73 
74   gst_element_class_set_static_metadata (element_class,
75       "unalignedvideoparse",
76       "Codec/Parser/Bin/Video",
77       "Parse unaligned raw video data",
78       "Carlos Rafael Giani <dv@pseudoterminal.org>");
79 }
80 
81 static void
gst_unaligned_video_parse_init(GstUnalignedVideoParse * unaligned_video_parse)82 gst_unaligned_video_parse_init (GstUnalignedVideoParse * unaligned_video_parse)
83 {
84   GstPad *inner_pad;
85   GstPad *ghostpad;
86 
87   unaligned_video_parse->inner_parser =
88       gst_element_factory_make ("rawvideoparse", "inner_parser");
89   g_assert (unaligned_video_parse->inner_parser != NULL);
90 
91   g_object_set (G_OBJECT (unaligned_video_parse->inner_parser),
92       "use-sink-caps", TRUE, NULL);
93 
94   gst_bin_add (GST_BIN (unaligned_video_parse),
95       unaligned_video_parse->inner_parser);
96 
97   inner_pad =
98       gst_element_get_static_pad (unaligned_video_parse->inner_parser, "sink");
99   ghostpad =
100       gst_ghost_pad_new_from_template ("sink", inner_pad,
101       gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS
102           (unaligned_video_parse), "sink"));
103   gst_element_add_pad (GST_ELEMENT (unaligned_video_parse), ghostpad);
104   gst_object_unref (GST_OBJECT (inner_pad));
105 
106   inner_pad = gst_element_get_static_pad (unaligned_video_parse->inner_parser,
107       "src");
108   ghostpad =
109       gst_ghost_pad_new_from_template ("src", inner_pad,
110       gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS
111           (unaligned_video_parse), "src"));
112   gst_element_add_pad (GST_ELEMENT (unaligned_video_parse), ghostpad);
113   gst_object_unref (GST_OBJECT (inner_pad));
114 }
115