Many bugfixes and improvements for the preloading system:
* Fixed memory handling. Now using Ptr::Ref. * Various bugfixes. * Speedup: Use preloaded data whenever possible.
This commit is contained in:
parent
e316b65ac8
commit
0554aeded0
|
@ -38,6 +38,7 @@
|
|||
|
||||
#include "LiveSupport/Core/TimeConversion.h"
|
||||
#include "GstreamerPlayer.h"
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
using namespace boost::posix_time;
|
||||
|
@ -114,8 +115,6 @@ GstreamerPlayer :: initialize(void) throw (std::exception)
|
|||
m_audioconvert = 0;
|
||||
m_audioscale = 0;
|
||||
|
||||
m_preloadThread = 0;
|
||||
|
||||
g_signal_connect(m_pipeline, "error", G_CALLBACK(errorHandler), this);
|
||||
|
||||
// TODO: read the caps from the config file
|
||||
|
@ -292,14 +291,14 @@ GstreamerPlayer :: preload(const std::string fileUrl)
|
|||
|
||||
if (m_preloadThread) {
|
||||
m_preloadThread->stop();
|
||||
// Wait for thread exit
|
||||
while (m_preloadThread) {}
|
||||
m_preloadThread->join();
|
||||
m_preloadThread.reset();
|
||||
}
|
||||
|
||||
Ptr<Preloader>::Ref loader;
|
||||
loader.reset(new Preloader(this, fileUrl));
|
||||
|
||||
m_preloadThread = new Thread(loader);
|
||||
m_preloadThread.reset(new Thread(loader));
|
||||
m_preloadThread->start();
|
||||
}
|
||||
|
||||
|
@ -323,8 +322,6 @@ GstreamerPlayer :: open(const std::string fileUrl)
|
|||
|
||||
debug() << "Opening URL: " << fileUrl << endl;
|
||||
|
||||
//preload(fileUrl);
|
||||
|
||||
std::string filePath;
|
||||
|
||||
if (fileUrl.find("file://") == 0) {
|
||||
|
@ -337,6 +334,11 @@ GstreamerPlayer :: open(const std::string fileUrl)
|
|||
throw std::invalid_argument("badly formed URL or unsupported protocol");
|
||||
}
|
||||
|
||||
if (m_preloadThread) {
|
||||
debug() << "Waiting for Preloader thread to finish..." << endl;
|
||||
m_preloadThread->join();
|
||||
}
|
||||
|
||||
const bool isSmil = fileUrl.substr(fileUrl.size()-5, fileUrl.size()) == ".smil" ? true : false;
|
||||
const bool isPreloaded = (m_preloadUrl == fileUrl);
|
||||
|
||||
|
@ -640,15 +642,12 @@ Preloader::Preloader(GstreamerPlayer* player, const std::string url) throw()
|
|||
: RunnableInterface()
|
||||
, m_player(player)
|
||||
, m_fileUrl(url)
|
||||
, m_stop(false)
|
||||
{}
|
||||
|
||||
|
||||
Preloader::~Preloader() throw()
|
||||
{
|
||||
DEBUG_BLOCK
|
||||
|
||||
m_player->m_preloadThread = 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -677,9 +676,8 @@ void Preloader::run() throw()
|
|||
return;
|
||||
}
|
||||
|
||||
m_player->m_preloadUrl.clear();
|
||||
|
||||
if (!p->m_preloadUrl.empty()) {
|
||||
p->m_preloadUrl.clear();
|
||||
g_object_unref(G_OBJECT(p->m_preloadFilesrc));
|
||||
g_object_unref(G_OBJECT(p->m_preloadDecoder));
|
||||
}
|
||||
|
@ -697,18 +695,13 @@ void Preloader::run() throw()
|
|||
gst_element_set_state(pipe, GST_STATE_PLAYING);
|
||||
|
||||
gint64 position = 0LL;
|
||||
while (position == 0LL && gst_bin_iterate(GST_BIN(pipe)) && !m_stop) {
|
||||
while (position == 0LL && gst_bin_iterate(GST_BIN(pipe))) {
|
||||
GstFormat format = GST_FORMAT_DEFAULT;
|
||||
gst_element_query(fakesink, GST_QUERY_POSITION, &format, &position);
|
||||
}
|
||||
|
||||
gst_element_set_state(pipe, GST_STATE_PAUSED);
|
||||
|
||||
if (m_stop) {
|
||||
gst_object_unref(GST_OBJECT(pipe));
|
||||
return;
|
||||
}
|
||||
|
||||
g_object_ref(G_OBJECT(p->m_preloadFilesrc));
|
||||
g_object_ref(G_OBJECT(p->m_preloadDecoder));
|
||||
gst_bin_remove_many(GST_BIN(pipe), p->m_preloadFilesrc, p->m_preloadDecoder, NULL);
|
||||
|
@ -717,7 +710,7 @@ void Preloader::run() throw()
|
|||
|
||||
p->m_preloadUrl = fileUrl;
|
||||
|
||||
delete this;
|
||||
p->m_preloadThread.reset();
|
||||
}
|
||||
|
||||
|
||||
|
@ -726,10 +719,6 @@ void Preloader::signal(int) throw()
|
|||
|
||||
|
||||
void Preloader::stop() throw()
|
||||
{
|
||||
DEBUG_BLOCK
|
||||
|
||||
m_stop = true;
|
||||
}
|
||||
{}
|
||||
|
||||
|
||||
|
|
|
@ -154,7 +154,7 @@ class GstreamerPlayer : virtual public Configurable,
|
|||
GstElement * m_preloadFilesrc;
|
||||
GstElement * m_preloadDecoder;
|
||||
|
||||
Thread * m_preloadThread;
|
||||
Ptr<Thread>::Ref m_preloadThread;
|
||||
|
||||
/**
|
||||
* The type for the vector of listeners.
|
||||
|
@ -451,7 +451,6 @@ class Preloader : public RunnableInterface
|
|||
private:
|
||||
GstreamerPlayer* m_player;
|
||||
std::string m_fileUrl;
|
||||
bool m_stop;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue