2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2005 Wim Taymans <wim@fluendo.com>
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.
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.
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., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 /* a base class for audio sinks.
25 * It uses a ringbuffer to schedule playback of samples. This makes
26 * it very easy to drop or insert samples to align incoming
27 * buffers to the exact playback timestamp.
29 * Subclasses must provide a ringbuffer pointing to either DMA
30 * memory or regular memory. A subclass should also call a callback
31 * function when it has played N segments in the buffer. The subclass
32 * is free to use a thread to signal this callback, use EIO or any
35 * The base class is able to operate in push or pull mode. The chain
36 * mode will queue the samples in the ringbuffer as much as possible.
37 * The available space is calculated in the callback function.
39 * The pull mode will pull_range() a new buffer of N samples with a
40 * configurable latency. This allows for high-end real time
41 * audio processing pipelines driven by the audiosink. The callback
42 * function will be used to perform a pull_range() on the sinkpad.
43 * The thread scheduling the callback can be a real-time thread.
45 * Subclasses must implement a GstRingBuffer in addition to overriding
46 * the methods in GstBaseSink and this class.
49 #ifndef __GST_BASE_AUDIO_SINK_H__
50 #define __GST_BASE_AUDIO_SINK_H__
53 #include <gst/base/gstbasesink.h>
54 #include "gstringbuffer.h"
55 #include "gstaudioclock.h"
59 #define GST_TYPE_BASE_AUDIO_SINK (gst_base_audio_sink_get_type())
60 #define GST_BASE_AUDIO_SINK(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_BASE_AUDIO_SINK,GstBaseAudioSink))
61 #define GST_BASE_AUDIO_SINK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_BASE_AUDIO_SINK,GstBaseAudioSinkClass))
62 #define GST_BASE_AUDIO_SINK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_BASE_AUDIO_SINK, GstBaseAudioSinkClass))
63 #define GST_IS_BASE_AUDIO_SINK(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_BASE_AUDIO_SINK))
64 #define GST_IS_BASE_AUDIO_SINK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_BASE_AUDIO_SINK))
67 * GST_BASE_AUDIO_SINK_CLOCK:
68 * @obj: a #GstBaseAudioSink
70 * Get the #GstClock of @obj.
72 #define GST_BASE_AUDIO_SINK_CLOCK(obj) (GST_BASE_AUDIO_SINK (obj)->clock)
74 * GST_BASE_AUDIO_SINK_PAD:
75 * @obj: a #GstBaseAudioSink
77 * Get the sink #GstPad of @obj.
79 #define GST_BASE_AUDIO_SINK_PAD(obj) (GST_BASE_SINK (obj)->sinkpad)
82 * GstBaseAudioSinkSlaveMethod:
83 * @GST_BASE_AUDIO_SINK_SLAVE_RESAMPLE: Resample to match the master clock
84 * @GST_BASE_AUDIO_SINK_SLAVE_SKEW: Adjust playout pointer when master clock
86 * @GST_BASE_AUDIO_SINK_SLAVE_NONE: No adjustment is done.
88 * Different possible clock slaving algorithms used when the internal audio
89 * clock is not selected as the pipeline master clock.
93 GST_BASE_AUDIO_SINK_SLAVE_RESAMPLE,
94 GST_BASE_AUDIO_SINK_SLAVE_SKEW,
95 GST_BASE_AUDIO_SINK_SLAVE_NONE
96 } GstBaseAudioSinkSlaveMethod;
98 #define GST_TYPE_BASE_AUDIO_SINK_SLAVE_METHOD (gst_base_audio_sink_slave_method_get_type ())
100 typedef struct _GstBaseAudioSink GstBaseAudioSink;
101 typedef struct _GstBaseAudioSinkClass GstBaseAudioSinkClass;
102 typedef struct _GstBaseAudioSinkPrivate GstBaseAudioSinkPrivate;
107 * Opaque #GstBaseAudioSink.
109 struct _GstBaseAudioSink {
112 /*< protected >*/ /* with LOCK */
114 GstRingBuffer *ringbuffer;
116 /* required buffer and latency in microseconds */
118 guint64 latency_time;
120 /* the next sample to write */
124 gboolean provide_clock;
125 GstClock *provided_clock;
128 GstBaseAudioSinkPrivate *priv;
133 /* with g_atomic_; currently rendering eos */
134 gboolean eos_rendering;
136 gpointer _gst_reserved[GST_PADDING - 1];
141 * GstBaseAudioSinkClass:
142 * @parent_class: the parent class.
143 * @create_ringbuffer: create and return a #GstRingBuffer to write to.
144 * @payload: payload data in a format suitable to write to the sink. If no
145 * payloading is required, returns a reffed copy of the original
146 * buffer, else returns the payloaded buffer with all other metadata
147 * copied. (Since: 0.10.36)
149 * #GstBaseAudioSink class. Override the vmethod to implement
152 struct _GstBaseAudioSinkClass {
153 GstBaseSinkClass parent_class;
155 /* subclass ringbuffer allocation */
156 GstRingBuffer* (*create_ringbuffer) (GstBaseAudioSink *sink);
158 /* subclass payloader */
159 GstBuffer* (*payload) (GstBaseAudioSink *sink,
163 gpointer _gst_reserved[GST_PADDING - 1];
166 GType gst_base_audio_sink_get_type(void);
167 GType gst_base_audio_sink_slave_method_get_type (void);
169 GstRingBuffer *gst_base_audio_sink_create_ringbuffer (GstBaseAudioSink *sink);
171 void gst_base_audio_sink_set_provide_clock (GstBaseAudioSink *sink, gboolean provide);
172 gboolean gst_base_audio_sink_get_provide_clock (GstBaseAudioSink *sink);
174 void gst_base_audio_sink_set_slave_method (GstBaseAudioSink *sink,
175 GstBaseAudioSinkSlaveMethod method);
176 GstBaseAudioSinkSlaveMethod
177 gst_base_audio_sink_get_slave_method (GstBaseAudioSink *sink);
179 void gst_base_audio_sink_set_drift_tolerance (GstBaseAudioSink *sink,
180 gint64 drift_tolerance);
181 gint64 gst_base_audio_sink_get_drift_tolerance (GstBaseAudioSink *sink);
183 void gst_base_audio_sink_set_alignment_threshold (GstBaseAudioSink * sink,
184 GstClockTime alignment_threshold);
186 gst_base_audio_sink_get_alignment_threshold (GstBaseAudioSink * sink);
188 void gst_base_audio_sink_set_discont_wait (GstBaseAudioSink * sink,
189 GstClockTime discont_wait);
191 gst_base_audio_sink_get_discont_wait (GstBaseAudioSink * sink);
195 #endif /* __GST_BASE_AUDIO_SINK_H__ */