From e1a2db28e8aa9d9ca7b6dbdf7df431e767608d24 Mon Sep 17 00:00:00 2001 From: kapil Date: Thu, 1 Oct 2009 22:08:14 +0000 Subject: [PATCH] Added support for playlist start time configuration, scheduler can pass any position from where to start the playlist by passing value (in seconds) to the GstreamerPlayer::start method. Whenever the playlist is stopped, GstreamerPlayer::Close returns time (in seconds) at what position it stopped, which can be useful if a playlist gets crashed in between. Scheduler should store this returned value for future reference to restart the playlist from the old position. Files Changed: GLiveSupport.cxx, PlaylistEvent.cxx, AudioPlayerInterface.h, GstreamerPlayer.cxx, GstreamerPlayContext.h, GstreamerPlayer.h --- .../PlaylistExecutor/AudioPlayerInterface.h | 4 +-- .../src/GstreamerPlayContext.h | 19 ++++++++++++- .../playlistExecutor/src/GstreamerPlayer.cxx | 27 +++++++++++++------ .../playlistExecutor/src/GstreamerPlayer.h | 6 ++--- .../gLiveSupport/src/GLiveSupport.cxx | 14 +++++----- .../products/scheduler/src/PlaylistEvent.cxx | 2 +- 6 files changed, 50 insertions(+), 22 deletions(-) diff --git a/campcaster/src/modules/playlistExecutor/include/LiveSupport/PlaylistExecutor/AudioPlayerInterface.h b/campcaster/src/modules/playlistExecutor/include/LiveSupport/PlaylistExecutor/AudioPlayerInterface.h index 1a11873ae..e7245da61 100644 --- a/campcaster/src/modules/playlistExecutor/include/LiveSupport/PlaylistExecutor/AudioPlayerInterface.h +++ b/campcaster/src/modules/playlistExecutor/include/LiveSupport/PlaylistExecutor/AudioPlayerInterface.h @@ -170,7 +170,7 @@ class AudioPlayerInterface * * @see #open */ - virtual void + virtual int close(void) throw (std::logic_error) = 0; /** @@ -204,7 +204,7 @@ class AudioPlayerInterface * @see #stop */ virtual void - start(void) throw (std::logic_error) + start(int) throw (std::logic_error) = 0; /** diff --git a/campcaster/src/modules/playlistExecutor/src/GstreamerPlayContext.h b/campcaster/src/modules/playlistExecutor/src/GstreamerPlayContext.h index 4cab1b37d..e60931449 100644 --- a/campcaster/src/modules/playlistExecutor/src/GstreamerPlayContext.h +++ b/campcaster/src/modules/playlistExecutor/src/GstreamerPlayContext.h @@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Author : $Author$ + Author : $Author: Kapil Agrawal$ Version : $Revision$ Location : $URL$ @@ -233,6 +233,23 @@ public: } return ns; } + /*------------------------------------------------------------------------------ + * Seeks to the passed argument seek + *---------------------------------------------------------------------------*/ + void + start_time (gint start_time){ + GstState state; + GstState pending; + gst_element_set_state (m_pipeline, GST_STATE_PAUSED); + gst_element_get_state (m_pipeline, &state, &pending, 50000000); + if (!gst_element_seek (m_pipeline, 1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH, GST_SEEK_TYPE_SET, + start_time*GST_SECOND, GST_SEEK_TYPE_END, 0)) { + g_print ("\nstart_time seek failed\n"); + } + else + g_print ("\n start_time seek succces\n"); + } + /*------------------------------------------------------------------------------ * Returns current stream's position. *----------------------------------------------------------------------------*/ diff --git a/campcaster/src/modules/playlistExecutor/src/GstreamerPlayer.cxx b/campcaster/src/modules/playlistExecutor/src/GstreamerPlayer.cxx index c5c955d32..03077710c 100644 --- a/campcaster/src/modules/playlistExecutor/src/GstreamerPlayer.cxx +++ b/campcaster/src/modules/playlistExecutor/src/GstreamerPlayer.cxx @@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Author : $Author$ + Author : $Author: Kapil Agrawal$ Version : $Revision$ Location : $URL$ @@ -303,7 +303,7 @@ GstreamerPlayer :: playNextSmil(void) throw ( { return false; } -// m_currentPlayLength = m_playContext->getPosition();//this gets the length of the stream that just completed + m_currentPlayLength = m_playContext->getPosition();//this gets the length of the stream that just completed m_playContext->closeContext(); if(m_smilHandler == NULL){ return false; @@ -327,7 +327,14 @@ GstreamerPlayer :: playNextSmil(void) throw ( m_url = (const char*) audioDescription->m_src; g_idle_add(GstreamerPlayer::fireOnStartEvent, this); m_smilOffset = audioDescription->m_begin; -// m_smilOffset += m_currentPlayLength; + // m_smilOffset += m_currentPlayLength; + m_start_time = m_start_time - (m_currentPlayLength/GST_SECOND); + if(m_start_time > 0){ + m_playContext->start_time (m_start_time); + } + else { + m_start_time = 0; + } m_playContext->playContext(); return true; } @@ -391,15 +398,16 @@ GstreamerPlayer :: getPosition(void) throw (std::logic_error) * Start playing *----------------------------------------------------------------------------*/ void -GstreamerPlayer :: start(void) throw (std::logic_error) +GstreamerPlayer :: start(int start_time) throw (std::logic_error) { DEBUG_BLOCK - + m_start_time = start_time; if (!isOpen()) { throw std::logic_error("GstreamerPlayer not opened yet"); } if (!isPlaying()) { + m_playContext->start_time (m_start_time); m_playContext->playContext(); }else{ error() << "Already playing!" << endl; @@ -452,19 +460,22 @@ GstreamerPlayer :: stop(void) throw (std::logic_error) /*------------------------------------------------------------------------------ * Close the currently opened audio file. *----------------------------------------------------------------------------*/ -void +int GstreamerPlayer :: close(void) throw (std::logic_error) { DEBUG_BLOCK - + gint64 ns; + int stop_time; + ns = m_playContext->getPosition(); m_playContext->stopContext(); m_playContext->closeContext(); if(m_smilHandler != NULL){ delete m_smilHandler; m_smilHandler = NULL; } - + stop_time = ns/GST_SECOND; m_open = false; + return (stop_time + (m_smilOffset/GST_SECOND)); } diff --git a/campcaster/src/modules/playlistExecutor/src/GstreamerPlayer.h b/campcaster/src/modules/playlistExecutor/src/GstreamerPlayer.h index fb5745fe4..d1ab1555d 100644 --- a/campcaster/src/modules/playlistExecutor/src/GstreamerPlayer.h +++ b/campcaster/src/modules/playlistExecutor/src/GstreamerPlayer.h @@ -128,7 +128,7 @@ class GstreamerPlayer : virtual public Configurable, gint64 m_Id; public: - + gint m_start_time; /** * Contains runtime error messages from GStreamer. */ @@ -314,7 +314,7 @@ public: * * @see #open */ - virtual void + virtual int close(void) throw (std::logic_error); /** @@ -329,7 +329,7 @@ public: * @see #stop */ virtual void - start(void) throw (std::logic_error); + start(int) throw (std::logic_error); /** * Pause the player. diff --git a/campcaster/src/products/gLiveSupport/src/GLiveSupport.cxx b/campcaster/src/products/gLiveSupport/src/GLiveSupport.cxx index 7acee5425..f82eaba10 100644 --- a/campcaster/src/products/gLiveSupport/src/GLiveSupport.cxx +++ b/campcaster/src/products/gLiveSupport/src/GLiveSupport.cxx @@ -1302,7 +1302,7 @@ GLiveSupport :: playOutputAudio(Ptr::Ref playable) { return false; } - outputPlayer->start(); + outputPlayer->start(0); std::cerr << "gLiveSupport: Live Mode playing audio clip '" << *playable->getTitle() << "'" << std::endl; @@ -1311,7 +1311,7 @@ GLiveSupport :: playOutputAudio(Ptr::Ref playable) case Playable::PlaylistType: outputItemPlayingNow = acquirePlaylist(playable->getId()); outputPlayer->open(*outputItemPlayingNow->getUri(), (gint64)outputItemPlayingNow->getId()->getId()); - outputPlayer->start(); + outputPlayer->start(0); std::cerr << "gLiveSupport: Live Mode playing playlist '" << *playable->getTitle() << "'" << std::endl; @@ -1361,7 +1361,7 @@ GLiveSupport :: pauseOutputAudio(void) outputPlayerIsPaused = true; } else if (outputPlayerIsPaused) { - outputPlayer->start(); + outputPlayer->start(0); outputPlayerIsPaused = false; } } @@ -1444,7 +1444,7 @@ GLiveSupport :: playCueAudio(Ptr::Ref playable) case Playable::AudioClipType: cueItemPlayingNow = acquireAudioClip(playable->getId()); cuePlayer->open(*cueItemPlayingNow->getUri(), (gint64)cueItemPlayingNow->getId()->getId()); - cuePlayer->start(); + cuePlayer->start(0); std::cerr << "gLiveSupport: Cue playing audio clip '" << *playable->getTitle() << "'" << std::endl; @@ -1453,7 +1453,7 @@ GLiveSupport :: playCueAudio(Ptr::Ref playable) case Playable::PlaylistType: cueItemPlayingNow = acquirePlaylist(playable->getId()); cuePlayer->open(*cueItemPlayingNow->getUri(), (gint64)cueItemPlayingNow->getId()->getId()); - cuePlayer->start(); + cuePlayer->start(0); std::cerr << "gLiveSupport: Cue playing playlist '" << *playable->getTitle() << "'" << std::endl; @@ -1502,7 +1502,7 @@ GLiveSupport :: pauseCueAudio(void) cuePlayerIsPaused = true; } else if (cuePlayerIsPaused) { - cuePlayer->start(); + cuePlayer->start(0); cuePlayerIsPaused = false; } } @@ -1770,7 +1770,7 @@ GLiveSupport :: playTestSoundOnCue(Ptr::Ref oldDevice, } cuePlayer->setAudioDevice(*newDevice); cuePlayer->open(*testAudioUrl, (gint64)0); - cuePlayer->start(); + cuePlayer->start(0); Ptr::Ref sleepT(new time_duration(microseconds(10))); while (cuePlayer->isPlaying()) { runMainLoop(); diff --git a/campcaster/src/products/scheduler/src/PlaylistEvent.cxx b/campcaster/src/products/scheduler/src/PlaylistEvent.cxx index 0b51489bc..380d61fb5 100644 --- a/campcaster/src/products/scheduler/src/PlaylistEvent.cxx +++ b/campcaster/src/products/scheduler/src/PlaylistEvent.cxx @@ -159,7 +159,7 @@ PlaylistEvent :: start(void) throw () try { audioPlayer->open(*playlist->getUri(), (gint64)playlist->getId()->getId()); - audioPlayer->start(); + audioPlayer->start(0); playLog->addPlayLogEntry(playlist->getId(), TimeConversion::now()); } catch (std::invalid_argument &e) {