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 GstPadLinkReturn
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__SeekableStreamEncoder *encoder,
82 const FLAC__byte buffer[], unsigned bytes,
83 unsigned samples, unsigned current_frame,
85 static FLAC__SeekableStreamEncoderSeekStatus
86 gst_flacenc_seek_callback (const FLAC__SeekableStreamEncoder *encoder,
87 FLAC__uint64 absolute_byte_offset,
90 static GstElementClass *parent_class = NULL;
91 /*static guint gst_flacenc_signals[LAST_SIGNAL] = { 0 }; */
94 flacenc_get_type (void)
96 static GType flacenc_type = 0;
99 static const GTypeInfo flacenc_info = {
100 sizeof(FlacEncClass),
103 (GClassInitFunc)gst_flacenc_class_init,
108 (GInstanceInitFunc)gst_flacenc_init,
110 flacenc_type = g_type_register_static (GST_TYPE_ELEMENT, "FlacEnc", &flacenc_info, 0);
116 gboolean exhaustive_model_search;
117 gboolean escape_coding;
119 gboolean loose_mid_side;
120 guint qlp_coeff_precision;
121 gboolean qlp_coeff_prec_search;
122 guint min_residual_partition_order;
123 guint max_residual_partition_order;
124 guint rice_parameter_search_dist;
129 static const FlacEncParams flacenc_params[] =
131 { FALSE, FALSE, FALSE, FALSE, 0, FALSE, 2, 2, 0, 0, 1152 },
132 { FALSE, FALSE, TRUE, TRUE, 0, FALSE, 2, 2, 0, 0, 1152 },
133 { FALSE, FALSE, TRUE, FALSE, 0, FALSE, 0, 3, 0, 0, 1152 },
134 { FALSE, FALSE, FALSE, FALSE, 0, FALSE, 3, 3, 0, 6, 4608 },
135 { FALSE, FALSE, TRUE, TRUE, 0, FALSE, 3, 3, 0, 8, 4608 },
136 { FALSE, FALSE, TRUE, FALSE, 0, FALSE, 3, 3, 0, 8, 4608 },
137 { FALSE, FALSE, TRUE, FALSE, 0, FALSE, 0, 4, 0, 8, 4608 },
138 { TRUE, FALSE, TRUE, FALSE, 0, FALSE, 0, 6, 0, 8, 4608 },
139 { TRUE, FALSE, TRUE, FALSE, 0, FALSE, 0, 6, 0, 12, 4608 },
140 { TRUE, TRUE, TRUE, FALSE, 0, FALSE, 0, 16, 0, 32, 4608 },
143 #define DEFAULT_QUALITY 5
145 #define GST_TYPE_FLACENC_QUALITY (gst_flacenc_quality_get_type ())
147 gst_flacenc_quality_get_type (void)
149 static GType qtype = 0;
151 static const GEnumValue values[] = {
152 { 0, "0", "0 - Fastest compression" },
157 { 5, "5", "5 - Default" },
160 { 8, "8", "8 - Highest compression " },
161 { 9, "9", "9 - Insane" },
164 qtype = g_enum_register_static ("FlacEncQuality", values);
170 gst_flacenc_class_init (FlacEncClass *klass)
172 GObjectClass *gobject_class;
173 GstElementClass *gstelement_class;
175 gobject_class = (GObjectClass*)klass;
176 gstelement_class = (GstElementClass*)klass;
178 parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
180 /* we have no properties atm so this is a bit silly */
181 gobject_class->set_property = gst_flacenc_set_property;
182 gobject_class->get_property = gst_flacenc_get_property;
183 gobject_class->dispose = gst_flacenc_dispose;
185 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_QUALITY,
186 g_param_spec_enum ("quality",
188 "Speed versus compression tradeoff",
189 GST_TYPE_FLACENC_QUALITY, DEFAULT_QUALITY, G_PARAM_READWRITE));
190 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_STREAMABLE_SUBSET,
191 g_param_spec_boolean ("streamable_subset",
193 "true to limit encoder to generating a Subset stream, else false",
194 TRUE, G_PARAM_READWRITE));
195 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MID_SIDE_STEREO,
196 g_param_spec_boolean ("mid_side_stereo",
197 "Do mid side stereo",
198 "Do mid side stereo (only for stereo input)",
199 flacenc_params[DEFAULT_QUALITY].mid_side, G_PARAM_READWRITE));
200 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LOOSE_MID_SIDE_STEREO,
201 g_param_spec_boolean ("loose_mid_side_stereo",
202 "Loose mid side stereo",
203 "Loose mid side stereo",
204 flacenc_params[DEFAULT_QUALITY].loose_mid_side, G_PARAM_READWRITE));
205 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_BLOCKSIZE,
206 g_param_spec_uint ("blocksize",
208 "Blocksize in samples",
209 FLAC__MIN_BLOCK_SIZE, FLAC__MAX_BLOCK_SIZE,
210 flacenc_params[DEFAULT_QUALITY].blocksize, G_PARAM_READWRITE));
211 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MAX_LPC_ORDER,
212 g_param_spec_uint ("max_lpc_order",
214 "Max LPC order; 0 => use only fixed predictors",
215 0, FLAC__MAX_LPC_ORDER,
216 flacenc_params[DEFAULT_QUALITY].max_lpc_order, G_PARAM_READWRITE));
217 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_QLP_COEFF_PRECISION,
218 g_param_spec_uint ("qlp_coeff_precision",
219 "QLP coefficients precision",
220 "Precision in bits of quantized linear-predictor coefficients; 0 = automatic",
222 flacenc_params[DEFAULT_QUALITY].qlp_coeff_precision, G_PARAM_READWRITE));
223 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_QLP_COEFF_PREC_SEARCH,
224 g_param_spec_boolean ("qlp_coeff_prec_search",
225 "Do QLP coefficients precision search",
226 "false = use qlp_coeff_precision, "
227 "true = search around qlp_coeff_precision, take best",
228 flacenc_params[DEFAULT_QUALITY].qlp_coeff_prec_search, G_PARAM_READWRITE));
229 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ESCAPE_CODING,
230 g_param_spec_boolean ("escape_coding",
232 "search for escape codes in the entropy coding stage "
233 "for slightly better compression",
234 flacenc_params[DEFAULT_QUALITY].escape_coding, G_PARAM_READWRITE));
235 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_EXHAUSTIVE_MODEL_SEARCH,
236 g_param_spec_boolean ("exhaustive_model_search",
237 "Do exhaustive model search",
238 "do exhaustive search of LP coefficient quantization (expensive!)",
239 flacenc_params[DEFAULT_QUALITY].exhaustive_model_search, G_PARAM_READWRITE));
240 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MIN_RESIDUAL_PARTITION_ORDER,
241 g_param_spec_uint ("min_residual_partition_order",
242 "Min residual partition order",
243 "Min residual partition order (above 4 doesn't usually help much)",
245 flacenc_params[DEFAULT_QUALITY].min_residual_partition_order, G_PARAM_READWRITE));
246 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MAX_RESIDUAL_PARTITION_ORDER,
247 g_param_spec_uint ("max_residual_partition_order",
248 "Max residual partition order",
249 "Max residual partition order (above 4 doesn't usually help much)",
251 flacenc_params[DEFAULT_QUALITY].max_residual_partition_order, G_PARAM_READWRITE));
252 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_RICE_PARAMETER_SEARCH_DIST,
253 g_param_spec_uint ("rice_parameter_search_dist",
254 "rice_parameter_search_dist",
255 "0 = try only calc'd parameter k; else try all [k-dist..k+dist] "
256 "parameters, use best",
257 0, FLAC__MAX_RICE_PARTITION_ORDER,
258 flacenc_params[DEFAULT_QUALITY].rice_parameter_search_dist, G_PARAM_READWRITE));
260 gstelement_class->change_state = gst_flacenc_change_state;
264 gst_flacenc_init (FlacEnc *flacenc)
266 flacenc->sinkpad = gst_pad_new_from_template (gst_flacenc_sink_template, "sink");
267 gst_element_add_pad(GST_ELEMENT(flacenc),flacenc->sinkpad);
268 gst_pad_set_chain_function(flacenc->sinkpad,gst_flacenc_chain);
269 gst_pad_set_link_function (flacenc->sinkpad, gst_flacenc_sinkconnect);
271 flacenc->srcpad = gst_pad_new_from_template (gst_flacenc_src_template, "src");
272 gst_element_add_pad(GST_ELEMENT(flacenc),flacenc->srcpad);
274 GST_FLAG_SET (flacenc, GST_ELEMENT_EVENT_AWARE);
276 flacenc->encoder = FLAC__seekable_stream_encoder_new();
278 FLAC__seekable_stream_encoder_set_write_callback (flacenc->encoder,
279 gst_flacenc_write_callback);
280 FLAC__seekable_stream_encoder_set_seek_callback (flacenc->encoder,
281 gst_flacenc_seek_callback);
283 FLAC__seekable_stream_encoder_set_client_data (flacenc->encoder,
286 flacenc->metadata = GST_CAPS_NEW (
288 "application/x-gst-metadata",
289 "DESCRIPTION", GST_PROPS_STRING ("Track encoded with GStreamer"),
290 "DATE", GST_PROPS_STRING (""),
291 "TRACKNUMBER", GST_PROPS_STRING (""),
292 "TITLE", GST_PROPS_STRING (""),
293 "ARTIST", GST_PROPS_STRING (""),
294 "ALBUM", GST_PROPS_STRING (""),
295 "GENRE", GST_PROPS_STRING (""),
296 "VERSION", GST_PROPS_STRING (""),
297 "COPYRIGHT", GST_PROPS_STRING (""),
298 "LICENSE", GST_PROPS_STRING (""),
299 "ORGANISATION", GST_PROPS_STRING (""),
300 "LOCATION", GST_PROPS_STRING (""),
301 "CONTACT", GST_PROPS_STRING (""),
302 "ISRC", GST_PROPS_STRING ("")
305 flacenc->negotiated = FALSE;
306 flacenc->first = TRUE;
307 flacenc->first_buf = NULL;
308 flacenc->data = NULL;
309 gst_flacenc_update_quality (flacenc, DEFAULT_QUALITY);
313 gst_flacenc_dispose (GObject *object)
315 FlacEnc *flacenc = GST_FLACENC (object);
317 FLAC__seekable_stream_encoder_delete (flacenc->encoder);
319 G_OBJECT_CLASS (parent_class)->dispose (object);
322 static GstPadLinkReturn
323 gst_flacenc_sinkconnect (GstPad *pad, GstCaps *caps)
327 flacenc = GST_FLACENC (gst_pad_get_parent (pad));
329 if (!GST_CAPS_IS_FIXED (caps))
330 return GST_PAD_LINK_DELAYED;
332 gst_caps_get_int (caps, "channels", &flacenc->channels);
333 gst_caps_get_int (caps, "depth", &flacenc->depth);
334 gst_caps_get_int (caps, "rate", &flacenc->sample_rate);
336 FLAC__seekable_stream_encoder_set_bits_per_sample (flacenc->encoder,
338 FLAC__seekable_stream_encoder_set_sample_rate (flacenc->encoder,
339 flacenc->sample_rate);
340 FLAC__seekable_stream_encoder_set_channels (flacenc->encoder,
343 flacenc->negotiated = TRUE;
345 return GST_PAD_LINK_OK;
349 gst_flacenc_update_quality (FlacEnc *flacenc, gint quality)
351 flacenc->quality = quality;
353 #define DO_UPDATE(name, val, str) \
355 if (FLAC__seekable_stream_encoder_get_##name (flacenc->encoder) != \
356 flacenc_params[quality].val) { \
357 FLAC__seekable_stream_encoder_set_##name (flacenc->encoder, \
358 flacenc_params[quality].val); \
359 g_object_notify (G_OBJECT (flacenc), str); \
363 g_object_freeze_notify (G_OBJECT (flacenc));
365 DO_UPDATE (do_mid_side_stereo, mid_side, "mid_side_stereo");
366 DO_UPDATE (loose_mid_side_stereo, loose_mid_side, "loose_mid_side");
367 DO_UPDATE (blocksize, blocksize, "blocksize");
368 DO_UPDATE (max_lpc_order, max_lpc_order, "max_lpc_order");
369 DO_UPDATE (qlp_coeff_precision, qlp_coeff_precision, "qlp_coeff_precision");
370 DO_UPDATE (do_qlp_coeff_prec_search, qlp_coeff_prec_search, "qlp_coeff_prec_search");
371 DO_UPDATE (do_escape_coding, escape_coding, "escape_coding");
372 DO_UPDATE (do_exhaustive_model_search, exhaustive_model_search, "exhaustive_model_search");
373 DO_UPDATE (min_residual_partition_order, min_residual_partition_order, "min_residual_partition_order");
374 DO_UPDATE (max_residual_partition_order, max_residual_partition_order, "max_residual_partition_order");
375 DO_UPDATE (rice_parameter_search_dist, rice_parameter_search_dist, "rice_parameter_search_dist");
379 g_object_thaw_notify (G_OBJECT (flacenc));
384 static FLAC__SeekableStreamEncoderSeekStatus
385 gst_flacenc_seek_callback (const FLAC__SeekableStreamEncoder *encoder,
386 FLAC__uint64 absolute_byte_offset,
392 flacenc = GST_FLACENC (client_data);
394 if (flacenc->stopped)
395 return FLAC__STREAM_ENCODER_OK;
397 event = gst_event_new_seek ((GstSeekType)(int)(GST_FORMAT_BYTES | GST_SEEK_METHOD_SET), absolute_byte_offset);
400 gst_pad_push (flacenc->srcpad, GST_BUFFER (event));
402 return FLAC__STREAM_ENCODER_OK;
405 static FLAC__StreamEncoderWriteStatus
406 gst_flacenc_write_callback (const FLAC__SeekableStreamEncoder *encoder,
407 const FLAC__byte buffer[], unsigned bytes,
408 unsigned samples, unsigned current_frame,
414 flacenc = GST_FLACENC (client_data);
416 if (flacenc->stopped)
417 return FLAC__STREAM_ENCODER_OK;
419 outbuf = gst_buffer_new_and_alloc (bytes);
421 memcpy (GST_BUFFER_DATA (outbuf), buffer, bytes);
423 if (flacenc->first) {
424 flacenc->first_buf = outbuf;
425 gst_buffer_ref (outbuf);
426 flacenc->first = FALSE;
429 gst_pad_push (flacenc->srcpad, outbuf);
431 return FLAC__STREAM_ENCODER_OK;
435 gst_flacenc_set_metadata (FlacEnc *flacenc, GstCaps *caps)
439 const gchar *meta_types[] = { "TITLE", "VERSION", "ALBUM", "TRACKNUMBER",
440 "ARTIST", "PERFORMER", "COPYRIGHT", "LICENSE",
441 "ORGANISATION", "DESCRIPTION", "GENRE", "DATE",
442 "LOCATION", "CONTACT", "ISRC", NULL };
444 g_return_if_fail (flacenc != NULL);
446 flacenc->meta = g_malloc (sizeof (FLAC__StreamMetadata **));
448 flacenc->meta[0] = FLAC__metadata_object_new (FLAC__METADATA_TYPE_VORBIS_COMMENT);
450 for ( indice = 0, comments=0; meta_types[indice] != NULL; indice++) {
451 if (gst_caps_has_property(caps, meta_types[indice])) {
454 FLAC__StreamMetadata_VorbisComment_Entry commment_entry;
456 gst_caps_get_string(caps, (gchar *)meta_types[indice], &entry);
458 if (!strcmp (entry, ""))
461 data = g_strdup_printf("%s=%s", meta_types[indice], entry);
462 commment_entry.length = GUINT32_TO_LE (strlen(entry) + strlen(meta_types[indice]) + 1);
463 commment_entry.entry = g_convert (data, commment_entry.length, "UTF8", "ISO-8859-1", NULL, NULL, NULL);
465 FLAC__metadata_object_vorbiscomment_insert_comment (flacenc->meta[0], comments++, commment_entry, TRUE);
469 FLAC__seekable_stream_encoder_set_metadata(flacenc->encoder, flacenc->meta, 1);
475 gst_flacenc_chain (GstPad *pad, GstBuffer *buf)
484 g_return_if_fail(buf != NULL);
486 flacenc = GST_FLACENC (gst_pad_get_parent (pad));
488 if (GST_IS_EVENT (buf)) {
489 GstEvent *event = GST_EVENT (buf);
491 switch (GST_EVENT_TYPE (event)) {
493 FLAC__seekable_stream_encoder_finish(flacenc->encoder);
495 gst_pad_event_default (pad, event);
501 if (!flacenc->negotiated) {
502 gst_element_error (GST_ELEMENT (flacenc),
503 "format not negotiated");
507 depth = flacenc->depth;
509 insize = GST_BUFFER_SIZE (buf);
510 samples = insize / ((depth+7)>>3);
512 if (FLAC__seekable_stream_encoder_get_state (flacenc->encoder) ==
513 FLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED)
515 FLAC__SeekableStreamEncoderState state;
517 gst_flacenc_set_metadata (flacenc, flacenc->metadata);
518 state = FLAC__seekable_stream_encoder_init (flacenc->encoder);
519 if (state != FLAC__STREAM_ENCODER_OK) {
520 gst_element_error (GST_ELEMENT (flacenc),
521 "could not initialize encoder (wrong parameters?)");
526 /* we keep a pointer in the flacenc struct because we are freeing the data
527 * after a push opreration that might never return */
528 data = flacenc->data = g_malloc (samples * sizeof (FLAC__int32));
531 gint8 *indata = (gint8 *) GST_BUFFER_DATA (buf);
534 for (i=0; i<samples; i++) {
535 data[i] = (FLAC__int32) *indata++;
538 else if (depth == 16) {
539 gint16 *indata = (gint16 *) GST_BUFFER_DATA (buf);
541 for (i=0; i<samples; i++) {
542 data[i] = (FLAC__int32) *indata++;
546 gst_buffer_unref(buf);
548 res = FLAC__seekable_stream_encoder_process_interleaved (flacenc->encoder,
549 (const FLAC__int32 *) data, samples / flacenc->channels);
551 g_free (flacenc->data);
552 flacenc->data = NULL;
555 gst_element_error (GST_ELEMENT (flacenc),
561 gst_flacenc_set_property (GObject *object, guint prop_id,
562 const GValue *value, GParamSpec *pspec)
566 this = (FlacEnc *)object;
569 gst_flacenc_update_quality (this, g_value_get_enum (value));
571 case ARG_STREAMABLE_SUBSET:
572 FLAC__seekable_stream_encoder_set_streamable_subset (this->encoder,
573 g_value_get_boolean (value));
575 case ARG_MID_SIDE_STEREO:
576 FLAC__seekable_stream_encoder_set_do_mid_side_stereo (this->encoder,
577 g_value_get_boolean (value));
579 case ARG_LOOSE_MID_SIDE_STEREO:
580 FLAC__seekable_stream_encoder_set_loose_mid_side_stereo (this->encoder,
581 g_value_get_boolean (value));
584 FLAC__seekable_stream_encoder_set_blocksize (this->encoder,
585 g_value_get_uint (value));
587 case ARG_MAX_LPC_ORDER:
588 FLAC__seekable_stream_encoder_set_max_lpc_order (this->encoder,
589 g_value_get_uint (value));
591 case ARG_QLP_COEFF_PRECISION:
592 FLAC__seekable_stream_encoder_set_qlp_coeff_precision (this->encoder,
593 g_value_get_uint (value));
595 case ARG_QLP_COEFF_PREC_SEARCH:
596 FLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search (this->encoder,
597 g_value_get_boolean (value));
599 case ARG_ESCAPE_CODING:
600 FLAC__seekable_stream_encoder_set_do_escape_coding (this->encoder,
601 g_value_get_boolean (value));
603 case ARG_EXHAUSTIVE_MODEL_SEARCH:
604 FLAC__seekable_stream_encoder_set_do_exhaustive_model_search (this->encoder,
605 g_value_get_boolean (value));
607 case ARG_MIN_RESIDUAL_PARTITION_ORDER:
608 FLAC__seekable_stream_encoder_set_min_residual_partition_order (this->encoder,
609 g_value_get_uint (value));
611 case ARG_MAX_RESIDUAL_PARTITION_ORDER:
612 FLAC__seekable_stream_encoder_set_max_residual_partition_order (this->encoder,
613 g_value_get_uint (value));
615 case ARG_RICE_PARAMETER_SEARCH_DIST:
616 FLAC__seekable_stream_encoder_set_rice_parameter_search_dist (this->encoder,
617 g_value_get_uint (value));
620 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
626 gst_flacenc_get_property (GObject *object, guint prop_id,
627 GValue *value, GParamSpec *pspec)
631 this = (FlacEnc *)object;
635 g_value_set_enum (value, this->quality);
637 case ARG_STREAMABLE_SUBSET:
638 g_value_set_boolean (value,
639 FLAC__seekable_stream_encoder_get_streamable_subset (this->encoder));
641 case ARG_MID_SIDE_STEREO:
642 g_value_set_boolean (value,
643 FLAC__seekable_stream_encoder_get_do_mid_side_stereo (this->encoder));
645 case ARG_LOOSE_MID_SIDE_STEREO:
646 g_value_set_boolean (value,
647 FLAC__seekable_stream_encoder_get_loose_mid_side_stereo (this->encoder));
650 g_value_set_uint (value,
651 FLAC__seekable_stream_encoder_get_blocksize (this->encoder));
653 case ARG_MAX_LPC_ORDER:
654 g_value_set_uint (value,
655 FLAC__seekable_stream_encoder_get_max_lpc_order (this->encoder));
657 case ARG_QLP_COEFF_PRECISION:
658 g_value_set_uint (value,
659 FLAC__seekable_stream_encoder_get_qlp_coeff_precision (this->encoder));
661 case ARG_QLP_COEFF_PREC_SEARCH:
662 g_value_set_boolean (value,
663 FLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search (this->encoder));
665 case ARG_ESCAPE_CODING:
666 g_value_set_boolean (value,
667 FLAC__seekable_stream_encoder_get_do_escape_coding (this->encoder));
669 case ARG_EXHAUSTIVE_MODEL_SEARCH:
670 g_value_set_boolean (value,
671 FLAC__seekable_stream_encoder_get_do_exhaustive_model_search (this->encoder));
673 case ARG_MIN_RESIDUAL_PARTITION_ORDER:
674 g_value_set_uint (value,
675 FLAC__seekable_stream_encoder_get_min_residual_partition_order (this->encoder));
677 case ARG_MAX_RESIDUAL_PARTITION_ORDER:
678 g_value_set_uint (value,
679 FLAC__seekable_stream_encoder_get_max_residual_partition_order (this->encoder));
681 case ARG_RICE_PARAMETER_SEARCH_DIST:
682 g_value_set_uint (value,
683 FLAC__seekable_stream_encoder_get_rice_parameter_search_dist (this->encoder));
686 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
691 static GstElementStateReturn
692 gst_flacenc_change_state (GstElement *element)
694 FlacEnc *flacenc = GST_FLACENC (element);
696 switch (GST_STATE_TRANSITION (element)) {
697 case GST_STATE_NULL_TO_READY:
698 case GST_STATE_READY_TO_PAUSED:
699 flacenc->first = TRUE;
700 flacenc->stopped = FALSE;
702 case GST_STATE_PAUSED_TO_PLAYING:
703 case GST_STATE_PLAYING_TO_PAUSED:
705 case GST_STATE_PAUSED_TO_READY:
706 if (FLAC__seekable_stream_encoder_get_state (flacenc->encoder) !=
707 FLAC__STREAM_ENCODER_UNINITIALIZED) {
708 flacenc->stopped = TRUE;
709 FLAC__seekable_stream_encoder_finish (flacenc->encoder);
711 flacenc->negotiated = FALSE;
712 if (flacenc->first_buf)
713 gst_buffer_unref (flacenc->first_buf);
714 flacenc->first_buf = NULL;
715 g_free (flacenc->data);
716 flacenc->data = NULL;
717 FLAC__metadata_object_delete (flacenc->meta[0]);
718 g_free (flacenc->meta);
720 case GST_STATE_READY_TO_NULL:
725 if (GST_ELEMENT_CLASS (parent_class)->change_state)
726 return GST_ELEMENT_CLASS (parent_class)->change_state (element);
728 return GST_STATE_SUCCESS;