Branch data Line data Source code
1 : : /* GStreamer
2 : : * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 : : * 2000,2005 Wim Taymans <wim@fluendo.com>
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., 59 Temple Place - Suite 330,
20 : : * Boston, MA 02111-1307, USA.
21 : : */
22 : :
23 : : /**
24 : : * SECTION:gstpushsrc
25 : : * @short_description: Base class for push based source elements
26 : : * @see_also: #GstBaseSrc
27 : : *
28 : : * This class is mostly useful for elements that cannot do
29 : : * random access, or at least very slowly. The source usually
30 : : * prefers to push out a fixed size buffer.
31 : : *
32 : : * Subclasses usually operate in a format that is different from the
33 : : * default GST_FORMAT_BYTES format of #GstBaseSrc.
34 : : *
35 : : * Classes extending this base class will usually be scheduled
36 : : * in a push based mode. If the peer accepts to operate without
37 : : * offsets and within the limits of the allowed block size, this
38 : : * class can operate in getrange based mode automatically. To make
39 : : * this possible, the subclass should override the ::check_get_range
40 : : * method.
41 : : *
42 : : * The subclass should extend the methods from the baseclass in
43 : : * addition to the ::create method.
44 : : *
45 : : * Seeking, flushing, scheduling and sync is all handled by this
46 : : * base class.
47 : : *
48 : : * Last reviewed on 2006-07-04 (0.10.9)
49 : : */
50 : :
51 : : #ifdef HAVE_CONFIG_H
52 : : # include "config.h"
53 : : #endif
54 : :
55 : : #include <stdlib.h>
56 : : #include <string.h>
57 : :
58 : : #include "gstpushsrc.h"
59 : : #include "gsttypefindhelper.h"
60 : : #include <gst/gstmarshal.h>
61 : :
62 : : GST_DEBUG_CATEGORY_STATIC (gst_push_src_debug);
63 : : #define GST_CAT_DEFAULT gst_push_src_debug
64 : :
65 : : #define _do_init(type) \
66 : : GST_DEBUG_CATEGORY_INIT (gst_push_src_debug, "pushsrc", 0, \
67 : : "pushsrc element");
68 : :
69 [ + + ][ + - ]: 147510 : GST_BOILERPLATE_FULL (GstPushSrc, gst_push_src, GstBaseSrc, GST_TYPE_BASE_SRC,
70 : 147510 : _do_init);
71 : :
72 : : static gboolean gst_push_src_check_get_range (GstBaseSrc * src);
73 : : static GstFlowReturn gst_push_src_create (GstBaseSrc * bsrc, guint64 offset,
74 : : guint length, GstBuffer ** ret);
75 : :
76 : : static void
77 : 24 : gst_push_src_base_init (gpointer g_class)
78 : : {
79 : : /* nop */
80 : 24 : }
81 : :
82 : : static void
83 : 12 : gst_push_src_class_init (GstPushSrcClass * klass)
84 : : {
85 : 12 : GstBaseSrcClass *gstbasesrc_class = (GstBaseSrcClass *) klass;
86 : :
87 : 12 : gstbasesrc_class->create = GST_DEBUG_FUNCPTR (gst_push_src_create);
88 : 12 : gstbasesrc_class->check_get_range =
89 : 12 : GST_DEBUG_FUNCPTR (gst_push_src_check_get_range);
90 : 12 : }
91 : :
92 : : static void
93 : 16 : gst_push_src_init (GstPushSrc * pushsrc, GstPushSrcClass * klass)
94 : : {
95 : : /* nop */
96 : 16 : }
97 : :
98 : : static gboolean
99 : 0 : gst_push_src_check_get_range (GstBaseSrc * src)
100 : : {
101 : : /* a pushsrc can by default never operate in pull mode override
102 : : * if you want something different. */
103 : 0 : return FALSE;
104 : : }
105 : :
106 : : static GstFlowReturn
107 : 147330 : gst_push_src_create (GstBaseSrc * bsrc, guint64 offset, guint length,
108 : : GstBuffer ** ret)
109 : : {
110 : : GstFlowReturn fret;
111 : : GstPushSrc *src;
112 : : GstPushSrcClass *pclass;
113 : :
114 : 147330 : src = GST_PUSH_SRC (bsrc);
115 : 147338 : pclass = GST_PUSH_SRC_GET_CLASS (src);
116 [ + - ]: 147338 : if (pclass->create)
117 : 147338 : fret = pclass->create (src, ret);
118 : : else
119 : 0 : fret = GST_FLOW_ERROR;
120 : :
121 : 147338 : return fret;
122 : : }
|