summaryrefslogtreecommitdiff
path: root/gst
diff options
context:
space:
mode:
authorVivia Nikolaidou <vivia@toolsonair.com>2017-02-20 18:58:11 +0200
committerSebastian Dröge <sebastian@centricular.com>2017-02-22 21:01:46 +0200
commit668c44072bd13aebd08e07f309691ea341ccfead (patch)
tree5ef3f0fa2819cf8178c8177a472f4e0d881126b2 /gst
parente2dffab9bee8611b0daa818806f36541bfedde26 (diff)
audiobuffersplit: Add strict-buffer-size property
If set to TRUE, any last audio samples too small to fill a buffer will be discarded. https://bugzilla.gnome.org/show_bug.cgi?id=779064
Diffstat (limited to 'gst')
-rw-r--r--gst/audiobuffersplit/gstaudiobuffersplit.c28
-rw-r--r--gst/audiobuffersplit/gstaudiobuffersplit.h2
2 files changed, 28 insertions, 2 deletions
diff --git a/gst/audiobuffersplit/gstaudiobuffersplit.c b/gst/audiobuffersplit/gstaudiobuffersplit.c
index 3b3526734..40eef57a8 100644
--- a/gst/audiobuffersplit/gstaudiobuffersplit.c
+++ b/gst/audiobuffersplit/gstaudiobuffersplit.c
@@ -45,6 +45,7 @@ enum
PROP_OUTPUT_BUFFER_DURATION,
PROP_ALIGNMENT_THRESHOLD,
PROP_DISCONT_WAIT,
+ PROP_STRICT_BUFFER_SIZE,
LAST_PROP
};
@@ -52,6 +53,7 @@ enum
#define DEFAULT_OUTPUT_BUFFER_DURATION_D (50)
#define DEFAULT_ALIGNMENT_THRESHOLD (40 * GST_MSECOND)
#define DEFAULT_DISCONT_WAIT (1 * GST_SECOND)
+#define DEFAULT_STRICT_BUFFER_SIZE (FALSE)
#define parent_class gst_audio_buffer_split_parent_class
G_DEFINE_TYPE (GstAudioBufferSplit, gst_audio_buffer_split, GST_TYPE_ELEMENT);
@@ -105,6 +107,13 @@ gst_audio_buffer_split_class_init (GstAudioBufferSplitClass * klass)
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
GST_PARAM_MUTABLE_READY));
+ g_object_class_install_property (gobject_class, PROP_STRICT_BUFFER_SIZE,
+ g_param_spec_boolean ("strict-buffer-size", "Strict buffer size",
+ "Discard the last samples at EOS or discont if they are too "
+ "small to fill a buffer", DEFAULT_STRICT_BUFFER_SIZE,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
+ GST_PARAM_MUTABLE_READY));
+
gst_element_class_set_static_metadata (gstelement_class,
"Audio Buffer Split", "Audio/Filter",
"Splits raw audio buffers into equal sized chunks",
@@ -140,6 +149,7 @@ gst_audio_buffer_split_init (GstAudioBufferSplit * self)
self->output_buffer_duration_d = DEFAULT_OUTPUT_BUFFER_DURATION_D;
self->alignment_threshold = DEFAULT_ALIGNMENT_THRESHOLD;
self->discont_wait = DEFAULT_DISCONT_WAIT;
+ self->strict_buffer_size = DEFAULT_STRICT_BUFFER_SIZE;
self->adapter = gst_adapter_new ();
}
@@ -175,6 +185,9 @@ gst_audio_buffer_split_set_property (GObject * object, guint property_id,
case PROP_DISCONT_WAIT:
self->discont_wait = g_value_get_uint64 (value);
break;
+ case PROP_STRICT_BUFFER_SIZE:
+ self->strict_buffer_size = g_value_get_boolean (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -198,6 +211,9 @@ gst_audio_buffer_split_get_property (GObject * object, guint property_id,
case PROP_DISCONT_WAIT:
g_value_set_uint64 (value, self->discont_wait);
break;
+ case PROP_STRICT_BUFFER_SIZE:
+ g_value_set_boolean (value, self->strict_buffer_size);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -379,7 +395,12 @@ gst_audio_buffer_split_handle_discont (GstAudioBufferSplit * self,
GST_INFO_OBJECT (self, "Have discont. Expected %"
G_GUINT64_FORMAT ", got %" G_GUINT64_FORMAT,
self->next_offset, start_offset);
- ret = gst_audio_buffer_split_output (self, TRUE);
+ if (self->strict_buffer_size) {
+ gst_adapter_clear (self->adapter);
+ ret = GST_FLOW_OK;
+ } else {
+ ret = gst_audio_buffer_split_output (self, TRUE);
+ }
}
self->next_offset = end_offset;
self->resync_time = timestamp;
@@ -499,7 +520,10 @@ gst_audio_buffer_split_sink_event (GstPad * pad, GstObject * parent,
}
break;
case GST_EVENT_EOS:
- gst_audio_buffer_split_output (self, TRUE);
+ if (self->strict_buffer_size)
+ gst_adapter_clear (self->adapter);
+ else
+ gst_audio_buffer_split_output (self, TRUE);
ret = gst_pad_event_default (pad, parent, event);
break;
default:
diff --git a/gst/audiobuffersplit/gstaudiobuffersplit.h b/gst/audiobuffersplit/gstaudiobuffersplit.h
index ac4558a19..5f40ac1b9 100644
--- a/gst/audiobuffersplit/gstaudiobuffersplit.h
+++ b/gst/audiobuffersplit/gstaudiobuffersplit.h
@@ -63,6 +63,8 @@ struct _GstAudioBufferSplit {
guint samples_per_buffer;
guint error_per_buffer;
guint accumulated_error;
+
+ gboolean strict_buffer_size;
};
struct _GstAudioBufferSplitClass {