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.
20 * SECTION:element-flacenc
21 * @see_also: #GstFlacDec
23 * flacenc encodes FLAC streams.
24 * <ulink url="http://flac.sourceforge.net/">FLAC</ulink>
25 * is a Free Lossless Audio Codec.
28 * <title>Example launch line</title>
30 * gst-launch audiotestsrc num-buffers=100 ! flacenc ! filesink location=beep.flac
35 /* TODO: - We currently don't handle discontinuities in the stream in a useful
36 * way and instead rely on the developer plugging in audiorate if
37 * the stream contains discontinuities.
46 #include <gstflacenc.h>
47 #include <gst/audio/audio.h>
48 #include <gst/tag/tag.h>
49 #include <gst/gsttagsetter.h>
51 /* Taken from http://flac.sourceforge.net/format.html#frame_header */
52 static const GstAudioChannelPosition channel_positions[8][8] = {
53 {GST_AUDIO_CHANNEL_POSITION_MONO},
54 {GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
55 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}, {
56 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
57 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
58 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER}, {
59 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
60 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
61 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
62 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT}, {
63 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
64 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
65 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
66 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
67 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT}, {
68 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
69 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
70 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
71 GST_AUDIO_CHANNEL_POSITION_LFE1,
72 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
73 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT},
74 /* FIXME: 7/8 channel layouts are not defined in the FLAC specs */
76 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
77 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
78 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
79 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
80 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
81 GST_AUDIO_CHANNEL_POSITION_LFE1,
82 GST_AUDIO_CHANNEL_POSITION_REAR_CENTER}, {
83 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
84 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
85 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
86 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
87 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
88 GST_AUDIO_CHANNEL_POSITION_LFE1,
89 GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
90 GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT}
93 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
94 #define FORMATS "{ S8LE, S16LE, S24LE, S24_32LE } "
96 #define FORMATS "{ S8BE, S16BE, S24BE, S24_32BE } "
99 #define FLAC_SINK_CAPS \
101 "format = (string) " FORMATS ", " \
102 "layout = (string) interleaved, " \
103 "rate = (int) [ 1, 655350 ], " \
104 "channels = (int) [ 1, 8 ]"
106 static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
109 GST_STATIC_CAPS ("audio/x-flac")
112 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
115 GST_STATIC_CAPS (FLAC_SINK_CAPS)
122 PROP_STREAMABLE_SUBSET,
123 PROP_MID_SIDE_STEREO,
124 PROP_LOOSE_MID_SIDE_STEREO,
127 PROP_QLP_COEFF_PRECISION,
128 PROP_QLP_COEFF_PREC_SEARCH,
130 PROP_EXHAUSTIVE_MODEL_SEARCH,
131 PROP_MIN_RESIDUAL_PARTITION_ORDER,
132 PROP_MAX_RESIDUAL_PARTITION_ORDER,
133 PROP_RICE_PARAMETER_SEARCH_DIST,
138 GST_DEBUG_CATEGORY_STATIC (flacenc_debug);
139 #define GST_CAT_DEFAULT flacenc_debug
141 #define gst_flac_enc_parent_class parent_class
142 G_DEFINE_TYPE_WITH_CODE (GstFlacEnc, gst_flac_enc, GST_TYPE_AUDIO_ENCODER,
143 G_IMPLEMENT_INTERFACE (GST_TYPE_TAG_SETTER, NULL));
145 static gboolean gst_flac_enc_start (GstAudioEncoder * enc);
146 static gboolean gst_flac_enc_stop (GstAudioEncoder * enc);
147 static gboolean gst_flac_enc_set_format (GstAudioEncoder * enc,
148 GstAudioInfo * info);
149 static GstFlowReturn gst_flac_enc_handle_frame (GstAudioEncoder * enc,
151 static GstCaps *gst_flac_enc_getcaps (GstAudioEncoder * enc, GstCaps * filter);
152 static gboolean gst_flac_enc_sink_event (GstAudioEncoder * enc,
155 static void gst_flac_enc_finalize (GObject * object);
157 static gboolean gst_flac_enc_update_quality (GstFlacEnc * flacenc,
159 static void gst_flac_enc_set_property (GObject * object, guint prop_id,
160 const GValue * value, GParamSpec * pspec);
161 static void gst_flac_enc_get_property (GObject * object, guint prop_id,
162 GValue * value, GParamSpec * pspec);
164 static FLAC__StreamEncoderWriteStatus
165 gst_flac_enc_write_callback (const FLAC__StreamEncoder * encoder,
166 const FLAC__byte buffer[], size_t bytes,
167 unsigned samples, unsigned current_frame, void *client_data);
168 static FLAC__StreamEncoderSeekStatus
169 gst_flac_enc_seek_callback (const FLAC__StreamEncoder * encoder,
170 FLAC__uint64 absolute_byte_offset, void *client_data);
171 static FLAC__StreamEncoderTellStatus
172 gst_flac_enc_tell_callback (const FLAC__StreamEncoder * encoder,
173 FLAC__uint64 * absolute_byte_offset, void *client_data);
177 gboolean exhaustive_model_search;
178 gboolean escape_coding;
180 gboolean loose_mid_side;
181 guint qlp_coeff_precision;
182 gboolean qlp_coeff_prec_search;
183 guint min_residual_partition_order;
184 guint max_residual_partition_order;
185 guint rice_parameter_search_dist;
191 static const GstFlacEncParams flacenc_params[] = {
192 {FALSE, FALSE, FALSE, FALSE, 0, FALSE, 2, 2, 0, 0, 1152},
193 {FALSE, FALSE, TRUE, TRUE, 0, FALSE, 2, 2, 0, 0, 1152},
194 {FALSE, FALSE, TRUE, FALSE, 0, FALSE, 0, 3, 0, 0, 1152},
195 {FALSE, FALSE, FALSE, FALSE, 0, FALSE, 3, 3, 0, 6, 4608},
196 {FALSE, FALSE, TRUE, TRUE, 0, FALSE, 3, 3, 0, 8, 4608},
197 {FALSE, FALSE, TRUE, FALSE, 0, FALSE, 3, 3, 0, 8, 4608},
198 {FALSE, FALSE, TRUE, FALSE, 0, FALSE, 0, 4, 0, 8, 4608},
199 {TRUE, FALSE, TRUE, FALSE, 0, FALSE, 0, 6, 0, 8, 4608},
200 {TRUE, FALSE, TRUE, FALSE, 0, FALSE, 0, 6, 0, 12, 4608},
201 {TRUE, TRUE, TRUE, FALSE, 0, FALSE, 0, 16, 0, 32, 4608},
204 #define DEFAULT_QUALITY 5
205 #define DEFAULT_PADDING 0
206 #define DEFAULT_SEEKPOINTS -10
208 #define GST_TYPE_FLAC_ENC_QUALITY (gst_flac_enc_quality_get_type ())
210 gst_flac_enc_quality_get_type (void)
212 static GType qtype = 0;
215 static const GEnumValue values[] = {
216 {0, "0 - Fastest compression", "0"},
221 {5, "5 - Default", "5"},
224 {8, "8 - Highest compression", "8"},
225 {9, "9 - Insane", "9"},
229 qtype = g_enum_register_static ("GstFlacEncQuality", values);
235 gst_flac_enc_class_init (GstFlacEncClass * klass)
237 GObjectClass *gobject_class;
238 GstElementClass *gstelement_class;
239 GstAudioEncoderClass *base_class;
241 gobject_class = (GObjectClass *) klass;
242 gstelement_class = (GstElementClass *) klass;
243 base_class = (GstAudioEncoderClass *) (klass);
245 GST_DEBUG_CATEGORY_INIT (flacenc_debug, "flacenc", 0,
246 "Flac encoding element");
248 gobject_class->set_property = gst_flac_enc_set_property;
249 gobject_class->get_property = gst_flac_enc_get_property;
250 gobject_class->finalize = gst_flac_enc_finalize;
252 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_QUALITY,
253 g_param_spec_enum ("quality",
255 "Speed versus compression tradeoff",
256 GST_TYPE_FLAC_ENC_QUALITY, DEFAULT_QUALITY,
257 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
258 g_object_class_install_property (G_OBJECT_CLASS (klass),
259 PROP_STREAMABLE_SUBSET, g_param_spec_boolean ("streamable-subset",
261 "true to limit encoder to generating a Subset stream, else false",
263 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
264 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_MID_SIDE_STEREO,
265 g_param_spec_boolean ("mid-side-stereo", "Do mid side stereo",
266 "Do mid side stereo (only for stereo input)",
267 flacenc_params[DEFAULT_QUALITY].mid_side,
268 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
269 g_object_class_install_property (G_OBJECT_CLASS (klass),
270 PROP_LOOSE_MID_SIDE_STEREO, g_param_spec_boolean ("loose-mid-side-stereo",
271 "Loose mid side stereo", "Loose mid side stereo",
272 flacenc_params[DEFAULT_QUALITY].loose_mid_side,
273 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
274 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_BLOCKSIZE,
275 g_param_spec_uint ("blocksize", "Blocksize", "Blocksize in samples",
276 FLAC__MIN_BLOCK_SIZE, FLAC__MAX_BLOCK_SIZE,
277 flacenc_params[DEFAULT_QUALITY].blocksize,
278 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
279 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_MAX_LPC_ORDER,
280 g_param_spec_uint ("max-lpc-order", "Max LPC order",
281 "Max LPC order; 0 => use only fixed predictors", 0,
282 FLAC__MAX_LPC_ORDER, flacenc_params[DEFAULT_QUALITY].max_lpc_order,
283 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
284 g_object_class_install_property (G_OBJECT_CLASS (klass),
285 PROP_QLP_COEFF_PRECISION, g_param_spec_uint ("qlp-coeff-precision",
286 "QLP coefficients precision",
287 "Precision in bits of quantized linear-predictor coefficients; 0 = automatic",
288 0, 32, flacenc_params[DEFAULT_QUALITY].qlp_coeff_precision,
289 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
290 g_object_class_install_property (G_OBJECT_CLASS (klass),
291 PROP_QLP_COEFF_PREC_SEARCH, g_param_spec_boolean ("qlp-coeff-prec-search",
292 "Do QLP coefficients precision search",
293 "false = use qlp_coeff_precision, "
294 "true = search around qlp_coeff_precision, take best",
295 flacenc_params[DEFAULT_QUALITY].qlp_coeff_prec_search,
296 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
297 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_ESCAPE_CODING,
298 g_param_spec_boolean ("escape-coding", "Do Escape coding",
299 "search for escape codes in the entropy coding stage "
300 "for slightly better compression",
301 flacenc_params[DEFAULT_QUALITY].escape_coding,
302 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
303 g_object_class_install_property (G_OBJECT_CLASS (klass),
304 PROP_EXHAUSTIVE_MODEL_SEARCH,
305 g_param_spec_boolean ("exhaustive-model-search",
306 "Do exhaustive model search",
307 "do exhaustive search of LP coefficient quantization (expensive!)",
308 flacenc_params[DEFAULT_QUALITY].exhaustive_model_search,
309 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
310 g_object_class_install_property (G_OBJECT_CLASS (klass),
311 PROP_MIN_RESIDUAL_PARTITION_ORDER,
312 g_param_spec_uint ("min-residual-partition-order",
313 "Min residual partition order",
314 "Min residual partition order (above 4 doesn't usually help much)", 0,
315 16, flacenc_params[DEFAULT_QUALITY].min_residual_partition_order,
316 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
317 g_object_class_install_property (G_OBJECT_CLASS (klass),
318 PROP_MAX_RESIDUAL_PARTITION_ORDER,
319 g_param_spec_uint ("max-residual-partition-order",
320 "Max residual partition order",
321 "Max residual partition order (above 4 doesn't usually help much)", 0,
322 16, flacenc_params[DEFAULT_QUALITY].max_residual_partition_order,
323 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
324 g_object_class_install_property (G_OBJECT_CLASS (klass),
325 PROP_RICE_PARAMETER_SEARCH_DIST,
326 g_param_spec_uint ("rice-parameter-search-dist",
327 "rice_parameter_search_dist",
328 "0 = try only calc'd parameter k; else try all [k-dist..k+dist] "
329 "parameters, use best", 0, FLAC__MAX_RICE_PARTITION_ORDER,
330 flacenc_params[DEFAULT_QUALITY].rice_parameter_search_dist,
331 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
336 * Write a PADDING block with this length in bytes
340 g_object_class_install_property (G_OBJECT_CLASS (klass),
342 g_param_spec_uint ("padding",
344 "Write a PADDING block with this length in bytes", 0, G_MAXUINT,
346 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
349 * GstFlacEnc:seekpoints
351 * Write a SEEKTABLE block with a specific number of seekpoints
352 * or with a specific interval spacing.
356 g_object_class_install_property (G_OBJECT_CLASS (klass),
358 g_param_spec_int ("seekpoints",
360 "Add SEEKTABLE metadata (if > 0, number of entries, if < 0, interval in sec)",
363 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
365 gst_element_class_add_pad_template (gstelement_class,
366 gst_static_pad_template_get (&src_factory));
367 gst_element_class_add_pad_template (gstelement_class,
368 gst_static_pad_template_get (&sink_factory));
370 gst_element_class_set_details_simple (gstelement_class, "FLAC audio encoder",
371 "Codec/Encoder/Audio",
372 "Encodes audio with the FLAC lossless audio encoder",
373 "Wim Taymans <wim.taymans@chello.be>");
375 base_class->start = GST_DEBUG_FUNCPTR (gst_flac_enc_start);
376 base_class->stop = GST_DEBUG_FUNCPTR (gst_flac_enc_stop);
377 base_class->set_format = GST_DEBUG_FUNCPTR (gst_flac_enc_set_format);
378 base_class->handle_frame = GST_DEBUG_FUNCPTR (gst_flac_enc_handle_frame);
379 base_class->getcaps = GST_DEBUG_FUNCPTR (gst_flac_enc_getcaps);
380 base_class->event = GST_DEBUG_FUNCPTR (gst_flac_enc_sink_event);
384 gst_flac_enc_init (GstFlacEnc * flacenc)
386 GstAudioEncoder *enc = GST_AUDIO_ENCODER (flacenc);
388 flacenc->encoder = FLAC__stream_encoder_new ();
389 gst_flac_enc_update_quality (flacenc, DEFAULT_QUALITY);
391 /* arrange granulepos marking (and required perfect ts) */
392 gst_audio_encoder_set_mark_granule (enc, TRUE);
393 gst_audio_encoder_set_perfect_timestamp (enc, TRUE);
397 gst_flac_enc_finalize (GObject * object)
399 GstFlacEnc *flacenc = GST_FLAC_ENC (object);
401 FLAC__stream_encoder_delete (flacenc->encoder);
403 G_OBJECT_CLASS (parent_class)->finalize (object);
407 gst_flac_enc_start (GstAudioEncoder * enc)
409 GstFlacEnc *flacenc = GST_FLAC_ENC (enc);
411 GST_DEBUG_OBJECT (enc, "start");
412 flacenc->stopped = TRUE;
413 flacenc->got_headers = FALSE;
414 flacenc->last_flow = GST_FLOW_OK;
416 flacenc->eos = FALSE;
417 flacenc->tags = gst_tag_list_new_empty ();
423 gst_flac_enc_stop (GstAudioEncoder * enc)
425 GstFlacEnc *flacenc = GST_FLAC_ENC (enc);
427 GST_DEBUG_OBJECT (enc, "stop");
428 gst_tag_list_free (flacenc->tags);
429 flacenc->tags = NULL;
430 if (FLAC__stream_encoder_get_state (flacenc->encoder) !=
431 FLAC__STREAM_ENCODER_UNINITIALIZED) {
432 flacenc->stopped = TRUE;
433 FLAC__stream_encoder_finish (flacenc->encoder);
436 FLAC__metadata_object_delete (flacenc->meta[0]);
438 if (flacenc->meta[1])
439 FLAC__metadata_object_delete (flacenc->meta[1]);
441 if (flacenc->meta[2])
442 FLAC__metadata_object_delete (flacenc->meta[2]);
444 g_free (flacenc->meta);
445 flacenc->meta = NULL;
447 g_list_foreach (flacenc->headers, (GFunc) gst_mini_object_unref, NULL);
448 g_list_free (flacenc->headers);
449 flacenc->headers = NULL;
451 gst_tag_setter_reset_tags (GST_TAG_SETTER (enc));
457 add_one_tag (const GstTagList * list, const gchar * tag, gpointer user_data)
461 GstFlacEnc *flacenc = GST_FLAC_ENC (user_data);
463 /* IMAGE and PREVIEW_IMAGE tags are already written
464 * differently, no need to store them inside the
465 * vorbiscomments too */
466 if (strcmp (tag, GST_TAG_IMAGE) == 0
467 || strcmp (tag, GST_TAG_PREVIEW_IMAGE) == 0)
470 comments = gst_tag_to_vorbis_comments (list, tag);
471 for (it = comments; it != NULL; it = it->next) {
472 FLAC__StreamMetadata_VorbisComment_Entry commment_entry;
474 commment_entry.length = strlen (it->data);
475 commment_entry.entry = it->data;
476 FLAC__metadata_object_vorbiscomment_insert_comment (flacenc->meta[0],
477 flacenc->meta[0]->data.vorbis_comment.num_comments,
478 commment_entry, TRUE);
481 g_list_free (comments);
485 gst_flac_enc_set_metadata (GstFlacEnc * flacenc, guint64 total_samples)
487 const GstTagList *user_tags;
490 gint n_images, n_preview_images;
492 gst_audio_encoder_get_audio_info (GST_AUDIO_ENCODER (flacenc));
494 g_return_if_fail (flacenc != NULL);
495 user_tags = gst_tag_setter_get_tag_list (GST_TAG_SETTER (flacenc));
496 if ((flacenc->tags == NULL) && (user_tags == NULL)) {
499 copy = gst_tag_list_merge (user_tags, flacenc->tags,
500 gst_tag_setter_get_tag_merge_mode (GST_TAG_SETTER (flacenc)));
501 n_images = gst_tag_list_get_tag_size (copy, GST_TAG_IMAGE);
502 n_preview_images = gst_tag_list_get_tag_size (copy, GST_TAG_PREVIEW_IMAGE);
505 g_new0 (FLAC__StreamMetadata *, 3 + n_images + n_preview_images);
508 FLAC__metadata_object_new (FLAC__METADATA_TYPE_VORBIS_COMMENT);
509 gst_tag_list_foreach (copy, add_one_tag, flacenc);
511 if (n_images + n_preview_images > 0) {
515 GstStructure *structure;
516 GstTagImageType image_type = GST_TAG_IMAGE_TYPE_NONE;
521 for (i = 0; i < n_images + n_preview_images; i++) {
523 if (!gst_tag_list_get_buffer_index (copy, GST_TAG_IMAGE, i, &buffer))
526 if (!gst_tag_list_get_buffer_index (copy, GST_TAG_PREVIEW_IMAGE,
527 i - n_images, &buffer))
531 flacenc->meta[entries] =
532 FLAC__metadata_object_new (FLAC__METADATA_TYPE_PICTURE);
535 caps = gst_buffer_get_caps (buffer);
536 structure = gst_caps_get_structure (caps, 0);
538 gst_structure_get (structure, "image-type", GST_TYPE_TAG_IMAGE_TYPE,
540 /* Convert to ID3v2 APIC image type */
541 if (image_type == GST_TAG_IMAGE_TYPE_NONE)
542 image_type = (i < n_images) ? 0x00 : 0x01;
544 image_type = image_type + 2;
547 gst_buffer_map (buffer, &map, GST_MAP_READ);
548 FLAC__metadata_object_picture_set_data (flacenc->meta[entries],
549 map.data, map.size, TRUE);
550 gst_buffer_unmap (buffer, &map);
553 /* FIXME: There's no way to set the picture type in libFLAC */
554 flacenc->meta[entries]->data.picture.type = image_type;
555 FLAC__metadata_object_picture_set_mime_type (flacenc->meta[entries],
556 (char *) gst_structure_get_name (structure), TRUE);
557 gst_caps_unref (caps);
560 gst_buffer_unref (buffer);
565 if (flacenc->seekpoints && total_samples != GST_CLOCK_TIME_NONE) {
569 flacenc->meta[entries] =
570 FLAC__metadata_object_new (FLAC__METADATA_TYPE_SEEKTABLE);
571 if (flacenc->seekpoints > 0) {
573 FLAC__metadata_object_seektable_template_append_spaced_points
574 (flacenc->meta[entries], flacenc->seekpoints, total_samples);
576 samples = -flacenc->seekpoints * GST_AUDIO_INFO_RATE (info);
578 FLAC__metadata_object_seektable_template_append_spaced_points_by_samples
579 (flacenc->meta[entries], samples, total_samples);
582 GST_DEBUG_OBJECT (flacenc, "adding seekpoint template %d failed",
583 flacenc->seekpoints);
584 FLAC__metadata_object_delete (flacenc->meta[1]);
585 flacenc->meta[entries] = NULL;
589 } else if (flacenc->seekpoints && total_samples == GST_CLOCK_TIME_NONE) {
590 GST_WARNING_OBJECT (flacenc, "total time unknown; can not add seekpoints");
593 if (flacenc->padding > 0) {
594 flacenc->meta[entries] =
595 FLAC__metadata_object_new (FLAC__METADATA_TYPE_PADDING);
596 flacenc->meta[entries]->length = flacenc->padding;
600 if (FLAC__stream_encoder_set_metadata (flacenc->encoder,
601 flacenc->meta, entries) != true)
602 g_warning ("Dude, i'm already initialized!");
604 gst_tag_list_free (copy);
608 gst_flac_enc_getcaps (GstAudioEncoder * enc, GstCaps * filter)
610 GstCaps *ret = NULL, *caps = NULL;
613 pad = GST_AUDIO_ENCODER_SINK_PAD (enc);
615 if (gst_pad_has_current_caps (pad)) {
616 ret = gst_pad_get_current_caps (pad);
619 GValue v_list = { 0, };
621 GstStructure *s, *s2;
623 g_value_init (&v_list, GST_TYPE_LIST);
624 g_value_init (&v, G_TYPE_STRING);
626 g_value_set_static_string (&v, GST_AUDIO_NE (S8));
627 gst_value_list_append_value (&v_list, &v);
628 g_value_set_static_string (&v, GST_AUDIO_NE (S16));
629 gst_value_list_append_value (&v_list, &v);
630 g_value_set_static_string (&v, GST_AUDIO_NE (S24));
631 gst_value_list_append_value (&v_list, &v);
632 g_value_set_static_string (&v, GST_AUDIO_NE (S24_32));
633 gst_value_list_append_value (&v_list, &v);
636 s = gst_structure_new_empty ("audio/x-raw");
637 gst_structure_take_value (s, "format", &v_list);
639 gst_structure_set (s, "layout", G_TYPE_STRING, "interleaved",
640 "rate", GST_TYPE_INT_RANGE, 1, 655350, NULL);
642 ret = gst_caps_new_empty ();
643 for (i = 1; i <= 8; i++) {
644 s2 = gst_structure_copy (s);
647 gst_structure_set (s2, "channels", G_TYPE_INT, 1, NULL);
649 guint64 channel_mask;
651 gst_audio_channel_positions_to_mask (channel_positions[i - 1], i,
653 gst_structure_set (s2, "channels", G_TYPE_INT, i, "channel-mask",
654 GST_TYPE_BITMASK, channel_mask, NULL);
657 gst_caps_append_structure (ret, s2);
659 gst_structure_free (s);
662 GST_DEBUG_OBJECT (pad, "Return caps %" GST_PTR_FORMAT, ret);
664 caps = gst_audio_encoder_proxy_getcaps (enc, ret);
665 gst_caps_unref (ret);
671 gst_flac_enc_peer_query_total_samples (GstFlacEnc * flacenc, GstPad * pad)
675 gst_audio_encoder_get_audio_info (GST_AUDIO_ENCODER (flacenc));
677 GST_DEBUG_OBJECT (flacenc, "querying peer for DEFAULT format duration");
678 if (gst_pad_peer_query_duration (pad, GST_FORMAT_DEFAULT, &duration)
679 && duration != GST_CLOCK_TIME_NONE)
682 GST_DEBUG_OBJECT (flacenc, "querying peer for TIME format duration");
684 if (gst_pad_peer_query_duration (pad, GST_FORMAT_TIME, &duration)
685 && duration != GST_CLOCK_TIME_NONE) {
686 GST_DEBUG_OBJECT (flacenc, "peer reported duration %" GST_TIME_FORMAT,
687 GST_TIME_ARGS (duration));
688 duration = GST_CLOCK_TIME_TO_FRAMES (duration, GST_AUDIO_INFO_RATE (info));
693 GST_DEBUG_OBJECT (flacenc, "Upstream reported no total samples");
694 return GST_CLOCK_TIME_NONE;
697 GST_DEBUG_OBJECT (flacenc,
698 "Upstream reported %" G_GUINT64_FORMAT " total samples", duration);
704 gst_flac_enc_set_format (GstAudioEncoder * enc, GstAudioInfo * info)
707 guint64 total_samples = GST_CLOCK_TIME_NONE;
708 FLAC__StreamEncoderInitStatus init_status;
711 flacenc = GST_FLAC_ENC (enc);
713 /* if configured again, means something changed, can't handle that */
714 if (FLAC__stream_encoder_get_state (flacenc->encoder) !=
715 FLAC__STREAM_ENCODER_UNINITIALIZED)
716 goto encoder_already_initialized;
718 caps = gst_caps_new_simple ("audio/x-flac",
719 "channels", G_TYPE_INT, GST_AUDIO_INFO_CHANNELS (info),
720 "rate", G_TYPE_INT, GST_AUDIO_INFO_RATE (info), NULL);
722 if (!gst_audio_encoder_set_output_format (enc, caps))
723 goto setting_src_caps_failed;
725 gst_caps_unref (caps);
727 gst_audio_get_channel_reorder_map (GST_AUDIO_INFO_CHANNELS (info),
728 channel_positions[GST_AUDIO_INFO_CHANNELS (info) - 1], info->position,
729 flacenc->channel_reorder_map);
731 total_samples = gst_flac_enc_peer_query_total_samples (flacenc,
732 GST_AUDIO_ENCODER_SINK_PAD (enc));
734 FLAC__stream_encoder_set_bits_per_sample (flacenc->encoder,
735 GST_AUDIO_INFO_WIDTH (info));
736 FLAC__stream_encoder_set_sample_rate (flacenc->encoder,
737 GST_AUDIO_INFO_RATE (info));
738 FLAC__stream_encoder_set_channels (flacenc->encoder,
739 GST_AUDIO_INFO_CHANNELS (info));
741 if (total_samples != GST_CLOCK_TIME_NONE)
742 FLAC__stream_encoder_set_total_samples_estimate (flacenc->encoder,
743 MIN (total_samples, G_GUINT64_CONSTANT (0x0FFFFFFFFF)));
745 gst_flac_enc_set_metadata (flacenc, total_samples);
747 /* callbacks clear to go now;
748 * write callbacks receives headers during init */
749 flacenc->stopped = FALSE;
751 init_status = FLAC__stream_encoder_init_stream (flacenc->encoder,
752 gst_flac_enc_write_callback, gst_flac_enc_seek_callback,
753 gst_flac_enc_tell_callback, NULL, flacenc);
754 if (init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK)
755 goto failed_to_initialize;
757 /* no special feedback to base class; should provide all available samples */
761 encoder_already_initialized:
763 g_warning ("flac already initialized -- fixme allow this");
766 setting_src_caps_failed:
768 GST_DEBUG_OBJECT (flacenc,
769 "Couldn't set caps on source pad: %" GST_PTR_FORMAT, caps);
770 gst_caps_unref (caps);
773 failed_to_initialize:
775 GST_ELEMENT_ERROR (flacenc, LIBRARY, INIT, (NULL),
776 ("could not initialize encoder (wrong parameters?) %d", init_status));
782 gst_flac_enc_update_quality (GstFlacEnc * flacenc, gint quality)
785 gst_audio_encoder_get_audio_info (GST_AUDIO_ENCODER (flacenc));
787 flacenc->quality = quality;
789 #define DO_UPDATE(name, val, str) \
791 if (FLAC__stream_encoder_get_##name (flacenc->encoder) != \
792 flacenc_params[quality].val) { \
793 FLAC__stream_encoder_set_##name (flacenc->encoder, \
794 flacenc_params[quality].val); \
795 g_object_notify (G_OBJECT (flacenc), str); \
799 g_object_freeze_notify (G_OBJECT (flacenc));
801 if (GST_AUDIO_INFO_CHANNELS (info) == 2
802 || GST_AUDIO_INFO_CHANNELS (info) == 0) {
803 DO_UPDATE (do_mid_side_stereo, mid_side, "mid_side_stereo");
804 DO_UPDATE (loose_mid_side_stereo, loose_mid_side, "loose_mid_side");
807 DO_UPDATE (blocksize, blocksize, "blocksize");
808 DO_UPDATE (max_lpc_order, max_lpc_order, "max_lpc_order");
809 DO_UPDATE (qlp_coeff_precision, qlp_coeff_precision, "qlp_coeff_precision");
810 DO_UPDATE (do_qlp_coeff_prec_search, qlp_coeff_prec_search,
811 "qlp_coeff_prec_search");
812 DO_UPDATE (do_escape_coding, escape_coding, "escape_coding");
813 DO_UPDATE (do_exhaustive_model_search, exhaustive_model_search,
814 "exhaustive_model_search");
815 DO_UPDATE (min_residual_partition_order, min_residual_partition_order,
816 "min_residual_partition_order");
817 DO_UPDATE (max_residual_partition_order, max_residual_partition_order,
818 "max_residual_partition_order");
819 DO_UPDATE (rice_parameter_search_dist, rice_parameter_search_dist,
820 "rice_parameter_search_dist");
824 g_object_thaw_notify (G_OBJECT (flacenc));
829 static FLAC__StreamEncoderSeekStatus
830 gst_flac_enc_seek_callback (const FLAC__StreamEncoder * encoder,
831 FLAC__uint64 absolute_byte_offset, void *client_data)
837 flacenc = GST_FLAC_ENC (client_data);
839 if (flacenc->stopped)
840 return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
842 if ((peerpad = gst_pad_get_peer (GST_AUDIO_ENCODER_SRC_PAD (flacenc)))) {
846 gst_segment_init (&seg, GST_FORMAT_BYTES);
847 seg.start = absolute_byte_offset;
848 seg.stop = GST_BUFFER_OFFSET_NONE;
850 event = gst_event_new_segment (&seg);
852 ret = gst_pad_send_event (peerpad, event);
853 gst_object_unref (peerpad);
856 GST_DEBUG ("Seek to %" G_GUINT64_FORMAT " %s",
857 (guint64) absolute_byte_offset, "succeeded");
859 GST_DEBUG ("Seek to %" G_GUINT64_FORMAT " %s",
860 (guint64) absolute_byte_offset, "failed");
861 return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
864 GST_DEBUG ("Seek to %" G_GUINT64_FORMAT " failed (no peer pad)",
865 (guint64) absolute_byte_offset);
868 flacenc->offset = absolute_byte_offset;
869 return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
873 notgst_value_array_append_buffer (GValue * array_val, GstBuffer * buf)
875 GValue value = { 0, };
877 g_value_init (&value, GST_TYPE_BUFFER);
878 /* copy buffer to avoid problems with circular refcounts */
879 buf = gst_buffer_copy (buf);
880 /* again, for good measure */
881 GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_HEADER);
882 gst_value_set_buffer (&value, buf);
883 gst_buffer_unref (buf);
884 gst_value_array_append_value (array_val, &value);
885 g_value_unset (&value);
888 #define HDR_TYPE_STREAMINFO 0
889 #define HDR_TYPE_VORBISCOMMENT 4
892 gst_flac_enc_process_stream_headers (GstFlacEnc * enc)
894 GstBuffer *vorbiscomment = NULL;
895 GstBuffer *streaminfo = NULL;
896 GstBuffer *marker = NULL;
897 GValue array = { 0, };
900 GstFlowReturn ret = GST_FLOW_OK;
902 gst_audio_encoder_get_audio_info (GST_AUDIO_ENCODER (enc));
904 caps = gst_caps_new_simple ("audio/x-flac",
905 "channels", G_TYPE_INT, GST_AUDIO_INFO_CHANNELS (info),
906 "rate", G_TYPE_INT, GST_AUDIO_INFO_RATE (info), NULL);
908 for (l = enc->headers; l != NULL; l = l->next) {
914 /* mark buffers so oggmux will ignore them if it already muxed the
915 * header buffers from the streamheaders field in the caps */
916 l->data = gst_buffer_make_writable (GST_BUFFER_CAST (l->data));
918 buf = GST_BUFFER_CAST (l->data);
919 GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_HEADER);
921 gst_buffer_map (buf, &map, GST_MAP_READ);
925 /* find initial 4-byte marker which we need to skip later on */
926 if (size == 4 && memcmp (data, "fLaC", 4) == 0) {
928 } else if (size > 1 && (data[0] & 0x7f) == HDR_TYPE_STREAMINFO) {
930 } else if (size > 1 && (data[0] & 0x7f) == HDR_TYPE_VORBISCOMMENT) {
934 gst_buffer_unmap (buf, &map);
937 if (marker == NULL || streaminfo == NULL || vorbiscomment == NULL) {
938 GST_WARNING_OBJECT (enc, "missing header %p %p %p, muxing into container "
939 "formats may be broken", marker, streaminfo, vorbiscomment);
943 g_value_init (&array, GST_TYPE_ARRAY);
945 /* add marker including STREAMINFO header */
953 /* minus one for the marker that is merged with streaminfo here */
954 num = g_list_length (enc->headers) - 1;
956 slen = gst_buffer_get_size (streaminfo);
957 buf = gst_buffer_new_and_alloc (13 + slen);
959 gst_buffer_map (buf, &map, GST_MAP_WRITE);
962 memcpy (bdata + 1, "FLAC", 4);
963 bdata[5] = 0x01; /* mapping version major */
964 bdata[6] = 0x00; /* mapping version minor */
965 bdata[7] = (num & 0xFF00) >> 8;
966 bdata[8] = (num & 0x00FF) >> 0;
967 memcpy (bdata + 9, "fLaC", 4);
968 gst_buffer_extract (streaminfo, 0, bdata + 13, slen);
969 gst_buffer_unmap (buf, &map);
971 notgst_value_array_append_buffer (&array, buf);
972 gst_buffer_unref (buf);
975 /* add VORBISCOMMENT header */
976 notgst_value_array_append_buffer (&array, vorbiscomment);
978 /* add other headers, if there are any */
979 for (l = enc->headers; l != NULL; l = l->next) {
980 GstBuffer *buf = GST_BUFFER_CAST (l->data);
982 if (buf != marker && buf != streaminfo && buf != vorbiscomment) {
983 notgst_value_array_append_buffer (&array, buf);
987 gst_structure_set_value (gst_caps_get_structure (caps, 0),
988 "streamheader", &array);
989 g_value_unset (&array);
992 gst_audio_encoder_set_output_format (GST_AUDIO_ENCODER (enc), caps);
994 /* push header buffers; update caps, so when we push the first buffer the
995 * negotiated caps will change to caps that include the streamheader field */
996 for (l = enc->headers; l != NULL; l = l->next) {
999 buf = GST_BUFFER (l->data);
1000 GST_LOG_OBJECT (enc,
1001 "Pushing header buffer, size %" G_GSIZE_FORMAT " bytes",
1002 gst_buffer_get_size (buf));
1004 GST_MEMDUMP_OBJECT (enc, "header buffer", GST_BUFFER_DATA (buf),
1005 GST_BUFFER_SIZE (buf));
1007 ret = gst_pad_push (GST_AUDIO_ENCODER_SRC_PAD (enc), buf);
1010 g_list_free (enc->headers);
1011 enc->headers = NULL;
1013 gst_caps_unref (caps);
1018 static FLAC__StreamEncoderWriteStatus
1019 gst_flac_enc_write_callback (const FLAC__StreamEncoder * encoder,
1020 const FLAC__byte buffer[], size_t bytes,
1021 unsigned samples, unsigned current_frame, void *client_data)
1023 GstFlowReturn ret = GST_FLOW_OK;
1024 GstFlacEnc *flacenc;
1027 flacenc = GST_FLAC_ENC (client_data);
1029 if (flacenc->stopped)
1030 return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
1032 outbuf = gst_buffer_new_and_alloc (bytes);
1033 gst_buffer_fill (outbuf, 0, buffer, bytes);
1035 /* we assume libflac passes us stuff neatly framed */
1036 if (!flacenc->got_headers) {
1038 GST_DEBUG_OBJECT (flacenc, "Got header, queueing (%u bytes)",
1040 flacenc->headers = g_list_append (flacenc->headers, outbuf);
1041 /* note: it's important that we increase our byte offset */
1044 GST_INFO_OBJECT (flacenc, "Non-header packet, we have all headers now");
1045 ret = gst_flac_enc_process_stream_headers (flacenc);
1046 flacenc->got_headers = TRUE;
1050 if (flacenc->got_headers && samples == 0) {
1051 /* header fixup, push downstream directly */
1052 GST_DEBUG_OBJECT (flacenc, "Fixing up headers at pos=%" G_GUINT64_FORMAT
1053 ", size=%u", flacenc->offset, (guint) bytes);
1055 GST_MEMDUMP_OBJECT (flacenc, "Presumed header fragment",
1056 GST_BUFFER_DATA (outbuf), GST_BUFFER_SIZE (outbuf));
1058 ret = gst_pad_push (GST_AUDIO_ENCODER_SRC_PAD (flacenc), outbuf);
1060 /* regular frame data, pass to base class */
1061 GST_LOG ("Pushing buffer: ts=%" GST_TIME_FORMAT ", samples=%u, size=%u, "
1062 "pos=%" G_GUINT64_FORMAT, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf)),
1063 samples, (guint) bytes, flacenc->offset);
1064 ret = gst_audio_encoder_finish_frame (GST_AUDIO_ENCODER (flacenc),
1068 if (ret != GST_FLOW_OK)
1069 GST_DEBUG_OBJECT (flacenc, "flow: %s", gst_flow_get_name (ret));
1071 flacenc->last_flow = ret;
1074 flacenc->offset += bytes;
1076 if (ret != GST_FLOW_OK)
1077 return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
1079 return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
1082 static FLAC__StreamEncoderTellStatus
1083 gst_flac_enc_tell_callback (const FLAC__StreamEncoder * encoder,
1084 FLAC__uint64 * absolute_byte_offset, void *client_data)
1086 GstFlacEnc *flacenc = GST_FLAC_ENC (client_data);
1088 *absolute_byte_offset = flacenc->offset;
1090 return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
1094 gst_flac_enc_sink_event (GstAudioEncoder * enc, GstEvent * event)
1096 GstFlacEnc *flacenc;
1097 GstTagList *taglist;
1098 gboolean ret = FALSE;
1100 flacenc = GST_FLAC_ENC (enc);
1102 GST_DEBUG ("Received %s event on sinkpad", GST_EVENT_TYPE_NAME (event));
1104 switch (GST_EVENT_TYPE (event)) {
1106 flacenc->eos = TRUE;
1107 ret = GST_AUDIO_ENCODER_CLASS (parent_class)->event (enc, event);
1110 if (flacenc->tags) {
1111 gst_event_parse_tag (event, &taglist);
1112 gst_tag_list_insert (flacenc->tags, taglist,
1113 gst_tag_setter_get_tag_merge_mode (GST_TAG_SETTER (flacenc)));
1115 g_assert_not_reached ();
1117 ret = GST_AUDIO_ENCODER_CLASS (parent_class)->event (enc, event);
1120 ret = GST_AUDIO_ENCODER_CLASS (parent_class)->event (enc, event);
1127 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
1128 #define READ_INT24 GST_READ_UINT24_LE
1130 #define READ_INT24 GST_READ_UINT24_BE
1133 static GstFlowReturn
1134 gst_flac_enc_handle_frame (GstAudioEncoder * enc, GstBuffer * buffer)
1136 GstFlacEnc *flacenc;
1138 gint samples, width, channels;
1143 GstAudioInfo *info =
1144 gst_audio_encoder_get_audio_info (GST_AUDIO_ENCODER (enc));
1147 flacenc = GST_FLAC_ENC (enc);
1149 /* base class ensures configuration */
1150 g_return_val_if_fail (GST_AUDIO_INFO_WIDTH (info) != 0,
1151 GST_FLOW_NOT_NEGOTIATED);
1153 width = GST_AUDIO_INFO_WIDTH (info);
1154 channels = GST_AUDIO_INFO_CHANNELS (info);
1155 reorder_map = flacenc->channel_reorder_map;
1157 if (G_UNLIKELY (!buffer)) {
1159 FLAC__stream_encoder_finish (flacenc->encoder);
1161 /* can't handle intermittent draining/resyncing */
1162 GST_ELEMENT_WARNING (flacenc, STREAM, FORMAT, (NULL),
1163 ("Stream discontinuity detected. "
1164 "The output may have wrong timestamps, "
1165 "consider using audiorate to handle discontinuities"));
1167 return flacenc->last_flow;
1170 gst_buffer_map (buffer, &map, GST_MAP_READ);
1171 samples = map.size / (width >> 3);
1173 data = g_malloc (samples * sizeof (FLAC__int32));
1175 samples /= channels;
1177 gint8 *indata = (gint8 *) map.data;
1179 for (i = 0; i < samples; i++)
1180 for (j = 0; j < channels; j++)
1181 data[i * channels + reorder_map[j]] =
1182 (FLAC__int32) indata[i * channels + j];
1183 } else if (width == 16) {
1184 gint16 *indata = (gint16 *) map.data;
1186 for (i = 0; i < samples; i++)
1187 for (j = 0; j < channels; j++)
1188 data[i * channels + reorder_map[j]] =
1189 (FLAC__int32) indata[i * channels + j];
1190 } else if (width == 24) {
1191 guint8 *indata = (guint8 *) map.data;
1194 for (i = 0; i < samples; i++)
1195 for (j = 0; j < channels; j++) {
1196 val = READ_INT24 (&indata[3 * (i * channels + j)]);
1197 if (val & 0x00800000)
1199 data[i * channels + reorder_map[j]] = (FLAC__int32) val;
1201 } else if (width == 32) {
1202 gint32 *indata = (gint32 *) map.data;
1204 for (i = 0; i < samples; i++)
1205 for (j = 0; j < channels; j++)
1206 data[i * channels + reorder_map[j]] =
1207 (FLAC__int32) indata[i * channels + j];
1209 g_assert_not_reached ();
1211 gst_buffer_unmap (buffer, &map);
1213 res = FLAC__stream_encoder_process_interleaved (flacenc->encoder,
1214 (const FLAC__int32 *) data, samples / channels);
1219 if (flacenc->last_flow == GST_FLOW_OK)
1220 return GST_FLOW_ERROR;
1222 return flacenc->last_flow;
1229 gst_flac_enc_set_property (GObject * object, guint prop_id,
1230 const GValue * value, GParamSpec * pspec)
1232 GstFlacEnc *this = GST_FLAC_ENC (object);
1234 GST_OBJECT_LOCK (this);
1238 gst_flac_enc_update_quality (this, g_value_get_enum (value));
1240 case PROP_STREAMABLE_SUBSET:
1241 FLAC__stream_encoder_set_streamable_subset (this->encoder,
1242 g_value_get_boolean (value));
1244 case PROP_MID_SIDE_STEREO:
1245 FLAC__stream_encoder_set_do_mid_side_stereo (this->encoder,
1246 g_value_get_boolean (value));
1248 case PROP_LOOSE_MID_SIDE_STEREO:
1249 FLAC__stream_encoder_set_loose_mid_side_stereo (this->encoder,
1250 g_value_get_boolean (value));
1252 case PROP_BLOCKSIZE:
1253 FLAC__stream_encoder_set_blocksize (this->encoder,
1254 g_value_get_uint (value));
1256 case PROP_MAX_LPC_ORDER:
1257 FLAC__stream_encoder_set_max_lpc_order (this->encoder,
1258 g_value_get_uint (value));
1260 case PROP_QLP_COEFF_PRECISION:
1261 FLAC__stream_encoder_set_qlp_coeff_precision (this->encoder,
1262 g_value_get_uint (value));
1264 case PROP_QLP_COEFF_PREC_SEARCH:
1265 FLAC__stream_encoder_set_do_qlp_coeff_prec_search (this->encoder,
1266 g_value_get_boolean (value));
1268 case PROP_ESCAPE_CODING:
1269 FLAC__stream_encoder_set_do_escape_coding (this->encoder,
1270 g_value_get_boolean (value));
1272 case PROP_EXHAUSTIVE_MODEL_SEARCH:
1273 FLAC__stream_encoder_set_do_exhaustive_model_search (this->encoder,
1274 g_value_get_boolean (value));
1276 case PROP_MIN_RESIDUAL_PARTITION_ORDER:
1277 FLAC__stream_encoder_set_min_residual_partition_order (this->encoder,
1278 g_value_get_uint (value));
1280 case PROP_MAX_RESIDUAL_PARTITION_ORDER:
1281 FLAC__stream_encoder_set_max_residual_partition_order (this->encoder,
1282 g_value_get_uint (value));
1284 case PROP_RICE_PARAMETER_SEARCH_DIST:
1285 FLAC__stream_encoder_set_rice_parameter_search_dist (this->encoder,
1286 g_value_get_uint (value));
1289 this->padding = g_value_get_uint (value);
1291 case PROP_SEEKPOINTS:
1292 this->seekpoints = g_value_get_int (value);
1295 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1299 GST_OBJECT_UNLOCK (this);
1303 gst_flac_enc_get_property (GObject * object, guint prop_id,
1304 GValue * value, GParamSpec * pspec)
1306 GstFlacEnc *this = GST_FLAC_ENC (object);
1308 GST_OBJECT_LOCK (this);
1312 g_value_set_enum (value, this->quality);
1314 case PROP_STREAMABLE_SUBSET:
1315 g_value_set_boolean (value,
1316 FLAC__stream_encoder_get_streamable_subset (this->encoder));
1318 case PROP_MID_SIDE_STEREO:
1319 g_value_set_boolean (value,
1320 FLAC__stream_encoder_get_do_mid_side_stereo (this->encoder));
1322 case PROP_LOOSE_MID_SIDE_STEREO:
1323 g_value_set_boolean (value,
1324 FLAC__stream_encoder_get_loose_mid_side_stereo (this->encoder));
1326 case PROP_BLOCKSIZE:
1327 g_value_set_uint (value,
1328 FLAC__stream_encoder_get_blocksize (this->encoder));
1330 case PROP_MAX_LPC_ORDER:
1331 g_value_set_uint (value,
1332 FLAC__stream_encoder_get_max_lpc_order (this->encoder));
1334 case PROP_QLP_COEFF_PRECISION:
1335 g_value_set_uint (value,
1336 FLAC__stream_encoder_get_qlp_coeff_precision (this->encoder));
1338 case PROP_QLP_COEFF_PREC_SEARCH:
1339 g_value_set_boolean (value,
1340 FLAC__stream_encoder_get_do_qlp_coeff_prec_search (this->encoder));
1342 case PROP_ESCAPE_CODING:
1343 g_value_set_boolean (value,
1344 FLAC__stream_encoder_get_do_escape_coding (this->encoder));
1346 case PROP_EXHAUSTIVE_MODEL_SEARCH:
1347 g_value_set_boolean (value,
1348 FLAC__stream_encoder_get_do_exhaustive_model_search (this->encoder));
1350 case PROP_MIN_RESIDUAL_PARTITION_ORDER:
1351 g_value_set_uint (value,
1352 FLAC__stream_encoder_get_min_residual_partition_order
1355 case PROP_MAX_RESIDUAL_PARTITION_ORDER:
1356 g_value_set_uint (value,
1357 FLAC__stream_encoder_get_max_residual_partition_order
1360 case PROP_RICE_PARAMETER_SEARCH_DIST:
1361 g_value_set_uint (value,
1362 FLAC__stream_encoder_get_rice_parameter_search_dist (this->encoder));
1365 g_value_set_uint (value, this->padding);
1367 case PROP_SEEKPOINTS:
1368 g_value_set_int (value, this->seekpoints);
1371 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1375 GST_OBJECT_UNLOCK (this);