mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-22 14:06:23 +00:00
modplug: port to 0.11
This commit is contained in:
parent
20ffe99cc7
commit
9fcfa6046d
2 changed files with 256 additions and 230 deletions
|
@ -325,7 +325,7 @@ GST_PLUGINS_NONPORTED=" aiff asfmux \
|
|||
videomeasure videosignal vmnc \
|
||||
decklink fbdev linsys shm vcd \
|
||||
apexsink bz2 cdaudio celt cog curl dc1394 dirac directfb resindvd \
|
||||
gsettings jp2k ladspa modplug mimic \
|
||||
gsettings jp2k ladspa mimic \
|
||||
musepack musicbrainz nas neon ofa openal opencv rsvg schro sdl smooth sndfile soundtouch spandsp timidity \
|
||||
wildmidi xvid apple_media lv2 teletextdec opus dvb"
|
||||
AC_SUBST(GST_PLUGINS_NONPORTED)
|
||||
|
|
|
@ -91,30 +91,16 @@ enum
|
|||
#define DEFAULT_OVERSAMP TRUE
|
||||
#define DEFAULT_NOISE_REDUCTION TRUE
|
||||
|
||||
#define FORMATS "{ "GST_AUDIO_NE (S32)", "GST_AUDIO_NE (S16)", U8 }"
|
||||
|
||||
static GstStaticPadTemplate modplug_src_template_factory =
|
||||
GST_STATIC_PAD_TEMPLATE ("src",
|
||||
GST_PAD_SRC,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS ("audio/x-raw-int,"
|
||||
" endianness = (int) BYTE_ORDER,"
|
||||
" signed = (boolean) true,"
|
||||
" width = (int) 32,"
|
||||
" depth = (int) 32,"
|
||||
GST_STATIC_CAPS ("audio/x-raw,"
|
||||
" format = (string) " FORMATS ", "
|
||||
" layout = (string) interleaved, "
|
||||
" rate = (int) { 8000, 11025, 22050, 44100 },"
|
||||
" channels = (int) [ 1, 2 ]; "
|
||||
"audio/x-raw-int,"
|
||||
" endianness = (int) BYTE_ORDER,"
|
||||
" signed = (boolean) true,"
|
||||
" width = (int) 16,"
|
||||
" depth = (int) 16,"
|
||||
" rate = (int) { 8000, 11025, 22050, 44100 },"
|
||||
" channels = (int) [ 1, 2 ]; "
|
||||
"audio/x-raw-int,"
|
||||
" endianness = (int) BYTE_ORDER,"
|
||||
" signed = (boolean) false,"
|
||||
" width = (int) 8,"
|
||||
" depth = (int) 8,"
|
||||
" rate = (int) { 8000, 11025, 22050, 44100 }, "
|
||||
" channels = (int) [ 1, 2 ]"));
|
||||
|
||||
static GstStaticPadTemplate modplug_sink_template_factory =
|
||||
|
@ -130,36 +116,20 @@ static void gst_modplug_set_property (GObject * object,
|
|||
static void gst_modplug_get_property (GObject * object,
|
||||
guint id, GValue * value, GParamSpec * pspec);
|
||||
|
||||
static void gst_modplug_fixate (GstPad * pad, GstCaps * caps);
|
||||
static const GstQueryType *gst_modplug_get_query_types (GstPad * pad);
|
||||
static gboolean gst_modplug_src_event (GstPad * pad, GstEvent * event);
|
||||
static gboolean gst_modplug_src_query (GstPad * pad, GstQuery * query);
|
||||
static gboolean gst_modplug_src_event (GstPad * pad, GstObject * parent,
|
||||
GstEvent * event);
|
||||
static gboolean gst_modplug_src_query (GstPad * pad, GstObject * parent,
|
||||
GstQuery * query);
|
||||
static GstStateChangeReturn gst_modplug_change_state (GstElement * element,
|
||||
GstStateChange transition);
|
||||
|
||||
static gboolean gst_modplug_sinkpad_activate (GstPad * pad);
|
||||
static gboolean gst_modplug_sinkpad_activate_pull (GstPad * pad,
|
||||
gboolean active);
|
||||
static gboolean gst_modplug_sinkpad_activate (GstPad * pad, GstObject * parent);
|
||||
static gboolean gst_modplug_sinkpad_activate_mode (GstPad * pad,
|
||||
GstObject * parent, GstPadMode mode, gboolean active);
|
||||
static void gst_modplug_loop (GstModPlug * element);
|
||||
|
||||
GST_BOILERPLATE (GstModPlug, gst_modplug, GstElement, GST_TYPE_ELEMENT);
|
||||
|
||||
static void
|
||||
gst_modplug_base_init (gpointer g_class)
|
||||
{
|
||||
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
||||
|
||||
gst_element_class_add_pad_template (element_class,
|
||||
gst_static_pad_template_get (&modplug_sink_template_factory));
|
||||
gst_element_class_add_pad_template (element_class,
|
||||
gst_static_pad_template_get (&modplug_src_template_factory));
|
||||
|
||||
gst_element_class_set_details_simple (element_class, "ModPlug",
|
||||
"Codec/Decoder/Audio", "Module decoder based on modplug engine",
|
||||
"Jeremy SIMON <jsimon13@yahoo.fr>");
|
||||
|
||||
GST_DEBUG_CATEGORY_INIT (modplug_debug, "modplug", 0, "ModPlug element");
|
||||
}
|
||||
#define parent_class gst_modplug_parent_class
|
||||
G_DEFINE_TYPE (GstModPlug, gst_modplug, GST_TYPE_ELEMENT);
|
||||
|
||||
static void
|
||||
gst_modplug_class_init (GstModPlugClass * klass)
|
||||
|
@ -234,30 +204,37 @@ gst_modplug_class_init (GstModPlugClass * klass)
|
|||
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
|
||||
|
||||
gstelement_class->change_state = gst_modplug_change_state;
|
||||
|
||||
gst_element_class_add_pad_template (gstelement_class,
|
||||
gst_static_pad_template_get (&modplug_sink_template_factory));
|
||||
gst_element_class_add_pad_template (gstelement_class,
|
||||
gst_static_pad_template_get (&modplug_src_template_factory));
|
||||
|
||||
gst_element_class_set_details_simple (gstelement_class, "ModPlug",
|
||||
"Codec/Decoder/Audio", "Module decoder based on modplug engine",
|
||||
"Jeremy SIMON <jsimon13@yahoo.fr>");
|
||||
|
||||
GST_DEBUG_CATEGORY_INIT (modplug_debug, "modplug", 0, "ModPlug element");
|
||||
}
|
||||
|
||||
static void
|
||||
gst_modplug_init (GstModPlug * modplug, GstModPlugClass * klass)
|
||||
gst_modplug_init (GstModPlug * modplug)
|
||||
{
|
||||
/* create the sink and src pads */
|
||||
modplug->sinkpad =
|
||||
gst_pad_new_from_static_template (&modplug_sink_template_factory, "sink");
|
||||
gst_pad_set_activate_function (modplug->sinkpad,
|
||||
GST_DEBUG_FUNCPTR (gst_modplug_sinkpad_activate));
|
||||
gst_pad_set_activatepull_function (modplug->sinkpad,
|
||||
GST_DEBUG_FUNCPTR (gst_modplug_sinkpad_activate_pull));
|
||||
gst_pad_set_activatemode_function (modplug->sinkpad,
|
||||
GST_DEBUG_FUNCPTR (gst_modplug_sinkpad_activate_mode));
|
||||
gst_element_add_pad (GST_ELEMENT (modplug), modplug->sinkpad);
|
||||
|
||||
modplug->srcpad =
|
||||
gst_pad_new_from_static_template (&modplug_src_template_factory, "src");
|
||||
gst_pad_set_fixatecaps_function (modplug->srcpad,
|
||||
GST_DEBUG_FUNCPTR (gst_modplug_fixate));
|
||||
gst_pad_set_event_function (modplug->srcpad,
|
||||
GST_DEBUG_FUNCPTR (gst_modplug_src_event));
|
||||
gst_pad_set_query_function (modplug->srcpad,
|
||||
GST_DEBUG_FUNCPTR (gst_modplug_src_query));
|
||||
gst_pad_set_query_type_function (modplug->srcpad,
|
||||
GST_DEBUG_FUNCPTR (gst_modplug_get_query_types));
|
||||
gst_element_add_pad (GST_ELEMENT (modplug), modplug->srcpad);
|
||||
|
||||
modplug->reverb = DEFAULT_REVERB;
|
||||
|
@ -291,35 +268,22 @@ gst_modplug_dispose (GObject * object)
|
|||
}
|
||||
}
|
||||
|
||||
static const GstQueryType *
|
||||
gst_modplug_get_query_types (GstPad * pad)
|
||||
{
|
||||
static const GstQueryType gst_modplug_src_query_types[] = {
|
||||
GST_QUERY_DURATION,
|
||||
GST_QUERY_POSITION,
|
||||
(GstQueryType) 0
|
||||
};
|
||||
|
||||
return gst_modplug_src_query_types;
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
gst_modplug_src_query (GstPad * pad, GstQuery * query)
|
||||
gst_modplug_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
|
||||
{
|
||||
GstModPlug *modplug;
|
||||
gboolean res = FALSE;
|
||||
|
||||
modplug = GST_MODPLUG (gst_pad_get_parent (pad));
|
||||
|
||||
if (!modplug->mSoundFile)
|
||||
goto done;
|
||||
modplug = GST_MODPLUG (parent);
|
||||
|
||||
switch (GST_QUERY_TYPE (query)) {
|
||||
case GST_QUERY_DURATION:
|
||||
{
|
||||
GstFormat format;
|
||||
|
||||
if (!modplug->mSoundFile)
|
||||
goto done;
|
||||
|
||||
gst_query_parse_duration (query, &format, NULL);
|
||||
if (format == GST_FORMAT_TIME) {
|
||||
gst_query_set_duration (query, format, modplug->song_length);
|
||||
|
@ -331,6 +295,9 @@ gst_modplug_src_query (GstPad * pad, GstQuery * query)
|
|||
{
|
||||
GstFormat format;
|
||||
|
||||
if (!modplug->mSoundFile)
|
||||
goto done;
|
||||
|
||||
gst_query_parse_position (query, &format, NULL);
|
||||
if (format == GST_FORMAT_TIME) {
|
||||
gint64 pos;
|
||||
|
@ -343,158 +310,181 @@ gst_modplug_src_query (GstPad * pad, GstQuery * query)
|
|||
}
|
||||
break;
|
||||
default:
|
||||
res = gst_pad_query_default (pad, query);
|
||||
res = gst_pad_query_default (pad, parent, query);
|
||||
break;
|
||||
}
|
||||
|
||||
done:
|
||||
gst_object_unref (modplug);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_modplug_src_event (GstPad * pad, GstEvent * event)
|
||||
gst_modplug_do_seek (GstModPlug * modplug, GstEvent * event)
|
||||
{
|
||||
gdouble rate;
|
||||
GstFormat format;
|
||||
GstSeekFlags flags;
|
||||
GstSeekType cur_type, stop_type;
|
||||
gboolean flush;
|
||||
gint64 cur, stop;
|
||||
GstSegment seg;
|
||||
/* FIXME timestamp is set but not used */
|
||||
#if 0
|
||||
guint64 timestamp;
|
||||
#endif
|
||||
|
||||
if (modplug->frequency == 0)
|
||||
goto no_song;
|
||||
|
||||
#if 0
|
||||
timestamp = gst_util_uint64_scale_int (modplug->offset, GST_SECOND,
|
||||
modplug->frequency);
|
||||
#endif
|
||||
|
||||
gst_event_parse_seek (event, &rate, &format, &flags,
|
||||
&cur_type, &cur, &stop_type, &stop);
|
||||
|
||||
if (format != GST_FORMAT_TIME)
|
||||
goto no_time;
|
||||
|
||||
/* FIXME: we should be using GstSegment for all this */
|
||||
if (cur_type != GST_SEEK_TYPE_SET || stop_type != GST_SEEK_TYPE_NONE)
|
||||
goto not_supported;
|
||||
|
||||
if (stop_type == GST_SEEK_TYPE_NONE)
|
||||
stop = GST_CLOCK_TIME_NONE;
|
||||
|
||||
cur = CLAMP (cur, 0, modplug->song_length);
|
||||
|
||||
GST_DEBUG_OBJECT (modplug, "seek to %" GST_TIME_FORMAT,
|
||||
GST_TIME_ARGS ((guint64) cur));
|
||||
|
||||
modplug->seek_at = cur;
|
||||
|
||||
flush = ((flags & GST_SEEK_FLAG_FLUSH) == GST_SEEK_FLAG_FLUSH);
|
||||
|
||||
if (flush) {
|
||||
gst_pad_push_event (modplug->srcpad, gst_event_new_flush_start ());
|
||||
} else {
|
||||
gst_pad_stop_task (modplug->sinkpad);
|
||||
}
|
||||
|
||||
GST_PAD_STREAM_LOCK (modplug->sinkpad);
|
||||
|
||||
if (flags & GST_SEEK_FLAG_SEGMENT) {
|
||||
gst_element_post_message (GST_ELEMENT (modplug),
|
||||
gst_message_new_segment_start (GST_OBJECT (modplug), format, cur));
|
||||
}
|
||||
if (stop == -1 && modplug->song_length > 0)
|
||||
stop = modplug->song_length;
|
||||
|
||||
if (flush) {
|
||||
gst_pad_push_event (modplug->srcpad, gst_event_new_flush_stop (TRUE));
|
||||
}
|
||||
|
||||
GST_LOG_OBJECT (modplug, "sending newsegment from %" GST_TIME_FORMAT "-%"
|
||||
GST_TIME_FORMAT ", pos=%" GST_TIME_FORMAT,
|
||||
GST_TIME_ARGS ((guint64) cur), GST_TIME_ARGS ((guint64) stop),
|
||||
GST_TIME_ARGS ((guint64) cur));
|
||||
|
||||
gst_segment_init (&seg, GST_FORMAT_TIME);
|
||||
seg.rate = rate;
|
||||
seg.start = cur;
|
||||
seg.stop = stop;
|
||||
seg.time = cur;
|
||||
gst_pad_push_event (modplug->srcpad, gst_event_new_segment (&seg));
|
||||
|
||||
modplug->offset =
|
||||
gst_util_uint64_scale_int (cur, modplug->frequency, GST_SECOND);
|
||||
|
||||
gst_pad_start_task (modplug->sinkpad,
|
||||
(GstTaskFunction) gst_modplug_loop, modplug);
|
||||
|
||||
GST_PAD_STREAM_UNLOCK (modplug->sinkpad);
|
||||
|
||||
return TRUE;
|
||||
|
||||
/* ERROR */
|
||||
no_song:
|
||||
{
|
||||
GST_DEBUG_OBJECT (modplug, "no song loaded yet");
|
||||
return FALSE;
|
||||
}
|
||||
no_time:
|
||||
{
|
||||
GST_DEBUG_OBJECT (modplug, "seeking is only supported in TIME format");
|
||||
return FALSE;
|
||||
}
|
||||
not_supported:
|
||||
{
|
||||
GST_DEBUG_OBJECT (modplug, "unsupported seek type");
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_modplug_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
|
||||
{
|
||||
GstModPlug *modplug;
|
||||
gboolean res = FALSE;
|
||||
|
||||
modplug = GST_MODPLUG (gst_pad_get_parent (pad));
|
||||
modplug = GST_MODPLUG (parent);
|
||||
|
||||
switch (GST_EVENT_TYPE (event)) {
|
||||
case GST_EVENT_SEEK:
|
||||
{
|
||||
gdouble rate;
|
||||
GstFormat format;
|
||||
GstSeekFlags flags;
|
||||
GstSeekType cur_type, stop_type;
|
||||
gboolean flush;
|
||||
gint64 cur, stop;
|
||||
/* FIXME timestamp is set but not used */
|
||||
#if 0
|
||||
guint64 timestamp;
|
||||
#endif
|
||||
|
||||
if (modplug->frequency == 0) {
|
||||
GST_DEBUG_OBJECT (modplug, "no song loaded yet");
|
||||
break;
|
||||
}
|
||||
|
||||
#if 0
|
||||
timestamp = gst_util_uint64_scale_int (modplug->offset, GST_SECOND,
|
||||
modplug->frequency);
|
||||
#endif
|
||||
|
||||
gst_event_parse_seek (event, &rate, &format, &flags,
|
||||
&cur_type, &cur, &stop_type, &stop);
|
||||
|
||||
if (format != GST_FORMAT_TIME) {
|
||||
GST_DEBUG_OBJECT (modplug, "seeking is only supported in TIME format");
|
||||
gst_event_unref (event);
|
||||
break;
|
||||
}
|
||||
|
||||
/* FIXME: we should be using GstSegment for all this */
|
||||
if (cur_type != GST_SEEK_TYPE_SET || stop_type != GST_SEEK_TYPE_NONE) {
|
||||
GST_DEBUG_OBJECT (modplug, "unsupported seek type");
|
||||
gst_event_unref (event);
|
||||
break;
|
||||
}
|
||||
|
||||
if (stop_type == GST_SEEK_TYPE_NONE)
|
||||
stop = GST_CLOCK_TIME_NONE;
|
||||
|
||||
cur = CLAMP (cur, 0, modplug->song_length);
|
||||
|
||||
GST_DEBUG_OBJECT (modplug, "seek to %" GST_TIME_FORMAT,
|
||||
GST_TIME_ARGS ((guint64) cur));
|
||||
|
||||
modplug->seek_at = cur;
|
||||
|
||||
flush = ((flags & GST_SEEK_FLAG_FLUSH) == GST_SEEK_FLAG_FLUSH);
|
||||
|
||||
if (flush) {
|
||||
gst_pad_push_event (modplug->srcpad, gst_event_new_flush_start ());
|
||||
} else {
|
||||
gst_pad_stop_task (modplug->sinkpad);
|
||||
}
|
||||
|
||||
GST_PAD_STREAM_LOCK (modplug->sinkpad);
|
||||
|
||||
if (flags & GST_SEEK_FLAG_SEGMENT) {
|
||||
gst_element_post_message (GST_ELEMENT (modplug),
|
||||
gst_message_new_segment_start (GST_OBJECT (modplug), format, cur));
|
||||
}
|
||||
if (stop == -1 && modplug->song_length > 0)
|
||||
stop = modplug->song_length;
|
||||
|
||||
if (flush) {
|
||||
gst_pad_push_event (modplug->srcpad, gst_event_new_flush_stop ());
|
||||
}
|
||||
|
||||
GST_LOG_OBJECT (modplug, "sending newsegment from %" GST_TIME_FORMAT "-%"
|
||||
GST_TIME_FORMAT ", pos=%" GST_TIME_FORMAT,
|
||||
GST_TIME_ARGS ((guint64) cur), GST_TIME_ARGS ((guint64) stop),
|
||||
GST_TIME_ARGS ((guint64) cur));
|
||||
|
||||
gst_pad_push_event (modplug->srcpad,
|
||||
gst_event_new_new_segment (FALSE, rate,
|
||||
GST_FORMAT_TIME, cur, stop, cur));
|
||||
|
||||
modplug->offset =
|
||||
gst_util_uint64_scale_int (cur, modplug->frequency, GST_SECOND);
|
||||
|
||||
gst_pad_start_task (modplug->sinkpad,
|
||||
(GstTaskFunction) gst_modplug_loop, modplug);
|
||||
|
||||
GST_PAD_STREAM_UNLOCK (modplug->sinkpad);
|
||||
res = TRUE;
|
||||
res = gst_modplug_do_seek (modplug, event);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
res = gst_pad_event_default (pad, event);
|
||||
res = gst_pad_event_default (pad, parent, event);
|
||||
break;
|
||||
}
|
||||
|
||||
gst_object_unref (modplug);
|
||||
return res;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_modplug_fixate (GstPad * pad, GstCaps * caps)
|
||||
{
|
||||
GstStructure *structure;
|
||||
|
||||
structure = gst_caps_get_structure (caps, 0);
|
||||
if (!gst_structure_fixate_field_nearest_int (structure, "rate", 44100))
|
||||
GST_WARNING_OBJECT (pad, "Failed to fixate rate to 44100");
|
||||
if (!gst_structure_fixate_field_nearest_int (structure, "channels", 2))
|
||||
GST_WARNING_OBJECT (pad, "Failed to fixate number of channels to stereo");
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_modplug_load_song (GstModPlug * modplug)
|
||||
{
|
||||
GstCaps *newcaps, *othercaps;
|
||||
GstCaps *newcaps;
|
||||
GstStructure *structure;
|
||||
GstMapInfo map;
|
||||
const gchar * format;
|
||||
|
||||
GST_DEBUG_OBJECT (modplug, "Setting caps");
|
||||
|
||||
/* negotiate srcpad caps */
|
||||
if ((othercaps = gst_pad_get_allowed_caps (modplug->srcpad))) {
|
||||
newcaps = gst_caps_copy_nth (othercaps, 0);
|
||||
gst_caps_unref (othercaps);
|
||||
} else {
|
||||
GST_WARNING ("no allowed caps on srcpad, no peer linked");
|
||||
/* FIXME: this can be done in a better way */
|
||||
newcaps =
|
||||
gst_caps_copy_nth (gst_pad_get_pad_template_caps (modplug->srcpad), 0);
|
||||
if ((newcaps = gst_pad_get_allowed_caps (modplug->srcpad)) == NULL) {
|
||||
newcaps = gst_pad_get_pad_template_caps (modplug->srcpad);
|
||||
}
|
||||
gst_pad_fixate_caps (modplug->srcpad, newcaps);
|
||||
newcaps = gst_caps_make_writable (newcaps);
|
||||
|
||||
GST_DEBUG_OBJECT (modplug, "allowed caps %"GST_PTR_FORMAT, newcaps);
|
||||
|
||||
structure = gst_caps_get_structure (newcaps, 0);
|
||||
|
||||
if (!gst_structure_fixate_field_string (structure, "format", GST_AUDIO_NE (S16)))
|
||||
GST_WARNING_OBJECT (modplug, "Failed to fixate format to S16NE");
|
||||
if (!gst_structure_fixate_field_nearest_int (structure, "rate", 44100))
|
||||
GST_WARNING_OBJECT (modplug, "Failed to fixate rate to 44100");
|
||||
if (!gst_structure_fixate_field_nearest_int (structure, "channels", 2))
|
||||
GST_WARNING_OBJECT (modplug, "Failed to fixate number of channels to stereo");
|
||||
|
||||
GST_DEBUG_OBJECT (modplug, "normalized caps %"GST_PTR_FORMAT, newcaps);
|
||||
|
||||
gst_caps_fixate (newcaps);
|
||||
|
||||
GST_DEBUG_OBJECT (modplug, "fixated caps %"GST_PTR_FORMAT, newcaps);
|
||||
|
||||
/* set up modplug to output the negotiated format */
|
||||
structure = gst_caps_get_structure (newcaps, 0);
|
||||
gst_structure_get_int (structure, "depth", &modplug->bits);
|
||||
format = gst_structure_get_string (structure, "format");
|
||||
|
||||
if (g_str_equal (format, GST_AUDIO_NE (S32)))
|
||||
modplug->bits = 32;
|
||||
else if (g_str_equal (format, GST_AUDIO_NE (S16)))
|
||||
modplug->bits = 16;
|
||||
else
|
||||
modplug->bits = 8;
|
||||
|
||||
gst_structure_get_int (structure, "channels", &modplug->channel);
|
||||
gst_structure_get_int (structure, "rate", &modplug->frequency);
|
||||
|
||||
|
@ -528,12 +518,11 @@ gst_modplug_load_song (GstModPlug * modplug)
|
|||
modplug->mSoundFile->SetReverbParameters (modplug->reverb_depth,
|
||||
modplug->reverb_delay);
|
||||
|
||||
if (!modplug->mSoundFile->Create (GST_BUFFER_DATA (modplug->buffer),
|
||||
modplug->song_size)) {
|
||||
GST_ELEMENT_ERROR (modplug, STREAM, DECODE, (NULL),
|
||||
("Unable to load song"));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gst_buffer_map (modplug->buffer, &map, GST_MAP_READ);
|
||||
if (!modplug->mSoundFile->Create (map.data, modplug->song_size))
|
||||
goto load_error;
|
||||
gst_buffer_unmap (modplug->buffer, &map);
|
||||
|
||||
modplug->song_length = modplug->mSoundFile->GetSongTime () * GST_SECOND;
|
||||
modplug->seek_at = -1;
|
||||
|
@ -542,34 +531,75 @@ gst_modplug_load_song (GstModPlug * modplug)
|
|||
GST_TIME_ARGS ((guint64) modplug->song_length));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_modplug_sinkpad_activate (GstPad * pad)
|
||||
{
|
||||
if (!gst_pad_check_pull_range (pad))
|
||||
/* ERRORS */
|
||||
load_error:
|
||||
{
|
||||
gst_buffer_unmap (modplug->buffer, &map);
|
||||
GST_ELEMENT_ERROR (modplug, STREAM, DECODE, (NULL),
|
||||
("Unable to load song"));
|
||||
return FALSE;
|
||||
|
||||
return gst_pad_activate_pull (pad, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_modplug_sinkpad_activate_pull (GstPad * pad, gboolean active)
|
||||
gst_modplug_sinkpad_activate (GstPad * sinkpad, GstObject * parent)
|
||||
{
|
||||
GstModPlug *modplug = GST_MODPLUG (GST_OBJECT_PARENT (pad));
|
||||
GstQuery *query;
|
||||
gboolean pull_mode;
|
||||
|
||||
if (active) {
|
||||
return gst_pad_start_task (pad, (GstTaskFunction) gst_modplug_loop,
|
||||
modplug);
|
||||
} else {
|
||||
return gst_pad_stop_task (pad);
|
||||
query = gst_query_new_scheduling ();
|
||||
|
||||
if (!gst_pad_peer_query (sinkpad, query)) {
|
||||
gst_query_unref (query);
|
||||
goto activate_push;
|
||||
}
|
||||
|
||||
pull_mode = gst_query_has_scheduling_mode (query, GST_PAD_MODE_PULL);
|
||||
gst_query_unref (query);
|
||||
|
||||
if (!pull_mode)
|
||||
goto activate_push;
|
||||
|
||||
GST_DEBUG_OBJECT (sinkpad, "activating pull");
|
||||
return gst_pad_activate_mode (sinkpad, GST_PAD_MODE_PULL, TRUE);
|
||||
|
||||
activate_push:
|
||||
{
|
||||
GST_DEBUG_OBJECT (sinkpad, "activating push");
|
||||
return gst_pad_activate_mode (sinkpad, GST_PAD_MODE_PUSH, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_modplug_sinkpad_activate_mode (GstPad * pad, GstObject * parent,
|
||||
GstPadMode mode, gboolean active)
|
||||
{
|
||||
GstModPlug *modplug = GST_MODPLUG (parent);
|
||||
gboolean res;
|
||||
|
||||
switch (mode) {
|
||||
case GST_PAD_MODE_PUSH:
|
||||
res = TRUE;
|
||||
break;
|
||||
case GST_PAD_MODE_PULL:
|
||||
if (active) {
|
||||
res = gst_pad_start_task (pad, (GstTaskFunction) gst_modplug_loop,
|
||||
modplug);
|
||||
} else {
|
||||
res = gst_pad_stop_task (pad);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
res = FALSE;
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_modplug_get_upstream_size (GstModPlug * modplug, gint64 * length)
|
||||
{
|
||||
GstFormat format = GST_FORMAT_BYTES;
|
||||
gboolean res = FALSE;
|
||||
GstPad *peer;
|
||||
|
||||
|
@ -577,7 +607,7 @@ gst_modplug_get_upstream_size (GstModPlug * modplug, gint64 * length)
|
|||
if (peer == NULL)
|
||||
return FALSE;
|
||||
|
||||
if (gst_pad_query_duration (peer, &format, length) && *length >= 0) {
|
||||
if (gst_pad_query_duration (peer, GST_FORMAT_BYTES, length) && *length >= 0) {
|
||||
res = TRUE;
|
||||
}
|
||||
|
||||
|
@ -590,6 +620,7 @@ gst_modplug_loop (GstModPlug * modplug)
|
|||
{
|
||||
GstFlowReturn flow;
|
||||
GstBuffer *out = NULL;
|
||||
GstMapInfo map;
|
||||
|
||||
g_assert (GST_IS_MODPLUG (modplug));
|
||||
|
||||
|
@ -626,18 +657,19 @@ gst_modplug_loop (GstModPlug * modplug)
|
|||
}
|
||||
|
||||
/* GST_LOG_OBJECT (modplug, "Read %u bytes", GST_BUFFER_SIZE (buffer)); */
|
||||
g_memmove (GST_BUFFER_DATA (modplug->buffer) + modplug->offset,
|
||||
GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer));
|
||||
gst_buffer_map (buffer, &map, GST_MAP_READ);
|
||||
gst_buffer_fill (modplug->buffer, modplug->offset, map.data, map.size);
|
||||
gst_buffer_unmap (buffer, &map);
|
||||
gst_buffer_unref (buffer);
|
||||
|
||||
modplug->offset += read_size;
|
||||
|
||||
/* actually load it */
|
||||
if (modplug->offset == modplug->song_size) {
|
||||
GstEvent *newsegment;
|
||||
GstTagList *tags;
|
||||
gboolean ok;
|
||||
gchar comment[16384];
|
||||
GstSegment seg;
|
||||
|
||||
ok = gst_modplug_load_song (modplug);
|
||||
gst_buffer_unref (modplug->buffer);
|
||||
|
@ -648,12 +680,12 @@ gst_modplug_loop (GstModPlug * modplug)
|
|||
goto pause;
|
||||
}
|
||||
|
||||
newsegment = gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME,
|
||||
0, modplug->song_length, 0);
|
||||
gst_pad_push_event (modplug->srcpad, newsegment);
|
||||
gst_segment_init (&seg, GST_FORMAT_TIME);
|
||||
seg.stop = modplug->song_length;
|
||||
gst_pad_push_event (modplug->srcpad, gst_event_new_segment (&seg));
|
||||
|
||||
/* get and send metadata */
|
||||
tags = gst_tag_list_new ();
|
||||
tags = gst_tag_list_new_empty ();
|
||||
gst_tag_list_add (tags, GST_TAG_MERGE_APPEND,
|
||||
GST_TAG_TITLE, modplug->mSoundFile->GetTitle (),
|
||||
GST_TAG_BEATS_PER_MINUTE,
|
||||
|
@ -663,9 +695,7 @@ gst_modplug_loop (GstModPlug * modplug)
|
|||
gst_tag_list_add (tags, GST_TAG_MERGE_APPEND,
|
||||
GST_TAG_COMMENT, comment, NULL);
|
||||
}
|
||||
|
||||
|
||||
gst_element_found_tags (GST_ELEMENT (modplug), tags);
|
||||
gst_pad_push_event (modplug->srcpad, gst_event_new_tag (tags));
|
||||
} else {
|
||||
/* not fully loaded yet */
|
||||
return;
|
||||
|
@ -688,19 +718,15 @@ gst_modplug_loop (GstModPlug * modplug)
|
|||
}
|
||||
|
||||
/* read and output a buffer */
|
||||
flow = gst_pad_alloc_buffer_and_set_caps (modplug->srcpad,
|
||||
GST_BUFFER_OFFSET_NONE, modplug->read_bytes,
|
||||
GST_PAD_CAPS (modplug->srcpad), &out);
|
||||
out = gst_buffer_new_allocate (NULL, modplug->read_bytes, 0);
|
||||
|
||||
if (flow != GST_FLOW_OK) {
|
||||
GST_LOG_OBJECT (modplug, "pad alloc flow: %s", gst_flow_get_name (flow));
|
||||
goto pause;
|
||||
}
|
||||
|
||||
if (!modplug->mSoundFile->Read (GST_BUFFER_DATA (out), modplug->read_bytes))
|
||||
gst_buffer_map (out, &map, GST_MAP_WRITE);
|
||||
if (!modplug->mSoundFile->Read (map.data, modplug->read_bytes)) {
|
||||
gst_buffer_unmap (out, &map);
|
||||
goto eos;
|
||||
}
|
||||
gst_buffer_unmap (out, &map);
|
||||
|
||||
GST_BUFFER_SIZE (out) = modplug->read_bytes;
|
||||
GST_BUFFER_DURATION (out) =
|
||||
gst_util_uint64_scale_int (modplug->read_samples, GST_SECOND,
|
||||
modplug->frequency);
|
||||
|
|
Loading…
Reference in a new issue