mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-18 07:47:17 +00:00
baseparse: remove is_seekable vmethod and use a set_seek instead
Seekability, like duration, etc is unlikely to change (frequently), and the default assumption covers most cases, so let subclass set when needed. At the same time, allow subclass to indicate if it has seek-metadata (table) available, and possibly have it provide an average bitrate.
This commit is contained in:
parent
4b0f92db79
commit
7ba1b6e4d7
2 changed files with 51 additions and 25 deletions
|
@ -218,6 +218,8 @@ struct _GstBaseParsePrivate
|
||||||
gboolean passthrough;
|
gboolean passthrough;
|
||||||
guint fps_num, fps_den;
|
guint fps_num, fps_den;
|
||||||
guint update_interval;
|
guint update_interval;
|
||||||
|
guint bitrate;
|
||||||
|
GstBaseParseSeekable seekable;
|
||||||
|
|
||||||
gboolean discont;
|
gboolean discont;
|
||||||
gboolean flushing;
|
gboolean flushing;
|
||||||
|
@ -307,8 +309,6 @@ static gboolean gst_base_parse_sink_eventfunc (GstBaseParse * parse,
|
||||||
static gboolean gst_base_parse_src_eventfunc (GstBaseParse * parse,
|
static gboolean gst_base_parse_src_eventfunc (GstBaseParse * parse,
|
||||||
GstEvent * event);
|
GstEvent * event);
|
||||||
|
|
||||||
static gboolean gst_base_parse_is_seekable (GstBaseParse * parse);
|
|
||||||
|
|
||||||
static void gst_base_parse_drain (GstBaseParse * parse);
|
static void gst_base_parse_drain (GstBaseParse * parse);
|
||||||
|
|
||||||
static void gst_base_parse_post_bitrates (GstBaseParse * parse,
|
static void gst_base_parse_post_bitrates (GstBaseParse * parse,
|
||||||
|
@ -359,7 +359,6 @@ gst_base_parse_class_init (GstBaseParseClass * klass)
|
||||||
klass->check_valid_frame = gst_base_parse_check_frame;
|
klass->check_valid_frame = gst_base_parse_check_frame;
|
||||||
klass->parse_frame = gst_base_parse_parse_frame;
|
klass->parse_frame = gst_base_parse_parse_frame;
|
||||||
klass->src_event = gst_base_parse_src_eventfunc;
|
klass->src_event = gst_base_parse_src_eventfunc;
|
||||||
klass->is_seekable = gst_base_parse_is_seekable;
|
|
||||||
klass->convert = gst_base_parse_convert_default;
|
klass->convert = gst_base_parse_convert_default;
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY_INIT (gst_base_parse_debug, "baseparse", 0,
|
GST_DEBUG_CATEGORY_INIT (gst_base_parse_debug, "baseparse", 0,
|
||||||
|
@ -752,7 +751,7 @@ gst_base_parse_src_eventfunc (GstBaseParse * parse, GstEvent * event)
|
||||||
switch (GST_EVENT_TYPE (event)) {
|
switch (GST_EVENT_TYPE (event)) {
|
||||||
case GST_EVENT_SEEK:
|
case GST_EVENT_SEEK:
|
||||||
{
|
{
|
||||||
if (bclass->is_seekable (parse)) {
|
if (parse->priv->seekable > GST_BASE_PARSE_SEEK_NONE) {
|
||||||
handled = gst_base_parse_handle_seek (parse, event);
|
handled = gst_base_parse_handle_seek (parse, event);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -764,20 +763,6 @@ gst_base_parse_src_eventfunc (GstBaseParse * parse, GstEvent * event)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* gst_base_parse_is_seekable:
|
|
||||||
* @parse: #GstBaseParse.
|
|
||||||
*
|
|
||||||
* Default handler for is_seekable.
|
|
||||||
*
|
|
||||||
* Returns: Always TRUE.
|
|
||||||
*/
|
|
||||||
static gboolean
|
|
||||||
gst_base_parse_is_seekable (GstBaseParse * parse)
|
|
||||||
{
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gst_base_parse_convert_default:
|
* gst_base_parse_convert_default:
|
||||||
* @parse: #GstBaseParse.
|
* @parse: #GstBaseParse.
|
||||||
|
@ -965,6 +950,11 @@ gst_base_parse_update_bitrates (GstBaseParse * parse, GstBuffer * buffer)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* override if subclass provided bitrate, e.g. metadata based */
|
||||||
|
if (parse->priv->bitrate) {
|
||||||
|
parse->priv->avg_bitrate = parse->priv->bitrate;
|
||||||
|
}
|
||||||
|
|
||||||
frame_bitrate = (8 * data_len * GST_SECOND) / frame_dur;
|
frame_bitrate = (8 * data_len * GST_SECOND) / frame_dur;
|
||||||
|
|
||||||
if (frame_bitrate < parse->priv->min_bitrate) {
|
if (frame_bitrate < parse->priv->min_bitrate) {
|
||||||
|
@ -1628,6 +1618,8 @@ gst_base_parse_activate (GstBaseParse * parse, gboolean active)
|
||||||
parse->priv->update_interval = 0;
|
parse->priv->update_interval = 0;
|
||||||
parse->priv->fps_num = parse->priv->fps_den = 0;
|
parse->priv->fps_num = parse->priv->fps_den = 0;
|
||||||
parse->priv->frame_duration = GST_CLOCK_TIME_NONE;
|
parse->priv->frame_duration = GST_CLOCK_TIME_NONE;
|
||||||
|
parse->priv->seekable = GST_BASE_PARSE_SEEK_DEFAULT;
|
||||||
|
parse->priv->bitrate = 0;
|
||||||
parse->priv->framecount = 0;
|
parse->priv->framecount = 0;
|
||||||
parse->priv->bytecount = 0;
|
parse->priv->bytecount = 0;
|
||||||
parse->priv->acc_duration = 0;
|
parse->priv->acc_duration = 0;
|
||||||
|
@ -1773,6 +1765,27 @@ gst_base_parse_set_duration (GstBaseParse * parse,
|
||||||
GST_BASE_PARSE_UNLOCK (parse);
|
GST_BASE_PARSE_UNLOCK (parse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_base_parse_set_seek:
|
||||||
|
* @parse: #GstBaseParse.
|
||||||
|
* @seek: #GstBaseParseSeekable.
|
||||||
|
* @abitrate: average bitrate.
|
||||||
|
*
|
||||||
|
* Sets whether and how the media is seekable (in time).
|
||||||
|
* Also optionally provides average bitrate detected in media (if non-zero),
|
||||||
|
* e.g. based on metadata, as it will be posted to the application.
|
||||||
|
*
|
||||||
|
* By default, announced average bitrate is estimated, and seekability is assumed
|
||||||
|
* possible based on estimated bitrate.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
gst_base_parse_set_seek (GstBaseParse * parse,
|
||||||
|
GstBaseParseSeekable seek, guint bitrate)
|
||||||
|
{
|
||||||
|
parse->priv->seekable = seek;
|
||||||
|
parse->priv->bitrate = bitrate;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gst_base_parse_set_min_frame_size:
|
* gst_base_parse_set_min_frame_size:
|
||||||
|
@ -2038,7 +2051,8 @@ gst_base_parse_query (GstPad * pad, GstQuery * query)
|
||||||
res = gst_pad_query_default (pad, query);
|
res = gst_pad_query_default (pad, query);
|
||||||
|
|
||||||
/* we may be able to help if in TIME */
|
/* we may be able to help if in TIME */
|
||||||
if (fmt == GST_FORMAT_TIME && klass->is_seekable (parse)) {
|
if (fmt == GST_FORMAT_TIME &&
|
||||||
|
parse->priv->seekable > GST_BASE_PARSE_SEEK_NONE) {
|
||||||
gst_query_parse_seeking (query, &fmt, &seekable, NULL, NULL);
|
gst_query_parse_seeking (query, &fmt, &seekable, NULL, NULL);
|
||||||
/* already OK if upstream takes care */
|
/* already OK if upstream takes care */
|
||||||
GST_LOG_OBJECT (parse, "upstream handled %d, seekable %d",
|
GST_LOG_OBJECT (parse, "upstream handled %d, seekable %d",
|
||||||
|
|
|
@ -130,6 +130,21 @@ G_BEGIN_DECLS
|
||||||
*/
|
*/
|
||||||
#define GST_BASE_PARSE_UNLOCK(obj) g_mutex_unlock (GST_BASE_PARSE_CAST (obj)->parse_lock)
|
#define GST_BASE_PARSE_UNLOCK(obj) g_mutex_unlock (GST_BASE_PARSE_CAST (obj)->parse_lock)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GstBaseParseSeekable:
|
||||||
|
* @GST_BASE_PARSE_SEEK_NONE: No seeking possible.
|
||||||
|
* GST_BASE_PARSE_SEEK_DEFAULT: Default seeking possible using estimated bitrate.
|
||||||
|
* GST_BASE_PARSE_SEEK_TABLE: Additional metadata provides more accurate seeking.
|
||||||
|
*
|
||||||
|
* Indicates what level (of quality) of seeking is possible.
|
||||||
|
*/
|
||||||
|
typedef enum _GstBaseParseSeekable {
|
||||||
|
GST_BASE_PARSE_SEEK_NONE,
|
||||||
|
GST_BASE_PARSE_SEEK_DEFAULT,
|
||||||
|
GST_BASE_PARSE_SEEK_TABLE
|
||||||
|
} GstBaseParseSeekable;
|
||||||
|
|
||||||
typedef struct _GstBaseParse GstBaseParse;
|
typedef struct _GstBaseParse GstBaseParse;
|
||||||
typedef struct _GstBaseParseClass GstBaseParseClass;
|
typedef struct _GstBaseParseClass GstBaseParseClass;
|
||||||
typedef struct _GstBaseParsePrivate GstBaseParsePrivate;
|
typedef struct _GstBaseParsePrivate GstBaseParsePrivate;
|
||||||
|
@ -196,10 +211,6 @@ struct _GstBaseParse {
|
||||||
* @src_event: Optional.
|
* @src_event: Optional.
|
||||||
* Event handler on the source pad. Should return TRUE
|
* Event handler on the source pad. Should return TRUE
|
||||||
* if the event was handled and can be dropped.
|
* if the event was handled and can be dropped.
|
||||||
* @is_seekable: Optional.
|
|
||||||
* Subclass can override this if it wants to control the
|
|
||||||
* seekability of the stream. Otherwise the element assumes
|
|
||||||
* that stream is always seekable.
|
|
||||||
*
|
*
|
||||||
* @get_frame_overhead: Finds the metadata overhead for the given frame. This
|
* @get_frame_overhead: Finds the metadata overhead for the given frame. This
|
||||||
* is used to enable more accurate bitrate computations.
|
* is used to enable more accurate bitrate computations.
|
||||||
|
@ -256,8 +267,6 @@ struct _GstBaseParseClass {
|
||||||
gboolean (*src_event) (GstBaseParse *parse,
|
gboolean (*src_event) (GstBaseParse *parse,
|
||||||
GstEvent *event);
|
GstEvent *event);
|
||||||
|
|
||||||
gboolean (*is_seekable) (GstBaseParse *parse);
|
|
||||||
|
|
||||||
gint (*get_frame_overhead) (GstBaseParse *parse,
|
gint (*get_frame_overhead) (GstBaseParse *parse,
|
||||||
GstBuffer *buf);
|
GstBuffer *buf);
|
||||||
|
|
||||||
|
@ -278,6 +287,9 @@ void gst_base_parse_set_duration (GstBaseParse *parse,
|
||||||
GstFormat fmt,
|
GstFormat fmt,
|
||||||
gint64 duration);
|
gint64 duration);
|
||||||
|
|
||||||
|
void gst_base_parse_set_seek (GstBaseParse * parse,
|
||||||
|
GstBaseParseSeekable seek, guint bitrate);
|
||||||
|
|
||||||
void gst_base_parse_set_min_frame_size (GstBaseParse *parse,
|
void gst_base_parse_set_min_frame_size (GstBaseParse *parse,
|
||||||
guint min_size);
|
guint min_size);
|
||||||
void gst_base_parse_set_passthrough (GstBaseParse * parse, gboolean passthrough);
|
void gst_base_parse_set_passthrough (GstBaseParse * parse, gboolean passthrough);
|
||||||
|
|
Loading…
Reference in a new issue