Skip to content

Commit

Permalink
implements setPixelFormat and getPixelFormat properly and with checks…
Browse files Browse the repository at this point in the history
… for if format is supported. also reallocates video texture if pixel format has changed. still need win and linux implement and videoGrabber texture check.
  • Loading branch information
ofTheo committed Aug 31, 2012
1 parent f330046 commit a0fb4ac
Show file tree
Hide file tree
Showing 14 changed files with 160 additions and 69 deletions.
31 changes: 16 additions & 15 deletions libs/openFrameworks/types/ofBaseTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ void ofBaseVideoGrabber::videoSettings(){
}

//---------------------------------------------------------------------------
void ofBaseVideoGrabber::setPixelFormat(ofPixelFormat pixelFormat){
ofLog(OF_LOG_WARNING, "ofBaseVideoGrabber::setPixelFormat not implemented");
}

ofPixelFormat ofBaseVideoGrabber::getPixelFormat(){
ofLog(OF_LOG_WARNING, "ofBaseVideoGrabber::getPixelFormat not implemented");
return OF_PIXELS_RGB;
}
//void ofBaseVideoGrabber::setPixelFormat(ofPixelFormat pixelFormat){
// ofLog(OF_LOG_WARNING, "ofBaseVideoGrabber::setPixelFormat not implemented");
//}
//
//ofPixelFormat ofBaseVideoGrabber::getPixelFormat(){
// ofLog(OF_LOG_WARNING, "ofBaseVideoGrabber::getPixelFormat not implemented");
// return OF_PIXELS_RGB;
//}

//---------------------------------------------------------------------------

Expand Down Expand Up @@ -131,12 +131,13 @@ void ofBaseVideoPlayer::nextFrame(){
void ofBaseVideoPlayer::previousFrame(){
ofLog(OF_LOG_WARNING, "ofBaseVideoPlayer::previousFrame not implemented");
}

//---------------------------------------------------------------------------
void ofBaseVideoPlayer::setPixelFormat(ofPixelFormat pixelFormat){
ofLog(OF_LOG_WARNING, "ofBaseVideoPlayer::setPixelFormat not implemented");
}
//void ofBaseVideoPlayer::setPixelFormat(ofPixelFormat pixelFormat){
// ofLog(OF_LOG_WARNING, "ofBaseVideoPlayer::setPixelFormat not implemented");
//}
//---------------------------------------------------------------------------
ofPixelFormat ofBaseVideoPlayer::getPixelFormat(){
ofLog(OF_LOG_WARNING, "ofBaseVideoPlayer::getPixelFormat not implemented");
return OF_PIXELS_RGB;
}
//ofPixelFormat ofBaseVideoPlayer::getPixelFormat(){
// ofLog(OF_LOG_WARNING, "ofBaseVideoPlayer::getPixelFormat not implemented");
// return OF_PIXELS_RGB;
//}
10 changes: 6 additions & 4 deletions libs/openFrameworks/types/ofBaseTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,14 @@ class ofBaseVideoGrabber: virtual public ofBaseVideo{
virtual float getHeight() = 0;
virtual float getWidth() = 0;

virtual bool setPixelFormat(ofPixelFormat pixelFormat) = 0;
virtual ofPixelFormat getPixelFormat() = 0;

//should implement!
virtual void setVerbose(bool bTalkToMe);
virtual void setDeviceID(int _deviceID);
virtual void setDesiredFrameRate(int framerate);
virtual void videoSettings();
virtual void setPixelFormat(ofPixelFormat pixelFormat);
virtual ofPixelFormat getPixelFormat();

};

Expand Down Expand Up @@ -241,6 +242,9 @@ class ofBaseVideoPlayer: virtual public ofBaseVideo{
virtual bool isLoaded() = 0;
virtual bool isPlaying() = 0;

virtual bool setPixelFormat(ofPixelFormat pixelFormat) = 0;
virtual ofPixelFormat getPixelFormat() = 0;

//should implement!
virtual float getPosition();
virtual float getSpeed();
Expand All @@ -261,8 +265,6 @@ class ofBaseVideoPlayer: virtual public ofBaseVideo{
virtual void firstFrame();
virtual void nextFrame();
virtual void previousFrame();
virtual void setPixelFormat(ofPixelFormat pixelFormat);
virtual ofPixelFormat getPixelFormat();
};

//----------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion libs/openFrameworks/video/ofQTKitGrabber.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ofQTKitGrabber : public ofBaseVideoGrabber {
int getAudioDeviceID();

void setDesiredFrameRate(int framerate){ ofLog(OF_LOG_WARNING, "ofQTKitGrabber -- Cannot specify framerate."); }
void setPixelFormat(ofPixelFormat pixelFormat);
bool setPixelFormat(ofPixelFormat pixelFormat);
ofPixelFormat getPixelFormat();
bool hasPreview();
void videoSettings();
Expand Down
17 changes: 12 additions & 5 deletions libs/openFrameworks/video/ofQTKitGrabber.mm
Original file line number Diff line number Diff line change
Expand Up @@ -803,16 +803,23 @@ - (void) dealloc
listVideoDevices();
}

void ofQTKitGrabber::setPixelFormat(ofPixelFormat pixelFormat){
if(pixelFormat != OF_PIXELS_RGB){
ofLogWarning("ofQTKitGrabber") << " Only supports pixel format OF_PIXELS_RGB" << endl;
}
//---------------------------------------------------------------------------
bool ofQTKitGrabber::setPixelFormat(ofPixelFormat pixelFormat){
//note as we only support RGB we are just confirming that this pixel format is supported
if( pixelFormat == OF_PIXELS_RGB ){
return true;
}
ofLogWarning("ofQTKitGrabber") << "requested pixel format not supported" << endl;
return false;
}

//---------------------------------------------------------------------------
ofPixelFormat ofQTKitGrabber::getPixelFormat(){
return OF_PIXELS_RGB;
//note if you support more than one pixel format you will need to return a ofPixelFormat variable.
return OF_PIXELS_RGB;
}

//---------------------------------------------------------------------------
vector<string>& ofQTKitGrabber::listVideoDevices(){

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
Expand Down
4 changes: 3 additions & 1 deletion libs/openFrameworks/video/ofQTKitPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ class ofQTKitPlayer : public ofBaseVideoPlayer {
void setLoopState(ofLoopType state);
void setSpeed(float speed);
void setFrame(int frame); // frame 0 = first frame...
void setPixelFormat(ofPixelFormat pixelFormat);

bool setPixelFormat(ofPixelFormat pixelFormat);
ofPixelFormat getPixelFormat();

ofQTKitDecodeMode getDecodeMode();

//Enabling synchronous scrubbing ensures that any call to setFrame, setPosition or jump to position
Expand Down
9 changes: 5 additions & 4 deletions libs/openFrameworks/video/ofQTKitPlayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,10 @@
return moviePlayer.movieSize.height;
}

void ofQTKitPlayer::setPixelFormat(ofPixelFormat newPixelFormat){
bool ofQTKitPlayer::setPixelFormat(ofPixelFormat newPixelFormat){
if(newPixelFormat != OF_PIXELS_RGB && newPixelFormat != OF_PIXELS_RGBA) {
ofLogError("ofQTKitPlayer::setPixelFormat -- Pixel format " + ofToString(newPixelFormat) + " is not supported");
return;
ofLogWarning("ofQTKitPlayer") << "setPixelFormat -- Pixel format " << ofToString(newPixelFormat) << " is not supported";
return false;
}

if(newPixelFormat != pixelFormat){
Expand All @@ -389,7 +389,8 @@
if(isLoaded()){
loadMovie(moviePath, decodeMode);
}
}
}
return true;
}

ofPixelFormat ofQTKitPlayer::getPixelFormat(){
Expand Down
16 changes: 16 additions & 0 deletions libs/openFrameworks/video/ofQuickTimeGrabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,22 @@ void ofQuickTimeGrabber::setDesiredFrameRate(int framerate){
attemptFramerate = framerate;
}

//---------------------------------------------------------------------------
bool ofQuickTimeGrabber::setPixelFormat(ofPixelFormat pixelFormat){
//note as we only support RGB we are just confirming that this pixel format is supported
if( pixelFormat == OF_PIXELS_RGB ){
return true;
}
ofLogWarning("ofQuickTimeGrabber") << "requested pixel format not supported" << endl;
return false;
}

//---------------------------------------------------------------------------
ofPixelFormat ofQuickTimeGrabber::getPixelFormat(){
//note if you support more than one pixel format you will need to return a ofPixelFormat variable.
return OF_PIXELS_RGB;
}

//--------------------------------------------------------------------
bool ofQuickTimeGrabber::initGrabber(int w, int h){

Expand Down
3 changes: 3 additions & 0 deletions libs/openFrameworks/video/ofQuickTimeGrabber.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class ofQuickTimeGrabber : public ofBaseVideoGrabber{
void update();
bool isFrameNew();

bool setPixelFormat(ofPixelFormat pixelFormat);
ofPixelFormat getPixelFormat();

unsigned char * getPixels();
ofPixelsRef getPixelsRef();

Expand Down
25 changes: 18 additions & 7 deletions libs/openFrameworks/video/ofQuickTimePlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
#include "ofUtils.h"

#ifndef TARGET_LINUX
//--------------------------------------------------------------
#ifdef OF_VIDEO_PLAYER_QUICKTIME
//--------------------------------------------------------------

bool createMovieFromPath(char * path, Movie &movie);
bool createMovieFromPath(char * path, Movie &movie){
Expand Down Expand Up @@ -101,11 +99,6 @@ OSErr DrawCompleteProc(Movie theMovie, long refCon){
return noErr;
}

//--------------------------------------------------------------
#endif
//--------------------------------------------------------------


//---------------------------------------------------------------------------
ofQuickTimePlayer::ofQuickTimePlayer (){

Expand Down Expand Up @@ -669,6 +662,22 @@ int ofQuickTimePlayer::getCurrentFrame(){

}

//---------------------------------------------------------------------------
bool ofQuickTimePlayer::setPixelFormat(ofPixelFormat pixelFormat){
//note as we only support RGB we are just confirming that this pixel format is supported
if( pixelFormat == OF_PIXELS_RGB ){
return true;
}
ofLogWarning("ofQuickTimePlayer") << "requested pixel format not supported" << endl;
return false;
}

//---------------------------------------------------------------------------
ofPixelFormat ofQuickTimePlayer::getPixelFormat(){
//note if you support more than one pixel format you will need to return a ofPixelFormat variable.
return OF_PIXELS_RGB;
}


//---------------------------------------------------------------------------
bool ofQuickTimePlayer::getIsMovieDone(){
Expand Down Expand Up @@ -842,4 +851,6 @@ bool ofQuickTimePlayer::isPlaying(){

#endif

#endif


25 changes: 11 additions & 14 deletions libs/openFrameworks/video/ofQuickTimePlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

#ifdef OF_VIDEO_PLAYER_QUICKTIME
#include "ofQtUtils.h"
#endif


class ofQuickTimePlayer : public ofBaseVideoPlayer{

Expand All @@ -25,6 +23,9 @@ class ofQuickTimePlayer : public ofBaseVideoPlayer{
void stop();

void clearMemory();

bool setPixelFormat(ofPixelFormat pixelFormat);
ofPixelFormat getPixelFormat();

bool isFrameNew();
unsigned char * getPixels();
Expand Down Expand Up @@ -82,21 +83,17 @@ class ofQuickTimePlayer : public ofBaseVideoPlayer{
bool bIsFrameNew; // if we are new
float speed;

//--------------------------------------
#ifdef OF_VIDEO_PLAYER_QUICKTIME
//--------------------------------------
MovieDrawingCompleteUPP myDrawCompleteProc;
MovieController thePlayer;
GWorldPtr offscreenGWorld;
Movie moviePtr;
unsigned char * offscreenGWorldPixels; // 32 bit: argb (qt k32ARGBPixelFormat)
void qtGetFrameCount(Movie & movForcount);
//--------------------------------------
#endif
//--------------------------------------
MovieDrawingCompleteUPP myDrawCompleteProc;
MovieController thePlayer;
GWorldPtr offscreenGWorld;
Movie moviePtr;
unsigned char * offscreenGWorldPixels; // 32 bit: argb (qt k32ARGBPixelFormat)
void qtGetFrameCount(Movie & movForcount);

};

#endif




Expand Down
37 changes: 28 additions & 9 deletions libs/openFrameworks/video/ofVideoGrabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
ofVideoGrabber::ofVideoGrabber(){
bUseTexture = false;
bInitialized = false;
grabberRunning = false;
RequestedDeviceID = -1;
internalPixelFormat = OF_PIXELS_RGB;
desiredFramerate = -1;
Expand Down Expand Up @@ -62,17 +63,17 @@ bool ofVideoGrabber::initGrabber(int w, int h, bool setUseTexture){
grabber->setDeviceID(RequestedDeviceID);
}

grabber->setPixelFormat(internalPixelFormat);
setPixelFormat(internalPixelFormat); //this safely handles checks for supported format

if( desiredFramerate!=-1 ){
grabber->setDesiredFrameRate(desiredFramerate);
}

bool bOk = grabber->initGrabber(w, h);
width = (int)grabber->getWidth();
height = (int)grabber->getHeight();
grabberRunning = grabber->initGrabber(w, h);
width = (int)grabber->getWidth();
height = (int)grabber->getHeight();

if( bOk && bUseTexture ){
if( grabberRunning && bUseTexture ){
if(internalPixelFormat == OF_PIXELS_RGB)
tex.allocate(width, height, GL_RGB);
else if(internalPixelFormat == OF_PIXELS_RGBA)
Expand All @@ -87,16 +88,33 @@ bool ofVideoGrabber::initGrabber(int w, int h, bool setUseTexture){
#endif
}

return bOk;
return grabberRunning;
}

//--------------------------------------------------------------------
void ofVideoGrabber::setPixelFormat(ofPixelFormat pixelFormat) {
internalPixelFormat = pixelFormat;
bool ofVideoGrabber::setPixelFormat(ofPixelFormat pixelFormat) {
internalPixelFormat = pixelFormat;
if( grabber != NULL ){
if( grabberRunning ){
ofLogWarning("ofVideoGrabber") << "setPixelFormat - can't be called while the grabber is running ";
internalPixelFormat = grabber->getPixelFormat();
return false;
}else{
if( !grabber->setPixelFormat(internalPixelFormat) ){
internalPixelFormat = grabber->getPixelFormat();
return false;
}
}
}
return true;
}

//---------------------------------------------------------------------------
ofPixelFormat ofVideoGrabber::getPixelFormat(){
return grabber->getPixelFormat();
if( grabber != NULL ){
internalPixelFormat = grabber->getPixelFormat();
}
return internalPixelFormat;
}

//--------------------------------------------------------------------
Expand Down Expand Up @@ -188,6 +206,7 @@ void ofVideoGrabber::close(){
if( grabber != NULL ){
grabber->close();
bInitialized=false;
grabberRunning = false;
}
tex.clear();
}
Expand Down
5 changes: 4 additions & 1 deletion libs/openFrameworks/video/ofVideoGrabber.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class ofVideoGrabber : public ofBaseVideoGrabber,public ofBaseVideoDraws{
void close();
bool initGrabber(int w, int h){return initGrabber(w,h,true);}
bool initGrabber(int w, int h, bool bTexture);
void setPixelFormat(ofPixelFormat pixelFormat);

bool setPixelFormat(ofPixelFormat pixelFormat);
ofPixelFormat getPixelFormat();

void videoSettings();
Expand Down Expand Up @@ -92,6 +93,8 @@ class ofVideoGrabber : public ofBaseVideoGrabber,public ofBaseVideoDraws{
ofPtr<ofBaseVideoGrabber> grabber;
int RequestedDeviceID;

bool grabberRunning; //this keeps track of whether the grabber opened sucessfully and is still open. //TODO: maybe expose this in a method?

ofPixelFormat internalPixelFormat;
int desiredFramerate;
};
Expand Down
Loading

0 comments on commit a0fb4ac

Please sign in to comment.