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(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_BASE_AUDIO_SINK))
66 #define GST_BASE_AUDIO_SINK_CLOCK(obj) (GST_BASE_AUDIO_SINK (obj)->clock)
67 #define GST_BASE_AUDIO_SINK_PAD(obj) (GST_BASE_SINK (obj)->sinkpad)
69 typedef struct _GstBaseAudioSink GstBaseAudioSink;
70 typedef struct _GstBaseAudioSinkClass GstBaseAudioSinkClass;
72 struct _GstBaseAudioSink {
75 /*< protected >*/ /* with LOCK */
77 GstRingBuffer *ringbuffer;
79 /* required buffer and latency */
80 GstClockTime buffer_time;
81 GstClockTime latency_time;
83 /* the next sample to write */
87 gboolean provide_clock;
88 GstClock *provided_clock;
91 gpointer _gst_reserved[GST_PADDING];
94 struct _GstBaseAudioSinkClass {
95 GstBaseSinkClass parent_class;
97 /* subclass ringbuffer allocation */
98 GstRingBuffer* (*create_ringbuffer) (GstBaseAudioSink *sink);
101 gpointer _gst_reserved[GST_PADDING];
104 GType gst_base_audio_sink_get_type(void);
106 GstRingBuffer *gst_base_audio_sink_create_ringbuffer (GstBaseAudioSink *sink);
110 #endif /* __GST_BASE_AUDIO_SINK_H__ */