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 *
00005 * This program is free software; you can redistribute it and/or modify
00006 * it under the terms of the GNU General Public License as published by
00007 * the Free Software Foundation; either version 2 of the License, or
00008 * (at your option) any later version.
00009 *
00010 * This program is distributed in the hope that it will be useful,
00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 * GNU General Public License for more details.
00014 *
00015 * You should have received a copy of the GNU General Public License
00016 * along with this program; if not, write to the Free Software Foundation,
00017 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018 */
00019 
00020 #ifndef _IEEE1394IO_H
00021 #define _IEEE1394IO_H 1
00022 
00023 #include <libraw1394/raw1394.h>
00024 #include <libraw1394/csr.h>
00025 #include "dv1394.h"
00026 
00027 #include <string>
00028 using std::string;
00029 #include <deque>
00030 using std::deque;
00031 
00032 class Frame;
00033 
00034 class IEEE1394Reader
00035 {
00036 protected:
00039         int droppedFrames;
00040 
00042         Frame   *currentFrame;
00043 
00045         deque < Frame* > inFrames;
00046 
00048         deque < Frame* > outFrames;
00049 
00050 public:
00051 
00052         IEEE1394Reader( int chn = 63, int frames = 50 );
00053         virtual ~IEEE1394Reader();
00054 
00055         // Mutex protected public methods
00056         virtual bool StartThread( void ) = 0;
00057         virtual void StopThread( void ) = 0;
00058         Frame* GetFrame( void );
00059         void DoneWithFrame( Frame* );
00060         int GetOutQueueSize( void )
00061         {
00062                 return outFrames.size();
00063         }
00064         int GetInQueueSize( void )
00065         {
00066                 return inFrames.size();
00067         }
00068         int GetDroppedFrames( void )
00069         {
00070                 return droppedFrames;
00071         }
00072         void ResetDroppedFrames( void )
00073         {
00074                 droppedFrames = 0;
00075         }
00076 
00077         // These two public methods are not mutex protected
00078         virtual bool Open( void ) = 0;
00079         virtual void Close( void ) = 0;
00080 
00081         bool WaitForAction( );
00082         void TriggerAction( );
00083 
00084         virtual bool StartReceive( void ) = 0;
00085         virtual void StopReceive( void ) = 0;
00086 
00087 protected:
00089         int     channel;
00090 
00092         pthread_t thread;
00093 
00096         pthread_mutex_t mutex;
00097 
00098         // This condition and mutex are used to indicate when new frames are
00099         // received
00100         pthread_mutex_t condition_mutex;
00101         pthread_cond_t condition;
00102 
00104         bool isRunning;
00105 
00106         void Flush( void );
00107 };
00108 
00109 
00110 class raw1394Reader: public IEEE1394Reader
00111 {
00112 private:
00113 
00115         int     port;
00116 
00118         raw1394handle_t handle;
00119 
00120 public:
00121 
00122         raw1394Reader( int crd = 0, int chn = 63, int frames = 50 );
00123         ~raw1394Reader();
00124 
00125         bool Open( void );
00126         void Close( void );
00127         bool StartReceive( void );
00128         void StopReceive( void );
00129         bool StartThread( void );
00130         void StopThread( void );
00131         int Handler( int channel, size_t length, quadlet_t *data );
00132         void *Thread();
00133 
00134 private:
00135         static int HandlerProxy( raw1394handle_t handle, int channel, size_t length, quadlet_t *data );
00136         static void* ThreadProxy( void *arg );
00137 };
00138 
00139 
00140 class dv1394Reader: public IEEE1394Reader
00141 {
00142 private:
00143 
00144         unsigned char *m_dv1394_map;
00145         int m_dv1394_fd;
00146 
00147 public:
00148 
00149         dv1394Reader( int chn = 63, int frames = 50 );
00150         ~dv1394Reader();
00151 
00152         bool Open( void );
00153         void Close( void );
00154         bool StartReceive( void );
00155         void StopReceive( void );
00156         bool StartThread( void );
00157         void StopThread( void );
00158         void* Thread( );
00159 
00160 private:
00161         bool Handler( int handle );
00162         static void* ThreadProxy( void *arg );
00163 };
00164 
00165 
00166 class AVC
00167 {
00168 private:
00170         int     port;
00171 
00174         pthread_mutex_t avc_mutex;
00175 
00177         raw1394handle_t avc_handle;
00178 
00179 public:
00180         AVC( int crd = 0 );
00181         ~AVC();
00182 
00183         int isPhyIDValid( int id );
00184         void Noop( void );
00185         int Play( int id );
00186         int Pause( int id );
00187         int Stop( int id );
00188         int FastForward( int id );
00189         int Rewind( int id );
00190         int Forward( int id );
00191         int Back( int id );
00192         int NextScene( int id );
00193         int PreviousScene( int id );
00194         int Record( int id );
00195         int Shuttle( int id, int speed );
00196         unsigned int TransportStatus( int id );
00197         bool Timecode( int id, char* timecode );
00198         int getNodeId( const char *guid );
00199 
00200 private:
00201         static int ResetHandler( raw1394handle_t handle, unsigned int generation );
00202 
00203 };
00204 
00205 class IEEE1394Writer
00206 {
00207 protected:
00208         int     m_fd;
00209         string m_deviceName;
00210         unsigned int m_channel;
00211         unsigned int    m_nBuffers;
00212         unsigned int    m_cip_n;
00213         unsigned int    m_cip_d;
00214         unsigned int    m_syt_offset;
00215 
00216 public:
00217         IEEE1394Writer()
00218         {}
00219         ;
00220         virtual ~IEEE1394Writer()
00221         {}
00222         ;
00223         virtual void SendFrame( Frame &frame ) = 0;
00224         bool isValid( void )
00225         {
00226                 return ( m_fd >= 0 );
00227         }
00228 
00229 };
00230 
00231 
00232 class dv1394Writer: public IEEE1394Writer
00233 {
00234 private:
00235         bool isInitialised;
00236 
00237 public:
00238 
00239         dv1394Writer( string device, unsigned int channel, unsigned int nBuffers,
00240                       unsigned int cip_n, unsigned int cip_d, unsigned int syt_offset );
00241         ~dv1394Writer();
00242         void SendFrame( Frame &frame );
00243 };
00244 
00245 #endif

Generated on Tue Jan 22 17:07:29 2008 for MUAN by  doxygen 1.4.7