Skip to content

Commit

Permalink
Merge pull request #7 from i-n-g-o/memory_fixes
Browse files Browse the repository at this point in the history
Memory fixes with audio loading
  • Loading branch information
prisonerjohn committed Mar 15, 2015
2 parents 3700e1f + ab38763 commit d2d6dba
Show file tree
Hide file tree
Showing 8 changed files with 301 additions and 136 deletions.
3 changes: 3 additions & 0 deletions example-audioData/src/testApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ void testApp::setup()
{
ofSetVerticalSync(true);

// explicitly tell it to load audio (default)
videoPlayer.setShouldLoadAudio(true);

// videoPlayer.loadMovie("Casey_You_need_noise.mov");
// videoPlayer.loadMovie("fingers.mov");
videoPlayer.loadMovie("cat.mp4");
Expand Down
4 changes: 2 additions & 2 deletions example/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
int main()
{
ofAppGlutWindow window;
ofSetupOpenGL(&window, 1920, 1080, OF_WINDOW);
ofRunApp(new testApp());
ofSetupOpenGL(&window, 1920, 1080, OF_WINDOW);
ofRunApp(new testApp());
}
52 changes: 49 additions & 3 deletions example/src/testApp.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
#include "testApp.h"

// cleanup
testApp::~testApp()
{
ofLogNotice() << "cleanup";
deleteMovie();
}

//--------------------------------------------------------------
void testApp::setup()
{
ofSetVerticalSync(true);
ofBackground(0);


videop = NULL;

// explicitly tell it to load audio (default)
video.setShouldLoadAudio(true);

video.loadMovie("test.mov");
video.play();
video.setLoopState(OF_LOOP_NORMAL);
Expand All @@ -21,14 +33,18 @@ void testApp::update()
if (video.isFrameNew()) {
image.setFromPixels(video.getPixelsRef());
}

if (videop != NULL) {
videop->update();
}
}

//--------------------------------------------------------------
void testApp::draw()
{
video.draw(0, 0);
if(image.bAllocated()){
image.draw(video.getWidth(), 0);
if(image.bAllocated()){
image.draw(video.getWidth(), 0);
}

// Draw a timeline at the bottom of the screen.
Expand Down Expand Up @@ -77,12 +93,42 @@ void testApp::keyPressed(int key)
case OF_KEY_DOWN:
video.setSpeed(video.getSpeed() * 0.9);
break;

case 'c':
ofLogNotice() << "create a new movie";

deleteMovie();

//create video
videop = new ofxAVFVideoPlayer;
videop->setShouldLoadAudio(true);

videop->loadMovie("test.mov");

// dont start the movie
// it will get cleaned up anyway
// videop->play();
break;


case 'd':
//destroy video
ofLogNotice() << "destroy the movie";
deleteMovie();

default:
break;
}
}

//--------------------------------------------------------------
void testApp::deleteMovie(){
if (videop != NULL) {
delete videop;
videop = NULL;
}
}

//--------------------------------------------------------------
void testApp::keyReleased(int key){

Expand Down
35 changes: 21 additions & 14 deletions example/src/testApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,28 @@

class testApp : public ofBaseApp
{
public:
void setup();
void update();
void draw();
public:

~testApp();

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);

void deleteMovie();

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);

ofxAVFVideoPlayer video;
ofImage image;

ofxAVFVideoPlayer* videop;
};
13 changes: 8 additions & 5 deletions src/ofxAVFVideoPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ofxAVFVideoPlayer : public ofBaseVideoPlayer {
float getAmplitudeAt(float pos, int channel = 0);
float * getAllAmplitudes();
int getNumAmplitudes();
bool isFrameNew(); //returns true if the frame has changed in this update cycle

// Returns openFrameworks compatible RGBA pixels.
Expand All @@ -52,6 +52,8 @@ class ofxAVFVideoPlayer : public ofBaseVideoPlayer {

bool isLoading();
bool isLoaded();
bool shouldLoadAudio();
void setShouldLoadAudio(bool doLoadAudio);
bool isAudioLoaded();
bool errorLoading();

Expand All @@ -70,7 +72,7 @@ class ofxAVFVideoPlayer : public ofBaseVideoPlayer {
float getVolume();

void setPosition(float pct);
void setTime(float seconds);
void setTime(float seconds);
void setPositionInSeconds(float seconds);
void setFrame(int frame); // frame 0 = first frame...
void setBalance(float balance);
Expand Down Expand Up @@ -100,9 +102,10 @@ class ofxAVFVideoPlayer : public ofBaseVideoPlayer {
bool bTheFutureIsNow;

bool bPaused;
bool bShouldPlay;

float scrubToTime;
bool bShouldPlay;
bool bShouldLoadAudio;

float scrubToTime;
bool bNewFrame;
bool bHavePixelsChanged;

Expand Down
Loading

0 comments on commit d2d6dba

Please sign in to comment.