Skip to content

Commit

Permalink
Add quick fix to broken usb media loading, close kr15h#119
Browse files Browse the repository at this point in the history
  • Loading branch information
kr15h committed Oct 15, 2017
1 parent 2d1c0a3 commit 7401408
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 71 deletions.
9 changes: 8 additions & 1 deletion src/MediaServer/DirectoryWatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ DirectoryWatcher::DirectoryWatcher(string path, int watcherMediaType){

for(int i = 0; i < _directory.size(); ++i){
_filePaths.push_back(path + _directory.getName(i));

ofFile file(path + _directory.getName(i));
if(_mediaType == SourceType::SOURCE_TYPE_VIDEO){
file.copyTo("sources/videos/" + _directory.getName(i));
}else if(_mediaType == SourceType::SOURCE_TYPE_IMAGE){
file.copyTo("sources/images/" + _directory.getName(i));
}
}
}

Expand All @@ -39,4 +46,4 @@ int DirectoryWatcher::getMediaType(){
}

} // namespace piMapper
} // namespace ofx
} // namespace ofx
88 changes: 18 additions & 70 deletions src/MediaServer/MediaServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,29 @@ namespace ofx {
namespace piMapper {

MediaServer::MediaServer():
videoWatcher(ofToDataPath(DEFAULT_VIDEOS_DIR, true), SourceType::SOURCE_TYPE_VIDEO),
piVideoWatcher(PI_IMAGES_DIR, SourceType::SOURCE_TYPE_VIDEO),
usb0VideoWatcher(USB0_VIDEOS_DIR, SourceType::SOURCE_TYPE_VIDEO),
usb1VideoWatcher(USB1_VIDEOS_DIR, SourceType::SOURCE_TYPE_VIDEO),
usb2VideoWatcher(USB2_VIDEOS_DIR, SourceType::SOURCE_TYPE_VIDEO),
usb3VideoWatcher(USB3_VIDEOS_DIR, SourceType::SOURCE_TYPE_VIDEO),
imageWatcher(ofToDataPath(DEFAULT_IMAGES_DIR, true), SourceType::SOURCE_TYPE_IMAGE),
piImageWatcher(PI_IMAGES_DIR, SourceType::SOURCE_TYPE_IMAGE),
usb0ImageWatcher(USB0_IMAGES_DIR, SourceType::SOURCE_TYPE_IMAGE),
usb1ImageWatcher(USB1_IMAGES_DIR, SourceType::SOURCE_TYPE_IMAGE),
usb2ImageWatcher(USB2_IMAGES_DIR, SourceType::SOURCE_TYPE_IMAGE),
usb3ImageWatcher(USB3_IMAGES_DIR, SourceType::SOURCE_TYPE_IMAGE)
usb3ImageWatcher(USB3_IMAGES_DIR, SourceType::SOURCE_TYPE_IMAGE),
imageWatcher(ofToDataPath(DEFAULT_IMAGES_DIR, true), SourceType::SOURCE_TYPE_IMAGE),
videoWatcher(ofToDataPath(DEFAULT_VIDEOS_DIR, true), SourceType::SOURCE_TYPE_VIDEO)
{
// What to do here?
// By initialising all above we also copy files from external media
// to the ofxPiMapper storage.

imageWatcher = DirectoryWatcher(
ofToDataPath(DEFAULT_IMAGES_DIR, true),
SourceType::SOURCE_TYPE_IMAGE);

videoWatcher = DirectoryWatcher(
ofToDataPath(DEFAULT_VIDEOS_DIR, true),
SourceType::SOURCE_TYPE_VIDEO);
}

void MediaServer::setup(){
Expand All @@ -39,63 +48,18 @@ void MediaServer::draw(){
}

int MediaServer::getNumImages(){
int numLocalImages = imageWatcher.getFilePaths().size();
int numPiImages = piImageWatcher.getFilePaths().size();
int numUsb0Images = usb0ImageWatcher.getFilePaths().size();
int numUsb1Images = usb1ImageWatcher.getFilePaths().size();
int numUsb2Images = usb2ImageWatcher.getFilePaths().size();
int numUsb3Images = usb3ImageWatcher.getFilePaths().size();

int sum =
numLocalImages +
numPiImages +
numUsb0Images +
numUsb1Images +
numUsb2Images +
numUsb3Images;

return sum;
return imageWatcher.getFilePaths().size();
}
int MediaServer::getNumVideos(){
int numLocalVideos = videoWatcher.getFilePaths().size();
int numPiVideos = piVideoWatcher.getFilePaths().size();
int numUsb0Videos = usb0VideoWatcher.getFilePaths().size();
int numUsb1Videos = usb1VideoWatcher.getFilePaths().size();
int numUsb2Videos = usb2VideoWatcher.getFilePaths().size();
int numUsb3Videos = usb3VideoWatcher.getFilePaths().size();

int sum =
numLocalVideos +
numPiVideos +
numUsb0Videos +
numUsb1Videos +
numUsb2Videos +
numUsb3Videos;

return sum;
return videoWatcher.getFilePaths().size();
}
int MediaServer::getNumFboSources(){
return fboSources.size();
}

vector <string> & MediaServer::getImagePaths(){
vector<string> & localPaths = imageWatcher.getFilePaths();
vector<string> & piPaths = piImageWatcher.getFilePaths();
vector<string> & usb0Paths = usb0ImageWatcher.getFilePaths();
vector<string> & usb1Paths = usb1ImageWatcher.getFilePaths();
vector<string> & usb2Paths = usb2ImageWatcher.getFilePaths();
vector<string> & usb3Paths = usb3ImageWatcher.getFilePaths();

_tempImagePaths.clear();

_tempImagePaths.insert(_tempImagePaths.end(), localPaths.begin(), localPaths.end());
_tempImagePaths.insert(_tempImagePaths.end(), piPaths.begin(), piPaths.end());
_tempImagePaths.insert(_tempImagePaths.end(), usb0Paths.begin(), usb0Paths.end());
_tempImagePaths.insert(_tempImagePaths.end(), usb1Paths.begin(), usb1Paths.end());
_tempImagePaths.insert(_tempImagePaths.end(), usb2Paths.begin(), usb2Paths.end());
_tempImagePaths.insert(_tempImagePaths.end(), usb3Paths.begin(), usb3Paths.end());

return _tempImagePaths;
return imageWatcher.getFilePaths();
}

vector <string> MediaServer::getImageNames(){
Expand All @@ -119,23 +83,7 @@ vector <string> MediaServer::getFboSourceNames(){
}

vector <string> & MediaServer::getVideoPaths(){
vector<string> & localPaths = videoWatcher.getFilePaths();
vector<string> & piPaths = piVideoWatcher.getFilePaths();
vector<string> & usb0Paths = usb0VideoWatcher.getFilePaths();
vector<string> & usb1Paths = usb1VideoWatcher.getFilePaths();
vector<string> & usb2Paths = usb2VideoWatcher.getFilePaths();
vector<string> & usb3Paths = usb3VideoWatcher.getFilePaths();

_tempVideoPaths.clear();

_tempVideoPaths.insert(_tempVideoPaths.begin(), localPaths.begin(), localPaths.end());
_tempVideoPaths.insert(_tempVideoPaths.begin(), piPaths.begin(), piPaths.end());
_tempVideoPaths.insert(_tempVideoPaths.begin(), usb0Paths.begin(), usb0Paths.end());
_tempVideoPaths.insert(_tempVideoPaths.begin(), usb1Paths.begin(), usb1Paths.end());
_tempVideoPaths.insert(_tempVideoPaths.begin(), usb2Paths.begin(), usb2Paths.end());
_tempVideoPaths.insert(_tempVideoPaths.begin(), usb3Paths.begin(), usb3Paths.end());

return _tempVideoPaths;
return videoWatcher.getFilePaths();
}

vector <string> MediaServer::getVideoNames(){
Expand Down Expand Up @@ -453,4 +401,4 @@ void MediaServer::unloadFboSource(string & fboSourceName){
} // unloadFboSource

} // namespace piMapper
} // namespace ofx
} // namespace ofx

0 comments on commit 7401408

Please sign in to comment.