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 #include "flac_compat.h"
28 extern GstPadTemplate *gst_flacenc_src_template, *gst_flacenc_sink_template;
30 /* elementfactory information */
31 GstElementDetails flacenc_details = {
33 "Codec/Audio/Encoder",
35 "Encodes audio with the FLAC lossless audio encoder",
37 "Wim Taymans <wim.taymans@chello.be>",
41 /* FlacEnc signals and args */
50 ARG_STREAMABLE_SUBSET,
52 ARG_LOOSE_MID_SIDE_STEREO,
55 ARG_QLP_COEFF_PRECISION,
56 ARG_QLP_COEFF_PREC_SEARCH,
58 ARG_EXHAUSTIVE_MODEL_SEARCH,
59 ARG_MIN_RESIDUAL_PARTITION_ORDER,
60 ARG_MAX_RESIDUAL_PARTITION_ORDER,
61 ARG_RICE_PARAMETER_SEARCH_DIST,
64 static void gst_flacenc_init (FlacEnc *flacenc);
65 static void gst_flacenc_class_init (FlacEncClass *klass);
66 static void gst_flacenc_dispose (GObject *object);
68 static GstPadConnectReturn
69 gst_flacenc_sinkconnect (GstPad *pad, GstCaps *caps);
70 static void gst_flacenc_chain (GstPad *pad, GstBuffer *buf);
72 static gboolean gst_flacenc_update_quality (FlacEnc *flacenc, gint quality);
73 static void gst_flacenc_set_property (GObject *object, guint prop_id,
74 const GValue *value, GParamSpec *pspec);
75 static void gst_flacenc_get_property (GObject *object, guint prop_id,
76 GValue *value, GParamSpec *pspec);
77 static GstElementStateReturn
78 gst_flacenc_change_state (GstElement *element);
80 static FLAC__StreamEncoderWriteStatus
81 gst_flacenc_write_callback (const FLAC__StreamEncoder *encoder,
82 const FLAC__byte buffer[], unsigned bytes,
83 unsigned samples, unsigned current_frame,
85 static void gst_flacenc_metadata_callback (const FLAC__StreamEncoder *encoder,
86 const FLAC__StreamMetadata *metadata,
89 static GstElementClass *parent_class = NULL;
90 /*static guint gst_flacenc_signals[LAST_SIGNAL] = { 0 }; */
93 flacenc_get_type (void)
95 static GType flacenc_type = 0;
98 static const GTypeInfo flacenc_info = {
102 (GClassInitFunc)gst_flacenc_class_init,
107 (GInstanceInitFunc)gst_flacenc_init,
109 flacenc_type = g_type_register_static (GST_TYPE_ELEMENT, "FlacEnc", &flacenc_info, 0);
115 gboolean exhaustive_model_search;
116 gboolean escape_coding;
118 gboolean loose_mid_side;
119 guint qlp_coeff_precision;
120 gboolean qlp_coeff_prec_search;
121 guint min_residual_partition_order;
122 guint max_residual_partition_order;
123 guint rice_parameter_search_dist;
128 static const FlacEncParams flacenc_params[] =
130 { FALSE, FALSE, FALSE, FALSE, 0, FALSE, 2, 2, 0, 0, 1152 },
131 { FALSE, FALSE, TRUE, TRUE, 0, FALSE, 2, 2, 0, 0, 1152 },
132 { FALSE, FALSE, TRUE, FALSE, 0, FALSE, 0, 3, 0, 0, 1152 },
133 { FALSE, FALSE, FALSE, FALSE, 0, FALSE, 3, 3, 0, 6, 4608 },
134 { FALSE, FALSE, TRUE, TRUE, 0, FALSE, 3, 3, 0, 8, 4608 },
135 { FALSE, FALSE, TRUE, FALSE, 0, FALSE, 3, 3, 0, 8, 4608 },
136 { FALSE, FALSE, TRUE, FALSE, 0, FALSE, 0, 4, 0, 8, 4608 },
137 { TRUE, FALSE, TRUE, FALSE, 0, FALSE, 0, 6, 0, 8, 4608 },
138 { TRUE, FALSE, TRUE, FALSE, 0, FALSE, 0, 6, 0, 12, 4608 },
139 { TRUE, TRUE, TRUE, FALSE, 0, FALSE, 0, 16, 0, 32, 4608 },
142 #define DEFAULT_QUALITY 5
144 #define GST_TYPE_FLACENC_QUALITY (gst_flacenc_quality_get_type ())
146 gst_flacenc_quality_get_type (void)
148 static GType qtype = 0;
150 static const GEnumValue values[] = {
151 { 0, "0", "0 - Fastest compression" },
156 { 5, "5", "5 - Default" },
159 { 8, "8", "8 - Highest compression " },
160 { 9, "9", "9 - Insane" },
163 qtype = g_enum_register_static ("FlacEncQuality", values);
169 gst_flacenc_class_init (FlacEncClass *klass)
171 GObjectClass *gobject_class;
172 GstElementClass *gstelement_class;
174 gobject_class = (GObjectClass*)klass;
175 gstelement_class = (GstElementClass*)klass;
177 parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
179 /* we have no properties atm so this is a bit silly */
180 gobject_class->set_property = gst_flacenc_set_property;
181 gobject_class->get_property = gst_flacenc_get_property;
182 gobject_class->dispose = gst_flacenc_dispose;
184 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_QUALITY,
185 g_param_spec_enum ("quality",
187 "Speed versus compression tradeoff",
188 GST_TYPE_FLACENC_QUALITY, DEFAULT_QUALITY, G_PARAM_READWRITE));
189 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_STREAMABLE_SUBSET,
190 g_param_spec_boolean ("streamable_subset",
192 "true to limit encoder to generating a Subset stream, else false",
193 TRUE, G_PARAM_READWRITE));
194 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MID_SIDE_STEREO,
195 g_param_spec_boolean ("mid_side_stereo",
196 "Do mid side stereo",
197 "Do mid side stereo (only for stereo input)",
198 flacenc_params[DEFAULT_QUALITY].mid_side, G_PARAM_READWRITE));
199 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LOOSE_MID_SIDE_STEREO,
200 g_param_spec_boolean ("loose_mid_side_stereo",
201 "Loose mid side stereo",
202 "Loose mid side stereo",
203 flacenc_params[DEFAULT_QUALITY].loose_mid_side, G_PARAM_READWRITE));
204 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_BLOCKSIZE,
205 g_param_spec_uint ("blocksize",
207 "Blocksize in samples",
208 FLAC__MIN_BLOCK_SIZE, FLAC__MAX_BLOCK_SIZE,
209 flacenc_params[DEFAULT_QUALITY].blocksize, G_PARAM_READWRITE));
210 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MAX_LPC_ORDER,
211 g_param_spec_uint ("max_lpc_order",
213 "Max LPC order; 0 => use only fixed predictors",
214 0, FLAC__MAX_LPC_ORDER,
215 flacenc_params[DEFAULT_QUALITY].max_lpc_order, G_PARAM_READWRITE));
216 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_QLP_COEFF_PRECISION,
217 g_param_spec_uint ("qlp_coeff_precision",
218 "QLP coefficients precision",
219 "Precision in bits of quantized linear-predictor coefficients; 0 = automatic",
221 flacenc_params[DEFAULT_QUALITY].qlp_coeff_precision, G_PARAM_READWRITE));
222 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_QLP_COEFF_PREC_SEARCH,
223 g_param_spec_boolean ("qlp_coeff_prec_search",
224 "Do QLP coefficients precision search",
225 "false = use qlp_coeff_precision, "
226 "true = search around qlp_coeff_precision, take best",
227 flacenc_params[DEFAULT_QUALITY].qlp_coeff_prec_search, G_PARAM_READWRITE));
228 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ESCAPE_CODING,
229 g_param_spec_boolean ("escape_coding",
231 "search for escape codes in the entropy coding stage "
232 "for slightly better compression",
233 flacenc_params[DEFAULT_QUALITY].escape_coding, G_PARAM_READWRITE));
234 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_EXHAUSTIVE_MODEL_SEARCH,
235 g_param_spec_boolean ("exhaustive_model_search",
236 "Do exhaustive model search",
237 "do exhaustive search of LP coefficient quantization (expensive!)",
238 flacenc_params[DEFAULT_QUALITY].exhaustive_model_search, G_PARAM_READWRITE));
239 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MIN_RESIDUAL_PARTITION_ORDER,
240 g_param_spec_uint ("min_residual_partition_order",
241 "Min residual partition order",
242 "Min residual partition order (above 4 doesn't usually help much)",
244 flacenc_params[DEFAULT_QUALITY].min_residual_partition_order, G_PARAM_READWRITE));
245 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MAX_RESIDUAL_PARTITION_ORDER,
246 g_param_spec_uint ("max_residual_partition_order",
247 "Max residual partition order",
248 "Max residual partition order (above 4 doesn't usually help much)",
250 flacenc_params[DEFAULT_QUALITY].max_residual_partition_order, G_PARAM_READWRITE));
251 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_RICE_PARAMETER_SEARCH_DIST,
252 g_param_spec_uint ("rice_parameter_search_dist",
253 "rice_parameter_search_dist",
254 "0 = try only calc'd parameter k; else try all [k-dist..k+dist] "
255 "parameters, use best",
256 0, FLAC__MAX_RICE_PARTITION_ORDER,
257 flacenc_params[DEFAULT_QUALITY].rice_parameter_search_dist, G_PARAM_READWRITE));
259 gstelement_class->change_state = gst_flacenc_change_state;
263 gst_flacenc_init (FlacEnc *flacenc)
265 flacenc->sinkpad = gst_pad_new_from_template (gst_flacenc_sink_template, "sink");
266 gst_element_add_pad(GST_ELEMENT(flacenc),flacenc->sinkpad);
267 gst_pad_set_chain_function(flacenc->sinkpad,gst_flacenc_chain);
268 gst_pad_set_connect_function (flacenc->sinkpad, gst_flacenc_sinkconnect);
270 flacenc->srcpad = gst_pad_new_from_template (gst_flacenc_src_template, "src");
271 gst_element_add_pad(GST_ELEMENT(flacenc),flacenc->srcpad);
273 GST_FLAG_SET (flacenc, GST_ELEMENT_EVENT_AWARE);
275 flacenc->encoder = FLAC__stream_encoder_new();
277 FLAC__stream_encoder_set_write_callback (flacenc->encoder,
278 gst_flacenc_write_callback);
279 FLAC__stream_encoder_set_metadata_callback (flacenc->encoder,
280 gst_flacenc_metadata_callback);
281 FLAC__stream_encoder_set_client_data (flacenc->encoder,
284 flacenc->negotiated = FALSE;
285 flacenc->first = TRUE;
286 flacenc->first_buf = NULL;
287 flacenc->data = NULL;
288 gst_flacenc_update_quality (flacenc, DEFAULT_QUALITY);
292 gst_flacenc_dispose (GObject *object)
294 FlacEnc *flacenc = GST_FLACENC (object);
296 FLAC__stream_encoder_delete (flacenc->encoder);
298 G_OBJECT_CLASS (parent_class)->dispose (object);
301 static GstPadConnectReturn
302 gst_flacenc_sinkconnect (GstPad *pad, GstCaps *caps)
306 flacenc = GST_FLACENC (gst_pad_get_parent (pad));
308 if (!GST_CAPS_IS_FIXED (caps))
309 return GST_PAD_CONNECT_DELAYED;
311 gst_caps_get_int (caps, "channels", &flacenc->channels);
312 gst_caps_get_int (caps, "depth", &flacenc->depth);
313 gst_caps_get_int (caps, "rate", &flacenc->sample_rate);
315 FLAC__stream_encoder_set_bits_per_sample (flacenc->encoder,
317 FLAC__stream_encoder_set_sample_rate (flacenc->encoder,
318 flacenc->sample_rate);
319 FLAC__stream_encoder_set_channels (flacenc->encoder,
322 flacenc->negotiated = TRUE;
324 return GST_PAD_CONNECT_OK;
328 gst_flacenc_update_quality (FlacEnc *flacenc, gint quality)
330 flacenc->quality = quality;
332 #define DO_UPDATE(name, val, str) \
334 if (FLAC__stream_encoder_get_##name (flacenc->encoder) != \
335 flacenc_params[quality].val) { \
336 FLAC__stream_encoder_set_##name (flacenc->encoder, \
337 flacenc_params[quality].val); \
338 g_object_notify (G_OBJECT (flacenc), str); \
342 g_object_freeze_notify (G_OBJECT (flacenc));
344 DO_UPDATE (do_mid_side_stereo, mid_side, "mid_side_stereo");
345 DO_UPDATE (loose_mid_side_stereo, loose_mid_side, "loose_mid_side");
346 DO_UPDATE (blocksize, blocksize, "blocksize");
347 DO_UPDATE (max_lpc_order, max_lpc_order, "max_lpc_order");
348 DO_UPDATE (qlp_coeff_precision, qlp_coeff_precision, "qlp_coeff_precision");
349 DO_UPDATE (do_qlp_coeff_prec_search, qlp_coeff_prec_search, "qlp_coeff_prec_search");
350 DO_UPDATE (do_escape_coding, escape_coding, "escape_coding");
351 DO_UPDATE (do_exhaustive_model_search, exhaustive_model_search, "exhaustive_model_search");
352 DO_UPDATE (min_residual_partition_order, min_residual_partition_order, "min_residual_partition_order");
353 DO_UPDATE (max_residual_partition_order, max_residual_partition_order, "max_residual_partition_order");
354 DO_UPDATE (rice_parameter_search_dist, rice_parameter_search_dist, "rice_parameter_search_dist");
358 g_object_thaw_notify (G_OBJECT (flacenc));
363 static FLAC__StreamEncoderWriteStatus
364 gst_flacenc_write_callback (const FLAC__StreamEncoder *encoder,
365 const FLAC__byte buffer[], unsigned bytes,
366 unsigned samples, unsigned current_frame,
372 flacenc = GST_FLACENC (client_data);
374 if (flacenc->stopped)
375 return FLAC__STREAM_ENCODER_OK;
377 outbuf = gst_buffer_new_and_alloc (bytes);
379 memcpy (GST_BUFFER_DATA (outbuf), buffer, bytes);
381 if (flacenc->first) {
382 flacenc->first_buf = outbuf;
383 gst_buffer_ref (outbuf);
384 flacenc->first = FALSE;
387 gst_pad_push (flacenc->srcpad, outbuf);
389 return FLAC__STREAM_ENCODER_OK;
393 gst_flacenc_metadata_callback (const FLAC__StreamEncoder *encoder,
394 const FLAC__StreamMetadata *metadata,
400 flacenc = GST_FLACENC (client_data);
402 if (flacenc->stopped)
405 event = gst_event_new_discontinuous (FALSE, GST_FORMAT_BYTES, 0, NULL);
406 gst_pad_push (flacenc->srcpad, GST_BUFFER (event));
408 if (flacenc->first_buf) {
409 const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
410 const unsigned min_framesize = metadata->data.stream_info.min_framesize;
411 const unsigned max_framesize = metadata->data.stream_info.max_framesize;
413 guint8 *data = GST_BUFFER_DATA (flacenc->first_buf);
414 GstBuffer *outbuf = flacenc->first_buf;
416 /* this looks evil but is actually how one is supposed to write
417 * the stream stats according to the FLAC examples */
419 memcpy (&data[26], metadata->data.stream_info.md5sum, 16);
421 data[21] = (data[21] & 0xf0) |
422 (FLAC__byte)((samples >> 32) & 0x0f);
423 data[22] = (FLAC__byte)((samples >> 24) & 0xff);
424 data[23] = (FLAC__byte)((samples >> 16) & 0xff);
425 data[24] = (FLAC__byte)((samples >> 8 ) & 0xff);
426 data[25] = (FLAC__byte)((samples ) & 0xff);
428 data[12] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
429 data[13] = (FLAC__byte)((min_framesize >> 8 ) & 0xFF);
430 data[14] = (FLAC__byte)((min_framesize ) & 0xFF);
432 data[15] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
433 data[16] = (FLAC__byte)((max_framesize >> 8 ) & 0xFF);
434 data[17] = (FLAC__byte)((max_framesize ) & 0xFF);
436 flacenc->first_buf = NULL;
437 gst_pad_push (flacenc->srcpad, outbuf);
442 gst_flacenc_chain (GstPad *pad, GstBuffer *buf)
451 g_return_if_fail(buf != NULL);
453 flacenc = GST_FLACENC (gst_pad_get_parent (pad));
455 if (GST_IS_EVENT (buf)) {
456 GstEvent *event = GST_EVENT (buf);
458 switch (GST_EVENT_TYPE (event)) {
460 FLAC__stream_encoder_finish(flacenc->encoder);
462 gst_pad_event_default (pad, event);
468 if (!flacenc->negotiated) {
469 gst_element_error (GST_ELEMENT (flacenc),
470 "format not negotiated");
474 depth = flacenc->depth;
476 insize = GST_BUFFER_SIZE (buf);
477 samples = insize / ((depth+7)>>3);
479 if (FLAC__stream_encoder_get_state (flacenc->encoder) ==
480 FLAC__STREAM_ENCODER_UNINITIALIZED)
482 FLAC__StreamEncoderState state;
484 state = FLAC__stream_encoder_init (flacenc->encoder);
485 if (state != FLAC__STREAM_ENCODER_OK) {
486 gst_element_error (GST_ELEMENT (flacenc),
487 "could not initialize encoder (wrong parameters?)");
492 /* we keep a pointer in the flacenc struct because we are freeing the data
493 * after a push opreration that might never return */
494 data = flacenc->data = g_malloc (samples * sizeof (FLAC__int32));
497 gint8 *indata = (gint8 *) GST_BUFFER_DATA (buf);
499 for (i=0; i<samples; i++) {
500 data[i] = (FLAC__int32) *indata++;
503 else if (depth == 16) {
504 gint16 *indata = (gint16 *) GST_BUFFER_DATA (buf);
506 for (i=0; i<samples; i++) {
507 data[i] = (FLAC__int32) *indata++;
511 gst_buffer_unref(buf);
513 res = FLAC__stream_encoder_process_interleaved (flacenc->encoder,
514 (const FLAC__int32 *) data, samples / flacenc->channels);
516 g_free (flacenc->data);
517 flacenc->data = NULL;
520 gst_element_error (GST_ELEMENT (flacenc),
526 gst_flacenc_set_property (GObject *object, guint prop_id,
527 const GValue *value, GParamSpec *pspec)
531 this = (FlacEnc *)object;
534 gst_flacenc_update_quality (this, g_value_get_enum (value));
536 case ARG_STREAMABLE_SUBSET:
537 FLAC__stream_encoder_set_streamable_subset (this->encoder,
538 g_value_get_boolean (value));
540 case ARG_MID_SIDE_STEREO:
541 FLAC__stream_encoder_set_do_mid_side_stereo (this->encoder,
542 g_value_get_boolean (value));
544 case ARG_LOOSE_MID_SIDE_STEREO:
545 FLAC__stream_encoder_set_loose_mid_side_stereo (this->encoder,
546 g_value_get_boolean (value));
549 FLAC__stream_encoder_set_blocksize (this->encoder,
550 g_value_get_uint (value));
552 case ARG_MAX_LPC_ORDER:
553 FLAC__stream_encoder_set_max_lpc_order (this->encoder,
554 g_value_get_uint (value));
556 case ARG_QLP_COEFF_PRECISION:
557 FLAC__stream_encoder_set_qlp_coeff_precision (this->encoder,
558 g_value_get_uint (value));
560 case ARG_QLP_COEFF_PREC_SEARCH:
561 FLAC__stream_encoder_set_do_qlp_coeff_prec_search (this->encoder,
562 g_value_get_boolean (value));
564 case ARG_ESCAPE_CODING:
565 FLAC__stream_encoder_set_do_escape_coding (this->encoder,
566 g_value_get_boolean (value));
568 case ARG_EXHAUSTIVE_MODEL_SEARCH:
569 FLAC__stream_encoder_set_do_exhaustive_model_search (this->encoder,
570 g_value_get_boolean (value));
572 case ARG_MIN_RESIDUAL_PARTITION_ORDER:
573 FLAC__stream_encoder_set_min_residual_partition_order (this->encoder,
574 g_value_get_uint (value));
576 case ARG_MAX_RESIDUAL_PARTITION_ORDER:
577 FLAC__stream_encoder_set_max_residual_partition_order (this->encoder,
578 g_value_get_uint (value));
580 case ARG_RICE_PARAMETER_SEARCH_DIST:
581 FLAC__stream_encoder_set_rice_parameter_search_dist (this->encoder,
582 g_value_get_uint (value));
585 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
591 gst_flacenc_get_property (GObject *object, guint prop_id,
592 GValue *value, GParamSpec *pspec)
596 this = (FlacEnc *)object;
600 g_value_set_enum (value, this->quality);
602 case ARG_STREAMABLE_SUBSET:
603 g_value_set_boolean (value,
604 FLAC__stream_encoder_get_streamable_subset (this->encoder));
606 case ARG_MID_SIDE_STEREO:
607 g_value_set_boolean (value,
608 FLAC__stream_encoder_get_do_mid_side_stereo (this->encoder));
610 case ARG_LOOSE_MID_SIDE_STEREO:
611 g_value_set_boolean (value,
612 FLAC__stream_encoder_get_loose_mid_side_stereo (this->encoder));
615 g_value_set_uint (value,
616 FLAC__stream_encoder_get_blocksize (this->encoder));
618 case ARG_MAX_LPC_ORDER:
619 g_value_set_uint (value,
620 FLAC__stream_encoder_get_max_lpc_order (this->encoder));
622 case ARG_QLP_COEFF_PRECISION:
623 g_value_set_uint (value,
624 FLAC__stream_encoder_get_qlp_coeff_precision (this->encoder));
626 case ARG_QLP_COEFF_PREC_SEARCH:
627 g_value_set_boolean (value,
628 FLAC__stream_encoder_get_do_qlp_coeff_prec_search (this->encoder));
630 case ARG_ESCAPE_CODING:
631 g_value_set_boolean (value,
632 FLAC__stream_encoder_get_do_escape_coding (this->encoder));
634 case ARG_EXHAUSTIVE_MODEL_SEARCH:
635 g_value_set_boolean (value,
636 FLAC__stream_encoder_get_do_exhaustive_model_search (this->encoder));
638 case ARG_MIN_RESIDUAL_PARTITION_ORDER:
639 g_value_set_uint (value,
640 FLAC__stream_encoder_get_min_residual_partition_order (this->encoder));
642 case ARG_MAX_RESIDUAL_PARTITION_ORDER:
643 g_value_set_uint (value,
644 FLAC__stream_encoder_get_max_residual_partition_order (this->encoder));
646 case ARG_RICE_PARAMETER_SEARCH_DIST:
647 g_value_set_uint (value,
648 FLAC__stream_encoder_get_rice_parameter_search_dist (this->encoder));
651 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
656 static GstElementStateReturn
657 gst_flacenc_change_state (GstElement *element)
659 FlacEnc *flacenc = GST_FLACENC (element);
661 switch (GST_STATE_TRANSITION (element)) {
662 case GST_STATE_NULL_TO_READY:
663 case GST_STATE_READY_TO_PAUSED:
664 flacenc->first = TRUE;
665 flacenc->stopped = FALSE;
667 case GST_STATE_PAUSED_TO_PLAYING:
668 case GST_STATE_PLAYING_TO_PAUSED:
670 case GST_STATE_PAUSED_TO_READY:
671 if (FLAC__stream_encoder_get_state (flacenc->encoder) !=
672 FLAC__STREAM_ENCODER_UNINITIALIZED) {
673 flacenc->stopped = TRUE;
674 FLAC__stream_encoder_finish (flacenc->encoder);
676 flacenc->negotiated = FALSE;
677 if (flacenc->first_buf)
678 gst_buffer_unref (flacenc->first_buf);
679 flacenc->first_buf = NULL;
680 g_free (flacenc->data);
681 flacenc->data = NULL;
683 case GST_STATE_READY_TO_NULL:
688 if (GST_ELEMENT_CLASS (parent_class)->change_state)
689 return GST_ELEMENT_CLASS (parent_class)->change_state (element);
691 return GST_STATE_SUCCESS;