diff --git a/livesupport/modules/gstreamerElements/include/LiveSupport/GstreamerElements/autoplug.h b/livesupport/modules/gstreamerElements/include/LiveSupport/GstreamerElements/autoplug.h index 0ea892f25..7022f8bde 100644 --- a/livesupport/modules/gstreamerElements/include/LiveSupport/GstreamerElements/autoplug.h +++ b/livesupport/modules/gstreamerElements/include/LiveSupport/GstreamerElements/autoplug.h @@ -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/include/LiveSupport/GstreamerElements/autoplug.h,v $ ------------------------------------------------------------------------------*/ @@ -34,7 +34,7 @@ * Functions for autoplugging gstreamer elements based on their MIME types. * * @author $Author: maroy $ - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ */ #ifdef __cplusplus @@ -76,6 +76,19 @@ ls_gst_autoplug_plug_source(GstElement * source, const gchar * name, const GstCaps * caps); +/** + * Return the current position in a previously autoplugged element. + * This is a workaround function, as querying the element returned by + * ls_gst_autoplug_plug_source() with the standard gstreamer calls + * will not give satisfactory results. + * + * @param element a GstElement that was returned by a previous call to + * ls_gst_autoplug_plug_source() + * @return the current position, in nanoseconds + */ +gint64 +ls_gst_autoplug_get_position(GstElement * element); + #ifdef __cplusplus } /* extern "C" */ diff --git a/livesupport/modules/gstreamerElements/src/AutoplugTest.cxx b/livesupport/modules/gstreamerElements/src/AutoplugTest.cxx index 926cd4e4f..cc162eebf 100644 --- a/livesupport/modules/gstreamerElements/src/AutoplugTest.cxx +++ b/livesupport/modules/gstreamerElements/src/AutoplugTest.cxx @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.10 $ + Version : $Revision: 1.11 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/gstreamerElements/src/AutoplugTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -115,6 +115,11 @@ static const char * embeddedSmilFile = "var/embedded.smil"; */ static const char * sequentialSmilFile = "var/sequentialSmil.smil"; +/** + * A long (in time) playlist + */ +static const char * longSmilFile = "var/bach.smil"; + /* =============================================== local function prototypes */ @@ -460,5 +465,34 @@ AutoplugTest :: playlistOpenTest(void) std::cerr << "duration for " << sequentialSmilFile << ": " << *duration << std::endl; #endif + + duration = openFile(longSmilFile); +#ifdef PRINT_TIMES + std::cerr << "duration for " << longSmilFile << ": " + << *duration << std::endl; +#endif +} + + +/*------------------------------------------------------------------------------ + * A test to see if play duration is reported properly. + *----------------------------------------------------------------------------*/ +void +AutoplugTest :: playDurationTest(void) + throw (CPPUNIT_NS::Exception) +{ + gint64 duration; + + duration = playFile(mp3TestFile); +#ifdef PRINT_TIMES + std::cerr << "duration for " << mp3TestFile << ": " + << duration << std::endl; +#endif + + duration = playFile(sequentialSmilFile); +#ifdef PRINT_TIMES + std::cerr << "duration for " << sequentialSmilFile << ": " + << duration << std::endl; +#endif } diff --git a/livesupport/modules/gstreamerElements/src/AutoplugTest.h b/livesupport/modules/gstreamerElements/src/AutoplugTest.h index e82be45f8..1d996e401 100644 --- a/livesupport/modules/gstreamerElements/src/AutoplugTest.h +++ b/livesupport/modules/gstreamerElements/src/AutoplugTest.h @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.6 $ + Version : $Revision: 1.7 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/gstreamerElements/src/AutoplugTest.h,v $ ------------------------------------------------------------------------------*/ @@ -65,7 +65,7 @@ using namespace boost::posix_time; * Unit test for the partialplay gstreamer element. * * @author $Author: maroy $ - * @version $Revision: 1.6 $ + * @version $Revision: 1.7 $ */ class AutoplugTest : public CPPUNIT_NS::TestFixture { @@ -79,6 +79,7 @@ class AutoplugTest : public CPPUNIT_NS::TestFixture CPPUNIT_TEST(shortTest); CPPUNIT_TEST(shortSmilTest); CPPUNIT_TEST(playlistOpenTest); + CPPUNIT_TEST(playDurationTest); CPPUNIT_TEST_SUITE_END(); private: @@ -183,6 +184,14 @@ class AutoplugTest : public CPPUNIT_NS::TestFixture void playlistOpenTest(void) throw (CPPUNIT_NS::Exception); + /** + * A test to see if play duration is reported properly. + * + * @exception CPPUNIT_NS::Exception on test failures. + */ + void + playDurationTest(void) throw (CPPUNIT_NS::Exception); + public: diff --git a/livesupport/modules/gstreamerElements/src/autoplug.c b/livesupport/modules/gstreamerElements/src/autoplug.c index ede62aa36..3b352057f 100644 --- a/livesupport/modules/gstreamerElements/src/autoplug.c +++ b/livesupport/modules/gstreamerElements/src/autoplug.c @@ -27,7 +27,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.9 $ + Version : $Revision: 1.10 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/gstreamerElements/src/autoplug.c,v $ ------------------------------------------------------------------------------*/ @@ -801,3 +801,30 @@ ls_gst_autoplug_plug_source(GstElement * source, return bin; } + +/*------------------------------------------------------------------------------ + * Return the current position of an autoplugged element + *----------------------------------------------------------------------------*/ +gint64 +ls_gst_autoplug_get_position(GstElement * element) +{ + GstFormat format; + gint64 position; + GstElement * sink; + + if (!element || !GST_IS_BIN(element)) { + return 0LL; + } + if (!(sink = gst_bin_get_by_name(GST_BIN(element), "audiosink"))) { + return 0LL; + } + + format = GST_FORMAT_TIME; + if (!gst_element_query(sink, GST_QUERY_POSITION, &format, &position) + || format != GST_FORMAT_TIME) { + return 0LL; + } + + return position; +} +