• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  *
3  * unit test for the audiosink base class
4  *
5  * Copyright (C) 2020 Seungha Yang <seungha.yang@navercorp.com>
6  *
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.
11  *
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.
16  *
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., 51 Franklin St, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26 
27 #include <gst/check/gstcheck.h>
28 #include <gst/audio/gstaudiosink.h>
29 
30 #define GST_TYPE_AUDIO_FOO_SINK           (gst_audio_foo_sink_get_type())
31 #define GST_AUDIO_FOO_SINK(obj)           (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AUDIO_FOO_SINK,GstAudioFooSink))
32 #define GST_AUDIO_FOO_SINK_CLASS(klass)   (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AUDIO_FOO_SINK,GstAudioFooSinkClass))
33 typedef struct _GstAudioFooSink GstAudioFooSink;
34 typedef struct _GstAudioFooSinkClass GstAudioFooSinkClass;
35 
36 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
37     GST_PAD_SINK,
38     GST_PAD_ALWAYS,
39     GST_STATIC_CAPS (GST_AUDIO_CAPS_MAKE (GST_AUDIO_FORMATS_ALL)));
40 
41 struct _GstAudioFooSink
42 {
43   GstAudioSink parent;
44 
45   guint num_clear_all_call;
46 };
47 
48 struct _GstAudioFooSinkClass
49 {
50   GstAudioSinkClass parent_class;
51 };
52 
53 GType gst_audio_foo_sink_get_type (void);
54 G_DEFINE_TYPE (GstAudioFooSink, gst_audio_foo_sink, GST_TYPE_AUDIO_SINK);
55 
56 static void
gst_audio_foo_sink_clear_all(GstAudioSink * sink)57 gst_audio_foo_sink_clear_all (GstAudioSink * sink)
58 {
59   GstAudioFooSink *self = GST_AUDIO_FOO_SINK (sink);
60 
61   self->num_clear_all_call++;
62 }
63 
64 static void
gst_audio_foo_sink_init(GstAudioFooSink * src)65 gst_audio_foo_sink_init (GstAudioFooSink * src)
66 {
67 }
68 
69 static void
gst_audio_foo_sink_class_init(GstAudioFooSinkClass * klass)70 gst_audio_foo_sink_class_init (GstAudioFooSinkClass * klass)
71 {
72   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
73   GstAudioSinkClass *audiosink_class = GST_AUDIO_SINK_CLASS (klass);
74 
75   gst_element_class_add_static_pad_template (element_class, &sink_template);
76   gst_element_class_set_metadata (element_class,
77       "AudioFooSink", "Sink/Audio",
78       "Audio Sink Unit Test element", "Foo Bar <foo@bar.com>");
79 
80   audiosink_class->extension->clear_all = gst_audio_foo_sink_clear_all;
81 }
82 
GST_START_TEST(test_class_extension)83 GST_START_TEST (test_class_extension)
84 {
85   GstAudioFooSink *foosink = NULL;
86   GstAudioBaseSink *bsink;
87   GstAudioRingBuffer *ringbuffer;
88 
89   foosink = g_object_new (GST_TYPE_AUDIO_FOO_SINK, NULL);
90   fail_unless (foosink != NULL);
91 
92   /* change state to READY to prepare audio ringbuffer */
93   fail_unless (gst_element_set_state (GST_ELEMENT (foosink),
94           GST_STATE_READY) == GST_STATE_CHANGE_SUCCESS);
95 
96   bsink = GST_AUDIO_BASE_SINK (foosink);
97   ringbuffer = bsink->ringbuffer;
98   fail_unless (ringbuffer != NULL);
99 
100   /* This will invoke GstAudioSink::clear_all method */
101   gst_audio_ring_buffer_clear_all (ringbuffer);
102   fail_unless_equals_int (foosink->num_clear_all_call, 1);
103 
104   gst_element_set_state (GST_ELEMENT (foosink), GST_STATE_NULL);
105   gst_clear_object (&foosink);
106 }
107 
108 GST_END_TEST;
109 
110 
111 static Suite *
audiosink_suite(void)112 audiosink_suite (void)
113 {
114   Suite *s = suite_create ("audiosink");
115   TCase *tc_chain = tcase_create ("general");
116 
117   suite_add_tcase (s, tc_chain);
118   tcase_add_test (tc_chain, test_class_extension);
119 
120   return s;
121 }
122 
123 GST_CHECK_MAIN (audiosink)
124