2001-12-23 14:15:30 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2001-12-23 14:15:30 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2002-03-19 04:10:05 +00:00
|
|
|
/*#define DEBUG_ENABLED */
|
2001-12-23 14:15:30 +00:00
|
|
|
#include "gstflacdec.h"
|
2003-11-28 13:04:21 +00:00
|
|
|
#include <gst/gsttaginterface.h>
|
|
|
|
|
2003-12-14 19:09:23 +00:00
|
|
|
#include <gst/tag/tag.h>
|
2001-12-23 14:15:30 +00:00
|
|
|
|
2002-09-18 20:56:42 +00:00
|
|
|
#include "flac_compat.h"
|
2001-12-23 14:15:30 +00:00
|
|
|
|
2003-11-01 15:46:35 +00:00
|
|
|
static GstPadTemplate *src_template, *sink_template;
|
2001-12-23 14:15:30 +00:00
|
|
|
|
|
|
|
/* elementfactory information */
|
|
|
|
GstElementDetails flacdec_details = {
|
|
|
|
"FLAC decoder",
|
2003-11-16 22:02:22 +00:00
|
|
|
"Codec/Decoder/Audio",
|
2001-12-23 14:15:30 +00:00
|
|
|
"Decodes FLAC lossless audio streams",
|
|
|
|
"Wim Taymans <wim.taymans@chello.be>",
|
|
|
|
};
|
|
|
|
|
|
|
|
/* FlacDec signals and args */
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2001-12-23 14:15:30 +00:00
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2001-12-23 14:15:30 +00:00
|
|
|
ARG_0,
|
2003-11-01 15:46:35 +00:00
|
|
|
ARG_METADATA
|
2001-12-23 14:15:30 +00:00
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_flacdec_base_init (gpointer g_class);
|
|
|
|
static void gst_flacdec_class_init (FlacDecClass * klass);
|
|
|
|
static void gst_flacdec_init (FlacDec * flacdec);
|
2004-05-07 20:26:46 +00:00
|
|
|
static void gst_flacdec_dispose (GObject * object);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
|
|
|
static void gst_flacdec_loop (GstElement * element);
|
|
|
|
static GstElementStateReturn gst_flacdec_change_state (GstElement * element);
|
|
|
|
static const GstFormat *gst_flacdec_get_src_formats (GstPad * pad);
|
|
|
|
static gboolean gst_flacdec_convert_src (GstPad * pad, GstFormat src_format,
|
|
|
|
gint64 src_value, GstFormat * dest_format, gint64 * dest_value);
|
|
|
|
static const GstQueryType *gst_flacdec_get_src_query_types (GstPad * pad);
|
|
|
|
static gboolean gst_flacdec_src_query (GstPad * pad, GstQueryType type,
|
|
|
|
GstFormat * format, gint64 * value);
|
|
|
|
static const GstEventMask *gst_flacdec_get_src_event_masks (GstPad * pad);
|
|
|
|
static gboolean gst_flacdec_src_event (GstPad * pad, GstEvent * event);
|
2001-12-23 14:15:30 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static FLAC__SeekableStreamDecoderReadStatus
|
|
|
|
gst_flacdec_read (const FLAC__SeekableStreamDecoder * decoder,
|
|
|
|
FLAC__byte buffer[], unsigned *bytes, void *client_data);
|
|
|
|
static FLAC__SeekableStreamDecoderSeekStatus
|
|
|
|
gst_flacdec_seek (const FLAC__SeekableStreamDecoder * decoder,
|
|
|
|
FLAC__uint64 position, void *client_data);
|
|
|
|
static FLAC__SeekableStreamDecoderTellStatus
|
|
|
|
gst_flacdec_tell (const FLAC__SeekableStreamDecoder * decoder,
|
|
|
|
FLAC__uint64 * position, void *client_data);
|
|
|
|
static FLAC__SeekableStreamDecoderLengthStatus
|
|
|
|
gst_flacdec_length (const FLAC__SeekableStreamDecoder * decoder,
|
|
|
|
FLAC__uint64 * length, void *client_data);
|
|
|
|
static FLAC__bool gst_flacdec_eof (const FLAC__SeekableStreamDecoder * decoder,
|
|
|
|
void *client_data);
|
|
|
|
static FLAC__StreamDecoderWriteStatus
|
|
|
|
gst_flacdec_write (const FLAC__SeekableStreamDecoder * decoder,
|
|
|
|
const FLAC__Frame * frame,
|
|
|
|
const FLAC__int32 * const buffer[], void *client_data);
|
|
|
|
static void gst_flacdec_metadata_callback (const FLAC__SeekableStreamDecoder *
|
|
|
|
decoder, const FLAC__StreamMetadata * metadata, void *client_data);
|
|
|
|
static void gst_flacdec_error_callback (const FLAC__SeekableStreamDecoder *
|
|
|
|
decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
|
2001-12-23 14:15:30 +00:00
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2002-03-19 04:10:05 +00:00
|
|
|
/*static guint gst_flacdec_signals[LAST_SIGNAL] = { 0 }; */
|
2001-12-23 14:15:30 +00:00
|
|
|
|
|
|
|
GType
|
2004-03-14 22:34:33 +00:00
|
|
|
flacdec_get_type (void)
|
|
|
|
{
|
2001-12-23 14:15:30 +00:00
|
|
|
static GType flacdec_type = 0;
|
|
|
|
|
|
|
|
if (!flacdec_type) {
|
|
|
|
static const GTypeInfo flacdec_info = {
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (FlacDecClass),
|
2003-11-01 15:46:35 +00:00
|
|
|
gst_flacdec_base_init,
|
2001-12-23 14:15:30 +00:00
|
|
|
NULL,
|
2004-03-14 22:34:33 +00:00
|
|
|
(GClassInitFunc) gst_flacdec_class_init,
|
2001-12-23 14:15:30 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (FlacDec),
|
2001-12-23 14:15:30 +00:00
|
|
|
0,
|
2004-03-14 22:34:33 +00:00
|
|
|
(GInstanceInitFunc) gst_flacdec_init,
|
2001-12-23 14:15:30 +00:00
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
flacdec_type =
|
2004-03-15 19:32:27 +00:00
|
|
|
g_type_register_static (GST_TYPE_ELEMENT, "FlacDec", &flacdec_info, 0);
|
2001-12-23 14:15:30 +00:00
|
|
|
}
|
|
|
|
return flacdec_type;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstCaps *
|
2003-11-01 15:46:35 +00:00
|
|
|
flac_caps_factory (void)
|
|
|
|
{
|
2003-12-22 01:47:09 +00:00
|
|
|
return gst_caps_new_simple ("audio/x-flac", NULL);
|
2004-03-14 22:34:33 +00:00
|
|
|
/* "rate", GST_PROPS_INT_RANGE (11025, 48000),
|
|
|
|
* "channels", GST_PROPS_INT_RANGE (1, 2), */
|
2003-11-01 15:46:35 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstCaps *
|
2003-11-01 15:46:35 +00:00
|
|
|
raw_caps_factory (void)
|
|
|
|
{
|
2003-12-22 01:47:09 +00:00
|
|
|
return gst_caps_new_simple ("audio/x-raw-int",
|
2004-03-14 22:34:33 +00:00
|
|
|
"endianness", G_TYPE_INT, G_BYTE_ORDER,
|
|
|
|
"signed", G_TYPE_BOOLEAN, TRUE,
|
|
|
|
"width", G_TYPE_INT, 16,
|
|
|
|
"depth", G_TYPE_INT, 16,
|
|
|
|
"rate", GST_TYPE_INT_RANGE, 11025, 48000,
|
|
|
|
"channels", GST_TYPE_INT_RANGE, 1, 2, NULL);
|
2003-11-01 15:46:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_flacdec_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
GstCaps *raw_caps, *flac_caps;
|
|
|
|
|
|
|
|
raw_caps = raw_caps_factory ();
|
|
|
|
flac_caps = flac_caps_factory ();
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
sink_template = gst_pad_template_new ("sink", GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS, flac_caps);
|
2004-03-14 22:34:33 +00:00
|
|
|
src_template = gst_pad_template_new ("src", GST_PAD_SRC,
|
2003-12-22 01:47:09 +00:00
|
|
|
GST_PAD_ALWAYS, raw_caps);
|
2003-11-01 15:46:35 +00:00
|
|
|
gst_element_class_add_pad_template (element_class, sink_template);
|
|
|
|
gst_element_class_add_pad_template (element_class, src_template);
|
|
|
|
gst_element_class_set_details (element_class, &flacdec_details);
|
|
|
|
}
|
|
|
|
|
2001-12-23 14:15:30 +00:00
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_flacdec_class_init (FlacDecClass * klass)
|
2001-12-23 14:15:30 +00:00
|
|
|
{
|
|
|
|
GstElementClass *gstelement_class;
|
2004-01-31 10:25:05 +00:00
|
|
|
GObjectClass *gobject_class;
|
2001-12-23 14:15:30 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gstelement_class = (GstElementClass *) klass;
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
2001-12-23 14:15:30 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
2003-04-27 12:00:41 +00:00
|
|
|
|
2004-05-07 20:26:46 +00:00
|
|
|
gobject_class->dispose = gst_flacdec_dispose;
|
2004-07-03 04:21:39 +00:00
|
|
|
|
2002-06-07 20:09:05 +00:00
|
|
|
gstelement_class->change_state = gst_flacdec_change_state;
|
2001-12-23 14:15:30 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void
|
|
|
|
gst_flacdec_init (FlacDec * flacdec)
|
2001-12-23 14:15:30 +00:00
|
|
|
{
|
2003-11-01 15:46:35 +00:00
|
|
|
flacdec->sinkpad = gst_pad_new_from_template (sink_template, "sink");
|
2001-12-23 14:15:30 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (flacdec), flacdec->sinkpad);
|
2002-06-07 20:09:05 +00:00
|
|
|
gst_pad_set_convert_function (flacdec->sinkpad, NULL);
|
2001-12-23 14:15:30 +00:00
|
|
|
|
|
|
|
gst_element_set_loop_function (GST_ELEMENT (flacdec), gst_flacdec_loop);
|
2003-11-01 15:46:35 +00:00
|
|
|
flacdec->srcpad = gst_pad_new_from_template (src_template, "src");
|
2001-12-23 14:15:30 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (flacdec), flacdec->srcpad);
|
2002-07-25 18:12:46 +00:00
|
|
|
gst_pad_set_formats_function (flacdec->srcpad, gst_flacdec_get_src_formats);
|
2002-06-07 20:09:05 +00:00
|
|
|
gst_pad_set_convert_function (flacdec->srcpad, gst_flacdec_convert_src);
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_pad_set_query_type_function (flacdec->srcpad,
|
|
|
|
gst_flacdec_get_src_query_types);
|
2002-07-25 18:12:46 +00:00
|
|
|
gst_pad_set_query_function (flacdec->srcpad, gst_flacdec_src_query);
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_pad_set_event_mask_function (flacdec->srcpad,
|
|
|
|
gst_flacdec_get_src_event_masks);
|
2002-06-07 20:09:05 +00:00
|
|
|
gst_pad_set_event_function (flacdec->srcpad, gst_flacdec_src_event);
|
2004-01-02 07:09:23 +00:00
|
|
|
gst_pad_use_explicit_caps (flacdec->srcpad);
|
2002-06-07 20:09:05 +00:00
|
|
|
|
|
|
|
flacdec->decoder = FLAC__seekable_stream_decoder_new ();
|
|
|
|
flacdec->total_samples = 0;
|
|
|
|
flacdec->init = TRUE;
|
|
|
|
flacdec->eos = FALSE;
|
|
|
|
flacdec->seek_pending = FALSE;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
FLAC__seekable_stream_decoder_set_read_callback (flacdec->decoder,
|
|
|
|
gst_flacdec_read);
|
|
|
|
FLAC__seekable_stream_decoder_set_seek_callback (flacdec->decoder,
|
|
|
|
gst_flacdec_seek);
|
|
|
|
FLAC__seekable_stream_decoder_set_tell_callback (flacdec->decoder,
|
|
|
|
gst_flacdec_tell);
|
|
|
|
FLAC__seekable_stream_decoder_set_length_callback (flacdec->decoder,
|
|
|
|
gst_flacdec_length);
|
|
|
|
FLAC__seekable_stream_decoder_set_eof_callback (flacdec->decoder,
|
|
|
|
gst_flacdec_eof);
|
2002-09-18 20:56:42 +00:00
|
|
|
#if FLAC_VERSION >= 0x010003
|
2004-03-14 22:34:33 +00:00
|
|
|
FLAC__seekable_stream_decoder_set_write_callback (flacdec->decoder,
|
|
|
|
gst_flacdec_write);
|
2002-09-18 20:56:42 +00:00
|
|
|
#else
|
|
|
|
FLAC__seekable_stream_decoder_set_write_callback (flacdec->decoder,
|
2004-03-14 22:34:33 +00:00
|
|
|
(FLAC__StreamDecoderWriteStatus (*)
|
2004-03-15 19:32:27 +00:00
|
|
|
(const FLAC__SeekableStreamDecoder * decoder,
|
|
|
|
const FLAC__Frame * frame,
|
|
|
|
const FLAC__int32 * buffer[], void *client_data))
|
2004-03-14 22:34:33 +00:00
|
|
|
(gst_flacdec_write));
|
2002-09-18 20:56:42 +00:00
|
|
|
#endif
|
2004-03-14 22:34:33 +00:00
|
|
|
FLAC__seekable_stream_decoder_set_metadata_respond (flacdec->decoder,
|
|
|
|
FLAC__METADATA_TYPE_VORBIS_COMMENT);
|
|
|
|
FLAC__seekable_stream_decoder_set_metadata_callback (flacdec->decoder,
|
|
|
|
gst_flacdec_metadata_callback);
|
|
|
|
FLAC__seekable_stream_decoder_set_error_callback (flacdec->decoder,
|
|
|
|
gst_flacdec_error_callback);
|
2002-06-07 20:09:05 +00:00
|
|
|
FLAC__seekable_stream_decoder_set_client_data (flacdec->decoder, flacdec);
|
|
|
|
}
|
2001-12-23 14:15:30 +00:00
|
|
|
|
2004-05-07 20:26:46 +00:00
|
|
|
static void
|
|
|
|
gst_flacdec_dispose (GObject * object)
|
|
|
|
{
|
|
|
|
FlacDec *flacdec;
|
|
|
|
|
|
|
|
flacdec = GST_FLACDEC (object);
|
|
|
|
|
|
|
|
if (flacdec->decoder)
|
|
|
|
FLAC__seekable_stream_decoder_delete (flacdec->decoder);
|
|
|
|
flacdec->decoder = NULL;
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-27 12:00:41 +00:00
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_flacdec_update_metadata (FlacDec * flacdec,
|
|
|
|
const FLAC__StreamMetadata * metadata)
|
2003-04-27 12:00:41 +00:00
|
|
|
{
|
2003-11-28 13:04:21 +00:00
|
|
|
GstTagList *list;
|
2003-04-27 12:00:41 +00:00
|
|
|
guint32 number_of_comments, cursor, str_len;
|
|
|
|
gchar *p_value, *value, *name, *str_ptr;
|
2003-11-28 13:04:21 +00:00
|
|
|
|
|
|
|
list = gst_tag_list_new ();
|
|
|
|
if (list == NULL) {
|
|
|
|
return FALSE;
|
2003-04-27 12:00:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
number_of_comments = metadata->data.vorbis_comment.num_comments;
|
|
|
|
value = NULL;
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_DEBUG ("%d tag(s) found", number_of_comments);
|
|
|
|
for (cursor = 0; cursor < number_of_comments; cursor++) {
|
2003-04-27 12:00:41 +00:00
|
|
|
str_ptr = metadata->data.vorbis_comment.comments[cursor].entry;
|
2004-01-13 23:59:51 +00:00
|
|
|
str_len = metadata->data.vorbis_comment.comments[cursor].length;
|
2004-03-14 22:34:33 +00:00
|
|
|
p_value = g_strstr_len (str_ptr, str_len, "=");
|
|
|
|
if (p_value) {
|
2003-04-27 12:00:41 +00:00
|
|
|
name = g_strndup (str_ptr, p_value - str_ptr);
|
2003-11-28 13:04:21 +00:00
|
|
|
value = g_strndup (p_value + 1, str_ptr + str_len - p_value - 1);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("%s : %s", name, value);
|
2003-11-28 13:04:21 +00:00
|
|
|
gst_vorbis_tag_add (list, name, value);
|
2003-04-27 12:00:41 +00:00
|
|
|
g_free (name);
|
|
|
|
g_free (value);
|
|
|
|
}
|
|
|
|
}
|
2003-11-28 13:04:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
gst_element_found_tags (GST_ELEMENT (flacdec), list);
|
|
|
|
if (GST_PAD_IS_USABLE (flacdec->srcpad)) {
|
|
|
|
gst_pad_push (flacdec->srcpad, GST_DATA (gst_event_new_tag (list)));
|
|
|
|
}
|
2003-04-27 12:00:41 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void
|
|
|
|
gst_flacdec_metadata_callback (const FLAC__SeekableStreamDecoder * decoder,
|
|
|
|
const FLAC__StreamMetadata * metadata, void *client_data)
|
2002-06-07 20:09:05 +00:00
|
|
|
{
|
|
|
|
FlacDec *flacdec;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2002-06-07 20:09:05 +00:00
|
|
|
flacdec = GST_FLACDEC (client_data);
|
2001-12-23 14:15:30 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
switch (metadata->type) {
|
2003-04-27 12:00:41 +00:00
|
|
|
case FLAC__METADATA_TYPE_STREAMINFO:
|
2004-03-14 22:34:33 +00:00
|
|
|
flacdec->stream_samples = metadata->data.stream_info.total_samples;
|
|
|
|
break;
|
2003-04-27 12:00:41 +00:00
|
|
|
case FLAC__METADATA_TYPE_VORBIS_COMMENT:
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_flacdec_update_metadata (flacdec, metadata);
|
|
|
|
break;
|
2003-04-27 12:00:41 +00:00
|
|
|
default:
|
2004-03-14 22:34:33 +00:00
|
|
|
break;
|
2003-04-27 12:00:41 +00:00
|
|
|
}
|
2001-12-23 14:15:30 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void
|
|
|
|
gst_flacdec_error_callback (const FLAC__SeekableStreamDecoder * decoder,
|
|
|
|
FLAC__StreamDecoderErrorStatus status, void *client_data)
|
2001-12-23 14:15:30 +00:00
|
|
|
{
|
2002-06-07 20:09:05 +00:00
|
|
|
FlacDec *flacdec;
|
|
|
|
gchar *error;
|
|
|
|
|
|
|
|
flacdec = GST_FLACDEC (client_data);
|
|
|
|
|
|
|
|
switch (status) {
|
2002-07-08 19:31:49 +00:00
|
|
|
case FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC:
|
2002-06-07 20:09:05 +00:00
|
|
|
error = "lost sync";
|
|
|
|
break;
|
2002-07-08 19:31:49 +00:00
|
|
|
case FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER:
|
2002-06-07 20:09:05 +00:00
|
|
|
error = "bad header";
|
|
|
|
break;
|
2002-07-08 19:31:49 +00:00
|
|
|
case FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH:
|
2002-06-07 20:09:05 +00:00
|
|
|
error = "CRC mismatch";
|
|
|
|
break;
|
|
|
|
default:
|
2004-02-16 17:09:18 +00:00
|
|
|
error = "unknown error";
|
2002-06-07 20:09:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-02-02 17:23:33 +00:00
|
|
|
GST_ELEMENT_ERROR (flacdec, STREAM, DECODE, (NULL), (error));
|
2001-12-23 14:15:30 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static FLAC__SeekableStreamDecoderSeekStatus
|
|
|
|
gst_flacdec_seek (const FLAC__SeekableStreamDecoder * decoder,
|
|
|
|
FLAC__uint64 position, void *client_data)
|
2001-12-23 14:15:30 +00:00
|
|
|
{
|
2002-06-07 20:09:05 +00:00
|
|
|
FlacDec *flacdec;
|
|
|
|
|
|
|
|
flacdec = GST_FLACDEC (client_data);
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("seek %" G_GINT64_FORMAT, position);
|
2002-06-07 20:09:05 +00:00
|
|
|
if (!gst_bytestream_seek (flacdec->bs, position, GST_SEEK_METHOD_SET)) {
|
|
|
|
return FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
|
|
|
|
}
|
|
|
|
return FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK;
|
2001-12-23 14:15:30 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static FLAC__SeekableStreamDecoderTellStatus
|
|
|
|
gst_flacdec_tell (const FLAC__SeekableStreamDecoder * decoder,
|
|
|
|
FLAC__uint64 * position, void *client_data)
|
2001-12-23 14:15:30 +00:00
|
|
|
{
|
|
|
|
FlacDec *flacdec;
|
|
|
|
|
|
|
|
flacdec = GST_FLACDEC (client_data);
|
|
|
|
|
2002-06-07 20:09:05 +00:00
|
|
|
*position = gst_bytestream_tell (flacdec->bs);
|
|
|
|
if (*position == -1)
|
|
|
|
return FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;
|
2001-12-23 14:15:30 +00:00
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("tell %" G_GINT64_FORMAT, *position);
|
2002-06-07 20:09:05 +00:00
|
|
|
|
|
|
|
return FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static FLAC__SeekableStreamDecoderLengthStatus
|
|
|
|
gst_flacdec_length (const FLAC__SeekableStreamDecoder * decoder,
|
|
|
|
FLAC__uint64 * length, void *client_data)
|
2002-06-07 20:09:05 +00:00
|
|
|
{
|
|
|
|
FlacDec *flacdec;
|
|
|
|
|
|
|
|
flacdec = GST_FLACDEC (client_data);
|
|
|
|
|
|
|
|
*length = gst_bytestream_length (flacdec->bs);
|
|
|
|
if (*length == -1)
|
|
|
|
return FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("length %" G_GINT64_FORMAT, *length);
|
2002-06-07 20:09:05 +00:00
|
|
|
|
|
|
|
return FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static FLAC__bool
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_flacdec_eof (const FLAC__SeekableStreamDecoder * decoder, void *client_data)
|
2002-06-07 20:09:05 +00:00
|
|
|
{
|
|
|
|
FlacDec *flacdec;
|
|
|
|
|
|
|
|
flacdec = GST_FLACDEC (client_data);
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("eof %d", flacdec->eos);
|
2002-06-07 20:09:05 +00:00
|
|
|
|
|
|
|
return flacdec->eos;
|
|
|
|
}
|
|
|
|
|
|
|
|
static FLAC__SeekableStreamDecoderReadStatus
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_flacdec_read (const FLAC__SeekableStreamDecoder * decoder,
|
|
|
|
FLAC__byte buffer[], unsigned *bytes, void *client_data)
|
2002-06-07 20:09:05 +00:00
|
|
|
{
|
|
|
|
FlacDec *flacdec;
|
|
|
|
gint insize = 0;
|
|
|
|
guint8 *indata;
|
|
|
|
|
|
|
|
flacdec = GST_FLACDEC (client_data);
|
|
|
|
|
|
|
|
//g_print ("read %u\n", *bytes);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2002-06-07 20:09:05 +00:00
|
|
|
while (insize == 0) {
|
|
|
|
insize = gst_bytestream_peek_bytes (flacdec->bs, &indata, *bytes);
|
|
|
|
if (insize < *bytes) {
|
|
|
|
GstEvent *event;
|
|
|
|
guint32 avail;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2002-06-07 20:09:05 +00:00
|
|
|
gst_bytestream_get_status (flacdec->bs, &avail, &event);
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2004-03-15 19:32:27 +00:00
|
|
|
case GST_EVENT_EOS:
|
|
|
|
GST_DEBUG ("eos");
|
|
|
|
flacdec->eos = TRUE;
|
|
|
|
gst_event_unref (event);
|
|
|
|
if (avail == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_EVENT_DISCONTINUOUS:
|
|
|
|
GST_DEBUG ("discont");
|
|
|
|
|
|
|
|
/* we are not yet sending the discont, we'll do that in the next write operation */
|
|
|
|
flacdec->need_discont = TRUE;
|
|
|
|
gst_event_unref (event);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
gst_pad_event_default (flacdec->sinkpad, event);
|
|
|
|
break;
|
2002-06-07 20:09:05 +00:00
|
|
|
}
|
|
|
|
if (avail > 0)
|
2004-03-15 19:32:27 +00:00
|
|
|
insize = gst_bytestream_peek_bytes (flacdec->bs, &indata, avail);
|
2002-06-07 20:09:05 +00:00
|
|
|
else
|
2004-03-15 19:32:27 +00:00
|
|
|
insize = 0;
|
2002-06-07 20:09:05 +00:00
|
|
|
}
|
2001-12-23 14:15:30 +00:00
|
|
|
}
|
|
|
|
|
2002-06-07 20:09:05 +00:00
|
|
|
memcpy (buffer, indata, insize);
|
|
|
|
*bytes = insize;
|
|
|
|
gst_bytestream_flush_fast (flacdec->bs, insize);
|
2001-12-23 14:15:30 +00:00
|
|
|
|
2002-06-07 20:09:05 +00:00
|
|
|
return FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK;
|
2001-12-23 14:15:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static FLAC__StreamDecoderWriteStatus
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_flacdec_write (const FLAC__SeekableStreamDecoder * decoder,
|
|
|
|
const FLAC__Frame * frame,
|
|
|
|
const FLAC__int32 * const buffer[], void *client_data)
|
2001-12-23 14:15:30 +00:00
|
|
|
{
|
|
|
|
FlacDec *flacdec;
|
|
|
|
GstBuffer *outbuf;
|
|
|
|
guint depth = frame->header.bits_per_sample;
|
|
|
|
guint channels = frame->header.channels;
|
|
|
|
guint samples = frame->header.blocksize;
|
|
|
|
guint j, i;
|
|
|
|
|
|
|
|
flacdec = GST_FLACDEC (client_data);
|
|
|
|
|
2002-06-07 20:09:05 +00:00
|
|
|
if (flacdec->need_discont) {
|
|
|
|
gint64 time = 0, bytes = 0;
|
|
|
|
GstFormat format;
|
|
|
|
GstEvent *discont;
|
|
|
|
|
|
|
|
flacdec->need_discont = FALSE;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2004-07-03 04:27:18 +00:00
|
|
|
if (flacdec->seek_pending) {
|
|
|
|
flacdec->total_samples = flacdec->seek_value;
|
|
|
|
}
|
2002-06-07 20:09:05 +00:00
|
|
|
|
2004-07-03 04:27:18 +00:00
|
|
|
if (GST_PAD_IS_USABLE (flacdec->srcpad)) {
|
|
|
|
GST_DEBUG ("send discont");
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2004-07-03 04:27:18 +00:00
|
|
|
format = GST_FORMAT_TIME;
|
|
|
|
gst_pad_convert (flacdec->srcpad, GST_FORMAT_DEFAULT,
|
|
|
|
flacdec->total_samples, &format, &time);
|
|
|
|
format = GST_FORMAT_BYTES;
|
|
|
|
gst_pad_convert (flacdec->srcpad, GST_FORMAT_DEFAULT,
|
|
|
|
flacdec->total_samples, &format, &bytes);
|
|
|
|
discont = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME, time,
|
|
|
|
GST_FORMAT_BYTES, bytes,
|
|
|
|
GST_FORMAT_DEFAULT, flacdec->total_samples, NULL);
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2004-07-03 04:27:18 +00:00
|
|
|
gst_pad_push (flacdec->srcpad, GST_DATA (discont));
|
2003-06-28 14:21:47 +00:00
|
|
|
}
|
2002-06-07 20:09:05 +00:00
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2001-12-23 14:15:30 +00:00
|
|
|
if (!GST_PAD_CAPS (flacdec->srcpad)) {
|
2004-01-02 07:09:23 +00:00
|
|
|
gst_pad_set_explicit_caps (flacdec->srcpad,
|
2004-03-15 19:32:27 +00:00
|
|
|
gst_caps_new_simple ("audio/x-raw-int",
|
|
|
|
"endianness", G_TYPE_INT, G_BYTE_ORDER,
|
|
|
|
"signed", G_TYPE_BOOLEAN, TRUE,
|
|
|
|
"width", G_TYPE_INT, depth,
|
|
|
|
"depth", G_TYPE_INT, depth,
|
|
|
|
"rate", G_TYPE_INT, frame->header.sample_rate,
|
|
|
|
"channels", G_TYPE_INT, channels, NULL));
|
2002-06-07 20:09:05 +00:00
|
|
|
|
|
|
|
flacdec->depth = depth;
|
|
|
|
flacdec->channels = channels;
|
|
|
|
flacdec->frequency = frame->header.sample_rate;
|
2001-12-23 14:15:30 +00:00
|
|
|
}
|
|
|
|
|
2003-06-28 14:21:47 +00:00
|
|
|
if (GST_PAD_IS_USABLE (flacdec->srcpad)) {
|
|
|
|
outbuf = gst_buffer_new ();
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_BUFFER_SIZE (outbuf) = samples * channels * ((depth + 7) >> 3);
|
2003-06-28 14:21:47 +00:00
|
|
|
GST_BUFFER_DATA (outbuf) = g_malloc (GST_BUFFER_SIZE (outbuf));
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (outbuf) =
|
2004-03-15 19:32:27 +00:00
|
|
|
flacdec->total_samples * GST_SECOND / frame->header.sample_rate;
|
2004-07-03 04:21:39 +00:00
|
|
|
GST_BUFFER_DURATION (outbuf) =
|
|
|
|
samples * GST_SECOND / frame->header.sample_rate;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-06-28 14:21:47 +00:00
|
|
|
if (depth == 8) {
|
2004-03-14 22:34:33 +00:00
|
|
|
guint8 *outbuffer = (guint8 *) GST_BUFFER_DATA (outbuf);
|
|
|
|
|
|
|
|
for (i = 0; i < samples; i++) {
|
2004-03-15 19:32:27 +00:00
|
|
|
for (j = 0; j < channels; j++) {
|
|
|
|
*outbuffer++ = (guint8) buffer[j][i];
|
|
|
|
}
|
2001-12-23 14:15:30 +00:00
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
} else if (depth == 16) {
|
|
|
|
guint16 *outbuffer = (guint16 *) GST_BUFFER_DATA (outbuf);
|
|
|
|
|
|
|
|
for (i = 0; i < samples; i++) {
|
2004-03-15 19:32:27 +00:00
|
|
|
for (j = 0; j < channels; j++) {
|
|
|
|
*outbuffer++ = (guint16) buffer[j][i];
|
|
|
|
}
|
2001-12-23 14:15:30 +00:00
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
} else {
|
2003-06-28 14:21:47 +00:00
|
|
|
g_warning ("flacdec: invalid depth %d found\n", depth);
|
|
|
|
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
|
|
|
|
}
|
2003-10-08 16:08:18 +00:00
|
|
|
gst_pad_push (flacdec->srcpad, GST_DATA (outbuf));
|
2001-12-23 14:15:30 +00:00
|
|
|
}
|
2002-06-07 20:09:05 +00:00
|
|
|
flacdec->total_samples += samples;
|
|
|
|
|
2002-07-08 19:31:49 +00:00
|
|
|
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
|
2001-12-23 14:15:30 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void
|
|
|
|
gst_flacdec_loop (GstElement * element)
|
2001-12-23 14:15:30 +00:00
|
|
|
{
|
|
|
|
FlacDec *flacdec;
|
2002-06-07 20:09:05 +00:00
|
|
|
gboolean res;
|
2001-12-23 14:15:30 +00:00
|
|
|
|
|
|
|
flacdec = GST_FLACDEC (element);
|
2002-06-07 20:09:05 +00:00
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("flacdec: entering loop");
|
2004-03-14 22:34:33 +00:00
|
|
|
if (flacdec->init) {
|
2003-11-22 13:17:51 +00:00
|
|
|
FLAC__StreamDecoderState res;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
|
|
|
GST_DEBUG ("flacdec: initializing decoder");
|
2003-11-22 13:17:51 +00:00
|
|
|
res = FLAC__seekable_stream_decoder_init (flacdec->decoder);
|
|
|
|
if (res != FLAC__SEEKABLE_STREAM_DECODER_OK) {
|
2004-02-02 17:23:33 +00:00
|
|
|
GST_ELEMENT_ERROR (flacdec, LIBRARY, INIT, (NULL),
|
2004-03-15 19:32:27 +00:00
|
|
|
(FLAC__SeekableStreamDecoderStateString[res]));
|
2003-11-22 13:17:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
/* FLAC__seekable_stream_decoder_process_metadata (flacdec->decoder); */
|
2002-06-07 20:09:05 +00:00
|
|
|
flacdec->init = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flacdec->seek_pending) {
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_DEBUG ("perform seek to sample %" G_GINT64_FORMAT, flacdec->seek_value);
|
2002-06-07 20:09:05 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (FLAC__seekable_stream_decoder_seek_absolute (flacdec->decoder,
|
2004-03-15 19:32:27 +00:00
|
|
|
flacdec->seek_value)) {
|
2002-06-07 20:09:05 +00:00
|
|
|
flacdec->total_samples = flacdec->seek_value;
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("seek done");
|
2004-03-14 22:34:33 +00:00
|
|
|
} else {
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("seek failed");
|
2002-06-07 20:09:05 +00:00
|
|
|
}
|
|
|
|
flacdec->seek_pending = FALSE;
|
|
|
|
}
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("flacdec: processing single");
|
2002-09-29 20:51:19 +00:00
|
|
|
res = FLAC__seekable_stream_decoder_process_single (flacdec->decoder);
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("flacdec: checking for EOS");
|
2004-03-14 22:34:33 +00:00
|
|
|
if (FLAC__seekable_stream_decoder_get_state (flacdec->decoder) ==
|
|
|
|
FLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM) {
|
2002-06-07 20:09:05 +00:00
|
|
|
GstEvent *event;
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("flacdec: sending EOS event");
|
2004-03-14 22:34:33 +00:00
|
|
|
FLAC__seekable_stream_decoder_reset (flacdec->decoder);
|
2002-06-07 20:09:05 +00:00
|
|
|
|
2003-06-28 14:21:47 +00:00
|
|
|
if (GST_PAD_IS_USABLE (flacdec->srcpad)) {
|
|
|
|
event = gst_event_new (GST_EVENT_EOS);
|
2003-10-08 16:08:18 +00:00
|
|
|
gst_pad_push (flacdec->srcpad, GST_DATA (event));
|
2003-06-28 14:21:47 +00:00
|
|
|
}
|
2002-06-07 20:09:05 +00:00
|
|
|
gst_element_set_eos (element);
|
|
|
|
}
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("flacdec: _loop end");
|
2002-06-07 20:09:05 +00:00
|
|
|
}
|
|
|
|
|
2004-02-04 19:28:51 +00:00
|
|
|
|
|
|
|
static const GstFormat *
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_flacdec_get_src_formats (GstPad * pad)
|
|
|
|
{
|
2004-02-04 19:28:51 +00:00
|
|
|
static const GstFormat formats[] = {
|
|
|
|
GST_FORMAT_DEFAULT,
|
|
|
|
GST_FORMAT_BYTES,
|
|
|
|
GST_FORMAT_TIME,
|
|
|
|
0,
|
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2004-02-04 19:28:51 +00:00
|
|
|
return formats;
|
2004-03-14 22:34:33 +00:00
|
|
|
}
|
2002-07-25 18:12:46 +00:00
|
|
|
|
2002-06-07 20:09:05 +00:00
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_flacdec_convert_src (GstPad * pad, GstFormat src_format, gint64 src_value,
|
|
|
|
GstFormat * dest_format, gint64 * dest_value)
|
2002-06-07 20:09:05 +00:00
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
FlacDec *flacdec = GST_FLACDEC (gst_pad_get_parent (pad));
|
|
|
|
guint scale = 1;
|
|
|
|
gint bytes_per_sample;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
bytes_per_sample = flacdec->channels * ((flacdec->depth + 7) >> 3);
|
2002-06-07 20:09:05 +00:00
|
|
|
|
|
|
|
switch (src_format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
switch (*dest_format) {
|
2004-03-15 19:32:27 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
|
|
|
if (bytes_per_sample == 0)
|
|
|
|
return FALSE;
|
|
|
|
*dest_value = src_value / bytes_per_sample;
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
{
|
|
|
|
gint byterate = bytes_per_sample * flacdec->frequency;
|
|
|
|
|
|
|
|
if (byterate == 0)
|
|
|
|
return FALSE;
|
|
|
|
*dest_value = src_value * GST_SECOND / byterate;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
2002-06-07 20:09:05 +00:00
|
|
|
}
|
|
|
|
break;
|
2003-05-24 10:41:21 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
2002-06-07 20:09:05 +00:00
|
|
|
switch (*dest_format) {
|
2004-03-15 19:32:27 +00:00
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
*dest_value = src_value * bytes_per_sample;
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
if (flacdec->frequency == 0)
|
|
|
|
return FALSE;
|
|
|
|
*dest_value = src_value * GST_SECOND / flacdec->frequency;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
2002-06-07 20:09:05 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
switch (*dest_format) {
|
2004-03-15 19:32:27 +00:00
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
scale = bytes_per_sample;
|
|
|
|
case GST_FORMAT_DEFAULT:
|
|
|
|
*dest_value = src_value * scale * flacdec->frequency / GST_SECOND;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
2002-06-07 20:09:05 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2004-02-04 19:28:51 +00:00
|
|
|
static const GstQueryType *
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_flacdec_get_src_query_types (GstPad * pad)
|
|
|
|
{
|
2004-02-04 19:28:51 +00:00
|
|
|
static const GstQueryType types[] = {
|
|
|
|
GST_QUERY_TOTAL,
|
|
|
|
GST_QUERY_POSITION,
|
|
|
|
0,
|
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2004-02-04 19:28:51 +00:00
|
|
|
return types;
|
2004-03-14 22:34:33 +00:00
|
|
|
}
|
2002-07-25 18:12:46 +00:00
|
|
|
|
2002-06-07 20:09:05 +00:00
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_flacdec_src_query (GstPad * pad, GstQueryType type,
|
|
|
|
GstFormat * format, gint64 * value)
|
2002-06-07 20:09:05 +00:00
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
FlacDec *flacdec = GST_FLACDEC (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
switch (type) {
|
2002-12-30 17:53:18 +00:00
|
|
|
case GST_QUERY_TOTAL:
|
2002-06-07 20:09:05 +00:00
|
|
|
{
|
|
|
|
guint64 samples;
|
|
|
|
|
|
|
|
if (flacdec->stream_samples == 0)
|
2004-03-15 19:32:27 +00:00
|
|
|
samples = flacdec->total_samples;
|
2002-06-07 20:09:05 +00:00
|
|
|
else
|
2004-03-15 19:32:27 +00:00
|
|
|
samples = flacdec->stream_samples;
|
2002-06-07 20:09:05 +00:00
|
|
|
|
ext/flac/gstflacdec.c: Only return true if we actually filled something in. Prevents player applications from showing...
Original commit message from CVS:
* ext/flac/gstflacdec.c: (gst_flacdec_src_query):
Only return true if we actually filled something in. Prevents
player applications from showing a random length for flac files.
* gst-libs/gst/riff/riff-read.c: (gst_riff_read_class_init),
(gst_riff_read_use_event), (gst_riff_read_handle_event),
(gst_riff_read_seek), (gst_riff_read_skip), (gst_riff_read_strh),
(gst_riff_read_strf_vids_with_data),
(gst_riff_read_strf_auds_with_data), (gst_riff_read_strf_iavs):
OK, ok, so I implemented event handling. Apparently it's normal
that we receive random events at random points without asking
for it.
* gst/avi/gstavidemux.c: (gst_avi_demux_reset),
(gst_avi_demux_src_convert), (gst_avi_demux_handle_src_query),
(gst_avi_demux_handle_src_event), (gst_avi_demux_stream_index),
(gst_avi_demux_sync), (gst_avi_demux_stream_scan),
(gst_avi_demux_massage_index), (gst_avi_demux_stream_header),
(gst_avi_demux_handle_seek), (gst_avi_demux_process_next_entry),
(gst_avi_demux_stream_data), (gst_avi_demux_loop):
* gst/avi/gstavidemux.h:
Implement non-lineair chunk handling and subchunk processing.
The first solves playback of AVI files where the audio and video
data of individual buffers that we read are not synchronized.
This should not happen according to the wonderful AVI specs, but
of course it does happen in reality. It is also a prerequisite for
the second. Subchunk processing allows us to cut chunks in small
pieces and process each of these pieces separately. This is
required because I've seen several AVI files with incredibly large
audio chunks, even some files with only one audio chunk for the
whole file. This allows for proper playback including seeking.
This patch is supposed to fix all AVI A/V sync issues.
* gst/flx/gstflxdec.c: (gst_flxdec_class_init),
(flx_decode_chunks), (flx_decode_color), (gst_flxdec_loop):
Work.
* gst/modplug/gstmodplug.cc:
Proper return value setting for the query() function.
* gst/playback/gstplaybasebin.c: (setup_source):
Being in non-playing state (after, e.g., EOS) is not necessarily
a bad thing. Allow for that. This fixes playback of short files.
They don't actually playback fully now, because the clock already
runs. This means that small files (<500kB) with a small length
(<2sec) will still not or barely play. Other files, such as mod
or flx, will work correctly, however.
2004-09-29 09:45:40 +00:00
|
|
|
res = gst_pad_convert (flacdec->srcpad,
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_FORMAT_DEFAULT, samples, format, value);
|
2002-06-07 20:09:05 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-12-30 17:53:18 +00:00
|
|
|
case GST_QUERY_POSITION:
|
ext/flac/gstflacdec.c: Only return true if we actually filled something in. Prevents player applications from showing...
Original commit message from CVS:
* ext/flac/gstflacdec.c: (gst_flacdec_src_query):
Only return true if we actually filled something in. Prevents
player applications from showing a random length for flac files.
* gst-libs/gst/riff/riff-read.c: (gst_riff_read_class_init),
(gst_riff_read_use_event), (gst_riff_read_handle_event),
(gst_riff_read_seek), (gst_riff_read_skip), (gst_riff_read_strh),
(gst_riff_read_strf_vids_with_data),
(gst_riff_read_strf_auds_with_data), (gst_riff_read_strf_iavs):
OK, ok, so I implemented event handling. Apparently it's normal
that we receive random events at random points without asking
for it.
* gst/avi/gstavidemux.c: (gst_avi_demux_reset),
(gst_avi_demux_src_convert), (gst_avi_demux_handle_src_query),
(gst_avi_demux_handle_src_event), (gst_avi_demux_stream_index),
(gst_avi_demux_sync), (gst_avi_demux_stream_scan),
(gst_avi_demux_massage_index), (gst_avi_demux_stream_header),
(gst_avi_demux_handle_seek), (gst_avi_demux_process_next_entry),
(gst_avi_demux_stream_data), (gst_avi_demux_loop):
* gst/avi/gstavidemux.h:
Implement non-lineair chunk handling and subchunk processing.
The first solves playback of AVI files where the audio and video
data of individual buffers that we read are not synchronized.
This should not happen according to the wonderful AVI specs, but
of course it does happen in reality. It is also a prerequisite for
the second. Subchunk processing allows us to cut chunks in small
pieces and process each of these pieces separately. This is
required because I've seen several AVI files with incredibly large
audio chunks, even some files with only one audio chunk for the
whole file. This allows for proper playback including seeking.
This patch is supposed to fix all AVI A/V sync issues.
* gst/flx/gstflxdec.c: (gst_flxdec_class_init),
(flx_decode_chunks), (flx_decode_color), (gst_flxdec_loop):
Work.
* gst/modplug/gstmodplug.cc:
Proper return value setting for the query() function.
* gst/playback/gstplaybasebin.c: (setup_source):
Being in non-playing state (after, e.g., EOS) is not necessarily
a bad thing. Allow for that. This fixes playback of short files.
They don't actually playback fully now, because the clock already
runs. This means that small files (<500kB) with a small length
(<2sec) will still not or barely play. Other files, such as mod
or flx, will work correctly, however.
2004-09-29 09:45:40 +00:00
|
|
|
res = gst_pad_convert (flacdec->srcpad,
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_FORMAT_DEFAULT, flacdec->total_samples, format, value);
|
2002-06-07 20:09:05 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2004-02-04 19:28:51 +00:00
|
|
|
static const GstEventMask *
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_flacdec_get_src_event_masks (GstPad * pad)
|
2004-02-04 19:28:51 +00:00
|
|
|
{
|
|
|
|
static const GstEventMask masks[] = {
|
2004-03-14 22:34:33 +00:00
|
|
|
{GST_EVENT_SEEK, GST_SEEK_FLAG_ACCURATE},
|
|
|
|
{0, 0},
|
2004-02-04 19:28:51 +00:00
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2004-02-04 19:28:51 +00:00
|
|
|
return masks;
|
|
|
|
}
|
2002-07-25 18:12:46 +00:00
|
|
|
|
2002-06-07 20:09:05 +00:00
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_flacdec_src_event (GstPad * pad, GstEvent * event)
|
|
|
|
{
|
2002-06-07 20:09:05 +00:00
|
|
|
gboolean res = TRUE;
|
|
|
|
FlacDec *flacdec = GST_FLACDEC (gst_pad_get_parent (pad));
|
|
|
|
GstFormat format;
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_SEEK:
|
2003-05-24 10:41:21 +00:00
|
|
|
format = GST_FORMAT_DEFAULT;
|
2002-06-07 20:09:05 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (gst_pad_convert (flacdec->srcpad,
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_EVENT_SEEK_FORMAT (event),
|
|
|
|
GST_EVENT_SEEK_OFFSET (event), &format, &flacdec->seek_value))
|
|
|
|
flacdec->seek_pending = TRUE;
|
2002-06-07 20:09:05 +00:00
|
|
|
else
|
2004-03-15 19:32:27 +00:00
|
|
|
res = FALSE;
|
2002-06-07 20:09:05 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2002-07-08 19:31:49 +00:00
|
|
|
gst_event_unref (event);
|
2002-06-07 20:09:05 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstElementStateReturn
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_flacdec_change_state (GstElement * element)
|
2002-06-07 20:09:05 +00:00
|
|
|
{
|
|
|
|
FlacDec *flacdec = GST_FLACDEC (element);
|
|
|
|
|
|
|
|
switch (GST_STATE_TRANSITION (element)) {
|
|
|
|
case GST_STATE_NULL_TO_READY:
|
|
|
|
case GST_STATE_READY_TO_PAUSED:
|
|
|
|
flacdec->bs = gst_bytestream_new (flacdec->sinkpad);
|
|
|
|
flacdec->seek_pending = FALSE;
|
|
|
|
flacdec->total_samples = 0;
|
|
|
|
flacdec->eos = FALSE;
|
2003-11-22 13:17:51 +00:00
|
|
|
if (flacdec->init == FALSE) {
|
2004-03-15 19:32:27 +00:00
|
|
|
FLAC__seekable_stream_decoder_reset (flacdec->decoder);
|
2003-11-22 13:17:51 +00:00
|
|
|
}
|
2002-06-07 20:09:05 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_PLAYING:
|
|
|
|
flacdec->eos = FALSE;
|
|
|
|
case GST_STATE_PLAYING_TO_PAUSED:
|
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
|
|
|
gst_bytestream_destroy (flacdec->bs);
|
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_NULL:
|
|
|
|
default:
|
|
|
|
break;
|
2001-12-23 14:15:30 +00:00
|
|
|
}
|
|
|
|
|
2002-06-07 20:09:05 +00:00
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
|
|
|
|
|
|
|
return GST_STATE_SUCCESS;
|
2001-12-23 14:15:30 +00:00
|
|
|
}
|