|
|
@ -61,47 +61,47 @@ int MediaServer::getNumFboSources(){ |
|
|
|
return fboSources.size(); |
|
|
|
} |
|
|
|
|
|
|
|
vector <string> & MediaServer::getImagePaths(){ |
|
|
|
std::vector<std::string> & MediaServer::getImagePaths(){ |
|
|
|
return imageWatcher.getFilePaths(); |
|
|
|
} |
|
|
|
|
|
|
|
vector <string> MediaServer::getImageNames(){ |
|
|
|
vector <string> imageNames; |
|
|
|
std::vector<std::string> MediaServer::getImageNames(){ |
|
|
|
std::vector<std::string> imageNames; |
|
|
|
for(int i = 0; i < getNumImages(); i++){ |
|
|
|
// Split image path
|
|
|
|
vector <string> pathParts = ofSplitString(getImagePaths()[i], "/"); |
|
|
|
std::vector<std::string> pathParts = ofSplitString(getImagePaths()[i], "/"); |
|
|
|
// And get only the last piece
|
|
|
|
string name = pathParts[pathParts.size() - 1]; |
|
|
|
std::string name = pathParts[pathParts.size() - 1]; |
|
|
|
imageNames.push_back(name); |
|
|
|
} |
|
|
|
return imageNames; |
|
|
|
} |
|
|
|
|
|
|
|
vector <string> MediaServer::getFboSourceNames(){ |
|
|
|
vector <string> fboSourceNames; |
|
|
|
std::vector<std::string> MediaServer::getFboSourceNames(){ |
|
|
|
std::vector<std::string> fboSourceNames; |
|
|
|
for(int i = 0; i < fboSources.size(); i++){ |
|
|
|
fboSourceNames.push_back(fboSources[i]->getName()); |
|
|
|
} |
|
|
|
return fboSourceNames; |
|
|
|
} |
|
|
|
|
|
|
|
vector <string> & MediaServer::getVideoPaths(){ |
|
|
|
std::vector<std::string> & MediaServer::getVideoPaths(){ |
|
|
|
return videoWatcher.getFilePaths(); |
|
|
|
} |
|
|
|
|
|
|
|
vector <string> MediaServer::getVideoNames(){ |
|
|
|
vector <string> videoNames; |
|
|
|
std::vector<std::string> MediaServer::getVideoNames(){ |
|
|
|
std::vector<std::string> videoNames; |
|
|
|
for(int i = 0; i < getNumVideos(); i++){ |
|
|
|
// Split video path
|
|
|
|
vector <string> pathParts = ofSplitString(getVideoPaths()[i], "/"); |
|
|
|
std::vector<std::string> pathParts = ofSplitString(getVideoPaths()[i], "/"); |
|
|
|
// And get only the last piece
|
|
|
|
string name = pathParts[pathParts.size() - 1]; |
|
|
|
std::string name = pathParts[pathParts.size() - 1]; |
|
|
|
videoNames.push_back(name); |
|
|
|
} |
|
|
|
return videoNames; |
|
|
|
} |
|
|
|
|
|
|
|
BaseSource * MediaServer::loadMedia(string & path, int mediaType){ |
|
|
|
BaseSource * MediaServer::loadMedia(std::string & path, int mediaType){ |
|
|
|
// Chose load method depending on type
|
|
|
|
if(mediaType == SourceType::SOURCE_TYPE_IMAGE){ |
|
|
|
return loadImage(path); |
|
|
@ -110,7 +110,7 @@ BaseSource * MediaServer::loadMedia(string & path, int mediaType){ |
|
|
|
}else if(mediaType == SourceType::SOURCE_TYPE_FBO){ |
|
|
|
return loadFboSource(path); |
|
|
|
}else{ |
|
|
|
stringstream ss; |
|
|
|
std::stringstream ss; |
|
|
|
ss << "Can not load media of unknown type: " << mediaType; |
|
|
|
ofLogFatalError("MediaServer") << ss.str(); |
|
|
|
std::exit(EXIT_FAILURE); |
|
|
@ -118,7 +118,7 @@ BaseSource * MediaServer::loadMedia(string & path, int mediaType){ |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
BaseSource * MediaServer::loadImage(string & path){ |
|
|
|
BaseSource * MediaServer::loadImage(std::string & path){ |
|
|
|
ImageSource * imageSource = 0; |
|
|
|
// Check if this image is already loaded
|
|
|
|
bool isImageLoaded = false; |
|
|
@ -131,11 +131,11 @@ BaseSource * MediaServer::loadImage(string & path){ |
|
|
|
// Increase reference count of this source
|
|
|
|
//referenceCount[path]++;
|
|
|
|
imageSource->referenceCount++; |
|
|
|
stringstream refss; |
|
|
|
std::stringstream refss; |
|
|
|
refss << "Current reference count for " << path << " = " << imageSource->referenceCount; |
|
|
|
ofLogNotice("MediaServer") << refss.str(); |
|
|
|
// Notify objects registered to onImageLoaded event
|
|
|
|
stringstream ss; |
|
|
|
std::stringstream ss; |
|
|
|
ss << "Image " << path << " already loaded"; |
|
|
|
ofLogNotice("MediaServer") << ss.str(); |
|
|
|
ofNotifyEvent(onImageLoaded, path, this); |
|
|
@ -147,7 +147,7 @@ BaseSource * MediaServer::loadImage(string & path){ |
|
|
|
loadedSources[path] = imageSource; |
|
|
|
// Set reference count of this image path to 1
|
|
|
|
//referenceCount[path] = 1;
|
|
|
|
stringstream refss; |
|
|
|
std::stringstream refss; |
|
|
|
refss << "Initialized reference count of " << path << " to " << imageSource->referenceCount; |
|
|
|
ofLogNotice("MediaServer") << refss.str(); |
|
|
|
// Notify objects registered to onImageLoaded event
|
|
|
@ -155,7 +155,7 @@ BaseSource * MediaServer::loadImage(string & path){ |
|
|
|
return imageSource; |
|
|
|
} |
|
|
|
|
|
|
|
void MediaServer::unloadImage(string & path){ |
|
|
|
void MediaServer::unloadImage(std::string & path){ |
|
|
|
ImageSource * source = static_cast <ImageSource *>(getSourceByPath(path)); |
|
|
|
ofLogNotice("MediaServer") << "Unload image, current reference count: " << source->referenceCount; |
|
|
|
source->referenceCount--; |
|
|
@ -166,28 +166,28 @@ void MediaServer::unloadImage(string & path){ |
|
|
|
return; |
|
|
|
} |
|
|
|
// Reference count 0 or less, unload image
|
|
|
|
stringstream ss; |
|
|
|
std::stringstream ss; |
|
|
|
ss << "Removing image " << path; |
|
|
|
ofLogNotice("MediaServer") << ss.str(); |
|
|
|
// Destroy image source
|
|
|
|
if(loadedSources.count(path)){ |
|
|
|
ofLogNotice("MediaServer") << "Source count BEFORE image removal: " << loadedSources.size() << endl; |
|
|
|
ofLogNotice("MediaServer") << "Source count BEFORE image removal: " << loadedSources.size() << std::endl; |
|
|
|
loadedSources[path]->clear(); |
|
|
|
map <string, BaseSource *>::iterator it = loadedSources.find(path); |
|
|
|
map <std::string, BaseSource *>::iterator it = loadedSources.find(path); |
|
|
|
delete it->second; |
|
|
|
loadedSources.erase(it); |
|
|
|
ofLogNotice("MediaServer") << "Source count AFTER image removal: " << loadedSources.size() << endl; |
|
|
|
ofLogNotice("MediaServer") << "Source count AFTER image removal: " << loadedSources.size() << std::endl; |
|
|
|
ofNotifyEvent(onImageUnloaded, path, this); |
|
|
|
return; |
|
|
|
} |
|
|
|
// Something wrong here, we should be out of the routine by now
|
|
|
|
stringstream failss; |
|
|
|
std::stringstream failss; |
|
|
|
failss << "Failed to remove image source: " << path; |
|
|
|
ofLogFatalError("MediaServer") << failss.str(); |
|
|
|
std::exit(EXIT_FAILURE); |
|
|
|
} |
|
|
|
|
|
|
|
BaseSource * MediaServer::loadVideo(string & path){ |
|
|
|
BaseSource * MediaServer::loadVideo(std::string & path){ |
|
|
|
VideoSource * videoSource = 0; |
|
|
|
// Check if this video is already loaded
|
|
|
|
bool isVideoLoaded = false; |
|
|
@ -199,11 +199,11 @@ BaseSource * MediaServer::loadVideo(string & path){ |
|
|
|
if(isVideoLoaded){ |
|
|
|
// Increase reference count of this source
|
|
|
|
videoSource->referenceCount++; |
|
|
|
stringstream refss; |
|
|
|
std::stringstream refss; |
|
|
|
refss << "Current reference count for " << path << " = " << videoSource->referenceCount; |
|
|
|
ofLogNotice("MediaServer") << refss.str(); |
|
|
|
// Notify objects registered to onImageLoaded event
|
|
|
|
stringstream ss; |
|
|
|
std::stringstream ss; |
|
|
|
ss << "Video " << path << " already loaded"; |
|
|
|
ofLogNotice("MediaServer") << ss.str(); |
|
|
|
ofNotifyEvent(onVideoLoaded, path, this); |
|
|
@ -215,14 +215,14 @@ BaseSource * MediaServer::loadVideo(string & path){ |
|
|
|
loadedSources[path] = videoSource; |
|
|
|
// Set reference count of this image path to 1
|
|
|
|
//referenceCount[path] = 1;
|
|
|
|
stringstream refss; |
|
|
|
std::stringstream refss; |
|
|
|
refss << "Initialized reference count of " << path << " to " << videoSource->referenceCount; |
|
|
|
ofLogNotice("MediaServer") << refss.str(); |
|
|
|
ofNotifyEvent(onVideoLoaded, path, this); |
|
|
|
return videoSource; |
|
|
|
} |
|
|
|
|
|
|
|
void MediaServer::unloadVideo(string & path){ |
|
|
|
void MediaServer::unloadVideo(std::string & path){ |
|
|
|
VideoSource * videoSource = static_cast <VideoSource *>(getSourceByPath(path)); |
|
|
|
// Decrease reference count of the video
|
|
|
|
//referenceCount[path]--;
|
|
|
@ -239,26 +239,26 @@ void MediaServer::unloadVideo(string & path){ |
|
|
|
if(loadedSources.count(path)){ |
|
|
|
ofLogNotice("MediaServer") |
|
|
|
<< "Source count before video removal: " |
|
|
|
<< loadedSources.size() << endl; |
|
|
|
<< loadedSources.size() << std::endl; |
|
|
|
videoSource->clear(); |
|
|
|
map <string, BaseSource *>::iterator it = loadedSources.find(path); |
|
|
|
map <std::string, BaseSource *>::iterator it = loadedSources.find(path); |
|
|
|
delete it->second; |
|
|
|
loadedSources.erase(it); |
|
|
|
ofLogNotice("MediaServer") |
|
|
|
<< "Source count after video removal: " |
|
|
|
<< loadedSources.size() << endl; |
|
|
|
<< loadedSources.size() << std::endl; |
|
|
|
ofNotifyEvent(onVideoUnloaded, path, this); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// Something wrong here, we should be out of the routine by now
|
|
|
|
stringstream failss; |
|
|
|
std::stringstream failss; |
|
|
|
failss << "Failed to remove video source: " << path; |
|
|
|
ofLogFatalError("MediaServer") << failss.str(); |
|
|
|
std::exit(EXIT_FAILURE); |
|
|
|
} |
|
|
|
|
|
|
|
void MediaServer::unloadMedia(string & path){ |
|
|
|
void MediaServer::unloadMedia(std::string & path){ |
|
|
|
if(loadedSources.count(path)){ |
|
|
|
BaseSource * mediaSource = getSourceByPath(path); |
|
|
|
if(mediaSource->getType() == SourceType::SOURCE_TYPE_IMAGE){ |
|
|
@ -279,7 +279,7 @@ void MediaServer::unloadMedia(string & path){ |
|
|
|
|
|
|
|
// Clear all loaded media
|
|
|
|
void MediaServer::clear(){ |
|
|
|
typedef map <string, BaseSource *>::iterator it_type; |
|
|
|
typedef map <std::string, BaseSource *>::iterator it_type; |
|
|
|
for(it_type i = loadedSources.begin(); i != loadedSources.end(); i++){ |
|
|
|
// Do not delete FBO source pointers as they are (and should be) initialized elsewhere
|
|
|
|
if(i->second->getType() != SourceType::SOURCE_TYPE_FBO){ |
|
|
@ -290,32 +290,32 @@ void MediaServer::clear(){ |
|
|
|
} |
|
|
|
|
|
|
|
// TODO: getLoadedSourceByPath
|
|
|
|
BaseSource * MediaServer::getSourceByPath(string & mediaPath){ |
|
|
|
BaseSource * MediaServer::getSourceByPath(std::string & mediaPath){ |
|
|
|
if(loadedSources.count(mediaPath)){ |
|
|
|
return loadedSources[mediaPath]; |
|
|
|
} |
|
|
|
// Source not found, exit with error
|
|
|
|
stringstream ss; |
|
|
|
std::stringstream ss; |
|
|
|
ss << "Could not find source by path: " << mediaPath; |
|
|
|
ofLogFatalError("MediaServer") << ss.str(); |
|
|
|
std::exit(EXIT_FAILURE); |
|
|
|
} |
|
|
|
|
|
|
|
string MediaServer::getDefaultImageDir(){ |
|
|
|
std::string MediaServer::getDefaultImageDir(){ |
|
|
|
return DEFAULT_IMAGES_DIR; |
|
|
|
} |
|
|
|
|
|
|
|
string MediaServer::getDefaultVideoDir(){ |
|
|
|
std::string MediaServer::getDefaultVideoDir(){ |
|
|
|
return DEFAULT_VIDEOS_DIR; |
|
|
|
} |
|
|
|
|
|
|
|
string MediaServer::getDefaultMediaDir(int sourceType){ |
|
|
|
std::string MediaServer::getDefaultMediaDir(int sourceType){ |
|
|
|
if(sourceType == SourceType::SOURCE_TYPE_IMAGE){ |
|
|
|
return getDefaultImageDir(); |
|
|
|
}else if(sourceType == SourceType::SOURCE_TYPE_VIDEO){ |
|
|
|
return getDefaultVideoDir(); |
|
|
|
}else{ |
|
|
|
stringstream ss; |
|
|
|
std::stringstream ss; |
|
|
|
ss << "Could not get default media dir. Unknown source type: " << sourceType; |
|
|
|
ofLogFatalError("MediaServer") << ss.str(); |
|
|
|
std::exit(EXIT_FAILURE); |
|
|
@ -346,7 +346,7 @@ void MediaServer::addFboSource(FboSource * fboSource){ |
|
|
|
fboSource->setup(); |
|
|
|
} |
|
|
|
|
|
|
|
BaseSource * MediaServer::loadFboSource(string & fboSourceName){ |
|
|
|
BaseSource * MediaServer::loadFboSource(std::string & fboSourceName){ |
|
|
|
ofLogNotice("MediaServer") << "Attempting to load FBO source with name " << fboSourceName; |
|
|
|
// Search for FBO source name in our storage
|
|
|
|
FboSource * source = 0; |
|
|
@ -378,7 +378,7 @@ BaseSource * MediaServer::loadFboSource(string & fboSourceName){ |
|
|
|
return loadedSources[fboSourceName]; |
|
|
|
} // loadFboSource
|
|
|
|
|
|
|
|
void MediaServer::unloadFboSource(string & fboSourceName){ |
|
|
|
void MediaServer::unloadFboSource(std::string & fboSourceName){ |
|
|
|
ofLogNotice("MediaServer") << "Attempt to unload FBO source " << fboSourceName; |
|
|
|
// Check if loaded at all
|
|
|
|
if(!loadedSources.count(fboSourceName)){ |
|
|
@ -396,9 +396,9 @@ void MediaServer::unloadFboSource(string & fboSourceName){ |
|
|
|
ofLogNotice("MediaServer") << fboSourceName << " reference count <= 0, removing from loaded sources"; |
|
|
|
source->referenceCount = 0; |
|
|
|
//source->removeAppListeners();
|
|
|
|
map <string, BaseSource *>::iterator it = loadedSources.find(fboSourceName); |
|
|
|
map <std::string, BaseSource *>::iterator it = loadedSources.find(fboSourceName); |
|
|
|
loadedSources.erase(it); |
|
|
|
ofLogNotice("MediaServer") << "Source count after FBO source removal: " << loadedSources.size() << endl; |
|
|
|
ofLogNotice("MediaServer") << "Source count after FBO source removal: " << loadedSources.size() << std::endl; |
|
|
|
ofNotifyEvent(onFboSourceUnloaded, fboSourceName, this); |
|
|
|
} |
|
|
|
} // unloadFboSource
|
|
|
|