2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 * SECTION:element-audiorate
23 * @see_also: #GstVideoRate
25 * This element takes an incoming stream of timestamped raw audio frames and
26 * produces a perfect stream by inserting or dropping samples as needed.
28 * This operation may be of use to link to elements that require or otherwise
29 * implicitly assume a perfect stream as they do not store timestamps,
30 * but derive this by some means (e.g. bitrate for some AVI cases).
32 * The properties #GstAudioRate:in, #GstAudioRate:out, #GstAudioRate:add
33 * and #GstAudioRate:drop can be read to obtain information about number of
34 * input samples, output samples, dropped samples (i.e. the number of unused
35 * input samples) and inserted samples (i.e. the number of samples added to
38 * When the #GstAudioRate:silent property is set to FALSE, a GObject property
39 * notification will be emitted whenever one of the #GstAudioRate:add or
40 * #GstAudioRate:drop values changes.
41 * This can potentially cause performance degradation.
42 * Note that property notification will happen from the streaming thread, so
43 * applications should be prepared for this.
45 * If the #GstAudioRate:tolerance property is non-zero, and an incoming buffer's
46 * timestamp deviates less than the property indicates from what would make a
47 * 'perfect time', then no samples will be added or dropped.
48 * Note that the output is still guaranteed to be a perfect stream, which means
49 * that the incoming data is then simply shifted (by less than the indicated
50 * tolerance) to a perfect time.
52 * ## Example pipelines
54 * gst-launch-1.0 -v autoaudiosrc ! audiorate ! audioconvert ! wavenc ! filesink location=alsa.wav
56 * Capture audio from the sound card and turn it into a perfect stream
57 * for saving in a raw audio file.
59 * gst-launch-1.0 -v uridecodebin uri=file:///path/to/audio.file ! audiorate ! audioconvert ! wavenc ! filesink location=alsa.wav
61 * Decodes an audio file and transforms it into a perfect stream for saving
62 * in a raw audio WAV file. Without the audio rate, the timing might not be
63 * preserved correctly in the WAV file in case the decoded stream is jittery
64 * or there are samples missing.
75 #include "gstaudiorate.h"
77 #define GST_CAT_DEFAULT audio_rate_debug
78 GST_DEBUG_CATEGORY_STATIC (audio_rate_debug);
80 /* GstAudioRate signals and args */
87 #define DEFAULT_SILENT TRUE
88 #define DEFAULT_TOLERANCE (40 * GST_MSECOND)
89 #define DEFAULT_SKIP_TO_FIRST FALSE
103 static GstStaticPadTemplate gst_audio_rate_src_template =
104 GST_STATIC_PAD_TEMPLATE ("src",
107 GST_STATIC_CAPS (GST_AUDIO_CAPS_MAKE (GST_AUDIO_FORMATS_ALL)
108 ", layout = (string) { interleaved, non-interleaved }")
111 static GstStaticPadTemplate gst_audio_rate_sink_template =
112 GST_STATIC_PAD_TEMPLATE ("sink",
115 GST_STATIC_CAPS (GST_AUDIO_CAPS_MAKE (GST_AUDIO_FORMATS_ALL)
116 ", layout = (string) { interleaved, non-interleaved }")
119 static gboolean gst_audio_rate_sink_event (GstPad * pad, GstObject * parent,
121 static gboolean gst_audio_rate_src_event (GstPad * pad, GstObject * parent,
123 static GstFlowReturn gst_audio_rate_chain (GstPad * pad, GstObject * parent,
126 static void gst_audio_rate_set_property (GObject * object,
127 guint prop_id, const GValue * value, GParamSpec * pspec);
128 static void gst_audio_rate_get_property (GObject * object,
129 guint prop_id, GValue * value, GParamSpec * pspec);
131 static GstStateChangeReturn gst_audio_rate_change_state (GstElement * element,
132 GstStateChange transition);
134 /*static guint gst_audio_rate_signals[LAST_SIGNAL] = { 0 }; */
136 static GParamSpec *pspec_drop = NULL;
137 static GParamSpec *pspec_add = NULL;
139 #define gst_audio_rate_parent_class parent_class
140 G_DEFINE_TYPE (GstAudioRate, gst_audio_rate, GST_TYPE_ELEMENT);
141 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (audiorate, "audiorate", GST_RANK_NONE,
142 GST_TYPE_AUDIO_RATE, GST_DEBUG_CATEGORY_INIT (audio_rate_debug, "audiorate",
143 0, "AudioRate stream fixer"));
146 gst_audio_rate_class_init (GstAudioRateClass * klass)
148 GObjectClass *object_class = G_OBJECT_CLASS (klass);
149 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
151 object_class->set_property = gst_audio_rate_set_property;
152 object_class->get_property = gst_audio_rate_get_property;
154 g_object_class_install_property (object_class, PROP_IN,
155 g_param_spec_uint64 ("in", "In",
156 "Number of input samples", 0, G_MAXUINT64, 0,
157 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
158 g_object_class_install_property (object_class, PROP_OUT,
159 g_param_spec_uint64 ("out", "Out", "Number of output samples", 0,
160 G_MAXUINT64, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
161 pspec_add = g_param_spec_uint64 ("add", "Add", "Number of added samples",
162 0, G_MAXUINT64, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
163 g_object_class_install_property (object_class, PROP_ADD, pspec_add);
164 pspec_drop = g_param_spec_uint64 ("drop", "Drop", "Number of dropped samples",
165 0, G_MAXUINT64, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
166 g_object_class_install_property (object_class, PROP_DROP, pspec_drop);
167 g_object_class_install_property (object_class, PROP_SILENT,
168 g_param_spec_boolean ("silent", "silent",
169 "Don't emit notify for dropped and duplicated frames", DEFAULT_SILENT,
170 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
172 * GstAudioRate:tolerance:
174 * The difference between incoming timestamp and next timestamp must exceed
175 * the given value for audiorate to add or drop samples.
177 g_object_class_install_property (object_class, PROP_TOLERANCE,
178 g_param_spec_uint64 ("tolerance", "tolerance",
179 "Only act if timestamp jitter/imperfection exceeds indicated tolerance (ns)",
180 0, G_MAXUINT64, DEFAULT_TOLERANCE,
181 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
184 * GstAudioRate:skip-to-first:
186 * Don't produce buffers before the first one we receive.
188 g_object_class_install_property (object_class, PROP_SKIP_TO_FIRST,
189 g_param_spec_boolean ("skip-to-first", "Skip to first buffer",
190 "Don't produce buffers before the first one we receive",
191 DEFAULT_SKIP_TO_FIRST, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
193 gst_element_class_set_static_metadata (element_class,
194 "Audio rate adjuster", "Filter/Effect/Audio",
195 "Drops/duplicates/adjusts timestamps on audio samples to make a perfect stream",
196 "Wim Taymans <wim@fluendo.com>");
198 gst_element_class_add_static_pad_template (element_class,
199 &gst_audio_rate_sink_template);
200 gst_element_class_add_static_pad_template (element_class,
201 &gst_audio_rate_src_template);
203 element_class->change_state = gst_audio_rate_change_state;
207 gst_audio_rate_reset (GstAudioRate * audiorate)
209 audiorate->next_offset = -1;
210 audiorate->next_ts = -1;
211 audiorate->discont = TRUE;
212 gst_segment_init (&audiorate->sink_segment, GST_FORMAT_UNDEFINED);
213 gst_segment_init (&audiorate->src_segment, GST_FORMAT_TIME);
215 GST_DEBUG_OBJECT (audiorate, "handle reset");
219 gst_audio_rate_setcaps (GstAudioRate * audiorate, GstCaps * caps)
224 if (!gst_audio_info_from_caps (&info, caps))
227 prev_rate = audiorate->info.rate;
228 audiorate->info = info;
230 if (audiorate->next_offset >= 0 && prev_rate > 0 && prev_rate != info.rate) {
231 GST_DEBUG_OBJECT (audiorate,
232 "rate changed from %d to %d", prev_rate, info.rate);
234 /* calculate next_offset based on new rate value */
235 audiorate->next_offset =
236 gst_util_uint64_scale_int_round (audiorate->next_ts,
237 info.rate, GST_SECOND);
245 GST_DEBUG_OBJECT (audiorate, "could not parse caps");
251 gst_audio_rate_init (GstAudioRate * audiorate)
254 gst_pad_new_from_static_template (&gst_audio_rate_sink_template, "sink");
255 gst_pad_set_event_function (audiorate->sinkpad, gst_audio_rate_sink_event);
256 gst_pad_set_chain_function (audiorate->sinkpad, gst_audio_rate_chain);
257 GST_PAD_SET_PROXY_CAPS (audiorate->sinkpad);
258 gst_element_add_pad (GST_ELEMENT (audiorate), audiorate->sinkpad);
261 gst_pad_new_from_static_template (&gst_audio_rate_src_template, "src");
262 gst_pad_set_event_function (audiorate->srcpad, gst_audio_rate_src_event);
263 GST_PAD_SET_PROXY_CAPS (audiorate->srcpad);
264 gst_element_add_pad (GST_ELEMENT (audiorate), audiorate->srcpad);
270 audiorate->silent = DEFAULT_SILENT;
271 audiorate->tolerance = DEFAULT_TOLERANCE;
275 gst_audio_rate_fill_to_time (GstAudioRate * audiorate, GstClockTime time)
279 GST_DEBUG_OBJECT (audiorate, "next_ts: %" GST_TIME_FORMAT
280 ", filling to %" GST_TIME_FORMAT, GST_TIME_ARGS (audiorate->next_ts),
281 GST_TIME_ARGS (time));
283 if (!GST_CLOCK_TIME_IS_VALID (time) ||
284 !GST_CLOCK_TIME_IS_VALID (audiorate->next_ts))
287 /* feed an empty buffer to chain with the given timestamp,
288 * it will take care of filling */
289 buf = gst_buffer_new ();
290 GST_BUFFER_TIMESTAMP (buf) = time;
291 gst_audio_rate_chain (audiorate->sinkpad, GST_OBJECT_CAST (audiorate), buf);
295 gst_audio_rate_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
298 GstAudioRate *audiorate;
300 audiorate = GST_AUDIO_RATE (parent);
302 switch (GST_EVENT_TYPE (event)) {
307 gst_event_parse_caps (event, &caps);
308 if ((res = gst_audio_rate_setcaps (audiorate, caps))) {
309 res = gst_pad_push_event (audiorate->srcpad, event);
311 gst_event_unref (event);
315 case GST_EVENT_FLUSH_STOP:
316 GST_DEBUG_OBJECT (audiorate, "handling FLUSH_STOP");
317 gst_audio_rate_reset (audiorate);
318 res = gst_pad_push_event (audiorate->srcpad, event);
320 case GST_EVENT_SEGMENT:
322 gst_event_copy_segment (event, &audiorate->sink_segment);
324 GST_DEBUG_OBJECT (audiorate, "handle NEWSEGMENT");
326 /* FIXME: bad things will likely happen if rate < 0 ... */
328 /* a new segment starts. We need to figure out what will be the next
329 * sample offset. We mark the offsets as invalid so that the _chain
330 * function will perform this calculation. */
331 gst_audio_rate_fill_to_time (audiorate, audiorate->src_segment.stop);
333 audiorate->next_offset = -1;
334 audiorate->next_ts = -1;
337 gst_audio_rate_fill_to_time (audiorate, audiorate->src_segment.start);
341 GST_DEBUG_OBJECT (audiorate, "updated segment: %" GST_SEGMENT_FORMAT,
342 &audiorate->sink_segment);
344 if (audiorate->sink_segment.format == GST_FORMAT_TIME) {
345 /* TIME formats can be copied to src and forwarded */
346 res = gst_pad_push_event (audiorate->srcpad, event);
347 gst_segment_copy_into (&audiorate->sink_segment,
348 &audiorate->src_segment);
350 /* other formats will be handled in the _chain function */
351 gst_event_unref (event);
357 /* Fill segment until the end */
358 if (GST_CLOCK_TIME_IS_VALID (audiorate->src_segment.stop))
359 gst_audio_rate_fill_to_time (audiorate, audiorate->src_segment.stop);
360 res = gst_pad_push_event (audiorate->srcpad, event);
364 /* Fill until end of gap */
365 GstClockTime timestamp, duration;
366 gst_event_parse_gap (event, ×tamp, &duration);
367 gst_event_unref (event);
368 if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
369 if (GST_CLOCK_TIME_IS_VALID (duration))
370 timestamp += duration;
371 gst_audio_rate_fill_to_time (audiorate, timestamp);
377 res = gst_pad_event_default (pad, parent, event);
385 gst_audio_rate_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
388 GstAudioRate *audiorate;
390 audiorate = GST_AUDIO_RATE (parent);
392 switch (GST_EVENT_TYPE (event)) {
394 res = gst_pad_push_event (audiorate->sinkpad, event);
402 gst_audio_rate_convert (GstAudioRate * audiorate,
403 GstFormat src_fmt, guint64 src_val, GstFormat dest_fmt, guint64 * dest_val)
405 return gst_audio_info_convert (&audiorate->info, src_fmt, src_val, dest_fmt,
406 (gint64 *) dest_val);
411 gst_audio_rate_convert_segments (GstAudioRate * audiorate)
413 GstFormat src_fmt, dst_fmt;
415 src_fmt = audiorate->sink_segment.format;
416 dst_fmt = audiorate->src_segment.format;
418 #define CONVERT_VAL(field) gst_audio_rate_convert (audiorate, \
419 src_fmt, audiorate->sink_segment.field, \
420 dst_fmt, &audiorate->src_segment.field);
422 audiorate->sink_segment.rate = audiorate->src_segment.rate;
423 audiorate->sink_segment.flags = audiorate->src_segment.flags;
424 audiorate->sink_segment.applied_rate = audiorate->src_segment.applied_rate;
429 CONVERT_VAL (position);
436 gst_audio_rate_notify_drop (GstAudioRate * audiorate)
438 g_object_notify_by_pspec ((GObject *) audiorate, pspec_drop);
442 gst_audio_rate_notify_add (GstAudioRate * audiorate)
444 g_object_notify_by_pspec ((GObject *) audiorate, pspec_add);
448 gst_audio_rate_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
450 GstAudioRate *audiorate;
451 GstClockTime in_time;
452 guint64 in_offset, in_offset_end, in_samples;
454 GstFlowReturn ret = GST_FLOW_OK;
455 GstClockTimeDiff diff;
459 audiorate = GST_AUDIO_RATE (parent);
461 rate = GST_AUDIO_INFO_RATE (&audiorate->info);
462 bpf = GST_AUDIO_INFO_BPF (&audiorate->info);
464 /* need to be negotiated now */
468 /* we have a new pending segment */
469 if (audiorate->next_offset == -1) {
472 /* update the TIME segment */
473 gst_audio_rate_convert_segments (audiorate);
475 /* first buffer, we are negotiated and we have a segment, calculate the
476 * current expected offsets based on the segment.start, which is the first
477 * media time of the segment and should match the media time of the first
478 * buffer in that segment, which is the offset expressed in DEFAULT units.
480 /* convert first timestamp of segment to sample position */
481 pos = gst_util_uint64_scale_int_round (audiorate->src_segment.start,
482 GST_AUDIO_INFO_RATE (&audiorate->info), GST_SECOND);
484 GST_DEBUG_OBJECT (audiorate, "resync to offset %" G_GINT64_FORMAT, pos);
486 /* resyncing is a discont */
487 audiorate->discont = TRUE;
489 audiorate->next_offset = pos;
491 gst_util_uint64_scale_int_round (audiorate->next_offset, GST_SECOND,
492 GST_AUDIO_INFO_RATE (&audiorate->info));
494 if (audiorate->skip_to_first && GST_BUFFER_TIMESTAMP_IS_VALID (buf)) {
495 GST_DEBUG_OBJECT (audiorate, "but skipping to first buffer instead");
496 pos = gst_util_uint64_scale_int_round (GST_BUFFER_TIMESTAMP (buf),
497 GST_AUDIO_INFO_RATE (&audiorate->info), GST_SECOND);
498 GST_DEBUG_OBJECT (audiorate, "so resync to offset %" G_GINT64_FORMAT,
500 audiorate->next_offset = pos;
501 audiorate->next_ts = GST_BUFFER_TIMESTAMP (buf);
505 in_time = GST_BUFFER_TIMESTAMP (buf);
506 if (in_time == GST_CLOCK_TIME_NONE) {
507 GST_DEBUG_OBJECT (audiorate, "no timestamp, using expected next time");
508 in_time = audiorate->next_ts;
511 meta = gst_buffer_get_audio_meta (buf);
512 in_size = gst_buffer_get_size (buf);
513 in_samples = meta ? meta->samples : in_size / bpf;
514 audiorate->in += in_samples;
516 /* calculate the buffer offset */
517 in_offset = gst_util_uint64_scale_int_round (in_time, rate, GST_SECOND);
518 in_offset_end = in_offset + in_samples;
520 GST_LOG_OBJECT (audiorate,
521 "in_time:%" GST_TIME_FORMAT ", in_duration:%" GST_TIME_FORMAT
522 ", in_size:%u, in_offset:%" G_GUINT64_FORMAT ", in_offset_end:%"
523 G_GUINT64_FORMAT ", ->next_offset:%" G_GUINT64_FORMAT ", ->next_ts:%"
524 GST_TIME_FORMAT, GST_TIME_ARGS (in_time),
525 GST_TIME_ARGS (GST_FRAMES_TO_CLOCK_TIME (in_samples, rate)),
526 in_size, in_offset, in_offset_end, audiorate->next_offset,
527 GST_TIME_ARGS (audiorate->next_ts));
529 diff = in_time - audiorate->next_ts;
530 if (diff <= (GstClockTimeDiff) audiorate->tolerance &&
531 diff >= (GstClockTimeDiff) - audiorate->tolerance) {
532 /* buffer time close enough to expected time,
533 * so produce a perfect stream by simply 'shifting'
534 * it to next ts and offset and sending */
535 GST_LOG_OBJECT (audiorate, "within tolerance %" GST_TIME_FORMAT,
536 GST_TIME_ARGS (audiorate->tolerance));
537 /* The outgoing buffer's offset will be set to ->next_offset, we also
538 * need to adjust the offset_end value accordingly */
539 in_offset_end = audiorate->next_offset + in_samples;
540 audiorate->out += in_samples;
544 /* do we need to insert samples */
545 if (in_offset > audiorate->next_offset) {
550 /* We don't want to allocate a single unreasonably huge buffer - it might
551 be hundreds of megabytes. So, limit each output buffer to one second of
553 fillsamples = in_offset - audiorate->next_offset;
555 while (fillsamples > 0) {
556 guint64 cursamples = MIN (fillsamples, rate);
559 fillsamples -= cursamples;
560 fillsize = cursamples * bpf;
562 fill = gst_buffer_new_and_alloc (fillsize);
564 gst_buffer_map (fill, &fillmap, GST_MAP_WRITE);
565 gst_audio_format_info_fill_silence (audiorate->info.finfo, fillmap.data,
567 gst_buffer_unmap (fill, &fillmap);
569 if (audiorate->info.layout == GST_AUDIO_LAYOUT_NON_INTERLEAVED) {
570 gst_buffer_add_audio_meta (fill, &audiorate->info, cursamples, NULL);
573 GST_DEBUG_OBJECT (audiorate, "inserting %" G_GUINT64_FORMAT " samples",
576 GST_BUFFER_OFFSET (fill) = audiorate->next_offset;
577 audiorate->next_offset += cursamples;
578 GST_BUFFER_OFFSET_END (fill) = audiorate->next_offset;
580 /* Use next timestamp, then calculate following timestamp based on
581 * offset to get duration. Necessary complexity to get 'perfect'
583 GST_BUFFER_TIMESTAMP (fill) = audiorate->next_ts;
585 gst_util_uint64_scale_int_round (audiorate->next_offset, GST_SECOND,
587 GST_BUFFER_DURATION (fill) =
588 audiorate->next_ts - GST_BUFFER_TIMESTAMP (fill);
590 /* we created this buffer to fill a gap */
591 GST_BUFFER_FLAG_SET (fill, GST_BUFFER_FLAG_GAP);
592 /* set discont if it's pending, this is mostly done for the first buffer
593 * and after a flushing seek */
594 if (audiorate->discont) {
595 GST_BUFFER_FLAG_SET (fill, GST_BUFFER_FLAG_DISCONT);
596 audiorate->discont = FALSE;
599 fill = gst_audio_buffer_clip (fill, &audiorate->src_segment, rate, bpf);
601 ret = gst_pad_push (audiorate->srcpad, fill);
603 if (ret != GST_FLOW_OK)
605 audiorate->out += cursamples;
606 audiorate->add += cursamples;
608 if (!audiorate->silent)
609 gst_audio_rate_notify_add (audiorate);
612 } else if (in_offset < audiorate->next_offset) {
613 /* need to remove samples */
614 if (in_offset_end <= audiorate->next_offset) {
615 guint64 drop = in_samples;
617 audiorate->drop += drop;
619 GST_DEBUG_OBJECT (audiorate, "dropping %" G_GUINT64_FORMAT " samples",
622 /* we can drop the buffer completely */
623 gst_buffer_unref (buf);
626 if (!audiorate->silent)
627 gst_audio_rate_notify_drop (audiorate);
631 guint64 truncsamples, leftsamples;
633 /* truncate buffer */
634 truncsamples = audiorate->next_offset - in_offset;
635 leftsamples = in_samples - truncsamples;
637 buf = gst_audio_buffer_truncate (buf, bpf, truncsamples, leftsamples);
639 audiorate->drop += truncsamples;
640 audiorate->out += leftsamples;
641 GST_DEBUG_OBJECT (audiorate, "truncating %" G_GUINT64_FORMAT " samples",
644 if (!audiorate->silent)
645 gst_audio_rate_notify_drop (audiorate);
650 if (gst_buffer_get_size (buf) == 0)
653 buf = gst_buffer_make_writable (buf);
655 /* Now calculate parameters for whichever buffer (either the original
656 * or truncated one) we're pushing. */
657 GST_BUFFER_OFFSET (buf) = audiorate->next_offset;
658 GST_BUFFER_OFFSET_END (buf) = in_offset_end;
660 GST_BUFFER_TIMESTAMP (buf) = audiorate->next_ts;
661 audiorate->next_ts = gst_util_uint64_scale_int_round (in_offset_end,
663 GST_BUFFER_DURATION (buf) = audiorate->next_ts - GST_BUFFER_TIMESTAMP (buf);
665 if (audiorate->discont) {
666 /* we need to output a discont buffer, do so now */
667 GST_DEBUG_OBJECT (audiorate, "marking DISCONT on output buffer");
668 GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
669 audiorate->discont = FALSE;
670 } else if (GST_BUFFER_IS_DISCONT (buf)) {
671 /* else we make everything continuous so we can safely remove the DISCONT
672 * flag from the buffer if there was one */
673 GST_DEBUG_OBJECT (audiorate, "removing DISCONT from buffer");
674 GST_BUFFER_FLAG_UNSET (buf, GST_BUFFER_FLAG_DISCONT);
677 buf = gst_audio_buffer_clip (buf, &audiorate->src_segment, rate, bpf);
679 /* set last_stop on segment */
680 audiorate->src_segment.position =
681 GST_BUFFER_TIMESTAMP (buf) + GST_BUFFER_DURATION (buf);
683 ret = gst_pad_push (audiorate->srcpad, buf);
687 audiorate->next_offset = in_offset_end;
691 gst_buffer_unref (buf);
698 gst_buffer_unref (buf);
700 GST_ELEMENT_ERROR (audiorate, STREAM, FORMAT,
701 (NULL), ("pipeline error, format was not negotiated"));
702 return GST_FLOW_NOT_NEGOTIATED;
707 gst_audio_rate_set_property (GObject * object,
708 guint prop_id, const GValue * value, GParamSpec * pspec)
710 GstAudioRate *audiorate = GST_AUDIO_RATE (object);
714 audiorate->silent = g_value_get_boolean (value);
717 audiorate->tolerance = g_value_get_uint64 (value);
719 case PROP_SKIP_TO_FIRST:
720 audiorate->skip_to_first = g_value_get_boolean (value);
723 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
729 gst_audio_rate_get_property (GObject * object,
730 guint prop_id, GValue * value, GParamSpec * pspec)
732 GstAudioRate *audiorate = GST_AUDIO_RATE (object);
736 g_value_set_uint64 (value, audiorate->in);
739 g_value_set_uint64 (value, audiorate->out);
742 g_value_set_uint64 (value, audiorate->add);
745 g_value_set_uint64 (value, audiorate->drop);
748 g_value_set_boolean (value, audiorate->silent);
751 g_value_set_uint64 (value, audiorate->tolerance);
753 case PROP_SKIP_TO_FIRST:
754 g_value_set_boolean (value, audiorate->skip_to_first);
757 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
762 static GstStateChangeReturn
763 gst_audio_rate_change_state (GstElement * element, GstStateChange transition)
765 GstAudioRate *audiorate = GST_AUDIO_RATE (element);
767 switch (transition) {
768 case GST_STATE_CHANGE_PAUSED_TO_READY:
770 case GST_STATE_CHANGE_READY_TO_PAUSED:
775 gst_audio_info_init (&audiorate->info);
776 gst_audio_rate_reset (audiorate);
782 return GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
786 plugin_init (GstPlugin * plugin)
788 return GST_ELEMENT_REGISTER (audiorate, plugin);
791 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
794 "Adjusts audio frames",
795 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)