| 1 | /* GStreamer |
| 2 | * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu> |
| 3 | * 2005 Wim Taymans <wim@fluendo.com> |
| 4 | * |
| 5 | * gstaudiobasesrc.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., 51 Franklin St, Fifth Floor, |
| 20 | * Boston, MA 02110-1301, USA. |
| 21 | */ |
| 22 | |
| 23 | /* a base class for audio sources. |
| 24 | */ |
| 25 | |
| 26 | #ifndef __GST_AUDIO_AUDIO_H__ |
| 27 | #include <gst/audio/audio.h> |
| 28 | #endif |
| 29 | |
| 30 | #ifndef __GST_AUDIO_BASE_SRC_H__ |
| 31 | #define __GST_AUDIO_BASE_SRC_H__ |
| 32 | |
| 33 | #include <gst/gst.h> |
| 34 | #include <gst/base/gstpushsrc.h> |
| 35 | |
| 36 | G_BEGIN_DECLS |
| 37 | |
| 38 | #define GST_TYPE_AUDIO_BASE_SRC (gst_audio_base_src_get_type()) |
| 39 | #define GST_AUDIO_BASE_SRC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AUDIO_BASE_SRC,GstAudioBaseSrc)) |
| 40 | #define GST_AUDIO_BASE_SRC_CAST(obj) ((GstAudioBaseSrc*)obj) |
| 41 | #define GST_AUDIO_BASE_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AUDIO_BASE_SRC,GstAudioBaseSrcClass)) |
| 42 | #define GST_AUDIO_BASE_SRC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_AUDIO_BASE_SRC, GstAudioBaseSrcClass)) |
| 43 | #define GST_IS_AUDIO_BASE_SRC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AUDIO_BASE_SRC)) |
| 44 | #define GST_IS_AUDIO_BASE_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AUDIO_BASE_SRC)) |
| 45 | |
| 46 | /** |
| 47 | * GST_AUDIO_BASE_SRC_CLOCK: |
| 48 | * @obj: a #GstAudioBaseSrc |
| 49 | * |
| 50 | * Get the #GstClock of @obj. |
| 51 | */ |
| 52 | #define GST_AUDIO_BASE_SRC_CLOCK(obj) (GST_AUDIO_BASE_SRC (obj)->clock) |
| 53 | /** |
| 54 | * GST_AUDIO_BASE_SRC_PAD: |
| 55 | * @obj: a #GstAudioBaseSrc |
| 56 | * |
| 57 | * Get the source #GstPad of @obj. |
| 58 | */ |
| 59 | #define GST_AUDIO_BASE_SRC_PAD(obj) (GST_BASE_SRC (obj)->srcpad) |
| 60 | |
| 61 | typedef struct _GstAudioBaseSrc GstAudioBaseSrc; |
| 62 | typedef struct _GstAudioBaseSrcClass GstAudioBaseSrcClass; |
| 63 | typedef struct _GstAudioBaseSrcPrivate GstAudioBaseSrcPrivate; |
| 64 | |
| 65 | /* FIXME 2.0: Should be "retimestamp" not "re-timestamp" */ |
| 66 | |
| 67 | /** |
| 68 | * GstAudioBaseSrcSlaveMethod: |
| 69 | * @GST_AUDIO_BASE_SRC_SLAVE_RESAMPLE: Resample to match the master clock. |
| 70 | * @GST_AUDIO_BASE_SRC_SLAVE_RE_TIMESTAMP: Retimestamp output buffers with master |
| 71 | * clock time. |
| 72 | * @GST_AUDIO_BASE_SRC_SLAVE_SKEW: Adjust capture pointer when master clock |
| 73 | * drifts too much. |
| 74 | * @GST_AUDIO_BASE_SRC_SLAVE_NONE: No adjustment is done. |
| 75 | * |
| 76 | * Different possible clock slaving algorithms when the internal audio clock was |
| 77 | * not selected as the pipeline clock. |
| 78 | */ |
| 79 | typedef enum |
| 80 | { |
| 81 | GST_AUDIO_BASE_SRC_SLAVE_RESAMPLE, |
| 82 | GST_AUDIO_BASE_SRC_SLAVE_RE_TIMESTAMP, |
| 83 | GST_AUDIO_BASE_SRC_SLAVE_SKEW, |
| 84 | GST_AUDIO_BASE_SRC_SLAVE_NONE |
| 85 | } GstAudioBaseSrcSlaveMethod; |
| 86 | |
| 87 | #define GST_AUDIO_BASE_SRC_SLAVE_RETIMESTAMP GST_AUDIO_BASE_SRC_SLAVE_RE_TIMESTAMP |
| 88 | |
| 89 | /** |
| 90 | * GstAudioBaseSrc: |
| 91 | * |
| 92 | * Opaque #GstAudioBaseSrc. |
| 93 | */ |
| 94 | struct _GstAudioBaseSrc { |
| 95 | GstPushSrc element; |
| 96 | |
| 97 | /*< protected >*/ /* with LOCK */ |
| 98 | /* our ringbuffer */ |
| 99 | GstAudioRingBuffer *ringbuffer; |
| 100 | |
| 101 | /* required buffer and latency */ |
| 102 | GstClockTime buffer_time; |
| 103 | GstClockTime latency_time; |
| 104 | |
| 105 | /* the next sample to write */ |
| 106 | guint64 next_sample; |
| 107 | |
| 108 | /* clock */ |
| 109 | GstClock *clock; |
| 110 | |
| 111 | /*< private >*/ |
| 112 | GstAudioBaseSrcPrivate *priv; |
| 113 | |
| 114 | gpointer _gst_reserved[GST_PADDING]; |
| 115 | }; |
| 116 | |
| 117 | /** |
| 118 | * GstAudioBaseSrcClass: |
| 119 | * @parent_class: the parent class. |
| 120 | * @create_ringbuffer: create and return a #GstAudioRingBuffer to read from. |
| 121 | * |
| 122 | * #GstAudioBaseSrc class. Override the vmethod to implement |
| 123 | * functionality. |
| 124 | */ |
| 125 | struct _GstAudioBaseSrcClass { |
| 126 | GstPushSrcClass parent_class; |
| 127 | |
| 128 | /* subclass ringbuffer allocation */ |
| 129 | GstAudioRingBuffer* (*create_ringbuffer) (GstAudioBaseSrc *src); |
| 130 | |
| 131 | /*< private >*/ |
| 132 | gpointer _gst_reserved[GST_PADDING]; |
| 133 | }; |
| 134 | |
| 135 | GST_AUDIO_API |
| 136 | GType gst_audio_base_src_get_type(void); |
| 137 | |
| 138 | GST_AUDIO_API |
| 139 | GstAudioRingBuffer * |
| 140 | gst_audio_base_src_create_ringbuffer (GstAudioBaseSrc *src); |
| 141 | |
| 142 | GST_AUDIO_API |
| 143 | void gst_audio_base_src_set_provide_clock (GstAudioBaseSrc *src, gboolean provide); |
| 144 | |
| 145 | GST_AUDIO_API |
| 146 | gboolean gst_audio_base_src_get_provide_clock (GstAudioBaseSrc *src); |
| 147 | |
| 148 | GST_AUDIO_API |
| 149 | void gst_audio_base_src_set_slave_method (GstAudioBaseSrc *src, |
| 150 | GstAudioBaseSrcSlaveMethod method); |
| 151 | GST_AUDIO_API |
| 152 | GstAudioBaseSrcSlaveMethod |
| 153 | gst_audio_base_src_get_slave_method (GstAudioBaseSrc *src); |
| 154 | |
| 155 | |
| 156 | #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC |
| 157 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstAudioBaseSrc, gst_object_unref) |
| 158 | #endif |
| 159 | |
| 160 | G_END_DECLS |
| 161 | |
| 162 | #endif /* __GST_AUDIO_BASE_SRC_H__ */ |
| 163 | |