2004-11-26 23:10:28 +00:00
|
|
|
/* GStreamer TTA plugin
|
|
|
|
* (c) 2004 Arwed v. Merkatz <v.merkatz@gmx.net>
|
|
|
|
*
|
|
|
|
* gstttaparse.c: TTA file parser
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2012-01-27 14:49:58 +00:00
|
|
|
/* FIXME 0.11: suppress warnings for deprecated API such as GStaticRecMutex
|
|
|
|
* with newer GLib versions (>= 2.31.0) */
|
|
|
|
#define GLIB_DISABLE_DEPRECATION_WARNINGS
|
|
|
|
|
2004-11-26 23:10:28 +00:00
|
|
|
#include <gst/gst.h>
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include "gstttaparse.h"
|
|
|
|
#include "ttadec.h"
|
|
|
|
#include "crc32.h"
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_tta_parse_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_tta_parse_debug
|
|
|
|
|
|
|
|
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("audio/x-ttafile")
|
|
|
|
);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("audio/x-tta, "
|
|
|
|
"width = (int) { 8, 16, 24 }, "
|
|
|
|
"channels = (int) { 1, 2 }, " "rate = (int) [ 8000, 96000 ]")
|
|
|
|
);
|
|
|
|
|
|
|
|
static void gst_tta_parse_class_init (GstTtaParseClass * klass);
|
|
|
|
static void gst_tta_parse_base_init (GstTtaParseClass * klass);
|
|
|
|
static void gst_tta_parse_init (GstTtaParse * ttaparse);
|
|
|
|
|
2005-09-22 11:17:26 +00:00
|
|
|
static gboolean gst_tta_parse_src_event (GstPad * pad, GstEvent * event);
|
|
|
|
static const GstQueryType *gst_tta_parse_get_query_types (GstPad * pad);
|
|
|
|
static gboolean gst_tta_parse_query (GstPad * pad, GstQuery * query);
|
|
|
|
static gboolean gst_tta_parse_activate (GstPad * pad);
|
|
|
|
static gboolean gst_tta_parse_activate_pull (GstPad * pad, gboolean active);
|
|
|
|
static void gst_tta_parse_loop (GstTtaParse * ttaparse);
|
|
|
|
static GstStateChangeReturn gst_tta_parse_change_state (GstElement * element,
|
|
|
|
GstStateChange transition);
|
2004-11-26 23:10:28 +00:00
|
|
|
|
2005-09-22 11:17:26 +00:00
|
|
|
static GstElementClass *parent_class = NULL;
|
2004-11-26 23:10:28 +00:00
|
|
|
|
|
|
|
GType
|
|
|
|
gst_tta_parse_get_type (void)
|
|
|
|
{
|
|
|
|
static GType plugin_type = 0;
|
|
|
|
|
|
|
|
if (!plugin_type) {
|
|
|
|
static const GTypeInfo plugin_info = {
|
|
|
|
sizeof (GstTtaParseClass),
|
|
|
|
(GBaseInitFunc) gst_tta_parse_base_init,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc) gst_tta_parse_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof (GstTtaParse),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc) gst_tta_parse_init,
|
|
|
|
};
|
|
|
|
plugin_type = g_type_register_static (GST_TYPE_ELEMENT,
|
|
|
|
"GstTtaParse", &plugin_info, 0);
|
|
|
|
}
|
|
|
|
return plugin_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_tta_parse_base_init (GstTtaParseClass * klass)
|
|
|
|
{
|
2010-03-18 16:30:26 +00:00
|
|
|
|
2004-11-26 23:10:28 +00:00
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&src_factory));
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&sink_factory));
|
2010-03-18 16:30:26 +00:00
|
|
|
gst_element_class_set_details_simple (element_class, "TTA file parser",
|
|
|
|
"Codec/Demuxer/Audio",
|
|
|
|
"Parses TTA files", "Arwed v. Merkatz <v.merkatz@gmx.net>");
|
2004-11-26 23:10:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_tta_parse_dispose (GObject * object)
|
|
|
|
{
|
|
|
|
GstTtaParse *ttaparse = GST_TTA_PARSE (object);
|
|
|
|
|
|
|
|
g_free (ttaparse->index);
|
|
|
|
|
2005-09-22 11:17:26 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
2004-11-26 23:10:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_tta_parse_class_init (GstTtaParseClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
|
|
|
|
2006-04-08 21:48:01 +00:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2004-11-26 23:10:28 +00:00
|
|
|
|
|
|
|
gobject_class->dispose = gst_tta_parse_dispose;
|
2005-09-22 11:17:26 +00:00
|
|
|
gstelement_class->change_state = gst_tta_parse_change_state;
|
2004-11-26 23:10:28 +00:00
|
|
|
}
|
|
|
|
|
2005-09-22 11:17:26 +00:00
|
|
|
static void
|
|
|
|
gst_tta_parse_reset (GstTtaParse * ttaparse)
|
2004-11-26 23:10:28 +00:00
|
|
|
{
|
2005-09-22 11:17:26 +00:00
|
|
|
ttaparse->header_parsed = FALSE;
|
|
|
|
ttaparse->current_frame = 0;
|
|
|
|
ttaparse->data_length = 0;
|
|
|
|
ttaparse->samplerate = 0;
|
|
|
|
}
|
2004-11-26 23:10:28 +00:00
|
|
|
|
2005-09-22 11:17:26 +00:00
|
|
|
static void
|
|
|
|
gst_tta_parse_init (GstTtaParse * ttaparse)
|
|
|
|
{
|
|
|
|
GstElementClass *klass = GST_ELEMENT_GET_CLASS (ttaparse);
|
|
|
|
|
|
|
|
ttaparse->sinkpad =
|
|
|
|
gst_pad_new_from_template (gst_element_class_get_pad_template (klass,
|
|
|
|
"sink"), "sink");
|
|
|
|
|
|
|
|
ttaparse->srcpad =
|
|
|
|
gst_pad_new_from_template (gst_element_class_get_pad_template (klass,
|
|
|
|
"src"), "src");
|
|
|
|
gst_pad_use_fixed_caps (ttaparse->srcpad);
|
|
|
|
gst_pad_set_query_type_function (ttaparse->srcpad,
|
|
|
|
gst_tta_parse_get_query_types);
|
|
|
|
gst_pad_set_query_function (ttaparse->srcpad, gst_tta_parse_query);
|
|
|
|
gst_pad_set_event_function (ttaparse->srcpad, gst_tta_parse_src_event);
|
|
|
|
|
|
|
|
gst_element_add_pad (GST_ELEMENT (ttaparse), ttaparse->sinkpad);
|
|
|
|
gst_element_add_pad (GST_ELEMENT (ttaparse), ttaparse->srcpad);
|
|
|
|
gst_pad_set_activate_function (ttaparse->sinkpad, gst_tta_parse_activate);
|
|
|
|
gst_pad_set_activatepull_function (ttaparse->sinkpad,
|
|
|
|
gst_tta_parse_activate_pull);
|
|
|
|
|
|
|
|
gst_tta_parse_reset (ttaparse);
|
2004-11-26 23:10:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2005-09-22 11:17:26 +00:00
|
|
|
gst_tta_parse_src_event (GstPad * pad, GstEvent * event)
|
2004-11-26 23:10:28 +00:00
|
|
|
{
|
2005-09-22 11:17:26 +00:00
|
|
|
GstTtaParse *ttaparse = GST_TTA_PARSE (GST_PAD_PARENT (pad));
|
|
|
|
|
|
|
|
gboolean res = TRUE;
|
2004-11-26 23:10:28 +00:00
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_SEEK:
|
|
|
|
{
|
2005-09-22 11:17:26 +00:00
|
|
|
gdouble rate;
|
|
|
|
GstFormat format;
|
|
|
|
GstSeekFlags flags;
|
|
|
|
GstSeekType start_type, stop_type;
|
|
|
|
gint64 start, stop;
|
|
|
|
|
|
|
|
gst_event_parse_seek (event, &rate, &format, &flags,
|
|
|
|
&start_type, &start, &stop_type, &stop);
|
|
|
|
|
|
|
|
if (format == GST_FORMAT_TIME) {
|
|
|
|
if (flags & GST_SEEK_FLAG_FLUSH) {
|
|
|
|
gst_pad_push_event (ttaparse->srcpad, gst_event_new_flush_start ());
|
|
|
|
gst_pad_push_event (ttaparse->sinkpad, gst_event_new_flush_start ());
|
2004-11-26 23:10:28 +00:00
|
|
|
} else {
|
2005-09-22 11:17:26 +00:00
|
|
|
gst_pad_pause_task (ttaparse->sinkpad);
|
|
|
|
}
|
2005-11-21 17:37:41 +00:00
|
|
|
GST_PAD_STREAM_LOCK (ttaparse->sinkpad);
|
2005-09-22 11:17:26 +00:00
|
|
|
|
|
|
|
switch (start_type) {
|
|
|
|
case GST_SEEK_TYPE_CUR:
|
|
|
|
ttaparse->current_frame += (start / GST_SECOND) / FRAME_TIME;
|
|
|
|
break;
|
|
|
|
case GST_SEEK_TYPE_END:
|
|
|
|
ttaparse->current_frame += (start / GST_SECOND) / FRAME_TIME;
|
|
|
|
break;
|
|
|
|
case GST_SEEK_TYPE_SET:
|
|
|
|
ttaparse->current_frame = (start / GST_SECOND) / FRAME_TIME;
|
|
|
|
break;
|
|
|
|
case GST_SEEK_TYPE_NONE:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
res = TRUE;
|
|
|
|
|
|
|
|
if (flags & GST_SEEK_FLAG_FLUSH) {
|
|
|
|
gst_pad_push_event (ttaparse->srcpad, gst_event_new_flush_stop ());
|
|
|
|
gst_pad_push_event (ttaparse->sinkpad, gst_event_new_flush_stop ());
|
2004-11-26 23:10:28 +00:00
|
|
|
}
|
2005-09-22 11:17:26 +00:00
|
|
|
|
2005-11-22 11:57:51 +00:00
|
|
|
gst_pad_push_event (ttaparse->srcpad, gst_event_new_new_segment (FALSE,
|
2005-10-11 16:34:36 +00:00
|
|
|
1.0, GST_FORMAT_TIME, 0,
|
2005-09-22 11:17:26 +00:00
|
|
|
ttaparse->num_frames * FRAME_TIME * GST_SECOND, 0));
|
|
|
|
|
|
|
|
gst_pad_start_task (ttaparse->sinkpad,
|
|
|
|
(GstTaskFunction) gst_tta_parse_loop, ttaparse);
|
|
|
|
|
2005-11-21 17:37:41 +00:00
|
|
|
GST_PAD_STREAM_UNLOCK (ttaparse->sinkpad);
|
2005-09-22 11:17:26 +00:00
|
|
|
|
2004-11-26 23:10:28 +00:00
|
|
|
} else {
|
2005-09-22 11:17:26 +00:00
|
|
|
res = FALSE;
|
2004-11-26 23:10:28 +00:00
|
|
|
}
|
2005-09-22 11:17:26 +00:00
|
|
|
|
|
|
|
gst_event_unref (event);
|
2004-11-26 23:10:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2005-09-22 11:17:26 +00:00
|
|
|
res = gst_pad_event_default (pad, event);
|
2004-11-26 23:10:28 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-09-22 11:17:26 +00:00
|
|
|
|
|
|
|
return res;
|
2004-11-26 23:10:28 +00:00
|
|
|
}
|
|
|
|
|
2005-09-22 11:17:26 +00:00
|
|
|
static const GstQueryType *
|
|
|
|
gst_tta_parse_get_query_types (GstPad * pad)
|
2004-11-26 23:10:28 +00:00
|
|
|
{
|
2005-09-22 11:17:26 +00:00
|
|
|
static const GstQueryType types[] = {
|
|
|
|
GST_QUERY_POSITION,
|
2005-10-19 15:58:01 +00:00
|
|
|
GST_QUERY_DURATION,
|
2005-09-22 11:17:26 +00:00
|
|
|
0
|
|
|
|
};
|
2004-11-26 23:10:28 +00:00
|
|
|
|
2005-09-22 11:17:26 +00:00
|
|
|
return types;
|
2004-11-26 23:10:28 +00:00
|
|
|
}
|
|
|
|
|
2005-09-22 11:17:26 +00:00
|
|
|
static gboolean
|
|
|
|
gst_tta_parse_query (GstPad * pad, GstQuery * query)
|
2004-11-26 23:10:28 +00:00
|
|
|
{
|
|
|
|
GstTtaParse *ttaparse = GST_TTA_PARSE (gst_pad_get_parent (pad));
|
|
|
|
|
2005-09-22 11:17:26 +00:00
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_POSITION:
|
2004-11-26 23:10:28 +00:00
|
|
|
{
|
2005-09-22 11:17:26 +00:00
|
|
|
GstFormat format;
|
2005-10-19 15:58:01 +00:00
|
|
|
gint64 cur;
|
2005-09-22 11:17:26 +00:00
|
|
|
|
2005-10-19 15:58:01 +00:00
|
|
|
gst_query_parse_position (query, &format, NULL);
|
2005-09-22 11:17:26 +00:00
|
|
|
switch (format) {
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
cur = ttaparse->index[ttaparse->current_frame].time;
|
2005-10-19 15:58:01 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
format = GST_FORMAT_BYTES;
|
|
|
|
cur = ttaparse->index[ttaparse->current_frame].pos;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
gst_query_set_position (query, format, cur);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_QUERY_DURATION:
|
|
|
|
{
|
|
|
|
GstFormat format;
|
|
|
|
gint64 end;
|
|
|
|
|
|
|
|
gst_query_parse_duration (query, &format, NULL);
|
|
|
|
switch (format) {
|
|
|
|
case GST_FORMAT_TIME:
|
2005-09-22 11:17:26 +00:00
|
|
|
end = ((gdouble) ttaparse->data_length /
|
|
|
|
(gdouble) ttaparse->samplerate) * GST_SECOND;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
format = GST_FORMAT_BYTES;
|
|
|
|
end = ttaparse->index[ttaparse->num_frames].pos +
|
|
|
|
ttaparse->index[ttaparse->num_frames].size;
|
|
|
|
break;
|
2004-11-26 23:10:28 +00:00
|
|
|
}
|
2005-10-19 15:58:01 +00:00
|
|
|
gst_query_set_duration (query, format, end);
|
2004-11-26 23:10:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2005-09-22 11:17:26 +00:00
|
|
|
return FALSE;
|
2004-11-26 23:10:28 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-09-22 11:17:26 +00:00
|
|
|
return TRUE;
|
2004-11-26 23:10:28 +00:00
|
|
|
}
|
|
|
|
|
2005-09-22 11:17:26 +00:00
|
|
|
static gboolean
|
|
|
|
gst_tta_parse_activate (GstPad * pad)
|
|
|
|
{
|
|
|
|
if (gst_pad_check_pull_range (pad)) {
|
|
|
|
return gst_pad_activate_pull (pad, TRUE);
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_tta_parse_activate_pull (GstPad * pad, gboolean active)
|
2004-11-26 23:10:28 +00:00
|
|
|
{
|
2005-09-22 11:17:26 +00:00
|
|
|
GstTtaParse *ttaparse = GST_TTA_PARSE (GST_OBJECT_PARENT (pad));
|
|
|
|
|
|
|
|
if (active) {
|
|
|
|
gst_pad_start_task (pad, (GstTaskFunction) gst_tta_parse_loop, ttaparse);
|
|
|
|
} else {
|
|
|
|
gst_pad_stop_task (pad);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_tta_parse_parse_header (GstTtaParse * ttaparse)
|
|
|
|
{
|
2004-11-26 23:10:28 +00:00
|
|
|
guchar *data;
|
2005-09-22 11:17:26 +00:00
|
|
|
GstBuffer *buf = NULL;
|
|
|
|
guint32 crc;
|
|
|
|
double frame_length;
|
|
|
|
int num_frames;
|
2004-11-26 23:10:28 +00:00
|
|
|
GstCaps *caps;
|
2005-09-22 11:17:26 +00:00
|
|
|
int i;
|
|
|
|
guint32 offset;
|
|
|
|
GstEvent *discont;
|
|
|
|
|
2010-11-25 18:25:27 +00:00
|
|
|
if (gst_pad_pull_range (ttaparse->sinkpad, 0, 22, &buf) != GST_FLOW_OK)
|
2005-09-22 11:17:26 +00:00
|
|
|
goto pull_fail;
|
|
|
|
data = GST_BUFFER_DATA (buf);
|
|
|
|
ttaparse->channels = GST_READ_UINT16_LE (data + 6);
|
|
|
|
ttaparse->bits = GST_READ_UINT16_LE (data + 8);
|
|
|
|
ttaparse->samplerate = GST_READ_UINT32_LE (data + 10);
|
|
|
|
ttaparse->data_length = GST_READ_UINT32_LE (data + 14);
|
|
|
|
crc = crc32 (data, 18);
|
|
|
|
if (crc != GST_READ_UINT32_LE (data + 18)) {
|
|
|
|
GST_DEBUG ("Header CRC wrong!");
|
|
|
|
}
|
|
|
|
frame_length = FRAME_TIME * ttaparse->samplerate;
|
|
|
|
num_frames = (ttaparse->data_length / frame_length) + 1;
|
|
|
|
ttaparse->num_frames = num_frames;
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
|
|
|
|
ttaparse->index =
|
|
|
|
(GstTtaIndex *) g_malloc (num_frames * sizeof (GstTtaIndex));
|
2010-11-25 18:25:27 +00:00
|
|
|
if (gst_pad_pull_range (ttaparse->sinkpad,
|
|
|
|
22, num_frames * 4 + 4, &buf) != GST_FLOW_OK)
|
2005-09-22 11:17:26 +00:00
|
|
|
goto pull_fail;
|
|
|
|
data = GST_BUFFER_DATA (buf);
|
|
|
|
|
|
|
|
offset = 22 + num_frames * 4 + 4; // header size + seektable size
|
|
|
|
for (i = 0; i < num_frames; i++) {
|
|
|
|
ttaparse->index[i].size = GST_READ_UINT32_LE (data + i * 4);
|
|
|
|
ttaparse->index[i].pos = offset;
|
|
|
|
offset += ttaparse->index[i].size;
|
|
|
|
ttaparse->index[i].time = i * FRAME_TIME * GST_SECOND;
|
|
|
|
}
|
|
|
|
crc = crc32 (data, num_frames * 4);
|
|
|
|
if (crc != GST_READ_UINT32_LE (data + num_frames * 4)) {
|
|
|
|
GST_DEBUG ("Seektable CRC wrong!");
|
|
|
|
}
|
2004-11-26 23:10:28 +00:00
|
|
|
|
2005-09-22 11:17:26 +00:00
|
|
|
GST_DEBUG
|
|
|
|
("channels: %u, bits: %u, samplerate: %u, data_length: %u, num_frames: %u",
|
|
|
|
ttaparse->channels, ttaparse->bits, ttaparse->samplerate,
|
|
|
|
ttaparse->data_length, num_frames);
|
2004-11-26 23:10:28 +00:00
|
|
|
|
2005-09-22 11:17:26 +00:00
|
|
|
ttaparse->header_parsed = TRUE;
|
|
|
|
caps = gst_caps_new_simple ("audio/x-tta",
|
|
|
|
"width", G_TYPE_INT, ttaparse->bits,
|
|
|
|
"channels", G_TYPE_INT, ttaparse->channels,
|
|
|
|
"rate", G_TYPE_INT, ttaparse->samplerate, NULL);
|
|
|
|
gst_pad_set_caps (ttaparse->srcpad, caps);
|
2004-11-26 23:10:28 +00:00
|
|
|
|
2005-09-22 11:17:26 +00:00
|
|
|
discont =
|
2005-11-22 11:57:51 +00:00
|
|
|
gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME, 0,
|
2005-09-22 11:17:26 +00:00
|
|
|
num_frames * FRAME_TIME * GST_SECOND, 0);
|
2004-11-26 23:10:28 +00:00
|
|
|
|
2005-09-22 11:17:26 +00:00
|
|
|
gst_pad_push_event (ttaparse->srcpad, discont);
|
2004-11-26 23:10:28 +00:00
|
|
|
|
2005-09-22 11:17:26 +00:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
|
|
|
|
pull_fail:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (ttaparse, STREAM, DEMUX, (NULL),
|
|
|
|
("Couldn't read header"));
|
|
|
|
return GST_FLOW_ERROR;
|
2004-11-26 23:10:28 +00:00
|
|
|
}
|
2005-09-22 11:17:26 +00:00
|
|
|
}
|
2004-11-26 23:10:28 +00:00
|
|
|
|
2005-09-22 11:17:26 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_tta_parse_stream_data (GstTtaParse * ttaparse)
|
|
|
|
{
|
|
|
|
GstBuffer *buf = NULL;
|
|
|
|
GstFlowReturn res = GST_FLOW_OK;
|
|
|
|
|
|
|
|
if (ttaparse->current_frame >= ttaparse->num_frames)
|
|
|
|
goto found_eos;
|
|
|
|
|
|
|
|
GST_DEBUG ("playing frame %u of %u", ttaparse->current_frame + 1,
|
|
|
|
ttaparse->num_frames);
|
|
|
|
if ((res = gst_pad_pull_range (ttaparse->sinkpad,
|
|
|
|
ttaparse->index[ttaparse->current_frame].pos,
|
|
|
|
ttaparse->index[ttaparse->current_frame].size,
|
|
|
|
&buf)) != GST_FLOW_OK)
|
|
|
|
goto pull_error;
|
|
|
|
|
|
|
|
GST_BUFFER_OFFSET (buf) = ttaparse->index[ttaparse->current_frame].pos;
|
|
|
|
GST_BUFFER_TIMESTAMP (buf) = ttaparse->index[ttaparse->current_frame].time;
|
|
|
|
if (ttaparse->current_frame + 1 == ttaparse->num_frames) {
|
|
|
|
guint32 samples =
|
|
|
|
ttaparse->data_length % (gint64) (ttaparse->samplerate * FRAME_TIME);
|
|
|
|
gdouble frametime = (gdouble) samples / (gdouble) ttaparse->samplerate;
|
|
|
|
|
|
|
|
GST_BUFFER_DURATION (buf) = (guint64) (frametime * GST_SECOND);
|
|
|
|
} else {
|
|
|
|
GST_BUFFER_DURATION (buf) = FRAME_TIME * GST_SECOND;
|
2004-11-26 23:10:28 +00:00
|
|
|
}
|
2005-09-22 11:17:26 +00:00
|
|
|
gst_buffer_set_caps (buf, GST_PAD_CAPS (ttaparse->srcpad));
|
2004-11-26 23:10:28 +00:00
|
|
|
|
2005-09-22 11:17:26 +00:00
|
|
|
if ((res = gst_pad_push (ttaparse->srcpad, buf)) != GST_FLOW_OK)
|
|
|
|
goto push_error;
|
|
|
|
ttaparse->current_frame++;
|
2004-11-26 23:10:28 +00:00
|
|
|
|
2005-09-22 11:17:26 +00:00
|
|
|
return res;
|
|
|
|
|
|
|
|
found_eos:
|
|
|
|
{
|
|
|
|
GST_DEBUG ("found EOS");
|
|
|
|
gst_pad_push_event (ttaparse->srcpad, gst_event_new_eos ());
|
2012-02-08 15:37:13 +00:00
|
|
|
return GST_FLOW_FLUSHING;
|
2004-11-26 23:10:28 +00:00
|
|
|
}
|
2005-09-22 11:17:26 +00:00
|
|
|
pull_error:
|
|
|
|
{
|
|
|
|
GST_DEBUG ("Error getting frame from the sinkpad");
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
push_error:
|
|
|
|
{
|
|
|
|
GST_DEBUG ("Error pushing on srcpad");
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_tta_parse_loop (GstTtaParse * ttaparse)
|
|
|
|
{
|
|
|
|
GstFlowReturn ret;
|
|
|
|
|
|
|
|
if (!ttaparse->header_parsed)
|
|
|
|
if ((ret = gst_tta_parse_parse_header (ttaparse)) != GST_FLOW_OK)
|
|
|
|
goto pause;
|
|
|
|
if ((ret = gst_tta_parse_stream_data (ttaparse)) != GST_FLOW_OK)
|
|
|
|
goto pause;
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
pause:
|
2007-06-08 16:49:41 +00:00
|
|
|
GST_LOG_OBJECT (ttaparse, "pausing task, %s", gst_flow_get_name (ret));
|
2005-09-22 11:17:26 +00:00
|
|
|
gst_pad_pause_task (ttaparse->sinkpad);
|
2010-08-27 16:52:54 +00:00
|
|
|
if (ret == GST_FLOW_UNEXPECTED) {
|
|
|
|
gst_pad_push_event (ttaparse->srcpad, gst_event_new_eos ());
|
|
|
|
} else if (ret < GST_FLOW_UNEXPECTED || ret == GST_FLOW_NOT_LINKED) {
|
2005-10-23 14:38:00 +00:00
|
|
|
GST_ELEMENT_ERROR (ttaparse, STREAM, FAILED,
|
2007-06-08 16:49:41 +00:00
|
|
|
("Internal data stream error."),
|
|
|
|
("streaming stopped, reason %s", gst_flow_get_name (ret)));
|
2005-09-22 11:17:26 +00:00
|
|
|
gst_pad_push_event (ttaparse->srcpad, gst_event_new_eos ());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_tta_parse_change_state (GstElement * element, GstStateChange transition)
|
|
|
|
{
|
|
|
|
GstStateChangeReturn ret;
|
|
|
|
GstTtaParse *ttaparse = GST_TTA_PARSE (element);
|
2004-11-26 23:10:28 +00:00
|
|
|
|
2005-09-22 11:17:26 +00:00
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
2004-11-26 23:10:28 +00:00
|
|
|
|
2005-09-22 11:17:26 +00:00
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
|
|
|
gst_tta_parse_reset (ttaparse);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2004-11-26 23:10:28 +00:00
|
|
|
}
|
|
|
|
|
2005-09-22 11:17:26 +00:00
|
|
|
return ret;
|
2004-11-26 23:10:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_tta_parse_plugin_init (GstPlugin * plugin)
|
|
|
|
{
|
|
|
|
if (!gst_element_register (plugin, "ttaparse",
|
2011-06-25 22:12:45 +00:00
|
|
|
GST_RANK_NONE, GST_TYPE_TTA_PARSE)) {
|
2004-11-26 23:10:28 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_tta_parse_debug, "ttaparse", 0,
|
|
|
|
"tta file parser");
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|