made the autoplug test work properly with SMIL files

This commit is contained in:
maroy 2005-06-27 14:31:06 +00:00
parent 9aebbbb938
commit d4557842f6
8 changed files with 109 additions and 58 deletions

View file

@ -23,11 +23,11 @@
Author : $Author: maroy $
Version : $Revision: 1.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/gstreamerElements/src/Attic/autoplug.h,v $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/gstreamerElements/include/LiveSupport/GstreamerElements/autoplug.h,v $
------------------------------------------------------------------------------*/
#ifndef Audioplug_h
#define Audioplug_h
#ifndef LiveSupport_GstreamerElements_Autoplug_h
#define LiveSupport_GstreamerElements_Autoplug_h
/**
* @file
@ -64,17 +64,19 @@ extern "C" {
* source, and produces raw audio on its src pad as it output.
*
* @param source the source to autoplug.
* @param name the name of the new element.
* @return a gstreamer element already linked to source, that produces
* the audio provided by source in audio/x-raw-int or
* audio/x-raw-float format, as needed.
*/
GstElement *
autoplug_plug_source(GstElement * source);
ls_gst_autoplug_plug_source(GstElement * source,
const gchar * name);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* Audioplug_h */
#endif /* LiveSupport_GstreamerElements_Autoplug_h */

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.3 $
Version : $Revision: 1.4 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/gstreamerElements/src/AutoplugTest.cxx,v $
------------------------------------------------------------------------------*/
@ -38,7 +38,7 @@
#include <gst/gst.h>
#include "autoplug.h"
#include "LiveSupport/GstreamerElements/autoplug.h"
#include "AutoplugTest.h"
@ -119,7 +119,7 @@ AutoplugTest :: playFile(const char * audioFile)
g_object_set(G_OBJECT(source), "location", audioFile, NULL);
decoder = autoplug_plug_source(source);
decoder = ls_gst_autoplug_plug_source(source, "decoder");
if (!decoder) {
gst_object_unref(GST_OBJECT(sink));
@ -132,11 +132,10 @@ AutoplugTest :: playFile(const char * audioFile)
gst_element_link(decoder, sink);
gst_bin_add_many(GST_BIN(pipeline), source, decoder, sink, NULL);
gst_element_set_state(source, GST_STATE_PAUSED);
gst_element_set_state(source, GST_STATE_PLAYING);
gst_element_set_state(decoder, GST_STATE_PAUSED);
gst_element_set_state(sink, GST_STATE_PAUSED);
gst_element_set_state(pipeline, GST_STATE_PLAYING);
gst_bin_sync_children_state(GST_BIN(pipeline));
// iterate until playTo is reached
while (gst_bin_iterate(GST_BIN(pipeline)));

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.1 $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/gstreamerElements/src/SeekPackTest.cxx,v $
------------------------------------------------------------------------------*/
@ -177,13 +177,15 @@ SeekPackTest :: firstTest(void)
throw (CPPUNIT_NS::Exception)
{
gint64 timePlayed;
char str[256];
timePlayed = playFile(testFile,
2LL * GST_SECOND,
1LL * GST_SECOND,
3LL * GST_SECOND);
CPPUNIT_ASSERT(timePlayed > 3.9 * GST_SECOND);
CPPUNIT_ASSERT(timePlayed < 4.1 * GST_SECOND);
g_snprintf(str, 256, "time played: %" G_GINT64_FORMAT, timePlayed);
CPPUNIT_ASSERT_MESSAGE(str, timePlayed > 3.9 * GST_SECOND);
CPPUNIT_ASSERT_MESSAGE(str, timePlayed < 4.1 * GST_SECOND);
}
@ -195,13 +197,15 @@ SeekPackTest :: noSilenceTest(void)
throw (CPPUNIT_NS::Exception)
{
gint64 timePlayed;
char str[256];
timePlayed = playFile(testFile,
0LL * GST_SECOND,
1LL * GST_SECOND,
3LL * GST_SECOND);
CPPUNIT_ASSERT(timePlayed > 1.9 * GST_SECOND);
CPPUNIT_ASSERT(timePlayed < 2.1 * GST_SECOND);
g_snprintf(str, 256, "time played: %" G_GINT64_FORMAT, timePlayed);
CPPUNIT_ASSERT_MESSAGE(str, timePlayed > 1.9 * GST_SECOND);
CPPUNIT_ASSERT_MESSAGE(str, timePlayed < 2.1 * GST_SECOND);
}
@ -213,12 +217,14 @@ SeekPackTest :: openEndedTest(void)
throw (CPPUNIT_NS::Exception)
{
gint64 timePlayed;
char str[256];
timePlayed = playFile(testFile,
2LL * GST_SECOND,
1LL * GST_SECOND,
-1LL);
CPPUNIT_ASSERT(timePlayed > 5.9 * GST_SECOND);
CPPUNIT_ASSERT(timePlayed < 6.1 * GST_SECOND);
g_snprintf(str, 256, "time played: %" G_GINT64_FORMAT, timePlayed);
CPPUNIT_ASSERT_MESSAGE(str, timePlayed > 5.9 * GST_SECOND);
CPPUNIT_ASSERT_MESSAGE(str, timePlayed < 6.1 * GST_SECOND);
}

View file

@ -27,7 +27,7 @@
Author : $Author: maroy $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/gstreamerElements/src/autoplug.c,v $
------------------------------------------------------------------------------*/
@ -36,7 +36,7 @@
#include <gst/gst.h>
#include "autoplug.h"
#include "LiveSupport/GstreamerElements/autoplug.h"
/* =================================================== local data structures */
@ -102,9 +102,12 @@ autoplug_typefound_handler(GstElement * typefind,
* Initialize a typefind object.
*
* @param typefind the Typefind structure to init.
* @param name the name of the topmost bin element, that will
* be returned at the end of autoplugging.
*/
static void
autoplug_init(Typefind * typefind);
autoplug_init(Typefind * typefind,
const gchar * name);
/**
* De-initialize a typefind object.
@ -247,7 +250,8 @@ autoplug_compare_ranks(GstPluginFeature * feature1,
* Initialize a Typefind object, like the factories that we care about.
*----------------------------------------------------------------------------*/
static void
autoplug_init(Typefind * typefind)
autoplug_init(Typefind * typefind,
const gchar * name)
{
/* first filter out the interesting element factories */
typefind->factories = gst_registry_pool_feature_filter(
@ -259,7 +263,7 @@ autoplug_init(Typefind * typefind)
(GCompareFunc) autoplug_compare_ranks);
typefind->pipeline = gst_pipeline_new("pipeline");
typefind->bin = gst_bin_new("bin");
typefind->bin = gst_bin_new(name);
typefind->typefind = gst_element_factory_make("typefind", "tf");
typefind->audiosink = gst_element_factory_make("audioconvert", "audiosink");
typefind->sink = gst_element_factory_make("fakesink", "fakesink");
@ -297,6 +301,7 @@ autoplug_deinit(Typefind * typefind)
{
g_list_free(typefind->factories);
gst_element_set_state(typefind->pipeline, GST_STATE_NULL);
if (typefind->typefind) {
g_signal_handler_disconnect(typefind->typefind,
typefind->typefindSignal);
@ -654,7 +659,8 @@ autoplug_remove_typefind_elements(Typefind * typefind,
* Filter the features that we're interested in.
*----------------------------------------------------------------------------*/
GstElement *
autoplug_plug_source(GstElement * source)
ls_gst_autoplug_plug_source(GstElement * source,
const gchar * name)
{
Typefind typefind;
GstElement * bin;
@ -664,7 +670,7 @@ autoplug_plug_source(GstElement * source)
g_object_ref(source);
typefind.source = source;
autoplug_init(&typefind);
autoplug_init(&typefind, name);
gst_element_set_state(typefind.audiosink, GST_STATE_PAUSED);
gst_element_set_state(typefind.sink, GST_STATE_PAUSED);
@ -679,19 +685,23 @@ autoplug_plug_source(GstElement * source)
return NULL;
}
/* remove the source element from the pipeline */
gst_bin_remove(GST_BIN(typefind.pipeline), typefind.source);
gst_element_unlink(typefind.source, typefind.bin);
/* remove the sink element */
gst_element_unlink(typefind.bin, typefind.sink);
gst_bin_remove(GST_BIN(typefind.pipeline), typefind.sink);
typefind.sink = NULL;
/* remove the typefind elements, and re-link with the source */
autoplug_remove_typefind_elements(&typefind, GST_BIN(typefind.bin));
gst_element_link(typefind.source, typefind.bin);
/* destory the pipeline, but keep source and bin */
g_object_ref(typefind.bin);
gst_bin_remove(GST_BIN(typefind.pipeline), typefind.bin);
/* remove the typefind elements, and re-link with the source */
autoplug_remove_typefind_elements(&typefind, GST_BIN(typefind.bin));
gst_element_link(typefind.source, typefind.bin);
bin = typefind.bin;
autoplug_deinit(&typefind);

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/gstreamerElements/src/minimal-audio-smil.c,v $
------------------------------------------------------------------------------*/
@ -110,7 +110,7 @@ GST_PLUGIN_DEFINE(GST_VERSION_MAJOR,
"minimalaudiosmil",
"Minimal Audio-only SMIL",
plugin_init,
"$Revision: 1.2 $",
"$Revision: 1.3 $",
"GPL",
"LiveSupport",
"http://livesupport.campware.org/")
@ -248,10 +248,13 @@ read_stream_into_memory(LivesupportMinimalAudioSmil * smil,
g_object_get(G_OBJECT(smil->oneshotReader), "length", &length, NULL);
g_object_get(G_OBJECT(smil->oneshotReader), "contents", &buffer, NULL);
gst_element_set_state(smil->oneshotReader, oldState);
if (!length) {
return;
}
*outbuffer = buffer;
*outbuffer = g_malloc(length);
*outlength = length;
memcpy(*outbuffer, buffer, length);
}
@ -431,7 +434,7 @@ handle_par_element(LivesupportMinimalAudioSmil * smil,
/*------------------------------------------------------------------------------
* Process the sink input as a SMIL file.
*----------------------------------------------------------------------------*/
e*----------------------------------------------------------------------------*/
static gboolean
process_smil_file(LivesupportMinimalAudioSmil * smil)
{
@ -440,6 +443,12 @@ process_smil_file(LivesupportMinimalAudioSmil * smil)
xmlDocPtr document;
xmlNode * node;
if (smil->fileProcessed) {
return TRUE;
}
smil->fileProcessed = TRUE;
if (!GST_PAD_IS_LINKED(smil->sinkpad)) {
return FALSE;
}
@ -447,12 +456,14 @@ process_smil_file(LivesupportMinimalAudioSmil * smil)
/* read the source document into memory */
read_stream_into_memory(smil, &buffer, &length);
if (!buffer) {
smil->fileProcessed = FALSE;
return FALSE;
}
/* parse the XML files */
document = xmlReadMemory((const char *) buffer,
length, "noname.xml", NULL, 0);
g_free(buffer);
if (!document
|| !(node = get_body_element(document))) {
GST_ELEMENT_ERROR(GST_ELEMENT(smil),
@ -515,17 +526,13 @@ livesupport_minimal_audio_smil_change_state(GstElement * element)
case GST_STATE_PAUSED_TO_PLAYING:
gst_element_set_state(GST_ELEMENT(smil->bin), GST_STATE_PLAYING);
if (!smil->fileProcessed) {
/* set to true, in case of multiple change events */
smil->fileProcessed = TRUE;
if (!(smil->fileProcessed = process_smil_file(smil))) {
if (!process_smil_file(smil)) {
GST_ELEMENT_ERROR(GST_ELEMENT(smil),
STREAM,
WRONG_TYPE,
("unable to process SMIL file"),
(NULL));
}
}
break;

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/gstreamerElements/src/oneshot-reader.c,v $
------------------------------------------------------------------------------*/
@ -93,7 +93,7 @@ GST_PLUGIN_DEFINE(GST_VERSION_MAJOR,
"oneshotreaderplugin",
"A reader that reads all of the input on one go",
plugin_init,
"$Revision: 1.2 $",
"$Revision: 1.3 $",
"GPL",
"LiveSupport",
"http://livesupport.campware.org/")
@ -218,6 +218,7 @@ read_stream_into_memory(LivesupportOneShotReader * reader,
guint32 length;
guint32 read;
guint8 * buffer;
gboolean ret;
*outbuffer = 0;
*outlength = 0;
@ -231,6 +232,9 @@ read_stream_into_memory(LivesupportOneShotReader * reader,
return;
}
/* seek to the beginning, to make sure... */
gst_bytestream_seek(reader->bytestream, 0LL, GST_SEEK_METHOD_SET);
length = (guint32) gst_bytestream_length(reader->bytestream);
buffer = g_malloc(length + 1);
read = 0;
@ -268,6 +272,9 @@ read_stream_into_memory(LivesupportOneShotReader * reader,
/* flush the bytestream, as we've read all from it anyway */
gst_bytestream_flush_fast(reader->bytestream, length);
/* re-seek to the beginning, to make sure it can be set to PLAYING again */
gst_bytestream_seek(reader->bytestream, 0LL, GST_SEEK_METHOD_SET);
/* put a 0 character at the end of the buffer */
buffer[length] = '\0';
@ -380,9 +387,11 @@ livesupport_one_shot_reader_dispose(GObject * object)
if (reader->bytestream) {
gst_bytestream_destroy(reader->bytestream);
reader->bytestream = 0;
}
if (reader->contents) {
g_free(reader->contents);
reader->contents = 0;
}
G_OBJECT_CLASS(parent_class)->dispose(object);

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.4 $
Version : $Revision: 1.5 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/gstreamerElements/src/seek-pack.c,v $
------------------------------------------------------------------------------*/
@ -42,6 +42,7 @@
#include <gst/gst.h>
#include "LiveSupport/GstreamerElements/autoplug.h"
#include "util.h"
#include "seek.h"
#include "seek-pack.h"
@ -112,6 +113,8 @@ livesupport_seek_pack_new(const gchar * uniqueName)
gchar * str = g_malloc(len);
LivesupportSeekPack * seekPack = g_malloc(sizeof(LivesupportSeekPack));
seekPack->name = g_strdup(uniqueName);
g_snprintf(str, len, "%s_seekPackSilence", uniqueName);
seekPack->silence = gst_element_factory_make("silence", str);
g_snprintf(str, len, "%s_seekPackAudioConvert", uniqueName);
@ -121,8 +124,8 @@ livesupport_seek_pack_new(const gchar * uniqueName)
/* TODO: typefind, and create Ogg Vorbis parser/decoder */
seekPack->parser = NULL;
g_snprintf(str, len, "%s_seekPackDecoder", uniqueName);
seekPack->decoder = gst_element_factory_make("mad", str);
/* generate decoder later, by autoplugging */
seekPack->decoder = 0;
g_snprintf(str, len, "%s_seekPackSwitcher", uniqueName);
seekPack->switcher = gst_element_factory_make("switcher", str);
g_snprintf(str, len, "%s_seekPackBin", uniqueName);
@ -174,6 +177,8 @@ livesupport_seek_pack_init(LivesupportSeekPack * seekPack,
{
GValue gvalue = { 0 };
gchar str[256];
unsigned int len = strlen(seekPack->name) + 64;
gchar * name = g_malloc(len);
seekPack->source = source;
@ -196,6 +201,11 @@ livesupport_seek_pack_init(LivesupportSeekPack * seekPack,
g_value_set_string(&gvalue, str);
gst_element_set_property(seekPack->switcher, "source-config", &gvalue);
g_snprintf(name, len, "%s_seekPackDecoder", seekPack->name);
seekPack->decoder = ls_gst_autoplug_plug_source(seekPack->source,
name);
g_free(name);
gst_element_link(seekPack->source, seekPack->decoder);
livesupport_seek_pack_seek(seekPack);
gst_element_link(seekPack->decoder, seekPack->switcher);
@ -215,6 +225,7 @@ livesupport_seek_pack_destroy(LivesupportSeekPack * seekPack)
{
gst_element_set_state(seekPack->bin, GST_STATE_NULL);
g_object_unref(seekPack->bin);
g_free(seekPack->name);
g_free(seekPack);
}
@ -264,9 +275,15 @@ livesupport_seek_pack_set_state(LivesupportSeekPack * seekPack,
{
/* FIXME: resetting the source from PLAYING state would make it lose
* it's seek position */
if (seekPack->audioconvert) {
gst_element_set_state(seekPack->audioconvert, state);
}
if (seekPack->decoder) {
gst_element_set_state(seekPack->decoder, state);
}
if (seekPack->switcher) {
gst_element_set_state(seekPack->switcher, state);
}
}
@ -299,8 +316,8 @@ livesupport_seek_pack_seek(LivesupportSeekPack * seekPack)
NULL);
GST_DEBUG("setting seek pipeline to PLAYING state");
gst_element_set_state(seekPack->decoder, GST_STATE_READY);
gst_element_set_state(fakesink, GST_STATE_READY);
gst_element_set_state(seekPack->decoder, GST_STATE_PAUSED);
gst_element_set_state(fakesink, GST_STATE_PAUSED);
gst_element_set_state(pipeline, GST_STATE_PLAYING);
GST_DEBUG("starting to iterate...");
@ -313,7 +330,6 @@ livesupport_seek_pack_seek(LivesupportSeekPack * seekPack)
ret = livesupport_seek(seekPack->decoder, seekType, seekPack->startTime);
GST_DEBUG("seek result: %d", ret);
gst_bin_remove_many(GST_BIN(pipeline),
seekPack->source,
seekPack->decoder,

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.3 $
Version : $Revision: 1.4 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/gstreamerElements/src/seek-pack.h,v $
------------------------------------------------------------------------------*/
@ -35,7 +35,7 @@
* some silence and then some specified part of the source.
*
* @author $Author: maroy $
* @version $Revision: 1.3 $
* @version $Revision: 1.4 $
*/
#ifdef __cplusplus
@ -64,6 +64,8 @@ typedef struct _LivesupportSeekPack LivesupportSeekPack;
* A SeekPack structure.
*/
struct _LivesupportSeekPack {
gchar * name;
GstElement * silence;
GstElement * audioconvert;