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/audio/multichannel.h>
49 #include <gst/tag/tag.h>
50 #include <gst/gsttagsetter.h>
52 /* Taken from http://flac.sourceforge.net/format.html#frame_header */
53 static const GstAudioChannelPosition channel_positions[8][8] = {
54 {GST_AUDIO_CHANNEL_POSITION_FRONT_MONO},
55 {GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
56 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}, {
57 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
58 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
59 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER}, {
60 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
61 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
62 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
63 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT}, {
64 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
65 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
66 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
67 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
68 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT}, {
69 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
70 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
71 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
72 GST_AUDIO_CHANNEL_POSITION_LFE,
73 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
74 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT},
75 /* FIXME: 7/8 channel layouts are not defined in the FLAC specs */
77 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
78 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
79 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
80 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
81 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
82 GST_AUDIO_CHANNEL_POSITION_LFE,
83 GST_AUDIO_CHANNEL_POSITION_REAR_CENTER}, {
84 GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT,
85 GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT,
86 GST_AUDIO_CHANNEL_POSITION_REAR_LEFT,
87 GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT,
88 GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER,
89 GST_AUDIO_CHANNEL_POSITION_LFE,
90 GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT,
91 GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT}
94 #define FLAC_SINK_CAPS \
96 "endianness = (int) BYTE_ORDER, " \
97 "signed = (boolean) TRUE, " \
100 "rate = (int) [ 1, 655350 ], " \
101 "channels = (int) [ 1, 8 ]; " \
102 "audio/x-raw-int, " \
103 "endianness = (int) BYTE_ORDER, " \
104 "signed = (boolean) TRUE, " \
105 "width = (int) 16, " \
106 "depth = (int) { 12, 16 }, " \
107 "rate = (int) [ 1, 655350 ], " \
108 "channels = (int) [ 1, 8 ]; " \
109 "audio/x-raw-int, " \
110 "endianness = (int) BYTE_ORDER, " \
111 "signed = (boolean) TRUE, " \
112 "width = (int) 32, " \
113 "depth = (int) { 20, 24 }, " \
114 "rate = (int) [ 1, 655350 ], " \
115 "channels = (int) [ 1, 8 ]"
117 static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
120 GST_STATIC_CAPS ("audio/x-flac")
123 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
126 GST_STATIC_CAPS (FLAC_SINK_CAPS)
133 PROP_STREAMABLE_SUBSET,
134 PROP_MID_SIDE_STEREO,
135 PROP_LOOSE_MID_SIDE_STEREO,
138 PROP_QLP_COEFF_PRECISION,
139 PROP_QLP_COEFF_PREC_SEARCH,
141 PROP_EXHAUSTIVE_MODEL_SEARCH,
142 PROP_MIN_RESIDUAL_PARTITION_ORDER,
143 PROP_MAX_RESIDUAL_PARTITION_ORDER,
144 PROP_RICE_PARAMETER_SEARCH_DIST,
149 GST_DEBUG_CATEGORY_STATIC (flacenc_debug);
150 #define GST_CAT_DEFAULT flacenc_debug
152 #define gst_flac_enc_parent_class parent_class
153 G_DEFINE_TYPE_WITH_CODE (GstFlacEnc, gst_flac_enc, GST_TYPE_AUDIO_ENCODER,
154 G_IMPLEMENT_INTERFACE (GST_TYPE_TAG_SETTER, NULL));
156 static gboolean gst_flac_enc_start (GstAudioEncoder * enc);
157 static gboolean gst_flac_enc_stop (GstAudioEncoder * enc);
158 static gboolean gst_flac_enc_set_format (GstAudioEncoder * enc,
159 GstAudioInfo * info);
160 static GstFlowReturn gst_flac_enc_handle_frame (GstAudioEncoder * enc,
162 static GstCaps *gst_flac_enc_getcaps (GstAudioEncoder * enc, GstCaps * filter);
163 static gboolean gst_flac_enc_sink_event (GstAudioEncoder * enc,
166 static void gst_flac_enc_finalize (GObject * object);
168 static gboolean gst_flac_enc_update_quality (GstFlacEnc * flacenc,
170 static void gst_flac_enc_set_property (GObject * object, guint prop_id,
171 const GValue * value, GParamSpec * pspec);
172 static void gst_flac_enc_get_property (GObject * object, guint prop_id,
173 GValue * value, GParamSpec * pspec);
175 static FLAC__StreamEncoderWriteStatus
176 gst_flac_enc_write_callback (const FLAC__StreamEncoder * encoder,
177 const FLAC__byte buffer[], size_t bytes,
178 unsigned samples, unsigned current_frame, void *client_data);
179 static FLAC__StreamEncoderSeekStatus
180 gst_flac_enc_seek_callback (const FLAC__StreamEncoder * encoder,
181 FLAC__uint64 absolute_byte_offset, void *client_data);
182 static FLAC__StreamEncoderTellStatus
183 gst_flac_enc_tell_callback (const FLAC__StreamEncoder * encoder,
184 FLAC__uint64 * absolute_byte_offset, void *client_data);
188 gboolean exhaustive_model_search;
189 gboolean escape_coding;
191 gboolean loose_mid_side;
192 guint qlp_coeff_precision;
193 gboolean qlp_coeff_prec_search;
194 guint min_residual_partition_order;
195 guint max_residual_partition_order;
196 guint rice_parameter_search_dist;
202 static const GstFlacEncParams flacenc_params[] = {
203 {FALSE, FALSE, FALSE, FALSE, 0, FALSE, 2, 2, 0, 0, 1152},
204 {FALSE, FALSE, TRUE, TRUE, 0, FALSE, 2, 2, 0, 0, 1152},
205 {FALSE, FALSE, TRUE, FALSE, 0, FALSE, 0, 3, 0, 0, 1152},
206 {FALSE, FALSE, FALSE, FALSE, 0, FALSE, 3, 3, 0, 6, 4608},
207 {FALSE, FALSE, TRUE, TRUE, 0, FALSE, 3, 3, 0, 8, 4608},
208 {FALSE, FALSE, TRUE, FALSE, 0, FALSE, 3, 3, 0, 8, 4608},
209 {FALSE, FALSE, TRUE, FALSE, 0, FALSE, 0, 4, 0, 8, 4608},
210 {TRUE, FALSE, TRUE, FALSE, 0, FALSE, 0, 6, 0, 8, 4608},
211 {TRUE, FALSE, TRUE, FALSE, 0, FALSE, 0, 6, 0, 12, 4608},
212 {TRUE, TRUE, TRUE, FALSE, 0, FALSE, 0, 16, 0, 32, 4608},
215 #define DEFAULT_QUALITY 5
216 #define DEFAULT_PADDING 0
217 #define DEFAULT_SEEKPOINTS 0
219 #define GST_TYPE_FLAC_ENC_QUALITY (gst_flac_enc_quality_get_type ())
221 gst_flac_enc_quality_get_type (void)
223 static GType qtype = 0;
226 static const GEnumValue values[] = {
227 {0, "0 - Fastest compression", "0"},
232 {5, "5 - Default", "5"},
235 {8, "8 - Highest compression", "8"},
236 {9, "9 - Insane", "9"},
240 qtype = g_enum_register_static ("GstFlacEncQuality", values);
246 gst_flac_enc_class_init (GstFlacEncClass * klass)
248 GObjectClass *gobject_class;
249 GstElementClass *gstelement_class;
250 GstAudioEncoderClass *base_class;
252 gobject_class = (GObjectClass *) klass;
253 gstelement_class = (GstElementClass *) klass;
254 base_class = (GstAudioEncoderClass *) (klass);
256 GST_DEBUG_CATEGORY_INIT (flacenc_debug, "flacenc", 0,
257 "Flac encoding element");
259 gobject_class->set_property = gst_flac_enc_set_property;
260 gobject_class->get_property = gst_flac_enc_get_property;
261 gobject_class->finalize = gst_flac_enc_finalize;
263 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_QUALITY,
264 g_param_spec_enum ("quality",
266 "Speed versus compression tradeoff",
267 GST_TYPE_FLAC_ENC_QUALITY, DEFAULT_QUALITY,
268 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
269 g_object_class_install_property (G_OBJECT_CLASS (klass),
270 PROP_STREAMABLE_SUBSET, g_param_spec_boolean ("streamable-subset",
272 "true to limit encoder to generating a Subset stream, else false",
274 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
275 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_MID_SIDE_STEREO,
276 g_param_spec_boolean ("mid-side-stereo", "Do mid side stereo",
277 "Do mid side stereo (only for stereo input)",
278 flacenc_params[DEFAULT_QUALITY].mid_side,
279 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
280 g_object_class_install_property (G_OBJECT_CLASS (klass),
281 PROP_LOOSE_MID_SIDE_STEREO, g_param_spec_boolean ("loose-mid-side-stereo",
282 "Loose mid side stereo", "Loose mid side stereo",
283 flacenc_params[DEFAULT_QUALITY].loose_mid_side,
284 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
285 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_BLOCKSIZE,
286 g_param_spec_uint ("blocksize", "Blocksize", "Blocksize in samples",
287 FLAC__MIN_BLOCK_SIZE, FLAC__MAX_BLOCK_SIZE,
288 flacenc_params[DEFAULT_QUALITY].blocksize,
289 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
290 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_MAX_LPC_ORDER,
291 g_param_spec_uint ("max-lpc-order", "Max LPC order",
292 "Max LPC order; 0 => use only fixed predictors", 0,
293 FLAC__MAX_LPC_ORDER, flacenc_params[DEFAULT_QUALITY].max_lpc_order,
294 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
295 g_object_class_install_property (G_OBJECT_CLASS (klass),
296 PROP_QLP_COEFF_PRECISION, g_param_spec_uint ("qlp-coeff-precision",
297 "QLP coefficients precision",
298 "Precision in bits of quantized linear-predictor coefficients; 0 = automatic",
299 0, 32, flacenc_params[DEFAULT_QUALITY].qlp_coeff_precision,
300 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
301 g_object_class_install_property (G_OBJECT_CLASS (klass),
302 PROP_QLP_COEFF_PREC_SEARCH, g_param_spec_boolean ("qlp-coeff-prec-search",
303 "Do QLP coefficients precision search",
304 "false = use qlp_coeff_precision, "
305 "true = search around qlp_coeff_precision, take best",
306 flacenc_params[DEFAULT_QUALITY].qlp_coeff_prec_search,
307 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
308 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_ESCAPE_CODING,
309 g_param_spec_boolean ("escape-coding", "Do Escape coding",
310 "search for escape codes in the entropy coding stage "
311 "for slightly better compression",
312 flacenc_params[DEFAULT_QUALITY].escape_coding,
313 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
314 g_object_class_install_property (G_OBJECT_CLASS (klass),
315 PROP_EXHAUSTIVE_MODEL_SEARCH,
316 g_param_spec_boolean ("exhaustive-model-search",
317 "Do exhaustive model search",
318 "do exhaustive search of LP coefficient quantization (expensive!)",
319 flacenc_params[DEFAULT_QUALITY].exhaustive_model_search,
320 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
321 g_object_class_install_property (G_OBJECT_CLASS (klass),
322 PROP_MIN_RESIDUAL_PARTITION_ORDER,
323 g_param_spec_uint ("min-residual-partition-order",
324 "Min residual partition order",
325 "Min residual partition order (above 4 doesn't usually help much)", 0,
326 16, flacenc_params[DEFAULT_QUALITY].min_residual_partition_order,
327 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
328 g_object_class_install_property (G_OBJECT_CLASS (klass),
329 PROP_MAX_RESIDUAL_PARTITION_ORDER,
330 g_param_spec_uint ("max-residual-partition-order",
331 "Max residual partition order",
332 "Max residual partition order (above 4 doesn't usually help much)", 0,
333 16, flacenc_params[DEFAULT_QUALITY].max_residual_partition_order,
334 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
335 g_object_class_install_property (G_OBJECT_CLASS (klass),
336 PROP_RICE_PARAMETER_SEARCH_DIST,
337 g_param_spec_uint ("rice-parameter-search-dist",
338 "rice_parameter_search_dist",
339 "0 = try only calc'd parameter k; else try all [k-dist..k+dist] "
340 "parameters, use best", 0, FLAC__MAX_RICE_PARTITION_ORDER,
341 flacenc_params[DEFAULT_QUALITY].rice_parameter_search_dist,
342 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
347 * Write a PADDING block with this length in bytes
351 g_object_class_install_property (G_OBJECT_CLASS (klass),
353 g_param_spec_uint ("padding",
355 "Write a PADDING block with this length in bytes", 0, G_MAXUINT,
357 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
360 * GstFlacEnc:seekpoints
362 * Write a SEEKTABLE block with a specific number of seekpoints
363 * or with a specific interval spacing.
367 g_object_class_install_property (G_OBJECT_CLASS (klass),
369 g_param_spec_int ("seekpoints",
371 "Add SEEKTABLE metadata (if > 0, number of entries, if < 0, interval in sec)",
374 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
376 gst_element_class_add_pad_template (gstelement_class,
377 gst_static_pad_template_get (&src_factory));
378 gst_element_class_add_pad_template (gstelement_class,
379 gst_static_pad_template_get (&sink_factory));
381 gst_element_class_set_details_simple (gstelement_class, "FLAC audio encoder",
382 "Codec/Encoder/Audio",
383 "Encodes audio with the FLAC lossless audio encoder",
384 "Wim Taymans <wim.taymans@chello.be>");
386 base_class->start = GST_DEBUG_FUNCPTR (gst_flac_enc_start);
387 base_class->stop = GST_DEBUG_FUNCPTR (gst_flac_enc_stop);
388 base_class->set_format = GST_DEBUG_FUNCPTR (gst_flac_enc_set_format);
389 base_class->handle_frame = GST_DEBUG_FUNCPTR (gst_flac_enc_handle_frame);
390 base_class->getcaps = GST_DEBUG_FUNCPTR (gst_flac_enc_getcaps);
391 base_class->event = GST_DEBUG_FUNCPTR (gst_flac_enc_sink_event);
395 gst_flac_enc_init (GstFlacEnc * flacenc)
397 GstAudioEncoder *enc = GST_AUDIO_ENCODER (flacenc);
399 flacenc->encoder = FLAC__stream_encoder_new ();
400 gst_flac_enc_update_quality (flacenc, DEFAULT_QUALITY);
402 /* arrange granulepos marking (and required perfect ts) */
403 gst_audio_encoder_set_mark_granule (enc, TRUE);
404 gst_audio_encoder_set_perfect_timestamp (enc, TRUE);
408 gst_flac_enc_finalize (GObject * object)
410 GstFlacEnc *flacenc = GST_FLAC_ENC (object);
412 FLAC__stream_encoder_delete (flacenc->encoder);
414 G_OBJECT_CLASS (parent_class)->finalize (object);
418 gst_flac_enc_start (GstAudioEncoder * enc)
420 GstFlacEnc *flacenc = GST_FLAC_ENC (enc);
422 GST_DEBUG_OBJECT (enc, "start");
423 flacenc->stopped = TRUE;
424 flacenc->got_headers = FALSE;
425 flacenc->last_flow = GST_FLOW_OK;
427 flacenc->channels = 0;
429 flacenc->sample_rate = 0;
430 flacenc->eos = FALSE;
431 flacenc->tags = gst_tag_list_new_empty ();
437 gst_flac_enc_stop (GstAudioEncoder * enc)
439 GstFlacEnc *flacenc = GST_FLAC_ENC (enc);
441 GST_DEBUG_OBJECT (enc, "stop");
442 gst_tag_list_free (flacenc->tags);
443 flacenc->tags = NULL;
444 if (FLAC__stream_encoder_get_state (flacenc->encoder) !=
445 FLAC__STREAM_ENCODER_UNINITIALIZED) {
446 flacenc->stopped = TRUE;
447 FLAC__stream_encoder_finish (flacenc->encoder);
450 FLAC__metadata_object_delete (flacenc->meta[0]);
452 if (flacenc->meta[1])
453 FLAC__metadata_object_delete (flacenc->meta[1]);
455 if (flacenc->meta[2])
456 FLAC__metadata_object_delete (flacenc->meta[2]);
458 g_free (flacenc->meta);
459 flacenc->meta = NULL;
461 g_list_foreach (flacenc->headers, (GFunc) gst_mini_object_unref, NULL);
462 g_list_free (flacenc->headers);
463 flacenc->headers = NULL;
469 add_one_tag (const GstTagList * list, const gchar * tag, gpointer user_data)
473 GstFlacEnc *flacenc = GST_FLAC_ENC (user_data);
475 /* IMAGE and PREVIEW_IMAGE tags are already written
476 * differently, no need to store them inside the
477 * vorbiscomments too */
478 if (strcmp (tag, GST_TAG_IMAGE) == 0
479 || strcmp (tag, GST_TAG_PREVIEW_IMAGE) == 0)
482 comments = gst_tag_to_vorbis_comments (list, tag);
483 for (it = comments; it != NULL; it = it->next) {
484 FLAC__StreamMetadata_VorbisComment_Entry commment_entry;
486 commment_entry.length = strlen (it->data);
487 commment_entry.entry = it->data;
488 FLAC__metadata_object_vorbiscomment_insert_comment (flacenc->meta[0],
489 flacenc->meta[0]->data.vorbis_comment.num_comments,
490 commment_entry, TRUE);
493 g_list_free (comments);
497 gst_flac_enc_set_metadata (GstFlacEnc * flacenc, guint64 total_samples)
499 const GstTagList *user_tags;
502 gint n_images, n_preview_images;
504 g_return_if_fail (flacenc != NULL);
505 user_tags = gst_tag_setter_get_tag_list (GST_TAG_SETTER (flacenc));
506 if ((flacenc->tags == NULL) && (user_tags == NULL)) {
509 copy = gst_tag_list_merge (user_tags, flacenc->tags,
510 gst_tag_setter_get_tag_merge_mode (GST_TAG_SETTER (flacenc)));
511 n_images = gst_tag_list_get_tag_size (copy, GST_TAG_IMAGE);
512 n_preview_images = gst_tag_list_get_tag_size (copy, GST_TAG_PREVIEW_IMAGE);
515 g_new0 (FLAC__StreamMetadata *, 3 + n_images + n_preview_images);
518 FLAC__metadata_object_new (FLAC__METADATA_TYPE_VORBIS_COMMENT);
519 gst_tag_list_foreach (copy, add_one_tag, flacenc);
521 if (n_images + n_preview_images > 0) {
525 GstStructure *structure;
526 GstTagImageType image_type = GST_TAG_IMAGE_TYPE_NONE;
532 for (i = 0; i < n_images + n_preview_images; i++) {
534 if (!gst_tag_list_get_buffer_index (copy, GST_TAG_IMAGE, i, &buffer))
537 if (!gst_tag_list_get_buffer_index (copy, GST_TAG_PREVIEW_IMAGE,
538 i - n_images, &buffer))
542 flacenc->meta[entries] =
543 FLAC__metadata_object_new (FLAC__METADATA_TYPE_PICTURE);
546 caps = gst_buffer_get_caps (buffer);
547 structure = gst_caps_get_structure (caps, 0);
549 gst_structure_get (structure, "image-type", GST_TYPE_TAG_IMAGE_TYPE,
551 /* Convert to ID3v2 APIC image type */
552 if (image_type == GST_TAG_IMAGE_TYPE_NONE)
553 image_type = (i < n_images) ? 0x00 : 0x01;
555 image_type = image_type + 2;
558 data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
559 FLAC__metadata_object_picture_set_data (flacenc->meta[entries],
561 gst_buffer_unmap (buffer, data, size);
564 /* FIXME: There's no way to set the picture type in libFLAC */
565 flacenc->meta[entries]->data.picture.type = image_type;
566 FLAC__metadata_object_picture_set_mime_type (flacenc->meta[entries],
567 (char *) gst_structure_get_name (structure), TRUE);
568 gst_caps_unref (caps);
571 gst_buffer_unref (buffer);
576 if (flacenc->seekpoints && total_samples != GST_CLOCK_TIME_NONE) {
580 flacenc->meta[entries] =
581 FLAC__metadata_object_new (FLAC__METADATA_TYPE_SEEKTABLE);
582 if (flacenc->seekpoints > 0) {
584 FLAC__metadata_object_seektable_template_append_spaced_points
585 (flacenc->meta[entries], flacenc->seekpoints, total_samples);
587 samples = -flacenc->seekpoints * flacenc->sample_rate;
589 FLAC__metadata_object_seektable_template_append_spaced_points_by_samples
590 (flacenc->meta[entries], samples, total_samples);
593 GST_DEBUG_OBJECT (flacenc, "adding seekpoint template %d failed",
594 flacenc->seekpoints);
595 FLAC__metadata_object_delete (flacenc->meta[1]);
596 flacenc->meta[entries] = NULL;
600 } else if (flacenc->seekpoints && total_samples == GST_CLOCK_TIME_NONE) {
601 GST_WARNING_OBJECT (flacenc, "total time unknown; can not add seekpoints");
604 if (flacenc->padding > 0) {
605 flacenc->meta[entries] =
606 FLAC__metadata_object_new (FLAC__METADATA_TYPE_PADDING);
607 flacenc->meta[entries]->length = flacenc->padding;
611 if (FLAC__stream_encoder_set_metadata (flacenc->encoder,
612 flacenc->meta, entries) != true)
613 g_warning ("Dude, i'm already initialized!");
615 gst_tag_list_free (copy);
619 gst_flac_enc_caps_append_structure_with_widths (GstCaps * caps,
623 GValue list = { 0, };
624 GValue depth = { 0, };
627 tmp = gst_structure_copy (s);
628 gst_structure_set (tmp, "width", G_TYPE_INT, 8, "depth", G_TYPE_INT, 8, NULL);
629 gst_caps_append_structure (caps, tmp);
631 tmp = gst_structure_copy (s);
633 g_value_init (&depth, G_TYPE_INT);
634 g_value_init (&list, GST_TYPE_LIST);
635 g_value_set_int (&depth, 12);
636 gst_value_list_append_value (&list, &depth);
637 g_value_set_int (&depth, 16);
638 gst_value_list_append_value (&list, &depth);
640 gst_structure_set (tmp, "width", G_TYPE_INT, 16, NULL);
641 gst_structure_set_value (tmp, "depth", &list);
642 gst_caps_append_structure (caps, tmp);
644 g_value_reset (&list);
648 g_value_set_int (&depth, 20);
649 gst_value_list_append_value (&list, &depth);
650 g_value_set_int (&depth, 24);
651 gst_value_list_append_value (&list, &depth);
653 gst_structure_set (tmp, "width", G_TYPE_INT, 32, NULL);
654 gst_structure_set_value (tmp, "depth", &list);
655 gst_caps_append_structure (caps, tmp);
657 g_value_unset (&list);
658 g_value_unset (&depth);
662 gst_flac_enc_getcaps (GstAudioEncoder * enc, GstCaps * filter)
664 GstCaps *ret = NULL, *caps = NULL;
667 pad = GST_AUDIO_ENCODER_SINK_PAD (enc);
669 GST_OBJECT_LOCK (pad);
671 if (gst_pad_has_current_caps (pad)) {
672 ret = gst_pad_get_current_caps (pad);
676 ret = gst_caps_new_empty ();
678 gst_flac_enc_caps_append_structure_with_widths (ret,
679 gst_structure_new ("audio/x-raw-int",
680 "endianness", G_TYPE_INT, G_BYTE_ORDER,
681 "signed", G_TYPE_BOOLEAN, TRUE,
682 "rate", GST_TYPE_INT_RANGE, 1, 655350,
683 "channels", GST_TYPE_INT_RANGE, 1, 2, NULL));
685 for (i = 3; i <= 8; i++) {
686 GValue positions = { 0, };
690 g_value_init (&positions, GST_TYPE_ARRAY);
691 g_value_init (&pos, GST_TYPE_AUDIO_CHANNEL_POSITION);
693 for (c = 0; c < i; c++) {
694 g_value_set_enum (&pos, channel_positions[i - 1][c]);
695 gst_value_array_append_value (&positions, &pos);
697 g_value_unset (&pos);
699 s = gst_structure_new ("audio/x-raw-int",
700 "endianness", G_TYPE_INT, G_BYTE_ORDER,
701 "signed", G_TYPE_BOOLEAN, TRUE,
702 "rate", GST_TYPE_INT_RANGE, 1, 655350,
703 "channels", G_TYPE_INT, i, NULL);
704 gst_structure_set_value (s, "channel-positions", &positions);
705 g_value_unset (&positions);
707 gst_flac_enc_caps_append_structure_with_widths (ret, s);
711 GST_OBJECT_UNLOCK (pad);
713 GST_DEBUG_OBJECT (pad, "Return caps %" GST_PTR_FORMAT, ret);
715 caps = gst_audio_encoder_proxy_getcaps (enc, ret);
716 gst_caps_unref (ret);
722 gst_flac_enc_query_peer_total_samples (GstFlacEnc * flacenc, GstPad * pad)
726 GST_DEBUG_OBJECT (flacenc, "querying peer for DEFAULT format duration");
727 if (gst_pad_query_peer_duration (pad, GST_FORMAT_DEFAULT, &duration)
728 && duration != GST_CLOCK_TIME_NONE)
731 GST_DEBUG_OBJECT (flacenc, "querying peer for TIME format duration");
733 if (gst_pad_query_peer_duration (pad, GST_FORMAT_TIME, &duration)
734 && duration != GST_CLOCK_TIME_NONE) {
735 GST_DEBUG_OBJECT (flacenc, "peer reported duration %" GST_TIME_FORMAT,
736 GST_TIME_ARGS (duration));
737 duration = GST_CLOCK_TIME_TO_FRAMES (duration, flacenc->sample_rate);
742 GST_DEBUG_OBJECT (flacenc, "Upstream reported no total samples");
743 return GST_CLOCK_TIME_NONE;
746 GST_DEBUG_OBJECT (flacenc,
747 "Upstream reported %" G_GUINT64_FORMAT " total samples", duration);
753 gst_flac_enc_set_format (GstAudioEncoder * enc, GstAudioInfo * info)
756 guint64 total_samples = GST_CLOCK_TIME_NONE;
757 FLAC__StreamEncoderInitStatus init_status;
760 flacenc = GST_FLAC_ENC (enc);
762 /* if configured again, means something changed, can't handle that */
763 if (FLAC__stream_encoder_get_state (flacenc->encoder) !=
764 FLAC__STREAM_ENCODER_UNINITIALIZED)
765 goto encoder_already_initialized;
767 flacenc->channels = GST_AUDIO_INFO_CHANNELS (info);
768 flacenc->width = GST_AUDIO_INFO_WIDTH (info);
769 flacenc->depth = GST_AUDIO_INFO_DEPTH (info);
770 flacenc->sample_rate = GST_AUDIO_INFO_RATE (info);
772 caps = gst_caps_new_simple ("audio/x-flac",
773 "channels", G_TYPE_INT, flacenc->channels,
774 "rate", G_TYPE_INT, flacenc->sample_rate, NULL);
776 if (!gst_pad_set_caps (GST_AUDIO_ENCODER_SRC_PAD (enc), caps))
777 goto setting_src_caps_failed;
779 gst_caps_unref (caps);
781 total_samples = gst_flac_enc_query_peer_total_samples (flacenc,
782 GST_AUDIO_ENCODER_SINK_PAD (enc));
784 FLAC__stream_encoder_set_bits_per_sample (flacenc->encoder, flacenc->depth);
785 FLAC__stream_encoder_set_sample_rate (flacenc->encoder, flacenc->sample_rate);
786 FLAC__stream_encoder_set_channels (flacenc->encoder, flacenc->channels);
788 if (total_samples != GST_CLOCK_TIME_NONE)
789 FLAC__stream_encoder_set_total_samples_estimate (flacenc->encoder,
790 MIN (total_samples, G_GUINT64_CONSTANT (0x0FFFFFFFFF)));
792 gst_flac_enc_set_metadata (flacenc, total_samples);
794 /* callbacks clear to go now;
795 * write callbacks receives headers during init */
796 flacenc->stopped = FALSE;
798 init_status = FLAC__stream_encoder_init_stream (flacenc->encoder,
799 gst_flac_enc_write_callback, gst_flac_enc_seek_callback,
800 gst_flac_enc_tell_callback, NULL, flacenc);
801 if (init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK)
802 goto failed_to_initialize;
804 /* no special feedback to base class; should provide all available samples */
808 encoder_already_initialized:
810 g_warning ("flac already initialized -- fixme allow this");
811 gst_object_unref (flacenc);
814 setting_src_caps_failed:
816 GST_DEBUG_OBJECT (flacenc,
817 "Couldn't set caps on source pad: %" GST_PTR_FORMAT, caps);
818 gst_caps_unref (caps);
819 gst_object_unref (flacenc);
822 failed_to_initialize:
824 GST_ELEMENT_ERROR (flacenc, LIBRARY, INIT, (NULL),
825 ("could not initialize encoder (wrong parameters?)"));
826 gst_object_unref (flacenc);
832 gst_flac_enc_update_quality (GstFlacEnc * flacenc, gint quality)
834 flacenc->quality = quality;
836 #define DO_UPDATE(name, val, str) \
838 if (FLAC__stream_encoder_get_##name (flacenc->encoder) != \
839 flacenc_params[quality].val) { \
840 FLAC__stream_encoder_set_##name (flacenc->encoder, \
841 flacenc_params[quality].val); \
842 g_object_notify (G_OBJECT (flacenc), str); \
846 g_object_freeze_notify (G_OBJECT (flacenc));
848 if (flacenc->channels == 2 || flacenc->channels == 0) {
849 DO_UPDATE (do_mid_side_stereo, mid_side, "mid_side_stereo");
850 DO_UPDATE (loose_mid_side_stereo, loose_mid_side, "loose_mid_side");
853 DO_UPDATE (blocksize, blocksize, "blocksize");
854 DO_UPDATE (max_lpc_order, max_lpc_order, "max_lpc_order");
855 DO_UPDATE (qlp_coeff_precision, qlp_coeff_precision, "qlp_coeff_precision");
856 DO_UPDATE (do_qlp_coeff_prec_search, qlp_coeff_prec_search,
857 "qlp_coeff_prec_search");
858 DO_UPDATE (do_escape_coding, escape_coding, "escape_coding");
859 DO_UPDATE (do_exhaustive_model_search, exhaustive_model_search,
860 "exhaustive_model_search");
861 DO_UPDATE (min_residual_partition_order, min_residual_partition_order,
862 "min_residual_partition_order");
863 DO_UPDATE (max_residual_partition_order, max_residual_partition_order,
864 "max_residual_partition_order");
865 DO_UPDATE (rice_parameter_search_dist, rice_parameter_search_dist,
866 "rice_parameter_search_dist");
870 g_object_thaw_notify (G_OBJECT (flacenc));
875 static FLAC__StreamEncoderSeekStatus
876 gst_flac_enc_seek_callback (const FLAC__StreamEncoder * encoder,
877 FLAC__uint64 absolute_byte_offset, void *client_data)
884 flacenc = GST_FLAC_ENC (client_data);
886 if (flacenc->stopped)
887 return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
889 gst_segment_init (&seg, GST_FORMAT_BYTES);
890 seg.start = absolute_byte_offset;
891 seg.stop = GST_BUFFER_OFFSET_NONE;
893 event = gst_event_new_segment (&seg);
895 if ((peerpad = gst_pad_get_peer (GST_AUDIO_ENCODER_SRC_PAD (flacenc)))) {
896 gboolean ret = gst_pad_send_event (peerpad, event);
898 gst_object_unref (peerpad);
901 GST_DEBUG ("Seek to %" G_GUINT64_FORMAT " %s",
902 (guint64) absolute_byte_offset, "succeeded");
904 GST_DEBUG ("Seek to %" G_GUINT64_FORMAT " %s",
905 (guint64) absolute_byte_offset, "failed");
906 return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
909 GST_DEBUG ("Seek to %" G_GUINT64_FORMAT " failed (no peer pad)",
910 (guint64) absolute_byte_offset);
913 flacenc->offset = absolute_byte_offset;
914 return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
918 notgst_value_array_append_buffer (GValue * array_val, GstBuffer * buf)
920 GValue value = { 0, };
922 g_value_init (&value, GST_TYPE_BUFFER);
923 /* copy buffer to avoid problems with circular refcounts */
924 buf = gst_buffer_copy (buf);
925 /* again, for good measure */
926 GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_IN_CAPS);
927 gst_value_set_buffer (&value, buf);
928 gst_buffer_unref (buf);
929 gst_value_array_append_value (array_val, &value);
930 g_value_unset (&value);
933 #define HDR_TYPE_STREAMINFO 0
934 #define HDR_TYPE_VORBISCOMMENT 4
937 gst_flac_enc_process_stream_headers (GstFlacEnc * enc)
939 GstBuffer *vorbiscomment = NULL;
940 GstBuffer *streaminfo = NULL;
941 GstBuffer *marker = NULL;
942 GValue array = { 0, };
945 GstFlowReturn ret = GST_FLOW_OK;
947 caps = gst_caps_new_simple ("audio/x-flac",
948 "channels", G_TYPE_INT, enc->channels,
949 "rate", G_TYPE_INT, enc->sample_rate, NULL);
951 for (l = enc->headers; l != NULL; l = l->next) {
956 /* mark buffers so oggmux will ignore them if it already muxed the
957 * header buffers from the streamheaders field in the caps */
958 l->data = gst_buffer_make_writable (GST_BUFFER_CAST (l->data));
960 buf = GST_BUFFER_CAST (l->data);
961 GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_IN_CAPS);
963 data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
965 /* find initial 4-byte marker which we need to skip later on */
966 if (size == 4 && memcmp (data, "fLaC", 4) == 0) {
968 } else if (size > 1 && (data[0] & 0x7f) == HDR_TYPE_STREAMINFO) {
970 } else if (size > 1 && (data[0] & 0x7f) == HDR_TYPE_VORBISCOMMENT) {
974 gst_buffer_unmap (buf, data, size);
977 if (marker == NULL || streaminfo == NULL || vorbiscomment == NULL) {
978 GST_WARNING_OBJECT (enc, "missing header %p %p %p, muxing into container "
979 "formats may be broken", marker, streaminfo, vorbiscomment);
983 g_value_init (&array, GST_TYPE_ARRAY);
985 /* add marker including STREAMINFO header */
992 /* minus one for the marker that is merged with streaminfo here */
993 num = g_list_length (enc->headers) - 1;
995 slen = gst_buffer_get_size (streaminfo);
996 buf = gst_buffer_new_and_alloc (13 + slen);
998 bdata = gst_buffer_map (buf, &bsize, NULL, GST_MAP_WRITE);
1000 memcpy (bdata + 1, "FLAC", 4);
1001 bdata[5] = 0x01; /* mapping version major */
1002 bdata[6] = 0x00; /* mapping version minor */
1003 bdata[7] = (num & 0xFF00) >> 8;
1004 bdata[8] = (num & 0x00FF) >> 0;
1005 memcpy (bdata + 9, "fLaC", 4);
1006 gst_buffer_extract (streaminfo, 0, bdata + 13, slen);
1007 gst_buffer_unmap (buf, bdata, bsize);
1009 notgst_value_array_append_buffer (&array, buf);
1010 gst_buffer_unref (buf);
1013 /* add VORBISCOMMENT header */
1014 notgst_value_array_append_buffer (&array, vorbiscomment);
1016 /* add other headers, if there are any */
1017 for (l = enc->headers; l != NULL; l = l->next) {
1018 GstBuffer *buf = GST_BUFFER_CAST (l->data);
1020 if (buf != marker && buf != streaminfo && buf != vorbiscomment) {
1021 notgst_value_array_append_buffer (&array, buf);
1025 gst_structure_set_value (gst_caps_get_structure (caps, 0),
1026 "streamheader", &array);
1027 g_value_unset (&array);
1031 /* push header buffers; update caps, so when we push the first buffer the
1032 * negotiated caps will change to caps that include the streamheader field */
1033 for (l = enc->headers; l != NULL; l = l->next) {
1036 buf = GST_BUFFER (l->data);
1037 GST_LOG_OBJECT (enc, "Pushing header buffer, size %u bytes",
1038 gst_buffer_get_size (buf));
1040 GST_MEMDUMP_OBJECT (enc, "header buffer", GST_BUFFER_DATA (buf),
1041 GST_BUFFER_SIZE (buf));
1043 ret = gst_pad_push (GST_AUDIO_ENCODER_SRC_PAD (enc), buf);
1046 g_list_free (enc->headers);
1047 enc->headers = NULL;
1049 gst_caps_unref (caps);
1054 static FLAC__StreamEncoderWriteStatus
1055 gst_flac_enc_write_callback (const FLAC__StreamEncoder * encoder,
1056 const FLAC__byte buffer[], size_t bytes,
1057 unsigned samples, unsigned current_frame, void *client_data)
1059 GstFlowReturn ret = GST_FLOW_OK;
1060 GstFlacEnc *flacenc;
1063 flacenc = GST_FLAC_ENC (client_data);
1065 if (flacenc->stopped)
1066 return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
1068 outbuf = gst_buffer_new_and_alloc (bytes);
1069 gst_buffer_fill (outbuf, 0, buffer, bytes);
1071 /* we assume libflac passes us stuff neatly framed */
1072 if (!flacenc->got_headers) {
1074 GST_DEBUG_OBJECT (flacenc, "Got header, queueing (%u bytes)",
1076 flacenc->headers = g_list_append (flacenc->headers, outbuf);
1077 /* note: it's important that we increase our byte offset */
1080 GST_INFO_OBJECT (flacenc, "Non-header packet, we have all headers now");
1081 ret = gst_flac_enc_process_stream_headers (flacenc);
1082 flacenc->got_headers = TRUE;
1084 } else if (flacenc->got_headers && samples == 0) {
1085 /* header fixup, push downstream directly */
1086 GST_DEBUG_OBJECT (flacenc, "Fixing up headers at pos=%" G_GUINT64_FORMAT
1087 ", size=%u", flacenc->offset, (guint) bytes);
1089 GST_MEMDUMP_OBJECT (flacenc, "Presumed header fragment",
1090 GST_BUFFER_DATA (outbuf), GST_BUFFER_SIZE (outbuf));
1092 ret = gst_pad_push (GST_AUDIO_ENCODER_SRC_PAD (flacenc), outbuf);
1094 /* regular frame data, pass to base class */
1095 GST_LOG ("Pushing buffer: ts=%" GST_TIME_FORMAT ", samples=%u, size=%u, "
1096 "pos=%" G_GUINT64_FORMAT, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf)),
1097 samples, (guint) bytes, flacenc->offset);
1098 ret = gst_audio_encoder_finish_frame (GST_AUDIO_ENCODER (flacenc),
1102 if (ret != GST_FLOW_OK)
1103 GST_DEBUG_OBJECT (flacenc, "flow: %s", gst_flow_get_name (ret));
1105 flacenc->last_flow = ret;
1108 flacenc->offset += bytes;
1110 if (ret != GST_FLOW_OK)
1111 return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
1113 return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
1116 static FLAC__StreamEncoderTellStatus
1117 gst_flac_enc_tell_callback (const FLAC__StreamEncoder * encoder,
1118 FLAC__uint64 * absolute_byte_offset, void *client_data)
1120 GstFlacEnc *flacenc = GST_FLAC_ENC (client_data);
1122 *absolute_byte_offset = flacenc->offset;
1124 return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
1128 gst_flac_enc_sink_event (GstAudioEncoder * enc, GstEvent * event)
1130 GstFlacEnc *flacenc;
1131 GstTagList *taglist;
1132 gboolean ret = FALSE;
1134 flacenc = GST_FLAC_ENC (enc);
1136 GST_DEBUG ("Received %s event on sinkpad", GST_EVENT_TYPE_NAME (event));
1138 switch (GST_EVENT_TYPE (event)) {
1139 case GST_EVENT_SEGMENT:{
1141 gint64 start, stream_time;
1143 if (flacenc->offset == 0) {
1144 gst_event_copy_segment (event, &seg);
1146 stream_time = seg.time;
1153 if (flacenc->offset > 0)
1154 GST_DEBUG ("Not handling mid-stream newsegment event");
1156 GST_DEBUG ("Not handling newsegment event with non-zero start");
1160 gst_segment_init (&seg, GST_FORMAT_BYTES);
1161 e = gst_event_new_segment (&seg);
1162 ret = gst_pad_push_event (GST_AUDIO_ENCODER_SRC_PAD (enc), e);
1165 if (stream_time > 0) {
1166 GST_DEBUG ("Not handling non-zero stream time");
1169 /* don't push it downstream, we'll generate our own via seek to 0 */
1170 gst_event_unref (event);
1175 flacenc->eos = TRUE;
1178 if (flacenc->tags) {
1179 gst_event_parse_tag (event, &taglist);
1180 gst_tag_list_insert (flacenc->tags, taglist,
1181 gst_tag_setter_get_tag_merge_mode (GST_TAG_SETTER (flacenc)));
1183 g_assert_not_reached ();
1193 static GstFlowReturn
1194 gst_flac_enc_handle_frame (GstAudioEncoder * enc, GstBuffer * buffer)
1196 GstFlacEnc *flacenc;
1199 gint samples, width;
1204 flacenc = GST_FLAC_ENC (enc);
1206 /* base class ensures configuration */
1207 g_return_val_if_fail (flacenc->depth != 0, GST_FLOW_NOT_NEGOTIATED);
1209 width = flacenc->width;
1211 if (G_UNLIKELY (!buffer)) {
1213 FLAC__stream_encoder_finish (flacenc->encoder);
1215 /* can't handle intermittent draining/resyncing */
1216 GST_ELEMENT_WARNING (flacenc, STREAM, FORMAT, (NULL),
1217 ("Stream discontinuity detected. "
1218 "The output may have wrong timestamps, "
1219 "consider using audiorate to handle discontinuities"));
1221 return flacenc->last_flow;
1224 bdata = gst_buffer_map (buffer, &bsize, NULL, GST_MAP_READ);
1225 samples = bsize / (width >> 3);
1227 data = g_malloc (samples * sizeof (FLAC__int32));
1230 gint8 *indata = (gint8 *) bdata;
1232 for (i = 0; i < samples; i++)
1233 data[i] = (FLAC__int32) indata[i];
1234 } else if (width == 16) {
1235 gint16 *indata = (gint16 *) bdata;
1237 for (i = 0; i < samples; i++)
1238 data[i] = (FLAC__int32) indata[i];
1239 } else if (width == 32) {
1240 gint32 *indata = (gint32 *) bdata;
1242 for (i = 0; i < samples; i++)
1243 data[i] = (FLAC__int32) indata[i];
1245 g_assert_not_reached ();
1247 gst_buffer_unmap (buffer, bdata, bsize);
1249 res = FLAC__stream_encoder_process_interleaved (flacenc->encoder,
1250 (const FLAC__int32 *) data, samples / flacenc->channels);
1255 if (flacenc->last_flow == GST_FLOW_OK)
1256 return GST_FLOW_ERROR;
1258 return flacenc->last_flow;
1265 gst_flac_enc_set_property (GObject * object, guint prop_id,
1266 const GValue * value, GParamSpec * pspec)
1268 GstFlacEnc *this = GST_FLAC_ENC (object);
1270 GST_OBJECT_LOCK (this);
1274 gst_flac_enc_update_quality (this, g_value_get_enum (value));
1276 case PROP_STREAMABLE_SUBSET:
1277 FLAC__stream_encoder_set_streamable_subset (this->encoder,
1278 g_value_get_boolean (value));
1280 case PROP_MID_SIDE_STEREO:
1281 FLAC__stream_encoder_set_do_mid_side_stereo (this->encoder,
1282 g_value_get_boolean (value));
1284 case PROP_LOOSE_MID_SIDE_STEREO:
1285 FLAC__stream_encoder_set_loose_mid_side_stereo (this->encoder,
1286 g_value_get_boolean (value));
1288 case PROP_BLOCKSIZE:
1289 FLAC__stream_encoder_set_blocksize (this->encoder,
1290 g_value_get_uint (value));
1292 case PROP_MAX_LPC_ORDER:
1293 FLAC__stream_encoder_set_max_lpc_order (this->encoder,
1294 g_value_get_uint (value));
1296 case PROP_QLP_COEFF_PRECISION:
1297 FLAC__stream_encoder_set_qlp_coeff_precision (this->encoder,
1298 g_value_get_uint (value));
1300 case PROP_QLP_COEFF_PREC_SEARCH:
1301 FLAC__stream_encoder_set_do_qlp_coeff_prec_search (this->encoder,
1302 g_value_get_boolean (value));
1304 case PROP_ESCAPE_CODING:
1305 FLAC__stream_encoder_set_do_escape_coding (this->encoder,
1306 g_value_get_boolean (value));
1308 case PROP_EXHAUSTIVE_MODEL_SEARCH:
1309 FLAC__stream_encoder_set_do_exhaustive_model_search (this->encoder,
1310 g_value_get_boolean (value));
1312 case PROP_MIN_RESIDUAL_PARTITION_ORDER:
1313 FLAC__stream_encoder_set_min_residual_partition_order (this->encoder,
1314 g_value_get_uint (value));
1316 case PROP_MAX_RESIDUAL_PARTITION_ORDER:
1317 FLAC__stream_encoder_set_max_residual_partition_order (this->encoder,
1318 g_value_get_uint (value));
1320 case PROP_RICE_PARAMETER_SEARCH_DIST:
1321 FLAC__stream_encoder_set_rice_parameter_search_dist (this->encoder,
1322 g_value_get_uint (value));
1325 this->padding = g_value_get_uint (value);
1327 case PROP_SEEKPOINTS:
1328 this->seekpoints = g_value_get_int (value);
1331 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1335 GST_OBJECT_UNLOCK (this);
1339 gst_flac_enc_get_property (GObject * object, guint prop_id,
1340 GValue * value, GParamSpec * pspec)
1342 GstFlacEnc *this = GST_FLAC_ENC (object);
1344 GST_OBJECT_LOCK (this);
1348 g_value_set_enum (value, this->quality);
1350 case PROP_STREAMABLE_SUBSET:
1351 g_value_set_boolean (value,
1352 FLAC__stream_encoder_get_streamable_subset (this->encoder));
1354 case PROP_MID_SIDE_STEREO:
1355 g_value_set_boolean (value,
1356 FLAC__stream_encoder_get_do_mid_side_stereo (this->encoder));
1358 case PROP_LOOSE_MID_SIDE_STEREO:
1359 g_value_set_boolean (value,
1360 FLAC__stream_encoder_get_loose_mid_side_stereo (this->encoder));
1362 case PROP_BLOCKSIZE:
1363 g_value_set_uint (value,
1364 FLAC__stream_encoder_get_blocksize (this->encoder));
1366 case PROP_MAX_LPC_ORDER:
1367 g_value_set_uint (value,
1368 FLAC__stream_encoder_get_max_lpc_order (this->encoder));
1370 case PROP_QLP_COEFF_PRECISION:
1371 g_value_set_uint (value,
1372 FLAC__stream_encoder_get_qlp_coeff_precision (this->encoder));
1374 case PROP_QLP_COEFF_PREC_SEARCH:
1375 g_value_set_boolean (value,
1376 FLAC__stream_encoder_get_do_qlp_coeff_prec_search (this->encoder));
1378 case PROP_ESCAPE_CODING:
1379 g_value_set_boolean (value,
1380 FLAC__stream_encoder_get_do_escape_coding (this->encoder));
1382 case PROP_EXHAUSTIVE_MODEL_SEARCH:
1383 g_value_set_boolean (value,
1384 FLAC__stream_encoder_get_do_exhaustive_model_search (this->encoder));
1386 case PROP_MIN_RESIDUAL_PARTITION_ORDER:
1387 g_value_set_uint (value,
1388 FLAC__stream_encoder_get_min_residual_partition_order
1391 case PROP_MAX_RESIDUAL_PARTITION_ORDER:
1392 g_value_set_uint (value,
1393 FLAC__stream_encoder_get_max_residual_partition_order
1396 case PROP_RICE_PARAMETER_SEARCH_DIST:
1397 g_value_set_uint (value,
1398 FLAC__stream_encoder_get_rice_parameter_search_dist (this->encoder));
1401 g_value_set_uint (value, this->padding);
1403 case PROP_SEEKPOINTS:
1404 g_value_set_int (value, this->seekpoints);
1407 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1411 GST_OBJECT_UNLOCK (this);