Merge branch 'master' into 0.11
Conflicts: ext/flac/gstflacenc.c
This commit is contained in:
commit
762602d56a
@ -1,7 +1,8 @@
|
|||||||
plugin_LTLIBRARIES = libgstflac.la
|
plugin_LTLIBRARIES = libgstflac.la
|
||||||
|
|
||||||
libgstflac_la_SOURCES = gstflac.c gstflacdec.c gstflacenc.c gstflactag.c
|
libgstflac_la_SOURCES = gstflac.c gstflacdec.c gstflacenc.c gstflactag.c
|
||||||
libgstflac_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CFLAGS) $(FLAC_CFLAGS)
|
libgstflac_la_CFLAGS = -DGST_USE_UNSTABLE_API \
|
||||||
|
$(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CFLAGS) $(FLAC_CFLAGS)
|
||||||
libgstflac_la_LIBADD = \
|
libgstflac_la_LIBADD = \
|
||||||
$(GST_PLUGINS_BASE_LIBS) -lgsttag-$(GST_MAJORMINOR) \
|
$(GST_PLUGINS_BASE_LIBS) -lgsttag-$(GST_MAJORMINOR) \
|
||||||
-lgstaudio-$(GST_MAJORMINOR) \
|
-lgstaudio-$(GST_MAJORMINOR) \
|
||||||
|
@ -151,24 +151,26 @@ GST_DEBUG_CATEGORY_STATIC (flacenc_debug);
|
|||||||
|
|
||||||
#define gst_flac_enc_parent_class parent_class
|
#define gst_flac_enc_parent_class parent_class
|
||||||
G_DEFINE_TYPE_WITH_CODE (GstFlacEnc, gst_flac_enc, GST_TYPE_ELEMENT,
|
G_DEFINE_TYPE_WITH_CODE (GstFlacEnc, gst_flac_enc, GST_TYPE_ELEMENT,
|
||||||
G_IMPLEMENT_INTERFACE (GST_TYPE_TAG_SETTER, NULL);
|
G_IMPLEMENT_INTERFACE (GST_TYPE_TAG_SETTER, NULL));
|
||||||
G_IMPLEMENT_INTERFACE (GST_TYPE_PRESET, NULL));
|
|
||||||
|
static gboolean gst_flac_enc_start (GstAudioEncoder * enc);
|
||||||
|
static gboolean gst_flac_enc_stop (GstAudioEncoder * enc);
|
||||||
|
static gboolean gst_flac_enc_set_format (GstAudioEncoder * enc,
|
||||||
|
GstAudioInfo * info);
|
||||||
|
static GstFlowReturn gst_flac_enc_handle_frame (GstAudioEncoder * enc,
|
||||||
|
GstBuffer * in_buf);
|
||||||
|
static GstCaps *gst_flac_enc_getcaps (GstAudioEncoder * enc, GstCaps * filter);
|
||||||
|
static gboolean gst_flac_enc_sink_event (GstAudioEncoder * enc,
|
||||||
|
GstEvent * event);
|
||||||
|
|
||||||
static void gst_flac_enc_finalize (GObject * object);
|
static void gst_flac_enc_finalize (GObject * object);
|
||||||
|
|
||||||
static gboolean gst_flac_enc_sink_setcaps (GstPad * pad, GstCaps * caps);
|
|
||||||
static GstCaps *gst_flac_enc_sink_getcaps (GstPad * pad);
|
|
||||||
static gboolean gst_flac_enc_sink_event (GstPad * pad, GstEvent * event);
|
|
||||||
static GstFlowReturn gst_flac_enc_chain (GstPad * pad, GstBuffer * buffer);
|
|
||||||
|
|
||||||
static gboolean gst_flac_enc_update_quality (GstFlacEnc * flacenc,
|
static gboolean gst_flac_enc_update_quality (GstFlacEnc * flacenc,
|
||||||
gint quality);
|
gint quality);
|
||||||
static void gst_flac_enc_set_property (GObject * object, guint prop_id,
|
static void gst_flac_enc_set_property (GObject * object, guint prop_id,
|
||||||
const GValue * value, GParamSpec * pspec);
|
const GValue * value, GParamSpec * pspec);
|
||||||
static void gst_flac_enc_get_property (GObject * object, guint prop_id,
|
static void gst_flac_enc_get_property (GObject * object, guint prop_id,
|
||||||
GValue * value, GParamSpec * pspec);
|
GValue * value, GParamSpec * pspec);
|
||||||
static GstStateChangeReturn gst_flac_enc_change_state (GstElement * element,
|
|
||||||
GstStateChange transition);
|
|
||||||
|
|
||||||
static FLAC__StreamEncoderWriteStatus
|
static FLAC__StreamEncoderWriteStatus
|
||||||
gst_flac_enc_write_callback (const FLAC__StreamEncoder * encoder,
|
gst_flac_enc_write_callback (const FLAC__StreamEncoder * encoder,
|
||||||
@ -245,9 +247,11 @@ gst_flac_enc_class_init (GstFlacEncClass * klass)
|
|||||||
{
|
{
|
||||||
GObjectClass *gobject_class;
|
GObjectClass *gobject_class;
|
||||||
GstElementClass *gstelement_class;
|
GstElementClass *gstelement_class;
|
||||||
|
GstAudioEncoderClass *base_class;
|
||||||
|
|
||||||
gobject_class = (GObjectClass *) klass;
|
gobject_class = (GObjectClass *) klass;
|
||||||
gstelement_class = (GstElementClass *) klass;
|
gstelement_class = (GstElementClass *) klass;
|
||||||
|
base_class = (GstAudioEncoderClass *) (klass);
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY_INIT (flacenc_debug, "flacenc", 0,
|
GST_DEBUG_CATEGORY_INIT (flacenc_debug, "flacenc", 0,
|
||||||
"Flac encoding element");
|
"Flac encoding element");
|
||||||
@ -369,8 +373,6 @@ gst_flac_enc_class_init (GstFlacEncClass * klass)
|
|||||||
DEFAULT_SEEKPOINTS,
|
DEFAULT_SEEKPOINTS,
|
||||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
gstelement_class->change_state = gst_flac_enc_change_state;
|
|
||||||
|
|
||||||
gst_element_class_add_pad_template (gstelement_class,
|
gst_element_class_add_pad_template (gstelement_class,
|
||||||
gst_static_pad_template_get (&src_factory));
|
gst_static_pad_template_get (&src_factory));
|
||||||
gst_element_class_add_pad_template (gstelement_class,
|
gst_element_class_add_pad_template (gstelement_class,
|
||||||
@ -380,36 +382,26 @@ gst_flac_enc_class_init (GstFlacEncClass * klass)
|
|||||||
"Codec/Encoder/Audio",
|
"Codec/Encoder/Audio",
|
||||||
"Encodes audio with the FLAC lossless audio encoder",
|
"Encodes audio with the FLAC lossless audio encoder",
|
||||||
"Wim Taymans <wim.taymans@chello.be>");
|
"Wim Taymans <wim.taymans@chello.be>");
|
||||||
|
|
||||||
|
base_class->start = GST_DEBUG_FUNCPTR (gst_flac_enc_start);
|
||||||
|
base_class->stop = GST_DEBUG_FUNCPTR (gst_flac_enc_stop);
|
||||||
|
base_class->set_format = GST_DEBUG_FUNCPTR (gst_flac_enc_set_format);
|
||||||
|
base_class->handle_frame = GST_DEBUG_FUNCPTR (gst_flac_enc_handle_frame);
|
||||||
|
base_class->getcaps = GST_DEBUG_FUNCPTR (gst_flac_enc_getcaps);
|
||||||
|
base_class->event = GST_DEBUG_FUNCPTR (gst_flac_enc_sink_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_flac_enc_init (GstFlacEnc * flacenc)
|
gst_flac_enc_init (GstFlacEnc * flacenc)
|
||||||
{
|
{
|
||||||
flacenc->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
|
GstAudioEncoder *enc = GST_AUDIO_ENCODER (flacenc);
|
||||||
gst_pad_set_chain_function (flacenc->sinkpad,
|
|
||||||
GST_DEBUG_FUNCPTR (gst_flac_enc_chain));
|
|
||||||
gst_pad_set_event_function (flacenc->sinkpad,
|
|
||||||
GST_DEBUG_FUNCPTR (gst_flac_enc_sink_event));
|
|
||||||
gst_pad_set_getcaps_function (flacenc->sinkpad,
|
|
||||||
GST_DEBUG_FUNCPTR (gst_flac_enc_sink_getcaps));
|
|
||||||
gst_pad_set_setcaps_function (flacenc->sinkpad,
|
|
||||||
GST_DEBUG_FUNCPTR (gst_flac_enc_sink_setcaps));
|
|
||||||
gst_element_add_pad (GST_ELEMENT (flacenc), flacenc->sinkpad);
|
|
||||||
|
|
||||||
flacenc->srcpad = gst_pad_new_from_static_template (&src_factory, "src");
|
|
||||||
gst_pad_use_fixed_caps (flacenc->srcpad);
|
|
||||||
gst_element_add_pad (GST_ELEMENT (flacenc), flacenc->srcpad);
|
|
||||||
|
|
||||||
flacenc->encoder = FLAC__stream_encoder_new ();
|
flacenc->encoder = FLAC__stream_encoder_new ();
|
||||||
|
|
||||||
flacenc->offset = 0;
|
|
||||||
flacenc->samples_written = 0;
|
|
||||||
flacenc->channels = 0;
|
|
||||||
gst_flac_enc_update_quality (flacenc, DEFAULT_QUALITY);
|
gst_flac_enc_update_quality (flacenc, DEFAULT_QUALITY);
|
||||||
flacenc->tags = gst_tag_list_new ();
|
|
||||||
flacenc->got_headers = FALSE;
|
/* arrange granulepos marking (and required perfect ts) */
|
||||||
flacenc->headers = NULL;
|
gst_audio_encoder_set_mark_granule (enc, TRUE);
|
||||||
flacenc->last_flow = GST_FLOW_OK;
|
gst_audio_encoder_set_perfect_timestamp (enc, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -417,12 +409,62 @@ gst_flac_enc_finalize (GObject * object)
|
|||||||
{
|
{
|
||||||
GstFlacEnc *flacenc = GST_FLAC_ENC (object);
|
GstFlacEnc *flacenc = GST_FLAC_ENC (object);
|
||||||
|
|
||||||
gst_tag_list_free (flacenc->tags);
|
|
||||||
FLAC__stream_encoder_delete (flacenc->encoder);
|
FLAC__stream_encoder_delete (flacenc->encoder);
|
||||||
|
|
||||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_flac_enc_start (GstAudioEncoder * enc)
|
||||||
|
{
|
||||||
|
GstFlacEnc *flacenc = GST_FLAC_ENC (enc);
|
||||||
|
|
||||||
|
GST_DEBUG_OBJECT (enc, "start");
|
||||||
|
flacenc->stopped = TRUE;
|
||||||
|
flacenc->got_headers = FALSE;
|
||||||
|
flacenc->last_flow = GST_FLOW_OK;
|
||||||
|
flacenc->offset = 0;
|
||||||
|
flacenc->channels = 0;
|
||||||
|
flacenc->depth = 0;
|
||||||
|
flacenc->sample_rate = 0;
|
||||||
|
flacenc->eos = FALSE;
|
||||||
|
flacenc->tags = gst_tag_list_new ();
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_flac_enc_stop (GstAudioEncoder * enc)
|
||||||
|
{
|
||||||
|
GstFlacEnc *flacenc = GST_FLAC_ENC (enc);
|
||||||
|
|
||||||
|
GST_DEBUG_OBJECT (enc, "stop");
|
||||||
|
gst_tag_list_free (flacenc->tags);
|
||||||
|
flacenc->tags = NULL;
|
||||||
|
if (FLAC__stream_encoder_get_state (flacenc->encoder) !=
|
||||||
|
FLAC__STREAM_ENCODER_UNINITIALIZED) {
|
||||||
|
flacenc->stopped = TRUE;
|
||||||
|
FLAC__stream_encoder_finish (flacenc->encoder);
|
||||||
|
}
|
||||||
|
if (flacenc->meta) {
|
||||||
|
FLAC__metadata_object_delete (flacenc->meta[0]);
|
||||||
|
|
||||||
|
if (flacenc->meta[1])
|
||||||
|
FLAC__metadata_object_delete (flacenc->meta[1]);
|
||||||
|
|
||||||
|
if (flacenc->meta[2])
|
||||||
|
FLAC__metadata_object_delete (flacenc->meta[2]);
|
||||||
|
|
||||||
|
g_free (flacenc->meta);
|
||||||
|
flacenc->meta = NULL;
|
||||||
|
}
|
||||||
|
g_list_foreach (flacenc->headers, (GFunc) gst_mini_object_unref, NULL);
|
||||||
|
g_list_free (flacenc->headers);
|
||||||
|
flacenc->headers = NULL;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
add_one_tag (const GstTagList * list, const gchar * tag, gpointer user_data)
|
add_one_tag (const GstTagList * list, const gchar * tag, gpointer user_data)
|
||||||
{
|
{
|
||||||
@ -478,9 +520,11 @@ gst_flac_enc_set_metadata (GstFlacEnc * flacenc, guint64 total_samples)
|
|||||||
|
|
||||||
if (n_images + n_preview_images > 0) {
|
if (n_images + n_preview_images > 0) {
|
||||||
GstBuffer *buffer;
|
GstBuffer *buffer;
|
||||||
|
#if 0
|
||||||
GstCaps *caps;
|
GstCaps *caps;
|
||||||
GstStructure *structure;
|
GstStructure *structure;
|
||||||
GstTagImageType image_type = GST_TAG_IMAGE_TYPE_NONE;
|
GstTagImageType image_type = GST_TAG_IMAGE_TYPE_NONE;
|
||||||
|
#endif
|
||||||
gint i;
|
gint i;
|
||||||
guint8 *data;
|
guint8 *data;
|
||||||
gsize size;
|
gsize size;
|
||||||
@ -498,6 +542,7 @@ gst_flac_enc_set_metadata (GstFlacEnc * flacenc, guint64 total_samples)
|
|||||||
flacenc->meta[entries] =
|
flacenc->meta[entries] =
|
||||||
FLAC__metadata_object_new (FLAC__METADATA_TYPE_PICTURE);
|
FLAC__metadata_object_new (FLAC__METADATA_TYPE_PICTURE);
|
||||||
|
|
||||||
|
#if 0
|
||||||
caps = gst_buffer_get_caps (buffer);
|
caps = gst_buffer_get_caps (buffer);
|
||||||
structure = gst_caps_get_structure (caps, 0);
|
structure = gst_caps_get_structure (caps, 0);
|
||||||
|
|
||||||
@ -508,18 +553,21 @@ gst_flac_enc_set_metadata (GstFlacEnc * flacenc, guint64 total_samples)
|
|||||||
image_type = (i < n_images) ? 0x00 : 0x01;
|
image_type = (i < n_images) ? 0x00 : 0x01;
|
||||||
else
|
else
|
||||||
image_type = image_type + 2;
|
image_type = image_type + 2;
|
||||||
|
#endif
|
||||||
|
|
||||||
data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
|
data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
|
||||||
FLAC__metadata_object_picture_set_data (flacenc->meta[entries],
|
FLAC__metadata_object_picture_set_data (flacenc->meta[entries],
|
||||||
data, size, TRUE);
|
data, size, TRUE);
|
||||||
gst_buffer_unmap (buffer, data, size);
|
gst_buffer_unmap (buffer, data, size);
|
||||||
|
|
||||||
|
#if 0
|
||||||
/* FIXME: There's no way to set the picture type in libFLAC */
|
/* FIXME: There's no way to set the picture type in libFLAC */
|
||||||
flacenc->meta[entries]->data.picture.type = image_type;
|
flacenc->meta[entries]->data.picture.type = image_type;
|
||||||
FLAC__metadata_object_picture_set_mime_type (flacenc->meta[entries],
|
FLAC__metadata_object_picture_set_mime_type (flacenc->meta[entries],
|
||||||
(char *) gst_structure_get_name (structure), TRUE);
|
(char *) gst_structure_get_name (structure), TRUE);
|
||||||
|
|
||||||
gst_caps_unref (caps);
|
gst_caps_unref (caps);
|
||||||
|
#endif
|
||||||
|
|
||||||
gst_buffer_unref (buffer);
|
gst_buffer_unref (buffer);
|
||||||
entries++;
|
entries++;
|
||||||
}
|
}
|
||||||
@ -611,14 +659,17 @@ gst_flac_enc_caps_append_structure_with_widths (GstCaps * caps,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static GstCaps *
|
static GstCaps *
|
||||||
gst_flac_enc_sink_getcaps (GstPad * pad)
|
gst_flac_enc_getcaps (GstAudioEncoder * enc, GstCaps * filter)
|
||||||
{
|
{
|
||||||
GstCaps *ret = NULL;
|
GstCaps *ret = NULL, *caps = NULL;
|
||||||
|
GstPad *pad;
|
||||||
|
|
||||||
|
pad = GST_AUDIO_ENCODER_SINK_PAD (enc);
|
||||||
|
|
||||||
GST_OBJECT_LOCK (pad);
|
GST_OBJECT_LOCK (pad);
|
||||||
|
|
||||||
if (GST_PAD_CAPS (pad)) {
|
if (gst_pad_has_current_caps (pad)) {
|
||||||
ret = gst_caps_ref (GST_PAD_CAPS (pad));
|
ret = gst_pad_get_current_caps (pad);
|
||||||
} else {
|
} else {
|
||||||
gint i, c;
|
gint i, c;
|
||||||
|
|
||||||
@ -661,25 +712,26 @@ gst_flac_enc_sink_getcaps (GstPad * pad)
|
|||||||
|
|
||||||
GST_DEBUG_OBJECT (pad, "Return caps %" GST_PTR_FORMAT, ret);
|
GST_DEBUG_OBJECT (pad, "Return caps %" GST_PTR_FORMAT, ret);
|
||||||
|
|
||||||
return ret;
|
caps = gst_audio_encoder_proxy_getcaps (enc, ret);
|
||||||
|
gst_caps_unref (ret);
|
||||||
|
|
||||||
|
return caps;
|
||||||
}
|
}
|
||||||
|
|
||||||
static guint64
|
static guint64
|
||||||
gst_flac_enc_query_peer_total_samples (GstFlacEnc * flacenc, GstPad * pad)
|
gst_flac_enc_query_peer_total_samples (GstFlacEnc * flacenc, GstPad * pad)
|
||||||
{
|
{
|
||||||
GstFormat fmt = GST_FORMAT_DEFAULT;
|
|
||||||
gint64 duration;
|
gint64 duration;
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (flacenc, "querying peer for DEFAULT format duration");
|
GST_DEBUG_OBJECT (flacenc, "querying peer for DEFAULT format duration");
|
||||||
if (gst_pad_query_peer_duration (pad, &fmt, &duration)
|
if (gst_pad_query_peer_duration (pad, GST_FORMAT_DEFAULT, &duration)
|
||||||
&& fmt == GST_FORMAT_DEFAULT && duration != GST_CLOCK_TIME_NONE)
|
&& duration != GST_CLOCK_TIME_NONE)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
fmt = GST_FORMAT_TIME;
|
|
||||||
GST_DEBUG_OBJECT (flacenc, "querying peer for TIME format duration");
|
GST_DEBUG_OBJECT (flacenc, "querying peer for TIME format duration");
|
||||||
|
|
||||||
if (gst_pad_query_peer_duration (pad, &fmt, &duration) &&
|
if (gst_pad_query_peer_duration (pad, GST_FORMAT_TIME, &duration)
|
||||||
fmt == GST_FORMAT_TIME && duration != GST_CLOCK_TIME_NONE) {
|
&& duration != GST_CLOCK_TIME_NONE) {
|
||||||
GST_DEBUG_OBJECT (flacenc, "peer reported duration %" GST_TIME_FORMAT,
|
GST_DEBUG_OBJECT (flacenc, "peer reported duration %" GST_TIME_FORMAT,
|
||||||
GST_TIME_ARGS (duration));
|
GST_TIME_ARGS (duration));
|
||||||
duration = GST_CLOCK_TIME_TO_FRAMES (duration, flacenc->sample_rate);
|
duration = GST_CLOCK_TIME_TO_FRAMES (duration, flacenc->sample_rate);
|
||||||
@ -698,45 +750,36 @@ done:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_flac_enc_sink_setcaps (GstPad * pad, GstCaps * caps)
|
gst_flac_enc_set_format (GstAudioEncoder * enc, GstAudioInfo * info)
|
||||||
{
|
{
|
||||||
GstFlacEnc *flacenc;
|
GstFlacEnc *flacenc;
|
||||||
GstStructure *structure;
|
|
||||||
guint64 total_samples = GST_CLOCK_TIME_NONE;
|
guint64 total_samples = GST_CLOCK_TIME_NONE;
|
||||||
FLAC__StreamEncoderInitStatus init_status;
|
FLAC__StreamEncoderInitStatus init_status;
|
||||||
gint depth, chans, rate, width;
|
GstCaps *caps;
|
||||||
|
|
||||||
flacenc = GST_FLAC_ENC (gst_pad_get_parent (pad));
|
flacenc = GST_FLAC_ENC (enc);
|
||||||
|
|
||||||
|
/* if configured again, means something changed, can't handle that */
|
||||||
if (FLAC__stream_encoder_get_state (flacenc->encoder) !=
|
if (FLAC__stream_encoder_get_state (flacenc->encoder) !=
|
||||||
FLAC__STREAM_ENCODER_UNINITIALIZED)
|
FLAC__STREAM_ENCODER_UNINITIALIZED)
|
||||||
goto encoder_already_initialized;
|
goto encoder_already_initialized;
|
||||||
|
|
||||||
structure = gst_caps_get_structure (caps, 0);
|
flacenc->channels = GST_AUDIO_INFO_CHANNELS (info);
|
||||||
|
flacenc->width = GST_AUDIO_INFO_WIDTH (info);
|
||||||
if (!gst_structure_get_int (structure, "channels", &chans) ||
|
flacenc->depth = GST_AUDIO_INFO_DEPTH (info);
|
||||||
!gst_structure_get_int (structure, "width", &width) ||
|
flacenc->sample_rate = GST_AUDIO_INFO_RATE (info);
|
||||||
!gst_structure_get_int (structure, "depth", &depth) ||
|
|
||||||
!gst_structure_get_int (structure, "rate", &rate)) {
|
|
||||||
GST_DEBUG_OBJECT (flacenc, "incomplete caps: %" GST_PTR_FORMAT, caps);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
flacenc->channels = chans;
|
|
||||||
flacenc->width = width;
|
|
||||||
flacenc->depth = depth;
|
|
||||||
flacenc->sample_rate = rate;
|
|
||||||
|
|
||||||
caps = gst_caps_new_simple ("audio/x-flac",
|
caps = gst_caps_new_simple ("audio/x-flac",
|
||||||
"channels", G_TYPE_INT, flacenc->channels,
|
"channels", G_TYPE_INT, flacenc->channels,
|
||||||
"rate", G_TYPE_INT, flacenc->sample_rate, NULL);
|
"rate", G_TYPE_INT, flacenc->sample_rate, NULL);
|
||||||
|
|
||||||
if (!gst_pad_set_caps (flacenc->srcpad, caps))
|
if (!gst_pad_set_caps (GST_AUDIO_ENCODER_SRC_PAD (enc), caps))
|
||||||
goto setting_src_caps_failed;
|
goto setting_src_caps_failed;
|
||||||
|
|
||||||
gst_caps_unref (caps);
|
gst_caps_unref (caps);
|
||||||
|
|
||||||
total_samples = gst_flac_enc_query_peer_total_samples (flacenc, pad);
|
total_samples = gst_flac_enc_query_peer_total_samples (flacenc,
|
||||||
|
GST_AUDIO_ENCODER_SINK_PAD (enc));
|
||||||
|
|
||||||
FLAC__stream_encoder_set_bits_per_sample (flacenc->encoder, flacenc->depth);
|
FLAC__stream_encoder_set_bits_per_sample (flacenc->encoder, flacenc->depth);
|
||||||
FLAC__stream_encoder_set_sample_rate (flacenc->encoder, flacenc->sample_rate);
|
FLAC__stream_encoder_set_sample_rate (flacenc->encoder, flacenc->sample_rate);
|
||||||
@ -748,13 +791,17 @@ gst_flac_enc_sink_setcaps (GstPad * pad, GstCaps * caps)
|
|||||||
|
|
||||||
gst_flac_enc_set_metadata (flacenc, total_samples);
|
gst_flac_enc_set_metadata (flacenc, total_samples);
|
||||||
|
|
||||||
|
/* callbacks clear to go now;
|
||||||
|
* write callbacks receives headers during init */
|
||||||
|
flacenc->stopped = FALSE;
|
||||||
|
|
||||||
init_status = FLAC__stream_encoder_init_stream (flacenc->encoder,
|
init_status = FLAC__stream_encoder_init_stream (flacenc->encoder,
|
||||||
gst_flac_enc_write_callback, gst_flac_enc_seek_callback,
|
gst_flac_enc_write_callback, gst_flac_enc_seek_callback,
|
||||||
gst_flac_enc_tell_callback, NULL, flacenc);
|
gst_flac_enc_tell_callback, NULL, flacenc);
|
||||||
if (init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK)
|
if (init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK)
|
||||||
goto failed_to_initialize;
|
goto failed_to_initialize;
|
||||||
|
|
||||||
gst_object_unref (flacenc);
|
/* no special feedback to base class; should provide all available samples */
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
@ -832,16 +879,20 @@ gst_flac_enc_seek_callback (const FLAC__StreamEncoder * encoder,
|
|||||||
GstFlacEnc *flacenc;
|
GstFlacEnc *flacenc;
|
||||||
GstEvent *event;
|
GstEvent *event;
|
||||||
GstPad *peerpad;
|
GstPad *peerpad;
|
||||||
|
GstSegment seg;
|
||||||
|
|
||||||
flacenc = GST_FLAC_ENC (client_data);
|
flacenc = GST_FLAC_ENC (client_data);
|
||||||
|
|
||||||
if (flacenc->stopped)
|
if (flacenc->stopped)
|
||||||
return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
|
return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
|
||||||
|
|
||||||
event = gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_BYTES,
|
gst_segment_init (&seg, GST_FORMAT_BYTES);
|
||||||
absolute_byte_offset, GST_BUFFER_OFFSET_NONE, 0);
|
seg.start = absolute_byte_offset;
|
||||||
|
seg.stop = GST_BUFFER_OFFSET_NONE;
|
||||||
|
seg.time = 0;
|
||||||
|
event = gst_event_new_segment (&seg);
|
||||||
|
|
||||||
if ((peerpad = gst_pad_get_peer (flacenc->srcpad))) {
|
if ((peerpad = gst_pad_get_peer (GST_AUDIO_ENCODER_SRC_PAD (flacenc)))) {
|
||||||
gboolean ret = gst_pad_send_event (peerpad, event);
|
gboolean ret = gst_pad_send_event (peerpad, event);
|
||||||
|
|
||||||
gst_object_unref (peerpad);
|
gst_object_unref (peerpad);
|
||||||
@ -882,7 +933,7 @@ notgst_value_array_append_buffer (GValue * array_val, GstBuffer * buf)
|
|||||||
#define HDR_TYPE_STREAMINFO 0
|
#define HDR_TYPE_STREAMINFO 0
|
||||||
#define HDR_TYPE_VORBISCOMMENT 4
|
#define HDR_TYPE_VORBISCOMMENT 4
|
||||||
|
|
||||||
static void
|
static GstFlowReturn
|
||||||
gst_flac_enc_process_stream_headers (GstFlacEnc * enc)
|
gst_flac_enc_process_stream_headers (GstFlacEnc * enc)
|
||||||
{
|
{
|
||||||
GstBuffer *vorbiscomment = NULL;
|
GstBuffer *vorbiscomment = NULL;
|
||||||
@ -891,6 +942,7 @@ gst_flac_enc_process_stream_headers (GstFlacEnc * enc)
|
|||||||
GValue array = { 0, };
|
GValue array = { 0, };
|
||||||
GstCaps *caps;
|
GstCaps *caps;
|
||||||
GList *l;
|
GList *l;
|
||||||
|
GstFlowReturn ret = GST_FLOW_OK;
|
||||||
|
|
||||||
caps = gst_caps_new_simple ("audio/x-flac",
|
caps = gst_caps_new_simple ("audio/x-flac",
|
||||||
"channels", G_TYPE_INT, enc->channels,
|
"channels", G_TYPE_INT, enc->channels,
|
||||||
@ -976,28 +1028,27 @@ gst_flac_enc_process_stream_headers (GstFlacEnc * enc)
|
|||||||
|
|
||||||
push_headers:
|
push_headers:
|
||||||
|
|
||||||
gst_pad_set_caps (enc->srcpad, caps);
|
|
||||||
|
|
||||||
/* push header buffers; update caps, so when we push the first buffer the
|
/* push header buffers; update caps, so when we push the first buffer the
|
||||||
* negotiated caps will change to caps that include the streamheader field */
|
* negotiated caps will change to caps that include the streamheader field */
|
||||||
for (l = enc->headers; l != NULL; l = l->next) {
|
for (l = enc->headers; l != NULL; l = l->next) {
|
||||||
GstBuffer *buf;
|
GstBuffer *buf;
|
||||||
|
|
||||||
buf = GST_BUFFER (l->data);
|
buf = GST_BUFFER (l->data);
|
||||||
gst_buffer_set_caps (buf, caps);
|
|
||||||
GST_LOG_OBJECT (enc, "Pushing header buffer, size %u bytes",
|
GST_LOG_OBJECT (enc, "Pushing header buffer, size %u bytes",
|
||||||
gst_buffer_get_size (buf));
|
gst_buffer_get_size (buf));
|
||||||
#if 0
|
#if 0
|
||||||
GST_MEMDUMP_OBJECT (enc, "header buffer", GST_BUFFER_DATA (buf),
|
GST_MEMDUMP_OBJECT (enc, "header buffer", GST_BUFFER_DATA (buf),
|
||||||
GST_BUFFER_SIZE (buf));
|
GST_BUFFER_SIZE (buf));
|
||||||
#endif
|
#endif
|
||||||
(void) gst_pad_push (enc->srcpad, buf);
|
ret = gst_pad_push (GST_AUDIO_ENCODER_SRC_PAD (enc), buf);
|
||||||
l->data = NULL;
|
l->data = NULL;
|
||||||
}
|
}
|
||||||
g_list_free (enc->headers);
|
g_list_free (enc->headers);
|
||||||
enc->headers = NULL;
|
enc->headers = NULL;
|
||||||
|
|
||||||
gst_caps_unref (caps);
|
gst_caps_unref (caps);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FLAC__StreamEncoderWriteStatus
|
static FLAC__StreamEncoderWriteStatus
|
||||||
@ -1017,31 +1068,6 @@ gst_flac_enc_write_callback (const FLAC__StreamEncoder * encoder,
|
|||||||
outbuf = gst_buffer_new_and_alloc (bytes);
|
outbuf = gst_buffer_new_and_alloc (bytes);
|
||||||
gst_buffer_fill (outbuf, 0, buffer, bytes);
|
gst_buffer_fill (outbuf, 0, buffer, bytes);
|
||||||
|
|
||||||
if (samples > 0 && flacenc->samples_written != (guint64) - 1) {
|
|
||||||
guint64 granulepos;
|
|
||||||
|
|
||||||
GST_BUFFER_TIMESTAMP (outbuf) = flacenc->start_ts +
|
|
||||||
GST_FRAMES_TO_CLOCK_TIME (flacenc->samples_written,
|
|
||||||
flacenc->sample_rate);
|
|
||||||
GST_BUFFER_DURATION (outbuf) =
|
|
||||||
GST_FRAMES_TO_CLOCK_TIME (samples, flacenc->sample_rate);
|
|
||||||
/* offset_end = granulepos for ogg muxer */
|
|
||||||
granulepos =
|
|
||||||
flacenc->granulepos_offset + flacenc->samples_written + samples;
|
|
||||||
GST_BUFFER_OFFSET_END (outbuf) = granulepos;
|
|
||||||
/* offset = timestamp corresponding to granulepos for ogg muxer
|
|
||||||
* (see vorbisenc for a much more elaborate version of this) */
|
|
||||||
GST_BUFFER_OFFSET (outbuf) =
|
|
||||||
GST_FRAMES_TO_CLOCK_TIME (granulepos, flacenc->sample_rate);
|
|
||||||
} else {
|
|
||||||
GST_BUFFER_TIMESTAMP (outbuf) = GST_CLOCK_TIME_NONE;
|
|
||||||
GST_BUFFER_DURATION (outbuf) = GST_CLOCK_TIME_NONE;
|
|
||||||
GST_BUFFER_OFFSET (outbuf) =
|
|
||||||
flacenc->samples_written * flacenc->width * flacenc->channels;
|
|
||||||
GST_BUFFER_OFFSET_END (outbuf) = 0;
|
|
||||||
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_IN_CAPS);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* we assume libflac passes us stuff neatly framed */
|
/* we assume libflac passes us stuff neatly framed */
|
||||||
if (!flacenc->got_headers) {
|
if (!flacenc->got_headers) {
|
||||||
if (samples == 0) {
|
if (samples == 0) {
|
||||||
@ -1052,34 +1078,34 @@ gst_flac_enc_write_callback (const FLAC__StreamEncoder * encoder,
|
|||||||
goto out;
|
goto out;
|
||||||
} else {
|
} else {
|
||||||
GST_INFO_OBJECT (flacenc, "Non-header packet, we have all headers now");
|
GST_INFO_OBJECT (flacenc, "Non-header packet, we have all headers now");
|
||||||
gst_flac_enc_process_stream_headers (flacenc);
|
ret = gst_flac_enc_process_stream_headers (flacenc);
|
||||||
flacenc->got_headers = TRUE;
|
flacenc->got_headers = TRUE;
|
||||||
}
|
}
|
||||||
} else if (flacenc->got_headers && samples == 0) {
|
} else if (flacenc->got_headers && samples == 0) {
|
||||||
|
/* header fixup, push downstream directly */
|
||||||
GST_DEBUG_OBJECT (flacenc, "Fixing up headers at pos=%" G_GUINT64_FORMAT
|
GST_DEBUG_OBJECT (flacenc, "Fixing up headers at pos=%" G_GUINT64_FORMAT
|
||||||
", size=%u", flacenc->offset, (guint) bytes);
|
", size=%u", flacenc->offset, (guint) bytes);
|
||||||
#if 0
|
#if 0
|
||||||
GST_MEMDUMP_OBJECT (flacenc, "Presumed header fragment",
|
GST_MEMDUMP_OBJECT (flacenc, "Presumed header fragment",
|
||||||
GST_BUFFER_DATA (outbuf), GST_BUFFER_SIZE (outbuf));
|
GST_BUFFER_DATA (outbuf), GST_BUFFER_SIZE (outbuf));
|
||||||
#endif
|
#endif
|
||||||
|
ret = gst_pad_push (GST_AUDIO_ENCODER_SRC_PAD (flacenc), outbuf);
|
||||||
} else {
|
} else {
|
||||||
|
/* regular frame data, pass to base class */
|
||||||
GST_LOG ("Pushing buffer: ts=%" GST_TIME_FORMAT ", samples=%u, size=%u, "
|
GST_LOG ("Pushing buffer: ts=%" GST_TIME_FORMAT ", samples=%u, size=%u, "
|
||||||
"pos=%" G_GUINT64_FORMAT, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf)),
|
"pos=%" G_GUINT64_FORMAT, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf)),
|
||||||
samples, (guint) bytes, flacenc->offset);
|
samples, (guint) bytes, flacenc->offset);
|
||||||
|
ret = gst_audio_encoder_finish_frame (GST_AUDIO_ENCODER (flacenc),
|
||||||
|
outbuf, samples);
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_buffer_set_caps (outbuf, GST_PAD_CAPS (flacenc->srcpad));
|
|
||||||
ret = gst_pad_push (flacenc->srcpad, outbuf);
|
|
||||||
|
|
||||||
if (ret != GST_FLOW_OK)
|
if (ret != GST_FLOW_OK)
|
||||||
GST_DEBUG_OBJECT (flacenc, "flow: %s", gst_flow_get_name (ret));
|
GST_DEBUG_OBJECT (flacenc, "flow: %s", gst_flow_get_name (ret));
|
||||||
|
|
||||||
flacenc->last_flow = ret;
|
flacenc->last_flow = ret;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
|
||||||
flacenc->offset += bytes;
|
flacenc->offset += bytes;
|
||||||
flacenc->samples_written += samples;
|
|
||||||
|
|
||||||
if (ret != GST_FLOW_OK)
|
if (ret != GST_FLOW_OK)
|
||||||
return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
|
return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
|
||||||
@ -1099,24 +1125,25 @@ gst_flac_enc_tell_callback (const FLAC__StreamEncoder * encoder,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_flac_enc_sink_event (GstPad * pad, GstEvent * event)
|
gst_flac_enc_sink_event (GstAudioEncoder * enc, GstEvent * event)
|
||||||
{
|
{
|
||||||
GstFlacEnc *flacenc;
|
GstFlacEnc *flacenc;
|
||||||
GstTagList *taglist;
|
GstTagList *taglist;
|
||||||
gboolean ret = TRUE;
|
gboolean ret = FALSE;
|
||||||
|
|
||||||
flacenc = GST_FLAC_ENC (gst_pad_get_parent (pad));
|
flacenc = GST_FLAC_ENC (enc);
|
||||||
|
|
||||||
GST_DEBUG ("Received %s event on sinkpad", GST_EVENT_TYPE_NAME (event));
|
GST_DEBUG ("Received %s event on sinkpad", GST_EVENT_TYPE_NAME (event));
|
||||||
|
|
||||||
switch (GST_EVENT_TYPE (event)) {
|
switch (GST_EVENT_TYPE (event)) {
|
||||||
case GST_EVENT_NEWSEGMENT:{
|
case GST_EVENT_SEGMENT:{
|
||||||
GstFormat format;
|
GstSegment seg;
|
||||||
gint64 start, stream_time;
|
gint64 start, stream_time;
|
||||||
|
|
||||||
if (flacenc->offset == 0) {
|
if (flacenc->offset == 0) {
|
||||||
gst_event_parse_new_segment (event, NULL, NULL, &format, &start, NULL,
|
gst_event_copy_segment (event, &seg);
|
||||||
&stream_time);
|
start = seg.start;
|
||||||
|
stream_time = seg.time;
|
||||||
} else {
|
} else {
|
||||||
start = -1;
|
start = -1;
|
||||||
stream_time = -1;
|
stream_time = -1;
|
||||||
@ -1128,23 +1155,24 @@ gst_flac_enc_sink_event (GstPad * pad, GstEvent * event)
|
|||||||
else
|
else
|
||||||
GST_DEBUG ("Not handling newsegment event with non-zero start");
|
GST_DEBUG ("Not handling newsegment event with non-zero start");
|
||||||
} else {
|
} else {
|
||||||
GstEvent *e = gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_BYTES,
|
GstEvent *e;
|
||||||
0, -1, 0);
|
|
||||||
|
|
||||||
ret = gst_pad_push_event (flacenc->srcpad, e);
|
gst_segment_init (&seg, GST_FORMAT_BYTES);
|
||||||
|
e = gst_event_new_segment (&seg);
|
||||||
|
ret = gst_pad_push_event (GST_AUDIO_ENCODER_SRC_PAD (enc), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stream_time > 0) {
|
if (stream_time > 0) {
|
||||||
GST_DEBUG ("Not handling non-zero stream time");
|
GST_DEBUG ("Not handling non-zero stream time");
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_event_unref (event);
|
|
||||||
/* don't push it downstream, we'll generate our own via seek to 0 */
|
/* don't push it downstream, we'll generate our own via seek to 0 */
|
||||||
|
gst_event_unref (event);
|
||||||
|
ret = TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GST_EVENT_EOS:
|
case GST_EVENT_EOS:
|
||||||
FLAC__stream_encoder_finish (flacenc->encoder);
|
flacenc->eos = TRUE;
|
||||||
ret = gst_pad_event_default (pad, event);
|
|
||||||
break;
|
break;
|
||||||
case GST_EVENT_TAG:
|
case GST_EVENT_TAG:
|
||||||
if (flacenc->tags) {
|
if (flacenc->tags) {
|
||||||
@ -1154,42 +1182,16 @@ gst_flac_enc_sink_event (GstPad * pad, GstEvent * event)
|
|||||||
} else {
|
} else {
|
||||||
g_assert_not_reached ();
|
g_assert_not_reached ();
|
||||||
}
|
}
|
||||||
ret = gst_pad_event_default (pad, event);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ret = gst_pad_event_default (pad, event);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_object_unref (flacenc);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
|
||||||
gst_flac_enc_check_discont (GstFlacEnc * flacenc, GstClockTime expected,
|
|
||||||
GstClockTime timestamp)
|
|
||||||
{
|
|
||||||
guint allowed_diff = GST_SECOND / flacenc->sample_rate / 2;
|
|
||||||
|
|
||||||
if ((timestamp + allowed_diff < expected)
|
|
||||||
|| (timestamp > expected + allowed_diff)) {
|
|
||||||
GST_ELEMENT_WARNING (flacenc, STREAM, FORMAT, (NULL),
|
|
||||||
("Stream discontinuity detected (wanted %" GST_TIME_FORMAT " got %"
|
|
||||||
GST_TIME_FORMAT "). The output will have wrong timestamps,"
|
|
||||||
" consider using audiorate to handle discontinuities",
|
|
||||||
GST_TIME_ARGS (expected), GST_TIME_ARGS (timestamp)));
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* TODO: Do something to handle discontinuities in the stream. The FLAC encoder
|
|
||||||
* unfortunately doesn't have any way to flush it's internal buffers */
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
gst_flac_enc_chain (GstPad * pad, GstBuffer * buffer)
|
gst_flac_enc_handle_frame (GstAudioEncoder * enc, GstBuffer * buffer)
|
||||||
{
|
{
|
||||||
GstFlacEnc *flacenc;
|
GstFlacEnc *flacenc;
|
||||||
FLAC__int32 *data;
|
FLAC__int32 *data;
|
||||||
@ -1199,42 +1201,26 @@ gst_flac_enc_chain (GstPad * pad, GstBuffer * buffer)
|
|||||||
FLAC__bool res;
|
FLAC__bool res;
|
||||||
gpointer bdata;
|
gpointer bdata;
|
||||||
|
|
||||||
flacenc = GST_FLAC_ENC (GST_PAD_PARENT (pad));
|
flacenc = GST_FLAC_ENC (enc);
|
||||||
|
|
||||||
/* make sure setcaps has been called and the encoder is set up */
|
/* base class ensures configuration */
|
||||||
if (G_UNLIKELY (flacenc->depth == 0))
|
g_return_val_if_fail (flacenc->depth != 0, GST_FLOW_NOT_NEGOTIATED);
|
||||||
return GST_FLOW_NOT_NEGOTIATED;
|
|
||||||
|
|
||||||
width = flacenc->width;
|
width = flacenc->width;
|
||||||
|
|
||||||
/* Save the timestamp of the first buffer. This will be later
|
if (G_UNLIKELY (!buffer)) {
|
||||||
* used as offset for all following buffers */
|
if (flacenc->eos) {
|
||||||
if (flacenc->start_ts == GST_CLOCK_TIME_NONE) {
|
FLAC__stream_encoder_finish (flacenc->encoder);
|
||||||
if (GST_BUFFER_TIMESTAMP_IS_VALID (buffer)) {
|
|
||||||
flacenc->start_ts = GST_BUFFER_TIMESTAMP (buffer);
|
|
||||||
flacenc->granulepos_offset = gst_util_uint64_scale
|
|
||||||
(GST_BUFFER_TIMESTAMP (buffer), flacenc->sample_rate, GST_SECOND);
|
|
||||||
} else {
|
} else {
|
||||||
flacenc->start_ts = 0;
|
/* can't handle intermittent draining/resyncing */
|
||||||
flacenc->granulepos_offset = 0;
|
GST_ELEMENT_WARNING (flacenc, STREAM, FORMAT, (NULL),
|
||||||
|
("Stream discontinuity detected. "
|
||||||
|
"The output may have wrong timestamps, "
|
||||||
|
"consider using audiorate to handle discontinuities"));
|
||||||
}
|
}
|
||||||
|
return flacenc->last_flow;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if we have a continous stream, if not drop some samples or the buffer or
|
|
||||||
* insert some silence samples */
|
|
||||||
if (flacenc->next_ts != GST_CLOCK_TIME_NONE
|
|
||||||
&& GST_BUFFER_TIMESTAMP_IS_VALID (buffer)) {
|
|
||||||
gst_flac_enc_check_discont (flacenc, flacenc->next_ts,
|
|
||||||
GST_BUFFER_TIMESTAMP (buffer));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (GST_BUFFER_TIMESTAMP_IS_VALID (buffer)
|
|
||||||
&& GST_BUFFER_DURATION_IS_VALID (buffer))
|
|
||||||
flacenc->next_ts =
|
|
||||||
GST_BUFFER_TIMESTAMP (buffer) + GST_BUFFER_DURATION (buffer);
|
|
||||||
else
|
|
||||||
flacenc->next_ts = GST_CLOCK_TIME_NONE;
|
|
||||||
|
|
||||||
bdata = gst_buffer_map (buffer, &bsize, NULL, GST_MAP_READ);
|
bdata = gst_buffer_map (buffer, &bsize, NULL, GST_MAP_READ);
|
||||||
samples = bsize / (width >> 3);
|
samples = bsize / (width >> 3);
|
||||||
|
|
||||||
@ -1259,7 +1245,6 @@ gst_flac_enc_chain (GstPad * pad, GstBuffer * buffer)
|
|||||||
g_assert_not_reached ();
|
g_assert_not_reached ();
|
||||||
}
|
}
|
||||||
gst_buffer_unmap (buffer, bdata, bsize);
|
gst_buffer_unmap (buffer, bdata, bsize);
|
||||||
gst_buffer_unref (buffer);
|
|
||||||
|
|
||||||
res = FLAC__stream_encoder_process_interleaved (flacenc->encoder,
|
res = FLAC__stream_encoder_process_interleaved (flacenc->encoder,
|
||||||
(const FLAC__int32 *) data, samples / flacenc->channels);
|
(const FLAC__int32 *) data, samples / flacenc->channels);
|
||||||
@ -1425,64 +1410,3 @@ gst_flac_enc_get_property (GObject * object, guint prop_id,
|
|||||||
|
|
||||||
GST_OBJECT_UNLOCK (this);
|
GST_OBJECT_UNLOCK (this);
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstStateChangeReturn
|
|
||||||
gst_flac_enc_change_state (GstElement * element, GstStateChange transition)
|
|
||||||
{
|
|
||||||
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
|
|
||||||
GstFlacEnc *flacenc = GST_FLAC_ENC (element);
|
|
||||||
|
|
||||||
switch (transition) {
|
|
||||||
case GST_STATE_CHANGE_NULL_TO_READY:
|
|
||||||
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
|
||||||
flacenc->stopped = FALSE;
|
|
||||||
flacenc->start_ts = GST_CLOCK_TIME_NONE;
|
|
||||||
flacenc->next_ts = GST_CLOCK_TIME_NONE;
|
|
||||||
flacenc->granulepos_offset = 0;
|
|
||||||
break;
|
|
||||||
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
||||||
|
|
||||||
switch (transition) {
|
|
||||||
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
|
|
||||||
break;
|
|
||||||
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
|
||||||
if (FLAC__stream_encoder_get_state (flacenc->encoder) !=
|
|
||||||
FLAC__STREAM_ENCODER_UNINITIALIZED) {
|
|
||||||
flacenc->stopped = TRUE;
|
|
||||||
FLAC__stream_encoder_finish (flacenc->encoder);
|
|
||||||
}
|
|
||||||
flacenc->offset = 0;
|
|
||||||
flacenc->samples_written = 0;
|
|
||||||
flacenc->channels = 0;
|
|
||||||
flacenc->depth = 0;
|
|
||||||
flacenc->sample_rate = 0;
|
|
||||||
if (flacenc->meta) {
|
|
||||||
FLAC__metadata_object_delete (flacenc->meta[0]);
|
|
||||||
|
|
||||||
if (flacenc->meta[1])
|
|
||||||
FLAC__metadata_object_delete (flacenc->meta[1]);
|
|
||||||
|
|
||||||
if (flacenc->meta[2])
|
|
||||||
FLAC__metadata_object_delete (flacenc->meta[2]);
|
|
||||||
|
|
||||||
g_free (flacenc->meta);
|
|
||||||
flacenc->meta = NULL;
|
|
||||||
}
|
|
||||||
g_list_foreach (flacenc->headers, (GFunc) gst_mini_object_unref, NULL);
|
|
||||||
g_list_free (flacenc->headers);
|
|
||||||
flacenc->headers = NULL;
|
|
||||||
flacenc->got_headers = FALSE;
|
|
||||||
flacenc->last_flow = GST_FLOW_OK;
|
|
||||||
break;
|
|
||||||
case GST_STATE_CHANGE_READY_TO_NULL:
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#define __GST_FLAC_ENC_H__
|
#define __GST_FLAC_ENC_H__
|
||||||
|
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
|
#include <gst/audio/gstaudioencoder.h>
|
||||||
|
|
||||||
#include <FLAC/all.h>
|
#include <FLAC/all.h>
|
||||||
|
|
||||||
@ -37,19 +38,15 @@ typedef struct _GstFlacEnc GstFlacEnc;
|
|||||||
typedef struct _GstFlacEncClass GstFlacEncClass;
|
typedef struct _GstFlacEncClass GstFlacEncClass;
|
||||||
|
|
||||||
struct _GstFlacEnc {
|
struct _GstFlacEnc {
|
||||||
GstElement element;
|
GstAudioEncoder element;
|
||||||
|
|
||||||
/* < private > */
|
/* < private > */
|
||||||
|
|
||||||
GstPad *sinkpad;
|
|
||||||
GstPad *srcpad;
|
|
||||||
|
|
||||||
GstFlowReturn last_flow; /* save flow from last push so we can pass the
|
GstFlowReturn last_flow; /* save flow from last push so we can pass the
|
||||||
* correct flow return upstream in case the push
|
* correct flow return upstream in case the push
|
||||||
* fails for some reason */
|
* fails for some reason */
|
||||||
|
|
||||||
guint64 offset;
|
guint64 offset;
|
||||||
guint64 samples_written;
|
|
||||||
gint channels;
|
gint channels;
|
||||||
gint width;
|
gint width;
|
||||||
gint depth;
|
gint depth;
|
||||||
@ -68,18 +65,14 @@ struct _GstFlacEnc {
|
|||||||
|
|
||||||
GstTagList * tags;
|
GstTagList * tags;
|
||||||
|
|
||||||
|
gboolean eos;
|
||||||
/* queue headers until we have them all so we can add streamheaders to caps */
|
/* queue headers until we have them all so we can add streamheaders to caps */
|
||||||
gboolean got_headers;
|
gboolean got_headers;
|
||||||
GList *headers;
|
GList *headers;
|
||||||
|
|
||||||
/* Timestamp and granulepos tracking */
|
|
||||||
GstClockTime start_ts;
|
|
||||||
GstClockTime next_ts;
|
|
||||||
guint64 granulepos_offset;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstFlacEncClass {
|
struct _GstFlacEncClass {
|
||||||
GstElementClass parent_class;
|
GstAudioEncoderClass parent_class;
|
||||||
};
|
};
|
||||||
|
|
||||||
GType gst_flac_enc_get_type(void);
|
GType gst_flac_enc_get_type(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user