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",
32 "Encodes audio with the FLAC lossless audio encoder",
34 "Wim Taymans <wim.taymans@chello.be>",
38 /* FlacEnc signals and args */
47 ARG_STREAMABLE_SUBSET,
49 ARG_LOOSE_MID_SIDE_STEREO,
52 ARG_QLP_COEFF_PRECISION,
53 ARG_QLP_COEFF_PREC_SEARCH,
55 ARG_EXHAUSTIVE_MODEL_SEARCH,
56 ARG_MIN_RESIDUAL_PARTITION_ORDER,
57 ARG_MAX_RESIDUAL_PARTITION_ORDER,
58 ARG_RICE_PARAMETER_SEARCH_DIST,
61 static void gst_flacenc_init (FlacEnc *flacenc);
62 static void gst_flacenc_class_init (FlacEncClass *klass);
63 static void gst_flacenc_dispose (GObject *object);
65 static GstPadConnectReturn
66 gst_flacenc_sinkconnect (GstPad *pad, GstCaps *caps);
67 static void gst_flacenc_chain (GstPad *pad, GstBuffer *buf);
69 static gboolean gst_flacenc_update_quality (FlacEnc *flacenc, gint quality);
70 static void gst_flacenc_set_property (GObject *object, guint prop_id,
71 const GValue *value, GParamSpec *pspec);
72 static void gst_flacenc_get_property (GObject *object, guint prop_id,
73 GValue *value, GParamSpec *pspec);
74 static GstElementStateReturn
75 gst_flacenc_change_state (GstElement *element);
77 static FLAC__StreamEncoderWriteStatus
78 gst_flacenc_write_callback (const FLAC__StreamEncoder *encoder,
79 const FLAC__byte buffer[], unsigned bytes,
80 unsigned samples, unsigned current_frame,
82 static void gst_flacenc_metadata_callback (const FLAC__StreamEncoder *encoder,
83 const FLAC__StreamMetadata *metadata,
86 static GstElementClass *parent_class = NULL;
87 /*static guint gst_flacenc_signals[LAST_SIGNAL] = { 0 }; */
90 flacenc_get_type (void)
92 static GType flacenc_type = 0;
95 static const GTypeInfo flacenc_info = {
99 (GClassInitFunc)gst_flacenc_class_init,
104 (GInstanceInitFunc)gst_flacenc_init,
106 flacenc_type = g_type_register_static (GST_TYPE_ELEMENT, "FlacEnc", &flacenc_info, 0);
112 gboolean exhaustive_model_search;
113 gboolean escape_coding;
115 gboolean loose_mid_side;
116 guint qlp_coeff_precision;
117 gboolean qlp_coeff_prec_search;
118 guint min_residual_partition_order;
119 guint max_residual_partition_order;
120 guint rice_parameter_search_dist;
125 static const FlacEncParams flacenc_params[] =
127 { FALSE, FALSE, FALSE, FALSE, 0, FALSE, 2, 2, 0, 0, 1152 },
128 { FALSE, FALSE, TRUE, TRUE, 0, FALSE, 2, 2, 0, 0, 1152 },
129 { FALSE, FALSE, TRUE, FALSE, 0, FALSE, 0, 3, 0, 0, 1152 },
130 { FALSE, FALSE, FALSE, FALSE, 0, FALSE, 3, 3, 0, 6, 4608 },
131 { FALSE, FALSE, TRUE, TRUE, 0, FALSE, 3, 3, 0, 8, 4608 },
132 { FALSE, FALSE, TRUE, FALSE, 0, FALSE, 3, 3, 0, 8, 4608 },
133 { FALSE, FALSE, TRUE, FALSE, 0, FALSE, 0, 4, 0, 8, 4608 },
134 { TRUE, FALSE, TRUE, FALSE, 0, FALSE, 0, 6, 0, 8, 4608 },
135 { TRUE, FALSE, TRUE, FALSE, 0, FALSE, 0, 6, 0, 12, 4608 },
136 { TRUE, TRUE, TRUE, FALSE, 0, FALSE, 0, 16, 0, 32, 4608 },
139 #define DEFAULT_QUALITY 5
141 #define GST_TYPE_FLACENC_QUALITY (gst_flacenc_quality_get_type ())
143 gst_flacenc_quality_get_type (void)
145 static GType qtype = 0;
147 static const GEnumValue values[] = {
148 { 0, "0", "0 - Fastest compression" },
153 { 5, "5", "5 - Default" },
156 { 8, "8", "8 - Highest compression " },
157 { 9, "9", "9 - Insane" },
160 qtype = g_enum_register_static ("FlacEncQuality", values);
166 gst_flacenc_class_init (FlacEncClass *klass)
168 GObjectClass *gobject_class;
169 GstElementClass *gstelement_class;
171 gobject_class = (GObjectClass*)klass;
172 gstelement_class = (GstElementClass*)klass;
174 parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
176 /* we have no properties atm so this is a bit silly */
177 gobject_class->set_property = gst_flacenc_set_property;
178 gobject_class->get_property = gst_flacenc_get_property;
179 gobject_class->dispose = gst_flacenc_dispose;
181 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_QUALITY,
182 g_param_spec_enum ("quality",
184 "Speed versus compression tradeoff",
185 GST_TYPE_FLACENC_QUALITY, DEFAULT_QUALITY, G_PARAM_READWRITE));
186 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_STREAMABLE_SUBSET,
187 g_param_spec_boolean ("streamable_subset",
189 "true to limit encoder to generating a Subset stream, else false",
190 TRUE, G_PARAM_READWRITE));
191 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MID_SIDE_STEREO,
192 g_param_spec_boolean ("mid_side_stereo",
193 "Do mid side stereo",
194 "Do mid side stereo (only for stereo input)",
195 flacenc_params[DEFAULT_QUALITY].mid_side, G_PARAM_READWRITE));
196 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LOOSE_MID_SIDE_STEREO,
197 g_param_spec_boolean ("loose_mid_side_stereo",
198 "Loose mid side stereo",
199 "Loose mid side stereo",
200 flacenc_params[DEFAULT_QUALITY].loose_mid_side, G_PARAM_READWRITE));
201 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_BLOCKSIZE,
202 g_param_spec_uint ("blocksize",
204 "Blocksize in samples",
205 FLAC__MIN_BLOCK_SIZE, FLAC__MAX_BLOCK_SIZE,
206 flacenc_params[DEFAULT_QUALITY].blocksize, G_PARAM_READWRITE));
207 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MAX_LPC_ORDER,
208 g_param_spec_uint ("max_lpc_order",
210 "Max LPC order; 0 => use only fixed predictors",
211 0, FLAC__MAX_LPC_ORDER,
212 flacenc_params[DEFAULT_QUALITY].max_lpc_order, G_PARAM_READWRITE));
213 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_QLP_COEFF_PRECISION,
214 g_param_spec_uint ("qlp_coeff_precision",
215 "QLP coefficients precision",
216 "Precision in bits of quantized linear-predictor coefficients; 0 = automatic",
218 flacenc_params[DEFAULT_QUALITY].qlp_coeff_precision, G_PARAM_READWRITE));
219 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_QLP_COEFF_PREC_SEARCH,
220 g_param_spec_boolean ("qlp_coeff_prec_search",
221 "Do QLP coefficients precision search",
222 "false = use qlp_coeff_precision, "
223 "true = search around qlp_coeff_precision, take best",
224 flacenc_params[DEFAULT_QUALITY].qlp_coeff_prec_search, G_PARAM_READWRITE));
225 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ESCAPE_CODING,
226 g_param_spec_boolean ("escape_coding",
228 "search for escape codes in the entropy coding stage "
229 "for slightly better compression",
230 flacenc_params[DEFAULT_QUALITY].escape_coding, G_PARAM_READWRITE));
231 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_EXHAUSTIVE_MODEL_SEARCH,
232 g_param_spec_boolean ("exhaustive_model_search",
233 "Do exhaustive model search",
234 "do exhaustive search of LP coefficient quantization (expensive!)",
235 flacenc_params[DEFAULT_QUALITY].exhaustive_model_search, G_PARAM_READWRITE));
236 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MIN_RESIDUAL_PARTITION_ORDER,
237 g_param_spec_uint ("min_residual_partition_order",
238 "Min residual partition order",
239 "Min residual partition order (above 4 doesn't usually help much)",
241 flacenc_params[DEFAULT_QUALITY].min_residual_partition_order, G_PARAM_READWRITE));
242 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MAX_RESIDUAL_PARTITION_ORDER,
243 g_param_spec_uint ("max_residual_partition_order",
244 "Max residual partition order",
245 "Max residual partition order (above 4 doesn't usually help much)",
247 flacenc_params[DEFAULT_QUALITY].max_residual_partition_order, G_PARAM_READWRITE));
248 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_RICE_PARAMETER_SEARCH_DIST,
249 g_param_spec_uint ("rice_parameter_search_dist",
250 "rice_parameter_search_dist",
251 "0 = try only calc'd parameter k; else try all [k-dist..k+dist] "
252 "parameters, use best",
253 0, FLAC__MAX_RICE_PARTITION_ORDER,
254 flacenc_params[DEFAULT_QUALITY].rice_parameter_search_dist, G_PARAM_READWRITE));
256 gstelement_class->change_state = gst_flacenc_change_state;
260 gst_flacenc_init (FlacEnc *flacenc)
262 flacenc->sinkpad = gst_pad_new_from_template (gst_flacenc_sink_template, "sink");
263 gst_element_add_pad(GST_ELEMENT(flacenc),flacenc->sinkpad);
264 gst_pad_set_chain_function(flacenc->sinkpad,gst_flacenc_chain);
265 gst_pad_set_connect_function (flacenc->sinkpad, gst_flacenc_sinkconnect);
267 flacenc->srcpad = gst_pad_new_from_template (gst_flacenc_src_template, "src");
268 gst_element_add_pad(GST_ELEMENT(flacenc),flacenc->srcpad);
270 GST_FLAG_SET (flacenc, GST_ELEMENT_EVENT_AWARE);
272 flacenc->encoder = FLAC__stream_encoder_new();
274 FLAC__stream_encoder_set_write_callback (flacenc->encoder,
275 gst_flacenc_write_callback);
276 FLAC__stream_encoder_set_metadata_callback (flacenc->encoder,
277 gst_flacenc_metadata_callback);
278 FLAC__stream_encoder_set_client_data (flacenc->encoder,
281 flacenc->negotiated = FALSE;
282 flacenc->first = TRUE;
283 flacenc->first_buf = NULL;
284 flacenc->data = NULL;
285 gst_flacenc_update_quality (flacenc, DEFAULT_QUALITY);
289 gst_flacenc_dispose (GObject *object)
291 FlacEnc *flacenc = GST_FLACENC (object);
293 FLAC__stream_encoder_delete (flacenc->encoder);
295 G_OBJECT_CLASS (parent_class)->dispose (object);
298 static GstPadConnectReturn
299 gst_flacenc_sinkconnect (GstPad *pad, GstCaps *caps)
303 flacenc = GST_FLACENC (gst_pad_get_parent (pad));
305 if (!GST_CAPS_IS_FIXED (caps))
306 return GST_PAD_CONNECT_DELAYED;
308 gst_caps_get_int (caps, "channels", &flacenc->channels);
309 gst_caps_get_int (caps, "depth", &flacenc->depth);
310 gst_caps_get_int (caps, "rate", &flacenc->sample_rate);
312 FLAC__stream_encoder_set_bits_per_sample (flacenc->encoder,
314 FLAC__stream_encoder_set_sample_rate (flacenc->encoder,
315 flacenc->sample_rate);
316 FLAC__stream_encoder_set_channels (flacenc->encoder,
319 flacenc->negotiated = TRUE;
321 return GST_PAD_CONNECT_OK;
325 gst_flacenc_update_quality (FlacEnc *flacenc, gint quality)
327 flacenc->quality = quality;
329 #define DO_UPDATE(name, val, str) \
331 if (FLAC__stream_encoder_get_##name (flacenc->encoder) != \
332 flacenc_params[quality].##val) { \
333 FLAC__stream_encoder_set_##name (flacenc->encoder, \
334 flacenc_params[quality].##val); \
335 g_object_notify (G_OBJECT (flacenc), str); \
339 g_object_freeze_notify (G_OBJECT (flacenc));
341 DO_UPDATE (do_mid_side_stereo, mid_side, "mid_side_stereo");
342 DO_UPDATE (loose_mid_side_stereo, loose_mid_side, "loose_mid_side");
343 DO_UPDATE (blocksize, blocksize, "blocksize");
344 DO_UPDATE (max_lpc_order, max_lpc_order, "max_lpc_order");
345 DO_UPDATE (qlp_coeff_precision, qlp_coeff_precision, "qlp_coeff_precision");
346 DO_UPDATE (do_qlp_coeff_prec_search, qlp_coeff_prec_search, "qlp_coeff_prec_search");
347 DO_UPDATE (do_escape_coding, escape_coding, "escape_coding");
348 DO_UPDATE (do_exhaustive_model_search, exhaustive_model_search, "exhaustive_model_search");
349 DO_UPDATE (min_residual_partition_order, min_residual_partition_order, "min_residual_partition_order");
350 DO_UPDATE (max_residual_partition_order, max_residual_partition_order, "max_residual_partition_order");
351 DO_UPDATE (rice_parameter_search_dist, rice_parameter_search_dist, "rice_parameter_search_dist");
355 g_object_thaw_notify (G_OBJECT (flacenc));
360 static FLAC__StreamEncoderWriteStatus
361 gst_flacenc_write_callback (const FLAC__StreamEncoder *encoder,
362 const FLAC__byte buffer[], unsigned bytes,
363 unsigned samples, unsigned current_frame,
369 flacenc = GST_FLACENC (client_data);
371 if (flacenc->stopped)
372 return FLAC__STREAM_ENCODER_WRITE_OK;
374 outbuf = gst_buffer_new_and_alloc (bytes);
376 memcpy (GST_BUFFER_DATA (outbuf), buffer, bytes);
378 if (flacenc->first) {
379 flacenc->first_buf = outbuf;
380 gst_buffer_ref (outbuf);
381 flacenc->first = FALSE;
384 gst_pad_push (flacenc->srcpad, outbuf);
386 return FLAC__STREAM_ENCODER_WRITE_OK;
390 gst_flacenc_metadata_callback (const FLAC__StreamEncoder *encoder,
391 const FLAC__StreamMetadata *metadata,
397 flacenc = GST_FLACENC (client_data);
399 if (flacenc->stopped)
402 event = gst_event_new_discontinuous (FALSE, GST_FORMAT_BYTES, 0, NULL);
403 gst_pad_push (flacenc->srcpad, GST_BUFFER (event));
405 if (flacenc->first_buf) {
406 const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
407 const unsigned min_framesize = metadata->data.stream_info.min_framesize;
408 const unsigned max_framesize = metadata->data.stream_info.max_framesize;
410 guint8 *data = GST_BUFFER_DATA (flacenc->first_buf);
411 GstBuffer *outbuf = flacenc->first_buf;
413 /* this looks evil but is actually how one is supposed to write
414 * the stream stats according to the FLAC examples */
416 memcpy (&data[26], metadata->data.stream_info.md5sum, 16);
418 data[21] = (data[21] & 0xf0) |
419 (FLAC__byte)((samples >> 32) & 0x0f);
420 data[22] = (FLAC__byte)((samples >> 24) & 0xff);
421 data[23] = (FLAC__byte)((samples >> 16) & 0xff);
422 data[24] = (FLAC__byte)((samples >> 8 ) & 0xff);
423 data[25] = (FLAC__byte)((samples ) & 0xff);
425 data[12] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
426 data[13] = (FLAC__byte)((min_framesize >> 8 ) & 0xFF);
427 data[14] = (FLAC__byte)((min_framesize ) & 0xFF);
429 data[15] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
430 data[16] = (FLAC__byte)((max_framesize >> 8 ) & 0xFF);
431 data[17] = (FLAC__byte)((max_framesize ) & 0xFF);
433 flacenc->first_buf = NULL;
434 gst_pad_push (flacenc->srcpad, outbuf);
439 gst_flacenc_chain (GstPad *pad, GstBuffer *buf)
448 g_return_if_fail(buf != NULL);
450 flacenc = GST_FLACENC (gst_pad_get_parent (pad));
452 if (GST_IS_EVENT (buf)) {
453 GstEvent *event = GST_EVENT (buf);
455 switch (GST_EVENT_TYPE (event)) {
457 FLAC__stream_encoder_finish(flacenc->encoder);
459 gst_pad_event_default (pad, event);
465 if (!flacenc->negotiated) {
466 gst_element_error (GST_ELEMENT (flacenc),
467 "format not negotiated");
471 depth = flacenc->depth;
473 insize = GST_BUFFER_SIZE (buf);
474 samples = insize / ((depth+7)>>3);
476 if (FLAC__stream_encoder_get_state (flacenc->encoder) ==
477 FLAC__STREAM_ENCODER_UNINITIALIZED)
479 FLAC__StreamEncoderState state;
481 state = FLAC__stream_encoder_init (flacenc->encoder);
482 if (state != FLAC__STREAM_ENCODER_OK) {
483 gst_element_error (GST_ELEMENT (flacenc),
484 "could not initialize encoder (wrong parameters?)");
489 /* we keep a pointer in the flacenc struct because we are freeing the data
490 * after a push opreration that might never return */
491 data = flacenc->data = g_malloc (samples * sizeof (FLAC__int32));
494 gint8 *indata = (gint8 *) GST_BUFFER_DATA (buf);
496 for (i=0; i<samples; i++) {
497 data[i] = (FLAC__int32) *indata++;
500 else if (depth == 16) {
501 gint16 *indata = (gint16 *) GST_BUFFER_DATA (buf);
503 for (i=0; i<samples; i++) {
504 data[i] = (FLAC__int32) *indata++;
508 gst_buffer_unref(buf);
510 res = FLAC__stream_encoder_process_interleaved (flacenc->encoder,
511 (const FLAC__int32 *) data, samples / flacenc->channels);
513 g_free (flacenc->data);
514 flacenc->data = NULL;
517 gst_element_error (GST_ELEMENT (flacenc),
523 gst_flacenc_set_property (GObject *object, guint prop_id,
524 const GValue *value, GParamSpec *pspec)
528 this = (FlacEnc *)object;
531 gst_flacenc_update_quality (this, g_value_get_enum (value));
533 case ARG_STREAMABLE_SUBSET:
534 FLAC__stream_encoder_set_streamable_subset (this->encoder,
535 g_value_get_boolean (value));
537 case ARG_MID_SIDE_STEREO:
538 FLAC__stream_encoder_set_do_mid_side_stereo (this->encoder,
539 g_value_get_boolean (value));
541 case ARG_LOOSE_MID_SIDE_STEREO:
542 FLAC__stream_encoder_set_loose_mid_side_stereo (this->encoder,
543 g_value_get_boolean (value));
546 FLAC__stream_encoder_set_blocksize (this->encoder,
547 g_value_get_uint (value));
549 case ARG_MAX_LPC_ORDER:
550 FLAC__stream_encoder_set_max_lpc_order (this->encoder,
551 g_value_get_uint (value));
553 case ARG_QLP_COEFF_PRECISION:
554 FLAC__stream_encoder_set_qlp_coeff_precision (this->encoder,
555 g_value_get_uint (value));
557 case ARG_QLP_COEFF_PREC_SEARCH:
558 FLAC__stream_encoder_set_do_qlp_coeff_prec_search (this->encoder,
559 g_value_get_boolean (value));
561 case ARG_ESCAPE_CODING:
562 FLAC__stream_encoder_set_do_escape_coding (this->encoder,
563 g_value_get_boolean (value));
565 case ARG_EXHAUSTIVE_MODEL_SEARCH:
566 FLAC__stream_encoder_set_do_exhaustive_model_search (this->encoder,
567 g_value_get_boolean (value));
569 case ARG_MIN_RESIDUAL_PARTITION_ORDER:
570 FLAC__stream_encoder_set_min_residual_partition_order (this->encoder,
571 g_value_get_uint (value));
573 case ARG_MAX_RESIDUAL_PARTITION_ORDER:
574 FLAC__stream_encoder_set_max_residual_partition_order (this->encoder,
575 g_value_get_uint (value));
577 case ARG_RICE_PARAMETER_SEARCH_DIST:
578 FLAC__stream_encoder_set_rice_parameter_search_dist (this->encoder,
579 g_value_get_uint (value));
582 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
588 gst_flacenc_get_property (GObject *object, guint prop_id,
589 GValue *value, GParamSpec *pspec)
593 this = (FlacEnc *)object;
597 g_value_set_enum (value, this->quality);
599 case ARG_STREAMABLE_SUBSET:
600 g_value_set_boolean (value,
601 FLAC__stream_encoder_get_streamable_subset (this->encoder));
603 case ARG_MID_SIDE_STEREO:
604 g_value_set_boolean (value,
605 FLAC__stream_encoder_get_do_mid_side_stereo (this->encoder));
607 case ARG_LOOSE_MID_SIDE_STEREO:
608 g_value_set_boolean (value,
609 FLAC__stream_encoder_get_loose_mid_side_stereo (this->encoder));
612 g_value_set_uint (value,
613 FLAC__stream_encoder_get_blocksize (this->encoder));
615 case ARG_MAX_LPC_ORDER:
616 g_value_set_uint (value,
617 FLAC__stream_encoder_get_max_lpc_order (this->encoder));
619 case ARG_QLP_COEFF_PRECISION:
620 g_value_set_uint (value,
621 FLAC__stream_encoder_get_qlp_coeff_precision (this->encoder));
623 case ARG_QLP_COEFF_PREC_SEARCH:
624 g_value_set_boolean (value,
625 FLAC__stream_encoder_get_do_qlp_coeff_prec_search (this->encoder));
627 case ARG_ESCAPE_CODING:
628 g_value_set_boolean (value,
629 FLAC__stream_encoder_get_do_escape_coding (this->encoder));
631 case ARG_EXHAUSTIVE_MODEL_SEARCH:
632 g_value_set_boolean (value,
633 FLAC__stream_encoder_get_do_exhaustive_model_search (this->encoder));
635 case ARG_MIN_RESIDUAL_PARTITION_ORDER:
636 g_value_set_uint (value,
637 FLAC__stream_encoder_get_min_residual_partition_order (this->encoder));
639 case ARG_MAX_RESIDUAL_PARTITION_ORDER:
640 g_value_set_uint (value,
641 FLAC__stream_encoder_get_max_residual_partition_order (this->encoder));
643 case ARG_RICE_PARAMETER_SEARCH_DIST:
644 g_value_set_uint (value,
645 FLAC__stream_encoder_get_rice_parameter_search_dist (this->encoder));
648 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
653 static GstElementStateReturn
654 gst_flacenc_change_state (GstElement *element)
656 FlacEnc *flacenc = GST_FLACENC (element);
658 switch (GST_STATE_TRANSITION (element)) {
659 case GST_STATE_NULL_TO_READY:
660 case GST_STATE_READY_TO_PAUSED:
661 flacenc->first = TRUE;
662 flacenc->stopped = FALSE;
664 case GST_STATE_PAUSED_TO_PLAYING:
665 case GST_STATE_PLAYING_TO_PAUSED:
667 case GST_STATE_PAUSED_TO_READY:
668 if (FLAC__stream_encoder_get_state (flacenc->encoder) !=
669 FLAC__STREAM_ENCODER_UNINITIALIZED) {
670 flacenc->stopped = TRUE;
671 FLAC__stream_encoder_finish (flacenc->encoder);
673 flacenc->negotiated = FALSE;
674 if (flacenc->first_buf)
675 gst_buffer_unref (flacenc->first_buf);
676 flacenc->first_buf = NULL;
677 g_free (flacenc->data);
678 flacenc->data = NULL;
680 case GST_STATE_READY_TO_NULL:
685 if (GST_ELEMENT_CLASS (parent_class)->change_state)
686 return GST_ELEMENT_CLASS (parent_class)->change_state (element);
688 return GST_STATE_SUCCESS;