Created
July 7, 2014 18:27
-
-
Save jvcleave/cdaff9da3e1216f8ed1b to your computer and use it in GitHub Desktop.
VideoSource
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "ofMain.h" | |
class VideoSource | |
{ | |
public: | |
ofVideoGrabber camera; | |
ofVideoPlayer videoPlayer; | |
bool isCamera; | |
VideoSource() | |
{ | |
isCamera = false; | |
} | |
void setup(int width, int height) | |
{ | |
camera.initGrabber(width, height); | |
isCamera = true; | |
} | |
void setup(string videoPath) | |
{ | |
videoPlayer.loadMovie(videoPath); | |
videoPlayer.play(); | |
isCamera = false; | |
} | |
void update() | |
{ | |
if(isCamera) | |
{ | |
camera.update(); | |
}else | |
{ | |
videoPlayer.update(); | |
} | |
} | |
bool isFrameNew() | |
{ | |
bool isNew = false; | |
if(isCamera) | |
{ | |
isNew = camera.isFrameNew(); | |
}else | |
{ | |
isNew = videoPlayer.isFrameNew(); | |
} | |
return isNew; | |
} | |
ofBaseHasPixels& getSource() | |
{ | |
if(isCamera) | |
{ | |
return camera; | |
}else | |
{ | |
return videoPlayer; | |
} | |
} | |
void draw(int x, int y) | |
{ | |
if(isCamera) | |
{ | |
camera.draw(x, y); | |
}else | |
{ | |
videoPlayer.draw(x, y); | |
} | |
} | |
int getWidth() | |
{ | |
int width = 0; | |
if(isCamera) | |
{ | |
width = camera.getWidth(); | |
}else | |
{ | |
width = videoPlayer.getWidth(); | |
} | |
return width; | |
} | |
int getHeight() | |
{ | |
int height = 0; | |
if(isCamera) | |
{ | |
height = camera.getHeight(); | |
}else | |
{ | |
height = videoPlayer.getHeight(); | |
} | |
return height; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment