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