Browse Source

Add `OMXPlayerCache` singleton

A possible way to fix application crashing when unloading last omx player video source.
master
Krisjanis Rijnieks 9 years ago
parent
commit
6b2bc5ea81
  1. 42
      src/Sources/OMXPlayerCache.cpp
  2. 23
      src/Sources/OMXPlayerCache.h

42
src/Sources/OMXPlayerCache.cpp

@ -0,0 +1,42 @@
#include "OMXPlayerCache.h"
namespace ofx {
namespace piMapper {
OMXPlayerCache * OMXPlayerCache::_instance = 0;
OMXPlayerCache * OMXPlayerCache::instance(){
if(_instance == 0){
_instance = new ofx::piMapper::OMXPlayerCache();
}
return _instance;
}
ofxOMXPlayer * OMXPlayerCache::load(string moviePath){
if(_players.find(moviePath) == _players.end()){
ofxOMXPlayerSettings settings;
settings.videoPath = moviePath;
settings.useHDMIForAudio = true;
settings.enableTexture = true;
settings.enableLooping = true;
settings.enableAudio = VideoSource::enableAudio;
ofxOMXPlayer * p = new ofxOMXPlayer();
p->setup(settings);
_players.push_back(p);
return p;
}
_players[moviePath]->restartMovie();
return _players[moviePath];
}
void OMXPlayerCache::unload(string moviePath){
if(_players.find(moviePath) != _players.end()){
_players[moviePath]->setPaused(true);
}
}
} // namespace piMapper
} // namespace ofx

23
src/Sources/OMXPlayerCache.h

@ -0,0 +1,23 @@
#pragma once
#include "ofMain.h"
#include "ofxOMXPlayer.h"
namespace ofx {
namespace piMapper {
class OMXPlayerCache {
public:
static OMXPlayerCache * instance();
ofxOMXPlayer * load(string moviePath);
void unload(string moviePath);
private:
static OMXPlayerCache * _instance;
map <string, ofxOMXPlayer *> _players;
};
} // namespace piMapper
} // namespace ofx
Loading…
Cancel
Save