From 962dd4cc979c9ded899bf7da147a50bb235279f0 Mon Sep 17 00:00:00 2001 From: Andy Dayton Date: Wed, 15 Nov 2017 17:15:57 -0600 Subject: [PATCH 1/2] Tentative fix to errors in new versions of oF related to ofPixels #5 --- example-project/src/testApp.cpp | 95 +++++++++++++++++++++++++++++++++ example-project/src/testApp.h | 27 ++++++++++ src/ofxAVFVideoPlayer.h | 26 ++++----- src/ofxAVFVideoPlayer.mm | 33 +++++++----- 4 files changed, 157 insertions(+), 24 deletions(-) create mode 100644 example-project/src/testApp.cpp create mode 100644 example-project/src/testApp.h diff --git a/example-project/src/testApp.cpp b/example-project/src/testApp.cpp new file mode 100644 index 0000000..6bc2d06 --- /dev/null +++ b/example-project/src/testApp.cpp @@ -0,0 +1,95 @@ +#include "testApp.h" + +//-------------------------------------------------------------- +void testApp::setup(){ + for(int i=0; iloadMovie("EmeliSande_NextToMe.mov"); + } + + + ofSetVerticalSync(true); + +} + +//-------------------------------------------------------------- +void testApp::update(){ + int i=0; + for(auto p : videoPlayers) { + p->update(); + if(true || p->isLoaded()) { + if(ofGetElapsedTimef() > i++ * 0.5) + p->play(); + } + } + + //cout << ofGetFrameRate() << endl; +} + +//-------------------------------------------------------------- +void testApp::draw(){ + int i=0; + for(auto p : videoPlayers) { + p->draw(ofMap(i++, 0, videoPlayers.size(), 0, ofGetWidth()), ofGetHeight()/2 - 108*2, 192*4, 108*4); + } + +} + +//-------------------------------------------------------------- +void testApp::keyPressed(int key){ + switch(key) { + case '1': + videoPlayers[0]->loadMovie("IntroVideo7.mov"); + break; + case '2': + videoPlayers[1]->loadMovie("TheLumineers_1.mov"); + break; + case '3': + videoPlayers[2]->loadMovie("EmeliSande_NextToMe.mov"); + break; + case '4': + videoPlayers[3]->loadMovie("iHRMF2012_SwedishHouseMafia_DontWorryChild.mov"); + break; + } +// videoPlayer2.loadMovie("IntroVideo7.mov"); +} + +//-------------------------------------------------------------- +void testApp::keyReleased(int key){ + +} + +//-------------------------------------------------------------- +void testApp::mouseMoved(int x, int y ){ + +} + +//-------------------------------------------------------------- +void testApp::mouseDragged(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void testApp::mousePressed(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void testApp::mouseReleased(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void testApp::windowResized(int w, int h){ + +} + +//-------------------------------------------------------------- +void testApp::gotMessage(ofMessage msg){ + +} + +//-------------------------------------------------------------- +void testApp::dragEvent(ofDragInfo dragInfo){ + +} \ No newline at end of file diff --git a/example-project/src/testApp.h b/example-project/src/testApp.h new file mode 100644 index 0000000..a326ba8 --- /dev/null +++ b/example-project/src/testApp.h @@ -0,0 +1,27 @@ +#pragma once + +#include "ofMain.h" +#include "ofxAVFVideoPlayer.h" + +class testApp : public ofBaseApp{ + + public: + void setup(); + void update(); + void draw(); + + void keyPressed (int key); + void keyReleased(int key); + void mouseMoved(int x, int y ); + void mouseDragged(int x, int y, int button); + void mousePressed(int x, int y, int button); + void mouseReleased(int x, int y, int button); + void windowResized(int w, int h); + void dragEvent(ofDragInfo dragInfo); + void gotMessage(ofMessage msg); + + std::vector videoPlayers; + static const int N_VIDEO_PLAYERS = 6; + + +}; diff --git a/src/ofxAVFVideoPlayer.h b/src/ofxAVFVideoPlayer.h index a28ada0..2038b9b 100644 --- a/src/ofxAVFVideoPlayer.h +++ b/src/ofxAVFVideoPlayer.h @@ -20,7 +20,8 @@ class ofxAVFVideoPlayer : public ofBaseVideoPlayer { ofxAVFVideoPlayer(); ~ofxAVFVideoPlayer(); - + + bool load(std::string name); bool loadMovie(string path); void closeMovie(); @@ -34,13 +35,14 @@ class ofxAVFVideoPlayer : public ofBaseVideoPlayer { OF_DEPRECATED_MSG("Use getTexture()->bind() instead. Ensure decodeMode != OF_QTKIT_DECODE_PIXELS_ONLY.", void bind()); OF_DEPRECATED_MSG("Use getTexture()->unbind() instead. Ensure decodeMode != OF_QTKIT_DECODE_PIXELS_ONLY.", void unbind()); - bool isFrameNew(); //returns true if the frame has changed in this update cycle - + bool isFrameNew() const; //returns true if the frame has changed in this update cycle + // Returns openFrameworks compatible RGBA pixels. // Be aware of your current render mode. - unsigned char * getPixels(); - ofPixelsRef getPixelsRef(); + ofPixels& getPixels(); + ofPixels& getPixels() const; + ofPixels& getPixelsRef(); // Returns openFrameworks compatible ofTexture pointer. // if decodeMode == OF_QTKIT_DECODE_PIXELS_ONLY, @@ -67,18 +69,18 @@ class ofxAVFVideoPlayer : public ofBaseVideoPlayer { // ofQTKitPlayer only supports OF_PIXELS_RGB and OF_PIXELS_RGBA. bool setPixelFormat(ofPixelFormat pixelFormat); - ofPixelFormat getPixelFormat(); - + ofPixelFormat getPixelFormat() const; + void draw(float x, float y, float w, float h); void draw(float x, float y); - float getWidth(); - float getHeight(); + float getWidth() const; + float getHeight() const; - bool isPaused(); - bool isLoaded(); + bool isPaused() const; + bool isLoaded() const; bool isLoading(); - bool isPlaying(); + bool isPlaying() const; bool errorLoading(); diff --git a/src/ofxAVFVideoPlayer.mm b/src/ofxAVFVideoPlayer.mm index 06da751..e53a7cb 100644 --- a/src/ofxAVFVideoPlayer.mm +++ b/src/ofxAVFVideoPlayer.mm @@ -27,6 +27,10 @@ close(); } +bool ofxAVFVideoPlayer::load(std::string name) { + // included this to get rid of build errors ¯\_(ツ)_/¯ +} + bool ofxAVFVideoPlayer::loadMovie(string path) { bInitialized = false; NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; @@ -97,22 +101,27 @@ [moviePlayer stop]; } -bool ofxAVFVideoPlayer::isFrameNew() { +bool ofxAVFVideoPlayer::isFrameNew() const { return true; } -unsigned char* ofxAVFVideoPlayer::getPixels() { - if(!moviePlayer || ![moviePlayer isReady] || !bInitialized) return NULL; +ofPixels& ofxAVFVideoPlayer::getPixels() { + if(!moviePlayer || ![moviePlayer isReady] || !bInitialized) return; if(bHavePixelsChanged) { fbo.readToPixels(pixels); bHavePixelsChanged = false; // Don't read pixels until next update() is called } - return pixels.getPixels(); + return pixels; } -ofPixelsRef ofxAVFVideoPlayer::getPixelsRef() { + +ofPixels& ofxAVFVideoPlayer::getPixels() const { + // included this to get rid of build errors ¯\_(ツ)_/¯ +} + +ofPixels& ofxAVFVideoPlayer::getPixelsRef() { getPixels(); return pixels; } @@ -194,7 +203,7 @@ } -ofPixelFormat ofxAVFVideoPlayer::getPixelFormat() { +ofPixelFormat ofxAVFVideoPlayer::getPixelFormat() const { } @@ -208,15 +217,15 @@ fbo.draw(x, y); } -float ofxAVFVideoPlayer::getWidth() { +float ofxAVFVideoPlayer::getWidth() const { return [moviePlayer getVideoSize].width; } -float ofxAVFVideoPlayer::getHeight() { +float ofxAVFVideoPlayer::getHeight() const { return [moviePlayer getVideoSize].height; } -bool ofxAVFVideoPlayer::isPaused() { +bool ofxAVFVideoPlayer::isPaused() const { return [moviePlayer player].rate == 0; } @@ -224,7 +233,7 @@ return [moviePlayer isLoading]; } -bool ofxAVFVideoPlayer::isLoaded() { +bool ofxAVFVideoPlayer::isLoaded() const { return bInitialized; } @@ -235,7 +244,7 @@ return (![moviePlayer isLoading] && ![moviePlayer isReady]); } -bool ofxAVFVideoPlayer::isPlaying() { +bool ofxAVFVideoPlayer::isPlaying() const { } @@ -257,4 +266,4 @@ void ofxAVFVideoPlayer::reallocatePixels() { -} \ No newline at end of file +} From 958fe322f3d3716e79524b948de67881610453f7 Mon Sep 17 00:00:00 2001 From: Andy Dayton Date: Wed, 15 Nov 2017 17:33:08 -0600 Subject: [PATCH 2/2] Remove extra example project (used for testing --- example-project/src/testApp.cpp | 95 --------------------------------- example-project/src/testApp.h | 27 ---------- 2 files changed, 122 deletions(-) delete mode 100644 example-project/src/testApp.cpp delete mode 100644 example-project/src/testApp.h diff --git a/example-project/src/testApp.cpp b/example-project/src/testApp.cpp deleted file mode 100644 index 6bc2d06..0000000 --- a/example-project/src/testApp.cpp +++ /dev/null @@ -1,95 +0,0 @@ -#include "testApp.h" - -//-------------------------------------------------------------- -void testApp::setup(){ - for(int i=0; iloadMovie("EmeliSande_NextToMe.mov"); - } - - - ofSetVerticalSync(true); - -} - -//-------------------------------------------------------------- -void testApp::update(){ - int i=0; - for(auto p : videoPlayers) { - p->update(); - if(true || p->isLoaded()) { - if(ofGetElapsedTimef() > i++ * 0.5) - p->play(); - } - } - - //cout << ofGetFrameRate() << endl; -} - -//-------------------------------------------------------------- -void testApp::draw(){ - int i=0; - for(auto p : videoPlayers) { - p->draw(ofMap(i++, 0, videoPlayers.size(), 0, ofGetWidth()), ofGetHeight()/2 - 108*2, 192*4, 108*4); - } - -} - -//-------------------------------------------------------------- -void testApp::keyPressed(int key){ - switch(key) { - case '1': - videoPlayers[0]->loadMovie("IntroVideo7.mov"); - break; - case '2': - videoPlayers[1]->loadMovie("TheLumineers_1.mov"); - break; - case '3': - videoPlayers[2]->loadMovie("EmeliSande_NextToMe.mov"); - break; - case '4': - videoPlayers[3]->loadMovie("iHRMF2012_SwedishHouseMafia_DontWorryChild.mov"); - break; - } -// videoPlayer2.loadMovie("IntroVideo7.mov"); -} - -//-------------------------------------------------------------- -void testApp::keyReleased(int key){ - -} - -//-------------------------------------------------------------- -void testApp::mouseMoved(int x, int y ){ - -} - -//-------------------------------------------------------------- -void testApp::mouseDragged(int x, int y, int button){ - -} - -//-------------------------------------------------------------- -void testApp::mousePressed(int x, int y, int button){ - -} - -//-------------------------------------------------------------- -void testApp::mouseReleased(int x, int y, int button){ - -} - -//-------------------------------------------------------------- -void testApp::windowResized(int w, int h){ - -} - -//-------------------------------------------------------------- -void testApp::gotMessage(ofMessage msg){ - -} - -//-------------------------------------------------------------- -void testApp::dragEvent(ofDragInfo dragInfo){ - -} \ No newline at end of file diff --git a/example-project/src/testApp.h b/example-project/src/testApp.h deleted file mode 100644 index a326ba8..0000000 --- a/example-project/src/testApp.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include "ofMain.h" -#include "ofxAVFVideoPlayer.h" - -class testApp : public ofBaseApp{ - - public: - void setup(); - void update(); - void draw(); - - void keyPressed (int key); - void keyReleased(int key); - void mouseMoved(int x, int y ); - void mouseDragged(int x, int y, int button); - void mousePressed(int x, int y, int button); - void mouseReleased(int x, int y, int button); - void windowResized(int w, int h); - void dragEvent(ofDragInfo dragInfo); - void gotMessage(ofMessage msg); - - std::vector videoPlayers; - static const int N_VIDEO_PLAYERS = 6; - - -};