expand tabs
[platform/upstream/gstreamer.git] / gst-libs / gst / audio / gstbaseaudiosink.h
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2005 Wim Taymans <wim@fluendo.com>
4  *
5  * gstbaseaudiosink.h:
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., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 /* a base class for audio sinks.
24  *
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.
28  *
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
33  * other mechanism.
34  *
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.
38  *
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.
44  *
45  * Subclasses must implement a GstRingBuffer in addition to overriding
46  * the methods in GstBaseSink and this class.
47  */
48
49 #ifndef __GST_BASE_AUDIO_SINK_H__
50 #define __GST_BASE_AUDIO_SINK_H__
51
52 #include <gst/gst.h>
53 #include <gst/base/gstbasesink.h>
54 #include "gstringbuffer.h"
55 #include "gstaudioclock.h"
56
57 G_BEGIN_DECLS
58
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))
65
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)
68
69 typedef struct _GstBaseAudioSink GstBaseAudioSink;
70 typedef struct _GstBaseAudioSinkClass GstBaseAudioSinkClass;
71
72 struct _GstBaseAudioSink {
73   GstBaseSink    element;
74
75   /*< protected >*/ /* with LOCK */
76   /* our ringbuffer */
77   GstRingBuffer *ringbuffer;
78
79   /* required buffer and latency */
80   GstClockTime   buffer_time;
81   GstClockTime   latency_time;
82
83   /* the next sample to write */
84   guint64        next_sample;
85
86   /* clock */
87   gboolean       provide_clock;
88   GstClock      *provided_clock;
89
90   /*< private >*/
91   gpointer _gst_reserved[GST_PADDING];
92 };
93
94 struct _GstBaseAudioSinkClass {
95   GstBaseSinkClass parent_class;
96
97   /* subclass ringbuffer allocation */
98   GstRingBuffer* (*create_ringbuffer)  (GstBaseAudioSink *sink);
99
100   /*< private >*/
101   gpointer _gst_reserved[GST_PADDING];
102 };
103
104 GType gst_base_audio_sink_get_type(void);
105
106 GstRingBuffer *gst_base_audio_sink_create_ringbuffer (GstBaseAudioSink *sink);
107
108 G_END_DECLS
109
110 #endif /* __GST_BASE_AUDIO_SINK_H__ */