Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Related Pages  

IEEE1394IO.hh

00001 /*
00002  * PIAVE - PIAVE Is A Video Editor
00003  *
00004  * Copyright (C) 2002 Rolf Dubitzky, rolf@dubitzky.de
00005  *
00006  */
00007 
00008 /*
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software Foundation,
00021  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00022  */
00023 
00024 
00030 #if ! defined( IEEE1394IO_HH )
00031 #define IEEE1394IO_HH
00032 
00033 // stdc
00034 #include <signal.h>
00035 #include <unistd.h>
00036 #include <fcntl.h>
00037 #include <sys/stat.h>
00038 #include <sys/time.h>
00039 
00040 // stdc++
00041 #include <string>
00042 
00043 // PIAVE
00044 #include "piave_base.hh"
00045 #include "mediaelements.hh"
00046 
00047 // IEEE1394
00048 #include <libraw1394/raw1394.h>
00049 #include <libraw1394/csr.h>
00050 #include <libdv/dv1394.h>
00051 // channel is 63 (broadcast) for video
00052 #define  AVC1394_CHANNEL_BROADCAST 63
00053 
00054 namespace PIAVE {
00055 
00056     class AVCController;
00057 
00058     class Raw1394Reader : public InAVStreamIFace
00059     {
00060       public:
00065         class FrameReciever
00066         {
00067           public:
00068             enum AccessMode { block, non_block };
00069 
00070             FrameReciever( int size = 250, int grow = 50 );
00071             ~FrameReciever();
00072             void        kick();
00073             void        push( Buffer * b );
00074             Buffer    * pop( AccessMode a );
00075             Buffer    * get( int i ) const { return _pool[i]; }
00076             int         getHeadIDX() { return _head; }
00077             
00078             bool isEmpty() const { return _head==_tail; }
00079             bool isFull()  const { int h=_head; inc(h); return h==_tail; }
00080             void clean();
00081 
00082             void inc( int & i ) const { if ( ++i == _size ) i = 0; }
00083 
00084             void switchOn()  { _on=true;  }
00085             void switchOff() { _on=false; }
00086             bool isOn() const { return _on; }
00087 
00088          private:
00089             void grow();
00090 
00091           private:
00092             Buffer         ** _pool;      /* the frames */
00093             int               _head;      /* head of ringbuffer */     
00094             int               _tail;      /* tail of ring */
00095             int               _size;      /* current size */
00096             int               _grow;      /* when buffer full, grow by grow */
00097 
00098             bool              _on;
00099 
00100             pthread_mutex_t   lock;           /* mutex ensuring exclusive access to buffer */
00101             pthread_cond_t    notempty;   /* signaled when buffer is not empty */
00102         };
00103 
00104       public:
00105         static Raw1394Reader * inst() { 
00106             if (!_singleton) _singleton = new Raw1394Reader();
00107             return _singleton; 
00108         }
00109 
00110         bool         isCapturing() const { return _isCapturing; }
00111 
00112         void startCapture();
00113         void stopCapture();
00114 
00119         int isoHandler( size_t, quadlet_t* );
00120 
00121 
00125         virtual void decodeMetaData( Frame & f );
00126         virtual void decodeVideo( Frame & f, uint8_t * dest = 0 );
00127         virtual void decodeAudio( Frame & f, uint8_t * dest = 0 );
00128         virtual Frame getFrame( Time t );
00129         virtual PropertyNode * getProperties( PropertyNode * p=0 ) const;
00130 
00131         /* consumers */
00132         int     addConsumer( FrameReciever * q ) { _consumers.push_back( q ); }
00133         
00134       private:
00135         Raw1394Reader();
00136         ~Raw1394Reader();
00137 
00141         static int _iso_handler( raw1394handle_t, int, size_t, quadlet_t* );
00142 
00143       private:
00144         static Raw1394Reader      * _singleton;
00145   
00146         Buffer          * _currentFrame;
00147         int               _currentFrameSize;
00148         int               _currentFrameExpectedSize;
00149 
00150         bool              _isCapturing;
00151 
00152         /* the consumers that want to process data */
00153         std::vector< FrameReciever* >   _consumers;
00154  
00155         static void     * _raw1394_poll( void * );
00156         pthread_t         _raw1394_poll_thread;
00157 
00158         AVDecoderIFace  * _dvDecoder;
00159     };
00160 
00161 
00162     class Raw1394Consumer
00163     {
00164       public:
00165         Raw1394Consumer();
00166         ~Raw1394Consumer();
00167 
00168 //         void addOutStream( OutAVStreamIFace * ostream );
00169 //         void addOutStream( OutAudioStreamIFace * ostream );
00170         void setOutStream( OutAVStreamIFace * ost ) { _outAVStreamIFace = ost; }
00171 
00172         void switchOn();
00173         void switchOff();
00174         void kick() { _frameQueue->kick(); }
00175 
00176       private:
00177 //         std::vector<OutAVStreamIFace *>      _outAVStreamIFaces;
00178 //         std::vector<OutAudioStreamIFace *>   _outAudioStreamIFaces;
00179 
00180         OutAVStreamIFace *      _outAVStreamIFace;
00181         Raw1394Reader::FrameReciever  * _frameQueue;
00182 
00183         void           raw1394Consume();
00184 
00185         static void * _raw1394_consume( void * );
00186         pthread_t     _raw1394_consumer_thread;
00187 
00188     };
00189 }
00190 
00191 #endif

Generated on Tue Oct 14 20:45:36 2003 for piave by doxygen1.2.18