diff --git a/NetworkSource.cpp b/NetworkSource.cpp index 61c323d..3724679 100644 --- a/NetworkSource.cpp +++ b/NetworkSource.cpp @@ -223,7 +223,7 @@ void NetworkStream::update() // make sure the shared memory socket exists if (config_.protocol == NetworkToolkit::SHM_RAW) { // for shared memory, the parameter is a file location in settings - parameter = SystemToolkit::full_filename(SystemToolkit::settings_path(), "shm") + parameter; + parameter = SystemToolkit::full_filename(SystemToolkit::temp_path(), "shm") + parameter; // try few times to see if file exists and wait 20ms each time for(int trial = 0; trial < 5; trial ++){ if ( SystemToolkit::file_exists(parameter)) @@ -232,7 +232,7 @@ void NetworkStream::update() } // failed to find the shm socket file: cannot connect if (!SystemToolkit::file_exists(parameter)) { - Log::Warning("Cannot connect to shared memory."); + Log::Warning("Cannot connect to shared memory %s.", parameter.c_str()); failed_ = true; } parameter = "\"" + parameter + "\""; diff --git a/Streamer.cpp b/Streamer.cpp index a3b39bf..c14a879 100644 --- a/Streamer.cpp +++ b/Streamer.cpp @@ -358,7 +358,7 @@ void VideoStreamer::addFrame (FrameBuffer *frame_buffer, float dt) } else if (config_.protocol == NetworkToolkit::SHM_RAW) { // TODO rename SHM socket "shm_PORT" - std::string path = SystemToolkit::full_filename(SystemToolkit::settings_path(), "shm"); + std::string path = SystemToolkit::full_filename(SystemToolkit::temp_path(), "shm"); path += std::to_string(config_.port); g_object_set (G_OBJECT (gst_bin_get_by_name (GST_BIN (pipeline_), "sink")), "socket-path", path.c_str(), NULL); diff --git a/SystemToolkit.cpp b/SystemToolkit.cpp index 21f196c..13b8dfa 100644 --- a/SystemToolkit.cpp +++ b/SystemToolkit.cpp @@ -254,6 +254,20 @@ string SystemToolkit::settings_path() } } +string SystemToolkit::temp_path() +{ + string temp; + + const char *tmpdir = getenv("TMPDIR"); + if (tmpdir) + temp = std::string(tmpdir); + else + temp = std::string( P_tmpdir ); + + temp += PATH_SEP; + return temp; +} + string SystemToolkit::full_filename(const std::string& path, const string &filename) { string fullfilename = path; diff --git a/SystemToolkit.h b/SystemToolkit.h index 2a1fda6..dfb1345 100644 --- a/SystemToolkit.h +++ b/SystemToolkit.h @@ -27,6 +27,9 @@ namespace SystemToolkit // get the OS dependent path where to store settings std::string settings_path(); + // get the OS dependent path where to store temporary files + std::string temp_path(); + // builds the OS dependent complete file name std::string full_filename(const std::string& path, const std::string& filename);