/* * This Software is the original work of Daniel TUNG * This Software is submitted in partial fulfillment of the * requirements for the degree of BCSE. * Dept. Computer Science, Monash University 2000 * * Copyright (c) 2000 beetung@cs.monash.edu.au * beetung@geocities.com * beetung@yahoo.com */ #ifndef CCC_STREAMER_H #define CCC_STREAMER_H #include #include #include #include "fastbuf.h" #include "bttv.h" #include "semaphore.h" //// //// This class encapsulate a streamer object. Its main job is to handle //// all the streaming video related tasks. //// // template ///////////////////////////////////////// class Streamer : public BaseSema { ///////////////////////////////////////// //// //// More like an Envenlop/Letter method. Implementing it this way //// minimizes alteration requried when introducing a new capture card. //// When another capture device comes along, only class BttvCapture is //// required to be re-coded. //// private: MySemaphore aSem; // this one should die with the object!!! // - to synchronize betwn bttv and isRead() BttvCapture bttv; public: Streamer(); ~Streamer(); void* Capture(void) { bttv.StartCapture(); return 0; } inline Fastbuf* grab1Frame() { return bttv.mmGrab1Frame(); } //---------------------- Fastbuf& GetCurrentFrame(void) { //---------------------- return bttv.GetCurrentFrame(); } /// block until a frame is ready as indicated /// by the semaphore //--------------------- void block (void) { SemWait();} void isReady (void) { SemWait();} //--------------------- //// not using this at the moment //--------------------- void *run(void) { isReady(); return 0;} //--------------------- }; /* :::::::::::::: COMMENTED OUT ::: BEGINS :::::::::::::::::::::::::::::: :::::::::::::: COMMENTED OUT ::: BEGINS :::::::::::::::::::::::::::::: :::::::::::::: COMMENTED OUT ::: BEGINS :::::::::::::::::::::::::::::: //// //// This class encapsulate a single frame along with its buffers //// and operations //// template ///////////////////////////////////////// class Frame { ///////////////////////////////////////// enum { GRABBER_BUFFER_SIZE_32BPP = 288*384*4 }; private: const bool bAlloc; // buf allocated by *this? const int bsize; // bufsize const int xSize, ySize; // size of buffer in terms of x,y Btype *buffer; // where to put image bool captured; // capture completed? int frame_id; // this frame id, (0-->30) public: //-------------------- Frame() : bsize(GRABBER_BUFFER_SIZE_32BPP),bAlloc(true), xSize(384),ySize(288),captured(false), frame_id(frameCount()++) { //-------------------- // cout << "ID: " << frame_id << endl; buffer = new Btype [bsize]; } //-------------------- Frame(Btype b) : captured(false), frame_id(frameCount()++),bAlloc(false), buffer(b) { //-------------------- // cout << "ID: " << frame_id << endl; } //-------------------- Frame(unsigned char * b) : captured(false), frame_id(frameCount()++),bAlloc(false), buffer((unsigned char*) b) { //-------------------- // cout << "ID: " << frame_id << endl; } //-------------------- ~Frame() { //-------------------- /// must delete buffer obviously!!! if (bAlloc) delete [] buffer; } /// /// reset flag so indicate as not-captured... /// //-------------------- void reset(void) { captured = false; } //-------------------- /// /// Various overloaded operators... /// //-------------------- operator bool (void) { return captured; } //-------------------- //-------------------- int* operator= (const Frame &b) { //-------------------- return (int*) &buf[0]; } //-------------------- static int& frameCount() { //-------------------- static int fCount =0; return fCount; } }; :::::::::::::: COMMENTED OUT ::: ENDS :::::::::::::::::::::::::::::: :::::::::::::: COMMENTED OUT ::: ENDS :::::::::::::::::::::::::::::: :::::::::::::: COMMENTED OUT ::: ENDS :::::::::::::::::::::::::::::: */ #endif