1 /* GStreamer
2 * Copyright (C) 2016 Carlos Rafael Giani <dv@pseudoterminal.org>
3 *
4 * gstunalignedaudioparse.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/audio/audio.h>
26 #include "gstunalignedaudioparse.h"
27 #include "unalignedaudio.h"
28
29 GST_DEBUG_CATEGORY (unaligned_audio_parse_debug);
30 #define GST_CAT_DEFAULT unaligned_audio_parse_debug
31
32 struct _GstUnalignedAudioParse
33 {
34 GstBin parent;
35 GstElement *inner_parser;
36 };
37
38 struct _GstUnalignedAudioParseClass
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_AUDIO_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_AUDIO_CAPS_MAKE (GST_AUDIO_FORMATS_ALL)
55 ", layout = (string) { interleaved, non-interleaved }")
56 );
57
58 G_DEFINE_TYPE (GstUnalignedAudioParse, gst_unaligned_audio_parse, GST_TYPE_BIN);
59
60 static void
gst_unaligned_audio_parse_class_init(GstUnalignedAudioParseClass * klass)61 gst_unaligned_audio_parse_class_init (GstUnalignedAudioParseClass * klass)
62 {
63 GstElementClass *element_class;
64
65 GST_DEBUG_CATEGORY_INIT (unaligned_audio_parse_debug, "unalignedaudioparse",
66 0, "Unaligned raw audio parser");
67
68 element_class = GST_ELEMENT_CLASS (klass);
69
70 gst_element_class_add_pad_template (element_class,
71 gst_static_pad_template_get (&static_sink_template));
72 gst_element_class_add_pad_template (element_class,
73 gst_static_pad_template_get (&static_src_template));
74
75 gst_element_class_set_static_metadata (element_class,
76 "unalignedaudioparse",
77 "Codec/Parser/Bin/Audio",
78 "Parse unaligned raw audio data",
79 "Carlos Rafael Giani <dv@pseudoterminal.org>");
80 }
81
82 static void
gst_unaligned_audio_parse_init(GstUnalignedAudioParse * unaligned_audio_parse)83 gst_unaligned_audio_parse_init (GstUnalignedAudioParse * unaligned_audio_parse)
84 {
85 GstPad *inner_pad;
86 GstPad *ghostpad;
87
88 unaligned_audio_parse->inner_parser =
89 gst_element_factory_make ("rawaudioparse", "inner_parser");
90 g_assert (unaligned_audio_parse->inner_parser != NULL);
91
92 g_object_set (G_OBJECT (unaligned_audio_parse->inner_parser),
93 "use-sink-caps", TRUE, NULL);
94
95 gst_bin_add (GST_BIN (unaligned_audio_parse),
96 unaligned_audio_parse->inner_parser);
97
98 inner_pad =
99 gst_element_get_static_pad (unaligned_audio_parse->inner_parser, "sink");
100 ghostpad =
101 gst_ghost_pad_new_from_template ("sink", inner_pad,
102 gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS
103 (unaligned_audio_parse), "sink"));
104 gst_element_add_pad (GST_ELEMENT (unaligned_audio_parse), ghostpad);
105 gst_object_unref (GST_OBJECT (inner_pad));
106
107 inner_pad = gst_element_get_static_pad (unaligned_audio_parse->inner_parser,
108 "src");
109 ghostpad =
110 gst_ghost_pad_new_from_template ("src", inner_pad,
111 gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS
112 (unaligned_audio_parse), "src"));
113 gst_element_add_pad (GST_ELEMENT (unaligned_audio_parse), ghostpad);
114 gst_object_unref (GST_OBJECT (inner_pad));
115 }
116