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.
27 #include <gstflacenc.h>
29 #include "flac_compat.h"
31 static GstPadTemplate *src_template, *sink_template;
33 /* elementfactory information */
34 GstElementDetails flacenc_details = {
36 "Codec/Encoder/Audio",
37 "Encodes audio with the FLAC lossless audio encoder",
38 "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_base_init (gpointer g_class);
65 static void gst_flacenc_init (FlacEnc *flacenc);
66 static void gst_flacenc_class_init (FlacEncClass *klass);
67 static void gst_flacenc_dispose (GObject *object);
69 static GstPadLinkReturn
70 gst_flacenc_sinkconnect (GstPad *pad, GstCaps *caps);
71 static void gst_flacenc_chain (GstPad *pad, GstData *_data);
73 static gboolean gst_flacenc_update_quality (FlacEnc *flacenc, gint quality);
74 static void gst_flacenc_set_property (GObject *object, guint prop_id,
75 const GValue *value, GParamSpec *pspec);
76 static void gst_flacenc_get_property (GObject *object, guint prop_id,
77 GValue *value, GParamSpec *pspec);
78 static GstElementStateReturn
79 gst_flacenc_change_state (GstElement *element);
81 static FLAC__StreamEncoderWriteStatus
82 gst_flacenc_write_callback (const FLAC__SeekableStreamEncoder *encoder,
83 const FLAC__byte buffer[], unsigned bytes,
84 unsigned samples, unsigned current_frame,
86 static FLAC__SeekableStreamEncoderSeekStatus
87 gst_flacenc_seek_callback (const FLAC__SeekableStreamEncoder *encoder,
88 FLAC__uint64 absolute_byte_offset,
91 static GstElementClass *parent_class = NULL;
92 /*static guint gst_flacenc_signals[LAST_SIGNAL] = { 0 }; */
95 flacenc_get_type (void)
97 static GType flacenc_type = 0;
100 static const GTypeInfo flacenc_info = {
101 sizeof(FlacEncClass),
102 gst_flacenc_base_init,
104 (GClassInitFunc)gst_flacenc_class_init,
109 (GInstanceInitFunc)gst_flacenc_init,
111 flacenc_type = g_type_register_static (GST_TYPE_ELEMENT, "FlacEnc", &flacenc_info, 0);
117 gboolean exhaustive_model_search;
118 gboolean escape_coding;
120 gboolean loose_mid_side;
121 guint qlp_coeff_precision;
122 gboolean qlp_coeff_prec_search;
123 guint min_residual_partition_order;
124 guint max_residual_partition_order;
125 guint rice_parameter_search_dist;
130 static const FlacEncParams flacenc_params[] =
132 { FALSE, FALSE, FALSE, FALSE, 0, FALSE, 2, 2, 0, 0, 1152 },
133 { FALSE, FALSE, TRUE, TRUE, 0, FALSE, 2, 2, 0, 0, 1152 },
134 { FALSE, FALSE, TRUE, FALSE, 0, FALSE, 0, 3, 0, 0, 1152 },
135 { FALSE, FALSE, FALSE, FALSE, 0, FALSE, 3, 3, 0, 6, 4608 },
136 { FALSE, FALSE, TRUE, TRUE, 0, FALSE, 3, 3, 0, 8, 4608 },
137 { FALSE, FALSE, TRUE, FALSE, 0, FALSE, 3, 3, 0, 8, 4608 },
138 { FALSE, FALSE, TRUE, FALSE, 0, FALSE, 0, 4, 0, 8, 4608 },
139 { TRUE, FALSE, TRUE, FALSE, 0, FALSE, 0, 6, 0, 8, 4608 },
140 { TRUE, FALSE, TRUE, FALSE, 0, FALSE, 0, 6, 0, 12, 4608 },
141 { TRUE, TRUE, TRUE, FALSE, 0, FALSE, 0, 16, 0, 32, 4608 },
144 #define DEFAULT_QUALITY 5
146 #define GST_TYPE_FLACENC_QUALITY (gst_flacenc_quality_get_type ())
148 gst_flacenc_quality_get_type (void)
150 static GType qtype = 0;
152 static const GEnumValue values[] = {
153 { 0, "0", "0 - Fastest compression" },
158 { 5, "5", "5 - Default" },
161 { 8, "8", "8 - Highest compression " },
162 { 9, "9", "9 - Insane" },
165 qtype = g_enum_register_static ("FlacEncQuality", values);
171 flac_caps_factory (void)
176 "application/x-flac",
178 "rate", GST_PROPS_INT_RANGE (11025, 48000),
179 "channels", GST_PROPS_INT_RANGE (1, 2),
184 raw_caps_factory (void)
191 "endianness", GST_PROPS_INT (G_BYTE_ORDER),
192 "signed", GST_PROPS_BOOLEAN (TRUE),
193 "width", GST_PROPS_INT (16),
194 "depth", GST_PROPS_INT (16),
195 "rate", GST_PROPS_INT_RANGE (11025, 48000),
196 "channels", GST_PROPS_INT_RANGE (1, 2),
201 gst_flacenc_base_init (gpointer g_class)
203 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
204 GstCaps *raw_caps, *flac_caps;
206 raw_caps = raw_caps_factory ();
207 flac_caps = flac_caps_factory ();
209 sink_template = gst_pad_template_new ("sink", GST_PAD_SINK,
212 src_template = gst_pad_template_new ("src", GST_PAD_SRC,
215 gst_element_class_add_pad_template (element_class, sink_template);
216 gst_element_class_add_pad_template (element_class, src_template);
217 gst_element_class_set_details (element_class, &flacenc_details);
221 gst_flacenc_class_init (FlacEncClass *klass)
223 GObjectClass *gobject_class;
224 GstElementClass *gstelement_class;
226 gobject_class = (GObjectClass*)klass;
227 gstelement_class = (GstElementClass*)klass;
229 parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
231 /* we have no properties atm so this is a bit silly */
232 gobject_class->set_property = gst_flacenc_set_property;
233 gobject_class->get_property = gst_flacenc_get_property;
234 gobject_class->dispose = gst_flacenc_dispose;
236 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_QUALITY,
237 g_param_spec_enum ("quality",
239 "Speed versus compression tradeoff",
240 GST_TYPE_FLACENC_QUALITY, DEFAULT_QUALITY, G_PARAM_READWRITE));
241 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_STREAMABLE_SUBSET,
242 g_param_spec_boolean ("streamable_subset",
244 "true to limit encoder to generating a Subset stream, else false",
245 TRUE, G_PARAM_READWRITE));
246 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MID_SIDE_STEREO,
247 g_param_spec_boolean ("mid_side_stereo",
248 "Do mid side stereo",
249 "Do mid side stereo (only for stereo input)",
250 flacenc_params[DEFAULT_QUALITY].mid_side, G_PARAM_READWRITE));
251 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LOOSE_MID_SIDE_STEREO,
252 g_param_spec_boolean ("loose_mid_side_stereo",
253 "Loose mid side stereo",
254 "Loose mid side stereo",
255 flacenc_params[DEFAULT_QUALITY].loose_mid_side, G_PARAM_READWRITE));
256 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_BLOCKSIZE,
257 g_param_spec_uint ("blocksize",
259 "Blocksize in samples",
260 FLAC__MIN_BLOCK_SIZE, FLAC__MAX_BLOCK_SIZE,
261 flacenc_params[DEFAULT_QUALITY].blocksize, G_PARAM_READWRITE));
262 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MAX_LPC_ORDER,
263 g_param_spec_uint ("max_lpc_order",
265 "Max LPC order; 0 => use only fixed predictors",
266 0, FLAC__MAX_LPC_ORDER,
267 flacenc_params[DEFAULT_QUALITY].max_lpc_order, G_PARAM_READWRITE));
268 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_QLP_COEFF_PRECISION,
269 g_param_spec_uint ("qlp_coeff_precision",
270 "QLP coefficients precision",
271 "Precision in bits of quantized linear-predictor coefficients; 0 = automatic",
273 flacenc_params[DEFAULT_QUALITY].qlp_coeff_precision, G_PARAM_READWRITE));
274 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_QLP_COEFF_PREC_SEARCH,
275 g_param_spec_boolean ("qlp_coeff_prec_search",
276 "Do QLP coefficients precision search",
277 "false = use qlp_coeff_precision, "
278 "true = search around qlp_coeff_precision, take best",
279 flacenc_params[DEFAULT_QUALITY].qlp_coeff_prec_search, G_PARAM_READWRITE));
280 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ESCAPE_CODING,
281 g_param_spec_boolean ("escape_coding",
283 "search for escape codes in the entropy coding stage "
284 "for slightly better compression",
285 flacenc_params[DEFAULT_QUALITY].escape_coding, G_PARAM_READWRITE));
286 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_EXHAUSTIVE_MODEL_SEARCH,
287 g_param_spec_boolean ("exhaustive_model_search",
288 "Do exhaustive model search",
289 "do exhaustive search of LP coefficient quantization (expensive!)",
290 flacenc_params[DEFAULT_QUALITY].exhaustive_model_search, G_PARAM_READWRITE));
291 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MIN_RESIDUAL_PARTITION_ORDER,
292 g_param_spec_uint ("min_residual_partition_order",
293 "Min residual partition order",
294 "Min residual partition order (above 4 doesn't usually help much)",
296 flacenc_params[DEFAULT_QUALITY].min_residual_partition_order, G_PARAM_READWRITE));
297 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_MAX_RESIDUAL_PARTITION_ORDER,
298 g_param_spec_uint ("max_residual_partition_order",
299 "Max residual partition order",
300 "Max residual partition order (above 4 doesn't usually help much)",
302 flacenc_params[DEFAULT_QUALITY].max_residual_partition_order, G_PARAM_READWRITE));
303 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_RICE_PARAMETER_SEARCH_DIST,
304 g_param_spec_uint ("rice_parameter_search_dist",
305 "rice_parameter_search_dist",
306 "0 = try only calc'd parameter k; else try all [k-dist..k+dist] "
307 "parameters, use best",
308 0, FLAC__MAX_RICE_PARTITION_ORDER,
309 flacenc_params[DEFAULT_QUALITY].rice_parameter_search_dist, G_PARAM_READWRITE));
311 gstelement_class->change_state = gst_flacenc_change_state;
315 gst_flacenc_init (FlacEnc *flacenc)
317 flacenc->sinkpad = gst_pad_new_from_template (sink_template, "sink");
318 gst_element_add_pad(GST_ELEMENT(flacenc),flacenc->sinkpad);
319 gst_pad_set_chain_function(flacenc->sinkpad,gst_flacenc_chain);
320 gst_pad_set_link_function (flacenc->sinkpad, gst_flacenc_sinkconnect);
322 flacenc->srcpad = gst_pad_new_from_template (src_template, "src");
323 gst_element_add_pad(GST_ELEMENT(flacenc),flacenc->srcpad);
325 GST_FLAG_SET (flacenc, GST_ELEMENT_EVENT_AWARE);
327 flacenc->encoder = FLAC__seekable_stream_encoder_new();
329 FLAC__seekable_stream_encoder_set_write_callback (flacenc->encoder,
330 gst_flacenc_write_callback);
331 FLAC__seekable_stream_encoder_set_seek_callback (flacenc->encoder,
332 gst_flacenc_seek_callback);
334 FLAC__seekable_stream_encoder_set_client_data (flacenc->encoder,
337 flacenc->metadata = GST_CAPS_NEW (
339 "application/x-gst-metadata",
340 "DESCRIPTION", GST_PROPS_STRING ("Track encoded with GStreamer"),
341 "DATE", GST_PROPS_STRING (""),
342 "TRACKNUMBER", GST_PROPS_STRING (""),
343 "TITLE", GST_PROPS_STRING (""),
344 "ARTIST", GST_PROPS_STRING (""),
345 "ALBUM", GST_PROPS_STRING (""),
346 "GENRE", GST_PROPS_STRING (""),
347 "VERSION", GST_PROPS_STRING (""),
348 "COPYRIGHT", GST_PROPS_STRING (""),
349 "LICENSE", GST_PROPS_STRING (""),
350 "ORGANISATION", GST_PROPS_STRING (""),
351 "LOCATION", GST_PROPS_STRING (""),
352 "CONTACT", GST_PROPS_STRING (""),
353 "ISRC", GST_PROPS_STRING ("")
356 flacenc->negotiated = FALSE;
357 flacenc->first = TRUE;
358 flacenc->first_buf = NULL;
359 flacenc->data = NULL;
360 gst_flacenc_update_quality (flacenc, DEFAULT_QUALITY);
364 gst_flacenc_dispose (GObject *object)
366 FlacEnc *flacenc = GST_FLACENC (object);
368 FLAC__seekable_stream_encoder_delete (flacenc->encoder);
370 G_OBJECT_CLASS (parent_class)->dispose (object);
373 static GstPadLinkReturn
374 gst_flacenc_sinkconnect (GstPad *pad, GstCaps *caps)
376 GstPadLinkReturn ret;
379 flacenc = GST_FLACENC (gst_pad_get_parent (pad));
381 if (!GST_CAPS_IS_FIXED (caps))
382 return GST_PAD_LINK_DELAYED;
384 gst_caps_get_int (caps, "channels", &flacenc->channels);
385 gst_caps_get_int (caps, "depth", &flacenc->depth);
386 gst_caps_get_int (caps, "rate", &flacenc->sample_rate);
388 caps = GST_CAPS_NEW ("flacenc_srccaps",
390 "channels", GST_PROPS_INT (flacenc->channels),
391 "rate", GST_PROPS_INT (flacenc->sample_rate));
392 ret = gst_pad_try_set_caps (flacenc->srcpad, caps);
397 FLAC__seekable_stream_encoder_set_bits_per_sample (flacenc->encoder,
399 FLAC__seekable_stream_encoder_set_sample_rate (flacenc->encoder,
400 flacenc->sample_rate);
401 FLAC__seekable_stream_encoder_set_channels (flacenc->encoder,
404 flacenc->negotiated = TRUE;
410 gst_flacenc_update_quality (FlacEnc *flacenc, gint quality)
412 flacenc->quality = quality;
414 #define DO_UPDATE(name, val, str) \
416 if (FLAC__seekable_stream_encoder_get_##name (flacenc->encoder) != \
417 flacenc_params[quality].val) { \
418 FLAC__seekable_stream_encoder_set_##name (flacenc->encoder, \
419 flacenc_params[quality].val); \
420 g_object_notify (G_OBJECT (flacenc), str); \
424 g_object_freeze_notify (G_OBJECT (flacenc));
426 DO_UPDATE (do_mid_side_stereo, mid_side, "mid_side_stereo");
427 DO_UPDATE (loose_mid_side_stereo, loose_mid_side, "loose_mid_side");
428 DO_UPDATE (blocksize, blocksize, "blocksize");
429 DO_UPDATE (max_lpc_order, max_lpc_order, "max_lpc_order");
430 DO_UPDATE (qlp_coeff_precision, qlp_coeff_precision, "qlp_coeff_precision");
431 DO_UPDATE (do_qlp_coeff_prec_search, qlp_coeff_prec_search, "qlp_coeff_prec_search");
432 DO_UPDATE (do_escape_coding, escape_coding, "escape_coding");
433 DO_UPDATE (do_exhaustive_model_search, exhaustive_model_search, "exhaustive_model_search");
434 DO_UPDATE (min_residual_partition_order, min_residual_partition_order, "min_residual_partition_order");
435 DO_UPDATE (max_residual_partition_order, max_residual_partition_order, "max_residual_partition_order");
436 DO_UPDATE (rice_parameter_search_dist, rice_parameter_search_dist, "rice_parameter_search_dist");
440 g_object_thaw_notify (G_OBJECT (flacenc));
445 static FLAC__SeekableStreamEncoderSeekStatus
446 gst_flacenc_seek_callback (const FLAC__SeekableStreamEncoder *encoder,
447 FLAC__uint64 absolute_byte_offset,
453 flacenc = GST_FLACENC (client_data);
455 if (flacenc->stopped)
456 return FLAC__STREAM_ENCODER_OK;
458 event = gst_event_new_seek ((GstSeekType)(int)(GST_FORMAT_BYTES | GST_SEEK_METHOD_SET), absolute_byte_offset);
461 gst_pad_push (flacenc->srcpad, GST_DATA (event));
463 return FLAC__STREAM_ENCODER_OK;
466 static FLAC__StreamEncoderWriteStatus
467 gst_flacenc_write_callback (const FLAC__SeekableStreamEncoder *encoder,
468 const FLAC__byte buffer[], unsigned bytes,
469 unsigned samples, unsigned current_frame,
475 flacenc = GST_FLACENC (client_data);
477 if (flacenc->stopped)
478 return FLAC__STREAM_ENCODER_OK;
480 outbuf = gst_buffer_new_and_alloc (bytes);
482 memcpy (GST_BUFFER_DATA (outbuf), buffer, bytes);
484 if (flacenc->first) {
485 flacenc->first_buf = outbuf;
486 gst_buffer_ref (outbuf);
487 flacenc->first = FALSE;
490 gst_pad_push (flacenc->srcpad, GST_DATA (outbuf));
492 return FLAC__STREAM_ENCODER_OK;
496 gst_flacenc_set_metadata (FlacEnc *flacenc, GstCaps *caps)
500 const gchar *meta_types[] = { "TITLE", "VERSION", "ALBUM", "TRACKNUMBER",
501 "ARTIST", "PERFORMER", "COPYRIGHT", "LICENSE",
502 "ORGANISATION", "DESCRIPTION", "GENRE", "DATE",
503 "LOCATION", "CONTACT", "ISRC", NULL };
505 g_return_if_fail (flacenc != NULL);
507 flacenc->meta = g_malloc (sizeof (FLAC__StreamMetadata **));
509 flacenc->meta[0] = FLAC__metadata_object_new (FLAC__METADATA_TYPE_VORBIS_COMMENT);
511 for ( indice = 0, comments=0; meta_types[indice] != NULL; indice++) {
512 if (gst_caps_has_property(caps, meta_types[indice])) {
515 FLAC__StreamMetadata_VorbisComment_Entry commment_entry;
517 gst_caps_get_string(caps, (gchar *)meta_types[indice], &entry);
519 if (!strcmp (entry, ""))
522 data = g_strdup_printf("%s=%s", meta_types[indice], entry);
523 commment_entry.length = GUINT32_TO_LE (strlen(entry) + strlen(meta_types[indice]) + 1);
524 commment_entry.entry = g_convert (data, commment_entry.length, "UTF8", "ISO-8859-1", NULL, NULL, NULL);
526 FLAC__metadata_object_vorbiscomment_insert_comment (flacenc->meta[0], comments++, commment_entry, TRUE);
530 FLAC__seekable_stream_encoder_set_metadata(flacenc->encoder, flacenc->meta, 1);
536 gst_flacenc_chain (GstPad *pad, GstData *_data)
538 GstBuffer *buf = GST_BUFFER (_data);
546 g_return_if_fail(buf != NULL);
548 flacenc = GST_FLACENC (gst_pad_get_parent (pad));
550 if (GST_IS_EVENT (buf)) {
551 GstEvent *event = GST_EVENT (buf);
553 switch (GST_EVENT_TYPE (event)) {
555 FLAC__seekable_stream_encoder_finish(flacenc->encoder);
557 gst_pad_event_default (pad, event);
563 if (!flacenc->negotiated) {
564 gst_element_error (GST_ELEMENT (flacenc),
565 "format not negotiated");
569 depth = flacenc->depth;
571 insize = GST_BUFFER_SIZE (buf);
572 samples = insize / ((depth+7)>>3);
574 if (FLAC__seekable_stream_encoder_get_state (flacenc->encoder) ==
575 FLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED)
577 FLAC__SeekableStreamEncoderState state;
579 gst_flacenc_set_metadata (flacenc, flacenc->metadata);
580 state = FLAC__seekable_stream_encoder_init (flacenc->encoder);
581 if (state != FLAC__STREAM_ENCODER_OK) {
582 gst_element_error (GST_ELEMENT (flacenc),
583 "could not initialize encoder (wrong parameters?)");
588 /* we keep a pointer in the flacenc struct because we are freeing the data
589 * after a push opreration that might never return */
590 data = flacenc->data = g_malloc (samples * sizeof (FLAC__int32));
593 gint8 *indata = (gint8 *) GST_BUFFER_DATA (buf);
596 for (i=0; i<samples; i++) {
597 data[i] = (FLAC__int32) *indata++;
600 else if (depth == 16) {
601 gint16 *indata = (gint16 *) GST_BUFFER_DATA (buf);
603 for (i=0; i<samples; i++) {
604 data[i] = (FLAC__int32) *indata++;
608 gst_buffer_unref(buf);
610 res = FLAC__seekable_stream_encoder_process_interleaved (flacenc->encoder,
611 (const FLAC__int32 *) data, samples / flacenc->channels);
613 g_free (flacenc->data);
614 flacenc->data = NULL;
617 gst_element_error (GST_ELEMENT (flacenc),
623 gst_flacenc_set_property (GObject *object, guint prop_id,
624 const GValue *value, GParamSpec *pspec)
628 this = (FlacEnc *)object;
631 gst_flacenc_update_quality (this, g_value_get_enum (value));
633 case ARG_STREAMABLE_SUBSET:
634 FLAC__seekable_stream_encoder_set_streamable_subset (this->encoder,
635 g_value_get_boolean (value));
637 case ARG_MID_SIDE_STEREO:
638 FLAC__seekable_stream_encoder_set_do_mid_side_stereo (this->encoder,
639 g_value_get_boolean (value));
641 case ARG_LOOSE_MID_SIDE_STEREO:
642 FLAC__seekable_stream_encoder_set_loose_mid_side_stereo (this->encoder,
643 g_value_get_boolean (value));
646 FLAC__seekable_stream_encoder_set_blocksize (this->encoder,
647 g_value_get_uint (value));
649 case ARG_MAX_LPC_ORDER:
650 FLAC__seekable_stream_encoder_set_max_lpc_order (this->encoder,
651 g_value_get_uint (value));
653 case ARG_QLP_COEFF_PRECISION:
654 FLAC__seekable_stream_encoder_set_qlp_coeff_precision (this->encoder,
655 g_value_get_uint (value));
657 case ARG_QLP_COEFF_PREC_SEARCH:
658 FLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search (this->encoder,
659 g_value_get_boolean (value));
661 case ARG_ESCAPE_CODING:
662 FLAC__seekable_stream_encoder_set_do_escape_coding (this->encoder,
663 g_value_get_boolean (value));
665 case ARG_EXHAUSTIVE_MODEL_SEARCH:
666 FLAC__seekable_stream_encoder_set_do_exhaustive_model_search (this->encoder,
667 g_value_get_boolean (value));
669 case ARG_MIN_RESIDUAL_PARTITION_ORDER:
670 FLAC__seekable_stream_encoder_set_min_residual_partition_order (this->encoder,
671 g_value_get_uint (value));
673 case ARG_MAX_RESIDUAL_PARTITION_ORDER:
674 FLAC__seekable_stream_encoder_set_max_residual_partition_order (this->encoder,
675 g_value_get_uint (value));
677 case ARG_RICE_PARAMETER_SEARCH_DIST:
678 FLAC__seekable_stream_encoder_set_rice_parameter_search_dist (this->encoder,
679 g_value_get_uint (value));
682 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
688 gst_flacenc_get_property (GObject *object, guint prop_id,
689 GValue *value, GParamSpec *pspec)
693 this = (FlacEnc *)object;
697 g_value_set_enum (value, this->quality);
699 case ARG_STREAMABLE_SUBSET:
700 g_value_set_boolean (value,
701 FLAC__seekable_stream_encoder_get_streamable_subset (this->encoder));
703 case ARG_MID_SIDE_STEREO:
704 g_value_set_boolean (value,
705 FLAC__seekable_stream_encoder_get_do_mid_side_stereo (this->encoder));
707 case ARG_LOOSE_MID_SIDE_STEREO:
708 g_value_set_boolean (value,
709 FLAC__seekable_stream_encoder_get_loose_mid_side_stereo (this->encoder));
712 g_value_set_uint (value,
713 FLAC__seekable_stream_encoder_get_blocksize (this->encoder));
715 case ARG_MAX_LPC_ORDER:
716 g_value_set_uint (value,
717 FLAC__seekable_stream_encoder_get_max_lpc_order (this->encoder));
719 case ARG_QLP_COEFF_PRECISION:
720 g_value_set_uint (value,
721 FLAC__seekable_stream_encoder_get_qlp_coeff_precision (this->encoder));
723 case ARG_QLP_COEFF_PREC_SEARCH:
724 g_value_set_boolean (value,
725 FLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search (this->encoder));
727 case ARG_ESCAPE_CODING:
728 g_value_set_boolean (value,
729 FLAC__seekable_stream_encoder_get_do_escape_coding (this->encoder));
731 case ARG_EXHAUSTIVE_MODEL_SEARCH:
732 g_value_set_boolean (value,
733 FLAC__seekable_stream_encoder_get_do_exhaustive_model_search (this->encoder));
735 case ARG_MIN_RESIDUAL_PARTITION_ORDER:
736 g_value_set_uint (value,
737 FLAC__seekable_stream_encoder_get_min_residual_partition_order (this->encoder));
739 case ARG_MAX_RESIDUAL_PARTITION_ORDER:
740 g_value_set_uint (value,
741 FLAC__seekable_stream_encoder_get_max_residual_partition_order (this->encoder));
743 case ARG_RICE_PARAMETER_SEARCH_DIST:
744 g_value_set_uint (value,
745 FLAC__seekable_stream_encoder_get_rice_parameter_search_dist (this->encoder));
748 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
753 static GstElementStateReturn
754 gst_flacenc_change_state (GstElement *element)
756 FlacEnc *flacenc = GST_FLACENC (element);
758 switch (GST_STATE_TRANSITION (element)) {
759 case GST_STATE_NULL_TO_READY:
760 case GST_STATE_READY_TO_PAUSED:
761 flacenc->first = TRUE;
762 flacenc->stopped = FALSE;
764 case GST_STATE_PAUSED_TO_PLAYING:
765 case GST_STATE_PLAYING_TO_PAUSED:
767 case GST_STATE_PAUSED_TO_READY:
768 if (FLAC__seekable_stream_encoder_get_state (flacenc->encoder) !=
769 FLAC__STREAM_ENCODER_UNINITIALIZED) {
770 flacenc->stopped = TRUE;
771 FLAC__seekable_stream_encoder_finish (flacenc->encoder);
773 flacenc->negotiated = FALSE;
774 if (flacenc->first_buf)
775 gst_buffer_unref (flacenc->first_buf);
776 flacenc->first_buf = NULL;
777 g_free (flacenc->data);
778 flacenc->data = NULL;
779 FLAC__metadata_object_delete (flacenc->meta[0]);
780 g_free (flacenc->meta);
782 case GST_STATE_READY_TO_NULL:
787 if (GST_ELEMENT_CLASS (parent_class)->change_state)
788 return GST_ELEMENT_CLASS (parent_class)->change_state (element);
790 return GST_STATE_SUCCESS;