2009-08-07 04:41:43 +00:00
|
|
|
/* Copyright (C) 2004-2005,2009 Michael Pyne <mpyne at kde org>
|
|
|
|
* Copyright (C) 2004-2006 Chris Lee <clee at kde org>
|
|
|
|
* Copyright (C) 2007 Brian Koropoff <bkoropoff at gmail com>
|
|
|
|
*
|
|
|
|
* 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-03-06 17:11:35 +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
|
|
|
|
|
2009-08-07 04:41:43 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstgme.h"
|
2012-03-18 17:33:00 +00:00
|
|
|
#include <gst/audio/audio.h>
|
2009-08-07 04:41:43 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <glib/gprintf.h>
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
static GstStaticPadTemplate sink_factory =
|
2009-08-07 07:21:04 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("audio/x-ay; "
|
|
|
|
"audio/x-gbs; "
|
|
|
|
"audio/x-gym; "
|
|
|
|
"audio/x-hes; "
|
|
|
|
"audio/x-kss; "
|
|
|
|
"audio/x-nsf; " "audio/x-sap; " "audio/x-spc; " "audio/x-vgm"));
|
2009-08-07 04:41:43 +00:00
|
|
|
|
|
|
|
static GstStaticPadTemplate src_factory =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
|
2012-03-18 17:33:00 +00:00
|
|
|
GST_STATIC_CAPS ("audio/x-raw, "
|
|
|
|
"format = (string) " GST_AUDIO_NE (S16) ", "
|
|
|
|
"layout = (string) interleaved, "
|
|
|
|
"rate = (int) 32000, " "channels = (int) 2"));
|
2009-08-07 04:41:43 +00:00
|
|
|
|
2011-10-08 09:57:58 +00:00
|
|
|
#define gst_gme_dec_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE (GstGmeDec, gst_gme_dec, GST_TYPE_ELEMENT);
|
2009-08-07 04:41:43 +00:00
|
|
|
|
2011-11-21 09:54:56 +00:00
|
|
|
static GstFlowReturn gst_gme_dec_chain (GstPad * pad, GstObject * parent,
|
|
|
|
GstBuffer * buffer);
|
|
|
|
static gboolean gst_gme_dec_sink_event (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event);
|
|
|
|
static gboolean gst_gme_dec_src_event (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event);
|
2011-11-17 08:56:34 +00:00
|
|
|
static gboolean gst_gme_dec_src_query (GstPad * pad, GstObject * parent,
|
|
|
|
GstQuery * query);
|
2009-08-07 04:59:55 +00:00
|
|
|
static GstStateChangeReturn gst_gme_dec_change_state (GstElement * element,
|
2009-08-07 04:41:43 +00:00
|
|
|
GstStateChange transition);
|
2009-08-07 04:59:55 +00:00
|
|
|
static void gst_gme_play (GstPad * pad);
|
|
|
|
static void gst_gme_dec_dispose (GObject * object);
|
|
|
|
static gboolean gme_setup (GstGmeDec * gme);
|
2009-08-07 04:41:43 +00:00
|
|
|
|
|
|
|
static gboolean
|
2009-08-07 04:59:55 +00:00
|
|
|
gme_negotiate (GstGmeDec * gme)
|
2009-08-07 04:41:43 +00:00
|
|
|
{
|
2012-03-18 17:33:00 +00:00
|
|
|
GstCaps *caps;
|
2009-08-07 04:41:43 +00:00
|
|
|
|
2012-03-18 17:33:00 +00:00
|
|
|
caps = gst_pad_get_pad_template_caps (gme->srcpad);
|
|
|
|
gst_pad_set_caps (gme->srcpad, caps);
|
2009-08-07 04:41:43 +00:00
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-10-08 09:57:58 +00:00
|
|
|
gst_gme_dec_class_init (GstGmeDecClass * klass)
|
2009-08-07 04:41:43 +00:00
|
|
|
{
|
2011-10-08 09:57:58 +00:00
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
|
|
|
GstElementClass *element_class = (GstElementClass *) klass;
|
|
|
|
|
|
|
|
gobject_class->dispose = gst_gme_dec_dispose;
|
2009-08-07 04:41:43 +00:00
|
|
|
|
2009-08-07 04:59:55 +00:00
|
|
|
gst_element_class_set_details_simple (element_class,
|
|
|
|
"Gaming console music file decoder", "Codec/Audio/Decoder",
|
|
|
|
"Uses libgme to emulate a gaming console sound processors",
|
|
|
|
"Chris Lee <clee@kde.org>, Brian Koropoff <bkoropoff@gmail.com>, "
|
|
|
|
"Michael Pyne <mpyne@kde.org>, Sebastian Dröge <sebastian.droege@collabora.co.uk>");
|
2009-08-07 04:41:43 +00:00
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&sink_factory));
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&src_factory));
|
|
|
|
|
2009-08-07 04:59:55 +00:00
|
|
|
element_class->change_state = GST_DEBUG_FUNCPTR (gst_gme_dec_change_state);
|
2009-08-07 04:41:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2011-10-08 09:57:58 +00:00
|
|
|
gst_gme_dec_init (GstGmeDec * gme)
|
2009-08-07 04:41:43 +00:00
|
|
|
{
|
2009-08-07 04:59:55 +00:00
|
|
|
gme->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
|
|
|
|
/* gst_pad_set_query_function (gme->sinkpad, NULL); */
|
|
|
|
gst_pad_set_event_function (gme->sinkpad, gst_gme_dec_sink_event);
|
|
|
|
gst_pad_set_chain_function (gme->sinkpad, gst_gme_dec_chain);
|
|
|
|
gst_element_add_pad (GST_ELEMENT (gme), gme->sinkpad);
|
|
|
|
|
|
|
|
gme->srcpad = gst_pad_new_from_static_template (&src_factory, "src");
|
|
|
|
gst_pad_set_event_function (gme->srcpad, gst_gme_dec_src_event);
|
|
|
|
gst_pad_set_query_function (gme->srcpad, gst_gme_dec_src_query);
|
|
|
|
gst_pad_use_fixed_caps (gme->srcpad);
|
|
|
|
gst_element_add_pad (GST_ELEMENT (gme), gme->srcpad);
|
|
|
|
|
2009-08-07 12:41:31 +00:00
|
|
|
gme->adapter = gst_adapter_new ();
|
2009-08-07 04:59:55 +00:00
|
|
|
gme->player = NULL;
|
|
|
|
gme->total_duration = GST_CLOCK_TIME_NONE;
|
|
|
|
gme->initialized = FALSE;
|
2009-08-07 04:41:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-08-07 04:59:55 +00:00
|
|
|
gst_gme_dec_dispose (GObject * object)
|
2009-08-07 04:41:43 +00:00
|
|
|
{
|
2009-08-07 04:59:55 +00:00
|
|
|
GstGmeDec *gme = GST_GME_DEC (object);
|
2009-08-07 04:41:43 +00:00
|
|
|
|
2009-08-07 12:41:31 +00:00
|
|
|
if (gme->adapter) {
|
2009-08-31 12:14:02 +00:00
|
|
|
g_object_unref (gme->adapter);
|
2009-08-07 12:41:31 +00:00
|
|
|
gme->adapter = NULL;
|
2009-08-07 04:41:43 +00:00
|
|
|
}
|
2012-01-16 17:01:18 +00:00
|
|
|
|
|
|
|
GST_CALL_PARENT (G_OBJECT_CLASS, dispose, (object));
|
2009-08-07 04:41:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2011-11-21 09:54:56 +00:00
|
|
|
gst_gme_dec_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
|
2009-08-07 04:41:43 +00:00
|
|
|
{
|
2011-11-21 09:54:56 +00:00
|
|
|
GstGmeDec *gme = GST_GME_DEC (parent);
|
2009-08-07 04:41:43 +00:00
|
|
|
|
2009-08-07 04:59:55 +00:00
|
|
|
/* Accumulate GME data until end-of-stream, then commence playback. */
|
2009-08-07 12:41:31 +00:00
|
|
|
gst_adapter_push (gme->adapter, buffer);
|
2009-08-07 04:41:43 +00:00
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-11-21 09:54:56 +00:00
|
|
|
gst_gme_dec_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
|
2009-08-07 04:41:43 +00:00
|
|
|
{
|
2011-11-21 09:54:56 +00:00
|
|
|
GstGmeDec *gme = GST_GME_DEC (parent);
|
2009-08-07 04:41:43 +00:00
|
|
|
gboolean result = TRUE;
|
|
|
|
gboolean forward = FALSE;
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_EOS:
|
|
|
|
/* we get EOS when we loaded the complete file, now try to initialize the
|
|
|
|
* decoding */
|
2009-08-07 04:59:55 +00:00
|
|
|
if (!(result = gme_setup (gme))) {
|
2009-08-07 04:41:43 +00:00
|
|
|
/* can't start, post an ERROR and push EOS downstream */
|
2009-08-07 04:59:55 +00:00
|
|
|
GST_ELEMENT_ERROR (gme, STREAM, DEMUX, (NULL),
|
2009-08-07 04:41:43 +00:00
|
|
|
("can't start playback"));
|
|
|
|
forward = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (forward)
|
2009-08-07 04:59:55 +00:00
|
|
|
result = gst_pad_push_event (gme->srcpad, event);
|
2009-08-07 04:41:43 +00:00
|
|
|
else
|
|
|
|
gst_event_unref (event);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-11-21 09:54:56 +00:00
|
|
|
gst_gme_dec_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
|
2009-08-07 04:41:43 +00:00
|
|
|
{
|
2011-11-21 09:54:56 +00:00
|
|
|
GstGmeDec *gme = GST_GME_DEC (parent);
|
2009-08-07 04:41:43 +00:00
|
|
|
gboolean result = FALSE;
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_SEEK:
|
|
|
|
{
|
|
|
|
gdouble rate;
|
|
|
|
GstFormat format;
|
|
|
|
GstSeekFlags flags;
|
|
|
|
GstSeekType start_type, stop_type;
|
|
|
|
gint64 start, stop;
|
|
|
|
gboolean flush;
|
|
|
|
|
|
|
|
gst_event_parse_seek (event, &rate, &format, &flags, &start_type, &start,
|
|
|
|
&stop_type, &stop);
|
|
|
|
|
|
|
|
gst_event_unref (event);
|
|
|
|
|
|
|
|
if (format != GST_FORMAT_TIME) {
|
2009-08-07 04:59:55 +00:00
|
|
|
GST_DEBUG_OBJECT (gme, "seeking is only supported in TIME format");
|
2009-08-07 04:41:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (start_type != GST_SEEK_TYPE_SET || stop_type != GST_SEEK_TYPE_NONE) {
|
2009-08-07 04:59:55 +00:00
|
|
|
GST_DEBUG_OBJECT (gme, "unsupported seek type");
|
2009-08-07 04:41:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stop_type == GST_SEEK_TYPE_NONE)
|
|
|
|
stop = GST_CLOCK_TIME_NONE;
|
|
|
|
|
|
|
|
if (start_type == GST_SEEK_TYPE_SET) {
|
2011-10-08 09:57:58 +00:00
|
|
|
GstSegment seg;
|
2009-08-07 04:59:55 +00:00
|
|
|
guint64 cur = gme_tell (gme->player) * GST_MSECOND;
|
2009-08-07 04:41:43 +00:00
|
|
|
guint64 dest = (guint64) start;
|
|
|
|
|
2009-08-07 04:59:55 +00:00
|
|
|
if (gme->total_duration != GST_CLOCK_TIME_NONE)
|
|
|
|
dest = CLAMP (dest, 0, gme->total_duration);
|
2009-08-07 04:56:54 +00:00
|
|
|
else
|
|
|
|
dest = MAX (0, dest);
|
2009-08-07 04:41:43 +00:00
|
|
|
|
|
|
|
if (dest == cur)
|
|
|
|
break;
|
|
|
|
|
|
|
|
flush = (flags & GST_SEEK_FLAG_FLUSH) == GST_SEEK_FLAG_FLUSH;
|
|
|
|
|
|
|
|
if (flush) {
|
2009-08-07 04:59:55 +00:00
|
|
|
gst_pad_push_event (gme->srcpad, gst_event_new_flush_start ());
|
2009-08-07 04:41:43 +00:00
|
|
|
} else {
|
2009-08-07 04:59:55 +00:00
|
|
|
gst_pad_stop_task (gme->srcpad);
|
2009-08-07 04:41:43 +00:00
|
|
|
}
|
|
|
|
|
2009-08-07 04:59:55 +00:00
|
|
|
GST_PAD_STREAM_LOCK (gme->srcpad);
|
2009-08-07 04:41:43 +00:00
|
|
|
|
|
|
|
if (flags & GST_SEEK_FLAG_SEGMENT) {
|
2009-08-07 04:59:55 +00:00
|
|
|
gst_element_post_message (GST_ELEMENT (gme),
|
|
|
|
gst_message_new_segment_start (GST_OBJECT (gme), format, cur));
|
2009-08-07 04:41:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (flush) {
|
2011-10-08 09:57:58 +00:00
|
|
|
gst_pad_push_event (gme->srcpad, gst_event_new_flush_stop (TRUE));
|
2009-08-07 04:41:43 +00:00
|
|
|
}
|
|
|
|
|
2009-08-07 04:56:54 +00:00
|
|
|
if (stop == GST_CLOCK_TIME_NONE
|
2009-08-07 04:59:55 +00:00
|
|
|
&& gme->total_duration != GST_CLOCK_TIME_NONE)
|
|
|
|
stop = gme->total_duration;
|
2009-08-07 04:41:43 +00:00
|
|
|
|
2011-10-08 09:57:58 +00:00
|
|
|
gst_segment_init (&seg, GST_FORMAT_TIME);
|
|
|
|
seg.rate = rate;
|
|
|
|
seg.start = dest;
|
|
|
|
seg.stop = stop;
|
|
|
|
seg.time = dest;
|
|
|
|
gst_pad_push_event (gme->srcpad, gst_event_new_segment (&seg));
|
2009-08-07 04:41:43 +00:00
|
|
|
|
2009-08-07 04:59:55 +00:00
|
|
|
gme->seekpoint = dest / GST_MSECOND; /* nsecs to msecs */
|
|
|
|
gme->seeking = TRUE;
|
2009-08-07 04:41:43 +00:00
|
|
|
|
2009-08-07 04:59:55 +00:00
|
|
|
gst_pad_start_task (gme->srcpad, (GstTaskFunction) gst_gme_play,
|
|
|
|
gme->srcpad);
|
2009-08-07 04:41:43 +00:00
|
|
|
|
2009-08-07 04:59:55 +00:00
|
|
|
GST_PAD_STREAM_UNLOCK (gme->srcpad);
|
2009-08-07 04:41:43 +00:00
|
|
|
result = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2009-08-07 04:59:55 +00:00
|
|
|
result = gst_pad_push_event (gme->sinkpad, event);
|
2009-08-07 04:41:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-11-17 08:56:34 +00:00
|
|
|
gst_gme_dec_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
|
2009-08-07 04:41:43 +00:00
|
|
|
{
|
2011-11-17 08:56:34 +00:00
|
|
|
GstGmeDec *gme = GST_GME_DEC (parent);
|
2009-08-07 04:41:43 +00:00
|
|
|
gboolean result = TRUE;
|
|
|
|
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_DURATION:
|
|
|
|
{
|
|
|
|
GstFormat format;
|
|
|
|
|
|
|
|
gst_query_parse_duration (query, &format, NULL);
|
2009-08-07 04:59:55 +00:00
|
|
|
if (!gme->initialized || format != GST_FORMAT_TIME
|
|
|
|
|| gme->total_duration == GST_CLOCK_TIME_NONE) {
|
2009-08-07 04:41:43 +00:00
|
|
|
result = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2009-08-07 04:59:55 +00:00
|
|
|
gst_query_set_duration (query, GST_FORMAT_TIME, gme->total_duration);
|
2009-08-07 04:41:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_QUERY_POSITION:
|
|
|
|
{
|
|
|
|
GstFormat format;
|
|
|
|
|
|
|
|
gst_query_parse_position (query, &format, NULL);
|
2009-08-07 04:59:55 +00:00
|
|
|
if (!gme->initialized || format != GST_FORMAT_TIME) {
|
2009-08-07 04:41:43 +00:00
|
|
|
result = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
gst_query_set_position (query, GST_FORMAT_TIME,
|
2009-08-07 04:59:55 +00:00
|
|
|
(gint64) gme_tell (gme->player) * GST_MSECOND);
|
2009-08-07 04:41:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2011-11-17 08:56:34 +00:00
|
|
|
result = gst_pad_query_default (pad, parent, query);
|
2009-08-07 04:41:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-08-07 04:59:55 +00:00
|
|
|
gst_gme_play (GstPad * pad)
|
2009-08-07 04:41:43 +00:00
|
|
|
{
|
2009-08-07 04:59:55 +00:00
|
|
|
GstGmeDec *gme = GST_GME_DEC (gst_pad_get_parent (pad));
|
2009-08-07 04:41:43 +00:00
|
|
|
GstFlowReturn flow_return;
|
|
|
|
GstBuffer *out;
|
2009-08-07 04:59:55 +00:00
|
|
|
gboolean seeking = gme->seeking;
|
2009-08-07 04:41:43 +00:00
|
|
|
gme_err_t gme_err = NULL;
|
|
|
|
const int NUM_SAMPLES = 1600; /* 4 bytes (stereo 16-bit) per sample */
|
|
|
|
|
|
|
|
if (!seeking) {
|
2012-01-25 17:49:58 +00:00
|
|
|
GstMapInfo map;
|
2011-10-08 09:57:58 +00:00
|
|
|
|
2009-08-07 04:41:43 +00:00
|
|
|
out = gst_buffer_new_and_alloc (NUM_SAMPLES * 4);
|
2009-08-07 04:59:55 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (out) = gme_tell (gme->player) * GST_MSECOND;
|
2009-08-07 04:41:43 +00:00
|
|
|
|
2012-01-25 17:49:58 +00:00
|
|
|
gst_buffer_map (out, &map, GST_MAP_WRITE);
|
|
|
|
gme_err = gme_play (gme->player, NUM_SAMPLES * 2, (short *) map.data);
|
|
|
|
gst_buffer_unmap (out, &map);
|
2011-10-08 09:57:58 +00:00
|
|
|
|
2009-08-07 04:41:43 +00:00
|
|
|
if (gme_err) {
|
2012-02-19 20:57:39 +00:00
|
|
|
GST_ELEMENT_ERROR (gme, STREAM, DEMUX, (NULL), ("%s", gme_err));
|
2009-08-07 04:41:43 +00:00
|
|
|
gst_pad_pause_task (pad);
|
|
|
|
gst_pad_push_event (pad, gst_event_new_eos ());
|
2009-08-07 04:59:55 +00:00
|
|
|
gst_object_unref (gme);
|
2009-08-07 04:41:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2009-08-07 04:59:55 +00:00
|
|
|
gme_seek (gme->player, gme->seekpoint);
|
|
|
|
gme->seeking = FALSE;
|
2009-08-07 04:41:43 +00:00
|
|
|
|
|
|
|
out = gst_buffer_new ();
|
|
|
|
}
|
|
|
|
|
2009-08-07 04:59:55 +00:00
|
|
|
if ((flow_return = gst_pad_push (gme->srcpad, out)) != GST_FLOW_OK) {
|
|
|
|
GST_DEBUG_OBJECT (gme, "pausing task, reason %s",
|
2009-08-07 04:41:43 +00:00
|
|
|
gst_flow_get_name (flow_return));
|
|
|
|
|
|
|
|
gst_pad_pause_task (pad);
|
|
|
|
|
2012-01-04 09:02:28 +00:00
|
|
|
if (flow_return == GST_FLOW_EOS) {
|
2010-08-27 16:58:23 +00:00
|
|
|
gst_pad_push_event (pad, gst_event_new_eos ());
|
2012-01-04 09:02:28 +00:00
|
|
|
} else if (flow_return < GST_FLOW_EOS || flow_return == GST_FLOW_NOT_LINKED) {
|
2010-08-27 16:58:23 +00:00
|
|
|
GST_ELEMENT_ERROR (gme, STREAM, FAILED, ("Internal data stream error."),
|
|
|
|
("stream stopped, reason %s", gst_flow_get_name (flow_return)));
|
|
|
|
|
2009-08-07 04:41:43 +00:00
|
|
|
gst_pad_push_event (pad, gst_event_new_eos ());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-16 23:08:39 +00:00
|
|
|
if (gme_tell (gme->player) * GST_MSECOND > gme->total_duration) {
|
2009-08-07 04:41:43 +00:00
|
|
|
gst_pad_pause_task (pad);
|
|
|
|
gst_pad_push_event (pad, gst_event_new_eos ());
|
|
|
|
}
|
|
|
|
|
2009-08-07 04:59:55 +00:00
|
|
|
gst_object_unref (gme);
|
2009-08-07 04:41:43 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2009-08-07 04:59:55 +00:00
|
|
|
gme_setup (GstGmeDec * gme)
|
2009-08-07 04:41:43 +00:00
|
|
|
{
|
2009-08-07 04:56:54 +00:00
|
|
|
gme_info_t *info;
|
2009-08-07 04:41:43 +00:00
|
|
|
gme_err_t gme_err = NULL;
|
|
|
|
GstTagList *taglist;
|
|
|
|
guint64 total_duration;
|
2011-04-16 23:08:39 +00:00
|
|
|
guint64 fade_time;
|
2009-08-07 12:41:31 +00:00
|
|
|
GstBuffer *buffer;
|
2011-10-08 09:57:58 +00:00
|
|
|
GstSegment seg;
|
2012-01-25 17:49:58 +00:00
|
|
|
GstMapInfo map;
|
2009-08-07 04:41:43 +00:00
|
|
|
|
2009-08-07 12:41:31 +00:00
|
|
|
if (!gst_adapter_available (gme->adapter) || !gme_negotiate (gme)) {
|
2009-08-07 04:41:43 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-08-07 12:41:31 +00:00
|
|
|
buffer =
|
|
|
|
gst_adapter_take_buffer (gme->adapter,
|
|
|
|
gst_adapter_available (gme->adapter));
|
|
|
|
|
2012-01-25 17:49:58 +00:00
|
|
|
gst_buffer_map (buffer, &map, GST_MAP_READ);
|
|
|
|
gme_err = gme_open_data (map.data, map.size, &gme->player, 32000);
|
|
|
|
gst_buffer_unmap (buffer, &map);
|
2009-08-07 12:41:31 +00:00
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
|
2009-08-07 04:59:55 +00:00
|
|
|
if (gme_err || !gme->player) {
|
|
|
|
if (gme->player) {
|
|
|
|
gme_delete (gme->player);
|
|
|
|
gme->player = NULL;
|
2009-08-07 04:56:54 +00:00
|
|
|
}
|
|
|
|
|
2012-02-19 20:57:39 +00:00
|
|
|
GST_ELEMENT_ERROR (gme, STREAM, DEMUX, (NULL), ("%s", gme_err));
|
2009-08-07 04:56:54 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-08-07 04:41:43 +00:00
|
|
|
|
2009-08-07 04:59:55 +00:00
|
|
|
gme_err = gme_track_info (gme->player, &info, 0);
|
2009-08-07 04:41:43 +00:00
|
|
|
|
2011-11-02 08:14:41 +00:00
|
|
|
taglist = gst_tag_list_new_empty ();
|
2009-08-07 04:41:43 +00:00
|
|
|
|
2009-08-07 05:23:07 +00:00
|
|
|
if (info->song && *info->song)
|
2009-08-07 04:41:43 +00:00
|
|
|
gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, GST_TAG_TITLE,
|
2009-08-07 04:56:54 +00:00
|
|
|
info->song, NULL);
|
2009-08-07 05:23:07 +00:00
|
|
|
if (info->author && *info->author)
|
2009-08-07 04:41:43 +00:00
|
|
|
gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, GST_TAG_ARTIST,
|
2009-08-07 04:56:54 +00:00
|
|
|
info->author, NULL);
|
2009-08-07 04:41:43 +00:00
|
|
|
/* Prefer the name of the official soundtrack over the name of the game (since this is
|
|
|
|
* how track numbers are derived)
|
|
|
|
*/
|
2009-08-07 05:23:07 +00:00
|
|
|
if (info->game && *info->game)
|
2009-08-07 04:41:43 +00:00
|
|
|
gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, GST_TAG_ALBUM, info->game,
|
|
|
|
NULL);
|
|
|
|
|
2009-08-07 05:23:07 +00:00
|
|
|
if (info->comment && *info->comment)
|
2009-08-07 04:41:43 +00:00
|
|
|
gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, GST_TAG_COMMENT,
|
|
|
|
info->comment, NULL);
|
2009-08-07 05:23:07 +00:00
|
|
|
if (info->dumper && *info->dumper)
|
2009-08-07 04:41:43 +00:00
|
|
|
gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, GST_TAG_CONTACT,
|
|
|
|
info->dumper, NULL);
|
2009-08-07 05:23:07 +00:00
|
|
|
if (info->copyright && *info->copyright)
|
2009-08-07 04:56:54 +00:00
|
|
|
gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, GST_TAG_COPYRIGHT,
|
|
|
|
info->copyright, NULL);
|
2009-08-07 05:23:07 +00:00
|
|
|
if (info->system && *info->system)
|
2009-08-07 04:41:43 +00:00
|
|
|
gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, GST_TAG_ENCODER,
|
2009-08-07 04:56:54 +00:00
|
|
|
info->system, NULL);
|
2009-08-07 04:41:43 +00:00
|
|
|
|
2009-08-07 04:59:55 +00:00
|
|
|
gme->total_duration = total_duration =
|
2011-04-16 23:08:39 +00:00
|
|
|
gst_util_uint64_scale_int (info->play_length + (info->loop_length >
|
|
|
|
0 ? 8000 : 0), GST_MSECOND, 1);
|
|
|
|
fade_time = info->loop_length > 0 ? info->play_length : 0;
|
2009-08-07 04:41:43 +00:00
|
|
|
|
|
|
|
gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE,
|
2009-08-07 04:56:54 +00:00
|
|
|
GST_TAG_DURATION, total_duration, NULL);
|
2009-08-07 04:41:43 +00:00
|
|
|
|
2012-06-06 14:00:45 +00:00
|
|
|
gst_pad_push_event (gme->srcpad, gst_event_new_tag ("GstDecoder", taglist));
|
2009-08-07 04:41:43 +00:00
|
|
|
|
2009-08-07 04:56:54 +00:00
|
|
|
g_free (info);
|
2009-08-07 04:41:43 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LIBGME_ACCURACY
|
|
|
|
/* TODO: Is it worth it to make this optional? */
|
2009-08-07 04:59:55 +00:00
|
|
|
gme_enable_accuracy (gme->player, 1);
|
2009-08-07 04:41:43 +00:00
|
|
|
#endif
|
2009-08-07 04:59:55 +00:00
|
|
|
gme_start_track (gme->player, 0);
|
2011-04-16 23:08:39 +00:00
|
|
|
if (fade_time)
|
|
|
|
gme_set_fade (gme->player, fade_time);
|
2009-08-07 04:41:43 +00:00
|
|
|
|
2011-10-08 09:57:58 +00:00
|
|
|
gst_segment_init (&seg, GST_FORMAT_TIME);
|
|
|
|
gst_pad_push_event (gme->srcpad, gst_event_new_segment (&seg));
|
2009-08-07 04:41:43 +00:00
|
|
|
|
2009-08-07 04:59:55 +00:00
|
|
|
gst_pad_start_task (gme->srcpad, (GstTaskFunction) gst_gme_play, gme->srcpad);
|
2009-08-07 04:41:43 +00:00
|
|
|
|
2009-08-07 04:59:55 +00:00
|
|
|
gme->initialized = TRUE;
|
|
|
|
gme->seeking = FALSE;
|
|
|
|
gme->seekpoint = 0;
|
|
|
|
return gme->initialized;
|
2009-08-07 04:41:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstStateChangeReturn
|
2009-08-07 04:59:55 +00:00
|
|
|
gst_gme_dec_change_state (GstElement * element, GstStateChange transition)
|
2009-08-07 04:41:43 +00:00
|
|
|
{
|
|
|
|
GstStateChangeReturn result;
|
2009-08-07 04:59:55 +00:00
|
|
|
GstGmeDec *dec;
|
2009-08-07 04:41:43 +00:00
|
|
|
|
2009-08-07 04:59:55 +00:00
|
|
|
dec = GST_GME_DEC (element);
|
2009-08-07 04:41:43 +00:00
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
2009-08-07 04:56:54 +00:00
|
|
|
dec->total_duration = GST_CLOCK_TIME_NONE;
|
2009-08-07 04:41:43 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
|
|
if (result == GST_STATE_CHANGE_FAILURE)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
2009-08-07 12:41:31 +00:00
|
|
|
gst_adapter_clear (dec->adapter);
|
2009-08-07 04:41:43 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
plugin_init (GstPlugin * plugin)
|
|
|
|
{
|
2009-08-07 04:59:55 +00:00
|
|
|
return gst_element_register (plugin, "gmedec", GST_RANK_PRIMARY,
|
|
|
|
GST_TYPE_GME_DEC);
|
2009-08-07 04:41:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
2012-04-05 16:02:56 +00:00
|
|
|
gmedec,
|
2009-08-07 04:59:55 +00:00
|
|
|
"GME Audio Decoder",
|
2009-08-07 04:41:43 +00:00
|
|
|
plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
|