Index: /trunk/libffado/src/libieee1394/CycleTimerHelper.cpp =================================================================== --- /trunk/libffado/src/libieee1394/CycleTimerHelper.cpp (revision 753) +++ /trunk/libffado/src/libieee1394/CycleTimerHelper.cpp (revision 754) @@ -106,5 +106,5 @@ bool CycleTimerHelper::setThreadParameters(bool rt, int priority) { - debugOutput( DEBUG_LEVEL_VERBOSE, "(%p) (rt=%d, prio=%d)...\n", this, rt, priority); + debugOutput( DEBUG_LEVEL_VERBOSE, "(%p) switch to: (rt=%d, prio=%d)...\n", this, rt, priority); if (priority > 98) priority = 98; // cap the priority m_realtime = rt; @@ -135,4 +135,33 @@ return rate; } + +//#define OLD_STYLE +#ifdef OLD_STYLE + +bool +CycleTimerHelper::Execute() +{ + usleep(m_usecs_per_update); + return true; +} +uint32_t +CycleTimerHelper::getCycleTimerTicks() +{ + uint32_t cycle_timer; + uint64_t local_time; + if(!m_Parent.readCycleTimerReg(&cycle_timer, &local_time)) { + debugError("Could not read cycle timer register\n"); + return false; + } + return CYCLE_TIMER_TO_TICKS(cycle_timer); +} + +uint32_t +CycleTimerHelper::getCycleTimerTicks(uint64_t now) +{ + return getCycleTimerTicks(); +} + +#else bool @@ -246,4 +275,5 @@ return retval; } +#endif uint32_t Index: /trunk/libffado/src/libieee1394/ieee1394service.cpp =================================================================== --- /trunk/libffado/src/libieee1394/ieee1394service.cpp (revision 753) +++ /trunk/libffado/src/libieee1394/ieee1394service.cpp (revision 754) @@ -45,5 +45,5 @@ #define FFADO_MAX_FIREWIRE_PORTS 16 -#define ISOMANAGER_PRIO_INCREASE 10 +#define ISOMANAGER_PRIO_INCREASE 11 #define CYCLETIMER_HELPER_PRIO_INCREASE 10 @@ -274,17 +274,19 @@ bool Ieee1394Service::setThreadParameters(bool rt, int priority) { + bool result = true; if (priority > 98) priority = 98; m_base_priority = priority; m_realtime = rt; if (m_pIsoManager) { - return m_pIsoManager->setThreadParameters(rt, priority + ISOMANAGER_PRIO_INCREASE); - } else { - return true; + debugOutput(DEBUG_LEVEL_VERBOSE, "Switching IsoManager to (rt=%d, prio=%d)\n", + rt, priority + ISOMANAGER_PRIO_INCREASE); + result &= m_pIsoManager->setThreadParameters(rt, priority + ISOMANAGER_PRIO_INCREASE); } if (m_pCTRHelper) { - return m_pCTRHelper->setThreadParameters(rt, priority + CYCLETIMER_HELPER_PRIO_INCREASE); - } else { - return true; - } + debugOutput(DEBUG_LEVEL_VERBOSE, "Switching CycleTimerHelper to (rt=%d, prio=%d)\n", + rt, priority + CYCLETIMER_HELPER_PRIO_INCREASE); + result &= m_pCTRHelper->setThreadParameters(rt, priority + CYCLETIMER_HELPER_PRIO_INCREASE); + } + return result; } @@ -315,19 +317,7 @@ * @return the current value of the cycle timer (as is) */ - uint32_t Ieee1394Service::getCycleTimer() { - // the new api should be realtime safe. - // it might cause a reschedule when turning preemption, - // back on but that won't hurt us if we have sufficient - // priority - int err; - uint32_t cycle_timer; - uint64_t local_time; - err=raw1394_read_cycle_timer(m_util_handle, &cycle_timer, &local_time); - if(err) { - debugWarning("raw1394_read_cycle_timer: %s\n", strerror(err)); - } - return cycle_timer; + return m_pCTRHelper->getCycleTimer(); } Index: /trunk/libffado/src/libieee1394/IsoHandlerManager.cpp =================================================================== --- /trunk/libffado/src/libieee1394/IsoHandlerManager.cpp (revision 753) +++ /trunk/libffado/src/libieee1394/IsoHandlerManager.cpp (revision 754) @@ -56,4 +56,5 @@ bool IsoHandlerManager::setThreadParameters(bool rt, int priority) { + debugOutput( DEBUG_LEVEL_VERBOSE, "(%p) switch to: (rt=%d, prio=%d)...\n", this, rt, priority); if (priority > 98) priority = 98; // cap the priority m_realtime = rt; @@ -252,6 +253,6 @@ //irq_interval=2; // HACK // create the actual handler - h = new IsoRecvHandler(*this, buffers, - max_packet_size, irq_interval); + h = new IsoHandler(*this, IsoHandler::eHT_Receive, + buffers, max_packet_size, irq_interval); if(!h) { debugFatal("Could not create IsoRecvHandler\n"); @@ -299,6 +300,6 @@ // create the actual handler - h = new IsoXmitHandler(*this, buffers, - max_packet_size, irq_interval); + h = new IsoHandler(*this, IsoHandler::eHT_Transmit, + buffers, max_packet_size, irq_interval); debugOutput( DEBUG_LEVEL_VERBOSE, " registering IsoXmitHandler\n"); Index: /trunk/libffado/src/libieee1394/IsoHandler.cpp =================================================================== --- /trunk/libffado/src/libieee1394/IsoHandler.cpp (revision 753) +++ /trunk/libffado/src/libieee1394/IsoHandler.cpp (revision 754) @@ -42,10 +42,10 @@ /* the C callbacks */ enum raw1394_iso_disposition -IsoXmitHandler::iso_transmit_handler(raw1394handle_t handle, +IsoHandler::iso_transmit_handler(raw1394handle_t handle, unsigned char *data, unsigned int *length, unsigned char *tag, unsigned char *sy, int cycle, unsigned int dropped) { - IsoXmitHandler *xmitHandler=static_cast(raw1394_get_userdata(handle)); + IsoHandler *xmitHandler = static_cast(raw1394_get_userdata(handle)); assert(xmitHandler); @@ -54,10 +54,10 @@ enum raw1394_iso_disposition -IsoRecvHandler::iso_receive_handler(raw1394handle_t handle, unsigned char *data, +IsoHandler::iso_receive_handler(raw1394handle_t handle, unsigned char *data, unsigned int length, unsigned char channel, unsigned char tag, unsigned char sy, unsigned int cycle, unsigned int dropped) { - IsoRecvHandler *recvHandler=static_cast(raw1394_get_userdata(handle)); + IsoHandler *recvHandler = static_cast(raw1394_get_userdata(handle)); assert(recvHandler); @@ -69,42 +69,69 @@ debugOutput( DEBUG_LEVEL_VERBOSE, "Busreset happened, generation %d...\n", generation); - IsoHandler *handler=static_cast(raw1394_get_userdata(handle)); + IsoHandler *handler = static_cast(raw1394_get_userdata(handle)); assert(handler); return handler->handleBusReset(generation); } - -/* Base class implementation */ -IsoHandler::IsoHandler(IsoHandlerManager& manager) - : m_manager(manager) - , m_handle(0) - , m_buf_packets(400) - , m_max_packet_size(1024) - , m_irq_interval(-1) - , m_packetcount(0) - , m_dropped(0) - , m_Client(0) +IsoHandler::IsoHandler(IsoHandlerManager& manager, enum EHandlerType t) + : m_manager( manager ) + , m_type ( t ) + , m_handle( 0 ) + , m_buf_packets( 400 ) + , m_max_packet_size( 1024 ) + , m_irq_interval( -1 ) + , m_packetcount( 0 ) + , m_dropped( 0 ) + , m_Client( 0 ) , m_poll_timeout( 100 ) , m_realtime ( false ) , m_priority ( 0 ) , m_Thread ( NULL ) - , m_State(E_Created) -{ -} - -IsoHandler::IsoHandler(IsoHandlerManager& manager, unsigned int buf_packets, unsigned int max_packet_size, int irq) - : m_manager(manager) - , m_handle(0) - , m_buf_packets(buf_packets) - , m_max_packet_size( max_packet_size) - , m_irq_interval(irq) - , m_packetcount(0) - , m_dropped(0) - , m_Client(0) + , m_speed( RAW1394_ISO_SPEED_400 ) + , m_prebuffers( 0 ) + , m_State( E_Created ) +{ +} + +IsoHandler::IsoHandler(IsoHandlerManager& manager, enum EHandlerType t, + unsigned int buf_packets, unsigned int max_packet_size, int irq) + : m_manager( manager ) + , m_type ( t ) + , m_handle( 0 ) + , m_buf_packets( buf_packets ) + , m_max_packet_size( max_packet_size ) + , m_irq_interval( irq ) + , m_packetcount( 0 ) + , m_dropped( 0 ) + , m_Client( 0 ) , m_poll_timeout( 100 ) , m_realtime ( false ) , m_priority ( 0 ) , m_Thread ( NULL ) - , m_State(E_Created) + , m_speed( RAW1394_ISO_SPEED_400 ) + , m_prebuffers( 0 ) + , m_State( E_Created ) +{ +} + +IsoHandler::IsoHandler(IsoHandlerManager& manager, enum EHandlerType t, unsigned int buf_packets, + unsigned int max_packet_size, int irq, + enum raw1394_iso_speed speed) + : m_manager( manager ) + , m_type ( t ) + , m_handle( 0 ) + , m_buf_packets( buf_packets ) + , m_max_packet_size( max_packet_size ) + , m_irq_interval( irq ) + , m_packetcount( 0 ) + , m_dropped( 0 ) + , m_Client( 0 ) + , m_poll_timeout( 100 ) + , m_realtime ( false ) + , m_priority ( 0 ) + , m_Thread ( NULL ) + , m_speed( speed ) + , m_prebuffers( 0 ) + , m_State( E_Created ) { } @@ -162,17 +189,19 @@ return false; } - - if (m_poll_fd.revents & POLLERR) { - debugWarning("error on fd for %p\n", this); - } - - if (m_poll_fd.revents & POLLHUP) { - debugWarning("hangup on fd for %p\n",this); - } - if(m_poll_fd.revents & (POLLIN)) { - iterate(); - } - + if(raw1394_loop_iterate(m_handle)) { + debugOutput( DEBUG_LEVEL_VERBOSE, + "IsoHandler (%p): Failed to iterate handler: %s\n", + this,strerror(errno)); + return false; + } + } else { + if (m_poll_fd.revents & POLLERR) { + debugWarning("error on fd for %p\n", this); + } + if (m_poll_fd.revents & POLLHUP) { + debugWarning("hangup on fd for %p\n",this); + } + } return true; } @@ -180,5 +209,5 @@ bool IsoHandler::setThreadParameters(bool rt, int priority) { - debugOutput( DEBUG_LEVEL_VERBOSE, "(%p) (rt=%d, prio=%d)...\n", this, rt, priority); + debugOutput( DEBUG_LEVEL_VERBOSE, "(%p) switch to: (rt=%d, prio=%d)...\n", this, rt, priority); if (priority > 98) priority = 98; // cap the priority m_realtime = rt; @@ -193,17 +222,4 @@ } return true; -} - -bool -IsoHandler::iterate() { - debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "IsoHandler (%p) iterate...\n",this); - if(raw1394_loop_iterate(m_handle)) { - debugOutput( DEBUG_LEVEL_VERBOSE, - "IsoHandler (%p): Failed to iterate handler: %s\n", - this,strerror(errno)); - return false; - } else { - return true; - } } @@ -259,28 +275,4 @@ } -bool IsoHandler::prepare() -{ - debugOutput( DEBUG_LEVEL_VERBOSE, "IsoHandler (%p) prepare...\n", this); - // check the state - if(m_State != E_Initialized) { - debugError("Incorrect state, expected E_Initialized, got %d\n",(int)m_State); - return false; - } - // Don't call until libraw1394's raw1394_new_handle() function has been - // fixed to correctly initialise the iso_packet_infos field. Bug is - // confirmed present in libraw1394 1.2.1. -// raw1394_iso_shutdown(m_handle); - m_State = E_Prepared; - return true; -} - -bool IsoHandler::enable(int cycle) -{ - debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); - m_poll_fd.events = POLLIN; - m_State = E_Running; - return true; -} - bool IsoHandler::disable() { @@ -311,5 +303,7 @@ */ -int IsoHandler::handleBusReset(unsigned int generation) { +int +IsoHandler::handleBusReset(unsigned int generation) +{ debugOutput( DEBUG_LEVEL_VERBOSE, "bus reset...\n"); @@ -330,9 +324,13 @@ debugOutputShort( DEBUG_LEVEL_NORMAL, " Handler type................: %s\n", - (this->getType()==EHT_Receive ? "Receive" : "Transmit")); + (this->getType() == eHT_Receive ? "Receive" : "Transmit")); debugOutputShort( DEBUG_LEVEL_NORMAL, " Port, Channel...............: %2d, %2d\n", m_manager.get1394Service().getPort(), channel); debugOutputShort( DEBUG_LEVEL_NORMAL, " Buffer, MaxPacketSize, IRQ..: %4d, %4d, %4d\n", m_buf_packets, m_max_packet_size, m_irq_interval); + if (this->getType() == eHT_Transmit) { + debugOutputShort( DEBUG_LEVEL_NORMAL, " Speed, PreBuffers...........: %2d, %2d\n", + m_speed, m_prebuffers); + } debugOutputShort( DEBUG_LEVEL_NORMAL, " Packet count................: %10d (%5d dropped)\n", this->getPacketCount(), this->getDroppedCount()); @@ -371,40 +369,15 @@ } -/* Child class implementations */ - -IsoRecvHandler::IsoRecvHandler(IsoHandlerManager& manager) - : IsoHandler(manager) -{ - debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); -} -IsoRecvHandler::IsoRecvHandler(IsoHandlerManager& manager, unsigned int buf_packets, - unsigned int max_packet_size, int irq) - : IsoHandler(manager, buf_packets,max_packet_size,irq) -{ - debugOutput( DEBUG_LEVEL_VERBOSE, "enter...\n"); - -} -IsoRecvHandler::~IsoRecvHandler() -{ - -} - -void IsoRecvHandler::flush() -{ - raw1394_iso_recv_flush(m_handle); -} - -bool -IsoRecvHandler::init() { - debugOutput( DEBUG_LEVEL_VERBOSE, "init recv handler %p\n",this); - - if(!(IsoHandler::init())) { - return false; - } - return true; - -} - -enum raw1394_iso_disposition IsoRecvHandler::putPacket( +void IsoHandler::flush() +{ + if(m_type == eHT_Receive) { + raw1394_iso_recv_flush(m_handle); + } else { + // do nothing + } +} + +// ISO packet interface +enum raw1394_iso_disposition IsoHandler::putPacket( unsigned char *data, unsigned int length, unsigned char channel, unsigned char tag, unsigned char sy, @@ -415,5 +388,5 @@ length, channel, cycle ); m_packetcount++; - m_dropped+=dropped; + m_dropped += dropped; if(m_Client) { @@ -424,50 +397,81 @@ } -bool IsoRecvHandler::prepare() -{ - debugOutput( DEBUG_LEVEL_VERBOSE, "Preparing iso receive handler (%p, client=%p)\n", this, m_Client); - // prepare the generic IsoHandler - if(!IsoHandler::prepare()) { - return false; - } - debugOutput( DEBUG_LEVEL_VERBOSE, "Preparing iso receive handler (%p)\n",this); - debugOutput( DEBUG_LEVEL_VERBOSE, " Buffers : %d \n", m_buf_packets); - debugOutput( DEBUG_LEVEL_VERBOSE, " Max Packet size : %d \n", m_max_packet_size); - debugOutput( DEBUG_LEVEL_VERBOSE, " Channel : %d \n", m_Client->getChannel()); - debugOutput( DEBUG_LEVEL_VERBOSE, " Irq interval : %d \n", m_irq_interval); - debugOutput( DEBUG_LEVEL_VERBOSE, " Mode : %s \n", - (m_irq_interval > 1)?"DMA_BUFFERFILL":"PACKET_PER_BUFFER"); - - if(m_irq_interval > 1) { - if(raw1394_iso_recv_init(m_handle, - iso_receive_handler, + +enum raw1394_iso_disposition IsoHandler::getPacket( + unsigned char *data, unsigned int *length, + unsigned char *tag, unsigned char *sy, + int cycle, unsigned int dropped) { + + debugOutput( DEBUG_LEVEL_VERY_VERBOSE, + "sending packet: length=%d, cycle=%d\n", + *length, cycle ); + m_packetcount++; + m_dropped += dropped; + + if(m_Client) { + return m_Client->getPacket(data, length, tag, sy, cycle, dropped, m_max_packet_size); + } + return RAW1394_ISO_OK; +} + +bool IsoHandler::prepare() +{ + // check the state + if(m_State != E_Initialized) { + debugError("Incorrect state, expected E_Initialized, got %d\n",(int)m_State); + return false; + } + + // Don't call until libraw1394's raw1394_new_handle() function has been + // fixed to correctly initialise the iso_packet_infos field. Bug is + // confirmed present in libraw1394 1.2.1. + // raw1394_iso_shutdown(m_handle); + m_State = E_Prepared; + + debugOutput( DEBUG_LEVEL_VERBOSE, "Preparing iso handler (%p, client=%p)\n", this, m_Client); + dumpInfo(); + if (getType() == eHT_Receive) { + if(m_irq_interval > 1) { + if(raw1394_iso_recv_init(m_handle, + iso_receive_handler, + m_buf_packets, + m_max_packet_size, + m_Client->getChannel(), + RAW1394_DMA_BUFFERFILL, + m_irq_interval)) { + debugFatal("Could not do receive initialisation (DMA_BUFFERFILL)!\n" ); + debugFatal(" %s\n",strerror(errno)); + return false; + } + } else { + if(raw1394_iso_recv_init(m_handle, + iso_receive_handler, + m_buf_packets, + m_max_packet_size, + m_Client->getChannel(), + RAW1394_DMA_PACKET_PER_BUFFER, + m_irq_interval)) { + debugFatal("Could not do receive initialisation (PACKET_PER_BUFFER)!\n" ); + debugFatal(" %s\n",strerror(errno)); + return false; + } + } + return true; + } else { + if(raw1394_iso_xmit_init(m_handle, + iso_transmit_handler, m_buf_packets, m_max_packet_size, m_Client->getChannel(), - RAW1394_DMA_BUFFERFILL, + m_speed, m_irq_interval)) { - debugFatal("Could not do receive initialisation!\n" ); - debugFatal(" %s\n",strerror(errno)); - - return false; - } - } else { - if(raw1394_iso_recv_init(m_handle, - iso_receive_handler, - m_buf_packets, - m_max_packet_size, - m_Client->getChannel(), - RAW1394_DMA_PACKET_PER_BUFFER, - m_irq_interval)) { - debugFatal("Could not do receive initialisation!\n" ); - debugFatal(" %s\n",strerror(errno)); - - return false; - } - } - return true; -} - -bool IsoRecvHandler::enable(int cycle) + debugFatal("Could not do xmit initialisation!\n" ); + return false; + } + return true; + } +} + +bool IsoHandler::enable(int cycle) { debugOutput( DEBUG_LEVEL_VERBOSE, "start on cycle %d\n", cycle); @@ -475,154 +479,25 @@ if(m_State != E_Prepared) { if(!prepare()) { - debugFatal("Could not prepare recv handler\n"); - return false; - } - } - if(raw1394_iso_recv_start(m_handle, cycle, -1, 0)) { - debugFatal("Could not start receive handler (%s)\n",strerror(errno)); - dumpInfo(); - return false; - } - // start the generic IsoHandler - if(!IsoHandler::enable(cycle)) { - return false; - } - return true; -} - -int IsoRecvHandler::handleBusReset(unsigned int generation) { - debugOutput( DEBUG_LEVEL_VERBOSE, "handle bus reset...\n"); - - //TODO: implement busreset - - // pass on the busreset signal - if(IsoHandler::handleBusReset(generation)) { - return -1; - } - return 0; -} - -/* ----------------- XMIT --------------- */ - -IsoXmitHandler::IsoXmitHandler(IsoHandlerManager& manager) - : IsoHandler(manager), m_prebuffers(0) -{ - debugOutput( DEBUG_LEVEL_VERBOSE, "IsoXmitHandler enter...\n"); - -} -IsoXmitHandler::IsoXmitHandler(IsoHandlerManager& manager, unsigned int buf_packets, - unsigned int max_packet_size, int irq) - : IsoHandler(manager, buf_packets, max_packet_size,irq), - m_speed(RAW1394_ISO_SPEED_400), m_prebuffers(0) -{ - debugOutput( DEBUG_LEVEL_VERBOSE, "IsoXmitHandler enter...\n"); - -} -IsoXmitHandler::IsoXmitHandler(IsoHandlerManager& manager, unsigned int buf_packets, - unsigned int max_packet_size, int irq, - enum raw1394_iso_speed speed) - : IsoHandler(manager, buf_packets,max_packet_size,irq), - m_speed(speed), m_prebuffers(0) -{ - debugOutput( DEBUG_LEVEL_VERBOSE, "IsoXmitHandler enter...\n"); - -} - -IsoXmitHandler::~IsoXmitHandler() -{ - // handle cleanup is done in the IsoHanlder destructor -} - -bool -IsoXmitHandler::init() { - - debugOutput( DEBUG_LEVEL_VERBOSE, "init xmit handler %p\n",this); - - if(!(IsoHandler::init())) { - return false; - } - - return true; -} - -bool IsoXmitHandler::prepare() -{ - debugOutput( DEBUG_LEVEL_VERBOSE, "Preparing iso transmit handler (%p, client=%p)\n", this, m_Client); - if(!(IsoHandler::prepare())) { - return false; - } - - debugOutput( DEBUG_LEVEL_VERBOSE, " Buffers : %d \n",m_buf_packets); - debugOutput( DEBUG_LEVEL_VERBOSE, " Max Packet size : %d \n",m_max_packet_size); - debugOutput( DEBUG_LEVEL_VERBOSE, " Channel : %d \n",m_Client->getChannel()); - debugOutput( DEBUG_LEVEL_VERBOSE, " Speed : %d \n",m_speed); - debugOutput( DEBUG_LEVEL_VERBOSE, " Irq interval : %d \n",m_irq_interval); - if(raw1394_iso_xmit_init(m_handle, - iso_transmit_handler, - m_buf_packets, - m_max_packet_size, - m_Client->getChannel(), - m_speed, - m_irq_interval)) { - debugFatal("Could not do xmit initialisation!\n" ); - - return false; - } - return true; -} - -bool IsoXmitHandler::enable(int cycle) -{ - debugOutput( DEBUG_LEVEL_VERBOSE, "start on cycle %d, %d prebuffers\n", - cycle, m_prebuffers); - // check the state - if(m_State != E_Prepared) { - if(!prepare()) { - debugFatal("Could not prepare xmit handler\n"); - return false; - } - } - if(raw1394_iso_xmit_start(m_handle, cycle, m_prebuffers)) { - debugFatal("Could not start xmit handler (%s)\n",strerror(errno)); - dumpInfo(); - return false; - } - if(!(IsoHandler::enable(cycle))) { - return false; - } - return true; -} - -enum raw1394_iso_disposition IsoXmitHandler::getPacket( - unsigned char *data, unsigned int *length, - unsigned char *tag, unsigned char *sy, - int cycle, unsigned int dropped) { - - debugOutput( DEBUG_LEVEL_VERY_VERBOSE, - "sending packet: length=%d, cycle=%d\n", - *length, cycle ); - m_packetcount++; - m_dropped+=dropped; - - if(m_Client) { - return m_Client->getPacket(data, length, tag, sy, cycle, dropped, m_max_packet_size); - } - return RAW1394_ISO_OK; -} - -int IsoXmitHandler::handleBusReset(unsigned int generation) { - debugOutput( DEBUG_LEVEL_VERBOSE, "bus reset...\n"); - //TODO: implement busreset - // pass on the busreset signal - if(IsoHandler::handleBusReset(generation)) { - return -1; - } - return 0; -} - -void IsoXmitHandler::dumpInfo() -{ - IsoHandler::dumpInfo(); - debugOutputShort( DEBUG_LEVEL_NORMAL, " Speed, PreBuffers...........: %2d, %2d\n", - m_speed, m_prebuffers); -} + debugFatal("Could not prepare handler\n"); + return false; + } + } + + if (getType() == eHT_Receive) { + if(raw1394_iso_recv_start(m_handle, cycle, -1, 0)) { + debugFatal("Could not start receive handler (%s)\n",strerror(errno)); + dumpInfo(); + return false; + } + } else { + if(raw1394_iso_xmit_start(m_handle, cycle, m_prebuffers)) { + debugFatal("Could not start xmit handler (%s)\n",strerror(errno)); + dumpInfo(); + return false; + } + } + + m_poll_fd.events = POLLIN; + m_State = E_Running; + return true; +} Index: /trunk/libffado/src/libieee1394/IsoHandler.h =================================================================== --- /trunk/libffado/src/libieee1394/IsoHandler.h (revision 753) +++ /trunk/libffado/src/libieee1394/IsoHandler.h (revision 754) @@ -49,28 +49,54 @@ public: enum EHandlerType { - EHT_Receive, - EHT_Transmit + eHT_Receive, + eHT_Transmit }; - IsoHandler(IsoHandlerManager& manager); - IsoHandler(IsoHandlerManager& manager, unsigned int buf_packets, unsigned int max_packet_size, int irq); - virtual ~IsoHandler(); + IsoHandler(IsoHandlerManager& manager, enum EHandlerType t); + IsoHandler(IsoHandlerManager& manager, enum EHandlerType t, + unsigned int buf_packets, unsigned int max_packet_size, int irq); + IsoHandler(IsoHandlerManager& manager, enum EHandlerType t, + unsigned int buf_packets, unsigned int max_packet_size, int irq, enum raw1394_iso_speed speed); + ~IsoHandler(); +private: // the ISO callback interface + static enum raw1394_iso_disposition + iso_receive_handler(raw1394handle_t handle, unsigned char *data, + unsigned int length, unsigned char channel, + unsigned char tag, unsigned char sy, unsigned int cycle, + unsigned int dropped); + + enum raw1394_iso_disposition + putPacket(unsigned char *data, unsigned int length, + unsigned char channel, unsigned char tag, unsigned char sy, + unsigned int cycle, unsigned int dropped); + + static enum raw1394_iso_disposition iso_transmit_handler(raw1394handle_t handle, + unsigned char *data, unsigned int *length, + unsigned char *tag, unsigned char *sy, + int cycle, unsigned int dropped); + enum raw1394_iso_disposition + getPacket(unsigned char *data, unsigned int *length, + unsigned char *tag, unsigned char *sy, + int cycle, unsigned int dropped); + +public: // runnable interface - virtual bool Init(); - virtual bool Execute(); + bool Init(); + bool Execute(); int getFileDescriptor() { return raw1394_get_fd(m_handle);}; bool setThreadParameters(bool rt, int priority); - virtual bool init(); - virtual bool prepare(); + bool init(); + bool prepare(); bool iterate(); void setVerboseLevel(int l); - virtual bool enable() {return enable(-1);}; - virtual bool enable(int cycle); - virtual bool disable(); + bool enable() {return enable(-1);}; + bool enable(int cycle); + bool disable(); - virtual void flush() = 0; + void flush(); + enum EHandlerType getType() {return m_type;}; bool isEnabled() @@ -88,121 +114,51 @@ void resetDroppedCount() {m_dropped=0;}; - virtual enum EHandlerType getType() = 0; + unsigned int getPreBuffers() {return m_prebuffers;}; + void setPreBuffers(unsigned int n) {m_prebuffers=n;}; - virtual void dumpInfo(); + void dumpInfo(); bool inUse() {return (m_Client != 0) ;}; - virtual bool isStreamRegistered(Streaming::StreamProcessor *s) {return (m_Client == s);}; + bool isStreamRegistered(Streaming::StreamProcessor *s) {return (m_Client == s);}; - virtual bool registerStream(Streaming::StreamProcessor *); - virtual bool unregisterStream(Streaming::StreamProcessor *); + bool registerStream(Streaming::StreamProcessor *); + bool unregisterStream(Streaming::StreamProcessor *); - protected: - IsoHandlerManager& m_manager; - raw1394handle_t m_handle; - unsigned int m_buf_packets; - unsigned int m_max_packet_size; - int m_irq_interval; +private: + IsoHandlerManager& m_manager; + enum EHandlerType m_type; + raw1394handle_t m_handle; + unsigned int m_buf_packets; + unsigned int m_max_packet_size; + int m_irq_interval; - int m_packetcount; - int m_dropped; - Streaming::StreamProcessor *m_Client; + int m_packetcount; + int m_dropped; + Streaming::StreamProcessor *m_Client; - virtual int handleBusReset(unsigned int generation); - DECLARE_DEBUG_MODULE; - private: - static int busreset_handler(raw1394handle_t handle, unsigned int generation); + int handleBusReset(unsigned int generation); - struct pollfd m_poll_fd; - int m_poll_timeout; - // threading - bool m_realtime; - int m_priority; - Util::Thread * m_Thread; + static int busreset_handler(raw1394handle_t handle, unsigned int generation); + + struct pollfd m_poll_fd; + int m_poll_timeout; + // threading + bool m_realtime; + int m_priority; + Util::Thread * m_Thread; + + enum raw1394_iso_speed m_speed; + unsigned int m_prebuffers; // the state machine - protected: - enum EHandlerStates { - E_Created, - E_Initialized, - E_Prepared, - E_Running, - E_Error - }; - enum EHandlerStates m_State; -}; - -/*! -\brief ISO receive handler class (not multichannel) -*/ - -class IsoRecvHandler : public IsoHandler -{ - - public: - IsoRecvHandler(IsoHandlerManager& manager); - IsoRecvHandler(IsoHandlerManager& manager, unsigned int buf_packets, unsigned int max_packet_size, int irq); - virtual ~IsoRecvHandler(); - - bool init(); - enum EHandlerType getType() { return EHT_Receive;}; - bool enable(int cycle); - virtual bool prepare(); - virtual void flush(); - - protected: - int handleBusReset(unsigned int generation); - private: - static enum raw1394_iso_disposition - iso_receive_handler(raw1394handle_t handle, unsigned char *data, - unsigned int length, unsigned char channel, - unsigned char tag, unsigned char sy, unsigned int cycle, - unsigned int dropped); - - enum raw1394_iso_disposition - putPacket(unsigned char *data, unsigned int length, - unsigned char channel, unsigned char tag, unsigned char sy, - unsigned int cycle, unsigned int dropped); -}; - -/*! -\brief ISO transmit handler class -*/ - -class IsoXmitHandler : public IsoHandler -{ - public: - IsoXmitHandler(IsoHandlerManager& manager); - IsoXmitHandler(IsoHandlerManager& manager, unsigned int buf_packets, - unsigned int max_packet_size, int irq); - IsoXmitHandler(IsoHandlerManager& manager, unsigned int buf_packets, - unsigned int max_packet_size, int irq, - enum raw1394_iso_speed speed); - virtual ~IsoXmitHandler(); - - bool init(); - enum EHandlerType getType() { return EHT_Transmit;}; - unsigned int getPreBuffers() {return m_prebuffers;}; - void setPreBuffers(unsigned int n) {m_prebuffers=n;}; - virtual bool enable(int cycle); - virtual bool prepare(); - virtual void flush() {}; - - void dumpInfo(); - protected: - int handleBusReset(unsigned int generation); - - private: - static enum raw1394_iso_disposition iso_transmit_handler(raw1394handle_t handle, - unsigned char *data, unsigned int *length, - unsigned char *tag, unsigned char *sy, - int cycle, unsigned int dropped); - enum raw1394_iso_disposition - getPacket(unsigned char *data, unsigned int *length, - unsigned char *tag, unsigned char *sy, - int cycle, unsigned int dropped); - - enum raw1394_iso_speed m_speed; - unsigned int m_prebuffers; + enum EHandlerStates { + E_Created, + E_Initialized, + E_Prepared, + E_Running, + E_Error + }; + enum EHandlerStates m_State; + DECLARE_DEBUG_MODULE; }; Index: /trunk/libffado/src/libstreaming/StreamProcessorManager.cpp =================================================================== --- /trunk/libffado/src/libstreaming/StreamProcessorManager.cpp (revision 753) +++ /trunk/libffado/src/libstreaming/StreamProcessorManager.cpp (revision 754) @@ -52,6 +52,6 @@ , m_period( 0 ) , m_nominal_framerate ( 0 ) + , m_xrun_happened( false ) , m_xruns(0) - , m_xrun_happened( false ) , m_nbperiods(0) { @@ -476,5 +476,5 @@ diff_between_streams[i] /= NB_PERIODS_FOR_ALIGN_AVERAGE; - diff_between_streams_frames[i] = roundf(diff_between_streams[i] / s->getTicksPerFrame()); + diff_between_streams_frames[i] = (int)roundf(diff_between_streams[i] / s->getTicksPerFrame()); debugOutput( DEBUG_LEVEL_VERBOSE, " avg offset between SyncSP %p and SP %p is %lld ticks, %d frames...\n", m_SyncSource, s, diff_between_streams[i], diff_between_streams_frames[i]); Index: /trunk/libffado/src/libstreaming/util/cip.c =================================================================== --- /trunk/libffado/src/libstreaming/util/cip.c (revision 742) +++ /trunk/libffado/src/libstreaming/util/cip.c (revision 754) @@ -213,6 +213,4 @@ struct iec61883_packet *packet) { - int nevents; - packet->eoh0 = 0; @@ -235,4 +233,4 @@ ptz->dbc += ptz->syt_interval; - return nevents; -} + return 0; +} Index: /trunk/libffado/SConstruct =================================================================== --- /trunk/libffado/SConstruct (revision 753) +++ /trunk/libffado/SConstruct (revision 754) @@ -176,5 +176,5 @@ print "Doing a DEBUG build" # -Werror could be added to, which would force the devs to really remove all the warnings :-) - env.AppendUnique( CCFLAGS=["-DDEBUG","-Wall","-g"] ) + env.AppendUnique( CCFLAGS=["-DDEBUG","-Wall","-g"] ) # HACK!! else: env.AppendUnique( CCFLAGS=["-O2","-DNDEBUG"] )