![]() |
![]() |
![]() |
GStreamer 0.10 Library Reference Manual | ![]() |
---|---|---|---|---|
#include <gst/base/gstbasesrc.h> GstBaseSrc; GstBaseSrcClass; enum GstBaseSrcFlags; gboolean gst_base_src_is_live (GstBaseSrc *src); void gst_base_src_set_live (GstBaseSrc *src, gboolean live); void gst_base_src_set_format (GstBaseSrc *src, GstFormat format); #define GST_BASE_SRC_PAD (obj)
This is a generice base class for source elements. The following types of sources are supported:
random access sources like files
seekable sources
live sources
The source can be configured to operate in any GstFormat with the
gst_base_src_set_format()
method. The currently set format determines
the format of the internal GstSegment and any GST_EVENT_NEW_SEGMENT
events. The default format for GstBaseSrc is GST_FORMAT_BYTES.
GstBaseSrc always supports push mode scheduling. If the following conditions are met, it also supports pull mode scheduling:
The format is set to GST_FORMAT_BYTES (default).
GstBaseSrc::is_seekable returns TRUE.
Since 0.10.9, any GstBaseSrc can enable pull based scheduling at any time by overriding GstBaseSrc::check_get_range so that it returns TRUE.
If all the conditions are met for operating in pull mode, GstBaseSrc is automatically seekable in push mode as well. The following conditions must be met to make the element seekable in push mode when the format is not GST_FORMAT_BYTES:
GstBaseSrc::is_seekable returns TRUE.
GstBaseSrc::query can convert all supported seek formats to the
internal format as set with gst_base_src_set_format()
.
GstBaseSrc::do_seek is implemented, performs the seek and returns TRUE.
When the element does not meet the requirements to operate in pull mode, the offset and length in the GstBaseSrc::create method should be ignored. It is recommended to subclass GstPushSrc instead, in this situation. If the element can operate in pull mode but only with specific offsets and lengths, it is allowed to generate an error when the wrong values are passed to the GstBaseSrc::create function.
GstBaseSrc has support for live sources. Live sources are sources that
produce data at a fixed rate, such as audio or video capture devices. A
typical live source also provides a clock to publish the rate at which
they produce data.
Use gst_base_src_set_live()
to activate the live source mode.
A live source does not produce data in the PAUSED state. This means that the GstBaseSrc::create method will not be called in PAUSED but only in PLAYING. To signal the pipeline that the element will not produce data, the return value from the READY to PAUSED state will be GST_STATE_CHANGE_NO_PREROLL.
A typical live source will timestamp the buffers it creates with the current stream time of the pipeline. This is one reason why a live source can only produce data in the PLAYING state, when the clock is actually distributed and running.
The GstBaseSrc::get_times method can be used to implement pseudo-live sources. The base source will wait for the specified stream time returned in GstBaseSrc::get_times before pushing out the buffer. It only makes sense to implement the ::get_times function if the source is a live source.
There is only support in GstBaseSrc for exactly one source pad, which should be named "src". A source implementation (subclass of GstBaseSrc) should install a pad template in its base_init function, like so:
static void my_element_base_init (gpointer g_class) { GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class); // srctemplate should be a GstStaticPadTemplate with direction // GST_PAD_SRC and name "src" gst_element_class_add_pad_template (gstelement_class, gst_static_pad_template_get (&srctemplate)); // see GstElementDetails gst_element_class_set_details (gstelement_class, &details); }
Applications that record from a live source may want to stop recording in a controlled way, so that the recording is stopped, but the data already in the pipeline is processed to the end (remember that many live sources would go on recording forever otherwise). For that to happen the application needs to make the source stop recording and send an EOS event down the pipeline. The application would then wait for an EOS message posted on the pipeline's bus to know when all data has been processed and the pipeline can safely be stopped.
Since GStreamer 0.10.3 an application may simply set the source element to NULL or READY state to make it send an EOS event downstream. The application should lock the state of the source afterwards, so that shutting down the pipeline from PLAYING doesn't temporarily start up the source element for a second time:
... // stop recording gst_element_set_state (audio_source, GST_STATE_NULL); gst_element_set_locked_state (audio_source, TRUE); ...
Now the application should wait for an EOS message to be posted on the pipeline's bus. Once it has received an EOS message, it may safely shut down the entire pipeline:
... // everything done - shut down pipeline gst_element_set_state (pipeline, GST_STATE_NULL); gst_element_set_locked_state (audio_source, FALSE); ...
Note that setting the source element to NULL or READY when the pipeline is in the PAUSED state may cause a deadlock since the streaming thread might be blocked in PREROLL.
Last reviewed on 2006-07-06 (0.10.9)
typedef struct { GstElement element; } GstBaseSrc;
The opaque GstBaseSrc data structure.
GstElement element ; |
the parent element. |
GstPad *srcpad ; |
|
GMutex *live_lock ; |
|
GCond *live_cond ; |
|
gboolean is_live ; |
|
gboolean live_running ; |
|
gint blocksize ; |
|
gboolean can_activate_push ; |
|
GstActivateMode pad_mode ; |
|
gboolean seekable ; |
|
gboolean random_access ; |
|
GstClockID clock_id ; |
|
GstClockTime end_time ; |
|
GstSegment segment ; |
|
gboolean need_newsegment ; |
|
guint64 offset ; |
|
guint64 size ; |
|
gint num_buffers ; |
|
gint num_buffers_left ; |
|
gpointer _gst_reserved [GST_PADDING_LARGE-1]; |
typedef struct { GstElementClass parent_class; /* virtual methods for subclasses */ /* get caps from subclass */ GstCaps* (*get_caps) (GstBaseSrc *src); /* notify the subclass of new caps */ gboolean (*set_caps) (GstBaseSrc *src, GstCaps *caps); /* decide on caps */ gboolean (*negotiate) (GstBaseSrc *src); /* generate and send a newsegment (UNUSED) */ gboolean (*newsegment) (GstBaseSrc *src); /* start and stop processing, ideal for opening/closing the resource */ gboolean (*start) (GstBaseSrc *src); gboolean (*stop) (GstBaseSrc *src); /* given a buffer, return start and stop time when it should be pushed * out. The base class will sync on the clock using these times. */ void (*get_times) (GstBaseSrc *src, GstBuffer *buffer, GstClockTime *start, GstClockTime *end); /* get the total size of the resource in bytes */ gboolean (*get_size) (GstBaseSrc *src, guint64 *size); /* check if the resource is seekable */ gboolean (*is_seekable) (GstBaseSrc *src); /* unlock any pending access to the resource. subclasses should unlock * any function ASAP. */ gboolean (*unlock) (GstBaseSrc *src); /* notify subclasses of an event */ gboolean (*event) (GstBaseSrc *src, GstEvent *event); /* ask the subclass to create a buffer with offset and size */ GstFlowReturn (*create) (GstBaseSrc *src, guint64 offset, guint size, GstBuffer **buf); /* additions that change padding... */ /* notify subclasses of a seek */ gboolean (*do_seek) (GstBaseSrc *src, GstSegment *segment); /* notify subclasses of a query */ gboolean (*query) (GstBaseSrc *src, GstQuery *query); /* check whether the source would support pull-based operation if * it were to be opened now. This vfunc is optional, but should be * implemented if possible to avoid unnecessary start/stop cycles. * The default implementation will open and close the resource to * find out whether get_range is supported and that is usually * undesirable. */ gboolean (*check_get_range) (GstBaseSrc *src); } GstBaseSrcClass;
GstElementClass parent_class ; |
Element parent class |
get_caps () |
Called to get the caps to report |
set_caps () |
Notify subclass of changed output caps |
negotiate () |
Negotiated the caps with the peer. |
newsegment () |
Generate and send a new_segment event (UNUSED) |
start () |
Start processing. Subclasses should open resources and prepare to produce data. |
stop () |
Stop processing. Subclasses should use this to close resources. |
get_times () |
Given a buffer, return the start and stop time when it should be pushed out. The base class will sync on the clock using these times. |
get_size () |
Return the total size of the resource, in the configured format. |
is_seekable () |
Check if the source can seek |
unlock () |
Unlock any pending access to the resource. Subclasses should unblock any blocked function ASAP |
event () |
Override this to implement custom event handling. |
create () |
Ask the subclass to create a buffer with offset and size. |
do_seek () |
Perform seeking on the resource to the indicated segment. |
query () |
Handle a requested query. |
check_get_range () |
Check whether the source would support pull-based operation if it were to be opened now. This vfunc is optional, but should be implemented if possible to avoid unnecessary start/stop cycles. The default implementation will open and close the resource to find out whether get_range is supported, and that is usually undesirable. |
typedef enum { GST_BASE_SRC_STARTED = (GST_ELEMENT_FLAG_LAST << 0), /* padding */ GST_BASE_SRC_FLAG_LAST = (GST_ELEMENT_FLAG_LAST << 2) } GstBaseSrcFlags;
The GstElement flags that a basesrc element may have.
gboolean gst_base_src_is_live (GstBaseSrc *src);
Check if an element is in live mode.
src : |
base source instance |
Returns : | TRUE if element is in live mode.
|
void gst_base_src_set_live (GstBaseSrc *src, gboolean live);
If the element listens to a live source, live
should
be set to TRUE
.
A live source will not produce data in the PAUSED state and will therefore not be able to participate in the PREROLL phase of a pipeline. To signal this fact to the application and the pipeline, the state change return value of the live source will be GST_STATE_CHANGE_NO_PREROLL.
src : |
base source instance |
live : |
new live-mode |
void gst_base_src_set_format (GstBaseSrc *src, GstFormat format);
Sets the default format of the source. This will be the format used for sending NEW_SEGMENT events and for performing seeks.
If a format of GST_FORMAT_BYTES is set, the element will be able to operate in pull mode if the GstBaseSrc::is_seekable returns TRUE.
Since
: 0.10.1
src : |
base source instance |
format : |
the format to use |
#define GST_BASE_SRC_PAD(obj) (GST_BASE_SRC_CAST (obj)->srcpad)
Gives the pointer to the GstPad object of the element.
obj : |
base source instance |