• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* -*- c-basic-offset: 2 -*-
2  * GStreamer
3  * Copyright (C) 1999-2001 Erik Walthinsen <omega@cse.ogi.edu>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 /**
22  * SECTION:element-speed
23  * @title: speed
24  *
25  * Plays an audio stream at a different speed (by resampling the audio).
26  *
27  * Do not use this element. Either use the 'pitch' element, or do a seek with
28  * a non-1.0 rate parameter, this will have the same effect as using the speed
29  * element (but relies on the decoder/demuxer to handle this correctly, also
30  * requires a fairly up-to-date gst-plugins-base, as of February 2007).
31  *
32  * ## Example launch line
33  * |[
34  * gst-launch-1.0 filesrc location=test.ogg ! decodebin ! audioconvert ! speed speed=1.5 ! audioconvert ! audioresample ! autoaudiosink
35  * ]| Plays an .ogg file at 1.5x speed.
36  *
37  */
38 
39 #ifdef HAVE_CONFIG_H
40 #  include "config.h"
41 #endif
42 
43 #include <string.h>
44 #include <math.h>
45 #include <gst/gst.h>
46 #include <gst/audio/audio.h>
47 
48 #include "gstspeed.h"
49 
50 GST_DEBUG_CATEGORY_STATIC (speed_debug);
51 #define GST_CAT_DEFAULT speed_debug
52 
53 enum
54 {
55   PROP_0,
56   PROP_SPEED
57 };
58 
59 /* assumption here: sizeof (gfloat) = 4 */
60 #define GST_SPEED_AUDIO_CAPS \
61   "audio/x-raw, " \
62     "format = {" GST_AUDIO_NE (F32) ", " GST_AUDIO_NE (S16) "}, " \
63     "rate = (int) [ 1, MAX ], " \
64     "channels = (int) [ 1, MAX ]"
65 
66 static GstStaticPadTemplate gst_speed_sink_template =
67 GST_STATIC_PAD_TEMPLATE ("sink",
68     GST_PAD_SINK,
69     GST_PAD_ALWAYS,
70     GST_STATIC_CAPS (GST_SPEED_AUDIO_CAPS)
71     );
72 
73 static GstStaticPadTemplate gst_speed_src_template =
74 GST_STATIC_PAD_TEMPLATE ("src",
75     GST_PAD_SRC,
76     GST_PAD_ALWAYS,
77     GST_STATIC_CAPS (GST_SPEED_AUDIO_CAPS)
78     );
79 
80 static void speed_set_property (GObject * object, guint prop_id,
81     const GValue * value, GParamSpec * pspec);
82 static void speed_get_property (GObject * object, guint prop_id, GValue * value,
83     GParamSpec * pspec);
84 
85 static gboolean speed_parse_caps (GstSpeed * filter, const GstCaps * caps);
86 
87 static GstFlowReturn speed_chain (GstPad * pad, GstObject * parent,
88     GstBuffer * buf);
89 
90 static GstStateChangeReturn speed_change_state (GstElement * element,
91     GstStateChange transition);
92 static gboolean speed_sink_event (GstPad * pad, GstObject * parent,
93     GstEvent * event);
94 static gboolean speed_src_event (GstPad * pad, GstObject * parent,
95     GstEvent * event);
96 
97 G_DEFINE_TYPE (GstSpeed, gst_speed, GST_TYPE_ELEMENT);
98 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (speed, "speed", GST_RANK_NONE,
99     GST_TYPE_SPEED, GST_DEBUG_CATEGORY_INIT (speed_debug, "speed", 0,
100         "speed element");
101     );
102 
103 static gboolean
speed_setcaps(GstPad * pad,GstCaps * caps)104 speed_setcaps (GstPad * pad, GstCaps * caps)
105 {
106   GstSpeed *filter;
107   gboolean ret;
108 
109   filter = GST_SPEED (gst_pad_get_parent (pad));
110 
111   ret = speed_parse_caps (filter, caps);
112 
113   gst_object_unref (filter);
114 
115   return ret;
116 }
117 
118 static gboolean
speed_parse_caps(GstSpeed * filter,const GstCaps * caps)119 speed_parse_caps (GstSpeed * filter, const GstCaps * caps)
120 {
121   g_return_val_if_fail (filter != NULL, FALSE);
122   g_return_val_if_fail (caps != NULL, FALSE);
123 
124   if (!gst_audio_info_from_caps (&filter->info, caps))
125     return FALSE;
126 
127 
128   return TRUE;
129 }
130 
131 static gboolean
speed_src_event(GstPad * pad,GstObject * parent,GstEvent * event)132 speed_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
133 {
134   GstSpeed *filter;
135   gboolean ret = FALSE;
136 
137   filter = GST_SPEED (parent);
138 
139   switch (GST_EVENT_TYPE (event)) {
140     case GST_EVENT_SEEK:{
141       gdouble rate;
142       GstFormat format;
143       GstSeekFlags flags;
144       GstSeekType start_type, stop_type;
145       gint64 start, stop;
146 
147       gst_event_parse_seek (event, &rate, &format, &flags, &start_type, &start,
148           &stop_type, &stop);
149       gst_event_unref (event);
150 
151       if (format != GST_FORMAT_TIME) {
152         GST_DEBUG_OBJECT (filter, "only support seeks in TIME format");
153         break;
154       }
155 
156       if (start_type != GST_SEEK_TYPE_NONE && start != -1) {
157         start *= filter->speed;
158       }
159 
160       if (stop_type != GST_SEEK_TYPE_NONE && stop != -1) {
161         stop *= filter->speed;
162       }
163 
164       event = gst_event_new_seek (rate, format, flags, start_type, start,
165           stop_type, stop);
166 
167       GST_LOG ("sending seek event: %" GST_PTR_FORMAT,
168           gst_event_get_structure (event));
169 
170       ret = gst_pad_send_event (GST_PAD_PEER (filter->sinkpad), event);
171       break;
172     }
173     default:
174       ret = gst_pad_event_default (pad, parent, event);
175       break;
176   }
177 
178   return ret;
179 }
180 
181 static gboolean
gst_speed_convert(GstSpeed * filter,GstFormat src_format,gint64 src_value,GstFormat * dest_format,gint64 * dest_value)182 gst_speed_convert (GstSpeed * filter, GstFormat src_format, gint64 src_value,
183     GstFormat * dest_format, gint64 * dest_value)
184 {
185   gboolean ret = TRUE;
186   guint scale = 1;
187 
188   if (src_format == *dest_format) {
189     *dest_value = src_value;
190     return TRUE;
191   }
192 
193   switch (src_format) {
194     case GST_FORMAT_BYTES:
195       switch (*dest_format) {
196         case GST_FORMAT_DEFAULT:
197           if (GST_AUDIO_INFO_BPF (&filter->info) == 0) {
198             ret = FALSE;
199             break;
200           }
201           *dest_value = src_value / GST_AUDIO_INFO_BPF (&filter->info);
202           break;
203         case GST_FORMAT_TIME:
204         {
205           gint byterate =
206               GST_AUDIO_INFO_BPF (&filter->info) *
207               GST_AUDIO_INFO_RATE (&filter->info);
208 
209           if (byterate == 0) {
210             ret = FALSE;
211             break;
212           }
213           *dest_value = src_value * GST_SECOND / byterate;
214           break;
215         }
216         default:
217           ret = FALSE;
218       }
219       break;
220     case GST_FORMAT_DEFAULT:
221       switch (*dest_format) {
222         case GST_FORMAT_BYTES:
223           *dest_value = src_value * GST_AUDIO_INFO_BPF (&filter->info);
224           break;
225         case GST_FORMAT_TIME:
226           if (GST_AUDIO_INFO_RATE (&filter->info) == 0) {
227             ret = FALSE;
228             break;
229           }
230           *dest_value =
231               src_value * GST_SECOND / GST_AUDIO_INFO_RATE (&filter->info);
232           break;
233         default:
234           ret = FALSE;
235       }
236       break;
237     case GST_FORMAT_TIME:
238       switch (*dest_format) {
239         case GST_FORMAT_BYTES:
240           scale = GST_AUDIO_INFO_BPF (&filter->info);
241           /* fallthrough */
242         case GST_FORMAT_DEFAULT:
243           *dest_value =
244               src_value * scale * GST_AUDIO_INFO_RATE (&filter->info) /
245               GST_SECOND;
246           break;
247         default:
248           ret = FALSE;
249       }
250       break;
251     default:
252       ret = FALSE;
253   }
254 
255   return ret;
256 
257 }
258 
259 static gboolean
speed_src_query(GstPad * pad,GstObject * parent,GstQuery * query)260 speed_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
261 {
262   gboolean ret = TRUE;
263   GstSpeed *filter;
264 
265   filter = GST_SPEED (parent);
266 
267   switch (GST_QUERY_TYPE (query)) {
268     case GST_QUERY_POSITION:
269     {
270       GstFormat format;
271       GstFormat rformat = GST_FORMAT_TIME;
272       gint64 cur;
273       GstFormat conv_format = GST_FORMAT_TIME;
274 
275       /* save requested format */
276       gst_query_parse_position (query, &format, NULL);
277 
278       /* query peer for current position in time */
279       gst_query_set_position (query, GST_FORMAT_TIME, -1);
280 
281       if (!gst_pad_peer_query_position (filter->sinkpad, rformat, &cur)) {
282         GST_LOG_OBJECT (filter, "TIME query on peer pad failed, trying BYTES");
283         rformat = GST_FORMAT_BYTES;
284         if (!gst_pad_peer_query_position (filter->sinkpad, rformat, &cur)) {
285           GST_LOG_OBJECT (filter, "BYTES query on peer pad failed too");
286           goto error;
287         }
288       }
289 
290       if (rformat == GST_FORMAT_BYTES)
291         GST_LOG_OBJECT (filter,
292             "peer pad returned current=%" G_GINT64_FORMAT " bytes", cur);
293       else if (rformat == GST_FORMAT_TIME)
294         GST_LOG_OBJECT (filter, "peer pad returned time=%" G_GINT64_FORMAT,
295             cur);
296 
297       /* convert to time format */
298       if (!gst_speed_convert (filter, rformat, cur, &conv_format, &cur)) {
299         ret = FALSE;
300         break;
301       }
302 
303       /* adjust for speed factor */
304       cur /= filter->speed;
305 
306       /* convert to time format */
307       if (!gst_speed_convert (filter, conv_format, cur, &format, &cur)) {
308         ret = FALSE;
309         break;
310       }
311       gst_query_set_position (query, format, cur);
312 
313       GST_LOG_OBJECT (filter,
314           "position query: we return %" G_GUINT64_FORMAT " (format %u)", cur,
315           format);
316 
317       break;
318     }
319     case GST_QUERY_DURATION:
320     {
321       GstFormat format;
322       GstFormat rformat = GST_FORMAT_TIME;
323       gint64 end;
324       GstFormat conv_format = GST_FORMAT_TIME;
325 
326       /* save requested format */
327       gst_query_parse_duration (query, &format, NULL);
328 
329       /* query peer for total length in time */
330       gst_query_set_duration (query, GST_FORMAT_TIME, -1);
331 
332       if (!gst_pad_peer_query_duration (filter->sinkpad, rformat, &end)) {
333         GST_LOG_OBJECT (filter, "TIME query on peer pad failed, trying BYTES");
334         rformat = GST_FORMAT_BYTES;
335         if (!gst_pad_peer_query_duration (filter->sinkpad, rformat, &end)) {
336           GST_LOG_OBJECT (filter, "BYTES query on peer pad failed too");
337           goto error;
338         }
339       }
340 
341       if (rformat == GST_FORMAT_BYTES)
342         GST_LOG_OBJECT (filter,
343             "peer pad returned total=%" G_GINT64_FORMAT " bytes", end);
344       else if (rformat == GST_FORMAT_TIME)
345         GST_LOG_OBJECT (filter, "peer pad returned time=%" G_GINT64_FORMAT,
346             end);
347 
348       /* convert to time format */
349       if (!gst_speed_convert (filter, rformat, end, &conv_format, &end)) {
350         ret = FALSE;
351         break;
352       }
353 
354       /* adjust for speed factor */
355       end /= filter->speed;
356 
357       /* convert to time format */
358       if (!gst_speed_convert (filter, conv_format, end, &format, &end)) {
359         ret = FALSE;
360         break;
361       }
362 
363       gst_query_set_duration (query, format, end);
364 
365       GST_LOG_OBJECT (filter,
366           "duration query: we return %" G_GUINT64_FORMAT " (format %u)", end,
367           format);
368 
369       break;
370     }
371     default:
372       ret = FALSE;
373       break;
374   }
375 
376   return ret;
377 
378 error:
379 
380   gst_object_unref (filter);
381   GST_DEBUG ("error handling query");
382   return FALSE;
383 }
384 
385 static void
gst_speed_class_init(GstSpeedClass * klass)386 gst_speed_class_init (GstSpeedClass * klass)
387 {
388   GObjectClass *gobject_class = (GObjectClass *) klass;
389   GstElementClass *gstelement_class = (GstElementClass *) klass;
390 
391   gobject_class->set_property = speed_set_property;
392   gobject_class->get_property = speed_get_property;
393   gstelement_class->change_state = speed_change_state;
394 
395   g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SPEED,
396       g_param_spec_float ("speed", "speed", "speed",
397           0.1f, 40.0, 1.0,
398           G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
399 
400   gst_element_class_set_static_metadata (gstelement_class, "Speed",
401       "Filter/Effect/Audio",
402       "Set speed/pitch on audio/raw streams (resampler)",
403       "Andy Wingo <apwingo@eos.ncsu.edu>, "
404       "Tim-Philipp Müller <tim@centricular.net>");
405 
406   gst_element_class_add_static_pad_template (gstelement_class,
407       &gst_speed_src_template);
408   gst_element_class_add_static_pad_template (gstelement_class,
409       &gst_speed_sink_template);
410 }
411 
412 static void
gst_speed_init(GstSpeed * filter)413 gst_speed_init (GstSpeed * filter)
414 {
415   filter->sinkpad =
416       gst_pad_new_from_static_template (&gst_speed_sink_template, "sink");
417   gst_pad_set_chain_function (filter->sinkpad, speed_chain);
418   gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
419   gst_pad_set_event_function (filter->sinkpad, speed_sink_event);
420   GST_PAD_SET_PROXY_CAPS (filter->sinkpad);
421 
422   filter->srcpad =
423       gst_pad_new_from_static_template (&gst_speed_src_template, "src");
424   gst_pad_set_query_function (filter->srcpad, speed_src_query);
425   gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
426   gst_pad_set_event_function (filter->srcpad, speed_src_event);
427   GST_PAD_SET_PROXY_CAPS (filter->srcpad);
428 
429   filter->offset = 0;
430   filter->timestamp = 0;
431 }
432 
433 static inline guint
speed_chain_int16(GstSpeed * filter,GstBuffer * in_buf,GstBuffer * out_buf,guint c,guint in_samples)434 speed_chain_int16 (GstSpeed * filter, GstBuffer * in_buf, GstBuffer * out_buf,
435     guint c, guint in_samples)
436 {
437   gint16 *in_data, *out_data;
438   gfloat interp, lower, i_float;
439   guint i, j;
440   GstMapInfo in_info, out_info;
441 
442   gst_buffer_map (in_buf, &in_info, GST_MAP_READ);
443   gst_buffer_map (out_buf, &out_info, GST_MAP_WRITE);
444 
445   in_data = (gint16 *) in_info.data + c;
446   out_data = (gint16 *) out_info.data + c;
447 
448   lower = in_data[0];
449   i_float = 0.5 * (filter->speed - 1.0);
450   i = (guint) ceil (i_float);
451   j = 0;
452 
453   while (i < in_samples) {
454     interp = i_float - floor (i_float);
455 
456     out_data[j * GST_AUDIO_INFO_CHANNELS (&filter->info)] =
457         lower * (1 - interp) +
458         in_data[i * GST_AUDIO_INFO_CHANNELS (&filter->info)] * interp;
459 
460     lower = in_data[i * GST_AUDIO_INFO_CHANNELS (&filter->info)];
461 
462     i_float += filter->speed;
463     i = (guint) ceil (i_float);
464 
465     ++j;
466   }
467 
468   gst_buffer_unmap (in_buf, &in_info);
469   gst_buffer_unmap (out_buf, &out_info);
470   return j;
471 }
472 
473 static inline guint
speed_chain_float32(GstSpeed * filter,GstBuffer * in_buf,GstBuffer * out_buf,guint c,guint in_samples)474 speed_chain_float32 (GstSpeed * filter, GstBuffer * in_buf, GstBuffer * out_buf,
475     guint c, guint in_samples)
476 {
477   gfloat *in_data, *out_data;
478   gfloat interp, lower, i_float;
479   guint i, j;
480   GstMapInfo in_info, out_info;
481 
482   gst_buffer_map (in_buf, &in_info, GST_MAP_WRITE);
483   gst_buffer_map (out_buf, &out_info, GST_MAP_WRITE);
484 
485   in_data = (gfloat *) in_info.data + c;
486   out_data = (gfloat *) out_info.data + c;
487 
488   lower = in_data[0];
489   i_float = 0.5 * (filter->speed - 1.0);
490   i = (guint) ceil (i_float);
491   j = 0;
492 
493   while (i < in_samples) {
494     interp = i_float - floor (i_float);
495 
496     out_data[j * GST_AUDIO_INFO_CHANNELS (&filter->info)] =
497         lower * (1 - interp) +
498         in_data[i * GST_AUDIO_INFO_CHANNELS (&filter->info)] * interp;
499 
500     lower = in_data[i * GST_AUDIO_INFO_CHANNELS (&filter->info)];
501 
502     i_float += filter->speed;
503     i = (guint) ceil (i_float);
504 
505     ++j;
506   }
507   gst_buffer_unmap (in_buf, &in_info);
508   gst_buffer_unmap (out_buf, &out_info);
509   return j;
510 }
511 
512 
513 static gboolean
speed_sink_event(GstPad * pad,GstObject * parent,GstEvent * event)514 speed_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
515 {
516   GstSpeed *filter = GST_SPEED (parent);
517   gboolean ret = FALSE;
518 
519   switch (GST_EVENT_TYPE (event)) {
520     case GST_EVENT_SEGMENT:{
521       gdouble rate;
522       GstFormat format;
523       gint64 start_value, stop_value;
524       const GstSegment *segment;
525       GstSegment seg;
526 
527       gst_event_parse_segment (event, &segment);
528 
529       rate = segment->rate;
530       format = segment->format;
531       start_value = segment->start;
532       stop_value = segment->stop;
533 
534       gst_event_unref (event);
535 
536       if (format != GST_FORMAT_TIME) {
537         GST_WARNING_OBJECT (filter, "newsegment event not in TIME format!");
538         break;
539       }
540 
541       g_assert (filter->speed > 0);
542 
543       if (start_value >= 0)
544         start_value /= filter->speed;
545       if (stop_value >= 0)
546         stop_value /= filter->speed;
547 
548       /* this would only really be correct if we clipped incoming data */
549       filter->timestamp = start_value;
550 
551       /* set to NONE so it gets reset later based on the timestamp when we have
552        * the samplerate */
553       filter->offset = GST_BUFFER_OFFSET_NONE;
554 
555       gst_segment_init (&seg, GST_FORMAT_TIME);
556       seg.rate = rate;
557       seg.start = start_value;
558       seg.stop = stop_value;
559       seg.time = segment->time;
560       ret = gst_pad_push_event (filter->srcpad, gst_event_new_segment (&seg));
561 
562       break;
563     }
564     case GST_EVENT_CAPS:
565     {
566       GstCaps *caps;
567 
568       gst_event_parse_caps (event, &caps);
569       ret = speed_setcaps (pad, caps);
570       if (!ret) {
571         gst_event_unref (event);
572         return ret;
573       }
574     }
575       /* Fallthrough so that the caps event gets forwarded */
576     default:
577       ret = gst_pad_event_default (pad, parent, event);
578       break;
579   }
580   return ret;
581 }
582 
583 static GstFlowReturn
speed_chain(GstPad * pad,GstObject * parent,GstBuffer * in_buf)584 speed_chain (GstPad * pad, GstObject * parent, GstBuffer * in_buf)
585 {
586   GstBuffer *out_buf;
587   GstSpeed *filter = GST_SPEED (parent);
588   guint c, in_samples, out_samples, out_size;
589   GstFlowReturn flow;
590   gsize size;
591 
592   if (G_UNLIKELY (filter->offset == GST_BUFFER_OFFSET_NONE)) {
593     filter->offset = gst_util_uint64_scale_int (filter->timestamp,
594         GST_AUDIO_INFO_RATE (&filter->info), GST_SECOND);
595   }
596 
597   /* buffersize has to be aligned to a frame */
598   out_size = ceil ((gfloat) gst_buffer_get_size (in_buf) / filter->speed);
599   out_size = ((out_size + GST_AUDIO_INFO_BPF (&filter->info) - 1) /
600       GST_AUDIO_INFO_BPF (&filter->info)) * GST_AUDIO_INFO_BPF (&filter->info);
601 
602   out_buf = gst_buffer_new_and_alloc (out_size);
603 
604   in_samples = gst_buffer_get_size (in_buf) /
605       GST_AUDIO_INFO_BPF (&filter->info);
606 
607   out_samples = 0;
608 
609   for (c = 0; c < GST_AUDIO_INFO_CHANNELS (&filter->info); ++c) {
610     if (GST_AUDIO_INFO_IS_INTEGER (&filter->info))
611       out_samples = speed_chain_int16 (filter, in_buf, out_buf, c, in_samples);
612     else
613       out_samples =
614           speed_chain_float32 (filter, in_buf, out_buf, c, in_samples);
615   }
616 
617   size = out_samples * GST_AUDIO_INFO_BPF (&filter->info);
618   gst_buffer_set_size (out_buf, size);
619 
620   GST_BUFFER_OFFSET (out_buf) = filter->offset;
621   GST_BUFFER_TIMESTAMP (out_buf) = filter->timestamp;
622 
623   filter->offset += size / GST_AUDIO_INFO_BPF (&filter->info);
624   filter->timestamp = gst_util_uint64_scale_int (filter->offset, GST_SECOND,
625       GST_AUDIO_INFO_RATE (&filter->info));
626 
627   /* make sure it's at least nominally a perfect stream */
628   GST_BUFFER_DURATION (out_buf) =
629       filter->timestamp - GST_BUFFER_TIMESTAMP (out_buf);
630   flow = gst_pad_push (filter->srcpad, out_buf);
631 
632   if (G_UNLIKELY (flow != GST_FLOW_OK))
633     GST_DEBUG_OBJECT (filter, "flow: %s", gst_flow_get_name (flow));
634 
635   gst_buffer_unref (in_buf);
636   return flow;
637 }
638 
639 static void
speed_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)640 speed_set_property (GObject * object, guint prop_id, const GValue * value,
641     GParamSpec * pspec)
642 {
643   GstSpeed *filter = GST_SPEED (object);
644 
645   switch (prop_id) {
646     case PROP_SPEED:
647       filter->speed = g_value_get_float (value);
648       break;
649     default:
650       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
651       break;
652   }
653 
654 }
655 
656 static void
speed_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)657 speed_get_property (GObject * object, guint prop_id, GValue * value,
658     GParamSpec * pspec)
659 {
660   GstSpeed *filter = GST_SPEED (object);
661 
662   switch (prop_id) {
663     case PROP_SPEED:
664       g_value_set_float (value, filter->speed);
665       break;
666     default:
667       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
668       break;
669   }
670 
671 }
672 
673 static GstStateChangeReturn
speed_change_state(GstElement * element,GstStateChange transition)674 speed_change_state (GstElement * element, GstStateChange transition)
675 {
676   GstSpeed *speed = GST_SPEED (element);
677 
678   switch (transition) {
679     case GST_STATE_CHANGE_READY_TO_PAUSED:
680       speed->offset = GST_BUFFER_OFFSET_NONE;
681       speed->timestamp = 0;
682       gst_audio_info_init (&speed->info);
683       break;
684     default:
685       break;
686   }
687 
688   return GST_ELEMENT_CLASS (gst_speed_parent_class)->change_state (element,
689       transition);
690 }
691 
692 static gboolean
plugin_init(GstPlugin * plugin)693 plugin_init (GstPlugin * plugin)
694 {
695   return GST_ELEMENT_REGISTER (speed, plugin);
696 }
697 
698 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
699     GST_VERSION_MINOR,
700     speed,
701     "Set speed/pitch on audio/raw streams (resampler)",
702     plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
703