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., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
24 #include <gstflacenc.h>
26 extern GstPadTemplate *gst_flacenc_src_template, *gst_flacenc_sink_template;
28 /* elementfactory information */
29 GstElementDetails flacenc_details = {
31 "Codec/Audio/Encoder",
33 "Encodes audio with the FLAC lossless audio encoder",
35 "Wim Taymans <wim.taymans@chello.be>",
39 /* FlacEnc signals and args */
48 ARG_STREAMABLE_SUBSET,
50 ARG_LOOSE_MID_SIDE_STEREO,
53 ARG_QLP_COEFF_PRECISION,
54 ARG_QLP_COEFF_PREC_SEARCH,
56 ARG_EXHAUSTIVE_MODEL_SEARCH,
57 ARG_MIN_RESIDUAL_PARTITION_ORDER,
58 ARG_MAX_RESIDUAL_PARTITION_ORDER,
59 ARG_RICE_PARAMETER_SEARCH_DIST,
62 static void gst_flacenc_init (FlacEnc *flacenc);
63 static void gst_flacenc_class_init (FlacEncClass *klass);
64 static void gst_flacenc_dispose (GObject *object);
66 static GstPadConnectReturn
67 gst_flacenc_sinkconnect (GstPad *pad, GstCaps *caps);
68 static void gst_flacenc_chain (GstPad *pad, GstBuffer *buf);
70 static gboolean gst_flacenc_update_quality (FlacEnc *flacenc, gint quality);
71 static void gst_flacenc_set_property (GObject *object, guint prop_id,
72 const GValue *value, GParamSpec *pspec);
73 static void gst_flacenc_get_property (GObject *object, guint prop_id,
74 GValue *value, GParamSpec *pspec);
75 static GstElementStateReturn
76 gst_flacenc_change_state (GstElement *element);
78 static FLAC__StreamEncoderWriteStatus
79 gst_flacenc_write_callback (const FLAC__StreamEncoder *encoder,
80 const FLAC__byte buffer[], unsigned bytes,
81 unsigned samples, unsigned current_frame,
83 static void gst_flacenc_metadata_callback (const FLAC__StreamEncoder *encoder,
84 const FLAC__StreamMetadata *metadata,
87 static GstElementClass *parent_class = NULL;
88 /*static guint gst_flacenc_signals[LAST_SIGNAL] = { 0 }; */
91 flacenc_get_type (void)
93 static GType flacenc_type = 0;
96 static const GTypeInfo flacenc_info = {
100 (GClassInitFunc)gst_flacenc_class_init,
105 (GInstanceInitFunc)gst_flacenc_init,
107 flacenc_type = g_type_register_static (GST_TYPE_ELEMENT, "FlacEnc", &flacenc_info, 0);
113 gboolean exhaustive_model_search;
114 gboolean escape_coding;
116 gboolean loose_mid_side;
117 guint qlp_coeff_precision;
118 gboolean qlp_coeff_prec_search;
119 guint min_residual_partition_order;
120 guint max_residual_partition_order;
121 guint rice_parameter_search_dist;
126 static const FlacEncParams flacenc_params[] =
128 { FALSE, FALSE, FALSE, FALSE, 0, FALSE, 2, 2, 0, 0, 1152 },
129 { FALSE, FALSE, TRUE, TRUE, 0, FALSE, 2, 2, 0, 0, 1152 },
130 { FALSE, FALSE, TRUE, FALSE, 0, FALSE, 0, 3, 0, 0, 1152 },
131 { FALSE, FALSE, FALSE, FALSE, 0, FALSE, 3, 3, 0, 6, 4608 },
132 { FALSE, FALSE, TRUE, TRUE, 0, FALSE, 3, 3, 0, 8, 4608 },
133 { FALSE, FALSE, TRUE, FALSE, 0, FALSE, 3, 3, 0, 8, 4608 },
134 { FALSE, FALSE, TRUE, FALSE, 0, FALSE, 0, 4, 0, 8, 4608 },
135 { TRUE, FALSE, TRUE, FALSE, 0, FALSE, 0, 6, 0, 8, 4608 },
136 { TRUE, FALSE, TRUE, FALSE, 0, FALSE, 0, 6, 0, 12, 4608 },
137 { TRUE, TRUE, TRUE, FALSE, 0, FALSE, 0, 16, 0, 32, 4608 },
140 #define DEFAULT_QUALITY 5
142 #define GST_TYPE_FLACENC_QUALITY (gst_flacenc_quality_get_type ())
144 gst_flacenc_quality_get_type (void)
146 static GType qtype = 0;
148 static const GEnumValue values[] = {
149 { 0, "0", "0 - Fastest compression" },
154 { 5, "5", "5 - Default" },
157 { 8, "8", "8 - Highest compression " },
158 { 9, "9", "9 - Insane" },
161 qtype = g_enum_register_static ("FlacEncQuality", values);
167 gst_flacenc_class_init (FlacEncClass *klass)
169 GObjectClass *gobject_class;
170 GstElementClass *gstelement_class;
172 gobject_class = (GObjectClass*)klass;
173 gstelement_class = (GstElementClass*)klass;
175 parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
177 /* we have no properties atm so this is a bit silly */
178 gobject_class->set_property = gst_flacenc_set_property;
179 gobject_class->get_property = gst_flacenc_get_property;
180 gobject_class->dispose = gst_flacenc_dispose;
182 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_QUALITY,
183 g_param_spec_enum ("quality",
185 "Speed versus compression tradeoff",
186 GST_TYPE_FLACENC_QUALITY, DEFAULT_QUALITY, G_PARAM_READWRITE));
187 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_STREAMABLE_SUBSET,
188 g_param_spec_boolean ("streamable_subset",
190 "true to limit encoder to generating a Subset stream, else false",
191 TRUE, G_PARAM_READWRITE));
192 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MID_SIDE_STEREO,
193 g_param_spec_boolean ("mid_side_stereo",
194 "Do mid side stereo",
195 "Do mid side stereo (only for stereo input)",
196 flacenc_params[DEFAULT_QUALITY].mid_side, G_PARAM_READWRITE));
197 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LOOSE_MID_SIDE_STEREO,
198 g_param_spec_boolean ("loose_mid_side_stereo",
199 "Loose mid side stereo",
200 "Loose mid side stereo",
201 flacenc_params[DEFAULT_QUALITY].loose_mid_side, G_PARAM_READWRITE));
202 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_BLOCKSIZE,
203 g_param_spec_uint ("blocksize",
205 "Blocksize in samples",
206 FLAC__MIN_BLOCK_SIZE, FLAC__MAX_BLOCK_SIZE,
207 flacenc_params[DEFAULT_QUALITY].blocksize, G_PARAM_READWRITE));
208 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MAX_LPC_ORDER,
209 g_param_spec_uint ("max_lpc_order",
211 "Max LPC order; 0 => use only fixed predictors",
212 0, FLAC__MAX_LPC_ORDER,
213 flacenc_params[DEFAULT_QUALITY].max_lpc_order, G_PARAM_READWRITE));
214 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_QLP_COEFF_PRECISION,
215 g_param_spec_uint ("qlp_coeff_precision",
216 "QLP coefficients precision",
217 "Precision in bits of quantized linear-predictor coefficients; 0 = automatic",
219 flacenc_params[DEFAULT_QUALITY].qlp_coeff_precision, G_PARAM_READWRITE));
220 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_QLP_COEFF_PREC_SEARCH,
221 g_param_spec_boolean ("qlp_coeff_prec_search",
222 "Do QLP coefficients precision search",
223 "false = use qlp_coeff_precision, "
224 "true = search around qlp_coeff_precision, take best",
225 flacenc_params[DEFAULT_QUALITY].qlp_coeff_prec_search, G_PARAM_READWRITE));
226 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ESCAPE_CODING,
227 g_param_spec_boolean ("escape_coding",
229 "search for escape codes in the entropy coding stage "
230 "for slightly better compression",
231 flacenc_params[DEFAULT_QUALITY].escape_coding, G_PARAM_READWRITE));
232 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_EXHAUSTIVE_MODEL_SEARCH,
233 g_param_spec_boolean ("exhaustive_model_search",
234 "Do exhaustive model search",
235 "do exhaustive search of LP coefficient quantization (expensive!)",
236 flacenc_params[DEFAULT_QUALITY].exhaustive_model_search, G_PARAM_READWRITE));
237 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MIN_RESIDUAL_PARTITION_ORDER,
238 g_param_spec_uint ("min_residual_partition_order",
239 "Min residual partition order",
240 "Min residual partition order (above 4 doesn't usually help much)",
242 flacenc_params[DEFAULT_QUALITY].min_residual_partition_order, G_PARAM_READWRITE));
243 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MAX_RESIDUAL_PARTITION_ORDER,
244 g_param_spec_uint ("max_residual_partition_order",
245 "Max residual partition order",
246 "Max residual partition order (above 4 doesn't usually help much)",
248 flacenc_params[DEFAULT_QUALITY].max_residual_partition_order, G_PARAM_READWRITE));
249 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_RICE_PARAMETER_SEARCH_DIST,
250 g_param_spec_uint ("rice_parameter_search_dist",
251 "rice_parameter_search_dist",
252 "0 = try only calc'd parameter k; else try all [k-dist..k+dist] "
253 "parameters, use best",
254 0, FLAC__MAX_RICE_PARTITION_ORDER,
255 flacenc_params[DEFAULT_QUALITY].rice_parameter_search_dist, G_PARAM_READWRITE));
257 gstelement_class->change_state = gst_flacenc_change_state;
261 gst_flacenc_init (FlacEnc *flacenc)
263 flacenc->sinkpad = gst_pad_new_from_template (gst_flacenc_sink_template, "sink");
264 gst_element_add_pad(GST_ELEMENT(flacenc),flacenc->sinkpad);
265 gst_pad_set_chain_function(flacenc->sinkpad,gst_flacenc_chain);
266 gst_pad_set_connect_function (flacenc->sinkpad, gst_flacenc_sinkconnect);
268 flacenc->srcpad = gst_pad_new_from_template (gst_flacenc_src_template, "src");
269 gst_element_add_pad(GST_ELEMENT(flacenc),flacenc->srcpad);
271 GST_FLAG_SET (flacenc, GST_ELEMENT_EVENT_AWARE);
273 flacenc->encoder = FLAC__stream_encoder_new();
275 FLAC__stream_encoder_set_write_callback (flacenc->encoder,
276 gst_flacenc_write_callback);
277 FLAC__stream_encoder_set_metadata_callback (flacenc->encoder,
278 gst_flacenc_metadata_callback);
279 FLAC__stream_encoder_set_client_data (flacenc->encoder,
282 flacenc->negotiated = FALSE;
283 flacenc->first = TRUE;
284 flacenc->first_buf = NULL;
285 flacenc->data = NULL;
286 gst_flacenc_update_quality (flacenc, DEFAULT_QUALITY);
290 gst_flacenc_dispose (GObject *object)
292 FlacEnc *flacenc = GST_FLACENC (object);
294 FLAC__stream_encoder_delete (flacenc->encoder);
296 G_OBJECT_CLASS (parent_class)->dispose (object);
299 static GstPadConnectReturn
300 gst_flacenc_sinkconnect (GstPad *pad, GstCaps *caps)
304 flacenc = GST_FLACENC (gst_pad_get_parent (pad));
306 if (!GST_CAPS_IS_FIXED (caps))
307 return GST_PAD_CONNECT_DELAYED;
309 gst_caps_get_int (caps, "channels", &flacenc->channels);
310 gst_caps_get_int (caps, "depth", &flacenc->depth);
311 gst_caps_get_int (caps, "rate", &flacenc->sample_rate);
313 FLAC__stream_encoder_set_bits_per_sample (flacenc->encoder,
315 FLAC__stream_encoder_set_sample_rate (flacenc->encoder,
316 flacenc->sample_rate);
317 FLAC__stream_encoder_set_channels (flacenc->encoder,
320 flacenc->negotiated = TRUE;
322 return GST_PAD_CONNECT_OK;
326 gst_flacenc_update_quality (FlacEnc *flacenc, gint quality)
328 flacenc->quality = quality;
330 #define DO_UPDATE(name, val, str) \
332 if (FLAC__stream_encoder_get_##name (flacenc->encoder) != \
333 flacenc_params[quality].##val) { \
334 FLAC__stream_encoder_set_##name (flacenc->encoder, \
335 flacenc_params[quality].##val); \
336 g_object_notify (G_OBJECT (flacenc), str); \
340 g_object_freeze_notify (G_OBJECT (flacenc));
342 DO_UPDATE (do_mid_side_stereo, mid_side, "mid_side_stereo");
343 DO_UPDATE (loose_mid_side_stereo, loose_mid_side, "loose_mid_side");
344 DO_UPDATE (blocksize, blocksize, "blocksize");
345 DO_UPDATE (max_lpc_order, max_lpc_order, "max_lpc_order");
346 DO_UPDATE (qlp_coeff_precision, qlp_coeff_precision, "qlp_coeff_precision");
347 DO_UPDATE (do_qlp_coeff_prec_search, qlp_coeff_prec_search, "qlp_coeff_prec_search");
348 DO_UPDATE (do_escape_coding, escape_coding, "escape_coding");
349 DO_UPDATE (do_exhaustive_model_search, exhaustive_model_search, "exhaustive_model_search");
350 DO_UPDATE (min_residual_partition_order, min_residual_partition_order, "min_residual_partition_order");
351 DO_UPDATE (max_residual_partition_order, max_residual_partition_order, "max_residual_partition_order");
352 DO_UPDATE (rice_parameter_search_dist, rice_parameter_search_dist, "rice_parameter_search_dist");
356 g_object_thaw_notify (G_OBJECT (flacenc));
361 static FLAC__StreamEncoderWriteStatus
362 gst_flacenc_write_callback (const FLAC__StreamEncoder *encoder,
363 const FLAC__byte buffer[], unsigned bytes,
364 unsigned samples, unsigned current_frame,
370 flacenc = GST_FLACENC (client_data);
372 if (flacenc->stopped)
373 return FLAC__STREAM_ENCODER_WRITE_OK;
375 outbuf = gst_buffer_new_and_alloc (bytes);
377 memcpy (GST_BUFFER_DATA (outbuf), buffer, bytes);
379 if (flacenc->first) {
380 flacenc->first_buf = outbuf;
381 gst_buffer_ref (outbuf);
382 flacenc->first = FALSE;
385 gst_pad_push (flacenc->srcpad, outbuf);
387 return FLAC__STREAM_ENCODER_WRITE_OK;
391 gst_flacenc_metadata_callback (const FLAC__StreamEncoder *encoder,
392 const FLAC__StreamMetadata *metadata,
398 flacenc = GST_FLACENC (client_data);
400 if (flacenc->stopped)
403 event = gst_event_new_discontinuous (FALSE, GST_FORMAT_BYTES, 0, NULL);
404 gst_pad_push (flacenc->srcpad, GST_BUFFER (event));
406 if (flacenc->first_buf) {
407 const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
408 const unsigned min_framesize = metadata->data.stream_info.min_framesize;
409 const unsigned max_framesize = metadata->data.stream_info.max_framesize;
411 guint8 *data = GST_BUFFER_DATA (flacenc->first_buf);
412 GstBuffer *outbuf = flacenc->first_buf;
414 /* this looks evil but is actually how one is supposed to write
415 * the stream stats according to the FLAC examples */
417 memcpy (&data[26], metadata->data.stream_info.md5sum, 16);
419 data[21] = (data[21] & 0xf0) |
420 (FLAC__byte)((samples >> 32) & 0x0f);
421 data[22] = (FLAC__byte)((samples >> 24) & 0xff);
422 data[23] = (FLAC__byte)((samples >> 16) & 0xff);
423 data[24] = (FLAC__byte)((samples >> 8 ) & 0xff);
424 data[25] = (FLAC__byte)((samples ) & 0xff);
426 data[12] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
427 data[13] = (FLAC__byte)((min_framesize >> 8 ) & 0xFF);
428 data[14] = (FLAC__byte)((min_framesize ) & 0xFF);
430 data[15] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
431 data[16] = (FLAC__byte)((max_framesize >> 8 ) & 0xFF);
432 data[17] = (FLAC__byte)((max_framesize ) & 0xFF);
434 flacenc->first_buf = NULL;
435 gst_pad_push (flacenc->srcpad, outbuf);
440 gst_flacenc_chain (GstPad *pad, GstBuffer *buf)
449 g_return_if_fail(buf != NULL);
451 flacenc = GST_FLACENC (gst_pad_get_parent (pad));
453 if (GST_IS_EVENT (buf)) {
454 GstEvent *event = GST_EVENT (buf);
456 switch (GST_EVENT_TYPE (event)) {
458 FLAC__stream_encoder_finish(flacenc->encoder);
460 gst_pad_event_default (pad, event);
466 if (!flacenc->negotiated) {
467 gst_element_error (GST_ELEMENT (flacenc),
468 "format not negotiated");
472 depth = flacenc->depth;
474 insize = GST_BUFFER_SIZE (buf);
475 samples = insize / ((depth+7)>>3);
477 if (FLAC__stream_encoder_get_state (flacenc->encoder) ==
478 FLAC__STREAM_ENCODER_UNINITIALIZED)
480 FLAC__StreamEncoderState state;
482 state = FLAC__stream_encoder_init (flacenc->encoder);
483 if (state != FLAC__STREAM_ENCODER_OK) {
484 gst_element_error (GST_ELEMENT (flacenc),
485 "could not initialize encoder (wrong parameters?)");
490 /* we keep a pointer in the flacenc struct because we are freeing the data
491 * after a push opreration that might never return */
492 data = flacenc->data = g_malloc (samples * sizeof (FLAC__int32));
495 gint8 *indata = (gint8 *) GST_BUFFER_DATA (buf);
497 for (i=0; i<samples; i++) {
498 data[i] = (FLAC__int32) *indata++;
501 else if (depth == 16) {
502 gint16 *indata = (gint16 *) GST_BUFFER_DATA (buf);
504 for (i=0; i<samples; i++) {
505 data[i] = (FLAC__int32) *indata++;
509 gst_buffer_unref(buf);
511 res = FLAC__stream_encoder_process_interleaved (flacenc->encoder,
512 (const FLAC__int32 *) data, samples / flacenc->channels);
514 g_free (flacenc->data);
515 flacenc->data = NULL;
518 gst_element_error (GST_ELEMENT (flacenc),
524 gst_flacenc_set_property (GObject *object, guint prop_id,
525 const GValue *value, GParamSpec *pspec)
529 this = (FlacEnc *)object;
532 gst_flacenc_update_quality (this, g_value_get_enum (value));
534 case ARG_STREAMABLE_SUBSET:
535 FLAC__stream_encoder_set_streamable_subset (this->encoder,
536 g_value_get_boolean (value));
538 case ARG_MID_SIDE_STEREO:
539 FLAC__stream_encoder_set_do_mid_side_stereo (this->encoder,
540 g_value_get_boolean (value));
542 case ARG_LOOSE_MID_SIDE_STEREO:
543 FLAC__stream_encoder_set_loose_mid_side_stereo (this->encoder,
544 g_value_get_boolean (value));
547 FLAC__stream_encoder_set_blocksize (this->encoder,
548 g_value_get_uint (value));
550 case ARG_MAX_LPC_ORDER:
551 FLAC__stream_encoder_set_max_lpc_order (this->encoder,
552 g_value_get_uint (value));
554 case ARG_QLP_COEFF_PRECISION:
555 FLAC__stream_encoder_set_qlp_coeff_precision (this->encoder,
556 g_value_get_uint (value));
558 case ARG_QLP_COEFF_PREC_SEARCH:
559 FLAC__stream_encoder_set_do_qlp_coeff_prec_search (this->encoder,
560 g_value_get_boolean (value));
562 case ARG_ESCAPE_CODING:
563 FLAC__stream_encoder_set_do_escape_coding (this->encoder,
564 g_value_get_boolean (value));
566 case ARG_EXHAUSTIVE_MODEL_SEARCH:
567 FLAC__stream_encoder_set_do_exhaustive_model_search (this->encoder,
568 g_value_get_boolean (value));
570 case ARG_MIN_RESIDUAL_PARTITION_ORDER:
571 FLAC__stream_encoder_set_min_residual_partition_order (this->encoder,
572 g_value_get_uint (value));
574 case ARG_MAX_RESIDUAL_PARTITION_ORDER:
575 FLAC__stream_encoder_set_max_residual_partition_order (this->encoder,
576 g_value_get_uint (value));
578 case ARG_RICE_PARAMETER_SEARCH_DIST:
579 FLAC__stream_encoder_set_rice_parameter_search_dist (this->encoder,
580 g_value_get_uint (value));
583 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
589 gst_flacenc_get_property (GObject *object, guint prop_id,
590 GValue *value, GParamSpec *pspec)
594 this = (FlacEnc *)object;
598 g_value_set_enum (value, this->quality);
600 case ARG_STREAMABLE_SUBSET:
601 g_value_set_boolean (value,
602 FLAC__stream_encoder_get_streamable_subset (this->encoder));
604 case ARG_MID_SIDE_STEREO:
605 g_value_set_boolean (value,
606 FLAC__stream_encoder_get_do_mid_side_stereo (this->encoder));
608 case ARG_LOOSE_MID_SIDE_STEREO:
609 g_value_set_boolean (value,
610 FLAC__stream_encoder_get_loose_mid_side_stereo (this->encoder));
613 g_value_set_uint (value,
614 FLAC__stream_encoder_get_blocksize (this->encoder));
616 case ARG_MAX_LPC_ORDER:
617 g_value_set_uint (value,
618 FLAC__stream_encoder_get_max_lpc_order (this->encoder));
620 case ARG_QLP_COEFF_PRECISION:
621 g_value_set_uint (value,
622 FLAC__stream_encoder_get_qlp_coeff_precision (this->encoder));
624 case ARG_QLP_COEFF_PREC_SEARCH:
625 g_value_set_boolean (value,
626 FLAC__stream_encoder_get_do_qlp_coeff_prec_search (this->encoder));
628 case ARG_ESCAPE_CODING:
629 g_value_set_boolean (value,
630 FLAC__stream_encoder_get_do_escape_coding (this->encoder));
632 case ARG_EXHAUSTIVE_MODEL_SEARCH:
633 g_value_set_boolean (value,
634 FLAC__stream_encoder_get_do_exhaustive_model_search (this->encoder));
636 case ARG_MIN_RESIDUAL_PARTITION_ORDER:
637 g_value_set_uint (value,
638 FLAC__stream_encoder_get_min_residual_partition_order (this->encoder));
640 case ARG_MAX_RESIDUAL_PARTITION_ORDER:
641 g_value_set_uint (value,
642 FLAC__stream_encoder_get_max_residual_partition_order (this->encoder));
644 case ARG_RICE_PARAMETER_SEARCH_DIST:
645 g_value_set_uint (value,
646 FLAC__stream_encoder_get_rice_parameter_search_dist (this->encoder));
649 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
654 static GstElementStateReturn
655 gst_flacenc_change_state (GstElement *element)
657 FlacEnc *flacenc = GST_FLACENC (element);
659 switch (GST_STATE_TRANSITION (element)) {
660 case GST_STATE_NULL_TO_READY:
661 case GST_STATE_READY_TO_PAUSED:
662 flacenc->first = TRUE;
663 flacenc->stopped = FALSE;
665 case GST_STATE_PAUSED_TO_PLAYING:
666 case GST_STATE_PLAYING_TO_PAUSED:
668 case GST_STATE_PAUSED_TO_READY:
669 if (FLAC__stream_encoder_get_state (flacenc->encoder) !=
670 FLAC__STREAM_ENCODER_UNINITIALIZED) {
671 flacenc->stopped = TRUE;
672 FLAC__stream_encoder_finish (flacenc->encoder);
674 flacenc->negotiated = FALSE;
675 if (flacenc->first_buf)
676 gst_buffer_unref (flacenc->first_buf);
677 flacenc->first_buf = NULL;
678 g_free (flacenc->data);
679 flacenc->data = NULL;
681 case GST_STATE_READY_TO_NULL:
686 if (GST_ELEMENT_CLASS (parent_class)->change_state)
687 return GST_ELEMENT_CLASS (parent_class)->change_state (element);
689 return GST_STATE_SUCCESS;