| 1 |
/* GStreamer |
| 2 |
* Copyright (C) 1999,2000 Erik Walthinsen <[email protected]> |
| 3 |
* 2000,2005 Wim Taymans <[email protected]> |
| 4 |
* |
| 5 |
* gstpushsrc.c: |
| 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 |
/** |
| 24 |
* SECTION:gstpushsrc |
| 25 |
* @title: GstPushSrc |
| 26 |
* @short_description: Base class for push based source elements |
| 27 |
* @see_also: #GstBaseSrc |
| 28 |
* |
| 29 |
* This class is mostly useful for elements that cannot do |
| 30 |
* random access, or at least very slowly. The source usually |
| 31 |
* prefers to push out a fixed size buffer. |
| 32 |
* |
| 33 |
* Subclasses usually operate in a format that is different from the |
| 34 |
* default GST_FORMAT_BYTES format of #GstBaseSrc. |
| 35 |
* |
| 36 |
* Classes extending this base class will usually be scheduled |
| 37 |
* in a push based mode. If the peer accepts to operate without |
| 38 |
* offsets and within the limits of the allowed block size, this |
| 39 |
* class can operate in getrange based mode automatically. To make |
| 40 |
* this possible, the subclass should implement and override the |
| 41 |
* SCHEDULING query. |
| 42 |
* |
| 43 |
* The subclass should extend the methods from the baseclass in |
| 44 |
* addition to the ::create method. |
| 45 |
* |
| 46 |
* Seeking, flushing, scheduling and sync is all handled by this |
| 47 |
* base class. |
| 48 |
*/ |
| 49 |
|
| 50 |
#ifdef HAVE_CONFIG_H |
| 51 |
# include "config.h" |
| 52 |
#endif |
| 53 |
|
| 54 |
#include <stdlib.h> |
| 55 |
#include <string.h> |
| 56 |
|
| 57 |
#include "gstpushsrc.h" |
| 58 |
#include "gsttypefindhelper.h" |
| 59 |
|
| 60 |
GST_DEBUG_CATEGORY_STATIC (gst_push_src_debug); |
| 61 |
#define GST_CAT_DEFAULT gst_push_src_debug |
| 62 |
|
| 63 |
#define _do_init \ |
| 64 |
GST_DEBUG_CATEGORY_INIT (gst_push_src_debug, "pushsrc", 0, \ |
| 65 |
"pushsrc element"); |
| 66 |
|
| 67 |
#define gst_push_src_parent_class parent_class |
| 68 |
G_DEFINE_TYPE_WITH_CODE (GstPushSrc, gst_push_src, GST_TYPE_BASE_SRC, _do_init); |
| 69 |
|
| 70 |
static gboolean gst_push_src_query (GstBaseSrc * src, GstQuery * query); |
| 71 |
static GstFlowReturn gst_push_src_create (GstBaseSrc * bsrc, guint64 offset, |
| 72 |
guint length, GstBuffer ** ret); |
| 73 |
static GstFlowReturn gst_push_src_alloc (GstBaseSrc * bsrc, guint64 offset, |
| 74 |
guint length, GstBuffer ** ret); |
| 75 |
static GstFlowReturn gst_push_src_fill (GstBaseSrc * bsrc, guint64 offset, |
| 76 |
guint length, GstBuffer * ret); |
| 77 |
|
| 78 |
static void |
| 79 |
gst_push_src_class_init (GstPushSrcClass * klass) |
| 80 |
{ |
| 81 |
GstBaseSrcClass *gstbasesrc_class = (GstBaseSrcClass *) klass; |
| 82 |
|
| 83 |
gstbasesrc_class->create = GST_DEBUG_FUNCPTR (gst_push_src_create); |
| 84 |
gstbasesrc_class->alloc = GST_DEBUG_FUNCPTR (gst_push_src_alloc); |
| 85 |
gstbasesrc_class->fill = GST_DEBUG_FUNCPTR (gst_push_src_fill); |
| 86 |
gstbasesrc_class->query = GST_DEBUG_FUNCPTR (gst_push_src_query); |
| 87 |
} |
| 88 |
|
| 89 |
static void |
| 90 |
gst_push_src_init (GstPushSrc * pushsrc) |
| 91 |
{ |
| 92 |
/* nop */ |
| 93 |
} |
| 94 |
|
| 95 |
static gboolean |
| 96 |
gst_push_src_query (GstBaseSrc * src, GstQuery * query) |
| 97 |
{ |
| 98 |
gboolean ret; |
| 99 |
|
| 100 |
switch (GST_QUERY_TYPE (query)) { |
| 101 |
case GST_QUERY_SCHEDULING: |
| 102 |
{ |
| 103 |
/* a pushsrc can by default never operate in pull mode override |
| 104 |
* if you want something different. */ |
| 105 |
gst_query_set_scheduling (query, GST_SCHEDULING_FLAG_SEQUENTIAL, 1, -1, |
| 106 |
0); |
| 107 |
gst_query_add_scheduling_mode (query, GST_PAD_MODE_PUSH); |
| 108 |
|
| 109 |
ret = TRUE; |
| 110 |
break; |
| 111 |
} |
| 112 |
default: |
| 113 |
ret = GST_BASE_SRC_CLASS (parent_class)->query (src, query); |
| 114 |
break; |
| 115 |
} |
| 116 |
return ret; |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
static GstFlowReturn |
| 121 |
gst_push_src_create (GstBaseSrc * bsrc, guint64 offset, guint length, |
| 122 |
GstBuffer ** ret) |
| 123 |
{ |
| 124 |
GstFlowReturn fret; |
| 125 |
GstPushSrc *src; |
| 126 |
GstPushSrcClass *pclass; |
| 127 |
|
| 128 |
src = GST_PUSH_SRC (bsrc); |
| 129 |
pclass = GST_PUSH_SRC_GET_CLASS (src); |
| 130 |
if (pclass->create) |
| 131 |
fret = pclass->create (src, ret); |
| 132 |
else |
| 133 |
fret = |
| 134 |
GST_BASE_SRC_CLASS (parent_class)->create (bsrc, offset, length, ret); |
| 135 |
|
| 136 |
return fret; |
| 137 |
} |
| 138 |
|
| 139 |
static GstFlowReturn |
| 140 |
gst_push_src_alloc (GstBaseSrc * bsrc, guint64 offset, guint length, |
| 141 |
GstBuffer ** ret) |
| 142 |
{ |
| 143 |
GstFlowReturn fret; |
| 144 |
GstPushSrc *src; |
| 145 |
GstPushSrcClass *pclass; |
| 146 |
|
| 147 |
src = GST_PUSH_SRC (bsrc); |
| 148 |
pclass = GST_PUSH_SRC_GET_CLASS (src); |
| 149 |
if (pclass->alloc) |
| 150 |
fret = pclass->alloc (src, ret); |
| 151 |
else |
| 152 |
fret = GST_BASE_SRC_CLASS (parent_class)->alloc (bsrc, offset, length, ret); |
| 153 |
|
| 154 |
return fret; |
| 155 |
} |
| 156 |
|
| 157 |
static GstFlowReturn |
| 158 |
gst_push_src_fill (GstBaseSrc * bsrc, guint64 offset, guint length, |
| 159 |
GstBuffer * ret) |
| 160 |
{ |
| 161 |
GstFlowReturn fret; |
| 162 |
GstPushSrc *src; |
| 163 |
GstPushSrcClass *pclass; |
| 164 |
|
| 165 |
src = GST_PUSH_SRC (bsrc); |
| 166 |
pclass = GST_PUSH_SRC_GET_CLASS (src); |
| 167 |
if (pclass->fill) |
| 168 |
fret = pclass->fill (src, ret); |
| 169 |
else |
| 170 |
fret = GST_BASE_SRC_CLASS (parent_class)->fill (bsrc, offset, length, ret); |
| 171 |
|
| 172 |
return fret; |
| 173 |
} |