Skip to content

Commit 2bd8b45

Browse files
authored
ofVideoPlayer using fs::path (#8138)
1 parent d9c11b9 commit 2bd8b45

16 files changed

+70
-70
lines changed

addons/ofxEmscripten/src/ofxEmscriptenVideoPlayer.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ ofxEmscriptenVideoPlayer::~ofxEmscriptenVideoPlayer() {
2828
html5video_player_delete(player_id);
2929
}
3030

31-
bool ofxEmscriptenVideoPlayer::load(string name){
31+
bool ofxEmscriptenVideoPlayer::load(const of::filesystem::path & fileName){
32+
std::string name = ofPathToString(fileName);
3233
if (name.substr(0, 7) == "http://" || name.substr(0, 8) == "https://"){
33-
html5video_player_load_url(player_id, name.c_str());
34+
html5video_player_load_url(player_id, fileName.c_str());
3435
} else{
35-
html5video_player_load(player_id, ofToDataPath(name).c_str());
36+
html5video_player_load(player_id, ofToDataPath(fileName).c_str());
3637
}
3738
return true;
3839
}

addons/ofxEmscripten/src/ofxEmscriptenVideoPlayer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ofxEmscriptenVideoPlayer: public ofBaseVideoPlayer {
1616
~ofxEmscriptenVideoPlayer();
1717

1818
//needs implementing
19-
bool load(const std::string fileName);
19+
bool load(const of::filesystem::path & fileName);
2020
void close();
2121
void update();
2222

addons/ofxiOS/src/video/ofxiOSVideoPlayer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ofxiOSVideoPlayer : public ofBaseVideoPlayer {
1515
void enableTextureCache();
1616
void disableTextureCache();
1717

18-
bool load(std::string name);
18+
bool load(const of::filesystem::path & fileName);
1919
void close();
2020
void update();
2121

@@ -62,7 +62,7 @@ class ofxiOSVideoPlayer : public ofBaseVideoPlayer {
6262
void * getAVFoundationVideoPlayer();
6363

6464
[[deprecated("use load()")]]
65-
bool loadMovie(std::string name);
65+
bool loadMovie(const of::filesystem::path & fileName);
6666
[[deprecated("use getPixels()")]]
6767
ofPixels & getPixelsRef();
6868
[[deprecated("use getPixels()")]]

addons/ofxiOS/src/video/ofxiOSVideoPlayer.mm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@
4141
}
4242

4343
//----------------------------------------
44-
bool ofxiOSVideoPlayer::load(string name) {
44+
bool ofxiOSVideoPlayer::load(const of::filesystem::path & fileName) {
4545

4646
if(!videoPlayer) {
4747
videoPlayer = (__bridge_retained void *)[[AVFoundationVideoPlayer alloc] init];
4848
[(__bridge AVFoundationVideoPlayer *)videoPlayer setWillBeUpdatedExternally:YES];
4949
}
5050

51-
NSString * videoPath = [NSString stringWithUTF8String:ofToDataPath(name).c_str()];
51+
NSString * videoPath = [NSString stringWithUTF8String:ofToDataPath(fileName).c_str()];
5252
[(__bridge AVFoundationVideoPlayer*)videoPlayer loadWithPath:videoPath];
5353

5454
bResetPixels = true;
@@ -589,8 +589,8 @@
589589
}
590590

591591
//---------------------------------------- DEPRECATED.
592-
bool ofxiOSVideoPlayer::loadMovie(string name) {
593-
return load(name);
592+
bool ofxiOSVideoPlayer::loadMovie(const of::filesystem::path & fileName) {
593+
return load(fileName);
594594
}
595595

596596
ofPixels & ofxiOSVideoPlayer::getPixelsRef() {

libs/openFrameworks/types/ofBaseTypes.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ ofBaseVideoPlayer::~ofBaseVideoPlayer(){
4747

4848
}
4949

50-
void ofBaseVideoPlayer::loadAsync(std::string name){
50+
void ofBaseVideoPlayer::loadAsync(const of::filesystem::path & fileName){
5151
ofLogWarning("ofBaseVideoPlayer") << "loadAsync() not implemented, loading synchronously";
52-
load(name);
52+
load(fileName);
5353
}
5454

5555
//---------------------------------------------------------------------------

libs/openFrameworks/video/ofAVFoundationPlayer.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ class ofAVFoundationPlayer : public ofBaseVideoPlayer {
2727
ofAVFoundationPlayer();
2828
~ofAVFoundationPlayer();
2929

30-
//FIXME: FS
31-
bool load(std::string name);
32-
void loadAsync(std::string name);
30+
bool load(const of::filesystem::path & fileName) override;
31+
void loadAsync(const of::filesystem::path & fileName) override;
3332
void close();
3433
void update();
3534

@@ -88,7 +87,7 @@ class ofAVFoundationPlayer : public ofBaseVideoPlayer {
8887
#endif
8988

9089
[[deprecated("use load()")]]
91-
bool loadMovie(std::string name);
90+
bool loadMovie(const of::filesystem::path & fileName);
9291
[[deprecated("use getPixels()")]]
9392
ofPixels & getPixelsRef();
9493
[[deprecated("use getPixels()")]]
@@ -98,7 +97,7 @@ class ofAVFoundationPlayer : public ofBaseVideoPlayer {
9897

9998
protected:
10099

101-
bool loadPlayer(std::string name, bool bAsync);
100+
bool loadPlayer(const of::filesystem::path & fileName, bool bAsync);
102101
void disposePlayer();
103102
bool isReady() const;
104103

libs/openFrameworks/video/ofAVFoundationPlayer.mm

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,31 +52,31 @@
5252
}
5353

5454
//--------------------------------------------------------------
55-
void ofAVFoundationPlayer::loadAsync(std::string name){
56-
loadPlayer(name, true);
55+
void ofAVFoundationPlayer::loadAsync(const of::filesystem::path & fileName){
56+
loadPlayer(fileName, true);
5757
}
5858

5959
//--------------------------------------------------------------
60-
bool ofAVFoundationPlayer::load(std::string name) {
61-
return loadPlayer(name, false);
60+
bool ofAVFoundationPlayer::load(const of::filesystem::path & fileName) {
61+
return loadPlayer(fileName, false);
6262
}
6363

6464
//--------------------------------------------------------------
65-
// FIXME: fs::path
66-
bool ofAVFoundationPlayer::loadPlayer(std::string name, bool bAsync) {
65+
bool ofAVFoundationPlayer::loadPlayer(const of::filesystem::path & fileName, bool bAsync) {
6766
if( ofGetUsingArbTex() == false ){
6867
killTextureCache();
6968
bUseTextureCache = false;
7069
}
7170

72-
NSString * videoPath = [NSString stringWithUTF8String:name.c_str()];
73-
NSString * videoLocalPath = [NSString stringWithUTF8String:ofToDataPath(name).c_str()];
71+
NSString * videoPath = [NSString stringWithUTF8String:fileName.c_str()];
72+
NSString * videoLocalPath = [NSString stringWithUTF8String:ofToDataPath(fileName).c_str()];
7473

7574
BOOL bStream = NO;
7675

77-
bStream = bStream || (ofIsStringInString(name, "http://"));
78-
bStream = bStream || (ofIsStringInString(name, "https://"));
79-
bStream = bStream || (ofIsStringInString(name, "rtsp://"));
76+
std::string fileNameStr { ofPathToString(fileName) };
77+
bStream = bStream || (ofIsStringInString(fileNameStr, "http://"));
78+
bStream = bStream || (ofIsStringInString(fileNameStr, "https://"));
79+
bStream = bStream || (ofIsStringInString(fileNameStr, "rtsp://"));
8080

8181
NSURL * url = nil;
8282
if(bStream == YES) {
@@ -762,8 +762,8 @@
762762
#endif
763763

764764
//-------------------------------------------------------------- DEPRECATED.
765-
bool ofAVFoundationPlayer::loadMovie(std::string name) {
766-
return load(name);
765+
bool ofAVFoundationPlayer::loadMovie(const of::filesystem::path & fileName) {
766+
return load(fileName);
767767
}
768768

769769
ofPixels & ofAVFoundationPlayer::getPixelsRef() {

libs/openFrameworks/video/ofDirectShowPlayer.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,9 +1146,8 @@ ofDirectShowPlayer & ofDirectShowPlayer::operator=(ofDirectShowPlayer&& other) {
11461146
return *this;
11471147
}
11481148

1149-
// FIXME: fs::path
1150-
bool ofDirectShowPlayer::load(std::string stringPath){
1151-
auto path = ofToDataPath(of::filesystem::path(stringPath));
1149+
bool ofDirectShowPlayer::load(const of::filesystem::path & fileName){
1150+
auto path = ofToDataPath(fileName);
11521151

11531152
close();
11541153
player.reset(new DirectShowVideo());

libs/openFrameworks/video/ofDirectShowPlayer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ofDirectShowPlayer : public ofBaseVideoPlayer{
2020
ofDirectShowPlayer(ofDirectShowPlayer &&);
2121
ofDirectShowPlayer & operator=(ofDirectShowPlayer&&);
2222

23-
bool load(std::string path);
23+
bool load(const of::filesystem::path & fileName) override;
2424
void update();
2525

2626
void close();

libs/openFrameworks/video/ofGstVideoPlayer.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,14 @@ bool ofGstVideoPlayer::createPipeline(std::string name){
187187
#endif
188188
}
189189

190-
void ofGstVideoPlayer::loadAsync(std::string name){
190+
void ofGstVideoPlayer::loadAsync(const of::filesystem::path & fileName){
191191
bAsyncLoad = true;
192-
load(name);
192+
load(fileName);
193193
}
194194

195195
// FIXME: fs::path
196-
bool ofGstVideoPlayer::load(std::string name){
196+
bool ofGstVideoPlayer::load(const of::filesystem::path & fileName){
197+
std::string name { ofPathToString(fileName) };
197198
if( name.find( "file://",0 ) != std::string::npos){
198199
bIsStream = bAsyncLoad;
199200
}else if( name.find( "://",0 ) == std::string::npos){
@@ -217,7 +218,7 @@ bool ofGstVideoPlayer::load(std::string name){
217218
internalPixelFormat = OF_PIXELS_NATIVE;
218219
bIsAllocated = false;
219220
videoUtils.reallocateOnNextFrame();
220-
g_object_set(G_OBJECT(videoUtils.getPipeline()), "uri", name.c_str(), (void*)NULL);
221+
g_object_set(G_OBJECT(videoUtils.getPipeline()), "uri", fileName.c_str(), (void*)NULL);
221222
gst_element_set_state (videoUtils.getPipeline(), GST_STATE_PAUSED);
222223
if(!bIsStream){
223224
gst_element_get_state (videoUtils.getPipeline(), NULL, NULL, -1);
@@ -227,7 +228,7 @@ bool ofGstVideoPlayer::load(std::string name){
227228
}
228229
}else{
229230
ofGstUtils::startGstMainLoop();
230-
return createPipeline(name) &&
231+
return createPipeline(fileName) &&
231232
videoUtils.startPipeline() &&
232233
(bIsStream || allocate());
233234
}

0 commit comments

Comments
 (0)