Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

ieee1394io.h

Go to the documentation of this file.
00001 /*
00002 * ieee1394io.cc -- asynchronously grabbing DV data
00003 * Copyright (C) 2000 Arne Schirmacher <arne@schirmacher.de>
00004 * Copyright (C) 2001-2007 Dan Dennedy <dan@dennedy.org>
00005 *
00006 * This program is free software; you can redistribute it and/or modify
00007 * it under the terms of the GNU General Public License as published by
00008 * the Free Software Foundation; either version 2 of the License, or
00009 * (at your option) any later version.
00010 *
00011 * This program is distributed in the hope that it will be useful,
00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 * GNU General Public License for more details.
00015 *
00016 * You should have received a copy of the GNU General Public License
00017 * along with this program; if not, write to the Free Software Foundation,
00018 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00019 */
00020 
00021 #ifndef _IEEE1394IO_H
00022 #define _IEEE1394IO_H 1
00023 
00024 #include <libraw1394/raw1394.h>
00025 #include <libraw1394/csr.h>
00026 #ifdef HAVE_IEC61883
00027 #include <libiec61883/iec61883.h>
00028 #endif
00029 #ifdef HAVE_DV1394
00030 #include "dv1394.h"
00031 #endif
00032 
00033 #include <string>
00034 using std::string;
00035 #include <deque>
00036 using std::deque;
00037 
00038 class Frame;
00039 
00040 class IEEE1394Reader
00041 {
00042 protected:
00045     int droppedFrames;
00046 
00048     Frame   *currentFrame;
00049 
00051     deque < Frame* > inFrames;
00052 
00054     deque < Frame* > outFrames;
00055 
00056 public:
00057 
00058     IEEE1394Reader( int chn = 63, int frames = 50 );
00059     virtual ~IEEE1394Reader();
00060 
00061     // Mutex protected public methods
00062     virtual bool StartThread( int port = 0 ) = 0;
00063     virtual void StopThread( void ) = 0;
00064     Frame* GetFrame( void );
00065     void DoneWithFrame( Frame* );
00066     int GetDroppedFrames( void );
00067     int GetOutQueueSize( void )
00068     {
00069         return outFrames.size();
00070     }
00071     int GetInQueueSize( void )
00072     {
00073         return inFrames.size();
00074     }
00075     void ResetDroppedFrames( void )
00076     {
00077         droppedFrames = 0;
00078     }
00079 
00080     // These two public methods are not mutex protected
00081     virtual bool Open( int port = 0 ) = 0;
00082     virtual void Close( void ) = 0;
00083 
00084     bool WaitForAction( int seconds = 0 );
00085     void TriggerAction( );
00086 
00087     virtual bool StartReceive( void ) = 0;
00088     virtual void StopReceive( void ) = 0;
00089 
00090 protected:
00092     int channel;
00093 
00095     pthread_t thread;
00096 
00099     pthread_mutex_t mutex;
00100 
00101     // This condition and mutex are used to indicate when new frames are
00102     // received
00103     pthread_mutex_t condition_mutex;
00104     pthread_cond_t condition;
00105 
00107     bool isRunning;
00108 
00109     void Flush( void );
00110 };
00111 
00112 
00113 #ifdef HAVE_IEC61883
00114 class iec61883Reader: public IEEE1394Reader
00115 {
00116 private:
00118     raw1394handle_t m_handle;
00119 
00121     iec61883_dv_fb_t m_iec61883dv;
00122 
00123 public:
00124 
00125     iec61883Reader( int channel = 63, int buffers = 50 );
00126     ~iec61883Reader();
00127 
00128     bool Open( int port );
00129     void Close( void );
00130     bool StartReceive( void );
00131     void StopReceive( void );
00132     bool StartThread( int port );
00133     void StopThread( void );
00134     int Handler( int length, int complete, unsigned char *data );
00135     void *Thread();
00136     void ResetHandler( void );
00137 
00138 private:
00139     static int ResetHandlerProxy( raw1394handle_t handle, unsigned int generation );
00140     static int HandlerProxy( unsigned char *data, int length, int complete, 
00141         void *callback_data );
00142     static void* ThreadProxy( void *arg );
00143 };
00144 #endif
00145 
00146 
00147 #ifdef HAVE_DV1394
00148 class dv1394Reader: public IEEE1394Reader
00149 {
00150 private:
00151 
00152     unsigned char *m_dv1394_map;
00153     int m_dv1394_fd;
00154 
00155 public:
00156 
00157     dv1394Reader( int chn = 63, int frames = 50 );
00158     ~dv1394Reader();
00159 
00160     bool Open( int port );
00161     void Close( void );
00162     bool StartReceive( void );
00163     void StopReceive( void );
00164     bool StartThread( int port ); // port ignored
00165     void StopThread( void );
00166     void* Thread( );
00167 
00168 private:
00169     bool Handler( int handle );
00170     static void* ThreadProxy( void *arg );
00171 };
00172 #endif
00173 
00174 
00175 class AVC
00176 {
00177 private:
00179     int port;
00180     int totalPorts;
00181 
00184     pthread_mutex_t avc_mutex;
00185 
00187     raw1394handle_t avc_handle;
00188 
00189 public:
00190     AVC( void );
00191     ~AVC();
00192 
00193     int isPhyIDValid( int id );
00194     void Noop( void );
00195     int Play( int id );
00196     int Pause( int id );
00197     int Stop( int id );
00198     int FastForward( int id );
00199     int Rewind( int id );
00200     int Forward( int id );
00201     int Back( int id );
00202     int NextScene( int id );
00203     int PreviousScene( int id );
00204     int Record( int id );
00205     int Shuttle( int id, int speed );
00206     unsigned int TransportStatus( int id );
00207     bool Timecode( int id, char* timecode );
00208     int getNodeId( const char *guid );
00209     int getPort( ) const
00210     {
00211         return port;
00212     }
00213 
00214 private:
00215     static int ResetHandler( raw1394handle_t handle, unsigned int generation );
00216 
00217 };
00218 
00219 class IEEE1394Writer
00220 {
00221 protected:
00222     bool m_isInitialised;
00223     unsigned int m_channel;
00224     unsigned int m_nBuffers;
00225     deque< Frame* > m_deque;
00226     pthread_t m_thread;
00227 
00230     pthread_mutex_t m_dequeMutex;
00231 
00234     pthread_mutex_t m_conditionMutex;
00235     pthread_cond_t m_condition;
00236 
00238     bool m_isRunning;
00239 
00240 public:
00241     IEEE1394Writer();
00242     virtual ~IEEE1394Writer();
00243 
00244     void StartThread();
00245     void StopThread();
00246     int WaitForAction( bool isBlocking, int seconds = 1 );
00247     void TriggerAction();
00248 
00249     virtual bool SendFrame( Frame &frame, bool isBlocking = true ) = 0;
00250     virtual bool isValid() = 0;
00251     virtual void* Thread() = 0;
00252 
00253 private:
00254     static void* ThreadProxy( void *arg );
00255 };
00256 
00257 
00258 #ifdef HAVE_IEC61883
00259 class iec61883Writer : public IEEE1394Writer
00260 {
00261 private:
00262     int m_port;
00263     raw1394handle_t m_handle;
00264     iec61883_dv_t m_iec61883dv;
00265     unsigned char* m_data;
00266     int m_index;
00267     bool m_isSilent;
00268     bool m_isReset;
00269 
00270 public:
00271 
00272     iec61883Writer( int port, unsigned int channel, unsigned int nBuffers );
00273     ~iec61883Writer();
00274     bool SendFrame( Frame &frame, bool isBlocking = true );
00275     bool isValid( void )
00276     {
00277         return ( !m_isInitialised || ( m_isInitialised && m_iec61883dv != NULL ) );
00278     }
00279     int Handler( unsigned char *data, int n_dif_blocks, unsigned int dropped );
00280     void* Thread();
00281     void ResetHandler( void );
00282 
00283 private:
00284     bool Open( bool isPAL );
00285     static int ResetHandlerProxy( raw1394handle_t handle, unsigned int generation );
00286     static int HandlerProxy( unsigned char *data, int n_dif_blocks,
00287         unsigned int dropped, void *callback_data);
00288 };
00289 #endif
00290 
00291 
00292 #ifdef HAVE_DV1394
00293 class dv1394Writer : public IEEE1394Writer
00294 {
00295 private:
00296     int m_fd;
00297     unsigned int m_channel;
00298     unsigned int m_cip_n;
00299     unsigned int m_cip_d;
00300     unsigned int m_syt_offset;
00301     bool m_isSilent;
00302 
00303 public:
00304 
00305     dv1394Writer( string device, unsigned int channel, unsigned int nBuffers,
00306                   unsigned int cip_n, unsigned int cip_d, unsigned int syt_offset );
00307     ~dv1394Writer();
00308     bool SendFrame( Frame &frame, bool isBlocking = true );
00309     bool isValid( void )
00310     {
00311         return ( m_fd >= 0 );
00312     }
00313     void* Thread();
00314 };
00315 #endif
00316 
00317 #endif

Generated on Sun Mar 11 22:11:45 2007 for Kino by  doxygen 1.4.2